1// $ANTLR 3.1.2 BuildOptions\\DebugTreeGrammar.g3 2009-09-30 13:18:15
2
3// The variable 'variable' is assigned but its value is never used.
4#pragma warning disable 219
5// Unreachable code detected.
6#pragma warning disable 162
7
8
9//import java.util.Map;
10//import java.util.HashMap;
11using BigInteger = java.math.BigInteger;
12using Console = System.Console;
13
14
15using System.Collections.Generic;
16using Antlr.Runtime;
17using Antlr.Runtime.Tree;
18using RewriteRuleITokenStream = Antlr.Runtime.Tree.RewriteRuleTokenStream;using Stack = System.Collections.Generic.Stack<object>;
19using List = System.Collections.IList;
20using ArrayList = System.Collections.Generic.List<object>;
21
22using Antlr.Runtime.Debug;
23using IOException = System.IO.IOException;
24[System.CodeDom.Compiler.GeneratedCode("ANTLR", "3.1.2")]
25[System.CLSCompliant(false)]
26public partial class DebugTreeGrammar : DebugTreeParser
27{
28	internal static readonly string[] tokenNames = new string[] {
29		"<invalid>", "<EOR>", "<DOWN>", "<UP>", "CALL", "FUNC", "ID", "INT", "NEWLINE", "WS", "'-'", "'%'", "'('", "')'", "'*'", "'/'", "'+'", "'='"
30	};
31	public const int EOF=-1;
32	public const int T__10=10;
33	public const int T__11=11;
34	public const int T__12=12;
35	public const int T__13=13;
36	public const int T__14=14;
37	public const int T__15=15;
38	public const int T__16=16;
39	public const int T__17=17;
40	public const int CALL=4;
41	public const int FUNC=5;
42	public const int ID=6;
43	public const int INT=7;
44	public const int NEWLINE=8;
45	public const int WS=9;
46
47	// delegates
48	// delegators
49
50	public static readonly string[] ruleNames =
51		new string[]
52		{
53			"invalidRule", "call", "expr", "prog", "stat"
54		};
55
56		int ruleLevel = 0;
57		public virtual int RuleLevel { get { return ruleLevel; } }
58		public virtual void IncRuleLevel() { ruleLevel++; }
59		public virtual void DecRuleLevel() { ruleLevel--; }
60		public DebugTreeGrammar( ITreeNodeStream input )
61			: this( input, DebugEventSocketProxy.DefaultDebuggerPort, new RecognizerSharedState() )
62		{
63		}
64		public DebugTreeGrammar( ITreeNodeStream input, int port, RecognizerSharedState state )
65			: base( input, state )
66		{
67			DebugEventSocketProxy proxy = new DebugEventSocketProxy( this, port, input.TreeAdaptor );
68			DebugListener = proxy;
69			try
70			{
71				proxy.Handshake();
72			}
73			catch ( IOException ioe )
74			{
75				ReportError( ioe );
76			}
77		}
78	public DebugTreeGrammar( ITreeNodeStream input, IDebugEventListener dbg )
79		: base( input, dbg, new RecognizerSharedState() )
80	{
81
82	}
83	protected virtual bool EvalPredicate( bool result, string predicate )
84	{
85		dbg.SemanticPredicate( result, predicate );
86		return result;
87	}
88
89
90	public override string[] TokenNames { get { return DebugTreeGrammar.tokenNames; } }
91	public override string GrammarFileName { get { return "BuildOptions\\DebugTreeGrammar.g3"; } }
92
93
94	#region Rules
95
96	// $ANTLR start "prog"
97	// BuildOptions\\DebugTreeGrammar.g3:53:0: prog : ( stat )* ;
98	private void prog(  )
99	{
100		try
101		{
102			dbg.EnterRule( GrammarFileName, "prog" );
103			if ( RuleLevel == 0 )
104			{
105				dbg.Commence();
106			}
107			IncRuleLevel();
108			dbg.Location( 53, -1 );
109
110		try
111		{
112			// BuildOptions\\DebugTreeGrammar.g3:53:9: ( ( stat )* )
113			dbg.EnterAlt( 1 );
114
115			// BuildOptions\\DebugTreeGrammar.g3:53:9: ( stat )*
116			{
117			dbg.Location( 53, 8 );
118			// BuildOptions\\DebugTreeGrammar.g3:53:9: ( stat )*
119			try
120			{
121				dbg.EnterSubRule( 1 );
122
123			for ( ; ; )
124			{
125				int alt1=2;
126				try
127				{
128					dbg.EnterDecision( 1 );
129
130				int LA1_0 = input.LA(1);
131
132				if ( ((LA1_0>=CALL && LA1_0<=INT)||(LA1_0>=10 && LA1_0<=11)||(LA1_0>=14 && LA1_0<=17)) )
133				{
134					alt1=1;
135				}
136
137
138				}
139				finally
140				{
141					dbg.ExitDecision( 1 );
142				}
143
144				switch ( alt1 )
145				{
146				case 1:
147					dbg.EnterAlt( 1 );
148
149					// BuildOptions\\DebugTreeGrammar.g3:53:0: stat
150					{
151					dbg.Location( 53, 8 );
152					PushFollow(Follow._stat_in_prog48);
153					stat();
154
155					state._fsp--;
156
157
158					}
159					break;
160
161				default:
162					goto loop1;
163				}
164			}
165
166			loop1:
167				;
168
169			}
170			finally
171			{
172				dbg.ExitSubRule( 1 );
173			}
174
175
176			}
177
178		}
179		catch ( RecognitionException re )
180		{
181			ReportError(re);
182			Recover(input,re);
183		}
184		finally
185		{
186		}
187		dbg.Location(54, 4);
188
189		}
190		finally
191		{
192			dbg.ExitRule( GrammarFileName, "prog" );
193			DecRuleLevel();
194			if ( RuleLevel == 0 )
195			{
196				dbg.Terminate();
197			}
198		}
199
200		return ;
201	}
202	// $ANTLR end "prog"
203
204
205	// $ANTLR start "stat"
206	// BuildOptions\\DebugTreeGrammar.g3:56:0: stat : ( expr | ^( '=' ID expr ) | ^( FUNC ( . )+ ) );
207	private void stat(  )
208	{
209		CommonTree ID2=null;
210		BigInteger expr1 = default(BigInteger);
211		BigInteger expr3 = default(BigInteger);
212
213		try
214		{
215			dbg.EnterRule( GrammarFileName, "stat" );
216			if ( RuleLevel == 0 )
217			{
218				dbg.Commence();
219			}
220			IncRuleLevel();
221			dbg.Location( 56, -1 );
222
223		try
224		{
225			// BuildOptions\\DebugTreeGrammar.g3:56:9: ( expr | ^( '=' ID expr ) | ^( FUNC ( . )+ ) )
226			int alt3=3;
227			try
228			{
229				dbg.EnterDecision( 3 );
230
231			switch ( input.LA(1) )
232			{
233			case CALL:
234			case ID:
235			case INT:
236			case 10:
237			case 11:
238			case 14:
239			case 15:
240			case 16:
241				{
242				alt3=1;
243				}
244				break;
245			case 17:
246				{
247				alt3=2;
248				}
249				break;
250			case FUNC:
251				{
252				alt3=3;
253				}
254				break;
255			default:
256				{
257					NoViableAltException nvae = new NoViableAltException("", 3, 0, input);
258
259					dbg.RecognitionException( nvae );
260					throw nvae;
261				}
262			}
263
264			}
265			finally
266			{
267				dbg.ExitDecision( 3 );
268			}
269
270			switch ( alt3 )
271			{
272			case 1:
273				dbg.EnterAlt( 1 );
274
275				// BuildOptions\\DebugTreeGrammar.g3:56:9: expr
276				{
277				dbg.Location( 56, 8 );
278				PushFollow(Follow._expr_in_stat63);
279				expr1=expr();
280
281				state._fsp--;
282
283				dbg.Location( 56, 35 );
284				 string result = expr1.ToString();
285				                                     Console.Out.WriteLine(expr1 + " (about " + result[0] + "*10^" + (result.Length-1) + ")");
286
287
288				}
289				break;
290			case 2:
291				dbg.EnterAlt( 2 );
292
293				// BuildOptions\\DebugTreeGrammar.g3:59:9: ^( '=' ID expr )
294				{
295				dbg.Location( 59, 8 );
296				dbg.Location( 59, 10 );
297				Match(input,17,Follow._17_in_stat98);
298
299				Match(input, TokenTypes.Down, null);
300				dbg.Location( 59, 14 );
301				ID2=(CommonTree)Match(input,ID,Follow._ID_in_stat100);
302				dbg.Location( 59, 17 );
303				PushFollow(Follow._expr_in_stat102);
304				expr3=expr();
305
306				state._fsp--;
307
308
309				Match(input, TokenTypes.Up, null);
310				dbg.Location( 59, 35 );
311				 globalMemory[(ID2!=null?ID2.Text:null)] = expr3;
312
313				}
314				break;
315			case 3:
316				dbg.EnterAlt( 3 );
317
318				// BuildOptions\\DebugTreeGrammar.g3:60:9: ^( FUNC ( . )+ )
319				{
320				dbg.Location( 60, 8 );
321				dbg.Location( 60, 10 );
322				Match(input,FUNC,Follow._FUNC_in_stat128);
323
324				Match(input, TokenTypes.Down, null);
325				dbg.Location( 60, 15 );
326				// BuildOptions\\DebugTreeGrammar.g3:60:16: ( . )+
327				int cnt2=0;
328				try
329				{
330					dbg.EnterSubRule( 2 );
331
332				for ( ; ; )
333				{
334					int alt2=2;
335					try
336					{
337						dbg.EnterDecision( 2 );
338
339					int LA2_0 = input.LA(1);
340
341					if ( ((LA2_0>=CALL && LA2_0<=17)) )
342					{
343						alt2=1;
344					}
345					else if ( (LA2_0==UP) )
346					{
347						alt2=2;
348					}
349
350
351					}
352					finally
353					{
354						dbg.ExitDecision( 2 );
355					}
356
357					switch ( alt2 )
358					{
359					case 1:
360						dbg.EnterAlt( 1 );
361
362						// BuildOptions\\DebugTreeGrammar.g3:60:0: .
363						{
364						dbg.Location( 60, 15 );
365						MatchAny(input);
366
367						}
368						break;
369
370					default:
371						if ( cnt2 >= 1 )
372							goto loop2;
373
374						EarlyExitException eee2 = new EarlyExitException( 2, input );
375						dbg.RecognitionException( eee2 );
376
377						throw eee2;
378					}
379					cnt2++;
380				}
381				loop2:
382					;
383
384				}
385				finally
386				{
387					dbg.ExitSubRule( 2 );
388				}
389
390
391				Match(input, TokenTypes.Up, null);
392
393				}
394				break;
395
396			}
397		}
398		catch ( RecognitionException re )
399		{
400			ReportError(re);
401			Recover(input,re);
402		}
403		finally
404		{
405		}
406		dbg.Location(61, 4);
407
408		}
409		finally
410		{
411			dbg.ExitRule( GrammarFileName, "stat" );
412			DecRuleLevel();
413			if ( RuleLevel == 0 )
414			{
415				dbg.Terminate();
416			}
417		}
418
419		return ;
420	}
421	// $ANTLR end "stat"
422
423
424	// $ANTLR start "expr"
425	// BuildOptions\\DebugTreeGrammar.g3:63:0: expr returns [BigInteger value] : ( ^( '+' a= expr b= expr ) | ^( '-' a= expr b= expr ) | ^( '*' a= expr b= expr ) | ^( '/' a= expr b= expr ) | ^( '%' a= expr b= expr ) | ID | INT | call );
426	private BigInteger expr(  )
427	{
428		BigInteger value = default(BigInteger);
429
430		CommonTree ID4=null;
431		CommonTree INT5=null;
432		BigInteger a = default(BigInteger);
433		BigInteger b = default(BigInteger);
434		BigInteger call6 = default(BigInteger);
435
436		try
437		{
438			dbg.EnterRule( GrammarFileName, "expr" );
439			if ( RuleLevel == 0 )
440			{
441				dbg.Commence();
442			}
443			IncRuleLevel();
444			dbg.Location( 63, -1 );
445
446		try
447		{
448			// BuildOptions\\DebugTreeGrammar.g3:64:9: ( ^( '+' a= expr b= expr ) | ^( '-' a= expr b= expr ) | ^( '*' a= expr b= expr ) | ^( '/' a= expr b= expr ) | ^( '%' a= expr b= expr ) | ID | INT | call )
449			int alt4=8;
450			try
451			{
452				dbg.EnterDecision( 4 );
453
454			switch ( input.LA(1) )
455			{
456			case 16:
457				{
458				alt4=1;
459				}
460				break;
461			case 10:
462				{
463				alt4=2;
464				}
465				break;
466			case 14:
467				{
468				alt4=3;
469				}
470				break;
471			case 15:
472				{
473				alt4=4;
474				}
475				break;
476			case 11:
477				{
478				alt4=5;
479				}
480				break;
481			case ID:
482				{
483				alt4=6;
484				}
485				break;
486			case INT:
487				{
488				alt4=7;
489				}
490				break;
491			case CALL:
492				{
493				alt4=8;
494				}
495				break;
496			default:
497				{
498					NoViableAltException nvae = new NoViableAltException("", 4, 0, input);
499
500					dbg.RecognitionException( nvae );
501					throw nvae;
502				}
503			}
504
505			}
506			finally
507			{
508				dbg.ExitDecision( 4 );
509			}
510
511			switch ( alt4 )
512			{
513			case 1:
514				dbg.EnterAlt( 1 );
515
516				// BuildOptions\\DebugTreeGrammar.g3:64:9: ^( '+' a= expr b= expr )
517				{
518				dbg.Location( 64, 8 );
519				dbg.Location( 64, 10 );
520				Match(input,16,Follow._16_in_expr172);
521
522				Match(input, TokenTypes.Down, null);
523				dbg.Location( 64, 15 );
524				PushFollow(Follow._expr_in_expr176);
525				a=expr();
526
527				state._fsp--;
528
529				dbg.Location( 64, 22 );
530				PushFollow(Follow._expr_in_expr180);
531				b=expr();
532
533				state._fsp--;
534
535
536				Match(input, TokenTypes.Up, null);
537				dbg.Location( 64, 35 );
538				 value = a.add(b);
539
540				}
541				break;
542			case 2:
543				dbg.EnterAlt( 2 );
544
545				// BuildOptions\\DebugTreeGrammar.g3:65:9: ^( '-' a= expr b= expr )
546				{
547				dbg.Location( 65, 8 );
548				dbg.Location( 65, 10 );
549				Match(input,10,Follow._10_in_expr200);
550
551				Match(input, TokenTypes.Down, null);
552				dbg.Location( 65, 15 );
553				PushFollow(Follow._expr_in_expr204);
554				a=expr();
555
556				state._fsp--;
557
558				dbg.Location( 65, 22 );
559				PushFollow(Follow._expr_in_expr208);
560				b=expr();
561
562				state._fsp--;
563
564
565				Match(input, TokenTypes.Up, null);
566				dbg.Location( 65, 35 );
567				 value = a.subtract(b);
568
569				}
570				break;
571			case 3:
572				dbg.EnterAlt( 3 );
573
574				// BuildOptions\\DebugTreeGrammar.g3:66:9: ^( '*' a= expr b= expr )
575				{
576				dbg.Location( 66, 8 );
577				dbg.Location( 66, 10 );
578				Match(input,14,Follow._14_in_expr228);
579
580				Match(input, TokenTypes.Down, null);
581				dbg.Location( 66, 15 );
582				PushFollow(Follow._expr_in_expr232);
583				a=expr();
584
585				state._fsp--;
586
587				dbg.Location( 66, 22 );
588				PushFollow(Follow._expr_in_expr236);
589				b=expr();
590
591				state._fsp--;
592
593
594				Match(input, TokenTypes.Up, null);
595				dbg.Location( 66, 35 );
596				 value = a.multiply(b);
597
598				}
599				break;
600			case 4:
601				dbg.EnterAlt( 4 );
602
603				// BuildOptions\\DebugTreeGrammar.g3:67:9: ^( '/' a= expr b= expr )
604				{
605				dbg.Location( 67, 8 );
606				dbg.Location( 67, 10 );
607				Match(input,15,Follow._15_in_expr256);
608
609				Match(input, TokenTypes.Down, null);
610				dbg.Location( 67, 15 );
611				PushFollow(Follow._expr_in_expr260);
612				a=expr();
613
614				state._fsp--;
615
616				dbg.Location( 67, 22 );
617				PushFollow(Follow._expr_in_expr264);
618				b=expr();
619
620				state._fsp--;
621
622
623				Match(input, TokenTypes.Up, null);
624				dbg.Location( 67, 35 );
625				 value = a.divide(b);
626
627				}
628				break;
629			case 5:
630				dbg.EnterAlt( 5 );
631
632				// BuildOptions\\DebugTreeGrammar.g3:68:9: ^( '%' a= expr b= expr )
633				{
634				dbg.Location( 68, 8 );
635				dbg.Location( 68, 10 );
636				Match(input,11,Follow._11_in_expr284);
637
638				Match(input, TokenTypes.Down, null);
639				dbg.Location( 68, 15 );
640				PushFollow(Follow._expr_in_expr288);
641				a=expr();
642
643				state._fsp--;
644
645				dbg.Location( 68, 22 );
646				PushFollow(Follow._expr_in_expr292);
647				b=expr();
648
649				state._fsp--;
650
651
652				Match(input, TokenTypes.Up, null);
653				dbg.Location( 68, 35 );
654				 value = a.remainder(b);
655
656				}
657				break;
658			case 6:
659				dbg.EnterAlt( 6 );
660
661				// BuildOptions\\DebugTreeGrammar.g3:69:9: ID
662				{
663				dbg.Location( 69, 8 );
664				ID4=(CommonTree)Match(input,ID,Follow._ID_in_expr311);
665				dbg.Location( 69, 35 );
666				 value = getValue((ID4!=null?ID4.Text:null));
667
668				}
669				break;
670			case 7:
671				dbg.EnterAlt( 7 );
672
673				// BuildOptions\\DebugTreeGrammar.g3:70:9: INT
674				{
675				dbg.Location( 70, 8 );
676				INT5=(CommonTree)Match(input,INT,Follow._INT_in_expr347);
677				dbg.Location( 70, 35 );
678				 value = new BigInteger((INT5!=null?INT5.Text:null));
679
680				}
681				break;
682			case 8:
683				dbg.EnterAlt( 8 );
684
685				// BuildOptions\\DebugTreeGrammar.g3:71:9: call
686				{
687				dbg.Location( 71, 8 );
688				PushFollow(Follow._call_in_expr382);
689				call6=call();
690
691				state._fsp--;
692
693				dbg.Location( 71, 35 );
694				 value = call6;
695
696				}
697				break;
698
699			}
700		}
701		catch ( RecognitionException re )
702		{
703			ReportError(re);
704			Recover(input,re);
705		}
706		finally
707		{
708		}
709		dbg.Location(72, 4);
710
711		}
712		finally
713		{
714			dbg.ExitRule( GrammarFileName, "expr" );
715			DecRuleLevel();
716			if ( RuleLevel == 0 )
717			{
718				dbg.Terminate();
719			}
720		}
721
722		return value;
723	}
724	// $ANTLR end "expr"
725
726
727	// $ANTLR start "call"
728	// BuildOptions\\DebugTreeGrammar.g3:74:0: call returns [BigInteger value] : ^( CALL ID expr ) ;
729	private BigInteger call(  )
730	{
731		BigInteger value = default(BigInteger);
732
733		CommonTree ID8=null;
734		BigInteger expr7 = default(BigInteger);
735
736		try
737		{
738			dbg.EnterRule( GrammarFileName, "call" );
739			if ( RuleLevel == 0 )
740			{
741				dbg.Commence();
742			}
743			IncRuleLevel();
744			dbg.Location( 74, -1 );
745
746		try
747		{
748			// BuildOptions\\DebugTreeGrammar.g3:75:9: ( ^( CALL ID expr ) )
749			dbg.EnterAlt( 1 );
750
751			// BuildOptions\\DebugTreeGrammar.g3:75:9: ^( CALL ID expr )
752			{
753			dbg.Location( 75, 8 );
754			dbg.Location( 75, 10 );
755			Match(input,CALL,Follow._CALL_in_call430);
756
757			Match(input, TokenTypes.Down, null);
758			dbg.Location( 75, 15 );
759			ID8=(CommonTree)Match(input,ID,Follow._ID_in_call432);
760			dbg.Location( 75, 18 );
761			PushFollow(Follow._expr_in_call434);
762			expr7=expr();
763
764			state._fsp--;
765
766
767			Match(input, TokenTypes.Up, null);
768			dbg.Location( 75, 35 );
769			 BigInteger p = expr7;
770			                                     CommonTree funcRoot = findFunction((ID8!=null?ID8.Text:null), p);
771			                                     if (funcRoot == null) {
772			                                         Console.Error.WriteLine("No match found for " + (ID8!=null?ID8.Text:null) + "(" + p + ")");
773			                                     } else {
774			                                         // Here we set up the local evaluator to run over the
775			                                         // function definition with the parameter value.
776			                                         // This re-reads a sub-AST of our input AST!
777			                                         DebugTreeGrammar e = new DebugTreeGrammar(funcRoot, functionDefinitions, globalMemory, p);
778			                                         value = e.expr();
779			                                     }
780
781
782			}
783
784		}
785		catch ( RecognitionException re )
786		{
787			ReportError(re);
788			Recover(input,re);
789		}
790		finally
791		{
792		}
793		dbg.Location(87, 4);
794
795		}
796		finally
797		{
798			dbg.ExitRule( GrammarFileName, "call" );
799			DecRuleLevel();
800			if ( RuleLevel == 0 )
801			{
802				dbg.Terminate();
803			}
804		}
805
806		return value;
807	}
808	// $ANTLR end "call"
809	#endregion Rules
810
811
812	#region Follow sets
813	private static class Follow
814	{
815		public static readonly BitSet _stat_in_prog48 = new BitSet(new ulong[]{0x3CCF2UL});
816		public static readonly BitSet _expr_in_stat63 = new BitSet(new ulong[]{0x2UL});
817		public static readonly BitSet _17_in_stat98 = new BitSet(new ulong[]{0x4UL});
818		public static readonly BitSet _ID_in_stat100 = new BitSet(new ulong[]{0x1CCD0UL});
819		public static readonly BitSet _expr_in_stat102 = new BitSet(new ulong[]{0x8UL});
820		public static readonly BitSet _FUNC_in_stat128 = new BitSet(new ulong[]{0x4UL});
821		public static readonly BitSet _16_in_expr172 = new BitSet(new ulong[]{0x4UL});
822		public static readonly BitSet _expr_in_expr176 = new BitSet(new ulong[]{0x1CCD0UL});
823		public static readonly BitSet _expr_in_expr180 = new BitSet(new ulong[]{0x8UL});
824		public static readonly BitSet _10_in_expr200 = new BitSet(new ulong[]{0x4UL});
825		public static readonly BitSet _expr_in_expr204 = new BitSet(new ulong[]{0x1CCD0UL});
826		public static readonly BitSet _expr_in_expr208 = new BitSet(new ulong[]{0x8UL});
827		public static readonly BitSet _14_in_expr228 = new BitSet(new ulong[]{0x4UL});
828		public static readonly BitSet _expr_in_expr232 = new BitSet(new ulong[]{0x1CCD0UL});
829		public static readonly BitSet _expr_in_expr236 = new BitSet(new ulong[]{0x8UL});
830		public static readonly BitSet _15_in_expr256 = new BitSet(new ulong[]{0x4UL});
831		public static readonly BitSet _expr_in_expr260 = new BitSet(new ulong[]{0x1CCD0UL});
832		public static readonly BitSet _expr_in_expr264 = new BitSet(new ulong[]{0x8UL});
833		public static readonly BitSet _11_in_expr284 = new BitSet(new ulong[]{0x4UL});
834		public static readonly BitSet _expr_in_expr288 = new BitSet(new ulong[]{0x1CCD0UL});
835		public static readonly BitSet _expr_in_expr292 = new BitSet(new ulong[]{0x8UL});
836		public static readonly BitSet _ID_in_expr311 = new BitSet(new ulong[]{0x2UL});
837		public static readonly BitSet _INT_in_expr347 = new BitSet(new ulong[]{0x2UL});
838		public static readonly BitSet _call_in_expr382 = new BitSet(new ulong[]{0x2UL});
839		public static readonly BitSet _CALL_in_call430 = new BitSet(new ulong[]{0x4UL});
840		public static readonly BitSet _ID_in_call432 = new BitSet(new ulong[]{0x1CCD0UL});
841		public static readonly BitSet _expr_in_call434 = new BitSet(new ulong[]{0x8UL});
842
843	}
844	#endregion Follow sets
845}
846