Exercise 29:

Conflict resolution: loop may iterate too many times
We have the following grammar to declare enumerations of identifiers, with the possibility to specify a default one:
  enumeration: 'enum'^ '{'! body '}'!;
  body: values (','! default)?;
  values: IDENT (','! IDENT)*;
  default: 'default'^ IDENT;
  IDENT: ('a'..'z'|'A'..'Z'|'_')('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;
However, we have detected a problem: the loop in the right-hand side of the rule
  values: IDENT (',' IDENT)*;
may iterate too many times when followed by “,”, causing undesired parsing errors. This happens because the loop starts with the token “,”, but it can also be followed by that same token (i.e. “,Follow(\in\text{Follow}(values))). The behavior of the parser is to keep repeating the loop as long as it seems promising to do so. Consequently, the parser will fail to detect that the loop is over if it is followed by “,”. Fix the grammar so that it has the desired behavior. The AST construction must not be altered.
Authors: Nil Mamano / Documentation:
To be able to submit you need to either log in, register, or become a guest.