예제 #1
0
 public override Template Visit(StmtWhile stmt_while)
 {
     Template template = new Template("while (<cond>) {\n    <body>\n}");
     template.Add("cond", stmt_while.Condition.Accept(this));
     template.Add("body", stmt_while.Body.Accept(this));
     return template;
 }
예제 #2
0
	private Stmt stmt_while()
	{
		EnterRule_stmt_while();
		EnterRule("stmt_while", 27);
		TraceIn("stmt_while", 27);
		Stmt value = default(Stmt);


		Expr a = default(Expr);
		StmtBlock b = default(StmtBlock);

		try { DebugEnterRule(GrammarFileName, "stmt_while");
		DebugLocation(352, 1);
		try
		{
			// SugarWalker.g:353:2: ( ^( Stmt_While a= expr b= stmt_block ) | ^( Stmt_Until a= expr b= stmt_block ) | ^( Stmt_Loop (a= expr )? b= stmt_block ) )
			int alt48=3;
			try { DebugEnterDecision(48, false);
			switch (input.LA(1))
			{
			case Stmt_While:
				{
				alt48 = 1;
				}
				break;
			case Stmt_Until:
				{
				alt48 = 2;
				}
				break;
			case Stmt_Loop:
				{
				alt48 = 3;
				}
				break;
			default:
				{
					NoViableAltException nvae = new NoViableAltException("", 48, 0, input);
					DebugRecognitionException(nvae);
					throw nvae;
				}
			}

			} finally { DebugExitDecision(48); }
			switch (alt48)
			{
			case 1:
				DebugEnterAlt(1);
				// SugarWalker.g:353:4: ^( Stmt_While a= expr b= stmt_block )
				{
				DebugLocation(353, 4);
				DebugLocation(353, 6);
				Match(input,Stmt_While,Follow._Stmt_While_in_stmt_while1403); 

				Match(input, TokenTypes.Down, null); 
				DebugLocation(353, 18);
				PushFollow(Follow._expr_in_stmt_while1407);
				a=expr();
				PopFollow();

				DebugLocation(353, 25);
				PushFollow(Follow._stmt_block_in_stmt_while1411);
				b=stmt_block();
				PopFollow();


				Match(input, TokenTypes.Up, null); 

				DebugLocation(354, 2);

						value = new StmtWhile(a, b);
					

				}
				break;
			case 2:
				DebugEnterAlt(2);
				// SugarWalker.g:357:4: ^( Stmt_Until a= expr b= stmt_block )
				{
				DebugLocation(357, 4);
				DebugLocation(357, 6);
				Match(input,Stmt_Until,Follow._Stmt_Until_in_stmt_while1421); 

				Match(input, TokenTypes.Down, null); 
				DebugLocation(357, 18);
				PushFollow(Follow._expr_in_stmt_while1425);
				a=expr();
				PopFollow();

				DebugLocation(357, 25);
				PushFollow(Follow._stmt_block_in_stmt_while1429);
				b=stmt_block();
				PopFollow();


				Match(input, TokenTypes.Up, null); 

				DebugLocation(358, 2);

						value = new StmtWhile(new ExprPrefix("!", new ExprBracket(a)), b);
					

				}
				break;
			case 3:
				DebugEnterAlt(3);
				// SugarWalker.g:361:4: ^( Stmt_Loop (a= expr )? b= stmt_block )
				{
				DebugLocation(361, 4);
				DebugLocation(361, 6);
				Match(input,Stmt_Loop,Follow._Stmt_Loop_in_stmt_while1439); 

				Match(input, TokenTypes.Down, null); 
				DebugLocation(361, 16);
				// SugarWalker.g:361:16: (a= expr )?
				int alt47=2;
				try { DebugEnterSubRule(47);
				try { DebugEnterDecision(47, false);
				int LA47_0 = input.LA(1);

				if (((LA47_0>=Expr_Access && LA47_0<=Expr_Tuple)||LA47_0==IDENT||LA47_0==Match_Tuple||LA47_0==NUMBER||LA47_0==STRING||LA47_0==75||LA47_0==78||LA47_0==82||LA47_0==85||LA47_0==89||LA47_0==95||LA47_0==98||LA47_0==102||LA47_0==104||LA47_0==110||LA47_0==113||LA47_0==117||LA47_0==150||LA47_0==DOUBLE))
				{
					alt47 = 1;
				}
				} finally { DebugExitDecision(47); }
				switch (alt47)
				{
				case 1:
					DebugEnterAlt(1);
					// SugarWalker.g:361:17: a= expr
					{
					DebugLocation(361, 18);
					PushFollow(Follow._expr_in_stmt_while1444);
					a=expr();
					PopFollow();


					}
					break;

				}
				} finally { DebugExitSubRule(47); }

				DebugLocation(361, 27);
				PushFollow(Follow._stmt_block_in_stmt_while1450);
				b=stmt_block();
				PopFollow();


				Match(input, TokenTypes.Up, null); 

				DebugLocation(362, 2);

						if (a == null)
						{
							value = new StmtWhile(new ExprConst("true", ConstType.Ident), b);
						}
						else
						{
							/*Expr iter = new ExprConst("_t_loop_iterator", ConstType.Ident);
							Expr start = new ExprAlloc("auto", "_t_loop_iterator", a, true);
							Expr condition = new ExprBin("!=", iter, new ExprConst("0", ConstType.Number));
							Expr next = new ExprPrefix("--", iter);
							value = new StmtFor(start, condition, next, b);*/
							throw new Exception("Not Implement!");
						}
					

				}
				break;

			}
		}
		catch (RecognitionException re)
		{
			ReportError(re);
			Recover(input,re);
		}
		finally
		{
			TraceOut("stmt_while", 27);
			LeaveRule("stmt_while", 27);
			LeaveRule_stmt_while();
		}
		DebugLocation(377, 1);
		} finally { DebugExitRule(GrammarFileName, "stmt_while"); }
		return value;

	}
