Machine-translated by Google. Questions are authored in English.
Top

Discussion

When two patterns match a lexeme of the same length, the scanner generator resolves the conflict by

  • A.choosing at random between the two competing patterns
  • B.taking the pattern that was listed first in the specification
  • C.taking the pattern that produces the shorter token name
  • D.reporting an ambiguity and then refusing to build the scanner at all

Answer: B

Rule order breaks ties. This is why keywords are listed before the general identifier pattern: both match the lexeme if, but the earlier keyword rule wins and the correct token is produced. Reversing the order silently turns every keyword in the language into an identifier.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.