Sunday, 16 June 2019

Create Yacc and Lex specification files to recognizes arithmetic expressions involving+,-,* and /.



Code:
%{
#include<stdio.h>
%}
%token ID NUMBER
%left '+' '-'
%left '*' '/'
%%
stmt:expr;
expr: expr '+' expr { $$ = $1 + $3; } | expr '-' expr| expr '*' expr | expr '/' expr | '(' expr
‘)' | NUMBER | ID;
%%
void main()
{
printf("enter expr : \n");
yyparse();
printf("valid exp");
exit(0);
}
void yyerror()
{
printf("invalid exp");
exit(0);
}

No comments:

Post a Comment

It's time To increase blogging capability. To have a chance to contribute in digital world. Any Interested People who want to make t...