-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDocMCalc.txt
150 lines (126 loc) · 5.45 KB
/
DocMCalc.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
The Language MCalc
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 MCalc==
===Identifiers===
Identifiers //Ident// are unquoted strings beginning with a letter,
followed by any combination of letters, digits, and the characters ``_ '``
reserved words excluded.
===Literals===
String literals //String// have the form
``"``//x//``"``}, where //x// is any sequence of any characters
except ``"`` unless preceded by ``\``.
Integer literals //Integer// are nonempty sequences of digits.
Double-precision float literals //Double// have the structure
indicated by the regular expression ``digit+ '.' digit+ ('e' ('-')? digit+)?`` i.e.\
two sequences of digits separated by a decimal point, optionally
followed by an unsigned or negative exponent.
===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 MCalc are the following:
| ``bool`` | ``double`` | ``else`` | ``false``
| ``if`` | ``int`` | ``print`` | ``return``
| ``string`` | ``true`` | ``void`` | ``while``
The symbols used in MCalc are the following:
| ( | ) | ; | {
| } | = | , | ||
| && | == | != | <
| > | <= | >= | +
| - | * | / | ++
| -- | | |
===Comments===
Single-line comments begin with //.Multiple-line comments are enclosed with /* and */.
==The syntactic structure of MCalc==
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// | -> | //[Entity]//
| //Entity// | -> | //Stm//
| | **|** | //FunctionDeclare//
| | **|** | //Function//
| //FunctionDeclare// | -> | //Type// //Ident// ``(`` //[FuncDeclarg]// ``)`` ``;``
| //Function// | -> | //Type// //Ident// ``(`` //[FuncDefarg]// ``)`` ``{`` //[Stm]// ``}``
| //FuncDeclarg// | -> | //Type//
| | **|** | //Type// //Ident//
| | **|** | //Type// //Ident// ``=`` //Exp//
| //FuncDefarg// | -> | //Type// //Ident//
| | **|** | //Type// //Ident// ``=`` //Exp//
| //[FuncDeclarg]// | -> | **eps**
| | **|** | //FuncDeclarg//
| | **|** | //FuncDeclarg// ``,`` //[FuncDeclarg]//
| //[FuncDefarg]// | -> | **eps**
| | **|** | //FuncDefarg//
| | **|** | //FuncDefarg// ``,`` //[FuncDefarg]//
| //[Entity]// | -> | **eps**
| | **|** | //Entity// //[Entity]//
| //[Stm]// | -> | **eps**
| | **|** | //Stm// //[Stm]//
| //VarDecl// | -> | //Ident//
| | **|** | //Ident// ``=`` //Exp//
| //[VarDecl]// | -> | //VarDecl//
| | **|** | //VarDecl// ``,`` //[VarDecl]//
| //Stm// | -> | //Type// //[VarDecl]// ``;``
| | **|** | //Exp// ``;``
| | **|** | ``{`` //[Stm]// ``}``
| | **|** | ``if`` ``(`` //Exp// ``)`` //Stm//
| | **|** | ``if`` ``(`` //Exp// ``)`` //Stm// ``else`` //Stm//
| | **|** | ``while`` ``(`` //Exp// ``)`` //Stm//
| | **|** | ``return`` //Exp// ``;``
| | **|** | ``return`` ``;``
| | **|** | ``print`` //Exp// ``;``
| //Exp// | -> | //Ident// ``=`` //Exp2//
| | **|** | //Exp1//
| //Exp3// | -> | //Exp3// ``||`` //Exp3//
| | **|** | //Exp4//
| //Exp4// | -> | //Exp4// ``&&`` //Exp5//
| | **|** | //Exp5//
| //Exp8// | -> | //Exp8// ``==`` //Exp9//
| | **|** | //Exp8// ``!=`` //Exp9//
| | **|** | //Exp9//
| //Exp9// | -> | //Exp9// ``<`` //Exp10//
| | **|** | //Exp9// ``>`` //Exp10//
| | **|** | //Exp9// ``<=`` //Exp10//
| | **|** | //Exp9// ``>=`` //Exp10//
| | **|** | //Exp10//
| //Exp11// | -> | //Exp11// ``+`` //Exp12//
| | **|** | //Exp11// ``-`` //Exp12//
| | **|** | //Exp12//
| //Exp12// | -> | //Exp12// ``*`` //Exp12//
| | **|** | //Exp12// ``/`` //Exp12//
| | **|** | //Exp13//
| //Exp13// | -> | ``-`` //Exp13//
| | **|** | ``+`` //Exp13//
| | **|** | ``++`` //Ident//
| | **|** | ``--`` //Ident//
| | **|** | //Exp14//
| //Exp14// | -> | //Ident// ``++``
| | **|** | //Ident// ``--``
| | **|** | //Exp15//
| //Exp15// | -> | //Ident// ``(`` ``)``
| | **|** | //Ident// ``(`` //[Exp2]// ``)``
| | **|** | //Exp16//
| //Exp16// | -> | //Ident//
| | **|** | //Constant//
| | **|** | ``(`` //Exp// ``)``
| //[Exp2]// | -> | **eps**
| | **|** | //Exp2//
| | **|** | //Exp2// ``,`` //[Exp2]//
| //Constant// | -> | //String//
| | **|** | //Integer//
| | **|** | //Double//
| | **|** | ``false``
| | **|** | ``true``
| //Exp1// | -> | //Exp2//
| //Exp2// | -> | //Exp3//
| //Exp5// | -> | //Exp6//
| //Exp6// | -> | //Exp7//
| //Exp7// | -> | //Exp8//
| //Exp10// | -> | //Exp11//
| //Type// | -> | ``int``
| | **|** | ``bool``
| | **|** | ``double``
| | **|** | ``string``
| | **|** | ``void``