71 lines
1.6 KiB
Text
71 lines
1.6 KiB
Text
%{
|
|
#include "table.h"
|
|
#include "yacc.tab.h"
|
|
%}
|
|
|
|
/*options for compiling*/
|
|
%option noyywrap
|
|
%option noinput
|
|
%option nounput
|
|
|
|
|
|
/*definition of the different types of comments*/
|
|
M_COMMENT (\/\/).*
|
|
S_COMMENT \/\*(.|\n)*?\*\/
|
|
|
|
|
|
/*definition of the Ids and types of ints*/
|
|
ID [a-zA-Z][a-zA-Z0-9]*
|
|
INT_DEC [0-9]+
|
|
INT_HEX 0x[0-9a-fA-F]+
|
|
|
|
|
|
%%
|
|
|
|
|
|
"if" return(tIF);
|
|
"else" return(tELSE);
|
|
"while" return(tWHILE);
|
|
"print" return(tPRINT);
|
|
"return" return(tRETURN);
|
|
"float" return(tFLOAT);
|
|
"int" return(tINT);
|
|
"void" return(tVOID);
|
|
"+" return(tADD);
|
|
"-" return(tSUB);
|
|
"*" return(tMUL);
|
|
"/" return(tDIV);
|
|
"<" return(tLT);
|
|
">" return(tGT);
|
|
"!=" return(tNE);
|
|
"==" return(tEQ);
|
|
">=" return(tGE);
|
|
"<=" return(tLE);
|
|
"=" return(tASSIGN);
|
|
"&&" return(tAND);
|
|
"||" return(tOR);
|
|
"!" return(tNOT);
|
|
"{" return(tLBRACE);
|
|
"}" return(tRBRACE);
|
|
"(" return(tLPAR);
|
|
")" return(tRPAR);
|
|
";" return(tSEMI);
|
|
"," return(tCOMMA);
|
|
|
|
{ID} {strncpy(yylval.str, yytext, NAME_MAX_LENGTH); return(tID);}
|
|
{INT_DEC} {yylval.nbInt = atoi(yytext); return(tNB);}
|
|
{INT_HEX} {yylval.nbInt = atoi(yytext); return(tNB);}
|
|
|
|
|
|
/*comments are ignored, same for spaces and lines*/
|
|
{M_COMMENT} ;
|
|
{S_COMMENT} ;
|
|
[ ]+ ;
|
|
\n ;
|
|
|
|
/*anything else is considered an error*/
|
|
. yyerror(yytext);
|
|
|
|
%%
|
|
|
|
// SI >> SC
|