1

I have these rules:

while: 'while' expr 'do' program;
if: 'if' expr 'then' program 'else' program;

I don't care what expr contains, so how can I take everything there until then or do?

I tried:

expr: .*?~('then'|'do');

but it is not working. Why?

Jiri Tousek
  • 12,211
  • 5
  • 29
  • 43
ddd
  • 13
  • 5

1 Answers1

0

If the content and structure doesn't matter to you use the token stream instead. Iterate over all tokens (starting at the while token until you encounter do (and jump over all nested loops). Your parser ensures the input is correct, so it is ok to use the token stream then.

Mike Lischke
  • 48,925
  • 16
  • 119
  • 181