Wisdom Materials
Home
About Us
Our Clients
Careers
Services
Education
Jobs
News
Business
Health
Astrology
Entertainment
RealEstate
Devotion
Contact Us
Compiler Construction Lab Manual
/ Statement Code Generation using Lex Program
Program Name
Write a Compiler Construction Program for Statement Code Generation using Lex Program.
Theory
Statement Code Generation using Lex program sections.
Program Code
Copy Program Code
#include
main() { char stmt[10]; printf("enter the c stmt\n"); gets(stmt); switch(stmt[3]) { case '+': printf("\n LOAD %c,R1",stmt[2]); printf("\n ADD %c,R1",stmt[4]); printf("\n STORE R1,%c\n",stmt[0]);break; case '-': printf("\n LOAD %c,R1",stmt[2]); printf("\n SUB %c,R1",stmt[4]); printf("\n STORE R1,%c\n",stmt[0]);break; case '*': printf("\n LOAD %c,R1",stmt[2]); printf("\n MUL %c,R1",stmt[4]); printf("\nSTORE R1,%c\n",stmt[0]);break; case '/': printf("\n LOAD %c,R1",stmt[2]); printf("\n DIV %c,R1",stmt[4]); printf("\n STORE R1,%c\n",stmt[0]);break; } }
Saving:
vi codegen.l
Compiling and Running
cc codegen.c
./a.out
Input
enter the c stmt a=b+c
Output
LOAD b,R1
ADD c,R1
STORE R1,a
Home
Back