-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser_template.th
140 lines (122 loc) · 5.27 KB
/
parser_template.th
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
// %nameParser.h
// LMNO parser generator template
//
// Copyright ©2010-2011 Brigham Toskin.
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// Some portions of the Software are taken from the Public Domain.
// Based on Lemon v1.
//
////////////////////////////////////////////////////////////////////////////////
//
// This file was generated by LMNO for the %name parser.
// All user-supplied content is the property of its respective authors and is
// subject to the following copyright and licensing terms:
%%
////////////////////////////////////////////////////////////////////////////////
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <stdlib.h>
// user includes
%%
// Token ID codes
%%
/* The next thing included is series of defines which control
* various aspects of the generated parser.
* YYCODETYPE is the data type used for storing terminal
* and nonterminal numbers. "unsigned char" is
* used if there are fewer than 250 terminals
* and nonterminals. "int" is used otherwise.
* YYNOCODE is a number of type YYCODETYPE which corresponds
* to no legal terminal or nonterminal number. This
* number is used to fill in empty slots of the hash
* table.
* YYFALLBACK If defined, this indicates that one or more tokens
* have fall-back values which should be used if the
* original value of the token will not parse.
* YYACTIONTYPE is the data type used for storing terminal
* and nonterminal numbers. "unsigned char" is
* used if there are fewer than 250 rules and
* states combined. "int" is used otherwise.
* %nameTOKENTYPE is the data type used for minor tokens given
* directly to the parser from the tokenizer.
* YYMINORTYPE is the data type used for all minor tokens.
* This is typically a union of many types, one of
* which is %nameTOKENTYPE. The entry in the union
* for base tokens is called "yy0".
* YYSTACKDEPTH is the maximum depth of the parser's stack.
* %nameARG_SDECL A static variable declaration for the %extra_argument
* %nameARG_PDECL A parameter declaration for the %extra_argument
* %nameARG_STORE Code to store %extra_argument into yypParser
* %nameARG_FETCH Code to extract %extra_argument from yypParser
* YYNSTATE the combined number of states.
* YYNRULE the number of rules in the grammar
* YYERRORSYMBOL is the code number of the error symbol. If not
* defined, then do no error processing.
*/
%%
#define YY_NO_ACTION (YYNSTATE+YYNRULE+2)
#define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1)
#define YY_ERROR_ACTION (YYNSTATE+YYNRULE)
// Stack Entry /////////////////////////////////////////////////////////////////
/* The following structure represents a single element of the
* parser's stack. Information stored includes:
*
* + The state number for the parser at this level of the stack.
*
* + The value of the token stored at this level of the stack.
* (In other words, the "major" token.)
*
* + The semantic value stored at this level of the stack. This is
* the information used by the action routines in the grammar.
* It is sometimes called the "minor" token.
*/
typedef struct yyStackEntry
{
int stateno; // The state-number
int major; // The major token value. This is the code
// number for the token at this stack level
YYMINORTYPE minor; // The user-supplied minor token value. This
// is the value of the token
} yyStackEntry;
// Parser //////////////////////////////////////////////////////////////////////
typedef struct %nameParser
{
int yyidx; // Index of top element in stack
int yyerrcnt; // Shifts left before out of the error
%nameARG_SDECL // A place to hold %extra_argument
yyStackEntry yystack[YYSTACKDEPTH]; // The parser's stack
#ifndef NDEBUG
static FILE *yyTraceFILE;
static char *yyTracePrompt;
#endif // NDEBUG
} %nameParser;
// Parser Operations ///////////////////////////////////////////////////////////
%nameParser* %nameAlloc();
void %nameFree(%nameParser** ppParser);
void %nameParse(%nameParser* pParser, int yymajor, %nameTOKENTYPE yyminor %nameARG_PDECL);
#ifndef NDEBUG
void %nameTrace(%nameParser* pParser, FILE *TraceFILE, const char *zTracePrompt);
#endif
#ifdef __cplusplus
} // extern "C"
#endif