Пример #1
0
 public CommonTree( CommonTree node )
     : base( node )
 {
     this.token = node.token;
     this.startIndex = node.startIndex;
     this.stopIndex = node.stopIndex;
 }
Пример #2
0
 /// <summary>
 /// Convert the ANTLR AST to PsiNode Tree
 /// </summary>
 /// <param name="syntaxTree">The ANTLR AST</param>
 /// <returns>The PsiNode Tree</returns>
 private static IPsiNode ConvertToPsiNode(CommonTree syntaxTree)
 {
     // PsiNode Tree
     return TreeConverter.FromCommonTreeToPsiNode(syntaxTree);
 }
Пример #3
0
 DecimalValueImpl(CommonTree tree) : base(tree, ValueType.DECIMAL)
 {
 }
Пример #4
0
 public DeclareBlockNode(CommonTree node)
     : base(node)
 {
 }
Пример #5
0
        protected static void AddSubTree(XmlNode n, CommonTree t, CssTreeParser ctp)
        {
            var argState = 0;
            var pos      = 0;
            var term     = 0;

            foreach (CommonTree child in ctp.Children(t))
            {
                var name   = child.Text;
                var first  = name.ToCharArray()[0];
                var second = '\0';
                if (name.Length > 1)
                {
                    second = name.ToCharArray()[1];
                }
                if (first >= 'A' && first <= 'Z' && second >= 'A' && second <= 'Z')
                {
                    Debug.Assert(n.OwnerDocument != null, "OwnerDocument != null");
                    var node = n.OwnerDocument.CreateElement(name);
                    if (name == "RULE") // later postion equals greater precedence
                    {
                        _lastClass = _target = "";
                        _noData    = false;
                        _term      = 0;
                    }
                    else if (name == "PROPERTY" && term == 0) // more terms equals greater precedence
                    {
                        term = _term;
                        var termAttr = n.OwnerDocument.CreateAttribute("term");
                        termAttr.Value = term.ToString();
                        if (_target != null && _target.StartsWith("stxfin"))
                        {
                            termAttr.Value = "99";
                        }
                        Debug.Assert(n.Attributes != null, "Attributes != null");
                        n.Attributes.Append(termAttr);
                    }
                    else
                    {
                        _term += 1;
                    }
                    n.AppendChild(node);
                    AddSubTree(node, child, ctp);
                    if (name == "RULE")
                    {
                        if (_noData)
                        {
                            Debug.Assert(node.ParentNode != null, "ParentNode != null");
                            node.ParentNode.RemoveChild(node);
                            continue;
                        }
                        pos += 1;
                        Debug.Assert(n.OwnerDocument != null, "OwnerDocument != null");
                        var posAttr = n.OwnerDocument.CreateAttribute("pos");
                        posAttr.Value = pos.ToString();
                        node.Attributes.Append(posAttr);
                        if (_lastClass != "")
                        {
                            var lastClassAttr = n.OwnerDocument.CreateAttribute("lastClass");
                            lastClassAttr.Value = _lastClass;
                            node.Attributes.Append(lastClassAttr);
                        }
                        if (_target != "")
                        {
                            var targetAttr = n.OwnerDocument.CreateAttribute("target");
                            targetAttr.Value = _target;
                            node.Attributes.Append(targetAttr);
                        }
                    }
                }
                else
                {
                    Debug.Assert(n.OwnerDocument != null, "OwnerDocument != null");
                    var node = n.OwnerDocument.CreateElement(argState == 0? "name": (argState & 1) == 1? "value": "unit");
                    argState      += 1;
                    node.InnerText = name;
                    n.AppendChild(node);
                    if (n.Name == "CLASS")
                    {
                        if (UniqueClasses != null && !UniqueClasses.Contains(name))
                        {
                            _noData = true;
                        }
                        _target = name;
                        if (!NeedHigher.Contains(name))
                        {
                            _lastClass = name;
                        }
                        else
                        {
                            VerboseMessage("skipping: {0}", name);
                        }
                    }
                    if (n.Name == "TAG")
                    {
                        _target = name;
                    }
                    AddSubTree(node, child, ctp);
                }
            }
        }
