diff options
author | pacien | 2018-02-22 23:52:17 +0100 |
---|---|---|
committer | pacien | 2018-02-22 23:52:17 +0100 |
commit | 11acfa2e75350d31a665b8ee99925916c2c8b5f1 (patch) | |
tree | e26cecf3f7d5313cb487466b62dbe14e3dd92c07 /src/tpc.lex | |
parent | c84e00f62d1fbd273e5a07f7105c727da0f0ff8b (diff) | |
download | tpc-compiler-11acfa2e75350d31a665b8ee99925916c2c8b5f1.tar.gz |
Remove token value copy
Diffstat (limited to 'src/tpc.lex')
-rw-r--r-- | src/tpc.lex | 43 |
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; } |
25 | int { strcpy(yylval.type, yytext); return TYPE; } | 25 | int { return TYPE; } |
26 | float { strcpy(yylval.type, yytext); return TYPE; } | 26 | float { return TYPE; } |
27 | double { strcpy(yylval.type, yytext); return TYPE; } | 27 | double { return TYPE; } |
28 | char { strcpy(yylval.type, yytext); return TYPE; } | 28 | char { return TYPE; } |
29 | void { return VOID; } | 29 | void { return VOID; } |
30 | const { return CONST; } | 30 | const { return CONST; } |
31 | if { return IF;} | 31 | if { return IF; } |
32 | else { return ELSE;} | 32 | else { return ELSE; } |
33 | while { return WHILE; } | 33 | while { return WHILE; } |
34 | return { return RETURN; } | 34 | return { 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 | ||