Everything is an object in the language I'm creating.  Thus, I allow:

"string".someFunction(), and
1234.equals(1234)

I'm using the latter as a testcase.  It's being parsed as follows:

1234. =>
    1. Take object production
    2. Take alt2
    3. Consume 1234
    4. See '.'
    4. Try DECIMAL production
    5. Consume '.'
    6. Throw execption because expected INTEGER is not found

After parsing the above the DECIMAL non-terminal throws an exception
since the missing INTEGER non-terminal isn't present.  How can I get
ANTLR to accept the INTEGER production instead?

And here's the relevant grammar portions:

object
    :   ID ('.' ID)* objectSuffix?
    |   literal ('.' ID objectSuffix)?;

objectSuffix
    :   '(' arguments? ')';

arguments
    :   argument (',' argument)*;

argument
    :   object;

literal:
    QUOTED_STRING
    |   INTEGER
    |   DECIMAL;



fragment NUMBER: '0'..'9';

INTEGER
    :   NUMBER+;

DECIMAL
    :   INTEGER '.' INTEGER;

fragment ID_BASIC_CHARSET: ('a'..'z' | 'A'..'Z' | '_');

ID  :    ID_BASIC_CHARSET (ID_BASIC_CHARSET | NUMBER)*;


As an alternative, I tried the following (IIRC):

object
    :   ID ('.' ID)* objectSuffix?
    |   (INTEGER '.' ID objectSuffix) => INTEGER '.' ID objectSuffix
    |   literal ('.' ID objectSuffix)?;

I didn't step through the above, but it seemed to give the exact same
behavior as the above cases.  I believe there's enough syntactical
information that I should be able to make this work.  Suggestions?

Thanks.

--Kaleb
http://twitter.com/kalebpederson
http://kalebpederson.com

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to