diff options
author | Adam NAILI | 2018-04-22 14:49:42 +0200 |
---|---|---|
committer | Adam NAILI | 2018-04-22 14:49:42 +0200 |
commit | 40f423a4b3b1e64e8424ab239cc14ecc5077640f (patch) | |
tree | c7da7c2eed97d62cc8ab2e003293935cda5a93dc /src/tpc.lex | |
parent | c0802bc17f856546b95a5b51252f7a35d9e1ab10 (diff) | |
download | tpc-compiler-40f423a4b3b1e64e8424ab239cc14ecc5077640f.tar.gz |
Beginning of the symbol table implementation
Diffstat (limited to 'src/tpc.lex')
-rw-r--r-- | src/tpc.lex | 25 |
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; } |
25 | int { return TYPE; } | 25 | entier { strcpy(yylval.type, yytext); return TYPE; } |
26 | char { return TYPE; } | 26 | caractere { strcpy(yylval.type, yytext); return TYPE; } |
27 | void { return VOID; } | 27 | void { return VOID; } |
28 | const { return CONST; } | 28 | const { return CONST; } |
29 | if { return IF; } | 29 | if { return IF; } |
@@ -33,9 +33,16 @@ return { return RETURN; } | |||
33 | print { return PRINT; } | 33 | print { return PRINT; } |
34 | readc { return READC; } | 34 | readc { return READC; } |
35 | reade { return READE; } | 35 | reade { 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++; } |