예제 #1
0
        public void TestBecomeRoot6() /*throws Exception*/
        {
            // emulates construction of ^(5 6)
            CommonTree root_0 = (CommonTree)adaptor.Nil();
            CommonTree root_1 = (CommonTree)adaptor.Nil();

            root_1 = (CommonTree)adaptor.BecomeRoot(new CommonTree(new CommonToken(5)), root_1);

            adaptor.AddChild(root_1, new CommonTree(new CommonToken(6)));

            adaptor.AddChild(root_0, root_1);

            root_0.SanityCheckParentAndChildIndexes();
        }
예제 #2
0
    // $ANTLR start "start"
    // D:\\Szkolenia\\Artykuł ProgramistaMag - DSL\\Code\\DSLSamples\\HelloWorld\\Simple.g:13:0: start : ID EOF -> ^( START ID ) ;
    public SimpleParser.start_return start() // throws RecognitionException [1]
    {
        SimpleParser.start_return retval = new SimpleParser.start_return();
        retval.Start = input.LT(1);

        CommonTree root_0 = null;

        IToken ID1  = null;
        IToken EOF2 = null;

        CommonTree             ID1_tree   = null;
        CommonTree             EOF2_tree  = null;
        RewriteRuleTokenStream stream_ID  = new RewriteRuleTokenStream(adaptor, "token ID");
        RewriteRuleTokenStream stream_EOF = new RewriteRuleTokenStream(adaptor, "token EOF");

        try
        {
            // D:\\Szkolenia\\Artykuł ProgramistaMag - DSL\\Code\\DSLSamples\\HelloWorld\\Simple.g:13:8: ( ID EOF -> ^( START ID ) )
            // D:\\Szkolenia\\Artykuł ProgramistaMag - DSL\\Code\\DSLSamples\\HelloWorld\\Simple.g:13:8: ID EOF
            {
                ID1 = (IToken)Match(input, ID, FOLLOW_ID_in_start50);
                stream_ID.Add(ID1);

                EOF2 = (IToken)Match(input, EOF, FOLLOW_EOF_in_start52);
                stream_EOF.Add(EOF2);



                // AST REWRITE
                // elements:          ID
                // token labels:
                // rule labels:       retval
                // token list labels:
                // rule list labels:
                // wildcard labels:
                retval.Tree = root_0;
                RewriteRuleSubtreeStream stream_retval = new RewriteRuleSubtreeStream(adaptor, "rule retval", retval != null ? retval.Tree : null);

                root_0 = (CommonTree)adaptor.GetNilNode();
                // 13:15: -> ^( START ID )
                {
                    // D:\\Szkolenia\\Artykuł ProgramistaMag - DSL\\Code\\DSLSamples\\HelloWorld\\Simple.g:13:18: ^( START ID )
                    {
                        CommonTree root_1 = (CommonTree)adaptor.GetNilNode();
                        root_1 = (CommonTree)adaptor.BecomeRoot((CommonTree)adaptor.Create(START, "START"), root_1);

                        adaptor.AddChild(root_1, stream_ID.NextNode());

                        adaptor.AddChild(root_0, root_1);
                    }
                }

                retval.Tree = root_0; retval.Tree = root_0;
            }

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

            retval.Tree = (CommonTree)adaptor.RulePostProcessing(root_0);
            adaptor.SetTokenBoundaries(retval.Tree, (IToken)retval.Start, (IToken)retval.Stop);
        }
        catch (RecognitionException re)
        {
            ReportError(re);
            Recover(input, re);
            // Conversion of the second argument necessary, but harmless
            retval.Tree = (CommonTree)adaptor.ErrorNode(input, (IToken)retval.Start, input.LT(-1), re);
        }
        finally
        {
        }
        return(retval);
    }
