aboutsummaryrefslogtreecommitdiff
path: root/src/tpc.lex
diff options
context:
space:
mode:
Diffstat (limited to 'src/tpc.lex')
-rw-r--r--src/tpc.lex46
1 files changed, 20 insertions, 26 deletions
diff --git a/src/tpc.lex b/src/tpc.lex
index eaeea89..8b824c0 100644
--- a/src/tpc.lex
+++ b/src/tpc.lex
@@ -14,37 +14,31 @@ int lineno = 1;
14 14
15%% 15%%
16[ \t\r]+ ; 16[ \t\r]+ ;
17\n { lineno++;} 17\n { lineno++; }
18"/*" { BEGIN COMMENT;} 18"/*" { BEGIN COMMENT; }
19&& { return AND; } 19"&&" { return AND; }
20"||" { return OR; } 20"||" { return OR; }
21"*"|"/"|% { yylval.divstar=yytext[0]; return DIVSTAR; } 21"*"|"/"|% { return DIVSTAR; }
22"+"|- { yylval.addsub=yytext[0]; return ADDSUB; } 22"+"|- { return ADDSUB; }
23"<"|"<="|">"|>= { strcpy(yylval.comp, yytext); return ORDER; } 23"<"|"<="|">"|">=" { return ORDER; }
24==|!= { strcpy(yylval.comp, yytext); return EQ; } 24==|!= { return EQ; }
25int { strcpy(yylval.type, yytext); return TYPE; } 25int { return TYPE; }
26float { strcpy(yylval.type, yytext); return TYPE; } 26char { return TYPE; }
27double { strcpy(yylval.type, yytext); return TYPE; }
28char { strcpy(yylval.type, yytext); return TYPE; }
29void { return VOID; } 27void { return VOID; }
30const { return CONST; } 28const { return CONST; }
31if { return IF;} 29if { return IF; }
32else { return ELSE;} 30else { return ELSE; }
33while { return WHILE; } 31while { return WHILE; }
34return { return RETURN; } 32return { return RETURN; }
35[a-zA-Z_][a-zA-Z0-9_]* { strcpy(yylval.ident, yytext); return IDENT; } 33print { return PRINT; }
36[0-9]+ { sscanf(yytext, "%d", &(yylval.num)); return NUM; } 34readc { return READC; }
37'\\?.' { if (strlen(yytext)==3) 35reade { return READE; }
38 yylval.caractere=yytext[1]; 36[a-zA-Z_][a-zA-Z0-9_]* { return IDENT; }
39 else switch(yytext[2]) { 37[0-9]+ { return NUM; }
40 case 'n': yylval.caractere='\n'; break; 38'\\?.' { return CARACTERE; }
41 case 't': yylval.caractere='\t'; break; 39. { return yytext[0]; }
42 case '\'': yylval.caractere='\''; break; 40<COMMENT>"*/" { BEGIN INITIAL; }
43 } 41<COMMENT>\n { lineno++; }
44 return CARACTERE; }
45. { return yytext[0];}
46<COMMENT>"*/" { BEGIN INITIAL;}
47<COMMENT>\n { lineno++;}
48<COMMENT>. ; 42<COMMENT>. ;
49%% 43%%
50 44