Thomas Gassmann (ETH Zürich)

EBNF

EBNF Rules:

Loading...
Loading...

Please make sure you have some valid rules first.

Useful information

The vast majority of the grammar simplification/normalization as well as the CYK algorithm have been adapted from github.com/JM4ier/parsley.

This EBNF parser mostly follows the EBNF syntax as discussed in the Einführung in die Programmierung" course taught at ETH Zürich.

  • The input to check is being evaluated against the last rule
  • Each EBNF rule occupies exactly one line
  • Lines starting with # are skipped
  • Empty lines are skipped
  • Each line is evaluated against the EBNF verifier separately
    • If a line matches the EBNF spec, the line is highlighted green
    • If a line does not match the EBNF spec, the line is highlighted red

However, there are some slight deviations:

  • This parser is sensitve to whitespace
  • For string literals that themselves contain EBNF tokens, use quotation marks

For the EBNF producer:

  • Words are sorted by length first, then lexicographically
  • Words are currently generated on the UI thread, so things might be slow depending on the rule :)
    • I will probably use web workers for this if I find the time
HS22 exam example

For the HS22 exam, the EBNF specficiation would slightly deviate and look like:

<identifier> <= a | b | y | z | 7 | x | c | k | m | n

<unary_expression> <= <unary_operator> <primary_expression>
<postfix_expression> <= <primary_expression> | <postfix_expression> ++ | <postfix_expression> --
<primary_expression> <= "(" <special_expression> ")" | <identifier>
<unary_operator> <= * | !
<assignment_expression> <= <expression>" "<assignment_operator>" "<special_expression>
<assignment_operator> <= = | +=
<special_expression> <= <primary_expression> | <special_expression>" "<binary_operator>" "<expression>
<binary_operator> <= * | / | + | %
<expression> <= <assignment_expression> | <postfix_expression> | <unary_expression>

Notice that the above EBNF specficiation matches e.g. *(a + b) but not *(a+b). To faciliate things, you might consider adding a rule akin to <whitespace> <= {" "}.

TODOs
  • Dark mode (I'm bad with colors, so I don't know which colors to choose for syntax highlighting)
  • Debounce
  • Don't load monaco from external CDN
  • Produce words in a web workers instead of doing it on the UI thread
  • Autocomplete
  • Open source it
  • Add escape character to e.g. allow matching quotation marks (")

I do not guarantee the correctness of any results. In case, you spot any errors, feel free to send me an email.