1 |
|
2 |
|
3 | (function () {
|
4 | function id(x) { return x[0]; }
|
5 |
|
6 | const lexer = require('./lex').lexer;
|
7 | const util = require('./parser-util');
|
8 | var grammar = {
|
9 | Lexer: lexer,
|
10 | ParserRules: [
|
11 | {"name": "Expression", "symbols": ["Exp0"], "postprocess": id},
|
12 | {"name": "Identifier", "symbols": [(lexer.has("identifier") ? {type: "identifier"} : identifier)], "postprocess": util.Identifier},
|
13 | {"name": "TypeIdentifier", "symbols": [(lexer.has("type_identifier") ? {type: "type_identifier"} : type_identifier)], "postprocess": util.Identifier},
|
14 | {"name": "StructName", "symbols": [(lexer.has("identifier") ? {type: "identifier"} : identifier)], "postprocess": util.Identifier},
|
15 | {"name": "StructName", "symbols": [(lexer.has("type_identifier") ? {type: "type_identifier"} : type_identifier)], "postprocess": util.Identifier},
|
16 | {"name": "FieldName", "symbols": [(lexer.has("identifier") ? {type: "identifier"} : identifier)], "postprocess": util.Identifier},
|
17 | {"name": "FieldName", "symbols": [(lexer.has("type_identifier") ? {type: "type_identifier"} : type_identifier)], "postprocess": util.Identifier},
|
18 | {"name": "Unop", "symbols": [{"literal":"!"}]},
|
19 | {"name": "Unop", "symbols": [{"literal":"~"}]},
|
20 | {"name": "Unop", "symbols": [{"literal":"-"}]},
|
21 | {"name": "Unop", "symbols": [{"literal":"*"}]},
|
22 | {"name": "Unop", "symbols": [{"literal":"&"}]},
|
23 | {"name": "Unop", "symbols": [{"literal":"("}, "_", "Tp", "_", {"literal":")"}]},
|
24 | {"name": "BinopB", "symbols": [{"literal":"*"}]},
|
25 | {"name": "BinopB", "symbols": [{"literal":"/"}]},
|
26 | {"name": "BinopB", "symbols": [{"literal":"%"}]},
|
27 | {"name": "BinopA", "symbols": [{"literal":"+"}]},
|
28 | {"name": "BinopA", "symbols": [{"literal":"-"}]},
|
29 | {"name": "Binop9", "symbols": [{"literal":"<"}, {"literal":"<"}]},
|
30 | {"name": "Binop9", "symbols": [{"literal":">"}, {"literal":">"}]},
|
31 | {"name": "Binop8", "symbols": [{"literal":"<"}]},
|
32 | {"name": "Binop8", "symbols": [{"literal":"<"}, {"literal":"="}]},
|
33 | {"name": "Binop8", "symbols": [{"literal":">"}, {"literal":"="}]},
|
34 | {"name": "Binop8", "symbols": [{"literal":">"}]},
|
35 | {"name": "Binop7", "symbols": [{"literal":"="}, {"literal":"="}]},
|
36 | {"name": "Binop7", "symbols": [{"literal":"!"}, {"literal":"="}]},
|
37 | {"name": "Binop6", "symbols": [{"literal":"&"}]},
|
38 | {"name": "Binop5", "symbols": [{"literal":"^"}]},
|
39 | {"name": "Binop4", "symbols": [{"literal":"|"}]},
|
40 | {"name": "Binop3", "symbols": [{"literal":"&&"}]},
|
41 | {"name": "Binop2", "symbols": [{"literal":"|"}, {"literal":"|"}]},
|
42 | {"name": "Binop1", "symbols": [{"literal":"?"}]},
|
43 | {"name": "Binop0", "symbols": [{"literal":"="}]},
|
44 | {"name": "Binop0", "symbols": [{"literal":"+"}, {"literal":"="}]},
|
45 | {"name": "Binop0", "symbols": [{"literal":"-"}, {"literal":"="}]},
|
46 | {"name": "Binop0", "symbols": [{"literal":"*"}, {"literal":"="}]},
|
47 | {"name": "Binop0", "symbols": [{"literal":"/"}, {"literal":"="}]},
|
48 | {"name": "Binop0", "symbols": [{"literal":"%"}, {"literal":"="}]},
|
49 | {"name": "Binop0", "symbols": [{"literal":"&"}, {"literal":"="}]},
|
50 | {"name": "Binop0", "symbols": [{"literal":"^"}, {"literal":"="}]},
|
51 | {"name": "Binop0", "symbols": [{"literal":"|"}, {"literal":"="}]},
|
52 | {"name": "Binop0", "symbols": [{"literal":"<"}, {"literal":"<"}, {"literal":"="}]},
|
53 | {"name": "Binop0", "symbols": [{"literal":">"}, {"literal":">"}, {"literal":"="}]},
|
54 | {"name": "ExpD", "symbols": [{"literal":"("}, "_", "Expression", "_", {"literal":")"}], "postprocess": x => x[2]},
|
55 | {"name": "ExpD", "symbols": [(lexer.has("numeric_literal") ? {type: "numeric_literal"} : numeric_literal)], "postprocess": util.IntLiteral},
|
56 | {"name": "ExpD", "symbols": ["StringLiteral"], "postprocess": util.StringLiteral},
|
57 | {"name": "ExpD", "symbols": ["CharLiteral"], "postprocess": util.CharLiteral},
|
58 | {"name": "ExpD", "symbols": [{"literal":"true"}], "postprocess": util.BoolLiteral},
|
59 | {"name": "ExpD", "symbols": [{"literal":"false"}], "postprocess": util.BoolLiteral},
|
60 | {"name": "ExpD", "symbols": [{"literal":"NULL"}], "postprocess": util.NullLiteral},
|
61 | {"name": "ExpD", "symbols": ["Identifier"], "postprocess": id},
|
62 | {"name": "ExpD", "symbols": ["Identifier", "_", "Funargs"], "postprocess": util.CallExpression},
|
63 | {"name": "ExpD", "symbols": ["ExpD", "_", {"literal":"."}, "_", "FieldName"], "postprocess": util.StructMemberExpression},
|
64 | {"name": "ExpD$subexpression$1", "symbols": [{"literal":"-"}, {"literal":">"}]},
|
65 | {"name": "ExpD", "symbols": ["ExpD", "_", "ExpD$subexpression$1", "_", "FieldName"], "postprocess": util.StructMemberExpression},
|
66 | {"name": "ExpD", "symbols": ["ExpD", "_", {"literal":"["}, "_", "Expression", "_", {"literal":"]"}], "postprocess": util.ArrayMemberExpression},
|
67 | {"name": "ExpD", "symbols": ["ExpD", "_", {"literal":"+"}, {"literal":"+"}], "postprocess": util.UpdateExpression},
|
68 | {"name": "ExpD", "symbols": ["ExpD", "_", {"literal":"-"}, {"literal":"-"}], "postprocess": util.UpdateExpression},
|
69 | {"name": "ExpD", "symbols": [{"literal":"alloc"}, "_", {"literal":"("}, "_", "Tp", "_", {"literal":")"}], "postprocess": util.AllocExpression},
|
70 | {"name": "ExpD", "symbols": [{"literal":"alloc_array"}, "_", {"literal":"("}, "_", "Tp", "_", {"literal":","}, "_", "Expression", "_", {"literal":")"}], "postprocess": util.AllocArrayExpression},
|
71 | {"name": "ExpD", "symbols": [{"literal":"assert"}, "_", {"literal":"("}, "_", "Expression", "_", {"literal":")"}], "postprocess": util.AssertExpression},
|
72 | {"name": "ExpD", "symbols": [{"literal":"error"}, "_", {"literal":"("}, "_", "Expression", "_", {"literal":")"}], "postprocess": util.ErrorExpression},
|
73 | {"name": "ExpD", "symbols": [{"literal":"\\"}, {"literal":"result"}], "postprocess": util.ResultExpression},
|
74 | {"name": "ExpD", "symbols": [{"literal":"\\"}, {"literal":"length"}, "_", {"literal":"("}, "_", "Expression", "_", {"literal":")"}], "postprocess": util.LengthExpression},
|
75 | {"name": "ExpD", "symbols": [{"literal":"\\"}, {"literal":"hastag"}, "_", {"literal":"("}, "_", "Tp", "_", {"literal":","}, "_", "Expression", "_", {"literal":")"}], "postprocess": util.HasTagExpression},
|
76 | {"name": "ExpD", "symbols": [{"literal":"("}, "_", {"literal":"*"}, "_", "Expression", "_", {"literal":")"}, "_", "Funargs"], "postprocess": util.IndirectCallExpression},
|
77 | {"name": "ExpC", "symbols": ["ExpD"], "postprocess": id},
|
78 | {"name": "ExpC", "symbols": ["Unop", "_", "ExpC"], "postprocess": util.UnaryExpression},
|
79 | {"name": "ExpB", "symbols": ["ExpC"], "postprocess": id},
|
80 | {"name": "ExpB", "symbols": ["ExpC", "_", "BinopB", "_", "ExpB"], "postprocess": util.BinaryExpression},
|
81 | {"name": "ExpA", "symbols": ["ExpB"], "postprocess": id},
|
82 | {"name": "ExpA", "symbols": ["ExpB", "_", "BinopA", "_", "ExpA"], "postprocess": util.BinaryExpression},
|
83 | {"name": "Exp9", "symbols": ["ExpA"], "postprocess": id},
|
84 | {"name": "Exp9", "symbols": ["ExpA", "_", "Binop9", "_", "Exp9"], "postprocess": util.BinaryExpression},
|
85 | {"name": "Exp8", "symbols": ["Exp9"], "postprocess": id},
|
86 | {"name": "Exp8", "symbols": ["Exp9", "_", "Binop8", "_", "Exp8"], "postprocess": util.BinaryExpression},
|
87 | {"name": "Exp7", "symbols": ["Exp8"], "postprocess": id},
|
88 | {"name": "Exp7", "symbols": ["Exp8", "_", "Binop7", "_", "Exp7"], "postprocess": util.BinaryExpression},
|
89 | {"name": "Exp6", "symbols": ["Exp7"], "postprocess": id},
|
90 | {"name": "Exp6", "symbols": ["Exp7", "_", "Binop6", "_", "Exp6"], "postprocess": util.BinaryExpression},
|
91 | {"name": "Exp5", "symbols": ["Exp6"], "postprocess": id},
|
92 | {"name": "Exp5", "symbols": ["Exp6", "_", "Binop5", "_", "Exp5"], "postprocess": util.BinaryExpression},
|
93 | {"name": "Exp4", "symbols": ["Exp5"], "postprocess": id},
|
94 | {"name": "Exp4", "symbols": ["Exp5", "_", "Binop4", "_", "Exp4"], "postprocess": util.BinaryExpression},
|
95 | {"name": "Exp3", "symbols": ["Exp4"], "postprocess": id},
|
96 | {"name": "Exp3", "symbols": ["Exp4", "_", "Binop3", "_", "Exp3"], "postprocess": util.BinaryExpression},
|
97 | {"name": "Exp2", "symbols": ["Exp3"], "postprocess": id},
|
98 | {"name": "Exp2", "symbols": ["Exp3", "_", "Binop2", "_", "Exp2"], "postprocess": util.BinaryExpression},
|
99 | {"name": "Exp1", "symbols": ["Exp2"], "postprocess": id},
|
100 | {"name": "Exp1", "symbols": ["Exp2", "_", "Binop1", "_", "Expression", "_", {"literal":":"}, "_", "Exp1"], "postprocess": util.ConditionalExpression},
|
101 | {"name": "Exp0", "symbols": ["Exp1"], "postprocess": id},
|
102 | {"name": "Exp0", "symbols": ["Exp1", "_", "Binop0", "_", "Exp0"], "postprocess": util.BinaryExpression},
|
103 | {"name": "Funargs$ebnf$1$subexpression$1$ebnf$1", "symbols": []},
|
104 | {"name": "Funargs$ebnf$1$subexpression$1$ebnf$1$subexpression$1", "symbols": [{"literal":","}, "_", "Expression"]},
|
105 | {"name": "Funargs$ebnf$1$subexpression$1$ebnf$1", "symbols": ["Funargs$ebnf$1$subexpression$1$ebnf$1", "Funargs$ebnf$1$subexpression$1$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
|
106 | {"name": "Funargs$ebnf$1$subexpression$1", "symbols": ["Expression", "_", "Funargs$ebnf$1$subexpression$1$ebnf$1"]},
|
107 | {"name": "Funargs$ebnf$1", "symbols": ["Funargs$ebnf$1$subexpression$1"], "postprocess": id},
|
108 | {"name": "Funargs$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
|
109 | {"name": "Funargs", "symbols": [{"literal":"("}, "_", "Funargs$ebnf$1", {"literal":")"}]},
|
110 | {"name": "Tp", "symbols": [{"literal":"int"}], "postprocess": util.IntType},
|
111 | {"name": "Tp", "symbols": [{"literal":"bool"}], "postprocess": util.BoolType},
|
112 | {"name": "Tp", "symbols": [{"literal":"string"}], "postprocess": util.StringType},
|
113 | {"name": "Tp", "symbols": [{"literal":"char"}], "postprocess": util.CharType},
|
114 | {"name": "Tp", "symbols": [{"literal":"void"}], "postprocess": util.VoidType},
|
115 | {"name": "Tp", "symbols": ["Tp", "_", {"literal":"*"}], "postprocess": util.PointerType},
|
116 | {"name": "Tp", "symbols": ["Tp", "_", {"literal":"["}, "_", {"literal":"]"}], "postprocess": util.ArrayType},
|
117 | {"name": "Tp", "symbols": [{"literal":"struct"}, "_", "StructName"], "postprocess": util.StructType},
|
118 | {"name": "Tp", "symbols": ["TypeIdentifier"], "postprocess": id},
|
119 | {"name": "StringLiteral$ebnf$1", "symbols": []},
|
120 | {"name": "StringLiteral$ebnf$1$subexpression$1", "symbols": [(lexer.has("special_character") ? {type: "special_character"} : special_character)]},
|
121 | {"name": "StringLiteral$ebnf$1$subexpression$1", "symbols": [(lexer.has("characters") ? {type: "characters"} : characters)]},
|
122 | {"name": "StringLiteral$ebnf$1", "symbols": ["StringLiteral$ebnf$1", "StringLiteral$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
|
123 | {"name": "StringLiteral", "symbols": [(lexer.has("string_delimiter") ? {type: "string_delimiter"} : string_delimiter), "StringLiteral$ebnf$1", (lexer.has("string_delimiter") ? {type: "string_delimiter"} : string_delimiter)]},
|
124 | {"name": "CharLiteral$subexpression$1", "symbols": [(lexer.has("special_character") ? {type: "special_character"} : special_character)]},
|
125 | {"name": "CharLiteral$subexpression$1", "symbols": [(lexer.has("character") ? {type: "character"} : character)]},
|
126 | {"name": "CharLiteral", "symbols": [(lexer.has("char_delimiter") ? {type: "char_delimiter"} : char_delimiter), "CharLiteral$subexpression$1", (lexer.has("char_delimiter") ? {type: "char_delimiter"} : char_delimiter)]},
|
127 | {"name": "_$ebnf$1", "symbols": []},
|
128 | {"name": "_$ebnf$1$subexpression$1", "symbols": [(lexer.has("whitespace") ? {type: "whitespace"} : whitespace)]},
|
129 | {"name": "_$ebnf$1$subexpression$1", "symbols": [(lexer.has("newline") ? {type: "newline"} : newline)]},
|
130 | {"name": "_$ebnf$1$subexpression$1", "symbols": [(lexer.has("annospace") ? {type: "annospace"} : annospace)]},
|
131 | {"name": "_$ebnf$1$subexpression$1", "symbols": ["LineComment"]},
|
132 | {"name": "_$ebnf$1$subexpression$1", "symbols": ["MultiComment"]},
|
133 | {"name": "_$ebnf$1", "symbols": ["_$ebnf$1", "_$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
|
134 | {"name": "_", "symbols": ["_$ebnf$1"]},
|
135 | {"name": "LineComment$ebnf$1", "symbols": []},
|
136 | {"name": "LineComment$ebnf$1", "symbols": ["LineComment$ebnf$1", (lexer.has("comment") ? {type: "comment"} : comment)], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
|
137 | {"name": "LineComment", "symbols": [(lexer.has("comment_line_start") ? {type: "comment_line_start"} : comment_line_start), "LineComment$ebnf$1", (lexer.has("comment_line_end") ? {type: "comment_line_end"} : comment_line_end)]},
|
138 | {"name": "MultiComment$ebnf$1", "symbols": []},
|
139 | {"name": "MultiComment$ebnf$1$subexpression$1", "symbols": [(lexer.has("comment") ? {type: "comment"} : comment)]},
|
140 | {"name": "MultiComment$ebnf$1$subexpression$1", "symbols": [(lexer.has("newline") ? {type: "newline"} : newline)]},
|
141 | {"name": "MultiComment$ebnf$1$subexpression$1", "symbols": ["MultiComment"]},
|
142 | {"name": "MultiComment$ebnf$1", "symbols": ["MultiComment$ebnf$1", "MultiComment$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
|
143 | {"name": "MultiComment", "symbols": [(lexer.has("comment_start") ? {type: "comment_start"} : comment_start), "MultiComment$ebnf$1", (lexer.has("comment_end") ? {type: "comment_end"} : comment_end)]}
|
144 | ]
|
145 | , ParserStart: "Expression"
|
146 | }
|
147 | if (typeof module !== 'undefined'&& typeof module.exports !== 'undefined') {
|
148 | module.exports = grammar;
|
149 | } else {
|
150 | window.grammar = grammar;
|
151 | }
|
152 | })();
|