Lex Prog
Lex Prog
#include <stdio.h>
#include <stdlib.h>
#include "y.tab.h" // Include the header file generated by Yacc
%}
%%
/* Keywords */
"if" { return IF; }
"else" { return ELSE; }
"while" { return WHILE; }
"int" { return INT; }
"float" { return FLOAT; }
"return" { return RETURN; }
/* Operators */
"+" { return PLUS; }
"-" { return MINUS; }
"*" { return MUL; }
"/" { return DIV; }
"=" { return ASSIGN; }
"==" { return EQ; }
"<" { return LT; }
">" { return GT; }
"!=" { return NEQ; }
/* Parentheses */
"(" { return LPAREN; }
")" { return RPAREN; }
/* Braces */
"{" { return LBRACE; }
"}" { return RBRACE; }
/* Semicolon */
";" { return SEMICOLON; }
/* Comma */
"," { return COMMA; }
%%
int yywrap() {
return 1;
}
int main() {
yyparse(); // Call the parser
return 0;
}