aboutsummaryrefslogtreecommitdiff
path: root/src/tpc.lex
diff options
context:
space:
mode:
authorpacien2018-02-22 23:52:17 +0100
committerpacien2018-02-22 23:52:17 +0100
commit11acfa2e75350d31a665b8ee99925916c2c8b5f1 (patch)
treee26cecf3f7d5313cb487466b62dbe14e3dd92c07 /src/tpc.lex
parentc84e00f62d1fbd273e5a07f7105c727da0f0ff8b (diff)
downloadtpc-compiler-11acfa2e75350d31a665b8ee99925916c2c8b5f1.tar.gz
Remove token value copy
Diffstat (limited to 'src/tpc.lex')
-rw-r--r--src/tpc.lex43
1 files changed, 18 insertions, 25 deletions
diff --git a/src/tpc.lex b/src/tpc.lex
index eaeea89..63d4391 100644
--- a/src/tpc.lex
+++ b/src/tpc.lex
@@ -14,37 +14,30 @@ 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; } 26float { return TYPE; }
27double { strcpy(yylval.type, yytext); return TYPE; } 27double { return TYPE; }
28char { strcpy(yylval.type, yytext); return TYPE; } 28char { return TYPE; }
29void { return VOID; } 29void { return VOID; }
30const { return CONST; } 30const { return CONST; }
31if { return IF;} 31if { return IF; }
32else { return ELSE;} 32else { return ELSE; }
33while { return WHILE; } 33while { return WHILE; }
34return { return RETURN; } 34return { return RETURN; }
35[a-zA-Z_][a-zA-Z0-9_]* { strcpy(yylval.ident, yytext); return IDENT; } 35[a-zA-Z_][a-zA-Z0-9_]* { return IDENT; }
36[0-9]+ { sscanf(yytext, "%d", &(yylval.num)); return NUM; } 36[0-9]+ { return NUM; }
37'\\?.' { if (strlen(yytext)==3) 37'\\?.' { return CARACTERE; }
38 yylval.caractere=yytext[1]; 38. { return yytext[0]; }
39 else switch(yytext[2]) { 39<COMMENT>"*/" { BEGIN INITIAL; }
40 case 'n': yylval.caractere='\n'; break; 40<COMMENT>\n { lineno++; }
41 case 't': yylval.caractere='\t'; break;
42 case '\'': yylval.caractere='\''; break;
43 }
44 return CARACTERE; }
45. { return yytext[0];}
46<COMMENT>"*/" { BEGIN INITIAL;}
47<COMMENT>\n { lineno++;}
48<COMMENT>. ; 41<COMMENT>. ;
49%% 42%%
50 43