0

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.

fast-reflexes
  • 4,891
  • 4
  • 31
  • 44

1 Answers1

1

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 }
ruakh
  • 175,680
  • 26
  • 273
  • 307
  • Aha... Then i misunderstood things.. Is using "...." to escape metacharacters a convention used in regexes generally or just in this specific situation? I thought that " wasn't considered a character with special meaning in regexes and would therefore match an actual ". (So "retrieve" would match only "retrieve" and not retrieve as a regex, therefore i draw the conclusion that it wasn't a regex) – fast-reflexes Dec 21 '12 at 19:18
  • @fast-reflexes: "Regexes" isn't really a single unitary concept; there's a lot of variation between regex engines. So saying that `"` isn't special in regexes is a bit like saying that `floobet` isn't a reserved word in programming languages: generally true, but not necessarily categorical. (But to be sure, I've never seen *any* other regex language that uses `"` in this way.) – ruakh Dec 21 '12 at 19:28