Sharecodepoint App Download Qrcode Sharecodepoint Android App Banner
Now You can search anything in sharecodepoint using your voice. Click on mic button. Sharecodepoint Youtube Channel

Hi All, Please give your feedback on google. Your Feedback is Important to Us Write Feedback





Sharecodepoint popular queries

Saturday, 23 February 2019

Program to test the validity of a simple expression involving operators +, -, * and / | Compiler Design Lab Programs | Yacc Programs


Yacc Part :

%token NUMBER ID NL
%left ‘+’ ‘-‘
%left ‘*’ ‘/’
%%
stmt : exp NL { printf(“Valid Expression”); exit(0);}
 ;
exp : exp ‘+’ exp
 | exp ‘-‘ exp
 | exp ‘*’ exp
 | exp ‘/’ exp
 | ‘(‘ exp ‘)’
 | ID
 | NUMBER
 ;
%%
int yyerror(char *msg)
{
 printf(“Invalid Expression\n”);
 exit(0);
}
main ()
{
 printf(“Enter the expression\n”);
 yyparse();

Lex Part :

%{
 #include “y.tab.h”
%}
%%
[0-9]+ { return DIGIT; }
[a-zA-Z][a-zA-Z0-9_]* { return ID; }
\n { return NL ;}
. { return yytext[0]; }
%%

0 comments:

Post a Comment

 

Version 23.2.3.4 - 2016 - 2019 - © Sharecodepoint | Made in India. | Copyright Content