Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

-> { ; }

-> ( | )

-> PRINT ( | )

-> = ( | )

-> {( | )}( $ | # | %)

-> (+ | - ) |

-> (* | / ) |

-> ^ | ( ) | |

-> |

-> |

-> [( + | - )] {}

-> [( + | - )] {} . {}

-> ? {( | | )} ?

-> ( 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9)

-> ( a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z )

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

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

Automating Access Databases With Macros

Authors: Fish Davis

1st Edition

1797816349, 978-1797816340

More Books

Students also viewed these Databases questions

Question

Mobilize your audiences into action through social media messages.

Answered: 1 week ago