OpenCores
URL https://opencores.org/ocsvn/tms1000/tms1000/trunk

Subversion Repositories tms1000

[/] [tms1000/] [trunk/] [assembler/] [casml.l] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 nand_gates
/*
2
casm.l: lexical analyzer specification
3
 
4
CASM is an assembler for the TMS1000 processor.
5
*/
6
 
7
%{
8
#include "y.tab.h"
9
#include "symtab.h"
10
#include "casm.h"
11
 
12
#ifdef OLD_FLEX
13
#undef yywrap
14
/* Only needed for versions of flex prior to 2.4.1. */
15
int yywrap (void);
16
#endif /* OLD_FLEX */
17
 
18
#undef YY_INPUT
19
#define YY_INPUT(buf,result,max_size) \
20
  { \
21
    int r = strlen (lineptr); \
22
    if (r > max_size) \
23
      r = max_size; \
24
    memcpy (buf, lineptr, r); \
25
    lineptr += r; \
26
    result = r; \
27
  }
28
#if 0
29
    fprintf (stderr, "yy_input: '%s', %d\n", lineptr, r); \
30
 
31
#endif
32
%}
33
 
34
octaldig        [0-7]
35
hexdigit    [0-9a-fA-F]
36
digit           [0-9]
37
alpha           [a-zA-Z]
38
alphanum        [a-zA-Z0-9_]
39
 
40
%%
41
{digit}+        { yylval.integer = atoi (yytext); return INTEGER; }
42
 
43
@{hexdigit}     { sscanf (yytext+1, "%x", &yylval.integer); return INTEGER; }
44
 
45
{alpha}{alphanum}*      {
46
                          if (yylval.integer = keyword (yytext))
47
                            return yylval.integer;
48
                          yylval.string = newstr (yytext);
49
                          return IDENT;
50
                        }
51
 
52
 
53
\;.*            ;
54
[ \t]+          ;
55
\n              ;
56
.               { return yytext [0]; }
57
 
58
%%
59
 
60
struct keyword
61
{
62
  char *name;
63
  int value;
64
}
65
keywords [] =
66
{
67
   "br",     BR ,
68
   "call",   CALL ,
69
   "calll",  CALLL,
70
   "clo",    CLO ,
71
   "comx",   COMX ,
72
   "ldp",    LDP  ,
73
   "ldx",    LDX  ,
74
   "sbit",   SBIT ,
75
   "rbit",   RBIT ,
76
   "retn",   RETN ,
77
   "rstr",   RSTR ,
78
   "setr",   SETR ,
79
   "tdo",    TDO  ,
80
   "alec",   ALEC ,
81
   "alem",   ALEM ,
82
   "amaac",  AMAAC,
83
   "a6aac",  A6AAC,
84
   "a8aac",  A8AAC,
85
   "a10aac", A10AAC,
86
   "cla",    CLA  ,
87
   "cpaiz",  CPAIZ,
88
   "dan",    DAN  ,
89
   "dman",   DMAN ,
90
   "dyn",    DYN  ,
91
   "ia",     IA   ,
92
   "imac",   IMAC ,
93
   "iyc",    IYC  ,
94
   "knez",   KNEZ ,
95
   "mnez",   MNEZ ,
96
   "saman",  SAMAN,
97
   "tam",    TAM  ,
98
   "tamiy",  TAMIY,
99
   "tamza",  TAMZA,
100
   "tay",    TAY  ,
101
   "tbit1",  TBIT1,
102
   "tcy",    TCY  ,
103
   "tcmiy",  TCMIY,
104
   "tka",    TKA  ,
105
   "tma",    TMA  ,
106
   "tmy",    TMY  ,
107
   "tya",    TYA  ,
108
   "xma",    XMA  ,
109
   "ynea",   YNEA ,
110
   "ynec",   YNEC ,
111
   "bl",     BL ,
112
   "rom",    ROM ,
113
   "symtab", SYMTAB,
114
    NULL,        0,
115
};
116
 
117
int keyword (char *string)
118
{
119
  struct keyword *ptr;
120
 
121
  for (ptr = keywords; ptr->name; ptr++)
122
    if (stricmp (string, ptr->name) == 0)
123
      return ptr->value;
124
  return 0;
125
}
126
 
127
int yywrap (void)
128
{
129
#ifdef OLD_FLEX
130
/* Only needed for versions of flex prior to 2.4.1. */
131
  yyrestart (yyin);
132
#endif /* OLD_FLEX */
133
  return (1);
134
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.