|
8 | 8 | * the LICENSE file that was distributed with this source code. |
9 | 9 | */ |
10 | 10 |
|
| 11 | +// All token codes are small integers with #defines that begin with "XX_" |
11 | 12 | %token_prefix XX_ |
| 13 | + |
| 14 | +// The type of the data attached to each token is xx_parser_token. |
12 | 15 | %token_type {xx_parser_token*} |
| 16 | + |
| 17 | +// Default type for non-terminals is zval. |
13 | 18 | %default_type {zval} |
| 19 | + |
| 20 | +// The generated parser function takes a 4th argument as follows: |
| 21 | +%extra_argument {xx_parser_status *status} |
| 22 | + |
14 | 23 | %default_destructor { |
15 | 24 | if (&$$) { |
16 | 25 | zval_ptr_dtor(&$$); |
17 | 26 | } |
18 | 27 | } |
19 | | -%extra_argument {xx_parser_status *status} |
| 28 | + |
| 29 | +// The name of the generated procedure that implements the parser |
| 30 | +// is as follows: |
20 | 31 | %name xx_ |
21 | 32 |
|
| 33 | +// Define operator precedence early so that this is the first occurrence |
| 34 | +// of the operator tokens in the grammer. Keeping the operators together |
| 35 | +// causes them to be assigned integer values that are close together, |
| 36 | +// which keeps parser tables smaller. |
| 37 | +// |
| 38 | +// The token values assigned to these symbols is determined by the order |
| 39 | +// in which lemon first sees them. |
22 | 40 | %left INTERNAL PUBLIC PROTECTED STATIC PRIVATE SCOPED . |
23 | | - |
24 | 41 | %left COMMA . |
25 | 42 | %right REQUIRE . |
26 | 43 | %right DOUBLEARROW . |
|
45 | 62 | %right SBRACKET_OPEN . |
46 | 63 | %right ARROW . |
47 | 64 |
|
| 65 | +// The following text is included near the beginning of the C source |
| 66 | +// code file that implements the parser. |
48 | 67 | %include { |
49 | 68 | #include "parser.h" |
50 | 69 | } |
| 70 | +// end %include |
51 | 71 |
|
| 72 | +// This code runs whenever there is a syntax error |
52 | 73 | %syntax_error { |
53 | | - |
54 | 74 | zval syntax_error; |
55 | 75 |
|
56 | 76 | array_init(&syntax_error); |
57 | | - |
58 | 77 | parser_add_str(&syntax_error, "type", "error"); |
59 | 78 |
|
60 | 79 | if (status->scanner_state->start_length) { |
|
80 | 99 | } |
81 | 100 | } |
82 | 101 |
|
83 | | -program ::= xx_language(Q) . { |
| 102 | +input ::= xx_language(Q) . { |
84 | 103 | status->ret = Q; |
85 | 104 | } |
86 | 105 |
|
|
0 commit comments