Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab 0 7 _ A ( VPL ) : Write a Java program to process and display the following stages of compiler: Stage 1 :

Lab07_A(VPL): Write a Java program to process and display the following stages of compiler:
Stage 1: Lexical analysis (Scanning)
Stage 2: Syntax Analysis (Parsing)
Stage 3: Semantic Analysis
Stage 4: Intermediate Code Representation (ICR)
VPL elearning lab to be done by all students: Students are to write Java codes for stages 1,2,3 and 4 of the compiler and submit on VPL/elearning for automatic grading.
Sample output:
A MINI COMPILER PROJECT FOR CTE711S
===================================
ENTER NEXT STRING === #1
-Every String/line must end with a semicolon (;)
-Enter String (Containing 0 to 9 and/or operators: +,/,*,-)
-Enter No Space in b/w chara & end the string with semicolon(;)ie 5-4+9*8/2; for Full(7 stages) results of compilation
-or Enter Space in b/w char with semicolon(;) at end of String ie 5-4+9*8/2 ; for the result of arithmetic expression
-Or Type 99 and press Enter to Quit:
7/3-9+6*2;
======STAGE1: COMPILER TECHNIQUES--> LEXICAL ANALYSIS-Scanner
SYMBOL TABLE COMPRISING ATTRIBUTES AND TOKENS:
TOKEN#17 identifier
TOKEN#2/ Operator
TOKEN#33 identifier
TOKEN#4- Operator
TOKEN#59 identifier
TOKEN#6+ Operator
TOKEN#76 identifier
TOKEN#8* Operator
TOKEN#92 identifier
TOKEN#10 ; symbol
Total number of Tokens: 10
GIVEN THE GRAMMAR: E=E1| E=E1*E2| E=E1+E2| E=digit | E={0,1,2,3,4,5,6,7,8,9}
======STAGE2: COMPILER TECHNIQUES--> SYNTAX ANALYSIS-Parser
GET A DERIVATION FOR : 7/3-9+6*2 ;
E7/ E3- E9+ E6* E2 ;
E7/ E3- E9+ E6* digit2 ;
E7/ digit3- E9+ E6* digit2 ;
E7/ digit3- E9+ digit6* digit2 ;
digit7/ digit3- E9+ digit6* digit2 ;
digit7/ digit3- digit9+ digit6* digit2 ;
digit7/ digit3- digit9+ digit6*2 ;
digit7/3- digit9+ digit6*2 ;
digit7/3- digit9+6*2 ;
7/3- digit9+6*2 ;
7/3-9+6*2 ;
======STAGE3: COMPILER TECHNIQUES--> SEMANTIC ANALYSIS
CONCLUSION-->This expression: 7/3-9+6*2 ; is Syntactically and Semantically correct
======STAGE4: COMPILER TECHNIQUES--> INTERMEDIATE CODE REPRESENTATION (ICR)
THE STRING ENTERED IS : 7/3-9+6*2
The ICR is as follows:
t1=7/3
t2=6*2
t3=9+t2
t4= t1-t3
CONCLUSION-->The expression was correctly generated in ICR

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Horse Betting The Road To Absolute Horse Racing 2

Authors: NAKAGAWA,YUKIO

1st Edition

B0CFZN219G, 979-8856410593

More Books

Students also viewed these Databases questions