Syntax diagram: Difference between revisions

Content deleted Content added
Yobot (talk | contribs)
m top: References after punctuation per WP:REFPUNCT, WP:CITEFOOT, WP:PAIC + other fixes
Add ABNF and Red Parse grammar examples. Tried up upload new diagram to match all examples, but wasn't allowed.
Line 9:
== Example ==
 
We use arithmetic expressions as an example., Firstin wevarious providegrammar aformats. simplified BNF grammar:
 
BNF:
<syntaxhighlight lang="bnf">
<expression> ::= <term> | <term> "+" <expression>
Line 20 ⟶ 22:
</syntaxhighlight>
 
EBNF:
This grammar can also be expressed in EBNF:
<syntaxhighlight lang="ebnf">
expression = term , [ "+" , expression ];
Line 30 ⟶ 32:
 
</syntaxhighlight>
 
ABNF:
<syntaxhighlight lang="abnf">
expression = term ["+" expression]
term = factor ["*" term]
factor = constant / variable / "(" expression ")"
variable = "x" / "y" / "z"
constant = 1*digit
DIGIT = "0" / "1" / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9"
</syntaxhighlight>
Note that ABNF also supports ranges, e.g. `DIGIT = %30-39`, but it is not used here for consistency with the other examples.
 
Red Language Parse Dialect:
<syntaxhighlight lang="Red">
expression: [term opt ["+" expression]]
term: [factor opt ["*" term]]
factor: [constant | variable | "(" expression ")"]
variable: ["x" | "y" | "z"]
constant: [some digit]
digit: ["0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"]
</syntaxhighlight>
Note that this format also supports ranges, e.g. `digit: charset [#"0" - #"9"]`, but it is not used here for consistency with the other examples.
 
 
 
{{Self-contradictory|about='expression' and 'term'; the diagrams do not match EBNF|date=October 2020}}