Question
Write a program in Python that takes a program written in Mini-Power, and outputs the tokens and lexemes into a new file. Mini Power: ->
Write a program in Python that takes a program written in "Mini-Power", and outputs the tokens and lexemes into a new file.
Mini Power:
The program should run like this: prompt> python lexer.py input.txt Processing input file input.txt 14 tokens produced Result in file input.out prompt>
The tokens in the grammar are: -SEMICOLON -PRINT -ID -PLUS -MINUS -TIMES -DIV -POWER -ASSIGN -INT_CONST -REAL_CONST -STRING -LPAREN -RPAREN -QUOTE
Example input and outpt: Input: a% = 5.5 ; b# = 3 ; c% = a% + b# ; PRINT "the result is " ; PRINT c%
Ouput: ID a REAL ASSIGN REAL_CONST 5.5 SEMICOLON ID b INTEGER ASSIGN INT_CONST 3 SEMICOLON ID c REAL PLUS ID b INTEGER SEMICOLON PRINT STRING the result is SEMICOLON PRINT ID c REAL
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