Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1) prog4 1.py will be implemented in Python. In prog4_1.py you will implement the following functions a. Tokenize(str): This function will take in an input
1) prog4 1.py will be implemented in Python. In prog4_1.py you will implement the following functions a. Tokenize(str): This function will take in an input string and tokenize it according to the same rules in assignment #2. You do not need to store the tokenized string, instead your function should return the list of tokens if is valid. Otherwise, it should raise a ValueError with the message "Unexpected Token: " as in Assignment #2 b. Parse(tokens): This function will take a list of tokens as input that have previously been parsed by the Tokenize function. This will validate the parse rules given during Assignment #2 and will raise a ValueError with the parse error message as appropriate prog4_2.py In python, Implement a StackMachine class. Your stack machine class should have the Execute(tokens) public function and the CurrentLine property (intial value zero). You may implement whatever internal data structures and functions are necessary such that your stack machine is easy for you to implement The Execute(tokens) function should accept a list of tokens that has previously been Tokenized and Parsed correctly. The Execute function will then perform the operation defined in the list of tokens as specified by the operation. (Not all operations will return a value, some will) . push #-Pushes the number onto the stack. Returns None e pop add . sub . mul Pops the top of the stack. Returns the popped value Pops two values off the stack, adds them pushes the result. Returns None Pops two, subtracts the second from the first, pushes result. Returns None Pops two, multiples, pushes result. Returns None Pops two, divides the first by the second, pushes result. Returns None iv 1) prog4 1.py will be implemented in Python. In prog4_1.py you will implement the following functions a. Tokenize(str): This function will take in an input string and tokenize it according to the same rules in assignment #2. You do not need to store the tokenized string, instead your function should return the list of tokens if is valid. Otherwise, it should raise a ValueError with the message "Unexpected Token: " as in Assignment #2 b. Parse(tokens): This function will take a list of tokens as input that have previously been parsed by the Tokenize function. This will validate the parse rules given during Assignment #2 and will raise a ValueError with the parse error message as appropriate prog4_2.py In python, Implement a StackMachine class. Your stack machine class should have the Execute(tokens) public function and the CurrentLine property (intial value zero). You may implement whatever internal data structures and functions are necessary such that your stack machine is easy for you to implement The Execute(tokens) function should accept a list of tokens that has previously been Tokenized and Parsed correctly. The Execute function will then perform the operation defined in the list of tokens as specified by the operation. (Not all operations will return a value, some will) . push #-Pushes the number onto the stack. Returns None e pop add . sub . mul Pops the top of the stack. Returns the popped value Pops two values off the stack, adds them pushes the result. Returns None Pops two, subtracts the second from the first, pushes result. Returns None Pops two, multiples, pushes result. Returns None Pops two, divides the first by the second, pushes result. Returns None iv
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