合肥生活安徽新闻合肥交通合肥房产生活服务合肥教育合肥招聘合肥旅游文化艺术合肥美食合肥地图合肥社保合肥医院企业服务合肥法律

CMSC 323代做、代写Java, Python编程

时间:2024-02-25  来源:合肥网hfw.cc  作者:hfw.cc 我要纠错



CMSC 323: Design and Implementation of Programming Languages
Exercise 3: Parsing in Python
Due Date: 02-22-24
Total Points: 100
Users of programming languages find it tedious and difficult to write programs using ASTs, so we use
simpler, more user-friendly notation to write our programs (The Java, Python, etc syntax programmers
interact with). We will call this our input or surface syntax. Converting the input syntax into ASTs (abstract
syntax trees) is called parsing.
For example, consider the following surface syntax and corresponding trees in Python.
Surface Snytax:
(/(* 8 (+ 2 (* 1 3))) 5)
Corresponding AST:
ast5 = Node("/")
ast5.left_child = Node("*")
ast5.left_child.left_child = Node(8)
ast5.left_child.right_child = Node("+")
ast5.left_child.right_child.left_child = Node(2)
ast5.left_child.right_child.right_child = Node("*")
ast5.left_child.right_child.right_child.left_child = Node(1)
ast5.left_child.right_child.right_child.right_child = Node(3)
ast5.right_child = Node(5);
It is obvious that the surface syntax is a much easier notation for a human to interact with.
For this exercise, we choose a simple pre-order notation which allows us not to worry about the
precedence of operations in our expressions as it is implicit in the notation.
You have been provided a Node (same as in Exercise 1) and a Parser class. Complete the method
parse in the Parse class. It should take the surface syntax in the example above (i.e. simple preorder
arithmetic expressions with parentheses) as input and build the corresponding syntax tree. Your
interpret method from Exercise 1 should be able to interpret the output of parse correctly.
Note that our surface syntax expects parentheses, spaces, numbers, and arithmetic operations (*, +, -, /)
only. Your trees will not be tested with any other characters.
Example surface syntaxes and corresponding trees:
请加QQ:99515681  邮箱:99515681@qq.com   WX:codehelp 

扫一扫在手机打开当前页
  • 上一篇:代写CSC8636 – Summative Assessment
  • 下一篇:self-signed certificate.代做、代写Java/c++设计编程
  • 无相关信息
    合肥生活资讯

    合肥图文信息
    新能源捕鱼一体电鱼竿好用吗
    新能源捕鱼一体电鱼竿好用吗
    海信罗马假日洗衣机亮相AWE  复古美学与现代科技完美结合
    海信罗马假日洗衣机亮相AWE 复古美学与现代
    合肥机场巴士4号线
    合肥机场巴士4号线
    合肥机场巴士3号线
    合肥机场巴士3号线
    合肥机场巴士2号线
    合肥机场巴士2号线
    合肥机场巴士1号线
    合肥机场巴士1号线
    合肥轨道交通线路图
    合肥轨道交通线路图
    合肥地铁5号线 运营时刻表
    合肥地铁5号线 运营时刻表
  • 币安app官网下载

    关于我们 | 打赏支持 | 广告服务 | 联系我们 | 网站地图 | 免责声明 | 帮助中心 | 友情链接 |

    Copyright © 2024 hfw.cc Inc. All Rights Reserved. 合肥网 版权所有
    ICP备06013414号-3 公安备 42010502001045