Question: 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
Get step-by-step solutions from verified subject matter experts
