37
+ − 1
%{
39
+ − 2
#include <prototypes.h>
+ − 3
#include "parser.h"
+ − 4
int column = 0;
+ − 5
int c;
37
+ − 6
%}
+ − 7
39
+ − 8
D [0-9]
+ − 9
L [a-zA-Z_]
+ − 10
H [a-fA-F0-9]
+ − 11
E [Ee][+-]?{D}+
+ − 12
FS (f|F|l|L)
+ − 13
IS (u|U|l|L)*
37
+ − 14
+ − 15
%%
39
+ − 16
"/*" { comment(); }
+ − 17
"#include <" { c = input(); while ( c != '>') c = input(); }
+ − 18
"#include \"" { c = input(); while ( c != '\"') c = input(); }
37
+ − 19
39
+ − 20
"auto" { count(); return(AUTO); }
+ − 21
"break" { count(); return(BREAK); }
+ − 22
"case" { count(); return(CASE); }
+ − 23
"char" { count(); return(CHAR); }
+ − 24
"const" { count(); return(CONST); }
+ − 25
"continue" { count(); return(CONTINUE); }
+ − 26
"default" { count(); return(DEFAULT); }
+ − 27
"do" { count(); return(DO); }
+ − 28
"double" { count(); return(DOUBLE); }
+ − 29
"else" { count(); return(ELSE); }
+ − 30
"enum" { count(); return(ENUM); }
+ − 31
"extern" { count(); return(EXTERN); }
+ − 32
"float" { count(); return(FLOAT); }
+ − 33
"for" { count(); return(FOR); }
+ − 34
"goto" { count(); return(GOTO); }
+ − 35
"if" { count(); return(IF); }
+ − 36
"int" { count(); return(INT); }
+ − 37
"long" { count(); return(LONG); }
+ − 38
"register" { count(); return(REGISTER); }
+ − 39
"return" { count(); return(RETURN); }
+ − 40
"short" { count(); return(SHORT); }
+ − 41
"signed" { count(); return(SIGNED); }
+ − 42
"sizeof" { count(); return(SIZEOF); }
+ − 43
"static" { count(); return(STATIC); }
+ − 44
"struct" { count(); return(STRUCT); }
+ − 45
"switch" { count(); return(SWITCH); }
+ − 46
"typedef" { count(); return(TYPEDEF); }
+ − 47
"union" { count(); return(UNION); }
+ − 48
"unsigned" { count(); return(UNSIGNED); }
+ − 49
"void" { count(); return(VOID); }
+ − 50
"volatile" { count(); return(VOLATILE); }
+ − 51
"while" { count(); return(WHILE); }
37
+ − 52
39
+ − 53
{L}({L}|{D})* { count(); return(check_type()); }
+ − 54
0[xX]{H}+{IS}? { count(); return(CONSTANT); }
+ − 55
0{D}+{IS}? { count(); return(CONSTANT); }
+ − 56
{D}+{IS}? { count(); return(CONSTANT); }
+ − 57
'(\\.|[^\\'])+' { count(); return(CONSTANT); }
37
+ − 58
39
+ − 59
{D}+{E}{FS}? { count(); return(CONSTANT); }
+ − 60
{D}*"."{D}+({E})?{FS}? { count(); return(CONSTANT); }
+ − 61
{D}+"."{D}*({E})?{FS}? { count(); return(CONSTANT); }
37
+ − 62
39
+ − 63
\"(\\.|[^\\"])*\" { count(); return(STRING_LITERAL); }
37
+ − 64
39
+ − 65
">>=" { count(); return(RIGHT_ASSIGN); }
+ − 66
"<<=" { count(); return(LEFT_ASSIGN); }
+ − 67
"+=" { count(); return(ADD_ASSIGN); }
+ − 68
"-=" { count(); return(SUB_ASSIGN); }
+ − 69
"*=" { count(); return(MUL_ASSIGN); }
+ − 70
"/=" { count(); return(DIV_ASSIGN); }
+ − 71
"%=" { count(); return(MOD_ASSIGN); }
+ − 72
"&=" { count(); return(AND_ASSIGN); }
+ − 73
"^=" { count(); return(XOR_ASSIGN); }
+ − 74
"|=" { count(); return(OR_ASSIGN); }
+ − 75
">>" { count(); return(RIGHT_OP); }
+ − 76
"<<" { count(); return(LEFT_OP); }
+ − 77
"++" { count(); return(INC_OP); }
+ − 78
"--" { count(); return(DEC_OP); }
+ − 79
"->" { count(); return(PTR_OP); }
+ − 80
"&&" { count(); return(AND_OP); }
+ − 81
"||" { count(); return(OR_OP); }
+ − 82
"<=" { count(); return(LE_OP); }
+ − 83
">=" { count(); return(GE_OP); }
+ − 84
"==" { count(); return(EQ_OP); }
+ − 85
"!=" { count(); return(NE_OP); }
+ − 86
";" { count(); return(';'); }
+ − 87
"{" { count(); return('{'); }
+ − 88
"}" { count(); return('}'); }
+ − 89
"," { count(); return(','); }
+ − 90
":" { count(); return(':'); }
+ − 91
"=" { count(); return('='); }
+ − 92
"(" { count(); return('('); }
+ − 93
")" { count(); return(')'); }
+ − 94
"[" { count(); return('['); }
+ − 95
"]" { count(); return(']'); }
+ − 96
"." { count(); return('.'); }
+ − 97
"&" { count(); return('&'); }
+ − 98
"!" { count(); return('!'); }
+ − 99
"~" { count(); return('~'); }
+ − 100
"-" { count(); return('-'); }
+ − 101
"+" { count(); return('+'); }
+ − 102
"*" { count(); return('*'); }
+ − 103
"/" { count(); return('/'); }
+ − 104
"%" { count(); return('%'); }
+ − 105
"<" { count(); return('<'); }
+ − 106
">" { count(); return('>'); }
+ − 107
"^" { count(); return('^'); }
+ − 108
"|" { count(); return('|'); }
+ − 109
"?" { count(); return('?'); }
+ − 110
[ \t\v\n\f] { count(); }
+ − 111
. { printf ("Unknown Token: %s\n", yytext); }
37
+ − 112
%%
+ − 113
+ − 114
int yywrap()
+ − 115
{
39
+ − 116
/* stop after eof */
+ − 117
return 1;
37
+ − 118
}
+ − 119
+ − 120
int count()
+ − 121
{
39
+ − 122
int i;
37
+ − 123
39
+ − 124
for (i = 0; yytext[i] != '\0'; i++)
+ − 125
if (yytext[i] == '\n')
+ − 126
column = 0;
+ − 127
else if (yytext[i] == '\t')
+ − 128
column += 4 - (column % 4);
+ − 129
else
+ − 130
column++;
37
+ − 131
39
+ − 132
return column;
37
+ − 133
}
+ − 134
+ − 135
int check_type()
+ − 136
{
39
+ − 137
return IDENTIFIER;
37
+ − 138
}
+ − 139
39
+ − 140
void comment()
37
+ − 141
{
39
+ − 142
int c;
37
+ − 143
39
+ − 144
c = input();
+ − 145
do {
+ − 146
while ( c != '*')
+ − 147
c = input();
+ − 148
c=input();
+ − 149
} while(c != '/');
37
+ − 150
}