Vous êtes sur la page 1sur 1

%{

#include<stdio.h>
#include<stdlib.h>
int yylex();
int yyerror();
%}
%token NUMBER ALPHA
%left '+' '-'
%left '*' '/'
%%
grammar:expr '\n' {printf("arithmetic exp is valid");exit(0);}
;
expr:expr'+'expr
|expr'-'expr
|expr'*'expr
|expr'/'expr
|'('expr')'
|NUMBER
|ALPHA
;
%%
int main()
{
printf("enter arithmetic expr\n");
yyparse();
return 0;
}
yyerror()
{
printf("arithmetic expression is invalid");
exit (0);
}

Vous aimerez peut-être aussi