summaryrefslogtreecommitdiff
path: root/grammar.txt
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2016-05-07 17:50:27 +0200
committerPeter Wu <peter@lekensteyn.nl>2016-05-07 18:11:09 +0200
commit6e80be9599af0d70ac51637a871c0d1d076eb745 (patch)
tree1bad59e6a82e61e73beba9b00d5b536204773767 /grammar.txt
parent1b115a3a0d318e4a0270f7be2a39db6f38f9d7f4 (diff)
downloadRegexTest-6e80be9599af0d70ac51637a871c0d1d076eb745.tar.gz
Add original grammer for part 4
This grammar looks like SDF[0]. Explanation of some constructs: - "start-symbol" refers to the start symbol (a non-terminal). - Lines below "context-free syntax" refers to the non-terminals. - Lines below "lexical syntax" refers to the terminals. - "context-free priorities" provides disambiguation constructs. Note that the "EXP ::= " part really belongs to each individual operand, so it means something like "A > B > C" (where A, B, C are the unary minus, multiplication and plus expressions respectively). I have no idea why Mark van den Brand chose to use multiple "context-free syntax" and "lexical syntax" groups (if that is appropriate terminology), as far as I can see all such blocks can be merged into one group. Maybe he wanted to emphasize the difference between the left-hand side names? [0]: http://releases.strategoxt.org/strategoxt-manual/unstable/manual/chunk-chapter/tutorial-sdf.html
Diffstat (limited to 'grammar.txt')
-rw-r--r--grammar.txt30
1 files changed, 30 insertions, 0 deletions
diff --git a/grammar.txt b/grammar.txt
new file mode 100644
index 0000000..0a7a66e
--- /dev/null
+++ b/grammar.txt
@@ -0,0 +1,30 @@
+start-symbol PROGRAM
+
+context-free syntax
+ PROGRAM ::= "begin" DECLS "|" (STATEMENT ";")* "end"
+ DECLS ::= "declare" (ID ",")*
+
+context-free syntax
+ STATEMENT ::= ID ":=" EXP
+
+context-free syntax
+ EXP ::= ID
+ EXP ::= NAT
+ EXP ::= EXP "+" EXP {left}
+ EXP ::= EXP "*" EXP {left}
+ EXP ::= "-" EXP
+ EXP ::= "(" EXP ")"
+
+lexical syntax
+ ID ::= [a-z][a-z0-9]*
+
+lexical syntax
+ NAT ::= [0] | [1-9][0-9]*
+
+lexical syntax
+ LAYOUT ::= [\ \n]*
+
+context-free priorities
+ EXP ::= "-" EXP >
+ EXP ::= "*" EXP >
+ EXP ::= "+" EXP