AeInstFile.l
2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
%{
#include <stdlib.h>
#include "AeInstFile.h"
#include "AeInstHash.h"
/*
* y.tab.h is created by "yacc -vd ic.y". It is included so the
* Lexical Analyzer knows the definitions of the "terminals" (%token)
* in the grammar and the %union types.
*/
#include "y.tab.h"
/* commentdepth keeps track of nested comments */
int commentdepth = 0;
%}
%start norm comment
LETTER [a-zA-Z_]
DIGIT [0-9]
HEXDIGIT [0-9A-F]
OCTALDIGIT [0-7]
ID ({LETTER}({LETTER}|{DIGIT})*)
DECINTEGER (-?{DIGIT}+)
OCTINTEGER ({OCTALDIGIT}+("B"|"C"))
HEXINTEGER ({DIGIT}{HEXDIGIT}*"H")
SCALEFACTOR ("E"("+"|"-")?{DIGIT}+)
REAL ({DIGIT}+"."{DIGIT}*{SCALEFACTOR}?/(".."|[^.]))
STRING ((\"[^"]*\")|(\'[^']*\'))
%%
<norm>[ \t\n] ; /* ignore whitespace */
<norm>{DECINTEGER} {
yylval.intval=
(int) strtol(yytext, (char **) NULL, 10);
return(INTCONST);
}
<norm>{OCTINTEGER} {
/* remove the B or C at end */
yytext[yyleng-1]='\0';
yylval.intval=
(int) strtol(yytext,(char **) NULL,8);
return(INTCONST);
}
<norm>{HEXINTEGER} {
/* remove the H at end */
yytext[yyleng-1]='\0';
yylval.intval=
(int) strtol(yytext,(char **) NULL,16);
return(INTCONST);
}
<norm>{REAL} {
sscanf(yytext, "%lf",&yylval.floatval);
return(FLOATCONST);
}
<norm>{STRING} {
yylval.stringval=
(char *) malloc((unsigned) yyleng+1);
strcpy(yylval.stringval,yytext);
return(STRINGCONST);
}
<norm>[+\-*/=<>\^,.;:|([{}\])] return(yytext[0]);
<norm>"&" return(AND);
<norm>":=" return(COLONEQUAL);
<norm>("#"|"<>") return(NOTEQUAL);
<norm>">=" return(GREATEREQUAL);
<norm>"<=" return(LESSEQUAL);
"/*" {/* Note: this is always active, because of nesting. */
BEGIN comment;
++commentdepth;
}
<norm>{ID} {
yylval.id = instFile->hash->Enter(ID, yytext, yyleng);
return(yylval.id->lextype);
}
<comment>(.|\n) ; /* discard everything within a comment */
<comment>"*/" {
if (--commentdepth == 0)
BEGIN norm;
}
<norm>. { /* No other rule applies, so it's a bad token */
fprintf(stderr,"Bad input char `%c' on line %d\n",
yytext[0],yylineno);
}
%%
/* lexinit - starts the Lexical Analyzer off in the right start condition */
void initLex(void)
{
BEGIN norm;
}
/* does this really need to be here? */
yywrap()
{
return 1;
}