1

I want to declare with EBNF notation a keyword, i.e. switch.

<keyword_switch> ::= "switch";

Is there a way to declare the keyword as case insensitive without declare all possible letters combination?

I think that the following declaration is correct (but unsire, I'm a newbie with EBNF):

<keyword_switch> ::= ("S"|"s")("W"|"w")("I"|"i")("T"|"t")("C"|"c")("H"|"h");

but it's not very readable. Is there another simpler way?

Jepessen
  • 11,744
  • 14
  • 82
  • 149

1 Answers1

1
<keyword_switch> ::= ("S"|"s")("W"|"w")("I"|"i")("T"|"t")("C"|"c")("H"|"h");

seems to be ok with antlr -- http://www.antlr3.org/pipermail/antlr-interest/2007-August/023267.html

Heretic as it may seem, I'd suggest

<keyword_switch> ::= "switch" | "Switch" | "SWITCH";

assuming that sWitch and sWiTcH etc. are hardly what a user would need.

rns
  • 771
  • 4
  • 9
  • But it will not be case insensitive. If there's no simple solution I'll maintain my code for real case insensitivity. – Jepessen Nov 01 '15 at 18:00
  • Yes, it won't. For real case insentivity, ANTLR, e.g., has [Aa] tokens or fragments -- http://stackoverflow.com/a/22160240/4007818 – rns Nov 02 '15 at 05:28
  • Marpa, on the other hand, has ":ic" and ":i" modifiers for real case-insensitivity -- https://metacpan.org/pod/distribution/Marpa-R2/pod/Scanless/DSL.pod#Single-quoted-strings – rns Nov 02 '15 at 05:42