Пример #6
0
 public PackageDefNode(CommonTree node)
     : base(node)
 {
 }
Пример #7
0
 public NotEqualNode(CommonTree node)
     : base(node)
 {
 }
Пример #8
0
 LangedStringValueImpl(CommonTree tree) : base(tree, ValueType.LANGED_STRING)
 {
 }
Пример #9
0
 public CodeSource(CommonTree tree)
 {
     Line   = tree.Line;
     Column = tree.CharPositionInLine;
 }
Пример #10
0
    // $ANTLR start "multiplicative_expression"
    // FastSimpleExpression.g3:61:0: multiplicative_expression : atom ( ( '*' | '/' | '%' ) atom )* ;
    private FastSimpleExpressionParser.multiplicative_expression_return multiplicative_expression()
    {
        FastSimpleExpressionParser.multiplicative_expression_return retval = new FastSimpleExpressionParser.multiplicative_expression_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        IToken char_literal8  = null;
        IToken char_literal9  = null;
        IToken char_literal10 = null;

        FastSimpleExpressionParser.atom_return atom7  = default(FastSimpleExpressionParser.atom_return);
        FastSimpleExpressionParser.atom_return atom11 = default(FastSimpleExpressionParser.atom_return);

        CommonTree char_literal8_tree  = null;
        CommonTree char_literal9_tree  = null;
        CommonTree char_literal10_tree = null;

        try
        {
            // FastSimpleExpression.g3:62:4: ( atom ( ( '*' | '/' | '%' ) atom )* )
            // FastSimpleExpression.g3:62:4: atom ( ( '*' | '/' | '%' ) atom )*
            {
                root_0 = (CommonTree)adaptor.Nil();

                PushFollow(Follow._atom_in_multiplicative_expression100);
                atom7 = atom();
                PopFollow();

                adaptor.AddChild(root_0, atom7.Tree);
                // FastSimpleExpression.g3:63:3: ( ( '*' | '/' | '%' ) atom )*
                while (true)
                {
                    int alt4  = 2;
                    int LA4_0 = input.LA(1);

                    if (((LA4_0 >= 8 && LA4_0 <= 10)))
                    {
                        alt4 = 1;
                    }


                    switch (alt4)
                    {
                    case 1:
                        // FastSimpleExpression.g3:63:5: ( '*' | '/' | '%' ) atom
                    {
                        // FastSimpleExpression.g3:63:5: ( '*' | '/' | '%' )
                        int alt3 = 3;
                        switch (input.LA(1))
                        {
                        case 9:
                        {
                            alt3 = 1;
                        }
                        break;

                        case 10:
                        {
                            alt3 = 2;
                        }
                        break;

                        case 8:
                        {
                            alt3 = 3;
                        }
                        break;

                        default:
                        {
                            NoViableAltException nvae = new NoViableAltException("", 3, 0, input);

                            throw nvae;
                        }
                        }

                        switch (alt3)
                        {
                        case 1:
                            // FastSimpleExpression.g3:63:6: '*'
                        {
                            char_literal8      = (IToken)Match(input, 9, Follow._9_in_multiplicative_expression107);
                            char_literal8_tree = (CommonTree)adaptor.Create(char_literal8);
                            root_0             = (CommonTree)adaptor.BecomeRoot(char_literal8_tree, root_0);
                        }
                        break;

                        case 2:
                            // FastSimpleExpression.g3:63:13: '/'
                        {
                            char_literal9      = (IToken)Match(input, 10, Follow._10_in_multiplicative_expression112);
                            char_literal9_tree = (CommonTree)adaptor.Create(char_literal9);
                            root_0             = (CommonTree)adaptor.BecomeRoot(char_literal9_tree, root_0);
                        }
                        break;

                        case 3:
                            // FastSimpleExpression.g3:63:20: '%'
                        {
                            char_literal10      = (IToken)Match(input, 8, Follow._8_in_multiplicative_expression117);
                            char_literal10_tree = (CommonTree)adaptor.Create(char_literal10);
                            root_0 = (CommonTree)adaptor.BecomeRoot(char_literal10_tree, root_0);
                        }
                        break;
                        }

                        PushFollow(Follow._atom_in_multiplicative_expression124);
                        atom11 = atom();
                        PopFollow();

                        adaptor.AddChild(root_0, atom11.Tree);
                    }
                    break;

                    default:
                        goto loop4;
                    }
                }

loop4:
                ;
            }

            retval.stop = input.LT(-1);

            retval.tree = (CommonTree)adaptor.RulePostProcessing(root_0);
            adaptor.SetTokenBoundaries(retval.tree, retval.start, retval.stop);
        }
        catch (RecognitionException re)
        {
            ReportError(re);
            Recover(input, re);
            retval.tree = (CommonTree)adaptor.ErrorNode(input, retval.start, input.LT(-1), re);
        }
        finally
        {
        }
        return(retval);
    }
Пример #11
0
    // $ANTLR start "additive_expression"
    // FastSimpleExpression.g3:54:0: additive_expression : multiplicative_expression ( ( '+' | '-' ) multiplicative_expression )* ;
    private FastSimpleExpressionParser.additive_expression_return additive_expression()
    {
        FastSimpleExpressionParser.additive_expression_return retval = new FastSimpleExpressionParser.additive_expression_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        IToken char_literal4 = null;
        IToken char_literal5 = null;

        FastSimpleExpressionParser.multiplicative_expression_return multiplicative_expression3 = default(FastSimpleExpressionParser.multiplicative_expression_return);
        FastSimpleExpressionParser.multiplicative_expression_return multiplicative_expression6 = default(FastSimpleExpressionParser.multiplicative_expression_return);

        CommonTree char_literal4_tree = null;
        CommonTree char_literal5_tree = null;

        try
        {
            // FastSimpleExpression.g3:55:4: ( multiplicative_expression ( ( '+' | '-' ) multiplicative_expression )* )
            // FastSimpleExpression.g3:55:4: multiplicative_expression ( ( '+' | '-' ) multiplicative_expression )*
            {
                root_0 = (CommonTree)adaptor.Nil();

                PushFollow(Follow._multiplicative_expression_in_additive_expression65);
                multiplicative_expression3 = multiplicative_expression();
                PopFollow();

                adaptor.AddChild(root_0, multiplicative_expression3.Tree);
                // FastSimpleExpression.g3:56:3: ( ( '+' | '-' ) multiplicative_expression )*
                while (true)
                {
                    int alt2  = 2;
                    int LA2_0 = input.LA(1);

                    if ((LA2_0 == 7 || LA2_0 == 11))
                    {
                        alt2 = 1;
                    }


                    switch (alt2)
                    {
                    case 1:
                        // FastSimpleExpression.g3:56:5: ( '+' | '-' ) multiplicative_expression
                    {
                        // FastSimpleExpression.g3:56:5: ( '+' | '-' )
                        int alt1  = 2;
                        int LA1_0 = input.LA(1);

                        if ((LA1_0 == 11))
                        {
                            alt1 = 1;
                        }
                        else if ((LA1_0 == 7))
                        {
                            alt1 = 2;
                        }
                        else
                        {
                            NoViableAltException nvae = new NoViableAltException("", 1, 0, input);

                            throw nvae;
                        }
                        switch (alt1)
                        {
                        case 1:
                            // FastSimpleExpression.g3:56:6: '+'
                        {
                            char_literal4      = (IToken)Match(input, 11, Follow._11_in_additive_expression72);
                            char_literal4_tree = (CommonTree)adaptor.Create(char_literal4);
                            root_0             = (CommonTree)adaptor.BecomeRoot(char_literal4_tree, root_0);
                        }
                        break;

                        case 2:
                            // FastSimpleExpression.g3:56:13: '-'
                        {
                            char_literal5      = (IToken)Match(input, 7, Follow._7_in_additive_expression77);
                            char_literal5_tree = (CommonTree)adaptor.Create(char_literal5);
                            root_0             = (CommonTree)adaptor.BecomeRoot(char_literal5_tree, root_0);
                        }
                        break;
                        }

                        PushFollow(Follow._multiplicative_expression_in_additive_expression84);
                        multiplicative_expression6 = multiplicative_expression();
                        PopFollow();

                        adaptor.AddChild(root_0, multiplicative_expression6.Tree);
                    }
                    break;

                    default:
                        goto loop2;
                    }
                }

loop2:
                ;
            }

            retval.stop = input.LT(-1);

            retval.tree = (CommonTree)adaptor.RulePostProcessing(root_0);
            adaptor.SetTokenBoundaries(retval.tree, retval.start, retval.stop);
        }
        catch (RecognitionException re)
        {
            ReportError(re);
            Recover(input, re);
            retval.tree = (CommonTree)adaptor.ErrorNode(input, retval.start, input.LT(-1), re);
        }
        finally
        {
        }
        return(retval);
    }
