diff --git a/src/parser/lexical_analyzer.l b/src/parser/lexical_analyzer.l index 18b2b893ceee611e94ba053df6742f813031fa45..b13f2824743692371ce75d0f4fc965709c0c99ae 100755 --- a/src/parser/lexical_analyzer.l +++ b/src/parser/lexical_analyzer.l @@ -18,9 +18,90 @@ void pass_node(char *text){ /*************** TO STUDENTS: Copy your Lab1 here. Make adjustments if necessary. +ADD \+ +SUB \- +MUL \* +DIV \/ +LT \< +LTE \<\= +GT \> +GTE \>\= +EQ \=\= +NEQ \!\= +ASSIN \= +SEMICOLON \; +COMMA \, +LPARENTHESE \( +RPARENTHESE \) +LBRACKET \[ +RBRACKET \] +LBRACE \{ +RBRACE \} +ELSE else +IF if +INT int +FLOAT float +RETURN return +VOID void +WHILE while + +IDENTIFIER [a-zA-Z]+ +INTEGER [0-9]+ +FLOATPOINT [0-9]+\.|[0-9]*\.[0-9]+ +ARRAY \[\] + +EOL [\n] +COMMENT \/\*([^\*]|(\*)*[^\*\/])*(\*)*\*\/ +BLANK [ \f\n\r\t\v] +ERROR . +TAB [\t]+ Note: don't modify the prologue unless you know what you are doing. ***************/ /* Example for you :-) */ -\+ { pos_start = pos_end; pos_end += 1; pass_node(yytext); return ADD; } +\+ {pos_start = pos_end; pos_end += strlen(yytext); pass_node(yytext);return ADD;} +\- {pos_start = pos_end; pos_end += strlen(yytext); pass_node(yytext);return SUB;} +\* {pos_start = pos_end; pos_end += strlen(yytext); pass_node(yytext);return MUL;} +\/ {pos_start = pos_end; pos_end += strlen(yytext); pass_node(yytext);return DIV;} +\< {pos_start = pos_end; pos_end += strlen(yytext); pass_node(yytext); return LT;} +\<\= {pos_start = pos_end; pos_end += strlen(yytext); pass_node(yytext); return LTE;} +\> {pos_start = pos_end; pos_end += strlen(yytext); pass_node(yytext); return GT;} +\>\= {pos_start = pos_end; pos_end += strlen(yytext); pass_node(yytext); return EQ;} +\!\= {pos_start = pos_end; pos_end += strlen(yytext); pass_node(yytext); return NEQ;} +\= {pos_start = pos_end; pos_end += strlen(yytext); pass_node(yytext); return ASSIN;} + +\; {pos_start = pos_end; pos_end += strlen(yytext); pass_node(yytext); return SEMICOLON;} +\, {pos_start = pos_end; pos_end += strlen(yytext); pass_node(yytext); return COMMA;} +\( {pos_start = pos_end; pos_end += strlen(yytext); pass_node(yytext); return LPARENTHESE;} +\) {pos_start = pos_end; pos_end += strlen(yytext); pass_node(yytext); return RPARENTHESE;} +\[ {pos_start = pos_end; pos_end += strlen(yytext); pass_node(yytext); return LBRACKET;} +\] {pos_start = pos_end; pos_end += strlen(yytext); pass_node(yytext); return RBRACKET;} +\{ {pos_start = pos_end; pos_end += strlen(yytext); pass_node(yytext); return LBRACE;} +\} {pos_start = pos_end; pos_end += strlen(yytext); pass_node(yytext); return RBRACE;} + +else {pos_start = pos_end; pos_end += strlen(yytext); pass_node(yytext); return ELSE;} +if {pos_start = pos_end; pos_end += strlen(yytext); pass_node(yytext); return IF;} +int {pos_start = pos_end; pos_end += strlen(yytext); pass_node(yytext); return INT;} +float {pos_start = pos_end; pos_end += strlen(yytext); pass_node(yytext); return FLOAT;} +return {pos_start = pos_end; pos_end += strlen(yytext); pass_node(yytext); return RETURN;} +void {pos_start = pos_end; pos_end += strlen(yytext); pass_node(yytext); return VOID;} +while {pos_start = pos_end; pos_end += strlen(yytext); pass_node(yytext); return WHILE;} + +[a-zA-Z]+ {pos_start = pos_end; pos_end += strlen(yytext); return IDENTIFIER;} +[0-9]+ {pos_start = pos_end; pos_end += strlen(yytext); pass_node(yytext); return INTEGER;} +[0-9]+\.|[0-9]*\.[0-9]+ {pos_start = pos_end; pos_end += strlen(yytext); pass_node(yytext); return FLOATPOINT;} +\[\] {pos_start = pos_end; pos_end += strlen(yytext); pass_node(yytext); return ARRAY;} + +[\t]+ {pos_start=pos_end;pos_end+=strlen(yytext);} +\/\*([^\*]|(\*)*[^\*\/])*(\*)*\*\/ { + for (int i=0;i