From 6e80be9599af0d70ac51637a871c0d1d076eb745 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sat, 7 May 2016 17:50:27 +0200 Subject: 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 --- grammar.txt | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 grammar.txt (limited to 'grammar.txt') 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 -- cgit v1.2.1