예제 #3
0
 public abstract Template Visit(StmtWhile stmt_while);
예제 #4
0
파일: Visitor.cs 프로젝트: BYVoid/SugarCpp
 public abstract Template Visit(StmtWhile stmt_while);
예제 #5
0
	private Stmt stmt_while()
	{
		EnterRule_stmt_while();
		EnterRule("stmt_while", 36);
		TraceIn("stmt_while", 36);
		Stmt value = default(Stmt);


		Expr a = default(Expr);
		StmtBlock b = default(StmtBlock);

		try { DebugEnterRule(GrammarFileName, "stmt_while");
		DebugLocation(482, 1);
		try
		{
			// SugarWalker.g:483:2: ( ^( Stmt_While a= expr b= stmt_block ) | ^( Stmt_Until a= expr b= stmt_block ) | ^( Stmt_Loop (a= expr )? b= stmt_block ) )
			int alt60=3;
			try { DebugEnterDecision(60, false);
			switch (input.LA(1))
			{
			case Stmt_While:
				{
				alt60 = 1;
				}
				break;
			case Stmt_Until:
				{
				alt60 = 2;
				}
				break;
			case Stmt_Loop:
				{
				alt60 = 3;
				}
				break;
			default:
				{
					NoViableAltException nvae = new NoViableAltException("", 60, 0, input);
					DebugRecognitionException(nvae);
					throw nvae;
				}
			}

			} finally { DebugExitDecision(60); }
			switch (alt60)
			{
			case 1:
				DebugEnterAlt(1);
				// SugarWalker.g:483:4: ^( Stmt_While a= expr b= stmt_block )
				{
				DebugLocation(483, 4);
				DebugLocation(483, 6);
				Match(input,Stmt_While,Follow._Stmt_While_in_stmt_while1835); 

				Match(input, TokenTypes.Down, null); 
				DebugLocation(483, 18);
				PushFollow(Follow._expr_in_stmt_while1839);
				a=expr();
				PopFollow();

				DebugLocation(483, 25);
				PushFollow(Follow._stmt_block_in_stmt_while1843);
				b=stmt_block();
				PopFollow();


				Match(input, TokenTypes.Up, null); 

				DebugLocation(484, 2);

						value = new StmtWhile(a, b);
					

				}
				break;
			case 2:
				DebugEnterAlt(2);
				// SugarWalker.g:487:4: ^( Stmt_Until a= expr b= stmt_block )
				{
				DebugLocation(487, 4);
				DebugLocation(487, 6);
				Match(input,Stmt_Until,Follow._Stmt_Until_in_stmt_while1853); 

				Match(input, TokenTypes.Down, null); 
				DebugLocation(487, 18);
				PushFollow(Follow._expr_in_stmt_while1857);
				a=expr();
				PopFollow();

				DebugLocation(487, 25);
				PushFollow(Follow._stmt_block_in_stmt_while1861);
				b=stmt_block();
				PopFollow();


				Match(input, TokenTypes.Up, null); 

				DebugLocation(488, 2);

						value = new StmtWhile(new ExprPrefix("!", new ExprBracket(a)), b);
					

				}
				break;
			case 3:
				DebugEnterAlt(3);
				// SugarWalker.g:491:4: ^( Stmt_Loop (a= expr )? b= stmt_block )
				{
				DebugLocation(491, 4);
				DebugLocation(491, 6);
				Match(input,Stmt_Loop,Follow._Stmt_Loop_in_stmt_while1871); 

				Match(input, TokenTypes.Down, null); 
				DebugLocation(491, 16);
				// SugarWalker.g:491:16: (a= expr )?
				int alt59=2;
				try { DebugEnterSubRule(59);
				try { DebugEnterDecision(59, false);
				int LA59_0 = input.LA(1);

				if (((LA59_0>=Expr_Access && LA59_0<=Expr_Alloc_Equal)||(LA59_0>=Expr_Bin && LA59_0<=Expr_Where)||LA59_0==IDENT||LA59_0==Match_Expr||LA59_0==Match_Tuple||LA59_0==NUMBER||LA59_0==STRING||LA59_0==89||LA59_0==92||LA59_0==96||LA59_0==99||LA59_0==104||LA59_0==110||LA59_0==113||LA59_0==118||LA59_0==121||LA59_0==128||LA59_0==131||LA59_0==135||LA59_0==183||LA59_0==DOUBLE))
				{
					alt59 = 1;
				}
				} finally { DebugExitDecision(59); }
				switch (alt59)
				{
				case 1:
					DebugEnterAlt(1);
					// SugarWalker.g:491:17: a= expr
					{
					DebugLocation(491, 18);
					PushFollow(Follow._expr_in_stmt_while1876);
					a=expr();
					PopFollow();


					}
					break;

				}
				} finally { DebugExitSubRule(59); }

				DebugLocation(491, 27);
				PushFollow(Follow._stmt_block_in_stmt_while1882);
				b=stmt_block();
				PopFollow();


				Match(input, TokenTypes.Up, null); 

				DebugLocation(492, 2);

						if (a == null)
						{
							value = new StmtWhile(new ExprConst("true", ConstType.Ident), b);
						}
						else
						{
							/*Expr iter = new ExprConst("_t_loop_iterator", ConstType.Ident);
							Expr start = new ExprAlloc(new AutoType(), "_t_loop_iterator", a, true);
							Expr condition = new ExprBin("!=", iter, new ExprConst("0", ConstType.Number));
							Expr next = new ExprPrefix("--", iter);
							value = new StmtFor(start, condition, next, b);*/
							throw new Exception("Not Implement!");
						}
					

				}
				break;

			}
		}
		catch (RecognitionException re)
		{
			ReportError(re);
			Recover(input,re);
		}
		finally
		{
			TraceOut("stmt_while", 36);
			LeaveRule("stmt_while", 36);
			LeaveRule_stmt_while();
		}
		DebugLocation(507, 1);
		} finally { DebugExitRule(GrammarFileName, "stmt_while"); }
		return value;

	}