Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning with no obvious reason #250

Open
MarcMazas opened this issue Nov 30, 2022 · 0 comments
Open

Warning with no obvious reason #250

MarcMazas opened this issue Nov 30, 2022 · 0 comments

Comments

@MarcMazas
Copy link
Collaborator

MarcMazas commented Nov 30, 2022

In the following small grammar, we have a compile warning for which I see no reason.
It looks to me it is a bug (well, I found this while building a very big set of test cases for JavaCC)..
Any idea? TIA. Marc

TOKEN :
{
  < a : "a" >
| < bB : "b" ("B")* >
}

int one_line() : {}
{
  p1() p2() p3() ";" { return 0; }
| ";"  { return 1; }
}

void p1() : {}
{ < ID1 : < bB > < a > > { System.out.println("got ID1"); } }

// here we have a JJ compile warning: ... Regular Expression choice : bB can never be matched as : ID2
// Why? We don't have it in p4() with the direct formulation nor in p3() when not single in the choice
void p2() : {}
{ < ID2 : < bB > | "c" > { System.out.println("got ID2"); } }

void p3() : {}
{ < ID3 : < bB > "!" | "c" > { System.out.println("got ID3"); } }

void p4() : {}
{ < ID4 : "b" ("B")* | "c" > { System.out.println("got ID4"); } }

Following is the remaining of the grammar, if someone wants to test.
Running the test cases shows that the parser does not accept the input corresponding to the warning.

options
{
  static = true;
  UNICODE_INPUT = true; // (default false)

}

PARSER_BEGIN(QuickTests)

public class QuickTests
{
  public static void main(String args []) throws ParseException
  {
    QuickTests parser = new QuickTests(System.in);
    boolean done = false;
    while (!done)
    {
      System.out.println("Reading from standard input...");
      System.out.println("Ex1: babb!; / Ex2: babc; / Ex3: bacb!; / Ex4: bacc;");
      try
      {
        switch (QuickTests.one_line())
        {
          case 0 : 
          System.out.println("OK.");
          break;
          case 1 : 
          System.out.println("Goodbye.");
          done = true;
          break;
          default : 
          break;
        }
      }
      catch (Exception e)
      {
        System.out.println("NOK.");
        System.out.println(e.getMessage());
        QuickTests.ReInit(System.in);
      }
      catch (Error e)
      {
        System.out.println("Oops.");
        System.out.println(e.getMessage());
        break;
      }
    }
  }
}

PARSER_END(QuickTests)

SKIP :
{
  " "
| "\t"
| "\n"
| "\r"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant