/* * Name : nac.l * Purpose : Lexer for the NAC (n-address code) file parser. * Author : Nikolaos Kavvadias (C) 2009, 2010 * Date : 05-Sep-2010 */ %{ #include #include #include #include #include "nac.tab.h" #define YY_NO_UNISTD_H 1 /* To avoid the inclusion of . */ void count(); %} ws [ \t\n\f\r] letter [a-zA-Z] integer [1-9][0-9]* anum [+-]?[a-zA-Z0-9_][a-zA-Z0-9_]* A [aA] B [bB] C [cC] D [dD] E [eE] F [fF] G [gG] H [hH] I [iI] J [jJ] K [kK] L [lL] M [mM] N [nN] O [oO] P [pP] Q [qQ] R [rR] S [sS] T [tT] U [uU] V [vV] W [wW] X [xX] Y [yY] Z [zZ] %% "//".* { count(); } {ws} { /* just eat-up whitespace */; } "(" { count(); return(T_LPAREN); } ")" { count(); return(T_RPAREN); } "{" { count(); return(T_LBRACE); } "}" { count(); return(T_RBRACE); } "[" { count(); return(T_LBRACKET); } "]" { count(); return(T_RBRACKET); } "," { count(); return(T_COMMA); } ":" { count(); return(T_COLON); } ";" { count(); return(T_SEMI); } "<=" { count(); return(T_ASSIGN); } "=" { count(); return(T_EQUAL); } {P}{R}{O}{C}{E}{D}{U}{R}{E} { count(); return(T_PROCEDURE); } {L}{O}{C}{A}{L}{V}{A}{R} { count(); return(T_LOCALVAR); } {G}{L}{O}{B}{A}{L}{V}{A}{R} { count(); return(T_GLOBALVAR); } {I}{N} { count(); return(T_IN); } {O}{U}{T} { count(); return(T_OUT); } {anum}"["{anum}"]""=""{"{anum}(","{anum})*"}" { count(); return(T_ID); } {anum}("["({anum})?"]")? { count(); return(T_ID); } /*[+-]?({integer}?"."{integer}|{integer}"."{integer}?) { count(); return(T_ID); }*/ /*{letter}{integer}"."?{integer}?{letter}? { count(); return(T_TYPE_ID); }*/ {anum}?"."{anum} { count(); return(T_ID); } . { fprintf(stderr, "Error: Unacceptable input character (0x%x).\n", yytext[0]); exit(1); } %% int column = 0; int yywrap() { return(1); } void count() { int i; for (i=0; yytext[i]!='\0'; i++) { if (yytext[i] == '\n') { column = 0; } else if (yytext[i] == '\t') { column += 8 - (column % 8); } else { column++; } } #ifdef DEBUG ECHO; #endif }