Пример #1
0
	public Function funcDef()
	{
		EnterRule_funcDef();
		EnterRule("funcDef", 10);
		TraceIn("funcDef", 10);
		Function funcDecl = default(Function);


		IToken identifier15 = default(IToken);
		List<Variable> parameterList16 = default(List<Variable>);
		IType type17 = default(IType);
		List<Variable> variableDef18 = default(List<Variable>);
		Body body19 = default(Body);


		    		funcDecl = new Function();
		    	
		try { DebugEnterRule(GrammarFileName, "funcDef");
		DebugLocation(182, 5);
		try
		{
			// D:\\projects\\repository\\ifmo\\Компиляторы\\PascalCompiler\\PascalCompiler\\Grammar\\Pascal.g:187:6: ( FUNCTION identifier ( LPAREN parameterList RPAREN )? COLON type SEMI ( variableDef )? body SEMI )
			DebugEnterAlt(1);
			// D:\\projects\\repository\\ifmo\\Компиляторы\\PascalCompiler\\PascalCompiler\\Grammar\\Pascal.g:187:8: FUNCTION identifier ( LPAREN parameterList RPAREN )? COLON type SEMI ( variableDef )? body SEMI
			{
			DebugLocation(187, 8);
			Match(input,FUNCTION,Follow._FUNCTION_in_funcDef565); 
			DebugLocation(188, 7);
			PushFollow(Follow._identifier_in_funcDef573);
			identifier15=identifier();
			PopFollow();

			DebugLocation(189, 7);

			    			funcDecl.SetName(identifier15);
			    		
			DebugLocation(192, 7);
			// D:\\projects\\repository\\ifmo\\Компиляторы\\PascalCompiler\\PascalCompiler\\Grammar\\Pascal.g:192:7: ( LPAREN parameterList RPAREN )?
			int alt8=2;
			try { DebugEnterSubRule(8);
			try { DebugEnterDecision(8, false);
			int LA8_0 = input.LA(1);

			if ((LA8_0==LPAREN))
			{
				alt8 = 1;
			}
			} finally { DebugExitDecision(8); }
			switch (alt8)
			{
			case 1:
				DebugEnterAlt(1);
				// D:\\projects\\repository\\ifmo\\Компиляторы\\PascalCompiler\\PascalCompiler\\Grammar\\Pascal.g:192:9: LPAREN parameterList RPAREN
				{
				DebugLocation(192, 9);
				Match(input,LPAREN,Follow._LPAREN_in_funcDef591); 
				DebugLocation(193, 7);
				PushFollow(Follow._parameterList_in_funcDef600);
				parameterList16=parameterList();
				PopFollow();

				DebugLocation(194, 7);

				    			foreach(var pr in parameterList16)
				    			{
				    				funcDecl.AddChild(pr);
				    			}
				    		
				DebugLocation(200, 7);
				Match(input,RPAREN,Follow._RPAREN_in_funcDef616); 

				}
				break;

			}
			} finally { DebugExitSubRule(8); }

			DebugLocation(200, 17);
			Match(input,COLON,Follow._COLON_in_funcDef621); 
			DebugLocation(201, 7);
			PushFollow(Follow._type_in_funcDef629);
			type17=type();
			PopFollow();

			DebugLocation(202, 7);

			    			funcDecl.SetReturnType(type17);	
			    		
			DebugLocation(205, 7);
			Match(input,SEMI,Follow._SEMI_in_funcDef645); 
			DebugLocation(206, 7);
			// D:\\projects\\repository\\ifmo\\Компиляторы\\PascalCompiler\\PascalCompiler\\Grammar\\Pascal.g:206:7: ( variableDef )?
			int alt9=2;
			try { DebugEnterSubRule(9);
			try { DebugEnterDecision(9, false);
			int LA9_0 = input.LA(1);

			if ((LA9_0==VAR))
			{
				alt9 = 1;
			}
			} finally { DebugExitDecision(9); }
			switch (alt9)
			{
			case 1:
				DebugEnterAlt(1);
				// D:\\projects\\repository\\ifmo\\Компиляторы\\PascalCompiler\\PascalCompiler\\Grammar\\Pascal.g:206:9: variableDef
				{
				DebugLocation(206, 9);
				PushFollow(Follow._variableDef_in_funcDef655);
				variableDef18=variableDef();
				PopFollow();

				DebugLocation(207, 7);

				    			foreach(var child in variableDef18)
							{
								funcDecl.AddChild(child);
							}
				    		

				}
				break;

			}
			} finally { DebugExitSubRule(9); }

			DebugLocation(214, 7);
			PushFollow(Follow._body_in_funcDef680);
			body19=body();
			PopFollow();

			DebugLocation(215, 7);

						funcDecl.AddChild(body19);
			    		
			DebugLocation(218, 7);
			Match(input,SEMI,Follow._SEMI_in_funcDef696); 

			}

		}

			catch (RecognitionException e)
			{
		        	throw e;
		    	}

		finally
		{
			TraceOut("funcDef", 10);
			LeaveRule("funcDef", 10);
			LeaveRule_funcDef();
		}
		DebugLocation(219, 5);
		} finally { DebugExitRule(GrammarFileName, "funcDef"); }
		return funcDecl;

	}