Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a Java program to process and display the following stages of compiler: Stage 1 : Lexical analysis ( Scanning ) Stage 2 : Syntax
Write a Java program to process and display the following stages of compiler:
Stage : Lexical analysis Scanning
Stage : Syntax Analysis Parsing
Stage : Semantic Analysis
Stage : Intermediate Code Representation ICR
Stage : Code Generation CG
Stage : Code Optimization CO
Stage : Target Machine Code TMC in Binary
VPL elearning lab to be done by all students: Students are to write Java codes for stages and of the compiler and submit on VPLelearning for automatic grading.
Sample output:
A MINI COMPILER PROJECT FOR CTES
ENTER NEXT STRING #
Every Stringline must end with a semicolon ;
Enter String Containing to andor operators:
Enter No Space in bw chara & end the string with semicolon;ie ; for Full stages results of compilation
or Enter Space in bw char with semicolon; at end of String ie ; for the result of arithmetic expression
Or Type and press Enter to Quit:
;
STAGE: COMPILER TECHNIQUES LEXICAL ANALYSISScanner
SYMBOL TABLE COMPRISING ATTRIBUTES AND TOKENS:
TOKEN# identifier
TOKEN# Operator
TOKEN# identifier
TOKEN# Operator
TOKEN# identifier
TOKEN# Operator
TOKEN# identifier
TOKEN# Operator
TOKEN# identifier
TOKEN# ; symbol
Total number of Tokens:
GIVEN THE GRAMMAR: EE EEE EEE Edigit E
STAGE: COMPILER TECHNIQUES SYNTAX ANALYSISParser
GET A DERIVATION FOR : ;
E E E E E ;
E E E E digit ;
E digit E E digit ;
E digit E digit digit ;
digit digit E digit digit ;
digit digit digit digit digit ;
digit digit digit digit ;
digit digit digit ;
digit digit ;
digit ;
;
STAGE: COMPILER TECHNIQUES SEMANTIC ANALYSIS
CONCLUSIONThis expression: ; is Syntactically and Semantically correct
STAGE: COMPILER TECHNIQUES INTERMEDIATE CODE REPRESENTATION ICR
THE STRING ENTERED IS :
The ICR is as follows:
t
t
tt
t tt
CONCLUSIONThe expression was correctly generated in ICR
STAGE: CODE GENERATION CG
LDA
DIV
STR t
LDA
MUL t
STR t
LDA
ADD t
STR t
LDA
SUB t
STR t
STAGE: CODE OPTIMISATION CO
DIV t
MUL t t
ADD t t
SUB t t
STAGE: TARGET MACHINE CODE TMC
END OF COMPILATION
THE ORIGINAL INPUT STRING IS: ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started