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

Subversion Repositories c16

[/] [c16/] [trunk/] [asm/] [assembler.flex] - Blame information for rev 31

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jsauermann
 
2
D                       [0-9]
3
L                       [A-Za-z_]
4
LD                      [0-9A-Za-z_]
5
ID                      {L}{LD}*
6
HX                      [0-9A-Fa-f]
7
 
8
%{
9
#include 
10
#include 
11
 
12
class Opcode;
13
class Operand;
14
class Expression;
15
 
16 30 jsauermann
#include "assembler_bison.hh"
17 2 jsauermann
 
18
void count();
19
int show_token(int op, const char * txt, YYSTYPE & lval);
20
#define token(x) show_token(x, yytext, yylval)
21
 
22
%}
23
 
24
%%
25
";".*                   { count(); return token(EOL  ); }
26
" "                     { count(); }
27
"\n"                    { count(); return token(EOL  ); }
28
 
29
".BYTE"                 { count(); return token(_BYTE  ); }
30
".WORD"                 { count(); return token(_WORD  ); }
31
".OFFSET"               { count(); return token(_OFFSET); }
32
".EXTERN"               { count(); return token(_EXTERN); }
33
".STATIC"               { count(); return token(_STATIC); }
34
ADD                     { count(); return token(ADD    ); }
35
AND                     { count(); return token(AND    ); }
36
CALL                    { count(); return token(CALL   ); }
37
CLRB                    { count(); return token(CLRB   ); }
38
CLRW                    { count(); return token(CLRW   ); }
39
DI                      { count(); return token(DI     ); }
40
DIV_IS                  { count(); return token(DIV_IS ); }
41
DIV_IU                  { count(); return token(DIV_IU ); }
42
EI                      { count(); return token(EI     ); }
43
HALT                    { count(); return token(HALT   ); }
44
IN                      { count(); return token(IN     ); }
45
JMP                     { count(); return token(JMP    ); }
46
LEA                     { count(); return token(LEA    ); }
47
LNOT                    { count(); return token(LNOT   ); }
48
MD_STP                  { count(); return token(MD_STP ); }
49
MD_FIN                  { count(); return token(MD_FIN ); }
50
MOD_FIN                 { count(); return token(MOD_FIN); }
51
MUL_IS                  { count(); return token(MUL_IS ); }
52
MUL_IU                  { count(); return token(MUL_IU ); }
53
MOVE                    { count(); return token(MOVE   ); }
54
NEG                     { count(); return token(NEG    ); }
55
NOT                     { count(); return token(NOT    ); }
56
NOP                     { count(); return token(NOP    ); }
57
OUT                     { count(); return token(OUT    ); }
58
OR                      { count(); return token(OR     ); }
59
RET                     { count(); return token(RET    ); }
60
RETI                    { count(); return token(RETI   ); }
61
SEQ                     { count(); return token(SEQ    ); }
62
SGE                     { count(); return token(SGE    ); }
63
SGT                     { count(); return token(SGT    ); }
64
SLE                     { count(); return token(SLE    ); }
65
SLT                     { count(); return token(SLT    ); }
66
SNE                     { count(); return token(SNE    ); }
67
SHS                     { count(); return token(SHS    ); }
68
SHI                     { count(); return token(SHI    ); }
69
SLS                     { count(); return token(SLS    ); }
70
SLO                     { count(); return token(SLO    ); }
71
LSL                     { count(); return token(LSL    ); }
72
LSR                     { count(); return token(LSR    ); }
73
ASR                     { count(); return token(ASR    ); }
74
SUB                     { count(); return token(SUB    ); }
75
XOR                     { count(); return token(XOR    ); }
76
 
77
RR                      { count(); return token(_RR   );  }
78
R                       { count(); return token(_R    );  }
79
RS                      { count(); return token(_RS   );  }
80
RU                      { count(); return token(_RU   );  }
81
RRZ                     { count(); return token(_RRZ  );  }
82
RRNZ                    { count(); return token(_RRNZ );  }
83
 
84
LL                      { count(); return token(_LL   );  }
85
L                       { count(); return token(_L    );  }
86
LS                      { count(); return token(_LS   );  }
87
LU                      { count(); return token(_LU   );  }
88
 
89
SP                      { count(); return token(_SP   );  }
90
 
91
[#,:+=()*/-]            { count(); return token(*yytext); }
92
 
93
0[xX]{HX}+              { count();
94
                          sscanf(yytext + 2, "%X", &yylval._num);
95
                          return token(INT   ); }
96
 
97
"-"0[xX]{HX}+           { count();
98
                          sscanf(yytext + 3, "%X", &yylval._num);
99
                          yylval._num = -yylval._num;
100
                          return token(INT   ); }
101
 
102
{D}+                    { count();
103
                          sscanf(yytext, "%d", &yylval._num);
104
                          return token(INT   ); }
105
 
106
"-"{D}+                 { count();
107
                          sscanf(yytext + 1, "%d", &yylval._num);
108
                          yylval._num = -yylval._num;
109
                          return token(INT   ); }
110
 
111
{ID}                    { count();   return token(IDENT); }
112
 
113
[ \t\v\n\f]             { count(); }
114
 
115
<>                       { return EOFILE;  }
116
.                       { return ERROR;   }
117
 
118
%%
119
 
120
int yywrap()
121
{
122
        return(1);
123
}
124
 
125
int column = 0;
126
int row    = 1;
127
 
128
//-----------------------------------------------------------------------------
129
void count()
130
{
131
   for (int i = 0; yytext[i]; i++)
132
       {
133
         if (yytext[i] == '\n')        { column = 0;   row++; }
134
         else if (yytext[i] == '\t')   column += 8 - (column % 8);
135
         else                          column++;
136
       }
137
}
138
//-----------------------------------------------------------------------------
139
int yyerror(const char *s)
140
{
141
   printf("\n%s Line %d Col %d\n", s, row, column);
142
   fflush(stdout);
143
}
144
//-----------------------------------------------------------------------------
145
bool did_crlf = false;
146
bool show_it  = false;
147
 
148
int show_token(int op, const char * txt, YYSTYPE & lval)
149
{
150
   if (op == INT)
151
      {
152
        did_crlf = false;
153
        if (show_it)   fprintf(stderr, "Token %3d : %s\n", op, txt);
154
      }
155
   else if (op == EOL)
156
      {
157
        lval._txt = 0;
158
        if (!did_crlf && show_it)   fprintf(stderr, "\n");
159
        did_crlf = true;
160
      }
161
   else
162
      {
163
        assert(txt);
164
        did_crlf = false;
165
        if (show_it)   fprintf(stderr, "Token %3d : %s\n", op, txt);
166
        char * cp = new char[strlen(txt) + 1];
167
        strcpy(cp, txt);
168
        lval._txt = cp;
169
      }
170
    return op;
171
}
172
//-----------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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