views:

298

answers:

2

I have strange problem with token < NULL: "null" > in my JavaCC parser. In expression like

String IsNullClause():
{
      String res = "";
}
{
     <IS> {res += " IS ";}
     [<NOT> {res += " NOT ";} ]
     <NULL> {res += " NULL ";}

{
 return res;
}
}

parser doesn't see NULL token and throws exception that "null" expected. If I change token definition to < NULL: "null_val" > or something else it works fine. Is this my mistake or JavaCC doesn't accept 'null' as a token value?

+2  A: 

There are sample Java language grammars in JavaCC package, with the following token difinition:

< NULL: "null" >

so I'm pretty sure JavaCC can handle null token.

Are you sure no token declared before NULL matches "null"? Tokens are matched in the order of declaration. You may try to declare NULL at the very beginning.

asalamon74
A: 

Are you sure no token declared before NULL matches "null"?

Yes, I'm sure. And after it too.

3biga