Пример #12
0
 private void VisitMulti(CommonTree tree)
 {
     throw new NotImplementedException();
 }
Пример #13
0
 private void VisitLeaf(CommonTree tree)
 {
     _opStack.PushConstant(String.Intern(tree.Text));
 }
Пример #14
0
 /// <summary> Creates StringEvalTreeWalker. </summary>
 /// <param name="tree">Parse tree.</param>
 public StringEvalTreeWalker(CommonTree tree)
 {
     _tree        = tree;
     _tree.Parent = null;
 }
Пример #15
0
 public CreateTableNode(CommonTree node)
     : base(node)
 {
 }
Пример #16
0
 internal Interface(CommonTree tree, IContainer parent) : base(tree, parent)
 {
 }
Пример #17
0
 public void emit1(CommonTree opAST, Bytecode opcode, string arg)
 {
     CompilationState.Emit1(opAST, opcode, arg);
 }
Пример #18
0
        protected virtual Expression VisitMethod(CommonTree tree, Expression inner)
        {
            // Calc param types
            var parameters = new Expression[tree.ChildCount - 1];
            var types      = new Type[parameters.Length];

            for (int i = 1; i < tree.ChildCount; i++)
            {
                parameters[i - 1] = Visit((CommonTree)tree.Children[i]);
                types[i - 1]      = parameters[i - 1].Type;
            }

            var methodName = GetMethodName(tree, inner == null);

            Member     member = null;
            Expression callOn = null;

            if (inner == null)
            {
                // Parameters
                var param = Parameters.Where(p => p.Name == methodName).FirstOrDefault();
                if (param != null)
                {
                    return(param);
                }

                // Find method on this
                if (This != null)
                {
                    member = CallProvider.FindMethod(This.Type, methodName, types);
                    if (member != null)
                    {
                        callOn = This;
                    }
                }

                // Static method
                if (member == null)
                {
                    member = CallProvider.FindMethod(null, methodName, types);
                }
            }
            else
            {
                // Instance method
                member = CallProvider.FindMethod(inner.Type, methodName, types);
                if (member != null)
                {
                    callOn = inner;
                }
            }

            if (member == null)
            {
                if (tree.Parent == null || tree.Parent.Type != FormulaLexer.CALL)
                {
                    throw new MethodNotFoundException(
                              string.Format("Method with name '{0}' does not exist.", methodName));
                }

                return(null);
            }

            return(member.CreateExpression(callOn, parameters));
        }
 public JavaScriptMethodRegion(JavaScriptAst ast, CommonTree methodDefinition)
 {
     this.ast = ast;
     this.methodDefinition = methodDefinition;
 }
