From 11acfa2e75350d31a665b8ee99925916c2c8b5f1 Mon Sep 17 00:00:00 2001 From: pacien Date: Thu, 22 Feb 2018 23:52:17 +0100 Subject: Remove token value copy --- src/tpc.lex | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) (limited to 'src/tpc.lex') 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; %% [ \t\r]+ ; -\n { lineno++;} -"/*" { BEGIN COMMENT;} +\n { lineno++; } +"/*" { BEGIN COMMENT; } && { return AND; } "||" { return OR; } -"*"|"/"|% { yylval.divstar=yytext[0]; return DIVSTAR; } -"+"|- { yylval.addsub=yytext[0]; return ADDSUB; } -"<"|"<="|">"|>= { strcpy(yylval.comp, yytext); return ORDER; } -==|!= { strcpy(yylval.comp, yytext); return EQ; } -int { strcpy(yylval.type, yytext); return TYPE; } -float { strcpy(yylval.type, yytext); return TYPE; } -double { strcpy(yylval.type, yytext); return TYPE; } -char { strcpy(yylval.type, yytext); return TYPE; } +"*"|"/"|% { return DIVSTAR; } +"+"|- { return ADDSUB; } +"<"|"<="|">"|>= { return ORDER; } +==|!= { return EQ; } +int { return TYPE; } +float { return TYPE; } +double { return TYPE; } +char { return TYPE; } void { return VOID; } const { return CONST; } -if { return IF;} -else { return ELSE;} +if { return IF; } +else { return ELSE; } while { return WHILE; } return { return RETURN; } -[a-zA-Z_][a-zA-Z0-9_]* { strcpy(yylval.ident, yytext); return IDENT; } -[0-9]+ { sscanf(yytext, "%d", &(yylval.num)); return NUM; } -'\\?.' { if (strlen(yytext)==3) - yylval.caractere=yytext[1]; - else switch(yytext[2]) { - case 'n': yylval.caractere='\n'; break; - case 't': yylval.caractere='\t'; break; - case '\'': yylval.caractere='\''; break; - } - return CARACTERE; } -. { return yytext[0];} -"*/" { BEGIN INITIAL;} -\n { lineno++;} +[a-zA-Z_][a-zA-Z0-9_]* { return IDENT; } +[0-9]+ { return NUM; } +'\\?.' { return CARACTERE; } +. { return yytext[0]; } +"*/" { BEGIN INITIAL; } +\n { lineno++; } . ; %% -- cgit v1.2.3 From 806dd4ff649a1fb9a28dc469cc17d7dd5dbc1da5 Mon Sep 17 00:00:00 2001 From: pacien Date: Fri, 23 Feb 2018 01:11:34 +0100 Subject: Adapt for new grammar --- src/tpc.lex | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/tpc.lex') diff --git a/src/tpc.lex b/src/tpc.lex index 63d4391..8b824c0 100644 --- a/src/tpc.lex +++ b/src/tpc.lex @@ -16,15 +16,13 @@ int lineno = 1; [ \t\r]+ ; \n { lineno++; } "/*" { BEGIN COMMENT; } -&& { return AND; } +"&&" { return AND; } "||" { return OR; } "*"|"/"|% { return DIVSTAR; } "+"|- { return ADDSUB; } -"<"|"<="|">"|>= { return ORDER; } +"<"|"<="|">"|">=" { return ORDER; } ==|!= { return EQ; } int { return TYPE; } -float { return TYPE; } -double { return TYPE; } char { return TYPE; } void { return VOID; } const { return CONST; } @@ -32,6 +30,9 @@ if { return IF; } else { return ELSE; } while { return WHILE; } return { return RETURN; } +print { return PRINT; } +readc { return READC; } +reade { return READE; } [a-zA-Z_][a-zA-Z0-9_]* { return IDENT; } [0-9]+ { return NUM; } '\\?.' { return CARACTERE; } -- cgit v1.2.3