Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8247239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:46:36+00:00 2026-06-07T22:46:36+00:00

I have a Token OR:’OR’; that I use for evaluating a boolean expression( a==b

  • 0

I have a Token OR:’OR’; that I use for evaluating a boolean expression( a==b OR a==c) I have another rule for parsing state abbreviation that are in a char list AZ,AK,OR,GA…
What I am finding is that antlr has error on the state list thinking OR should be an or token rather then

stateName   
    : CHAR CHAR (','|EOF) ->^(STATE CHAR+)
    ;   

how would I go about resolving this ambiguity?

here are some of the rules I am trying to parse

  • THEN STATE_LICENSE
    AL,AK,AS,AZ,AR,CT,DE,DC,FM,FL,GA,GU,HI,ID,IL,IN,IA,KS,KY,LA,ME,MH,MD,MA,MI,MN,MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,MP,OH,OK,OR,PW,PA
  • IF 1198 == “x” OR 1190 != “x” THEN DISABLE 800
  • IF 801 >= “1000000” THEN DISPLAY_ERROR “It’s+too+expensive.+Go+and+get+cheaper+one+!!!”

Here is the gramar that I am using

grammar PointFieldRule;


options 
{
//language = 'CSharp3'; 
output=AST; 
ASTLabelType=CommonTree;
} 
tokens{
STATE;

}


rule : ifExpression?  actionExpression EOF!
;
ifExpression 
    :'IF'! logicalConditionExpression
    ;

logicalConditionExpression
    : booleanAndConditionExpression ( BigOR^ booleanAndConditionExpression)*
    ;


booleanAndConditionExpression
    : logicalCondition ( BigAND^ logicalCondition )*
    ;

BigAND : 'and'|'AND';

logicalCondition
    : booleanAndCondition ( OR^ booleanAndCondition )*
    ;

OR:'||';

booleanAndCondition
    : evalCondition ( AND^ evalCondition)*
    ;

AND: '&&';

evalCondition 
    : FieldID OPERATOR^ (FieldID|STRING)
    ;

 actionExpression 
    : 'THEN'! (actionMessage | fieldAction | stateAction )  
    ;

actionMessage 
    : ('DISPLAY_WARNING' | 'DISPLAY_ERROR')^ STRING
    ;

fieldAction 
    : ('DISABLE' | 'REQUIRED')^ FieldID ( ','! FieldID )* 
    ;


stateAction
    : 'STATE_LICENSE'^ stateName+ //(','! stateName)*
    ;

FieldID
    :'0'..'9'+;

 /* item : FIELD 
    | CHAR CHAR
    ;
*/
//class csharpTestLexer extends Lexer; 

stateName   
    : CHAR CHAR (','|EOF) ->^(STATE CHAR+)
    ;   
CHAR:  ('a'..'z'|'A'..'Z')
    ;

WS : (' ' 
| '\t' 
| '\n' 
| '\r') 
{ $channel = HIDDEN; } 
//{ $channel = Hidden; } 
; 



OPERATOR 
    :   '=='
    | '!='
    |    '<='
    |    '>='
    |    '<'
    |    '>'
    | 'TD'
    | 'FD'
    | 'PD'
    | 'TY'
    | 'LY'
    | 'TM'
    | 'LM'
    | '+(DELTA%)>'
    | '-(DELTA%)>'
    | '+(DELTA)>'
    | '-(DELTA)>'
    | 'LIKE'
    ;


STRING
    :  '"' ( ESC_SEQ | ~('\\'|'"') )* '"'
    ;


fragment
HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ;

fragment
ESC_SEQ
    :   '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
    |   UNICODE_ESC
    |   OCTAL_ESC
    ;

fragment
OCTAL_ESC
    :   '\\' ('0'..'3') ('0'..'7') ('0'..'7')
    |   '\\' ('0'..'7') ('0'..'7')
    |   '\\' ('0'..'7')
    ;

fragment
UNICODE_ESC
    :   '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
    ;

//fragment
BigOR: 'or'|'OR';
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T22:46:39+00:00Added an answer on June 7, 2026 at 10:46 pm

    The lexer creates tokens independently from the parser. So it doesn’t matter if the parser might “need” two CHAR tokens at a given point, if the lexer “sees” the text "OR", it will always create a BigOR token. There’s nothing you can do about that.

    In your case, you can simply let stateName match two CHAR tokens, or a single OR token like this:

    stateName   
     : name (','|EOF) ->^(STATE name)
     ;   
    
    name
     : CHAR CHAR
     | BigOR
     ;
    

    Parsing input "THEN STATE_LICENSE AL,OR,PA" will result in the following AST:

    enter image description here

    Note that the OR is a single token, unlike the others, whose type are CHAR and have their chars separated. If you want your OR node to behave like that too, do something like this:

    name
     : CHAR CHAR
     | BigOR     -> CHAR[""+$BigOR.text.charAt(0)] CHAR[""+$BigOR.text.charAt(1)]
     ;
    

    resulting in:

    enter image description here

    Or if you want the two separate chars to be concatenated, do:

    name
     : (CHAR CHAR | BigOR) -> CHAR[$text]
     ;
    

    resulting in:

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this kind of setup : Overridden BaseRunserverCommand that adds another option (--token)
I have a token definition that can contain multiple lines (something like multi line
i have installed the token module, but don't know how to use it. i
I have got access_token. Using zend framework. I have obtained token for multiple permissions.
i have a hardware token for remote login to some citrix environment. When i
I have implemented antiforgery token on my login page. Now I had one user
I have a valid SAML 2 token from my application IdP: When I try
I have a before_save defined as follows: def before_save self.token = generate_token end I
I have successfully followed the examples to gain an AuthSub token to authorize my
I have a small script and it throws Unexpected token error on line 2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.