首页 > > 详细

ASTs留学生辅导、讲解Java,c++编程设计、Python语言辅导、programs讲解辅导Python编程|解析Haskell程序

Assessed Exercise 2, Task 1
Implement the part of the language in black. No need to implement code generation for the red
parts. No test for this task will feature programs containing language constructs in red. Your code
generator can throw CodegenException for the ASTs that correspond to language constructs in
red, or you can return RISC-V code, it does not matter.
PROG → DEC | DEC; PROG
DEC → def ID (VARDEC) = E
VARDEC → ε | VARDECNE
VARDECNE → ID | VARDECNE, ID
ID → ... (identifiers)
INT → ... (Integers)
E → INT
| ID
| if E COMP E then E else E endif
| (E BINOP E)
| (E)
| ID(ARGS)
| skip
| (E; E)
| while E COMP E do E endwhile
| repeat E until E COMP E endrepeat
| ID := E
| break
| continue
ARGS → ε | ARGSNE
ARGSNE → E | ARGSNE, E
COMP → == | < | > | <= | >=
BINOP → + | - | * | /
Recall that the relevant definitions are here, here and here (and in the Zip file / Github given on the
parent page). If you don't want to implement a feature, simply throw CodegenException when
the code generator encounters this feature.
Note that the translation of procedure invocation (given by the production E → ID(ARGS) in the
grammar above) is part of Task 1. Since every program will have at least one procedure invocation,
I strongly suggest that you focus on getting this right.

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!