コード例 #1
0
ファイル: Parser.cs プロジェクト: DamianReeves/Functional
 public object ParseFile(string filename, TextReader reader)
 {
     var input = new ANTLRReaderStream(reader);
     var lexer = new FunctionalLexer(input);
     var tokenStream = new CommonTokenStream(lexer);
     var parser = new FunctionalParser(tokenStream);
     var tree = parser.prog().Tree;
     var nodes = new CommonTreeNodeStream(tree);
     var eval = new FunctionalTreeParser(nodes, parser.FunctionDefinitions);
     eval.prog();
     return default(BigInteger);
 }
コード例 #2
0
	private BigInteger call()
	{
		EnterRule_call();
		EnterRule("call", 4);
		TraceIn("call", 4);
		BigInteger value = default(BigInteger);


		CommonTree ID8 = default(CommonTree);
		BigInteger expr7 = default(BigInteger);

		try { DebugEnterRule(GrammarFileName, "call");
		DebugLocation(38, 4);
		try
		{
			// Parsing\\FunctionalTreeParser.g3:39:5: ( ^( CALL ID expr ) )
			DebugEnterAlt(1);
			// Parsing\\FunctionalTreeParser.g3:39:9: ^( CALL ID expr )
			{
			DebugLocation(39, 9);
			DebugLocation(39, 11);
			Match(input,CALL,Follow._CALL_in_call437); 

			Match(input, TokenTypes.Down, null); 
			DebugLocation(39, 16);
			ID8=(CommonTree)Match(input,ID,Follow._ID_in_call439); 
			DebugLocation(39, 19);
			PushFollow(Follow._expr_in_call441);
			expr7=expr();
			PopFollow();


			Match(input, TokenTypes.Up, null); 

			DebugLocation(39, 36);
			 BigInteger p = expr7;
			                                     var funcRoot = this.FindFunction((ID8!=null?ID8.Text:null), p);
			                                     if (funcRoot == null) {
			                                         System.Console.Error.WriteLine("No match found for " + (ID8!=null?ID8.Text:null) + "(" + p + ")");
			                                     } else {
			                                         // Here we set up the local evaluator to run over the
			                                         // function definition with the parameter value.
			                                         // This re-reads a sub-AST of our input AST!
			                                         var e = new FunctionalTreeParser(funcRoot, functionDefinitions, globalMemory, p);
			                                         value = e.expr();
			                                     }
			                                   

			}

		}
		catch (RecognitionException re)
		{
			ReportError(re);
			Recover(input,re);
		}
		finally
		{
			TraceOut("call", 4);
			LeaveRule("call", 4);
			LeaveRule_call();
		}
		DebugLocation(51, 4);
		} finally { DebugExitRule(GrammarFileName, "call"); }
		return value;

	}