1 using System;
2 using System.Collections;
3 using System.Lex;
4 using System.Parsing;
5 using System;
6 using MdbTokens;
7
8
9
10 public static class StatementParser
11 {
12 public static UniquePtr<cmsx.debug.Node> Parse(MdbLexer& lexer)
13 {
14 UniquePtr<cmsx.debug.Node> value;
15 #if (DEBUG)
16 if (lexer.Log() != null)
17 {
18 lexer.Log()->WriteBeginRule(u"parse");
19 lexer.Log()->IncIndent();
20 }
21 #endif
22 ++lexer;
23 System.Lex.Span span = lexer.GetSpan();
24 Match match = Statement(lexer);
25 value.Reset(cast<cmsx.debug.Node*>(match.value));
26 #if (DEBUG)
27 if (lexer.Log() != null)
28 {
29 lexer.Log()->DecIndent();
30 lexer.Log()->WriteEndRule(u"parse");
31 }
32 #endif
33 if (match.hit)
34 {
35 if (*lexer == System.Lex.END_TOKEN)
36 {
37 return value;
38 }
39 else
40 {
41 lexer.ThrowExpectationFailure(lexer.GetSpan(), GetEndTokenInfo());
42 }
43 }
44 else
45 {
46 lexer.ThrowExpectationFailure(span, u"Statement");
47 }
48 return value;
49 }
50 public static Match Statement(MdbLexer& lexer)
51 {
52 #if (DEBUG)
53 Span debugSpan;
54 bool writeToLog = lexer.Log() != null;
55 if (writeToLog)
56 {
57 debugSpan = lexer.GetSpan();
58 System.Lex.WriteBeginRuleToLog(lexer, u"Statement");
59 }
60 #endif
61 UniquePtr<cmsx.debug.Node> printStatement;
62 UniquePtr<cmsx.debug.Node> traceStatement;
63 Match match(false);
64 Match* parentMatch0 = &match;
65 {
66 long save = lexer.GetPos();
67 Match match(false);
68 Match* parentMatch1 = &match;
69 {
70 long pos = lexer.GetPos();
71 Match match = StatementParser.PrintStatement(lexer);
72 printStatement.Reset(cast<cmsx.debug.Node*>(match.value));
73 if (match.hit)
74 {
75 {
76 #if (DEBUG)
77 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Statement");
78 #endif
79 return Match(true, printStatement.Release());
80 }
81 }
82 *parentMatch1 = match;
83 }
84 *parentMatch0 = match;
85 if (!match.hit)
86 {
87 Match match(false);
88 Match* parentMatch2 = &match;
89 lexer.SetPos(save);
90 {
91 Match match(false);
92 Match* parentMatch3 = &match;
93 {
94 long pos = lexer.GetPos();
95 Match match = StatementParser.TraceStatement(lexer);
96 traceStatement.Reset(cast<cmsx.debug.Node*>(match.value));
97 if (match.hit)
98 {
99 {
100 #if (DEBUG)
101 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Statement");
102 #endif
103 return Match(true, traceStatement.Release());
104 }
105 }
106 *parentMatch3 = match;
107 }
108 *parentMatch2 = match;
109 }
110 *parentMatch0 = match;
111 }
112 }
113 #if (DEBUG)
114 if (writeToLog)
115 {
116 if (match.hit)
117 {
118 System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Statement");
119 }
120 else
121 {
122 System.Lex.WriteFailureToLog(lexer, u"Statement");
123 }
124 }
125 #endif
126 if (!match.hit)
127 {
128 match.value = null;
129 }
130 return match;
131 }
132 public static Match PrintStatement(MdbLexer& lexer)
133 {
134 #if (DEBUG)
135 Span debugSpan;
136 bool writeToLog = lexer.Log() != null;
137 if (writeToLog)
138 {
139 debugSpan = lexer.GetSpan();
140 System.Lex.WriteBeginRuleToLog(lexer, u"PrintStatement");
141 }
142 #endif
143 Span s;
144 UniquePtr<cmsx.debug.Node> expr;
145 Match match(false);
146 Match* parentMatch0 = &match;
147 {
148 Match match(false);
149 Match* parentMatch1 = &match;
150 {
151 long pos = lexer.GetPos();
152 Span span = lexer.GetSpan();
153 Match match(false);
154 if (*lexer == PRINT)
155 {
156 ++lexer;
157 match.hit = true;
158 }
159 if (match.hit)
160 {
161 s = span;
162 }
163 *parentMatch1 = match;
164 }
165 *parentMatch0 = match;
166 }
167 if (match.hit)
168 {
169 Match match(false);
170 Match* parentMatch2 = &match;
171 {
172 Match match(false);
173 Match* parentMatch3 = &match;
174 {
175 long pos = lexer.GetPos();
176 Span span = lexer.GetSpan();
177 Match match = MdbExprParser.Expression(lexer);
178 expr.Reset(cast<cmsx.debug.Node*>(match.value));
179 if (match.hit)
180 {
181 s.end = span.end;
182 {
183 #if (DEBUG)
184 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"PrintStatement");
185 #endif
186 return Match(true, new cmsx.debug.PrintStatementNode(s, expr.Release()));
187 }
188 }
189 *parentMatch3 = match;
190 }
191 *parentMatch2 = match;
192 }
193 *parentMatch0 = match;
194 }
195 #if (DEBUG)
196 if (writeToLog)
197 {
198 if (match.hit)
199 {
200 System.Lex.WriteSuccessToLog(lexer, debugSpan, u"PrintStatement");
201 }
202 else
203 {
204 System.Lex.WriteFailureToLog(lexer, u"PrintStatement");
205 }
206 }
207 #endif
208 if (!match.hit)
209 {
210 match.value = null;
211 }
212 return match;
213 }
214 public static Match TraceStatement(MdbLexer& lexer)
215 {
216 #if (DEBUG)
217 Span debugSpan;
218 bool writeToLog = lexer.Log() != null;
219 if (writeToLog)
220 {
221 debugSpan = lexer.GetSpan();
222 System.Lex.WriteBeginRuleToLog(lexer, u"TraceStatement");
223 }
224 #endif
225 Span s;
226 UniquePtr<cmsx.debug.Node> expr;
227 Match match(false);
228 Match* parentMatch0 = &match;
229 {
230 long pos = lexer.GetPos();
231 Span span = lexer.GetSpan();
232 Match match(false);
233 Match* parentMatch1 = &match;
234 {
235 Match match(false);
236 Match* parentMatch2 = &match;
237 {
238 Match match(false);
239 Match* parentMatch3 = &match;
240 {
241 long pos = lexer.GetPos();
242 Span span = lexer.GetSpan();
243 Match match(false);
244 if (*lexer == TRACE)
245 {
246 ++lexer;
247 match.hit = true;
248 }
249 if (match.hit)
250 {
251 s = span;
252 }
253 *parentMatch3 = match;
254 }
255 *parentMatch2 = match;
256 }
257 if (match.hit)
258 {
259 Match match(false);
260 Match* parentMatch4 = &match;
261 {
262 Match match(true);
263 long save = lexer.GetPos();
264 Match* parentMatch5 = &match;
265 {
266 Match match = MdbExprParser.Expression(lexer);
267 expr.Reset(cast<cmsx.debug.Node*>(match.value));
268 if (match.hit)
269 {
270 *parentMatch5 = match;
271 }
272 else
273 {
274 lexer.SetPos(save);
275 }
276 }
277 *parentMatch4 = match;
278 }
279 *parentMatch2 = match;
280 }
281 *parentMatch1 = match;
282 }
283 if (match.hit)
284 {
285 s.end = span.end;
286 {
287 #if (DEBUG)
288 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"TraceStatement");
289 #endif
290 return Match(true, new cmsx.debug.TraceStatementNode(s, expr.Release()));
291 }
292 }
293 *parentMatch0 = match;
294 }
295 #if (DEBUG)
296 if (writeToLog)
297 {
298 if (match.hit)
299 {
300 System.Lex.WriteSuccessToLog(lexer, debugSpan, u"TraceStatement");
301 }
302 else
303 {
304 System.Lex.WriteFailureToLog(lexer, u"TraceStatement");
305 }
306 }
307 #endif
308 if (!match.hit)
309 {
310 match.value = null;
311 }
312 return match;
313 }
314 }