예제 #3
0
    // $ANTLR start "additiveExpression"
    // D:\\Szkolenia\\Artykuł ProgramistaMag - DSL\\Code\\DSLSamples\\SimpleDSL\\Simple.g:10:0: additiveExpression : ( multiplicativeExpression ) ( ( '+' | '-' ) multiplicativeExpression )* ;
    public SimpleParser.additiveExpression_return additiveExpression() // throws RecognitionException [1]
    {
        SimpleParser.additiveExpression_return retval = new SimpleParser.additiveExpression_return();
        retval.Start = input.LT(1);

        CommonTree root_0 = null;

        IToken char_literal3 = null;
        IToken char_literal4 = null;

        SimpleParser.multiplicativeExpression_return multiplicativeExpression2 = default(SimpleParser.multiplicativeExpression_return);

        SimpleParser.multiplicativeExpression_return multiplicativeExpression5 = default(SimpleParser.multiplicativeExpression_return);


        CommonTree char_literal3_tree = null;
        CommonTree char_literal4_tree = null;

        try
        {
            // D:\\Szkolenia\\Artykuł ProgramistaMag - DSL\\Code\\DSLSamples\\SimpleDSL\\Simple.g:11:2: ( ( multiplicativeExpression ) ( ( '+' | '-' ) multiplicativeExpression )* )
            // D:\\Szkolenia\\Artykuł ProgramistaMag - DSL\\Code\\DSLSamples\\SimpleDSL\\Simple.g:11:2: ( multiplicativeExpression ) ( ( '+' | '-' ) multiplicativeExpression )*
            {
                root_0 = (CommonTree)adaptor.GetNilNode();

                // D:\\Szkolenia\\Artykuł ProgramistaMag - DSL\\Code\\DSLSamples\\SimpleDSL\\Simple.g:11:2: ( multiplicativeExpression )
                // D:\\Szkolenia\\Artykuł ProgramistaMag - DSL\\Code\\DSLSamples\\SimpleDSL\\Simple.g:11:3: multiplicativeExpression
                {
                    PushFollow(FOLLOW_multiplicativeExpression_in_additiveExpression52);
                    multiplicativeExpression2 = multiplicativeExpression();
                    state.followingStackPointer--;

                    adaptor.AddChild(root_0, multiplicativeExpression2.Tree);
                }

                // D:\\Szkolenia\\Artykuł ProgramistaMag - DSL\\Code\\DSLSamples\\SimpleDSL\\Simple.g:11:29: ( ( '+' | '-' ) multiplicativeExpression )*
                do
                {
                    int alt2  = 2;
                    int LA2_0 = input.LA(1);

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


                    switch (alt2)
                    {
                    case 1:
                        // D:\\Szkolenia\\Artykuł ProgramistaMag - DSL\\Code\\DSLSamples\\SimpleDSL\\Simple.g:11:30: ( '+' | '-' ) multiplicativeExpression
                    {
                        // D:\\Szkolenia\\Artykuł ProgramistaMag - DSL\\Code\\DSLSamples\\SimpleDSL\\Simple.g:11:30: ( '+' | '-' )
                        int alt1  = 2;
                        int LA1_0 = input.LA(1);

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

                            throw nvae_d1s0;
                        }
                        switch (alt1)
                        {
                        case 1:
                            // D:\\Szkolenia\\Artykuł ProgramistaMag - DSL\\Code\\DSLSamples\\SimpleDSL\\Simple.g:11:31: '+'
                        {
                            char_literal3      = (IToken)Match(input, 13, FOLLOW_13_in_additiveExpression57);
                            char_literal3_tree = (CommonTree)adaptor.Create(char_literal3);
                            root_0             = (CommonTree)adaptor.BecomeRoot(char_literal3_tree, root_0);
                        }
                        break;

                        case 2:
                            // D:\\Szkolenia\\Artykuł ProgramistaMag - DSL\\Code\\DSLSamples\\SimpleDSL\\Simple.g:11:36: '-'
                        {
                            char_literal4      = (IToken)Match(input, 7, FOLLOW_7_in_additiveExpression60);
                            char_literal4_tree = (CommonTree)adaptor.Create(char_literal4);
                            root_0             = (CommonTree)adaptor.BecomeRoot(char_literal4_tree, root_0);
                        }
                        break;
                        }

                        PushFollow(FOLLOW_multiplicativeExpression_in_additiveExpression64);
                        multiplicativeExpression5 = multiplicativeExpression();
                        state.followingStackPointer--;

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

                    default:
                        goto loop2;
                    }
                } while (true);

loop2:
                ;               // Stops C# compiler whining that label 'loop2' has no statements
            }

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

            retval.Tree = (CommonTree)adaptor.RulePostProcessing(root_0);
            adaptor.SetTokenBoundaries(retval.Tree, (IToken)retval.Start, (IToken)retval.Stop);
        }
        catch (RecognitionException re)
        {
            ReportError(re);
            Recover(input, re);
            // Conversion of the second argument necessary, but harmless
            retval.Tree = (CommonTree)adaptor.ErrorNode(input, (IToken)retval.Start, input.LT(-1), re);
        }
        finally
        {
        }
        return(retval);
    }