Пример #20
0
        protected virtual Expression VisitBinary(CommonTree tree)
        {
            ExpressionType type;

            switch (tree.Type)
            {
            case FormulaLexer.PLUS:
                type = ExpressionType.Add;
                break;

            case FormulaLexer.MINUS:
                type = ExpressionType.Subtract;
                break;

            case FormulaLexer.MULTIPLY:
                type = ExpressionType.Multiply;
                break;

            case FormulaLexer.DIVIDE:
                type = ExpressionType.Divide;
                break;

            case FormulaLexer.MODULO:
                type = ExpressionType.Modulo;
                break;

            case FormulaLexer.AND:
                type = ExpressionType.And;
                break;

            case FormulaLexer.OR:
                type = ExpressionType.Or;
                break;

            case FormulaLexer.EQUALS:
                type = ExpressionType.Equal;
                break;

            case FormulaLexer.NOTEQUALS:
                type = ExpressionType.NotEqual;
                break;

            case FormulaLexer.LESSOREQUALS:
                type = ExpressionType.LessThanOrEqual;
                break;

            case FormulaLexer.LESS:
                type = ExpressionType.LessThan;
                break;

            case FormulaLexer.GREATEROREQUALS:
                type = ExpressionType.GreaterThanOrEqual;
                break;

            case FormulaLexer.GREATER:
                type = ExpressionType.GreaterThan;
                break;

            default:
                throw new InvalidOperationException("Invalid AST tree.");
            }

            var arg1 = Visit((CommonTree)tree.Children[0]);
            var arg2 = Visit((CommonTree)tree.Children[1]);


            // TEMP:
            if (arg1.Type == typeof(decimal) && arg2.Type == typeof(int))
            {
                arg2 = Expression.Convert(arg2, typeof(decimal));
            }
            else if (arg1.Type == typeof(int) && arg2.Type == typeof(decimal))
            {
                arg1 = Expression.Convert(arg1, typeof(decimal));
            }

            if (arg1.Type == typeof(string) && arg2.Type == typeof(string) && type == ExpressionType.Add)
            {
                return(Expression.Add(arg1, arg2,
                                      typeof(string).GetMethod("Concat", new[] { typeof(string), typeof(string) })));
            }


            // AndAlso
            return(Expression.MakeBinary(type, arg1, arg2));
        }
 public JavaScriptAst(CommonTokenStream tokenStream, CommonTree tree)
 {
     this.tokenStream = tokenStream;
     this.tree        = tree;
 }
Пример #22
0
 public void emit2(CommonTree opAST, Bytecode opcode, string s, int arg2)
 {
     CompilationState.Emit2(opAST, opcode, s, arg2);
 }
Пример #23
0
 public TableTypeNode(CommonTree node)
     : base(node)
 {
 }
Пример #24
0
 public void emit(CommonTree opAST, Bytecode opcode)
 {
     CompilationState.Emit(opAST, opcode);
 }
Пример #25
0
 public IfNode(CommonTree node)
     : base(node)
 {
 }
Пример #26
0
 private void Indent(CommonTree indent)
 {
     CompilationState.Indent(indent);
 }
