-
Notifications
You must be signed in to change notification settings - Fork 1
/
DocXYZgrammar.txt
130 lines (108 loc) · 4.7 KB
/
DocXYZgrammar.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
The Language XYZgrammar
BNF Converter
%This txt2tags file is machine-generated by the BNF-converter
%Process by txt2tags to generate html or latex
This document was automatically generated by the //BNF-Converter//. It was generated together with the lexer, the parser, and the abstract syntax module, which guarantees that the document matches with the implementation of the language (provided no hand-hacking has taken place).
==The lexical structure of XYZgrammar==
===Identifiers===
Identifiers //Ident// are unquoted strings beginning with a letter,
followed by any combination of letters, digits, and the characters ``_ '``
reserved words excluded.
===Literals===
Integer literals //Integer// are nonempty sequences of digits.
String literals //String// have the form
``"``//x//``"``}, where //x// is any sequence of any characters
except ``"`` unless preceded by ``\``.
===Reserved words and symbols===
The set of reserved words is the set of terminals appearing in the grammar. Those reserved words that consist of non-letter characters are called symbols, and they are treated in a different way from those that are similar to identifiers. The lexer follows rules familiar from languages like Haskell, C, and Java, including longest match and spacing conventions.
The reserved words used in XYZgrammar are the following:
| ``Generator`` | ``bool`` | ``else`` | ``false``
| ``for`` | ``func`` | ``if`` | ``int``
| ``next`` | ``nextOrDefault`` | ``print`` | ``println``
| ``return`` | ``string`` | ``true`` | ``void``
| ``while`` | ``yield`` | |
The symbols used in XYZgrammar are the following:
| { | } | ; | =
| , | ( | ) | :
| & | func* | . | <
| > | - | ! | &&
| || | + | * | /
| % | <= | >= | ==
| != | | |
===Comments===
Single-line comments begin with //.Multiple-line comments are enclosed with /* and */.
==The syntactic structure of XYZgrammar==
Non-terminals are enclosed between < and >.
The symbols -> (production), **|** (union)
and **eps** (empty rule) belong to the BNF notation.
All other symbols are terminals.
| //Program// | -> | //[Stmt]//
| //Block// | -> | ``{`` //[Stmt]// ``}``
| //[Stmt]// | -> | **eps**
| | **|** | //Stmt// //[Stmt]//
| //Stmt// | -> | ``;``
| | **|** | //Block//
| | **|** | //Type// //[Item]// ``;``
| | **|** | //Ident// ``=`` //Expr// ``;``
| | **|** | ``return`` //Expr// ``;``
| | **|** | ``return`` ``;``
| | **|** | ``if`` ``(`` //Expr// ``)`` //Block//
| | **|** | ``if`` ``(`` //Expr// ``)`` //Block// ``else`` //Block//
| | **|** | ``while`` ``(`` //Expr// ``)`` //Block//
| | **|** | ``for`` ``(`` //Type// //Ident// ``:`` //Expr// ``)`` //Block//
| | **|** | //Expr// ``;``
| | **|** | ``func`` //Type// //Ident// ``(`` //[Arg]// ``)`` //Block//
| | **|** | ``func*`` //Type// //Ident// ``(`` //[Arg]// ``)`` //Block//
| | **|** | ``yield`` //Expr// ``;``
| | **|** | ``print`` ``(`` //Expr// ``)`` ``;``
| | **|** | ``println`` ``(`` //Expr// ``)`` ``;``
| //Item// | -> | //Ident//
| | **|** | //Ident// ``=`` //Expr//
| //[Item]// | -> | //Item//
| | **|** | //Item// ``,`` //[Item]//
| //Arg// | -> | //Type// //Ident//
| | **|** | //Type// ``&`` //Ident//
| //[Arg]// | -> | **eps**
| | **|** | //Arg//
| | **|** | //Arg// ``,`` //[Arg]//
| //Expr6// | -> | //Ident// ``.`` ``next`` ``(`` ``)``
| | **|** | //Ident// ``.`` ``nextOrDefault`` ``(`` //Expr// ``)``
| | **|** | //Ident//
| | **|** | //Integer//
| | **|** | ``true``
| | **|** | ``false``
| | **|** | //Ident// ``(`` //[Expr]// ``)``
| | **|** | //String//
| | **|** | ``(`` //Expr// ``)``
| //Type// | -> | ``int``
| | **|** | ``string``
| | **|** | ``bool``
| | **|** | ``void``
| | **|** | ``Generator`` ``<`` //Type// ``>``
| //Expr5// | -> | ``-`` //Expr6//
| | **|** | ``!`` //Expr6//
| | **|** | //Expr6//
| //Expr4// | -> | //Expr4// //MulOp// //Expr5//
| | **|** | //Expr5//
| //Expr3// | -> | //Expr3// //AddOp// //Expr4//
| | **|** | //Expr4//
| //Expr2// | -> | //Expr2// //RelOp// //Expr3//
| | **|** | //Expr3//
| //Expr1// | -> | //Expr2// ``&&`` //Expr1//
| | **|** | //Expr2//
| //Expr// | -> | //Expr1// ``||`` //Expr//
| | **|** | //Expr1//
| //[Expr]// | -> | **eps**
| | **|** | //Expr//
| | **|** | //Expr// ``,`` //[Expr]//
| //AddOp// | -> | ``+``
| | **|** | ``-``
| //MulOp// | -> | ``*``
| | **|** | ``/``
| | **|** | ``%``
| //RelOp// | -> | ``<``
| | **|** | ``<=``
| | **|** | ``>``
| | **|** | ``>=``
| | **|** | ``==``
| | **|** | ``!=``