Hello,

I am having a difficulty with my tree grammar. The java class definition that antrl produces from the grammar will not compile.

In the grammar (see the attached grammar file) the start rule calls the booleanExpression rule passing it a string argument. In the generated class the start() method  invokes a "delegated" rule which in turn invokes a "fragment" which in turn invokes the booleanExpression() method (see line 867 in the attached java file) passing it the string argument which was never passed in by the start() method???

I am trying to work around it - any advice will be much appreciated.
Best Regards,

Robert Vaessen


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

// $ANTLR 3.1.1 ClientApiTreeParser.g 2008-11-08 11:15:05

package com.wachovia.cib.robert.antlr.clientApi;

import java.io.*;
import com.wachovia.cib.cdl.*;


import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;import java.util.Stack;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
public class ClientApiTreeParser extends ClientApiBaseTreeParser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "BooleanExpression", "RelationalExpression", "Predicate", "Function", "Letter", "Ampersand", "ElementSeperator", "OpenBracket", "CloseBracket", "OpenParen", "CloseParen", "IntegerLiteral", "DecimalLiteral", "DoubleLiteral", "StringLiteral", "RelationalOperator", "BooleanOperator", "FunctionName", "Name", "WhiteSpace"
    };
    public static final int BooleanOperator=20;
    public static final int CloseParen=14;
    public static final int RelationalOperator=19;
    public static final int BooleanExpression=4;
    public static final int EOF=-1;
    public static final int FunctionName=21;
    public static final int DecimalLiteral=16;
    public static final int Ampersand=9;
    public static final int StringLiteral=18;
    public static final int CloseBracket=12;
    public static final int Function=7;
    public static final int OpenParen=13;
    public static final int OpenBracket=11;
    public static final int Name=22;
    public static final int WhiteSpace=23;
    public static final int RelationalExpression=5;
    public static final int IntegerLiteral=15;
    public static final int Predicate=6;
    public static final int DoubleLiteral=17;
    public static final int Letter=8;
    public static final int ElementSeperator=10;

    // delegates
    // delegators


        public ClientApiTreeParser(TreeNodeStream input) {
            this(input, new RecognizerSharedState());
        }
        public ClientApiTreeParser(TreeNodeStream input, RecognizerSharedState state) {
            super(input, state);
             
        }
        

    public String[] getTokenNames() { return ClientApiTreeParser.tokenNames; }
    public String getGrammarFileName() { return "ClientApiTreeParser.g"; }


    	private String mCdlVariableName;

    	public static void main(String[] inArgs) throws Exception {
    		if (inArgs.length == 1) {
    			BufferedReader theInputReader = new BufferedReader(new InputStreamReader(new FileInputStream(inArgs[0])));

    			String theLine;
    			while ((theLine = theInputReader.readLine()) != null) {
    				int theIndex = theLine.indexOf("->");
    				String theCdlClassName = theLine.substring(0, theIndex); 
    				String theXPathExpression = theLine.substring(theIndex + 2); 

    				try {
    					System.out.println("\nCode to extract \"" + theXPathExpression + "\" from \"" + theCdlClassName + "\":");
    					System.out.println('\t' + getTreeParser(theXPathExpression).start(theCdlClassName, "inCdlObject"));
    				}
    				catch (Throwable t) {
    					t.printStackTrace();
    				}
    			}
    		}
    		else {
    			System.err.println("Please provide the name of a file containing a list of expressions to be evaluated");
    		}
    		System.exit(0);
    	}

    	public static String getExtractionCode(String inCdlClassName, String inCdlVariableName, String inXPathExpression) throws RecognitionException {
    		return getTreeParser(inXPathExpression).start(inCdlClassName, inCdlVariableName);
    	}

    	private static ClientApiTreeParser getTreeParser(String inXPathExpression) throws RecognitionException {
    		CharStream theTextStream = new ANTLRStringStream(inXPathExpression);
    		ClientApiLexer theLexer = new ClientApiLexer(theTextStream);
    		CommonTokenStream theTokenStream = new CommonTokenStream(theLexer);
    		ClientApiParser theParser = new ClientApiParser(theTokenStream);
    		CommonTree theTree = (CommonTree) theParser.start().getTree();
    		CommonTreeNodeStream theNodes = new CommonTreeNodeStream(theTree); 
    		ClientApiTreeParser theTreeParser = new ClientApiTreeParser(theNodes);
    		return theTreeParser;
    	}



    // $ANTLR start "start"
    // ClientApiTreeParser.g:61:1: start[String inCdlClassName, String inCdlVariableName] returns [String code] : ( booleanExpression[inCdlVariableName] | objectPath[builder] );
    public final String start(String inCdlClassName, String inCdlVariableName) throws RecognitionException {
        String code = null;

        String booleanExpression1 = null;



        	linkDefinitions();
        	pushDefiniton(inCdlClassName);
        	mCdlVariableName = inCdlVariableName;
        	CodeBuilder builder = new CodeBuilder();

        try {
            // ClientApiTreeParser.g:72:2: ( booleanExpression[inCdlVariableName] | objectPath[builder] )
            int alt1=2;
            int LA1_0 = input.LA(1);

            if ( (LA1_0==Name) ) {
                int LA1_1 = input.LA(2);

                if ( (synpred1_ClientApiTreeParser()) ) {
                    alt1=1;
                }
                else if ( (true) ) {
                    alt1=2;
                }
                else {
                    if (state.backtracking>0) {state.failed=true; return code;}
                    NoViableAltException nvae =
                        new NoViableAltException("", 1, 1, input);

                    throw nvae;
                }
            }
            else if ( (LA1_0==Function) ) {
                alt1=1;
            }
            else {
                if (state.backtracking>0) {state.failed=true; return code;}
                NoViableAltException nvae =
                    new NoViableAltException("", 1, 0, input);

                throw nvae;
            }
            switch (alt1) {
                case 1 :
                    // ClientApiTreeParser.g:72:4: booleanExpression[inCdlVariableName]
                    {
                    pushFollow(FOLLOW_booleanExpression_in_start77);
                    booleanExpression1=booleanExpression(inCdlVariableName);

                    state._fsp--;
                    if (state.failed) return code;
                    if ( state.backtracking==0 ) {
                       builder.append(booleanExpression1); 
                    }

                    }
                    break;
                case 2 :
                    // ClientApiTreeParser.g:73:4: objectPath[builder]
                    {
                    pushFollow(FOLLOW_objectPath_in_start85);
                    objectPath(builder);

                    state._fsp--;
                    if (state.failed) return code;

                    }
                    break;

            }
            if ( state.backtracking==0 ) {

              	code = builder.toString();
              	unlinkDefinitions();

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return code;
    }
    // $ANTLR end "start"


    // $ANTLR start "booleanExpression"
    // ClientApiTreeParser.g:77:1: booleanExpression[String variableName] returns [String code] : left= relationalExpression ( ( booleanOperator ) right= relationalExpression )* ;
    public final String booleanExpression(String variableName) throws RecognitionException {
        String code = null;

        String left = null;

        String right = null;

        String booleanOperator2 = null;



        	CodeBuilder builder = new CodeBuilder();

        try {
            // ClientApiTreeParser.g:84:2: (left= relationalExpression ( ( booleanOperator ) right= relationalExpression )* )
            // ClientApiTreeParser.g:84:4: left= relationalExpression ( ( booleanOperator ) right= relationalExpression )*
            {
            pushFollow(FOLLOW_relationalExpression_in_booleanExpression115);
            left=relationalExpression();

            state._fsp--;
            if (state.failed) return code;
            if ( state.backtracking==0 ) {
               builder.append(left); 
            }
            // ClientApiTreeParser.g:84:62: ( ( booleanOperator ) right= relationalExpression )*
            loop2:
            do {
                int alt2=2;
                int LA2_0 = input.LA(1);

                if ( (LA2_0==BooleanOperator) ) {
                    alt2=1;
                }


                switch (alt2) {
            	case 1 :
            	    // ClientApiTreeParser.g:84:63: ( booleanOperator ) right= relationalExpression
            	    {
            	    // ClientApiTreeParser.g:84:63: ( booleanOperator )
            	    // ClientApiTreeParser.g:84:64: booleanOperator
            	    {
            	    pushFollow(FOLLOW_booleanOperator_in_booleanExpression121);
            	    booleanOperator2=booleanOperator();

            	    state._fsp--;
            	    if (state.failed) return code;

            	    }

            	    pushFollow(FOLLOW_relationalExpression_in_booleanExpression126);
            	    right=relationalExpression();

            	    state._fsp--;
            	    if (state.failed) return code;

            	    }
            	    break;

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

            if ( state.backtracking==0 ) {
               builder.insert(0, '(').append(booleanOperator2).append(right).append(')'); 
            }

            }

            if ( state.backtracking==0 ) {

              	code = builder.toString();

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return code;
    }
    // $ANTLR end "booleanExpression"


    // $ANTLR start "relationalExpression"
    // ClientApiTreeParser.g:87:1: relationalExpression returns [String code] : ( objectPath[builder] relationalOperator literal | function[builder] relationalOperator literal );
    public final String relationalExpression() throws RecognitionException {
        String code = null;

        String relationalOperator3 = null;

        String literal4 = null;

        String relationalOperator5 = null;

        String literal6 = null;



        	linkDefinitions();
        	CodeBuilder builder = new CodeBuilder();

        try {
            // ClientApiTreeParser.g:96:2: ( objectPath[builder] relationalOperator literal | function[builder] relationalOperator literal )
            int alt3=2;
            int LA3_0 = input.LA(1);

            if ( (LA3_0==Name) ) {
                alt3=1;
            }
            else if ( (LA3_0==Function) ) {
                alt3=2;
            }
            else {
                if (state.backtracking>0) {state.failed=true; return code;}
                NoViableAltException nvae =
                    new NoViableAltException("", 3, 0, input);

                throw nvae;
            }
            switch (alt3) {
                case 1 :
                    // ClientApiTreeParser.g:96:4: objectPath[builder] relationalOperator literal
                    {
                    pushFollow(FOLLOW_objectPath_in_relationalExpression155);
                    objectPath(builder);

                    state._fsp--;
                    if (state.failed) return code;
                    pushFollow(FOLLOW_relationalOperator_in_relationalExpression158);
                    relationalOperator3=relationalOperator();

                    state._fsp--;
                    if (state.failed) return code;
                    pushFollow(FOLLOW_literal_in_relationalExpression160);
                    literal4=literal();

                    state._fsp--;
                    if (state.failed) return code;
                    if ( state.backtracking==0 ) {
                       builder.append(' ').append(relationalOperator3).append(' ').append(literal4); 
                    }

                    }
                    break;
                case 2 :
                    // ClientApiTreeParser.g:97:4: function[builder] relationalOperator literal
                    {
                    pushFollow(FOLLOW_function_in_relationalExpression167);
                    function(builder);

                    state._fsp--;
                    if (state.failed) return code;
                    pushFollow(FOLLOW_relationalOperator_in_relationalExpression170);
                    relationalOperator5=relationalOperator();

                    state._fsp--;
                    if (state.failed) return code;
                    pushFollow(FOLLOW_literal_in_relationalExpression172);
                    literal6=literal();

                    state._fsp--;
                    if (state.failed) return code;
                    if ( state.backtracking==0 ) {
                       builder.append("<funtion> ").append(relationalOperator5).append(' ').append(literal6); 
                    }

                    }
                    break;

            }
            if ( state.backtracking==0 ) {

              	code = builder.toString();
              	unlinkDefinitions();

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return code;
    }
    // $ANTLR end "relationalExpression"


    // $ANTLR start "objectPath"
    // ClientApiTreeParser.g:100:1: objectPath[CodeBuilder code] : memberReference[code] ( memberReference[code] )* ;
    public final void objectPath(CodeBuilder code) throws RecognitionException {
        try {
            // ClientApiTreeParser.g:101:2: ( memberReference[code] ( memberReference[code] )* )
            // ClientApiTreeParser.g:101:4: memberReference[code] ( memberReference[code] )*
            {
            pushFollow(FOLLOW_memberReference_in_objectPath186);
            memberReference(code);

            state._fsp--;
            if (state.failed) return ;
            // ClientApiTreeParser.g:101:26: ( memberReference[code] )*
            loop4:
            do {
                int alt4=2;
                int LA4_0 = input.LA(1);

                if ( (LA4_0==Name) ) {
                    alt4=1;
                }


                switch (alt4) {
            	case 1 :
            	    // ClientApiTreeParser.g:0:0: memberReference[code]
            	    {
            	    pushFollow(FOLLOW_memberReference_in_objectPath189);
            	    memberReference(code);

            	    state._fsp--;
            	    if (state.failed) return ;

            	    }
            	    break;

            	default :
            	    break loop4;
                }
            } while (true);


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end "objectPath"


    // $ANTLR start "memberReference"
    // ClientApiTreeParser.g:104:1: memberReference[CodeBuilder code] : ( ^( name[code] predicate[code] ) | name[code] );
    public final void memberReference(CodeBuilder code) throws RecognitionException {
        try {
            // ClientApiTreeParser.g:105:2: ( ^( name[code] predicate[code] ) | name[code] )
            int alt5=2;
            int LA5_0 = input.LA(1);

            if ( (LA5_0==Name) ) {
                int LA5_1 = input.LA(2);

                if ( (LA5_1==DOWN) ) {
                    alt5=1;
                }
                else if ( (LA5_1==EOF||LA5_1==UP||LA5_1==RelationalOperator||LA5_1==Name) ) {
                    alt5=2;
                }
                else {
                    if (state.backtracking>0) {state.failed=true; return ;}
                    NoViableAltException nvae =
                        new NoViableAltException("", 5, 1, input);

                    throw nvae;
                }
            }
            else {
                if (state.backtracking>0) {state.failed=true; return ;}
                NoViableAltException nvae =
                    new NoViableAltException("", 5, 0, input);

                throw nvae;
            }
            switch (alt5) {
                case 1 :
                    // ClientApiTreeParser.g:105:4: ^( name[code] predicate[code] )
                    {
                    pushFollow(FOLLOW_name_in_memberReference204);
                    name(code);

                    state._fsp--;
                    if (state.failed) return ;

                    match(input, Token.DOWN, null); if (state.failed) return ;
                    pushFollow(FOLLOW_predicate_in_memberReference207);
                    predicate(code);

                    state._fsp--;
                    if (state.failed) return ;

                    match(input, Token.UP, null); if (state.failed) return ;
                    if ( state.backtracking==0 ) {
                       addCast(code); 
                    }

                    }
                    break;
                case 2 :
                    // ClientApiTreeParser.g:106:4: name[code]
                    {
                    pushFollow(FOLLOW_name_in_memberReference216);
                    name(code);

                    state._fsp--;
                    if (state.failed) return ;

                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end "memberReference"


    // $ANTLR start "name"
    // ClientApiTreeParser.g:109:1: name[CodeBuilder code] : Name ;
    public final void name(CodeBuilder code) throws RecognitionException {
        CommonTree Name7=null;

        try {
            // ClientApiTreeParser.g:110:2: ( Name )
            // ClientApiTreeParser.g:110:4: Name
            {
            Name7=(CommonTree)match(input,Name,FOLLOW_Name_in_name229); if (state.failed) return ;
            if ( state.backtracking==0 ) {

              			String theName = (Name7!=null?Name7.getText():null).substring(0, 1).toUpperCase() + (Name7!=null?Name7.getText():null).substring(1); // Change first letter to upper case
              			code.append(".get").append(theName).append("()");
              			pushDefiniton(theName);
              		
            }

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end "name"


    // $ANTLR start "predicate"
    // ClientApiTreeParser.g:117:1: predicate[CodeBuilder code] : ( IntegerLiteral | relationalExpression );
    public final void predicate(CodeBuilder code) throws RecognitionException {
        CommonTree IntegerLiteral8=null;
        String relationalExpression9 = null;


        try {
            // ClientApiTreeParser.g:118:2: ( IntegerLiteral | relationalExpression )
            int alt6=2;
            int LA6_0 = input.LA(1);

            if ( (LA6_0==IntegerLiteral) ) {
                alt6=1;
            }
            else if ( (LA6_0==Function||LA6_0==Name) ) {
                alt6=2;
            }
            else {
                if (state.backtracking>0) {state.failed=true; return ;}
                NoViableAltException nvae =
                    new NoViableAltException("", 6, 0, input);

                throw nvae;
            }
            switch (alt6) {
                case 1 :
                    // ClientApiTreeParser.g:118:4: IntegerLiteral
                    {
                    IntegerLiteral8=(CommonTree)match(input,IntegerLiteral,FOLLOW_IntegerLiteral_in_predicate243); if (state.failed) return ;
                    if ( state.backtracking==0 ) {
                       code.append(".get(").append((IntegerLiteral8!=null?IntegerLiteral8.getText():null)).append(')'); 
                    }

                    }
                    break;
                case 2 :
                    // ClientApiTreeParser.g:119:4: relationalExpression
                    {
                    pushFollow(FOLLOW_relationalExpression_in_predicate252);
                    relationalExpression9=relationalExpression();

                    state._fsp--;
                    if (state.failed) return ;
                    if ( state.backtracking==0 ) {
                       code.append(".find(").append(relationalExpression9).append(')');  
                    }

                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end "predicate"


    // $ANTLR start "function"
    // ClientApiTreeParser.g:122:1: function[CodeBuilder code] : ^( Function FunctionName objectPath[code] ) ;
    public final void function(CodeBuilder code) throws RecognitionException {
        try {
            // ClientApiTreeParser.g:123:2: ( ^( Function FunctionName objectPath[code] ) )
            // ClientApiTreeParser.g:123:4: ^( Function FunctionName objectPath[code] )
            {
            match(input,Function,FOLLOW_Function_in_function267); if (state.failed) return ;

            match(input, Token.DOWN, null); if (state.failed) return ;
            match(input,FunctionName,FOLLOW_FunctionName_in_function269); if (state.failed) return ;
            pushFollow(FOLLOW_objectPath_in_function271);
            objectPath(code);

            state._fsp--;
            if (state.failed) return ;

            match(input, Token.UP, null); if (state.failed) return ;

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end "function"


    // $ANTLR start "booleanOperator"
    // ClientApiTreeParser.g:126:1: booleanOperator returns [String text] : BooleanOperator ;
    public final String booleanOperator() throws RecognitionException {
        String text = null;

        CommonTree BooleanOperator10=null;

        try {
            // ClientApiTreeParser.g:127:2: ( BooleanOperator )
            // ClientApiTreeParser.g:127:5: BooleanOperator
            {
            BooleanOperator10=(CommonTree)match(input,BooleanOperator,FOLLOW_BooleanOperator_in_booleanOperator289); if (state.failed) return text;
            if ( state.backtracking==0 ) {
               text = "or".equals((BooleanOperator10!=null?BooleanOperator10.getText():null)) ? "||" : "&&"; 
            }

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return text;
    }
    // $ANTLR end "booleanOperator"


    // $ANTLR start "relationalOperator"
    // ClientApiTreeParser.g:130:1: relationalOperator returns [String text] : RelationalOperator ;
    public final String relationalOperator() throws RecognitionException {
        String text = null;

        CommonTree RelationalOperator11=null;

        try {
            // ClientApiTreeParser.g:131:2: ( RelationalOperator )
            // ClientApiTreeParser.g:131:5: RelationalOperator
            {
            RelationalOperator11=(CommonTree)match(input,RelationalOperator,FOLLOW_RelationalOperator_in_relationalOperator307); if (state.failed) return text;
            if ( state.backtracking==0 ) {
               text = "=".equals((RelationalOperator11!=null?RelationalOperator11.getText():null)) ? "==" : (RelationalOperator11!=null?RelationalOperator11.getText():null); 
            }

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return text;
    }
    // $ANTLR end "relationalOperator"


    // $ANTLR start "numericLiteral"
    // ClientApiTreeParser.g:134:1: numericLiteral returns [String text] : ( IntegerLiteral | DecimalLiteral | DoubleLiteral );
    public final String numericLiteral() throws RecognitionException {
        String text = null;

        CommonTree IntegerLiteral12=null;
        CommonTree DecimalLiteral13=null;
        CommonTree DoubleLiteral14=null;

        try {
            // ClientApiTreeParser.g:135:2: ( IntegerLiteral | DecimalLiteral | DoubleLiteral )
            int alt7=3;
            switch ( input.LA(1) ) {
            case IntegerLiteral:
                {
                alt7=1;
                }
                break;
            case DecimalLiteral:
                {
                alt7=2;
                }
                break;
            case DoubleLiteral:
                {
                alt7=3;
                }
                break;
            default:
                if (state.backtracking>0) {state.failed=true; return text;}
                NoViableAltException nvae =
                    new NoViableAltException("", 7, 0, input);

                throw nvae;
            }

            switch (alt7) {
                case 1 :
                    // ClientApiTreeParser.g:135:4: IntegerLiteral
                    {
                    IntegerLiteral12=(CommonTree)match(input,IntegerLiteral,FOLLOW_IntegerLiteral_in_numericLiteral324); if (state.failed) return text;
                    if ( state.backtracking==0 ) {
                       text = (IntegerLiteral12!=null?IntegerLiteral12.getText():null); 
                    }

                    }
                    break;
                case 2 :
                    // ClientApiTreeParser.g:136:4: DecimalLiteral
                    {
                    DecimalLiteral13=(CommonTree)match(input,DecimalLiteral,FOLLOW_DecimalLiteral_in_numericLiteral331); if (state.failed) return text;
                    if ( state.backtracking==0 ) {
                       text = (DecimalLiteral13!=null?DecimalLiteral13.getText():null); 
                    }

                    }
                    break;
                case 3 :
                    // ClientApiTreeParser.g:137:4: DoubleLiteral
                    {
                    DoubleLiteral14=(CommonTree)match(input,DoubleLiteral,FOLLOW_DoubleLiteral_in_numericLiteral338); if (state.failed) return text;
                    if ( state.backtracking==0 ) {
                       text = (DoubleLiteral14!=null?DoubleLiteral14.getText():null); 
                    }

                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return text;
    }
    // $ANTLR end "numericLiteral"


    // $ANTLR start "literal"
    // ClientApiTreeParser.g:140:1: literal returns [String text] : ( StringLiteral | numericLiteral );
    public final String literal() throws RecognitionException {
        String text = null;

        CommonTree StringLiteral15=null;
        String numericLiteral16 = null;


        try {
            // ClientApiTreeParser.g:141:2: ( StringLiteral | numericLiteral )
            int alt8=2;
            int LA8_0 = input.LA(1);

            if ( (LA8_0==StringLiteral) ) {
                alt8=1;
            }
            else if ( ((LA8_0>=IntegerLiteral && LA8_0<=DoubleLiteral)) ) {
                alt8=2;
            }
            else {
                if (state.backtracking>0) {state.failed=true; return text;}
                NoViableAltException nvae =
                    new NoViableAltException("", 8, 0, input);

                throw nvae;
            }
            switch (alt8) {
                case 1 :
                    // ClientApiTreeParser.g:141:4: StringLiteral
                    {
                    StringLiteral15=(CommonTree)match(input,StringLiteral,FOLLOW_StringLiteral_in_literal355); if (state.failed) return text;
                    if ( state.backtracking==0 ) {
                       text = (StringLiteral15!=null?StringLiteral15.getText():null); 
                    }

                    }
                    break;
                case 2 :
                    // ClientApiTreeParser.g:142:4: numericLiteral
                    {
                    pushFollow(FOLLOW_numericLiteral_in_literal362);
                    numericLiteral16=numericLiteral();

                    state._fsp--;
                    if (state.failed) return text;
                    if ( state.backtracking==0 ) {
                       text = numericLiteral16; 
                    }

                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return text;
    }
    // $ANTLR end "literal"

    // $ANTLR start synpred1_ClientApiTreeParser
    public final void synpred1_ClientApiTreeParser_fragment() throws RecognitionException {   
        // ClientApiTreeParser.g:72:4: ( booleanExpression[inCdlVariableName] )
        // ClientApiTreeParser.g:72:4: booleanExpression[inCdlVariableName]
        {
        pushFollow(FOLLOW_booleanExpression_in_synpred1_ClientApiTreeParser77);
        booleanExpression(inCdlVariableName);

        state._fsp--;
        if (state.failed) return ;

        }
    }
    // $ANTLR end synpred1_ClientApiTreeParser

    // Delegated rules

    public final boolean synpred1_ClientApiTreeParser() {
        state.backtracking++;
        int start = input.mark();
        try {
            synpred1_ClientApiTreeParser_fragment(); // can never throw exception
        } catch (RecognitionException re) {
            System.err.println("impossible: "+re);
        }
        boolean success = !state.failed;
        input.rewind(start);
        state.backtracking--;
        state.failed=false;
        return success;
    }


 

    public static final BitSet FOLLOW_booleanExpression_in_start77 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_objectPath_in_start85 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_relationalExpression_in_booleanExpression115 = new BitSet(new long[]{0x0000000000100002L});
    public static final BitSet FOLLOW_booleanOperator_in_booleanExpression121 = new BitSet(new long[]{0x0000000000400080L});
    public static final BitSet FOLLOW_relationalExpression_in_booleanExpression126 = new BitSet(new long[]{0x0000000000100002L});
    public static final BitSet FOLLOW_objectPath_in_relationalExpression155 = new BitSet(new long[]{0x0000000000080000L});
    public static final BitSet FOLLOW_relationalOperator_in_relationalExpression158 = new BitSet(new long[]{0x0000000000078000L});
    public static final BitSet FOLLOW_literal_in_relationalExpression160 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_function_in_relationalExpression167 = new BitSet(new long[]{0x0000000000080000L});
    public static final BitSet FOLLOW_relationalOperator_in_relationalExpression170 = new BitSet(new long[]{0x0000000000078000L});
    public static final BitSet FOLLOW_literal_in_relationalExpression172 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_memberReference_in_objectPath186 = new BitSet(new long[]{0x0000000000400002L});
    public static final BitSet FOLLOW_memberReference_in_objectPath189 = new BitSet(new long[]{0x0000000000400002L});
    public static final BitSet FOLLOW_name_in_memberReference204 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_predicate_in_memberReference207 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_name_in_memberReference216 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_Name_in_name229 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_IntegerLiteral_in_predicate243 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_relationalExpression_in_predicate252 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_Function_in_function267 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_FunctionName_in_function269 = new BitSet(new long[]{0x0000000000400000L});
    public static final BitSet FOLLOW_objectPath_in_function271 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_BooleanOperator_in_booleanOperator289 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_RelationalOperator_in_relationalOperator307 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_IntegerLiteral_in_numericLiteral324 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_DecimalLiteral_in_numericLiteral331 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_DoubleLiteral_in_numericLiteral338 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_StringLiteral_in_literal355 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_numericLiteral_in_literal362 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_booleanExpression_in_synpred1_ClientApiTreeParser77 = new BitSet(new long[]{0x0000000000000002L});

}
tree grammar ClientApiTreeParser;

options {
        ASTLabelType = CommonTree;
        backtrack = true;
        superClass = ClientApiBaseTreeParser;
        tokenVocab = ClientApi;
}

@header {
package com.wachovia.cib.robert.antlr.clientApi;

import java.io.*;
import com.wachovia.cib.cdl.*;
}

@members {
        private String mCdlVariableName;

        public static void main(String[] inArgs) throws Exception {
                if (inArgs.length == 1) {
                        BufferedReader theInputReader = new BufferedReader(new 
InputStreamReader(new FileInputStream(inArgs[0])));

                        String theLine;
                        while ((theLine = theInputReader.readLine()) != null) {
                                int theIndex = theLine.indexOf("->");
                                String theCdlClassName = theLine.substring(0, 
theIndex); 
                                String theXPathExpression = 
theLine.substring(theIndex + 2); 

                                try {
                                        System.out.println("\nCode to extract 
\"" + theXPathExpression + "\" from \"" + theCdlClassName + "\":");
                                        System.out.println('\t' + 
getTreeParser(theXPathExpression).start(theCdlClassName, "inCdlObject"));
                                }
                                catch (Throwable t) {
                                        t.printStackTrace();
                                }
                        }
                }
                else {
                        System.err.println("Please provide the name of a file 
containing a list of expressions to be evaluated");
                }
                System.exit(0);
        }

        public static String getExtractionCode(String inCdlClassName, String 
inCdlVariableName, String inXPathExpression) throws RecognitionException {
                return getTreeParser(inXPathExpression).start(inCdlClassName, 
inCdlVariableName);
        }

        private static ClientApiTreeParser getTreeParser(String 
inXPathExpression) throws RecognitionException {
                CharStream theTextStream = new 
ANTLRStringStream(inXPathExpression);
                ClientApiLexer theLexer = new ClientApiLexer(theTextStream);
                CommonTokenStream theTokenStream = new 
CommonTokenStream(theLexer);
                ClientApiParser theParser = new ClientApiParser(theTokenStream);
                CommonTree theTree = (CommonTree) theParser.start().getTree();
                CommonTreeNodeStream theNodes = new 
CommonTreeNodeStream(theTree); 
                ClientApiTreeParser theTreeParser = new 
ClientApiTreeParser(theNodes);
                return theTreeParser;
        }
}

start[String inCdlClassName, String inCdlVariableName] returns [String code]
@init {
        linkDefinitions();
        pushDefiniton(inCdlClassName);
        mCdlVariableName = inCdlVariableName;
        CodeBuilder builder = new CodeBuilder();
}
@after {
        $code = builder.toString();
        unlinkDefinitions();
}
        :       booleanExpression[inCdlVariableName] { 
builder.append($booleanExpression.code); }
        |       objectPath[builder]
        ;


booleanExpression[String variableName] returns [String code]
@init {
        CodeBuilder builder = new CodeBuilder();
}
@after {
        $code = builder.toString();
}
        :       left=relationalExpression { builder.append($left.code); } 
((booleanOperator) right=relationalExpression)* { builder.insert(0, 
'(').append($booleanOperator.text).append($right.code).append(')'); }
        ;

relationalExpression returns [String code]
@init {
        linkDefinitions();
        CodeBuilder builder = new CodeBuilder();
}
@after {
        $code = builder.toString();
        unlinkDefinitions();
}
        :       objectPath[builder] relationalOperator literal  { 
builder.append(' ').append($relationalOperator.text).append(' 
').append($literal.text); }
        |       function[builder] relationalOperator literal    { 
builder.append("<funtion> ").append($relationalOperator.text).append(' 
').append($literal.text); }
        ;

objectPath[CodeBuilder code]
        :       memberReference[code] memberReference[code]*
        ;

memberReference[CodeBuilder code]
        :       ^(name[code] predicate[code])   { addCast(code); }
        |       name[code]
        ;

name[CodeBuilder code]
        :       Name {
                        String theName = $Name.text.substring(0, 
1).toUpperCase() + $Name.text.substring(1); // Change first letter to upper case
                        code.append(".get").append(theName).append("()");
                        pushDefiniton(theName);
                }
        ;

predicate[CodeBuilder code]
        :       IntegerLiteral                  { 
code.append(".get(").append($IntegerLiteral.text).append(')'); }
        |       relationalExpression    { 
code.append(".find(").append($relationalExpression.code).append(')');  }
        ;

function[CodeBuilder code]
        :       ^(Function FunctionName objectPath[code])
        ;

booleanOperator returns [String text]
        :       BooleanOperator { $text = "or".equals($BooleanOperator.text) ? 
"||" : "&&"; }
        ;

relationalOperator returns [String text]
        :       RelationalOperator { $text = 
"=".equals($RelationalOperator.text) ? "==" : $RelationalOperator.text; }
        ;

numericLiteral returns [String text]
        :       IntegerLiteral  { $text = $IntegerLiteral.text; }
        |       DecimalLiteral  { $text = $DecimalLiteral.text; }
        |       DoubleLiteral   { $text = $DoubleLiteral.text; }
        ;

literal returns [String text]
        :       StringLiteral   { $text = $StringLiteral.text; }
        |       numericLiteral  { $text = $numericLiteral.text; }
        ;
List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address

Reply via email to