-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.rkt
More file actions
18 lines (17 loc) · 977 Bytes
/
Copy pathparser.rkt
File metadata and controls
18 lines (17 loc) · 977 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#lang brag
; This is the grammar that defines the language.
; The / operator removes the following symbol from the parse tree.
; The @ operator removes the following rule from the parse tree and splices its children in its parent node.
; This grammar silently exports a parse function.
; As secd-instruction is preceded by an @ operator, the parser will never contain this node,
; therefore, our expander needs only provide bindings for the remaining rules.
secd-program: secd-instruction-list
secd-instruction-list: /"(" secd-instruction* /")"
@secd-instruction: /"(" (secd-int-const | secd-add | secd-sub | secd-fun | secd-apply | secd-if0) /")"
secd-int-const: /"INT_CONST" INTEGER
secd-add: /"ADD"
secd-sub: /"SUB"
secd-fun: /"FUN" secd-instruction* /"(" secd-return /")" ; Every function needs a return statement as its last instruction. This rule enforces that.
secd-return: /"RETURN"
secd-apply: /"APPLY"
secd-if0: /"IF0" secd-instruction-list secd-instruction-list