Wisdom Materials
Home
About Us
Our Clients
Careers
Services
Education
Jobs
News
Business
Health
Astrology
Entertainment
RealEstate
Devotion
Contact Us
Compiler Construction Lab Manual
/ LALR Using YACC Compiler
Program Name
Write a Compiler Construction Program for LALR Using YACC Compiler.
Theory
LALR Using YACC Compiler.
Program Code
Copy Program Code
//LALR.L %{ #include "y.tab.h" extern int yylval; %} %% [0-9]+ {yylval=atoi(yytext); return num;} \n return 0; . return yytext[0]; %% yywrap() { return 1; } //LALR.Y %{ #include
%} %token num; %% cmd:E {printf("%d\n",$1);} E:T'+'E {$$=$1+$3;} |T{$$=$1;} ; T:F'*'T{$$=$1*$3;} |F{$$=$1;} ; F:'('E')'{$$=$2;} |num{$$=$1;} ; %% main() { yyparse(); } yyerror(char *s) { printf("%s",s); }
Saving:
vi lalr.l
Compiling and Running
yacc -d lalr.y
lex.yy.c y.tab.c
./a.out
Input
2+3
2++
Output
5
Syntax Error
Home
Back