Frage

What's the point in allowing the use of both keywords and regexes in the section covering lexical rules in a JFlex input file?

It seems

retrieve { action code}

...and

 "retrieve" { action code }

... both match an input containing "retrieve", the first one being a regex and the second one being a keyword. I mean all keywords should be able to be interpreted in the form of a regex so it seems superfluous to allow both.

War es hilfreich?

Lösung

I'm not sure quite what you mean by "keyword". According to the "Lexical rules" section of the JFlex User's Manual, both of your examples use regexes.

It's true that the regexes retrieve and "retrieve" are equivalent, but that's just because the sole effect of the "..." notation is to disable regex metacharacters, and none of the characters in retrieve are regex metacharacters to begin with. (By the way, you can also wrap just part of a regex in quotation marks; so, for example, retrieve is also equivalent to r"et"ri"ev"e.)

The quotation marks are more useful if (say) one of the keywords in your language is +++***+++, in which case you could write either of these:

\+\+\+\*\*\*\+\+\+ { action code }
"+++***+++" { action code }
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top