%{ #include "cpl.tab.h" #include #include #include extern int yylineno; void yyerror(const char *s); %} %option noyywrap DIGIT [0-9] ID [a-zA-Z][a-zA-Z0-9_]* WS [ \t]+ %% "if" { return IF; } "else" { return ELSE; } "while" { return WHILE; } "return" { return RETURN; } "print" { return PRINT; } "&&" { return AND; } "||" { return OR; } "!" { return NOT; } ">=" { return GE; } "<=" { return LE; } "==" { return EQ; } "!=" { return NE; } ">" { return '>'; } "<" { return '<'; } "+" { return '+'; } "-" { return '-'; } "*" { return '*'; } "/" { return '/'; } "%" { return '%'; } "(" { return '('; } ")" { return ')'; } ";" { return ';'; } "=" { return '='; } "{" { return '{'; } "}" { return '}'; } {DIGIT}+ { yylval.num = atoi(yytext); return NUMBER; } {ID} { yylval.str = strdup(yytext); return IDENTIFIER; } {WS} /* skip whitespace */ \n { yylineno++; } . { yyerror("Invalid character"); } %%