[SOLVED] COMP340 Homework 6-Parser

35.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon comp-340-HW6-taderj.zip (366.2 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
🔒 Securely Powered by:
Secure Checkout
5/5 - (1 vote)

 

Homework Description

In this homework, you need to complete parserr.py (and modify other files if necessary) so that our parser builds a tree from the below three cases.

  1. Grouped Expression (ex. 1 * (2 + 5))
  2. Single Number Expression (ex. 25)
  3. Expression with Negative Sign (ex. -25 * 3)

Homework Guideline

To get information about how to implement the above cases in a parser, look at ‘HW6_resources.pptx’ on Blackboard.

Test Cases

This section provides several test cases to check whether you wrote a parser correctly. In the main.py, you will change srcCode with the below test cases and see whether your output results are matched with the ones given in the table.

COMP 340 – HW 6 Due date: 04/29/2021 11:59 pm Total Points: 20 pts

import lexer
import parserr

srcCode = “1 * (2 + 5)”
tokSeq = lexer.tokenize(srcCode) rootNode = parserr.parse(tokSeq) parserr.printTree(rootNode)

print()

main.py

Test Case (srcCode) 1 * ( 2+ 5 )
(1 + 2) * 5 + 4
23 * ((1 + 5) * 33)

24 125

Output Result

(1 * ( 2 + 5 ))
(((1 + 2) * 5) + 4) (23 * ((1 + 5) * 33)) 24
125

Page 1 of 2

-5
– -5
– (-5)

 

  • comp-340-HW6-taderj.zip