public static FNode ParseFNode(string Text, MemoryStruct LocalHeap, Workspace Home, string Alias, Schema Columns, Register Memory) { // Build text stream // AntlrInputStream ais = new AntlrInputStream(Text); HScriptLexer lex = new HScriptLexer(ais); // Build token tree // CommonTokenStream cts = new CommonTokenStream(lex); HScriptParser par = new HScriptParser(cts); // Build AST // IParseTree tree = par.expression(); // Visit each node getting the final node // ExpressionVisitor v = new ExpressionVisitor(LocalHeap, Home); v.AddSchema(Alias, Columns, Memory); return v.Visit(tree); }
public static FNodeSet ParseFNodeSet(string Text, MemoryStruct LocalHeap, Workspace Home, string Alias, Schema Columns, Register Memory) { // Build text stream // AntlrInputStream ais = new AntlrInputStream(Text); HScriptLexer lex = new HScriptLexer(ais); // Build token tree // CommonTokenStream cts = new CommonTokenStream(lex); HScriptParser par = new HScriptParser(cts); // Build AST // IParseTree tree = par.expression_alias_list(); if (tree == null) tree = par.expression_or_wildcard_set(); // Visit each node getting the final node // ExpressionVisitor v = new ExpressionVisitor(LocalHeap, Home); v.AddSchema(Alias, Columns, Memory); if (tree is HScriptParser.Expression_or_wildcard_setContext) { HScriptParser.Expression_or_wildcard_setContext a = tree as HScriptParser.Expression_or_wildcard_setContext; return VisitorHelper.GetReturnStatement(v, a); } else if (tree is HScriptParser.Expression_alias_listContext) { HScriptParser.Expression_alias_listContext b = tree as HScriptParser.Expression_alias_listContext; return v.ToNodes(b); } throw new Exception("Expression is not an expression set: " + Text); }
internal void LoadCommandStack(string Script) { // Clear the current stack // this.Commands.Clear(); this._CompileErrorMessages.Clear(); // Create a token stream and do lexal analysis // AntlrInputStream TextStream = new AntlrInputStream(Script); HScriptLexer HorseLexer = new HScriptLexer(TextStream); // Parse the script // CommonTokenStream HorseTokenStream = new CommonTokenStream(HorseLexer); HScriptParser HorseParser = new HScriptParser(HorseTokenStream); HorseParser.RemoveErrorListeners(); HorseParser.AddErrorListener(new ParserErrorListener()); // Create an executer object // CommandVisitor processor = new CommandVisitor(this.Home); // Load the call stack // try { foreach (HScriptParser.CommandContext context in HorseParser.compile_unit().command_set().command()) { this.Commands.Add(context); } } catch (Exception e) { this._CompileErrorMessages.Add(e.Message); } }