parser-lr 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -1
- package/bin/parser-lr.js +369 -9068
- package/bin/parser-lr.js.map +1 -1
- package/dist/lib/grammar/grammar-json-path.d.ts +2 -0
- package/dist/lib/grammar/grammar-json-path.d.ts.map +1 -0
- package/dist/lib/grammar/grammar-json-path.esm.d.ts +5 -0
- package/dist/lib/grammar/grammar-json-path.esm.d.ts.map +1 -0
- package/dist/lib/grammar/grammar-json-path.esm.js +9 -0
- package/dist/lib/grammar/grammar-json-path.esm.js.map +1 -0
- package/dist/lib/grammar/grammar-json-path.js +2 -0
- package/dist/lib/grammar/grammar-json-path.js.map +1 -0
- package/dist/lib/grammar/grammar.json +1218 -4476
- package/dist/lib/grammar/index.d.ts +2 -0
- package/dist/lib/grammar/index.d.ts.map +1 -1
- package/dist/lib/grammar/index.js +1 -0
- package/dist/lib/grammar/index.js.map +1 -1
- package/dist/lib/grammar/meta-grammar-table.d.ts.map +1 -1
- package/dist/lib/grammar/meta-grammar-table.js +4 -2
- package/dist/lib/grammar/meta-grammar-table.js.map +1 -1
- package/dist/lib/grammar/table-validator.d.ts +26 -0
- package/dist/lib/grammar/table-validator.d.ts.map +1 -0
- package/dist/lib/grammar/table-validator.js +211 -0
- package/dist/lib/grammar/table-validator.js.map +1 -0
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +1 -0
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/transform/cst-transformer.d.ts +14 -0
- package/dist/lib/transform/cst-transformer.d.ts.map +1 -1
- package/dist/lib/transform/cst-transformer.js +82 -11
- package/dist/lib/transform/cst-transformer.js.map +1 -1
- package/dist/lib/transform/grammar-fixture.d.ts +56 -0
- package/dist/lib/transform/grammar-fixture.d.ts.map +1 -0
- package/dist/lib/transform/grammar-fixture.js +101 -0
- package/dist/lib/transform/grammar-fixture.js.map +1 -0
- package/dist/lib-cjs/ast/ast-node.js +70 -0
- package/dist/lib-cjs/ast/ast-node.js.map +1 -0
- package/dist/lib-cjs/errors/index.js +9 -0
- package/dist/lib-cjs/errors/index.js.map +1 -0
- package/dist/lib-cjs/errors/parser-lr-error.js +52 -0
- package/dist/lib-cjs/errors/parser-lr-error.js.map +1 -0
- package/dist/lib-cjs/grammar/ast-schema.js +43 -0
- package/dist/lib-cjs/grammar/ast-schema.js.map +1 -0
- package/dist/lib-cjs/grammar/ast-type.js +3 -0
- package/dist/lib-cjs/grammar/ast-type.js.map +1 -0
- package/dist/lib-cjs/grammar/expression.js +3 -0
- package/dist/lib-cjs/grammar/expression.js.map +1 -0
- package/dist/lib-cjs/grammar/grammar-from-cst.js +641 -0
- package/dist/lib-cjs/grammar/grammar-from-cst.js.map +1 -0
- package/dist/lib-cjs/grammar/grammar-json-path.js +13 -0
- package/dist/lib-cjs/grammar/grammar-json-path.js.map +1 -0
- package/dist/lib-cjs/grammar/grammar-literals.js +71 -0
- package/dist/lib-cjs/grammar/grammar-literals.js.map +1 -0
- package/dist/lib-cjs/grammar/grammar.js +64 -0
- package/dist/lib-cjs/grammar/grammar.js.map +1 -0
- package/dist/lib-cjs/grammar/grammar.json +5760 -0
- package/dist/lib-cjs/grammar/index.js +19 -0
- package/dist/lib-cjs/grammar/index.js.map +1 -0
- package/dist/lib-cjs/grammar/meta-grammar-table.js +39 -0
- package/dist/lib-cjs/grammar/meta-grammar-table.js.map +1 -0
- package/dist/lib-cjs/grammar/production.js +3 -0
- package/dist/lib-cjs/grammar/production.js.map +1 -0
- package/dist/lib-cjs/grammar/read-grammar-error.js +22 -0
- package/dist/lib-cjs/grammar/read-grammar-error.js.map +1 -0
- package/dist/lib-cjs/grammar/read-grammar.js +24 -0
- package/dist/lib-cjs/grammar/read-grammar.js.map +1 -0
- package/dist/lib-cjs/grammar/table-validator.js +215 -0
- package/dist/lib-cjs/grammar/table-validator.js.map +1 -0
- package/dist/lib-cjs/grammar/token-rule.js +3 -0
- package/dist/lib-cjs/grammar/token-rule.js.map +1 -0
- package/dist/lib-cjs/grammar/transform-expression.js +3 -0
- package/dist/lib-cjs/grammar/transform-expression.js.map +1 -0
- package/dist/lib-cjs/grammar/transform-rule.js +3 -0
- package/dist/lib-cjs/grammar/transform-rule.js.map +1 -0
- package/dist/lib-cjs/grammar/transform-schema.js +43 -0
- package/dist/lib-cjs/grammar/transform-schema.js.map +1 -0
- package/dist/lib-cjs/index.js +66 -0
- package/dist/lib-cjs/index.js.map +1 -0
- package/dist/lib-cjs/lexer/index.js +32 -0
- package/dist/lib-cjs/lexer/index.js.map +1 -0
- package/dist/lib-cjs/lexer/lexer-compile-error.js +22 -0
- package/dist/lib-cjs/lexer/lexer-compile-error.js.map +1 -0
- package/dist/lib-cjs/lexer/lexer-compile.js +201 -0
- package/dist/lib-cjs/lexer/lexer-compile.js.map +1 -0
- package/dist/lib-cjs/lexer/lexer-error.js +22 -0
- package/dist/lib-cjs/lexer/lexer-error.js.map +1 -0
- package/dist/lib-cjs/lexer/lexer-input-error.js +17 -0
- package/dist/lib-cjs/lexer/lexer-input-error.js.map +1 -0
- package/dist/lib-cjs/lexer/lexer-state-error.js +19 -0
- package/dist/lib-cjs/lexer/lexer-state-error.js.map +1 -0
- package/dist/lib-cjs/lexer/lexer.js +278 -0
- package/dist/lib-cjs/lexer/lexer.js.map +1 -0
- package/dist/lib-cjs/lexer/token.js +44 -0
- package/dist/lib-cjs/lexer/token.js.map +1 -0
- package/dist/lib-cjs/package.json +3 -0
- package/dist/lib-cjs/parse-context-error.js +19 -0
- package/dist/lib-cjs/parse-context-error.js.map +1 -0
- package/dist/lib-cjs/parse-context.js +137 -0
- package/dist/lib-cjs/parse-context.js.map +1 -0
- package/dist/lib-cjs/parse-output-error.js +19 -0
- package/dist/lib-cjs/parse-output-error.js.map +1 -0
- package/dist/lib-cjs/parse-output.js +18 -0
- package/dist/lib-cjs/parse-output.js.map +1 -0
- package/dist/lib-cjs/parse-table/analysis/first-follow.js +294 -0
- package/dist/lib-cjs/parse-table/analysis/first-follow.js.map +1 -0
- package/dist/lib-cjs/parse-table/analysis/index.js +9 -0
- package/dist/lib-cjs/parse-table/analysis/index.js.map +1 -0
- package/dist/lib-cjs/parse-table/bnf/bnf-grammar.js +140 -0
- package/dist/lib-cjs/parse-table/bnf/bnf-grammar.js.map +1 -0
- package/dist/lib-cjs/parse-table/bnf/bnf-production.js +3 -0
- package/dist/lib-cjs/parse-table/bnf/bnf-production.js.map +1 -0
- package/dist/lib-cjs/parse-table/bnf/bnf-symbol.js +39 -0
- package/dist/lib-cjs/parse-table/bnf/bnf-symbol.js.map +1 -0
- package/dist/lib-cjs/parse-table/bnf/desugar-ebnf.js +224 -0
- package/dist/lib-cjs/parse-table/bnf/desugar-ebnf.js.map +1 -0
- package/dist/lib-cjs/parse-table/bnf/index.js +13 -0
- package/dist/lib-cjs/parse-table/bnf/index.js.map +1 -0
- package/dist/lib-cjs/parse-table/build-lr-table.js +171 -0
- package/dist/lib-cjs/parse-table/build-lr-table.js.map +1 -0
- package/dist/lib-cjs/parse-table/index.js +49 -0
- package/dist/lib-cjs/parse-table/index.js.map +1 -0
- package/dist/lib-cjs/parse-table/lr-algorithm-error.js +19 -0
- package/dist/lib-cjs/parse-table/lr-algorithm-error.js.map +1 -0
- package/dist/lib-cjs/parse-table/lr-algorithm.js +31 -0
- package/dist/lib-cjs/parse-table/lr-algorithm.js.map +1 -0
- package/dist/lib-cjs/parse-table/lr0/index.js +14 -0
- package/dist/lib-cjs/parse-table/lr0/index.js.map +1 -0
- package/dist/lib-cjs/parse-table/lr0/lr0-item-set.js +286 -0
- package/dist/lib-cjs/parse-table/lr0/lr0-item-set.js.map +1 -0
- package/dist/lib-cjs/parse-table/lr1/index.js +18 -0
- package/dist/lib-cjs/parse-table/lr1/index.js.map +1 -0
- package/dist/lib-cjs/parse-table/lr1/lr1-item-set.js +432 -0
- package/dist/lib-cjs/parse-table/lr1/lr1-item-set.js.map +1 -0
- package/dist/lib-cjs/parse-table/parse-table-build-error.js +24 -0
- package/dist/lib-cjs/parse-table/parse-table-build-error.js.map +1 -0
- package/dist/lib-cjs/parse-table/parse-table-error.js +19 -0
- package/dist/lib-cjs/parse-table/parse-table-error.js.map +1 -0
- package/dist/lib-cjs/parse-table/parse-table-json.js +12 -0
- package/dist/lib-cjs/parse-table/parse-table-json.js.map +1 -0
- package/dist/lib-cjs/parse-table/parse-table.js +345 -0
- package/dist/lib-cjs/parse-table/parse-table.js.map +1 -0
- package/dist/lib-cjs/parse-table/slr/index.js +13 -0
- package/dist/lib-cjs/parse-table/slr/index.js.map +1 -0
- package/dist/lib-cjs/parse-table/slr/parse-action.js +8 -0
- package/dist/lib-cjs/parse-table/slr/parse-action.js.map +1 -0
- package/dist/lib-cjs/parse-table/slr/slr-table.js +18 -0
- package/dist/lib-cjs/parse-table/slr/slr-table.js.map +1 -0
- package/dist/lib-cjs/parse-table/table/index.js +21 -0
- package/dist/lib-cjs/parse-table/table/index.js.map +1 -0
- package/dist/lib-cjs/parse-table/table/lr-parse-table.js +192 -0
- package/dist/lib-cjs/parse-table/table/lr-parse-table.js.map +1 -0
- package/dist/lib-cjs/parse-table/table/parse-action.js +54 -0
- package/dist/lib-cjs/parse-table/table/parse-action.js.map +1 -0
- package/dist/lib-cjs/parse-table/table/table-builder-base.js +153 -0
- package/dist/lib-cjs/parse-table/table/table-builder-base.js.map +1 -0
- package/dist/lib-cjs/parse-table/token-inventory.js +18 -0
- package/dist/lib-cjs/parse-table/token-inventory.js.map +1 -0
- package/dist/lib-cjs/parser-lr.js +143 -0
- package/dist/lib-cjs/parser-lr.js.map +1 -0
- package/dist/lib-cjs/shift-reduce/index.js +11 -0
- package/dist/lib-cjs/shift-reduce/index.js.map +1 -0
- package/dist/lib-cjs/shift-reduce/shift-reduce-engine.js +224 -0
- package/dist/lib-cjs/shift-reduce/shift-reduce-engine.js.map +1 -0
- package/dist/lib-cjs/transform/binding-map.js +82 -0
- package/dist/lib-cjs/transform/binding-map.js.map +1 -0
- package/dist/lib-cjs/transform/cst-transformer.js +480 -0
- package/dist/lib-cjs/transform/cst-transformer.js.map +1 -0
- package/dist/lib-cjs/transform/grammar-fixture.js +109 -0
- package/dist/lib-cjs/transform/grammar-fixture.js.map +1 -0
- package/dist/lib-cjs/transform/index.js +12 -0
- package/dist/lib-cjs/transform/index.js.map +1 -0
- package/docs/grammar.md +80 -0
- package/docs/parser-lr-enhancement-proposals.md +548 -0
- package/grammars/6502.grammar +233 -0
- package/grammars/calc.grammar +30 -0
- package/grammars/ferrite.grammar +991 -0
- package/grammars/fixtures/build-optional/build-optional.grammar +32 -0
- package/grammars/fixtures/build-optional/input.txt +1 -0
- package/grammars/fixtures/comparison-op/comparison-op.grammar +28 -0
- package/grammars/fixtures/comparison-op/input.txt +1 -0
- package/grammars/fixtures/flatten-repeat/flatten-repeat.grammar +28 -0
- package/grammars/fixtures/flatten-repeat/input.txt +1 -0
- package/grammars/fixtures/help-topic/help-topic.grammar +28 -0
- package/grammars/fixtures/help-topic/input.txt +1 -0
- package/grammars/fixtures/let-target/input.txt +1 -0
- package/grammars/fixtures/let-target/let-target.grammar +33 -0
- package/grammars/fixtures/pass-preserves-production/bare-terminal/bare-terminal.grammar +24 -0
- package/grammars/fixtures/pass-preserves-production/bare-terminal/input.txt +1 -0
- package/grammars/fixtures/pass-preserves-production/labeled-variant/input-end-if.txt +1 -0
- package/grammars/fixtures/pass-preserves-production/labeled-variant/input-end.txt +1 -0
- package/grammars/fixtures/pass-preserves-production/labeled-variant/labeled-variant.grammar +24 -0
- package/grammars/fixtures/pass-preserves-production/optional-absent/input.txt +1 -0
- package/grammars/fixtures/pass-preserves-production/optional-absent/optional-absent.grammar +24 -0
- package/grammars/fixtures/pass-preserves-production/optional-present/input.txt +1 -0
- package/grammars/fixtures/pass-preserves-production/optional-present/optional-present.grammar +24 -0
- package/grammars/grammar.grammar +428 -0
- package/grammars/lisp.grammar +95 -0
- package/package.json +10 -5
|
@@ -0,0 +1,991 @@
|
|
|
1
|
+
// Ferrite — a C-like language with C#-style structs, namespaces, and pointer semantics.
|
|
2
|
+
// No preprocessor; sources compile as single units (namespaces + using, like C# assemblies).
|
|
3
|
+
//
|
|
4
|
+
// Example:
|
|
5
|
+
//
|
|
6
|
+
// namespace Ferrite.Math {
|
|
7
|
+
// struct Vec2 {
|
|
8
|
+
// float32 x;
|
|
9
|
+
// float32 y;
|
|
10
|
+
// float32 dot(Vec2* other) {
|
|
11
|
+
// return x * other->x + y * other->y;
|
|
12
|
+
// }
|
|
13
|
+
// }
|
|
14
|
+
// }
|
|
15
|
+
//
|
|
16
|
+
// using Ferrite.Math;
|
|
17
|
+
//
|
|
18
|
+
// int32 main() {
|
|
19
|
+
// Vec2 a = { 1.0, 2.0 };
|
|
20
|
+
// Vec2* p = &a;
|
|
21
|
+
// return (int32)p->dot(&a);
|
|
22
|
+
// }
|
|
23
|
+
|
|
24
|
+
name "ferrite" ;
|
|
25
|
+
|
|
26
|
+
tokens
|
|
27
|
+
kw_struct = /struct/ ;
|
|
28
|
+
kw_namespace = /namespace/ ;
|
|
29
|
+
kw_using = /using/ ;
|
|
30
|
+
kw_if = /if/ ;
|
|
31
|
+
kw_else = /else/ ;
|
|
32
|
+
kw_while = /while/ ;
|
|
33
|
+
kw_for = /for/ ;
|
|
34
|
+
kw_return = /return/ ;
|
|
35
|
+
kw_break = /break/ ;
|
|
36
|
+
kw_continue = /continue/ ;
|
|
37
|
+
kw_new = /new/ ;
|
|
38
|
+
kw_null = /null/ ;
|
|
39
|
+
kw_true = /true/ ;
|
|
40
|
+
kw_false = /false/ ;
|
|
41
|
+
kw_void = /void/ ;
|
|
42
|
+
kw_bool = /bool/ ;
|
|
43
|
+
kw_int8 = /int8/ ;
|
|
44
|
+
kw_int16 = /int16/ ;
|
|
45
|
+
kw_int32 = /int32/ ;
|
|
46
|
+
kw_int64 = /int64/ ;
|
|
47
|
+
kw_uint8 = /uint8/ ;
|
|
48
|
+
kw_uint16 = /uint16/ ;
|
|
49
|
+
kw_uint32 = /uint32/ ;
|
|
50
|
+
kw_uint64 = /uint64/ ;
|
|
51
|
+
kw_float32 = /float32/ ;
|
|
52
|
+
kw_float64 = /float64/ ;
|
|
53
|
+
kw_char = /char/ ;
|
|
54
|
+
|
|
55
|
+
identifier = /[A-Za-z_][A-Za-z0-9_]*/ ;
|
|
56
|
+
int_literal = /0x[0-9A-F]+|0b[01]+|[0-9]+/i ;
|
|
57
|
+
float_literal = /[0-9]+\.[0-9]+([E][+-]?[0-9]+)?|[0-9]+[E][+-]?[0-9]+/i ;
|
|
58
|
+
char_literal = /'(?:\\.|[^'\\])'/ ;
|
|
59
|
+
string_literal = /"(?:\\.|[^"\\])*"/ ;
|
|
60
|
+
|
|
61
|
+
lbrace = /\{/ ;
|
|
62
|
+
rbrace = /\}/ ;
|
|
63
|
+
lpar = /\(/ ;
|
|
64
|
+
rpar = /\)/ ;
|
|
65
|
+
lbrack = /\[/ ;
|
|
66
|
+
rbrack = /\]/ ;
|
|
67
|
+
semicolon = /;/ ;
|
|
68
|
+
comma = /,/ ;
|
|
69
|
+
dot = /\./ ;
|
|
70
|
+
colon = /:/ ;
|
|
71
|
+
|
|
72
|
+
arrow = /->/ ;
|
|
73
|
+
inc = /\+\+/ ;
|
|
74
|
+
dec = /--/ ;
|
|
75
|
+
plus = /\+/ ;
|
|
76
|
+
minus = /-/ ;
|
|
77
|
+
star = /\*/ ;
|
|
78
|
+
slash = /\// ;
|
|
79
|
+
percent = /%/ ;
|
|
80
|
+
amp = /&/ ;
|
|
81
|
+
pipe = /\|/ ;
|
|
82
|
+
caret = /\^/ ;
|
|
83
|
+
tilde = /~/ ;
|
|
84
|
+
bang = /!/ ;
|
|
85
|
+
lt = /</ ;
|
|
86
|
+
gt = />/ ;
|
|
87
|
+
assign = /=/ ;
|
|
88
|
+
question = /\?/ ;
|
|
89
|
+
|
|
90
|
+
eq = /==/ ;
|
|
91
|
+
ne = /!=/ ;
|
|
92
|
+
le = /<=/ ;
|
|
93
|
+
ge = />=/ ;
|
|
94
|
+
lshift = /<</ ;
|
|
95
|
+
rshift = />>/ ;
|
|
96
|
+
andand = /&&/ ;
|
|
97
|
+
oror = /\|\|/ ;
|
|
98
|
+
pluseq = /\+=/ ;
|
|
99
|
+
minuseq = /-=/ ;
|
|
100
|
+
stareq = /\*=/ ;
|
|
101
|
+
slasheq = /\/=/ ;
|
|
102
|
+
ampeq = /&=/ ;
|
|
103
|
+
pipeeq = /\|=/ ;
|
|
104
|
+
careteq = /\^=/ ;
|
|
105
|
+
|
|
106
|
+
skip
|
|
107
|
+
whitespace = /[ \t\r\n]+/ ;
|
|
108
|
+
line_comment = /\/\/[^\n\r]*/ ;
|
|
109
|
+
block_comment = /\/\*[\s\S]*?\*\// ;
|
|
110
|
+
|
|
111
|
+
start program ;
|
|
112
|
+
|
|
113
|
+
grammar
|
|
114
|
+
program =
|
|
115
|
+
{ [decl]:top_decl }
|
|
116
|
+
;
|
|
117
|
+
|
|
118
|
+
top_decl =
|
|
119
|
+
#namespace [nsKw]:kw_namespace [qname]:qualified_name [body]:namespace_body
|
|
120
|
+
| #using [useKw]:kw_using [qname]:qualified_name [semi]:semicolon
|
|
121
|
+
| #struct struct_decl
|
|
122
|
+
| #function function_decl
|
|
123
|
+
;
|
|
124
|
+
|
|
125
|
+
namespace_body =
|
|
126
|
+
[open]:lbrace
|
|
127
|
+
{ [member]:namespace_member }
|
|
128
|
+
[close]:rbrace
|
|
129
|
+
;
|
|
130
|
+
|
|
131
|
+
namespace_member =
|
|
132
|
+
#struct struct_decl
|
|
133
|
+
| #function function_decl
|
|
134
|
+
| #namespace [nsKw]:kw_namespace [qname]:qualified_name [body]:namespace_body
|
|
135
|
+
| #using [useKw]:kw_using [qname]:qualified_name [semi]:semicolon
|
|
136
|
+
| #statement [stmt]:statement
|
|
137
|
+
;
|
|
138
|
+
|
|
139
|
+
qualified_name =
|
|
140
|
+
[head]:identifier { name_part }
|
|
141
|
+
;
|
|
142
|
+
|
|
143
|
+
name_part =
|
|
144
|
+
[dotTok]:dot [part]:identifier
|
|
145
|
+
;
|
|
146
|
+
|
|
147
|
+
struct_decl =
|
|
148
|
+
[structKw]:kw_struct
|
|
149
|
+
[sym]:identifier
|
|
150
|
+
[body]:struct_body
|
|
151
|
+
[semi]:semicolon
|
|
152
|
+
;
|
|
153
|
+
|
|
154
|
+
struct_body =
|
|
155
|
+
[open]:lbrace
|
|
156
|
+
{ [member]:struct_member }
|
|
157
|
+
[close]:rbrace
|
|
158
|
+
;
|
|
159
|
+
|
|
160
|
+
struct_member =
|
|
161
|
+
#field field_decl
|
|
162
|
+
| #method method_decl
|
|
163
|
+
;
|
|
164
|
+
|
|
165
|
+
field_decl =
|
|
166
|
+
[type]:type_spec
|
|
167
|
+
[sym]:identifier
|
|
168
|
+
[semi]:semicolon
|
|
169
|
+
;
|
|
170
|
+
|
|
171
|
+
method_decl =
|
|
172
|
+
#method
|
|
173
|
+
[type]:type_spec
|
|
174
|
+
[sym]:identifier
|
|
175
|
+
[open]:lpar
|
|
176
|
+
[close]:rpar
|
|
177
|
+
[body]:block
|
|
178
|
+
| #methodParams
|
|
179
|
+
[type]:type_spec
|
|
180
|
+
[sym]:identifier
|
|
181
|
+
[open]:lpar
|
|
182
|
+
[params]:param_list
|
|
183
|
+
[close]:rpar
|
|
184
|
+
[body]:block
|
|
185
|
+
;
|
|
186
|
+
|
|
187
|
+
function_decl =
|
|
188
|
+
#defined
|
|
189
|
+
[type]:type_spec
|
|
190
|
+
[sym]:identifier
|
|
191
|
+
[open]:lpar
|
|
192
|
+
[close]:rpar
|
|
193
|
+
[body]:block
|
|
194
|
+
| #definedParams
|
|
195
|
+
[type]:type_spec
|
|
196
|
+
[sym]:identifier
|
|
197
|
+
[open]:lpar
|
|
198
|
+
[params]:param_list
|
|
199
|
+
[close]:rpar
|
|
200
|
+
[body]:block
|
|
201
|
+
| #prototype
|
|
202
|
+
[type]:type_spec
|
|
203
|
+
[sym]:identifier
|
|
204
|
+
[open]:lpar
|
|
205
|
+
[close]:rpar
|
|
206
|
+
[semi]:semicolon
|
|
207
|
+
| #prototypeParams
|
|
208
|
+
[type]:type_spec
|
|
209
|
+
[sym]:identifier
|
|
210
|
+
[open]:lpar
|
|
211
|
+
[params]:param_list
|
|
212
|
+
[close]:rpar
|
|
213
|
+
[semi]:semicolon
|
|
214
|
+
;
|
|
215
|
+
|
|
216
|
+
param_list =
|
|
217
|
+
#list [first]:param { param_sep }
|
|
218
|
+
;
|
|
219
|
+
|
|
220
|
+
param_sep =
|
|
221
|
+
[commaTok]:comma [rest]:param
|
|
222
|
+
;
|
|
223
|
+
|
|
224
|
+
param =
|
|
225
|
+
[type]:type_spec
|
|
226
|
+
[sym]:identifier
|
|
227
|
+
;
|
|
228
|
+
|
|
229
|
+
type_spec =
|
|
230
|
+
#voidType [voidKw]:kw_void { [ptr]:star }
|
|
231
|
+
| #bool [boolKw]:kw_bool { [ptr]:star }
|
|
232
|
+
| #int8 [int8Kw]:kw_int8 { [ptr]:star }
|
|
233
|
+
| #int16 [int16Kw]:kw_int16 { [ptr]:star }
|
|
234
|
+
| #int32 [int32Kw]:kw_int32 { [ptr]:star }
|
|
235
|
+
| #int64 [int64Kw]:kw_int64 { [ptr]:star }
|
|
236
|
+
| #uint8 [uint8Kw]:kw_uint8 { [ptr]:star }
|
|
237
|
+
| #uint16 [uint16Kw]:kw_uint16 { [ptr]:star }
|
|
238
|
+
| #uint32 [uint32Kw]:kw_uint32 { [ptr]:star }
|
|
239
|
+
| #uint64 [uint64Kw]:kw_uint64 { [ptr]:star }
|
|
240
|
+
| #float32 [float32Kw]:kw_float32 { [ptr]:star }
|
|
241
|
+
| #float64 [float64Kw]:kw_float64 { [ptr]:star }
|
|
242
|
+
| #char [charKw]:kw_char { [ptr]:star }
|
|
243
|
+
| #named [sym]:identifier { [ptr]:star }
|
|
244
|
+
| #array [elem]:type_spec [open]:lbrack [size]:int_literal [close]:rbrack { [ptr]:star }
|
|
245
|
+
| #arrayUnsized [elem]:type_spec [open]:lbrack [close]:rbrack { [ptr]:star }
|
|
246
|
+
;
|
|
247
|
+
|
|
248
|
+
block =
|
|
249
|
+
[open]:lbrace
|
|
250
|
+
{ [stmt]:statement }
|
|
251
|
+
[close]:rbrace
|
|
252
|
+
;
|
|
253
|
+
|
|
254
|
+
statement =
|
|
255
|
+
#block [body]:block
|
|
256
|
+
| #varDecl [type]:type_spec [sym]:identifier [ [init]:var_init ] [semi]:semicolon
|
|
257
|
+
| #if [ifKw]:kw_if [cond]:lpar [condition]:expression [condEnd]:rpar [then]:statement [ [elseKw]:kw_else [elseBody]:statement ]
|
|
258
|
+
| #while [whileKw]:kw_while [cond]:lpar [condition]:expression [condEnd]:rpar [body]:statement
|
|
259
|
+
| #for [forKw]:kw_for [openFor]:lpar [ [init]:for_init ] [semi1]:semicolon [ [test]:expression ] [semi2]:semicolon [ [step]:expression ] [closeFor]:rpar [body]:statement
|
|
260
|
+
| #return [returnKw]:kw_return [ [expr]:expression ] [semi]:semicolon
|
|
261
|
+
| #break [breakKw]:kw_break [semi]:semicolon
|
|
262
|
+
| #continue [continueKw]:kw_continue [semi]:semicolon
|
|
263
|
+
| #exprStmt [expr]:expression [semi]:semicolon
|
|
264
|
+
;
|
|
265
|
+
|
|
266
|
+
var_init =
|
|
267
|
+
#assign [eqTok]:assign [value]:expression
|
|
268
|
+
| #braceInit [eqTok]:assign [open]:lbrace [ [values]:init_list ] [close]:rbrace
|
|
269
|
+
;
|
|
270
|
+
|
|
271
|
+
init_list =
|
|
272
|
+
#list [first]:expression { expr_sep }
|
|
273
|
+
;
|
|
274
|
+
|
|
275
|
+
expr_sep =
|
|
276
|
+
[commaTok]:comma [rest]:expression
|
|
277
|
+
;
|
|
278
|
+
|
|
279
|
+
for_init =
|
|
280
|
+
#var [type]:type_spec [sym]:identifier [ [vinit]:var_init ]
|
|
281
|
+
| #expr [expr]:expression
|
|
282
|
+
;
|
|
283
|
+
|
|
284
|
+
expression =
|
|
285
|
+
[value]:assignment_expr
|
|
286
|
+
;
|
|
287
|
+
|
|
288
|
+
assignment_expr =
|
|
289
|
+
#plain [value]:logical_or_expr
|
|
290
|
+
| #assign [left]:unary_expr [op]:assign_op [right]:assignment_expr
|
|
291
|
+
;
|
|
292
|
+
|
|
293
|
+
assign_op =
|
|
294
|
+
#eq [tok]:assign
|
|
295
|
+
| #pluseq [tok]:pluseq
|
|
296
|
+
| #minuseq [tok]:minuseq
|
|
297
|
+
| #stareq [tok]:stareq
|
|
298
|
+
| #slasheq [tok]:slasheq
|
|
299
|
+
| #ampeq [tok]:ampeq
|
|
300
|
+
| #pipeeq [tok]:pipeeq
|
|
301
|
+
| #careteq [tok]:careteq
|
|
302
|
+
;
|
|
303
|
+
|
|
304
|
+
logical_or_expr =
|
|
305
|
+
#single [value]:logical_and_expr
|
|
306
|
+
| #chain [left]:logical_or_expr [op]:oror [right]:logical_and_expr
|
|
307
|
+
;
|
|
308
|
+
|
|
309
|
+
logical_and_expr =
|
|
310
|
+
#single [value]:bitwise_or_expr
|
|
311
|
+
| #chain [left]:logical_and_expr [op]:andand [right]:bitwise_or_expr
|
|
312
|
+
;
|
|
313
|
+
|
|
314
|
+
bitwise_or_expr =
|
|
315
|
+
#single [value]:bitwise_xor_expr
|
|
316
|
+
| #chain [left]:bitwise_or_expr [op]:pipe [right]:bitwise_xor_expr
|
|
317
|
+
;
|
|
318
|
+
|
|
319
|
+
bitwise_xor_expr =
|
|
320
|
+
#single [value]:bitwise_and_expr
|
|
321
|
+
| #chain [left]:bitwise_xor_expr [op]:caret [right]:bitwise_and_expr
|
|
322
|
+
;
|
|
323
|
+
|
|
324
|
+
bitwise_and_expr =
|
|
325
|
+
#single [value]:equality_expr
|
|
326
|
+
| #chain [left]:bitwise_and_expr [op]:amp [right]:equality_expr
|
|
327
|
+
;
|
|
328
|
+
equality_expr =
|
|
329
|
+
#single [value]:relational_expr
|
|
330
|
+
| #chain [head]:relational_expr [op]:equality_op [tail]:relational_expr
|
|
331
|
+
;
|
|
332
|
+
|
|
333
|
+
equality_op =
|
|
334
|
+
#eq [tok]:eq
|
|
335
|
+
| #ne [tok]:ne
|
|
336
|
+
;
|
|
337
|
+
|
|
338
|
+
relational_expr =
|
|
339
|
+
#single [value]:shift_expr
|
|
340
|
+
| #chain [head]:shift_expr [op]:relational_op [tail]:shift_expr
|
|
341
|
+
;
|
|
342
|
+
|
|
343
|
+
relational_op =
|
|
344
|
+
#lt [tok]:lt
|
|
345
|
+
| #gt [tok]:gt
|
|
346
|
+
| #le [tok]:le
|
|
347
|
+
| #ge [tok]:ge
|
|
348
|
+
;
|
|
349
|
+
|
|
350
|
+
shift_expr =
|
|
351
|
+
#single [value]:additive_expr
|
|
352
|
+
| #chain [head]:additive_expr [op]:shift_op [tail]:additive_expr
|
|
353
|
+
;
|
|
354
|
+
|
|
355
|
+
shift_op =
|
|
356
|
+
#lshift [tok]:lshift
|
|
357
|
+
| #rshift [tok]:rshift
|
|
358
|
+
;
|
|
359
|
+
|
|
360
|
+
additive_expr =
|
|
361
|
+
#single [value]:multiplicative_expr
|
|
362
|
+
| #chain [left]:additive_expr [op]:additive_op [right]:multiplicative_expr
|
|
363
|
+
;
|
|
364
|
+
|
|
365
|
+
additive_op =
|
|
366
|
+
#plus [tok]:plus
|
|
367
|
+
| #minus [tok]:minus
|
|
368
|
+
;
|
|
369
|
+
|
|
370
|
+
multiplicative_expr =
|
|
371
|
+
#single [value]:unary_expr
|
|
372
|
+
| #chain [left]:multiplicative_expr [op]:multiplicative_op [right]:unary_expr
|
|
373
|
+
;
|
|
374
|
+
|
|
375
|
+
multiplicative_op =
|
|
376
|
+
#star [tok]:star
|
|
377
|
+
| #slash [tok]:slash
|
|
378
|
+
| #percent [tok]:percent
|
|
379
|
+
;
|
|
380
|
+
|
|
381
|
+
unary_expr =
|
|
382
|
+
#postfix [value]:postfix_expr
|
|
383
|
+
| #cast [open]:lpar [type]:type_spec [close]:rpar [value]:unary_expr
|
|
384
|
+
| #preInc [op]:inc [value]:unary_expr
|
|
385
|
+
| #preDec [op]:dec [value]:unary_expr
|
|
386
|
+
| #addr [op]:amp [value]:unary_expr
|
|
387
|
+
| #deref [op]:star [value]:unary_expr
|
|
388
|
+
| #not [op]:bang [value]:unary_expr
|
|
389
|
+
| #bitNot [op]:tilde [value]:unary_expr
|
|
390
|
+
| #neg [op]:minus [value]:unary_expr
|
|
391
|
+
| #plus [op]:plus [value]:unary_expr
|
|
392
|
+
;
|
|
393
|
+
|
|
394
|
+
postfix_expr =
|
|
395
|
+
#primary [value]:primary_expr { [suffix]:postfix_suffix }
|
|
396
|
+
;
|
|
397
|
+
|
|
398
|
+
postfix_suffix =
|
|
399
|
+
#index [open]:lbrack [index]:expression [close]:rbrack
|
|
400
|
+
| #call [open]:lpar [close]:rpar
|
|
401
|
+
| #callArgs [open]:lpar [args]:arg_list [close]:rpar
|
|
402
|
+
| #member [dotTok]:dot [sym]:identifier
|
|
403
|
+
| #arrow [arrowTok]:arrow [sym]:identifier
|
|
404
|
+
| #postInc [op]:inc
|
|
405
|
+
| #postDec [op]:dec
|
|
406
|
+
;
|
|
407
|
+
|
|
408
|
+
arg_list =
|
|
409
|
+
#list [first]:expression { expr_sep }
|
|
410
|
+
;
|
|
411
|
+
|
|
412
|
+
primary_expr =
|
|
413
|
+
#ident [sym]:identifier
|
|
414
|
+
| #int [value]:int_literal
|
|
415
|
+
| #float [value]:float_literal
|
|
416
|
+
| #char [value]:char_literal
|
|
417
|
+
| #string [value]:string_literal
|
|
418
|
+
| #true [trueKw]:kw_true
|
|
419
|
+
| #false [falseKw]:kw_false
|
|
420
|
+
| #null [nullKw]:kw_null
|
|
421
|
+
| #paren [open]:lpar [inner]:expression [close]:rpar
|
|
422
|
+
| #new [newKw]:kw_new [type]:type_spec [open]:lpar [close]:rpar
|
|
423
|
+
| #newArgs [newKw]:kw_new [type]:type_spec [open]:lpar [args]:arg_list [close]:rpar
|
|
424
|
+
;
|
|
425
|
+
|
|
426
|
+
ast
|
|
427
|
+
program =
|
|
428
|
+
{ top_decl }
|
|
429
|
+
;
|
|
430
|
+
|
|
431
|
+
top_decl =
|
|
432
|
+
#namespace [nsKw]:kw_namespace [qname]:qualified_name [body]:namespace_body
|
|
433
|
+
| #using [useKw]:kw_using [qname]:qualified_name [semi]:semicolon
|
|
434
|
+
| #struct struct_decl
|
|
435
|
+
| #function function_decl
|
|
436
|
+
;
|
|
437
|
+
|
|
438
|
+
namespace_body =
|
|
439
|
+
[open]:lbrace
|
|
440
|
+
{ [member]:namespace_member }
|
|
441
|
+
[close]:rbrace
|
|
442
|
+
;
|
|
443
|
+
|
|
444
|
+
namespace_member =
|
|
445
|
+
#struct struct_decl
|
|
446
|
+
| #function function_decl
|
|
447
|
+
| #namespace [nsKw]:kw_namespace [qname]:qualified_name [body]:namespace_body
|
|
448
|
+
| #using [useKw]:kw_using [qname]:qualified_name [semi]:semicolon
|
|
449
|
+
| #statement [stmt]:statement
|
|
450
|
+
;
|
|
451
|
+
|
|
452
|
+
qualified_name =
|
|
453
|
+
[head]:identifier { name_part }
|
|
454
|
+
;
|
|
455
|
+
|
|
456
|
+
name_part =
|
|
457
|
+
[dotTok]:dot [part]:identifier
|
|
458
|
+
;
|
|
459
|
+
|
|
460
|
+
struct_decl =
|
|
461
|
+
[structKw]:kw_struct
|
|
462
|
+
[sym]:identifier
|
|
463
|
+
[body]:struct_body
|
|
464
|
+
[semi]:semicolon
|
|
465
|
+
;
|
|
466
|
+
|
|
467
|
+
struct_body =
|
|
468
|
+
[open]:lbrace
|
|
469
|
+
{ [member]:struct_member }
|
|
470
|
+
[close]:rbrace
|
|
471
|
+
;
|
|
472
|
+
|
|
473
|
+
struct_member =
|
|
474
|
+
#field field_decl
|
|
475
|
+
| #method method_decl
|
|
476
|
+
;
|
|
477
|
+
|
|
478
|
+
field_decl =
|
|
479
|
+
[type]:type_spec
|
|
480
|
+
[sym]:identifier
|
|
481
|
+
[semi]:semicolon
|
|
482
|
+
;
|
|
483
|
+
|
|
484
|
+
method_decl =
|
|
485
|
+
#method
|
|
486
|
+
[type]:type_spec
|
|
487
|
+
[sym]:identifier
|
|
488
|
+
[open]:lpar
|
|
489
|
+
[close]:rpar
|
|
490
|
+
[body]:block
|
|
491
|
+
| #methodParams
|
|
492
|
+
[type]:type_spec
|
|
493
|
+
[sym]:identifier
|
|
494
|
+
[open]:lpar
|
|
495
|
+
[params]:param_list
|
|
496
|
+
[close]:rpar
|
|
497
|
+
[body]:block
|
|
498
|
+
;
|
|
499
|
+
|
|
500
|
+
function_decl =
|
|
501
|
+
#defined
|
|
502
|
+
[type]:type_spec
|
|
503
|
+
[sym]:identifier
|
|
504
|
+
[open]:lpar
|
|
505
|
+
[close]:rpar
|
|
506
|
+
[body]:block
|
|
507
|
+
| #definedParams
|
|
508
|
+
[type]:type_spec
|
|
509
|
+
[sym]:identifier
|
|
510
|
+
[open]:lpar
|
|
511
|
+
[params]:param_list
|
|
512
|
+
[close]:rpar
|
|
513
|
+
[body]:block
|
|
514
|
+
| #prototype
|
|
515
|
+
[type]:type_spec
|
|
516
|
+
[sym]:identifier
|
|
517
|
+
[open]:lpar
|
|
518
|
+
[close]:rpar
|
|
519
|
+
[semi]:semicolon
|
|
520
|
+
| #prototypeParams
|
|
521
|
+
[type]:type_spec
|
|
522
|
+
[sym]:identifier
|
|
523
|
+
[open]:lpar
|
|
524
|
+
[params]:param_list
|
|
525
|
+
[close]:rpar
|
|
526
|
+
[semi]:semicolon
|
|
527
|
+
;
|
|
528
|
+
|
|
529
|
+
param_list =
|
|
530
|
+
#list [first]:param { param_sep }
|
|
531
|
+
;
|
|
532
|
+
|
|
533
|
+
param_sep =
|
|
534
|
+
[commaTok]:comma [rest]:param
|
|
535
|
+
;
|
|
536
|
+
|
|
537
|
+
param =
|
|
538
|
+
[type]:type_spec
|
|
539
|
+
[sym]:identifier
|
|
540
|
+
;
|
|
541
|
+
|
|
542
|
+
type_spec =
|
|
543
|
+
#voidType [voidKw]:kw_void { [ptr]:star }
|
|
544
|
+
| #bool [boolKw]:kw_bool { [ptr]:star }
|
|
545
|
+
| #int8 [int8Kw]:kw_int8 { [ptr]:star }
|
|
546
|
+
| #int16 [int16Kw]:kw_int16 { [ptr]:star }
|
|
547
|
+
| #int32 [int32Kw]:kw_int32 { [ptr]:star }
|
|
548
|
+
| #int64 [int64Kw]:kw_int64 { [ptr]:star }
|
|
549
|
+
| #uint8 [uint8Kw]:kw_uint8 { [ptr]:star }
|
|
550
|
+
| #uint16 [uint16Kw]:kw_uint16 { [ptr]:star }
|
|
551
|
+
| #uint32 [uint32Kw]:kw_uint32 { [ptr]:star }
|
|
552
|
+
| #uint64 [uint64Kw]:kw_uint64 { [ptr]:star }
|
|
553
|
+
| #float32 [float32Kw]:kw_float32 { [ptr]:star }
|
|
554
|
+
| #float64 [float64Kw]:kw_float64 { [ptr]:star }
|
|
555
|
+
| #char [charKw]:kw_char { [ptr]:star }
|
|
556
|
+
| #named [sym]:identifier { [ptr]:star }
|
|
557
|
+
| #array [elem]:type_spec [open]:lbrack [size]:int_literal [close]:rbrack { [ptr]:star }
|
|
558
|
+
| #arrayUnsized [elem]:type_spec [open]:lbrack [close]:rbrack { [ptr]:star }
|
|
559
|
+
;
|
|
560
|
+
|
|
561
|
+
block =
|
|
562
|
+
[open]:lbrace
|
|
563
|
+
{ statement }
|
|
564
|
+
[close]:rbrace
|
|
565
|
+
;
|
|
566
|
+
|
|
567
|
+
statement =
|
|
568
|
+
#block [body]:block
|
|
569
|
+
| #varDecl [type]:type_spec [sym]:identifier [ [init]:var_init ] [semi]:semicolon
|
|
570
|
+
| #if [ifKw]:kw_if [cond]:lpar [condition]:expression [condEnd]:rpar [then]:statement [ [elseKw]:kw_else [elseBody]:statement ]
|
|
571
|
+
| #while [whileKw]:kw_while [cond]:lpar [condition]:expression [condEnd]:rpar [body]:statement
|
|
572
|
+
| #for [forKw]:kw_for [openFor]:lpar [ [init]:for_init ] [semi1]:semicolon [ [test]:expression ] [semi2]:semicolon [ [step]:expression ] [closeFor]:rpar [body]:statement
|
|
573
|
+
| #return [returnKw]:kw_return [ [expr]:expression ] [semi]:semicolon
|
|
574
|
+
| #break [breakKw]:kw_break [semi]:semicolon
|
|
575
|
+
| #continue [continueKw]:kw_continue [semi]:semicolon
|
|
576
|
+
| #exprStmt [expr]:expression [semi]:semicolon
|
|
577
|
+
;
|
|
578
|
+
|
|
579
|
+
var_init =
|
|
580
|
+
#assign [eqTok]:assign [value]:expression
|
|
581
|
+
| #braceInit [eqTok]:assign [open]:lbrace [ [values]:init_list ] [close]:rbrace
|
|
582
|
+
;
|
|
583
|
+
|
|
584
|
+
init_list =
|
|
585
|
+
#list [first]:expression { expr_sep }
|
|
586
|
+
;
|
|
587
|
+
|
|
588
|
+
expr_sep =
|
|
589
|
+
[commaTok]:comma [rest]:expression
|
|
590
|
+
;
|
|
591
|
+
|
|
592
|
+
for_init =
|
|
593
|
+
#var [type]:type_spec [sym]:identifier [ [vinit]:var_init ]
|
|
594
|
+
| #expr [expr]:expression
|
|
595
|
+
;
|
|
596
|
+
|
|
597
|
+
expression =
|
|
598
|
+
[value]:assignment_expr
|
|
599
|
+
;
|
|
600
|
+
|
|
601
|
+
assignment_expr =
|
|
602
|
+
#plain [value]:logical_or_expr
|
|
603
|
+
| #assign [left]:unary_expr [op]:assign_op [right]:assignment_expr
|
|
604
|
+
;
|
|
605
|
+
|
|
606
|
+
assign_op =
|
|
607
|
+
#eq [tok]:assign
|
|
608
|
+
| #pluseq [tok]:pluseq
|
|
609
|
+
| #minuseq [tok]:minuseq
|
|
610
|
+
| #stareq [tok]:stareq
|
|
611
|
+
| #slasheq [tok]:slasheq
|
|
612
|
+
| #ampeq [tok]:ampeq
|
|
613
|
+
| #pipeeq [tok]:pipeeq
|
|
614
|
+
| #careteq [tok]:careteq
|
|
615
|
+
;
|
|
616
|
+
|
|
617
|
+
logical_or_expr =
|
|
618
|
+
#single [value]:logical_and_expr
|
|
619
|
+
| #chain [left]:logical_or_expr [op]:oror [right]:logical_and_expr
|
|
620
|
+
;
|
|
621
|
+
|
|
622
|
+
logical_and_expr =
|
|
623
|
+
#single [value]:bitwise_or_expr
|
|
624
|
+
| #chain [left]:logical_and_expr [op]:andand [right]:bitwise_or_expr
|
|
625
|
+
;
|
|
626
|
+
|
|
627
|
+
bitwise_or_expr =
|
|
628
|
+
#single [value]:bitwise_xor_expr
|
|
629
|
+
| #chain [left]:bitwise_or_expr [op]:pipe [right]:bitwise_xor_expr
|
|
630
|
+
;
|
|
631
|
+
|
|
632
|
+
bitwise_xor_expr =
|
|
633
|
+
#single [value]:bitwise_and_expr
|
|
634
|
+
| #chain [left]:bitwise_xor_expr [op]:caret [right]:bitwise_and_expr
|
|
635
|
+
;
|
|
636
|
+
|
|
637
|
+
bitwise_and_expr =
|
|
638
|
+
#single [value]:equality_expr
|
|
639
|
+
| #chain [left]:bitwise_and_expr [op]:amp [right]:equality_expr
|
|
640
|
+
;
|
|
641
|
+
equality_expr =
|
|
642
|
+
#single [value]:relational_expr
|
|
643
|
+
| #chain [head]:relational_expr [op]:equality_op [tail]:relational_expr
|
|
644
|
+
;
|
|
645
|
+
|
|
646
|
+
equality_op =
|
|
647
|
+
#eq [tok]:eq
|
|
648
|
+
| #ne [tok]:ne
|
|
649
|
+
;
|
|
650
|
+
|
|
651
|
+
relational_expr =
|
|
652
|
+
#single [value]:shift_expr
|
|
653
|
+
| #chain [head]:shift_expr [op]:relational_op [tail]:shift_expr
|
|
654
|
+
;
|
|
655
|
+
|
|
656
|
+
relational_op =
|
|
657
|
+
#lt [tok]:lt
|
|
658
|
+
| #gt [tok]:gt
|
|
659
|
+
| #le [tok]:le
|
|
660
|
+
| #ge [tok]:ge
|
|
661
|
+
;
|
|
662
|
+
|
|
663
|
+
shift_expr =
|
|
664
|
+
#single [value]:additive_expr
|
|
665
|
+
| #chain [head]:additive_expr [op]:shift_op [tail]:additive_expr
|
|
666
|
+
;
|
|
667
|
+
|
|
668
|
+
shift_op =
|
|
669
|
+
#lshift [tok]:lshift
|
|
670
|
+
| #rshift [tok]:rshift
|
|
671
|
+
;
|
|
672
|
+
|
|
673
|
+
additive_expr =
|
|
674
|
+
#single [value]:multiplicative_expr
|
|
675
|
+
| #chain [left]:additive_expr [op]:additive_op [right]:multiplicative_expr
|
|
676
|
+
;
|
|
677
|
+
|
|
678
|
+
additive_op =
|
|
679
|
+
#plus [tok]:plus
|
|
680
|
+
| #minus [tok]:minus
|
|
681
|
+
;
|
|
682
|
+
|
|
683
|
+
multiplicative_expr =
|
|
684
|
+
#single [value]:unary_expr
|
|
685
|
+
| #chain [left]:multiplicative_expr [op]:multiplicative_op [right]:unary_expr
|
|
686
|
+
;
|
|
687
|
+
|
|
688
|
+
multiplicative_op =
|
|
689
|
+
#star [tok]:star
|
|
690
|
+
| #slash [tok]:slash
|
|
691
|
+
| #percent [tok]:percent
|
|
692
|
+
;
|
|
693
|
+
|
|
694
|
+
unary_expr =
|
|
695
|
+
#postfix [value]:postfix_expr
|
|
696
|
+
| #cast [open]:lpar [type]:type_spec [close]:rpar [value]:unary_expr
|
|
697
|
+
| #preInc [op]:inc [value]:unary_expr
|
|
698
|
+
| #preDec [op]:dec [value]:unary_expr
|
|
699
|
+
| #addr [op]:amp [value]:unary_expr
|
|
700
|
+
| #deref [op]:star [value]:unary_expr
|
|
701
|
+
| #not [op]:bang [value]:unary_expr
|
|
702
|
+
| #bitNot [op]:tilde [value]:unary_expr
|
|
703
|
+
| #neg [op]:minus [value]:unary_expr
|
|
704
|
+
| #plus [op]:plus [value]:unary_expr
|
|
705
|
+
;
|
|
706
|
+
|
|
707
|
+
postfix_expr =
|
|
708
|
+
#primary [value]:primary_expr { postfix_suffix }
|
|
709
|
+
;
|
|
710
|
+
|
|
711
|
+
postfix_suffix =
|
|
712
|
+
#index [open]:lbrack [index]:expression [close]:rbrack
|
|
713
|
+
| #call [open]:lpar [close]:rpar
|
|
714
|
+
| #callArgs [open]:lpar [args]:arg_list [close]:rpar
|
|
715
|
+
| #member [dotTok]:dot [sym]:identifier
|
|
716
|
+
| #arrow [arrowTok]:arrow [sym]:identifier
|
|
717
|
+
| #postInc [op]:inc
|
|
718
|
+
| #postDec [op]:dec
|
|
719
|
+
;
|
|
720
|
+
|
|
721
|
+
arg_list =
|
|
722
|
+
#list [first]:expression { expr_sep }
|
|
723
|
+
;
|
|
724
|
+
|
|
725
|
+
primary_expr =
|
|
726
|
+
#ident [sym]:identifier
|
|
727
|
+
| #int [value]:int_literal
|
|
728
|
+
| #float [value]:float_literal
|
|
729
|
+
| #char [value]:char_literal
|
|
730
|
+
| #string [value]:string_literal
|
|
731
|
+
| #true [trueKw]:kw_true
|
|
732
|
+
| #false [falseKw]:kw_false
|
|
733
|
+
| #null [nullKw]:kw_null
|
|
734
|
+
| #paren [open]:lpar [inner]:expression [close]:rpar
|
|
735
|
+
| #new [newKw]:kw_new [type]:type_spec [open]:lpar [close]:rpar
|
|
736
|
+
| #newArgs [newKw]:kw_new [type]:type_spec [open]:lpar [args]:arg_list [close]:rpar
|
|
737
|
+
;
|
|
738
|
+
|
|
739
|
+
transform
|
|
740
|
+
program ->
|
|
741
|
+
#main pass(program$repeat_0) ;
|
|
742
|
+
|
|
743
|
+
program$repeat_0 ->
|
|
744
|
+
#main flatten(program.#program, decl, program$repeat_0) ;
|
|
745
|
+
|
|
746
|
+
top_decl ->
|
|
747
|
+
#namespace top_decl.#namespace(nsKw, qname, body)
|
|
748
|
+
| #using top_decl.#using(useKw, qname, semi)
|
|
749
|
+
| #struct pass(struct_decl)
|
|
750
|
+
| #function pass(function_decl) ;
|
|
751
|
+
|
|
752
|
+
namespace_body ->
|
|
753
|
+
#main namespace_body.#namespace_body(open, namespace_body$repeat_0, close) ;
|
|
754
|
+
|
|
755
|
+
namespace_body$repeat_0 ->
|
|
756
|
+
#main flatten(namespace_body.#namespace_body, member, namespace_body$repeat_0) ;
|
|
757
|
+
|
|
758
|
+
namespace_member ->
|
|
759
|
+
#struct pass(struct_decl)
|
|
760
|
+
| #function pass(function_decl)
|
|
761
|
+
| #namespace namespace_member.#namespace(nsKw, qname, body)
|
|
762
|
+
| #using namespace_member.#using(useKw, qname, semi)
|
|
763
|
+
| #statement pass(stmt) ;
|
|
764
|
+
|
|
765
|
+
qualified_name ->
|
|
766
|
+
#main qualified_name.#qualified_name(head, qualified_name$repeat_1) ;
|
|
767
|
+
|
|
768
|
+
qualified_name$repeat_1 ->
|
|
769
|
+
#main flatten(qualified_name.#qualified_name, name_part, qualified_name$repeat_1) ;
|
|
770
|
+
|
|
771
|
+
name_part ->
|
|
772
|
+
#main name_part.#part(dotTok, part) ;
|
|
773
|
+
|
|
774
|
+
struct_decl ->
|
|
775
|
+
#main struct_decl.#struct_decl(structKw, sym, body, semi) ;
|
|
776
|
+
|
|
777
|
+
struct_body ->
|
|
778
|
+
#main struct_body.#struct_body(open, struct_body$repeat_0, close) ;
|
|
779
|
+
|
|
780
|
+
struct_body$repeat_0 ->
|
|
781
|
+
#main flatten(struct_body.#struct_body, member, struct_body$repeat_0) ;
|
|
782
|
+
|
|
783
|
+
struct_member ->
|
|
784
|
+
#field pass(field_decl)
|
|
785
|
+
| #method pass(method_decl) ;
|
|
786
|
+
|
|
787
|
+
field_decl ->
|
|
788
|
+
#main field_decl.#field_decl(type, sym, semi) ;
|
|
789
|
+
|
|
790
|
+
method_decl ->
|
|
791
|
+
#method method_decl.#method(type, sym, open, close, body)
|
|
792
|
+
| #methodParams method_decl.#method(type, sym, open, params, close, body) ;
|
|
793
|
+
|
|
794
|
+
function_decl ->
|
|
795
|
+
#defined function_decl.#defined(type, sym, open, close, body)
|
|
796
|
+
| #definedParams function_decl.#defined(type, sym, open, params, close, body)
|
|
797
|
+
| #prototype function_decl.#prototype(type, sym, open, close, semi)
|
|
798
|
+
| #prototypeParams function_decl.#prototype(type, sym, open, params, close, semi) ;
|
|
799
|
+
|
|
800
|
+
param_list ->
|
|
801
|
+
#main flatten(param_list.#list, first, param_list$repeat_0) ;
|
|
802
|
+
|
|
803
|
+
param_list$repeat_0 ->
|
|
804
|
+
#main flatten(param_list.#list, param_sep, param_list$repeat_0) ;
|
|
805
|
+
|
|
806
|
+
param_sep ->
|
|
807
|
+
#main param_sep.#sep(commaTok, rest) ;
|
|
808
|
+
|
|
809
|
+
param ->
|
|
810
|
+
#main param.#param(type, sym) ;
|
|
811
|
+
|
|
812
|
+
type_spec ->
|
|
813
|
+
#voidType type_spec.#voidType(voidKw, type_spec$repeat_0)
|
|
814
|
+
| #bool type_spec.#bool(boolKw, type_spec$repeat_0)
|
|
815
|
+
| #int8 type_spec.#int8(int8Kw, type_spec$repeat_0)
|
|
816
|
+
| #int16 type_spec.#int16(int16Kw, type_spec$repeat_0)
|
|
817
|
+
| #int32 type_spec.#int32(int32Kw, type_spec$repeat_0)
|
|
818
|
+
| #int64 type_spec.#int64(int64Kw, type_spec$repeat_0)
|
|
819
|
+
| #uint8 type_spec.#uint8(uint8Kw, type_spec$repeat_0)
|
|
820
|
+
| #uint16 type_spec.#uint16(uint16Kw, type_spec$repeat_0)
|
|
821
|
+
| #uint32 type_spec.#uint32(uint32Kw, type_spec$repeat_0)
|
|
822
|
+
| #uint64 type_spec.#uint64(uint64Kw, type_spec$repeat_0)
|
|
823
|
+
| #float32 type_spec.#float32(float32Kw, type_spec$repeat_0)
|
|
824
|
+
| #float64 type_spec.#float64(float64Kw, type_spec$repeat_0)
|
|
825
|
+
| #char type_spec.#char(charKw, type_spec$repeat_0)
|
|
826
|
+
| #named type_spec.#named(sym, type_spec$repeat_0)
|
|
827
|
+
| #array type_spec.#array(elem, size, open, close, type_spec$repeat_0)
|
|
828
|
+
| #arrayUnsized type_spec.#array(elem, open, close, type_spec$repeat_0) ;
|
|
829
|
+
|
|
830
|
+
type_spec$repeat_0 ->
|
|
831
|
+
#main flatten(type_spec.#pointers, ptr, type_spec$repeat_0) ;
|
|
832
|
+
|
|
833
|
+
block ->
|
|
834
|
+
#main block.#block(open, block$repeat_0, close) ;
|
|
835
|
+
|
|
836
|
+
block$repeat_0 ->
|
|
837
|
+
#main flatten(block.#block, stmt, block$repeat_0) ;
|
|
838
|
+
|
|
839
|
+
statement ->
|
|
840
|
+
#block pass(body)
|
|
841
|
+
| #varDecl statement.#varDecl(type, sym, init, semi)
|
|
842
|
+
| #if statement.#if(ifKw, cond, condition, condEnd, then, elseKw, elseBody)
|
|
843
|
+
| #while statement.#while(whileKw, cond, condition, condEnd, body)
|
|
844
|
+
| #for statement.#for(forKw, openFor, init, semi1, test, semi2, step, closeFor, body)
|
|
845
|
+
| #return statement.#return(returnKw, expr, semi)
|
|
846
|
+
| #break statement.#break(breakKw, semi)
|
|
847
|
+
| #continue statement.#continue(continueKw, semi)
|
|
848
|
+
| #exprStmt statement.#exprStmt(expr, semi) ;
|
|
849
|
+
|
|
850
|
+
var_init ->
|
|
851
|
+
#assign var_init.#assign(eqTok, value)
|
|
852
|
+
| #braceInit var_init.#braceInit(eqTok, open, values, close) ;
|
|
853
|
+
|
|
854
|
+
init_list ->
|
|
855
|
+
#main flatten(init_list.#list, first, init_list$repeat_0) ;
|
|
856
|
+
|
|
857
|
+
init_list$repeat_0 ->
|
|
858
|
+
#main flatten(init_list.#list, expr_sep, init_list$repeat_0) ;
|
|
859
|
+
|
|
860
|
+
expr_sep ->
|
|
861
|
+
#main expr_sep.#sep(commaTok, rest) ;
|
|
862
|
+
|
|
863
|
+
for_init ->
|
|
864
|
+
#var for_init.#var(type, sym, vinit)
|
|
865
|
+
| #expr pass(expr) ;
|
|
866
|
+
|
|
867
|
+
expression ->
|
|
868
|
+
#main pass(value) ;
|
|
869
|
+
|
|
870
|
+
assignment_expr ->
|
|
871
|
+
#plain pass(value)
|
|
872
|
+
| #assign assignment_expr.#assign(left, op, right) ;
|
|
873
|
+
|
|
874
|
+
assign_op ->
|
|
875
|
+
#eq pass(tok)
|
|
876
|
+
| #pluseq pass(tok)
|
|
877
|
+
| #minuseq pass(tok)
|
|
878
|
+
| #stareq pass(tok)
|
|
879
|
+
| #slasheq pass(tok)
|
|
880
|
+
| #ampeq pass(tok)
|
|
881
|
+
| #pipeeq pass(tok)
|
|
882
|
+
| #careteq pass(tok) ;
|
|
883
|
+
|
|
884
|
+
logical_or_expr ->
|
|
885
|
+
#single pass(value)
|
|
886
|
+
| #chain logical_or_expr.#chain(left, op, right) ;
|
|
887
|
+
|
|
888
|
+
logical_and_expr ->
|
|
889
|
+
#single pass(value)
|
|
890
|
+
| #chain logical_and_expr.#chain(left, op, right) ;
|
|
891
|
+
|
|
892
|
+
bitwise_or_expr ->
|
|
893
|
+
#single pass(value)
|
|
894
|
+
| #chain bitwise_or_expr.#chain(left, op, right) ;
|
|
895
|
+
|
|
896
|
+
bitwise_xor_expr ->
|
|
897
|
+
#single pass(value)
|
|
898
|
+
| #chain bitwise_xor_expr.#chain(left, op, right) ;
|
|
899
|
+
|
|
900
|
+
bitwise_and_expr ->
|
|
901
|
+
#single pass(value)
|
|
902
|
+
| #chain bitwise_and_expr.#chain(left, op, right) ;
|
|
903
|
+
|
|
904
|
+
equality_expr ->
|
|
905
|
+
#single pass(value)
|
|
906
|
+
| #chain equality_expr.#chain(head, op, tail) ;
|
|
907
|
+
|
|
908
|
+
equality_op ->
|
|
909
|
+
#eq pass(tok)
|
|
910
|
+
| #ne pass(tok) ;
|
|
911
|
+
|
|
912
|
+
relational_expr ->
|
|
913
|
+
#single pass(value)
|
|
914
|
+
| #chain relational_expr.#chain(head, op, tail) ;
|
|
915
|
+
|
|
916
|
+
relational_op ->
|
|
917
|
+
#lt pass(tok)
|
|
918
|
+
| #gt pass(tok)
|
|
919
|
+
| #le pass(tok)
|
|
920
|
+
| #ge pass(tok) ;
|
|
921
|
+
|
|
922
|
+
shift_expr ->
|
|
923
|
+
#single pass(value)
|
|
924
|
+
| #chain shift_expr.#chain(head, op, tail) ;
|
|
925
|
+
|
|
926
|
+
shift_op ->
|
|
927
|
+
#lshift pass(tok)
|
|
928
|
+
| #rshift pass(tok) ;
|
|
929
|
+
|
|
930
|
+
additive_expr ->
|
|
931
|
+
#single pass(value)
|
|
932
|
+
| #chain additive_expr.#chain(left, op, right) ;
|
|
933
|
+
|
|
934
|
+
additive_op ->
|
|
935
|
+
#plus pass(tok)
|
|
936
|
+
| #minus pass(tok) ;
|
|
937
|
+
|
|
938
|
+
multiplicative_expr ->
|
|
939
|
+
#single pass(value)
|
|
940
|
+
| #chain multiplicative_expr.#chain(left, op, right) ;
|
|
941
|
+
|
|
942
|
+
multiplicative_op ->
|
|
943
|
+
#star pass(tok)
|
|
944
|
+
| #slash pass(tok)
|
|
945
|
+
| #percent pass(tok) ;
|
|
946
|
+
|
|
947
|
+
unary_expr ->
|
|
948
|
+
#postfix pass(value)
|
|
949
|
+
| #cast unary_expr.#cast(open, type, close, value)
|
|
950
|
+
| #preInc unary_expr.#preInc(op, value)
|
|
951
|
+
| #preDec unary_expr.#preDec(op, value)
|
|
952
|
+
| #addr unary_expr.#addr(op, value)
|
|
953
|
+
| #deref unary_expr.#deref(op, value)
|
|
954
|
+
| #not unary_expr.#not(op, value)
|
|
955
|
+
| #bitNot unary_expr.#bitNot(op, value)
|
|
956
|
+
| #neg unary_expr.#neg(op, value)
|
|
957
|
+
| #plus unary_expr.#plus(op, value) ;
|
|
958
|
+
|
|
959
|
+
postfix_expr ->
|
|
960
|
+
#primary postfix_expr.#primary(value, postfix_expr$repeat_0) ;
|
|
961
|
+
|
|
962
|
+
postfix_expr$repeat_0 ->
|
|
963
|
+
#primary flatten(postfix_expr.#primary, suffix, postfix_expr$repeat_0) ;
|
|
964
|
+
|
|
965
|
+
postfix_suffix ->
|
|
966
|
+
#index postfix_suffix.#index(open, index, close)
|
|
967
|
+
| #call postfix_suffix.#call(open, close)
|
|
968
|
+
| #callArgs postfix_suffix.#call(open, args, close)
|
|
969
|
+
| #member postfix_suffix.#member(dotTok, sym)
|
|
970
|
+
| #arrow postfix_suffix.#arrow(arrowTok, sym)
|
|
971
|
+
| #postInc pass(op)
|
|
972
|
+
| #postDec pass(op) ;
|
|
973
|
+
|
|
974
|
+
arg_list ->
|
|
975
|
+
#main flatten(arg_list.#list, first, arg_list$repeat_0) ;
|
|
976
|
+
|
|
977
|
+
arg_list$repeat_0 ->
|
|
978
|
+
#main flatten(arg_list.#list, expr_sep, arg_list$repeat_0) ;
|
|
979
|
+
|
|
980
|
+
primary_expr ->
|
|
981
|
+
#ident pass(sym)
|
|
982
|
+
| #int pass(value)
|
|
983
|
+
| #float pass(value)
|
|
984
|
+
| #char pass(value)
|
|
985
|
+
| #string pass(value)
|
|
986
|
+
| #true pass(trueKw)
|
|
987
|
+
| #false pass(falseKw)
|
|
988
|
+
| #null pass(nullKw)
|
|
989
|
+
| #paren pass(inner)
|
|
990
|
+
| #new primary_expr.#new(newKw, type, open, close)
|
|
991
|
+
| #newArgs primary_expr.#new(newKw, type, open, args, close) ;
|