Starting from:

$24.99

CSCI312 Homework 1-Working with Python Parse Trees Solution

CSCI 312 Homework 1
File names: Names of files and variables, when specified, must be EXACTLY as specified. This includes simple mistakes such as capitalization.
Project: Use the Python AST module to make four programs that handle arithmetic expressions, as follows:
>>> postfix(’2 + (3 * 4) ** 5’)
’2 3 4 * 5 ** +’
>>> infix(’2 + (3 * 4) ** 5’)
’(2+((3*4)**5))’
>>> prefix(’2 + (3 * 4) ** 5’)
’+ 2 ** * 3 4 5’
>>> calc(’2 + (3 * 4) ** 5’)
248834
1
2
3
4
5
6
7
8
The infix should be fully parenthesized, so spaces are not needed. The prefix and postfix will have exactly one space between tokens and nothing else.
Also finish the unittest module provided on the website with a more complete set of tests.
Hand in: Two files, ast_homework.py and test_ast_homework.py.
Follow best practices for docstrings, for example, as found here: https://coderslegacy. com/python/best-practices-for-docstrings/
1

More products