Exemplo n.º 1
0
        public void Prepare(RootNode tree)
        {
            funcDefinitions_.Clear();

            foreach (ISCNode node in tree.Children)
            {
                if (node is VarDefNode)
                {
                    globalScope_.Add(node as VarDefNode);
                }
                else if (node is FuncDefNode)
                {
                    FuncDefNode funcDef = node as FuncDefNode;
                    if (funcDefinitions_.Contains(funcDef))
                        throw new InterpreterException("Multiple function definitions for function: " + funcDef.Name);
                    funcDefinitions_.Add(funcDef);

                    if (funcDef.Name == "main")
                        mainFuncDef_ = funcDef;
                }
                else if (node is FuncDeclNode)
                {
                    // Just ignore function declarations
                }
            }
            if (mainFuncDef_ == null)
                throw new InterpreterException("Missing 'main' function");
            globalScope_.FuncDefs = funcDefinitions_;
        }
Exemplo n.º 2
0
	public RootNode walk()
	{
		EnterRule_walk();
		EnterRule("walk", 1);
		TraceIn("walk", 1);
		RootNode node = default(RootNode);


		ISCNode programStatement1 = default(ISCNode);


			node = new RootNode();

		try { DebugEnterRule(GrammarFileName, "walk");
		DebugLocation(17, 0);
		try
		{
			// Grammar\\SimpleCTreeWalker.g:20:3: ( ^( PROGRAM ( programStatement )* ) )
			DebugEnterAlt(1);
			// Grammar\\SimpleCTreeWalker.g:22:2: ^( PROGRAM ( programStatement )* )
			{
			DebugLocation(22, 2);
			DebugLocation(22, 4);
			Match(input,PROGRAM,Follow._PROGRAM_in_walk61); 

			if (input.LA(1) == TokenTypes.Down)
			{
				Match(input, TokenTypes.Down, null); 
				DebugLocation(22, 12);
				// Grammar\\SimpleCTreeWalker.g:22:12: ( programStatement )*
				try { DebugEnterSubRule(1);
				while (true)
				{
					int alt1=2;
					try { DebugEnterDecision(1, false);
					int LA1_0 = input.LA(1);

					if (((LA1_0>=FUNC_DECL && LA1_0<=FUNC_DEF)||LA1_0==VAR_DEF))
					{
						alt1 = 1;
					}


					} finally { DebugExitDecision(1); }
					switch ( alt1 )
					{
					case 1:
						DebugEnterAlt(1);
						// Grammar\\SimpleCTreeWalker.g:22:13: programStatement
						{
						DebugLocation(22, 13);
						PushFollow(Follow._programStatement_in_walk64);
						programStatement1=programStatement();
						PopFollow();

						DebugLocation(22, 30);
						 node.Children.Add(programStatement1); 

						}
						break;

					default:
						goto loop1;
					}
				}

				loop1:
					;

				} finally { DebugExitSubRule(1); }


				Match(input, TokenTypes.Up, null); 
			}


			}

		}
		catch (RecognitionException re)
		{
			ReportError(re);
			Recover(input,re);
		}
		finally
		{
			TraceOut("walk", 1);
			LeaveRule("walk", 1);
			LeaveRule_walk();
		}
		DebugLocation(23, 0);
		} finally { DebugExitRule(GrammarFileName, "walk"); }
		return node;

	}