aboutsummaryrefslogtreecommitdiff
path: root/src/tpc.lex
diff options
context:
space:
mode:
authorAdam NAILI2018-04-22 14:49:42 +0200
committerAdam NAILI2018-04-22 14:49:42 +0200
commit40f423a4b3b1e64e8424ab239cc14ecc5077640f (patch)
treec7da7c2eed97d62cc8ab2e003293935cda5a93dc /src/tpc.lex
parentc0802bc17f856546b95a5b51252f7a35d9e1ab10 (diff)
downloadtpc-compiler-40f423a4b3b1e64e8424ab239cc14ecc5077640f.tar.gz
Beginning of the symbol table implementation
Diffstat (limited to 'src/tpc.lex')
-rw-r--r--src/tpc.lex25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/tpc.lex b/src/tpc.lex
index 8b824c0..5137d39 100644
--- a/src/tpc.lex
+++ b/src/tpc.lex
@@ -18,12 +18,12 @@ int lineno = 1;
18"/*" { BEGIN COMMENT; } 18"/*" { BEGIN COMMENT; }
19"&&" { return AND; } 19"&&" { return AND; }
20"||" { return OR; } 20"||" { return OR; }
21"*"|"/"|% { return DIVSTAR; } 21"*"|"/"|% { yylval.divstar=yytext[0]; return DIVSTAR; }
22"+"|- { return ADDSUB; } 22"+"|- { yylval.addsub=yytext[0]; return ADDSUB; }
23"<"|"<="|">"|">=" { return ORDER; } 23"<"|"<="|">"|">=" { strcpy(yylval.comp, yytext); return ORDER; }
24==|!= { return EQ; } 24==|!= { strcpy(yylval.comp, yytext); return EQ; }
25int { return TYPE; } 25entier { strcpy(yylval.type, yytext); return TYPE; }
26char { return TYPE; } 26caractere { strcpy(yylval.type, yytext); return TYPE; }
27void { return VOID; } 27void { return VOID; }
28const { return CONST; } 28const { return CONST; }
29if { return IF; } 29if { return IF; }
@@ -33,9 +33,16 @@ return { return RETURN; }
33print { return PRINT; } 33print { return PRINT; }
34readc { return READC; } 34readc { return READC; }
35reade { return READE; } 35reade { return READE; }
36[a-zA-Z_][a-zA-Z0-9_]* { return IDENT; } 36[a-zA-Z_][a-zA-Z0-9_]* { strcpy(yylval.ident, yytext); return IDENT; }
37[0-9]+ { return NUM; } 37[0-9]+ { sscanf(yytext, "%d", &(yylval.num)); return NUM; }
38'\\?.' { return CARACTERE; } 38'\\?.' { if (strlen(yytext)==3)
39 yylval.caractere=yytext[1];
40 else switch(yytext[2]) {
41 case 'n': yylval.caractere='\n'; break;
42 case 't': yylval.caractere='\t'; break;
43 case '\'': yylval.caractere='\''; break;
44 }
45 return CARACTERE; }
39. { return yytext[0]; } 46. { return yytext[0]; }
40<COMMENT>"*/" { BEGIN INITIAL; } 47<COMMENT>"*/" { BEGIN INITIAL; }
41<COMMENT>\n { lineno++; } 48<COMMENT>\n { lineno++; }