@sormy/lemon-js 1.0.1

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/lempar.js ADDED
@@ -0,0 +1,779 @@
1
+ /*
2
+ ** Generated by lemon-js. Changes belong in the grammar this came from, since
3
+ ** anything written here is lost the next time it is generated.
4
+ **
5
+ *************************************************************************
6
+ ** 2000-05-29
7
+ **
8
+ ** The author disclaims copyright to this source code. In place of
9
+ ** a legal notice, here is a blessing:
10
+ **
11
+ ** May you do good and not evil.
12
+ ** May you find forgiveness for yourself and forgive others.
13
+ ** May you share freely, never taking more than you give.
14
+ **
15
+ ** Based on SQLite distribution v3.17.0
16
+ ** Adopted for JavaScript by Artem Butusov <art.sormy@gmail.com>
17
+ **
18
+ *************************************************************************
19
+ ** Driver template for the LEMON parser generator.
20
+ **
21
+ ** The "lemon" program processes an LALR(1) input grammar file, then uses
22
+ ** this template to construct a parser. The "lemon" program inserts text
23
+ ** at each "%%" line. Also, any "P-a-r-s-e" identifer prefix (without the
24
+ ** interstitial "-" characters) contained in this template is changed into
25
+ ** the value of the %name directive from the grammar. Otherwise, the content
26
+ ** of this template is copied straight through into the generate parser
27
+ ** source file.
28
+ **
29
+ ** The following is the concatenation of all %include directives from the
30
+ ** input grammar file:
31
+ */
32
+ /************ Begin %include sections from the grammar ************************/
33
+ %%
34
+ /**************** End of %include directives **********************************/
35
+ function Parse() {
36
+ /* These constants specify the various numeric values for terminal symbols
37
+ ** in a format understandable to "makeheaders".
38
+ ***************** Begin makeheaders token definitions *************************/
39
+ %%
40
+ /**************** End makeheaders token definitions ***************************/
41
+
42
+ /* The next sections is a series of control #defines.
43
+ ** various aspects of the generated parser.
44
+ ** YYNOCODE is a number of type YYCODETYPE that is not used for
45
+ ** any terminal or nonterminal symbol.
46
+ ** YYFALLBACK If defined, this indicates that one or more tokens
47
+ ** (also known as: "terminal symbols") have fall-back
48
+ ** values which should be used if the original symbol
49
+ ** would not parse. This permits keywords to sometimes
50
+ ** be used as identifiers, for example.
51
+ ** YYSTACKDEPTH is the maximum depth of the parser's stack. If
52
+ ** zero the stack is dynamically sized using realloc()
53
+ ** YYERRORSYMBOL is the code number of the error symbol. If not
54
+ ** defined, then do no error processing.
55
+ ** YYNSTATE the combined number of states.
56
+ ** YYNRULE the number of rules in the grammar
57
+ ** YY_MAX_SHIFT Maximum value for shift actions
58
+ ** YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions
59
+ ** YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions
60
+ ** YY_MIN_REDUCE Maximum value for reduce actions
61
+ ** YY_ERROR_ACTION The yy_action[] code for syntax error
62
+ ** YY_ACCEPT_ACTION The yy_action[] code for accept
63
+ ** YY_NO_ACTION The yy_action[] code for no-op
64
+ */
65
+ /************* Begin control #defines *****************************************/
66
+ %%
67
+ /************* End control #defines *******************************************/
68
+
69
+ /* Define the yytestcase() macro to be a no-op if is not already defined
70
+ ** otherwise.
71
+ **
72
+ ** Applications can choose to define yytestcase() in the %include section
73
+ ** to a macro that can assist in verifying code coverage. For production
74
+ ** code the yytestcase() macro should be turned off. But it is useful
75
+ ** for testing.
76
+ */
77
+ if (!this.yytestcase) {
78
+ this.yytestcase = function () {};
79
+ }
80
+
81
+
82
+ /* Next are the tables used to determine what action to take based on the
83
+ ** current state and lookahead token. These tables are used to implement
84
+ ** functions that take a state number and lookahead value and return an
85
+ ** action integer.
86
+ **
87
+ ** Suppose the action integer is N. Then the action is determined as
88
+ ** follows
89
+ **
90
+ ** 0 <= N <= YY_MAX_SHIFT Shift N. That is, push the lookahead
91
+ ** token onto the stack and goto state N.
92
+ **
93
+ ** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
94
+ ** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE.
95
+ **
96
+ ** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE
97
+ ** and YY_MAX_REDUCE
98
+ **
99
+ ** N == YY_ERROR_ACTION A syntax error has occurred.
100
+ **
101
+ ** N == YY_ACCEPT_ACTION The parser accepts its input.
102
+ **
103
+ ** N == YY_NO_ACTION No such action. Denotes unused
104
+ ** slots in the yy_action[] table.
105
+ **
106
+ ** The action table is constructed as a single large table named yy_action[].
107
+ ** Given state S and lookahead X, the action is computed as either:
108
+ **
109
+ ** (A) N = yy_action[ yy_shift_ofst[S] + X ]
110
+ ** (B) N = yy_default[S]
111
+ **
112
+ ** The (A) formula is preferred. The B formula is used instead if:
113
+ ** (1) The yy_shift_ofst[S]+X value is out of range, or
114
+ ** (2) yy_lookahead[yy_shift_ofst[S]+X] is not equal to X, or
115
+ ** (3) yy_shift_ofst[S] equal YY_SHIFT_USE_DFLT.
116
+ ** (Implementation note: YY_SHIFT_USE_DFLT is chosen so that
117
+ ** YY_SHIFT_USE_DFLT+X will be out of range for all possible lookaheads X.
118
+ ** Hence only tests (1) and (2) need to be evaluated.)
119
+ **
120
+ ** The formulas above are for computing the action when the lookahead is
121
+ ** a terminal symbol. If the lookahead is a non-terminal (as occurs after
122
+ ** a reduce action) then the yy_reduce_ofst[] array is used in place of
123
+ ** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of
124
+ ** YY_SHIFT_USE_DFLT.
125
+ **
126
+ ** The following are the tables generated in this section:
127
+ **
128
+ ** yy_action[] A single table containing all actions.
129
+ ** yy_lookahead[] A table containing the lookahead for each entry in
130
+ ** yy_action. Used to detect hash collisions.
131
+ ** yy_shift_ofst[] For each state, the offset into yy_action for
132
+ ** shifting terminals.
133
+ ** yy_reduce_ofst[] For each state, the offset into yy_action for
134
+ ** shifting non-terminals after a reduce.
135
+ ** yy_default[] Default action for each state.
136
+ **
137
+ *********** Begin parsing tables **********************************************/
138
+ %%
139
+ /********** End of lemon-generated parsing tables *****************************/
140
+
141
+ /* The next table maps tokens (terminal symbols) into fallback tokens.
142
+ ** If a construct like the following:
143
+ **
144
+ ** %fallback ID X Y Z.
145
+ **
146
+ ** appears in the grammar, then ID becomes a fallback token for X, Y,
147
+ ** and Z. Whenever one of the tokens X, Y, or Z is input to the parser
148
+ ** but it does not parse, the type of the token is changed to ID and
149
+ ** the parse is retried before an error is thrown.
150
+ **
151
+ ** This feature can be used, for example, to cause some keywords in a language
152
+ ** to revert to identifiers if they keyword does not apply in the context where
153
+ ** it appears.
154
+ */
155
+ this.yyFallback = [
156
+ %%
157
+ ];
158
+
159
+ /* The following structure represents a single element of the
160
+ ** parser's stack. Information stored includes:
161
+ **
162
+ ** + The state number for the parser at this level of the stack.
163
+ **
164
+ ** + The value of the token stored at this level of the stack.
165
+ ** (In other words, the "major" token.)
166
+ **
167
+ ** + The semantic value stored at this level of the stack. This is
168
+ ** the information used by the action routines in the grammar.
169
+ ** It is sometimes called the "minor" token.
170
+ **
171
+ ** After the "shift" half of a SHIFTREDUCE action, the stateno field
172
+ ** actually contains the reduce action for the second half of the
173
+ ** SHIFTREDUCE.
174
+ */
175
+ //{
176
+ // stateno, /* The state-number, or reduce action in SHIFTREDUCE */
177
+ // major, /* The major token value. This is the code
178
+ // ** number for the token at this stack level */
179
+ // minor, /* The user-supplied minor token value. This
180
+ // ** is the value of the token */
181
+ //}
182
+
183
+ /* The state of the parser is completely contained in an instance of
184
+ ** the following structure */
185
+ this.yyhwm = 0; /* High-water mark of the stack */
186
+ this.yyerrcnt = -1; /* Shifts left before out of the error */
187
+ this.yystack = null; /* The parser's stack */
188
+ this.yyidx = -1; /* Stack index of current element in the stack */
189
+
190
+ this.yyTraceCallback = null;
191
+ this.yyTracePrompt = "";
192
+
193
+ /*
194
+ ** Turn parser tracing on by giving a stream to which to write the trace
195
+ ** and a prompt to preface each trace message. Tracing is turned off
196
+ ** by making either argument NULL
197
+ **
198
+ ** Inputs:
199
+ ** <ul>
200
+ ** <li> A callback to which trace output should be written.
201
+ ** If NULL, then tracing is turned off.
202
+ ** <li> A prefix string written at the beginning of every
203
+ ** line of trace output. Default is "".
204
+ ** </ul>
205
+ **
206
+ ** Outputs:
207
+ ** None.
208
+ */
209
+ this.setTraceCallback = function (callback, prompt) {
210
+ this.yyTraceCallback = callback;
211
+ this.yyTracePrompt = prompt || "";
212
+ }
213
+
214
+ this.trace = function (message) {
215
+ this.yyTraceCallback(this.yyTracePrompt + message + "\n");
216
+ }
217
+
218
+ /* For tracing shifts, the names of all terminals and nonterminals
219
+ ** are required. The following table supplies these names */
220
+ this.yyTokenName = [
221
+ %%
222
+ ];
223
+
224
+ /* For tracing reduce actions, the names of all rules are required.
225
+ */
226
+ this.yyRuleName = [
227
+ %%
228
+ ];
229
+ /*
230
+ ** Try to increase the size of the parser stack. Return the number
231
+ ** of errors. Return 0 on success.
232
+ */
233
+ this.yyGrowStack = function () {
234
+ // fix me: yystksz*2 + 100
235
+ this.yystack.push({
236
+ stateno: undefined,
237
+ major: undefined,
238
+ minor: undefined
239
+ });
240
+ }
241
+
242
+ /* Initialize a new parser that has already been allocated.
243
+ */
244
+ this.init = function () {
245
+ this.yyhwm = 0;
246
+ this.yyerrcnt = -1;
247
+ this.yyidx = 0;
248
+ if (this.YYSTACKDEPTH <= 0) {
249
+ this.yystack = [];
250
+ this.yyGrowStack();
251
+ } else {
252
+ this.yystack = new Array(this.YYSTACKDEPTH);
253
+ for (var i = 0; i < this.YYSTACKDEPTH; i++) {
254
+ this.yystack[i] = {
255
+ stateno: undefined,
256
+ major: undefined,
257
+ minor: undefined
258
+ };
259
+ }
260
+ }
261
+ var yytos = this.yystack[0];
262
+ yytos.stateno = 0;
263
+ yytos.major = 0;
264
+ }
265
+
266
+ /* The following function deletes the "minor type" or semantic value
267
+ ** associated with a symbol. The symbol can be either a terminal
268
+ ** or nonterminal. "yymajor" is the symbol code, and "yypminor" is
269
+ ** a pointer to the value to be deleted. The code used to do the
270
+ ** deletions is derived from the %destructor and/or %token_destructor
271
+ ** directives of the input grammar.
272
+ */
273
+ this.yy_destructor = function (
274
+ yymajor, /* Type code for object to destroy */
275
+ yyminor /* The object to be destroyed */
276
+ ) {
277
+ switch (yymajor) {
278
+ /* Here is inserted the actions which take place when a
279
+ ** terminal or non-terminal is destroyed. This can happen
280
+ ** when the symbol is popped from the stack during a
281
+ ** reduce or during error processing or when a parser is
282
+ ** being destroyed before it is finished parsing.
283
+ **
284
+ ** Note: during a reduce, the only symbols destroyed are those
285
+ ** which appear on the RHS of the rule, but which are *not* used
286
+ ** inside the C code.
287
+ */
288
+ /********* Begin destructor definitions ***************************************/
289
+ %%
290
+ /********* End destructor definitions *****************************************/
291
+ default: break; /* If no destructor action specified: do nothing */
292
+ }
293
+ }
294
+
295
+ /*
296
+ ** Pop the parser's stack once.
297
+ **
298
+ ** If there is a destructor routine associated with the token which
299
+ ** is popped from the stack, then call it.
300
+ */
301
+ this.yy_pop_parser_stack = function () {
302
+ // assert( pParser->yytos!=0 );
303
+ // assert( pParser->yytos > pParser->yystack );
304
+ var yytos = this.yystack[this.yyidx];
305
+
306
+ if (this.yyTraceCallback) {
307
+ this.trace("Popping " + this.yyTokenName[yytos.major]);
308
+ }
309
+ this.yy_destructor(yytos.major, yytos.minor);
310
+
311
+ this.yyidx--;
312
+ }
313
+
314
+ /*
315
+ ** Clear all secondary memory allocations from the parser
316
+ */
317
+ this.finalize = function () {
318
+ while (this.yyidx > 0) {
319
+ this.yy_pop_parser_stack();
320
+ }
321
+ this.yystack = null;
322
+ }
323
+
324
+ /*
325
+ ** Return the peak depth of the stack for a parser.
326
+ */
327
+ this.getStackPeak = function () {
328
+ return this.yyhwm;
329
+ }
330
+
331
+ /*
332
+ ** Find the appropriate action for a parser given the terminal
333
+ ** look-ahead token iLookAhead.
334
+ */
335
+ this.yy_find_shift_action = function (
336
+ iLookAhead /* The look-ahead token */
337
+ ) {
338
+ var yytos = this.yystack[this.yyidx];
339
+ var stateno = yytos.stateno;
340
+
341
+ if (stateno >= this.YY_MIN_REDUCE) {
342
+ return stateno;
343
+ }
344
+
345
+ // assert( stateno <= YY_SHIFT_COUNT );
346
+
347
+ do {
348
+ var i = this.yy_shift_ofst[stateno];
349
+ // assert( iLookAhead!=YYNOCODE );
350
+ i += iLookAhead;
351
+ if (i < 0 || i >= this.yy_action.length || this.yy_lookahead[i] != iLookAhead) {
352
+ if (this.YYFALLBACK) {
353
+ var iFallback; /* Fallback token */
354
+ if ((iLookAhead < this.yyFallback.length)
355
+ && (iFallback = this.yyFallback[iLookAhead]) != 0
356
+ ) {
357
+ if (this.yyTraceCallback) {
358
+ this.trace("FALLBACK " + this.yyTokenName[iLookAhead] + " => " + this.yyTokenName[iFallback]);
359
+ }
360
+ }
361
+ // assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
362
+ iLookAhead = iFallback;
363
+ continue;
364
+ }
365
+
366
+ if (this.YYWILDCARD) {
367
+ var j = i - iLookAhead + this.YYWILDCARD;
368
+ var cond1 = (this.YY_SHIFT_MIN + this.YYWILDCARD) < 0 ? j >= 0 : true;
369
+ var cond2 = (this.YY_SHIFT_MAX + this.YYWILDCARD) >= this.yy_action.length ? j < this.yy_action.length : true;
370
+ if (cond1 && cond2 && this.yy_lookahead[j] == this.YYWILDCARD && iLookAhead > 0) {
371
+ if (this.yyTraceCallback) {
372
+ this.trace("WILDCARD " + this.yyTokenName[iLookAhead] + " => " + this.yyTokenName[this.YYWILDCARD]);
373
+ }
374
+ return this.yy_action[j];
375
+ }
376
+ }
377
+
378
+ return this.yy_default[stateno];
379
+ } else {
380
+ return this.yy_action[i];
381
+ }
382
+ } while (true);
383
+ }
384
+
385
+ /*
386
+ ** Find the appropriate action for a parser given the non-terminal
387
+ ** look-ahead token iLookAhead.
388
+ */
389
+ this.yy_find_reduce_action = function (
390
+ stateno, /* Current state number */
391
+ iLookAhead /* The look-ahead token */
392
+ ) {
393
+ if (this.YYERRORSYMBOL) {
394
+ if (stateno > this.YY_REDUCE_COUNT) {
395
+ return this.yy_default[stateno];
396
+ }
397
+ } else {
398
+ // assert( stateno<=YY_REDUCE_COUNT );
399
+ }
400
+
401
+ var i = this.yy_reduce_ofst[stateno];
402
+ // assert( i!=YY_REDUCE_USE_DFLT );
403
+ // assert( iLookAhead!=YYNOCODE );
404
+ i += iLookAhead;
405
+
406
+ if (this.YYERRORSYMBOL) {
407
+ if (i < 0 || i >= this.yy_action.length || this.yy_lookahead[i] != iLookAhead) {
408
+ return this.yy_default[stateno];
409
+ }
410
+ } else {
411
+ // assert( i>=0 && i<YY_ACTTAB_COUNT );
412
+ // assert( yy_lookahead[i]==iLookAhead );
413
+ }
414
+
415
+ return this.yy_action[i];
416
+ }
417
+
418
+ /*
419
+ ** The following routine is called if the stack overflows.
420
+ */
421
+ this.yyStackOverflow = function () {
422
+ if (this.yyTraceCallback) {
423
+ this.trace("Stack Overflow!");
424
+ }
425
+
426
+ while (this.yyidx > 0) {
427
+ this.yy_pop_parser_stack();
428
+ }
429
+ /* Here code is inserted which will execute if the parser
430
+ ** stack every overflows */
431
+ /******** Begin %stack_overflow code ******************************************/
432
+ %%
433
+ /******** End %stack_overflow code ********************************************/
434
+ }
435
+
436
+ /*
437
+ ** Print tracing information for a SHIFT action
438
+ */
439
+ this.yyTraceShift = function (yyNewState) {
440
+ if (this.yyTraceCallback) {
441
+ var yytos = this.yystack[this.yyidx];
442
+ if (yyNewState < this.YYNSTATE) {
443
+ this.trace("Shift '" + this.yyTokenName[yytos.major] + "', go to state " + yyNewState);
444
+ } else {
445
+ this.trace("Shift '" + this.yyTokenName[yytos.major] + "'");
446
+ }
447
+ }
448
+ }
449
+
450
+ /*
451
+ ** Perform a shift action.
452
+ */
453
+ this.yy_shift = function (
454
+ yyNewState, /* The new state to shift in */
455
+ yyMajor, /* The major token to shift in */
456
+ yyMinor /* The minor token to shift in */
457
+ ) {
458
+ this.yyidx++;
459
+
460
+ if (this.yyidx > this.yyhwm) {
461
+ this.yyhwm++;
462
+ // assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) );
463
+ }
464
+
465
+ if (this.YYSTACKDEPTH > 0) {
466
+ if (this.yyidx >= this.YYSTACKDEPTH) {
467
+ this.yyidx--;
468
+ this.yyStackOverflow();
469
+ return;
470
+ }
471
+ } else {
472
+ if (this.yyidx >= this.yystack.length) {
473
+ this.yyGrowStack();
474
+ }
475
+ }
476
+
477
+ if (yyNewState > this.YY_MAX_SHIFT) {
478
+ yyNewState += this.YY_MIN_REDUCE - this.YY_MIN_SHIFTREDUCE;
479
+ }
480
+
481
+ var yytos = this.yystack[this.yyidx];
482
+ yytos.stateno = yyNewState;
483
+ yytos.major = yyMajor;
484
+ yytos.minor = yyMinor;
485
+
486
+ this.yyTraceShift(yyNewState);
487
+ }
488
+
489
+ /* The following table contains information about every rule that
490
+ ** is used during the reduce.
491
+ */
492
+ //{
493
+ // lhs, /* Symbol on the left-hand side of the rule */
494
+ // nrhs, /* Number of right-hand side symbols in the rule */
495
+ //}
496
+ this.yyRuleInfo = [
497
+ %%
498
+ ];
499
+
500
+ /*
501
+ ** Perform a reduce action and the shift that must immediately
502
+ ** follow the reduce.
503
+ */
504
+ this.yy_reduce = function (
505
+ yyruleno /* Number of the rule by which to reduce */
506
+ ){
507
+ var yymsp = this.yystack[this.yyidx]; /* The top of the parser's stack */
508
+
509
+ if (yyruleno < this.yyRuleName.length) {
510
+ var yysize = this.yyRuleInfo[yyruleno].nrhs;
511
+ var ruleName = this.yyRuleName[yyruleno];
512
+ var newStateNo = this.yystack[this.yyidx - yysize].stateno;
513
+ if (this.yyTraceCallback) {
514
+ this.trace("Reduce [" + ruleName + "], go to state " + newStateNo + ".");
515
+ }
516
+ }
517
+
518
+ /* Check that the stack is large enough to grow by a single entry
519
+ ** if the RHS of the rule is empty. This ensures that there is room
520
+ ** enough on the stack to push the LHS value */
521
+ if (this.yyRuleInfo[yyruleno].nrhs == 0) {
522
+ if (this.yyidx > this.yyhwm) {
523
+ this.yyhwm++;
524
+ // assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack));
525
+ }
526
+ if (this.YYSTACKDEPTH > 0) {
527
+ if (this.yyidx >= this.YYSTACKDEPTH - 1) {
528
+ this.yyStackOverflow();
529
+ return;
530
+ }
531
+ } else {
532
+ if (this.yyidx >= this.yystack.length - 1) {
533
+ this.yyGrowStack();
534
+ yymsp = this.yystack[this.yyidx];
535
+ }
536
+ }
537
+ }
538
+
539
+ var yylhsminor;
540
+ switch (yyruleno) {
541
+ /* Beginning here are the reduction cases. A typical example
542
+ ** follows:
543
+ ** case 0:
544
+ ** #line <lineno> <grammarfile>
545
+ ** { ... } // User supplied code
546
+ ** #line <lineno> <thisfile>
547
+ ** break;
548
+ */
549
+ /********** Begin reduce actions **********************************************/
550
+ %%
551
+ /********** End reduce actions ************************************************/
552
+ };
553
+ // assert( yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
554
+
555
+ var yygoto = this.yyRuleInfo[yyruleno].lhs; /* The next state */
556
+ var yysize = this.yyRuleInfo[yyruleno].nrhs; /* Amount to pop the stack */
557
+ var yyact = this.yy_find_reduce_action( /* The next action */
558
+ this.yystack[this.yyidx - yysize].stateno,
559
+ yygoto
560
+ );
561
+ if (yyact <= this.YY_MAX_SHIFTREDUCE) {
562
+ if (yyact > this.YY_MAX_SHIFT) {
563
+ yyact += this.YY_MIN_REDUCE - this.YY_MIN_SHIFTREDUCE;
564
+ }
565
+ this.yyidx -= yysize - 1;
566
+ yymsp = this.yystack[this.yyidx];
567
+ yymsp.stateno = yyact;
568
+ yymsp.major = yygoto;
569
+ this.yyTraceShift(yyact);
570
+ } else {
571
+ // assert( yyact == YY_ACCEPT_ACTION );
572
+ this.yyidx -= yysize;
573
+ this.yy_accept();
574
+ }
575
+ }
576
+
577
+ /*
578
+ ** The following code executes when the parse fails
579
+ */
580
+ this.yy_parse_failed = function () {
581
+ if (this.yyTraceCallback) {
582
+ this.trace("Fail!");
583
+ }
584
+ while (this.yyidx > 0) {
585
+ this.yy_pop_parser_stack();
586
+ }
587
+ /* Here code is inserted which will be executed whenever the
588
+ ** parser fails */
589
+ /************ Begin %parse_failure code ***************************************/
590
+ %%
591
+ /************ End %parse_failure code *****************************************/
592
+ }
593
+
594
+ /*
595
+ ** The following code executes when a syntax error first occurs.
596
+ */
597
+ this.yy_syntax_error = function (
598
+ yymajor, /* The major type of the error token */
599
+ yyminor /* The minor type of the error token */
600
+ ) {
601
+ var TOKEN = yyminor;
602
+ /************ Begin %syntax_error code ****************************************/
603
+ %%
604
+ /************ End %syntax_error code ******************************************/
605
+ }
606
+
607
+ /*
608
+ ** The following is executed when the parser accepts
609
+ */
610
+ this.yy_accept = function () {
611
+ if (this.yyTraceCallback) {
612
+ this.trace("Accept!");
613
+ }
614
+ if (!this.YYNOERRORRECOVERY) {
615
+ this.yyerrcnt = -1;
616
+ }
617
+ // assert( yypParser->yytos==yypParser->yystack );
618
+ /* Here code is inserted which will be executed whenever the
619
+ ** parser accepts */
620
+ /*********** Begin %parse_accept code *****************************************/
621
+ %%
622
+ /*********** End %parse_accept code *******************************************/
623
+ }
624
+
625
+ /* The main parser program.
626
+ ** The first argument is a pointer to a structure obtained from
627
+ ** "ParseAlloc" which describes the current state of the parser.
628
+ ** The second argument is the major token number. The third is
629
+ ** the minor token. The fourth optional argument is whatever the
630
+ ** user wants (and specified in the grammar) and is available for
631
+ ** use by the action routines.
632
+ **
633
+ ** Inputs:
634
+ ** <ul>
635
+ ** <li> A pointer to the parser (an opaque structure.)
636
+ ** <li> The major token number.
637
+ ** <li> The minor token number.
638
+ ** <li> An option argument of a grammar-specified type.
639
+ ** </ul>
640
+ **
641
+ ** Outputs:
642
+ ** None.
643
+ */
644
+ this.parse = function (
645
+ yymajor, /* The major token code number */
646
+ yyminor /* The value for the token */
647
+ ) {
648
+ var yyact; /* The parser action. */
649
+ var yyendofinput; /* True if we are at the end of input */
650
+ var yyerrorhit = 0; /* True if yymajor has invoked an error */
651
+
652
+ //assert( yypParser->yytos!=0 );
653
+
654
+ if (yymajor === undefined || yymajor === null) {
655
+ yymajor = 0;
656
+ }
657
+
658
+ yyendofinput = yymajor == 0;
659
+
660
+ if (this.yyTraceCallback) {
661
+ this.trace("Input '" + this.yyTokenName[yymajor] + "'");
662
+ }
663
+
664
+ do {
665
+ yyact = this.yy_find_shift_action(yymajor);
666
+ if (yyact <= this.YY_MAX_SHIFTREDUCE) { // check me?
667
+ this.yy_shift(yyact, yymajor, yyminor);
668
+ if (!this.YYNOERRORRECOVERY) {
669
+ this.yyerrcnt--;
670
+ }
671
+ yymajor = this.YYNOCODE;
672
+ } else if (yyact <= this.YY_MAX_REDUCE) { // check me?
673
+ this.yy_reduce(yyact - this.YY_MIN_REDUCE); // check me?
674
+ } else {
675
+ // assert( yyact == YY_ERROR_ACTION );
676
+ if (this.yyTraceCallback) {
677
+ this.trace("Syntax Error!");
678
+ }
679
+ if (this.YYERRORSYMBOL) {
680
+ /* A syntax error has occurred.
681
+ ** The response to an error depends upon whether or not the
682
+ ** grammar defines an error token "ERROR".
683
+ **
684
+ ** This is what we do if the grammar does define ERROR:
685
+ **
686
+ ** * Call the %syntax_error function.
687
+ **
688
+ ** * Begin popping the stack until we enter a state where
689
+ ** it is legal to shift the error symbol, then shift
690
+ ** the error symbol.
691
+ **
692
+ ** * Set the error count to three.
693
+ **
694
+ ** * Begin accepting and shifting new tokens. No new error
695
+ ** processing will occur until three tokens have been
696
+ ** shifted successfully.
697
+ **
698
+ */
699
+ if (this.yyerrcnt < 0) {
700
+ this.yy_syntax_error(yymajor, yyminor);
701
+ }
702
+ var yymx = this.yystack[this.yyidx].major;
703
+ if (yymx == this.YYERRORSYMBOL || yyerrorhit) {
704
+ if (this.yyTraceCallback) {
705
+ this.trace("Discard input token " + this.yyTokenName[yymajor]);
706
+ }
707
+ this.yy_destructor(yymajor, yyminor);
708
+ yymajor = this.YYNOCODE;
709
+ } else {
710
+ while (this.yyidx >= 0
711
+ && yymx != this.YYERRORSYMBOL
712
+ && (yyact = this.yy_find_reduce_action(
713
+ this.yystack[this.yyidx].stateno,
714
+ this.YYERRORSYMBOL)) >= this.YY_MIN_REDUCE // check me?
715
+ ) {
716
+ this.yy_pop_parser_stack();
717
+ }
718
+ if (this.yyidx < 0 || yymajor == 0) {
719
+ this.yy_destructor(yymajor, yyminor);
720
+ this.yy_parse_failed();
721
+ if (!this.YYNOERRORRECOVERY) {
722
+ this.yyerrcnt = -1;
723
+ }
724
+ yymajor = this.YYNOCODE;
725
+ } else if (yymx != this.YYERRORSYMBOL) {
726
+ this.yy_shift(yyact, this.YYERRORSYMBOL, yyminor); // check me?
727
+ }
728
+ }
729
+ this.yyerrcnt = 3;
730
+ yyerrorhit = 1;
731
+ } else if (this.YYNOERRORRECOVERY) {
732
+ /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to
733
+ ** do any kind of error recovery. Instead, simply invoke the syntax
734
+ ** error routine and continue going as if nothing had happened.
735
+ **
736
+ ** Applications can set this macro (for example inside %include) if
737
+ ** they intend to abandon the parse upon the first syntax error seen.
738
+ */
739
+ this.yy_syntax_error(yymajor, yyminor);
740
+ this.yy_destructor(yymajor, yyminor);
741
+ yymajor = this.YYNOCODE;
742
+ } else { /* YYERRORSYMBOL is not defined */
743
+ /* This is what we do if the grammar does not define ERROR:
744
+ **
745
+ ** * Report an error message, and throw away the input token.
746
+ **
747
+ ** * If the input token is $, then fail the parse.
748
+ **
749
+ ** As before, subsequent error messages are suppressed until
750
+ ** three input tokens have been successfully shifted.
751
+ */
752
+ if (this.yyerrcnt <= 0) {
753
+ this.yy_syntax_error(yymajor, yyminor);
754
+ }
755
+ this.yyerrcnt = 3;
756
+ this.yy_destructor(yymajor, yyminor);
757
+ if (yyendofinput) {
758
+ this.yy_parse_failed();
759
+ if (!this.YYNOERRORRECOVERY) {
760
+ this.yyerrcnt = -1;
761
+ }
762
+ }
763
+ yymajor = this.YYNOCODE;
764
+ }
765
+ }
766
+ } while (yymajor != this.YYNOCODE && this.yyidx > 0);
767
+
768
+ if (this.yyTraceCallback) {
769
+ var remainingTokens = [];
770
+ for (var i = 1; i <= this.yyidx; i++) {
771
+ remainingTokens.push(this.yyTokenName[this.yystack[i].major]);
772
+ }
773
+ this.trace("Return. Stack=[" + remainingTokens.join(" ") + "]");
774
+ }
775
+ }
776
+
777
+ this.init();
778
+
779
+ } // function Parse()