aboutsummaryrefslogtreecommitdiff
path: root/src/tools/parser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/parser.cpp')
-rw-r--r--src/tools/parser.cpp79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/tools/parser.cpp b/src/tools/parser.cpp
index a70dfa4..e4fc95f 100644
--- a/src/tools/parser.cpp
+++ b/src/tools/parser.cpp
@@ -149,12 +149,91 @@ private:
149 QueueBuf qbIn; 149 QueueBuf qbIn;
150}; 150};
151 151
152void redAdd( Bu::Parser &p )
153{
154}
155
156void redPrint( Bu::Parser &p )
157{
158}
159
152int main( int argc, char *argv[] ) 160int main( int argc, char *argv[] )
153{ 161{
154 File fIn( argv[1], File::Read ); 162 File fIn( argv[1], File::Read );
155 163
156 Parser p; 164 Parser p;
157 165
166 {
167 Parser::NonTerminal nt;
168 int iSelf = p.addNonTerminal("expr");
169 nt.addProduction(
170 Parser::Production(
171 Parser::State(
172 Parser::State::typeTerminal,
173 tokPlus
174 )
175 ).append(
176 Parser::State(
177 Parser::State::typeNonTerminal,
178 iSelf
179 )
180 ).append(
181 Parser::State(
182 Parser::State::typeReduction,
183 p.addReduction("add")
184 )
185 )
186 );
187 nt.addProduction(
188 Parser::Production()
189 );
190 p.addNonTerminal( "expr", nt );
191 }
192 {
193 Parser::NonTerminal nt;
194 nt.addProduction(
195 Parser::Production(
196 Parser::State(
197 Parser::State::typeTerminalPush,
198 tokNumber
199 )
200 ).append(
201 Parser::State(
202 Parser::State::typeNonTerminal,
203 p.getNonTerminalId("expr")
204 )
205 )
206 );
207 p.addNonTerminal( "expr'", nt );
208 }
209 {
210 Parser::NonTerminal nt;
211 nt.addProduction(
212 Parser::Production(
213 Parser::State(
214 Parser::State::typeNonTerminal,
215 p.getNonTerminalId("expr'")
216 )
217 ).append(
218 Parser::State(
219 Parser::State::typeTerminal,
220 tokCompute
221 )
222 ).append(
223 Parser::State(
224 Parser::State::typeReduction,
225 p.addReduction("print")
226 )
227 )
228 );
229 p.addNonTerminal("input", nt );
230 }
231
232 p.setRootNonTerminal("input");
233
234 p.setReduction("add", Bu::slot( &redAdd ) );
235 p.setReduction("print", Bu::slot( &redPrint ) );
236
158 p.pushLexer( new MathLexer( fIn ) ); 237 p.pushLexer( new MathLexer( fIn ) );
159 238
160 p.parse(); 239 p.parse();