Пример #27
0
        public VM.CompiledScript Compile(ICharStream input)
        {
            try
            {
                LSLTreeAdaptor lslAdaptor = new LSLTreeAdaptor();


                //
                // Initial parse and AST creation
                //
                LSLLexer          lex    = new LSLLexer(input);
                CommonTokenStream tokens = new CommonTokenStream(lex);
                LSLParser         p      = new LSLParser(tokens);
                p.TreeAdaptor        = lslAdaptor;
                p.TraceDestination   = _traceRedirect;
                lex.TraceDestination = _traceRedirect;
                LSLParser.prog_return r = p.prog();

                if (p.NumberOfSyntaxErrors > 0)
                {
                    _listener.Error(Convert.ToString(p.NumberOfSyntaxErrors) + " syntax error(s)");
                    return(null);
                }


                //
                // Definitions
                //
                CommonTree           t     = (CommonTree)r.Tree;
                CommonTreeNodeStream nodes = new CommonTreeNodeStream(lslAdaptor, t);
                nodes.TokenStream = tokens;

                SymbolTable symtab = new SymbolTable(tokens, Defaults.SystemMethods.Values, DefaultConstants.Constants.Values);
                symtab.StatusListener = _listener;

                Def def = new Def(nodes, symtab);
                def.TraceDestination = _traceRedirect;
                def.Downup(t);

                nodes.Reset();

                if (_listener.HasErrors() || def.NumberOfSyntaxErrors > 0)
                {
                    return(null);
                }


                //
                // Type and more semantic checks
                //
                Compiler.Types types = new Compiler.Types(nodes, symtab);
                types.TraceDestination = _traceRedirect;
                types.Downup(t);

                nodes.Reset();

                if (_listener.HasErrors() || types.NumberOfSyntaxErrors > 0)
                {
                    return(null);
                }


                StringTemplateGroup templates;
                using (TextReader fr = new StreamReader(Path.Combine(_templatePath, "ByteCode.stg")))
                {
                    templates = new StringTemplateGroup(fr);
                    fr.Close();
                }

                if (_outputAstGraph)
                {
                    DotTreeGenerator dotgen = new DotTreeGenerator();
                    string           dot    = dotgen.ToDot(t);

                    TextWriter tw = new StreamWriter("ast.txt");
                    tw.WriteLine(dot);
                    tw.Close();
                }

                Analyze analyze = new Analyze(nodes, symtab);
                analyze.TraceDestination = _traceRedirect;
                analyze.Downup(t);

                nodes.Reset();

                foreach (Compiler.BranchAnalyze.FunctionBranch b in analyze.FunctionBranches.Where(pred => pred.Type != null))
                {
                    if (!b.AllCodePathsReturn())
                    {
                        if (_listener != null)
                        {
                            _listener.Error("line: " + b.Node.Line + ":" +
                                            b.Node.CharPositionInLine + " " + b.Node.Text + "(): Not all control paths return a value");
                        }
                    }
                }

                if (_listener.HasErrors() || analyze.NumberOfSyntaxErrors > 0)
                {
                    return(null);
                }


                //
                // Bytecode generation
                //
                Gen g = new Gen(nodes, symtab);
                g.TemplateGroup    = templates;
                g.TraceDestination = _traceRedirect;

                Gen.script_return ret = g.script();

                if (_listener.HasErrors() || g.NumberOfSyntaxErrors > 0)
                {
                    return(null);
                }

                if (ret.Template == null)
                {
                    return(null);
                }

                StringTemplate template = ret.Template;

                if (_byteCodeDebugging)
                {
                    _byteCode = template.ToString();
                }

                //
                // Bytecode compilation
                //
                AssemblerLexer    alex    = new AssemblerLexer(new ANTLRStringStream(template.ToString()));
                CommonTokenStream atokens = new CommonTokenStream(alex);
                AssemblerParser   ap      = new AssemblerParser(atokens);
                BytecodeGenerator bcgen   = new BytecodeGenerator(Defaults.SystemMethods.Values);

                ap.SetGenerator(bcgen);
                ap.TraceDestination = _traceRedirect;

                try
                {
                    ap.program();

                    if (_listener.HasErrors() || p.NumberOfSyntaxErrors > 0)
                    {
                        _listener.Error(Convert.ToString(ap.NumberOfSyntaxErrors) + " bytecode generation error(s)");
                        return(null);
                    }

                    return(bcgen.Result);
                }
                catch (GenerationException e)
                {
                    _listener.Error(e.Message);
                }

                return(null);
            }
            catch (TooManyErrorsException e)
            {
                _listener.Error(String.Format("Too many errors {0}", e.InnerException.Message));
            }
            catch (RecognitionException e)
            {
                _listener.Error("line: " + e.Line.ToString() + ":" + e.CharPositionInLine.ToString() + " " + e.Message);
            }
            catch (Exception e)
            {
                _listener.Error(e.Message);
            }

            return(null);
        }
Пример #28
0
 public void setOption(CommonTree id)
 {
     CompilationState.SetOption(id);
 }
Пример #29
0
 public AssignVarNode(CommonTree node)
     : base(node)
 {
 }
Пример #30
0
 public void func(CommonTree id)
 {
     CompilationState.Function(templateToken, id);
 }
Пример #31
0
 public void refAttr(CommonTree id)
 {
     CompilationState.ReferenceAttribute(templateToken, id);
 }
 /// <summary>Creates the selector expression node.</summary>
 /// <param name="selectorExpressionTree">The selector expression tree.</param>
 /// <returns>The selector expression node.</returns>
 private static SelectorExpressionNode CreateSelectorExpressionNode(CommonTree selectorExpressionTree)
 {
     return(selectorExpressionTree == null ? null : new SelectorExpressionNode(
                selectorExpressionTree.Children().Select(_ => _.TextOrDefault()).ToSafeReadOnlyCollection()));
 }