Search code examples
javasqlantlr3

Can token stream be changed at runtime?


I need to parse SQL Server if statements in ANTLR 3. SQL Server if statements are as:

IF expression BEGIN? statements END?

Since BEGIN and END are optional. I just need to add BEGIN and END tokens in ANTLR token stream at runtime if these are not specified in the token stream.


Solution

  • Solved the issue by adding predicates as:

    IF expression {input.LA(1) == BEGIN}? => BEGIN statements_list END | statements_list