Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a lexical analyzer in Python that accepts the following language and generates a report: Tokens SEMICOLON PRINT ID PLUS MINUS TIMES DIV POWER ASSIGN
Write a lexical analyzer in Python that accepts the following language and generates a report:
Tokens |
SEMICOLON |
ID |
PLUS |
MINUS |
TIMES |
DIV |
POWER |
ASSIGN |
INT_CONST |
REAL_CONST |
STRING |
LPAREN |
RPAREN |
QUOTE |
A Sample program:
a% = 5.5; b# = 3; c% = a% + b#; PRINT "the result is"; PRINT c%; |
Sample Report:
ID a REAL ASSIGN REAL_CONST 5.5 SEMICOLON ID b INTEGER ASSIGN INT_CONST 3 SEMICOLON ID c REAL ASSIGN ID a REAL PLUS ID b INTEGER SEMICOLON PRINT STRING the result is SEMICOLON PRINT ID c REAL SEMICOLON |
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