220187
220187
220187
220187
%{
#include "y.tab.h"
%}
%%
%%
int yywrap() {
return 1;
}
```
%{
#include <stdio.h>
#include <stdlib.h>
int yylex();
void yyerror(char *s);
typedef struct {
char *name;
int ival;
float fval;
} Symbol;
Symbol symtab[100];
int symcount = 0;
%}
%union {
int ival;
float fval;
char *string;
}
%%
program:
statement program
| /* empty */
;
statement:
IDENTIFIER ASSIGN expression SEMICOLON { /* handle variable assignment */ }
| IF condition THEN statement ELSE statement SEMICOLON { /* handle if-statement */ }
| /* empty */
;
expression:
expression PLUS expression { /* handle addition */ }
| expression MINUS expression { /* handle subtraction */ }
| expression MULT expression { /* handle multiplication */ }
| expression DIV expression { /* handle division */ }
| LPAREN expression RPAREN
| IDENTIFIER { /* handle variable access */ }
| INTEGER { /* handle integer literal */ }
| FLOAT { /* handle float literal */ }
;
condition:
expression { /* return 1 if expression is true, 0 if false */ }
;
%%
int main() {
yyparse();
return 0;
}