[antlr-interest] Why does ANTLR generate code that will never call an OR'd alternative?

Gerald Rosenberg gerald at certiv.net
Fri Aug 20 23:34:33 PDT 2010


  Most likely, the parser generation analysis determined that isToken 
can never be reached.  Check your error log for an alt skipped message.



------ Original Message (Saturday, August 21, 2010 1:01:20 
AM) From: Avid Trober ------
Subject: [antlr-interest] Why does ANTLR generate code that will never call
an OR'd alternative?
> For this rule,
>
>
>
> identifier
>
>                  :       isToken | IDENTIFIER;
>
>
>
> ANTLR generates code that would never calls the isToken rule
> (target=CSharp2):
>
>
>
>      public MYParser.identifier_return identifier()    // throws
> RecognitionException [1]
>
>      {
>
> .
>
>              // .  : ( isToken | IDENTIFIER )
>
>              int alt30 = 2;
>
>              int LA30_0 = input.LA(1);
>
>
>
>              if ( (LA30_0 == IDENTIFIER) )   //<== token must be IDENTIFIER
> to call isToken???
>
>              {
>
>                  int LA30_1 = input.LA(2);
>
>
>
>                  if ( ((isToken(input.LT(1)))) )  //<== why must LA30_0 ==
> IDENTIFIER to call isToken?
>
>                  {
>
>                      alt30 = 1;
>
>                  }
>
>                  else if ( (true) )
>
>                  {
>
>                      alt30 = 2;
>
>                  }
>
> .
>
>              else                         //<== since not IDENTIFIER, why
> not call isToken here???
>
>              {
>
>                  NoViableAltException nvae_d30s0 =
>
>                      new NoViableAltException("", 30, 0, input);
>
>
>
>                  throw nvae_d30s0;
>
>              }
>
>
>
> I would think it's something to do with DFA optimization?   Perhaps that's
> why IDENTIFIER is checked first.
>
> But, if IDENTIFIER is false, why not call isToken???    Afterall, the rule
> is IDENTIFIER  ****OR***** isToken.
>
>
>
> Thanks,
>
> Trober
>
>
>
>
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>


-- 

Gerald B. Rosenberg, Esq.
NewTechLaw
260 Sheridan Ave., Suite 208
Palo Alto, CA 94306-2009
650.325.2100 (office) / 650.703.1724 (cell)
650.325.2107 (facsimile)

www.newtechlaw.com

CONFIDENTIALITY NOTICE: This email message (including any attachments) 
is being sent by an attorney,
is for the sole use of the intended recipient, and may contain 
confidential and privileged information.
Any unauthorized review, use, disclosure or distribution is prohibited. 
If you are not the intended
recipient, please contact the sender immediately by reply email and 
delete all copies of this message
and any attachments without retaining a copy.



More information about the antlr-interest mailing list