-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDocmyjs.txt
149 lines (128 loc) · 5.45 KB
/
Docmyjs.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
The Language myjs
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 myjs==
===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.
===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 myjs are the following:
| ``catch`` | ``else`` | ``false`` | ``function``
| ``if`` | ``return`` | ``throw`` | ``true``
| ``try`` | ``undefined`` | ``var`` | ``while``
The symbols used in myjs are the following:
| ; | = | { | }
| . | [ | ] | (
| ) | , | : | ||
| && | === | !== | <
| > | <= | >= | +
| - | * | / | ++
| -- | ! | return; |
===Comments===
Single-line comments begin with //.Multiple-line comments are enclosed with /* and */.
==The syntactic structure of myjs==
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]//
| //[Stmt]// | -> | **eps**
| | **|** | //Stmt//
| | **|** | //Stmt// //[Stmt]//
| //MaybeIdent// | -> | **eps**
| | **|** | //Ident//
| //Decl// | -> | ``var`` //Ident// ``;``
| | **|** | ``var`` //Ident// ``=`` //Expr// ``;``
| | **|** | //FunExpr//
| //CompoundStmt// | -> | ``{`` //[Stmt]// ``}``
| //Stmt// | -> | //CompoundStmt//
| | **|** | //Expr// ``;``
| | **|** | //Decl//
| | **|** | ``;``
| | **|** | ``if`` ``(`` //Expr// ``)`` //Stmt// //ElseClause//
| | **|** | ``while`` ``(`` //Expr// ``)`` //Stmt//
| | **|** | ``throw`` //Expr//
| | **|** | ``try`` //CompoundStmt// ``catch`` ``(`` //Ident// ``)`` //CompoundStmt//
| | **|** | ``return`` //Expr// ``;``
| | **|** | ``return;``
| //Lvalue// | -> | //[QIdentPart]//
| //QIdentPart// | -> | //IIdent//
| //[QIdentPart]// | -> | //QIdentPart//
| | **|** | //QIdentPart// ``.`` //[QIdentPart]//
| //IIdent// | -> | //Ident//
| | **|** | //Ident// ``[`` //Expr// ``]``
| //ParamNames// | -> | ``(`` //[Ident]// ``)``
| //[Ident]// | -> | **eps**
| | **|** | //Ident//
| | **|** | //Ident// ``,`` //[Ident]//
| //Params// | -> | ``(`` //[Param]// ``)``
| //Param// | -> | //Expr//
| //[Param]// | -> | **eps**
| | **|** | //Param//
| | **|** | //Param// ``,`` //[Param]//
| //KeyValuePair// | -> | //Key// ``:`` //Expr//
| //Key// | -> | //Ident//
| | **|** | //String//
| //[KeyValuePair]// | -> | **eps**
| | **|** | //KeyValuePair//
| | **|** | //KeyValuePair// ``,`` //[KeyValuePair]//
| //Literal// | -> | //Integer//
| | **|** | //String//
| | **|** | ``true``
| | **|** | ``false``
| | **|** | ``undefined``
| | **|** | ``{`` //[KeyValuePair]// ``}``
| | **|** | ``[`` //[Param]// ``]``
| //FunExpr// | -> | ``function`` //MaybeIdent// //ParamNames// //CompoundStmt//
| //Expr// | -> | //FunExpr//
| | **|** | //Lvalue// ``=`` //Expr//
| | **|** | //Expr1//
| //Expr2// | -> | //Expr2// ``||`` //Expr3//
| | **|** | //Expr3//
| //Expr3// | -> | //Expr3// ``&&`` //Expr4//
| | **|** | //Expr4//
| //Expr4// | -> | //Expr4// ``===`` //Expr5//
| | **|** | //Expr4// ``!==`` //Expr5//
| | **|** | //Expr5//
| //Expr5// | -> | //Expr5// ``<`` //Expr6//
| | **|** | //Expr5// ``>`` //Expr6//
| | **|** | //Expr5// ``<=`` //Expr6//
| | **|** | //Expr5// ``>=`` //Expr6//
| | **|** | //Expr6//
| //Expr6// | -> | //Expr6// ``+`` //Expr7//
| | **|** | //Expr6// ``-`` //Expr7//
| | **|** | //Expr6// ``*`` //Expr7//
| | **|** | //Expr6// ``/`` //Expr7//
| | **|** | //Expr7//
| //Expr7// | -> | ``++`` //Lvalue//
| | **|** | ``--`` //Lvalue//
| | **|** | //Expr8//
| //Expr8// | -> | //UnaryOp// //Expr9//
| | **|** | //Expr9//
| //Expr9// | -> | ``(`` //Expr// ``)``
| | **|** | //Expr10//
| //Expr10// | -> | //Lvalue// //Params//
| | **|** | //Expr11//
| //Expr11// | -> | //Literal//
| | **|** | //Expr12//
| //Expr12// | -> | //Lvalue//
| | **|** | //Expr13//
| //UnaryOp// | -> | ``!``
| //ElseClause// | -> | ``else`` //Stmt//
| | **|** | **eps**
| //Expr1// | -> | //Expr2//
| //Expr13// | -> | //Expr14//
| //Expr14// | -> | //Expr15//
| //Expr15// | -> | //Expr16//
| //Expr16// | -> | //Expr17//
| //Expr17// | -> | //Expr18//
| //Expr18// | -> | ``(`` //Expr// ``)``