From 66f66d2363e41274589ccad098269e379e348632 Mon Sep 17 00:00:00 2001 From: pacien Date: Tue, 20 Feb 2018 23:40:23 +0100 Subject: Import from TD11 --- src/tpc.lex | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/tpc.lex (limited to 'src/tpc.lex') diff --git a/src/tpc.lex b/src/tpc.lex new file mode 100644 index 0000000..eaeea89 --- /dev/null +++ b/src/tpc.lex @@ -0,0 +1,50 @@ +%{ +/** + * UPEM / Compilation / Projet + * Pacien TRAN-GIRARD, Adam NAILI + */ + +#include "tpc.tab.h" + +int lineno = 1; +%} + +%option noinput nounput noyywrap +%x COMMENT + +%% +[ \t\r]+ ; +\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; } +void { return VOID; } +const { return CONST; } +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++;} +. ; +%% + -- cgit v1.2.3