5

I'm implementing a Pascal parser from this EBNF defintion. There is something I don't understand in the following specifications:

variable
   entire-variable | component-variable | referenced-variable 

entire-variable
   variable-identifier | field-identifier

component-variable
   indexed-variable | field-designator | file-buffer

field-designator
   record-variable "." field-identifier 

Assume we want to apply the variable production on a.b[0]. Since a conforms to the entire-variable production, this will prevent component-variable from detecting the field-designator a.b and therefore the . following a will stop the parser.

Leandro Caniglia
  • 14,495
  • 4
  • 29
  • 51
  • I don't have the Pascal spec in front of me but I can make a few observations. When the parser sees 'a', it should already know what 'a' is defined as. Also the parser can look-ahead and see the '.'. – Stuart Jan 15 '19 at 03:06
  • Readers of this question might also want to take a look at [How to define Pascal variables in PetitParser](https://stackoverflow.com/q/54207918/4081336) – Leandro Caniglia Jan 19 '19 at 11:32

1 Answers1

3

Since EBNF doesn't have ordered choices, the longest match is often used to determine which rules apply.

Ken White
  • 123,280
  • 14
  • 225
  • 444
Uran
  • 141
  • 2
  • 12