Content deleted Content added
RainbowCrane (talk | contribs) AWB recategorisation, WikiProject Stub Sorting, Replaced: {{computer-stub}} → {{comp-sci-stub}} using AWB |
Undid revision 1293116503 by Jmason37 (talk) spam; we do not need two links to the same site |
||
(130 intermediate revisions by 93 users not shown) | |||
Line 1:
{{Short description|Visual description of context-free grammar}}
'''Syntax diagrams''' (or '''railroad diagrams''') are a way to represent a [[
== Principle ==
The representation of a grammar is
Each diagram has an entry point and an end point. The diagram describes
== Example ==
We use arithmetic expressions as an example
BNF:
<expression> ::= <term> | <term> "+" <expression>▼
<syntaxhighlight lang="bnf">
<term> ::= <factor> | <factor> "*" <term>
<variable> ::= "x" | "y" | "z"
▲ <digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
</syntaxhighlight>
EBNF:
expression = term , {"+" term};▼
<syntaxhighlight lang="ebnf">
term = factor , [ "*" , term ];
variable = "x" | "y" | "z";
constant = digit , {digit};▼
▲ digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
</syntaxhighlight>
ABNF:
<syntaxhighlight lang="abnf" highlight="6">
term = factor ["*" term]
factor = constant / variable / "(" expression ")"
variable = "x" / "y" / "z"
DIGIT = "0" / "1" / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9"
</syntaxhighlight>
ABNF also supports ranges, e.g. {{code|2=abnf|1=DIGIT = %x30-39}}, but it is not used here for consistency with the other examples.
[[Red (programming language)]] Parse Dialect:
<syntaxhighlight lang="Red" highlight="7">
Red [Title: "Parse Dialect"]
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>
This format also supports ranges, e.g. {{code|2=red|digit: charset [#"0" - #"9"]}}, but it is not used here for consistency with the other examples.
One possible syntax diagram for the example grammars is below. While the syntax for the text-based grammars differs, the syntax diagram for all of them can be the same because it is a [[metalanguage]].
[[Image:Syntax-diagram-example.png|"Railroad" syntax diagram]]
==See also==
* [[Recursive transition network]]
* [[Extended
==References==
{{reflist}}
Note: the first link is sometimes blocked by the server outside of its ___domain, but it is available on [https://web.archive.org/web/20180909121538/https://www.research-collection.ethz.ch/bitstream/handle/20.500.11850/68910/eth-3059-01.pdf archive.org]. The file was also mirrored at [http://www.standardpascal.org/The_Programming_Language_Pascal_1973.pdf standardpascal.org].
==External links==
*
*
* [https://karmin.ch/ebnf/index EBNF Parser & Renderer]
▲* {{en}} [http://dotnet.jku.at/applications/Visualizer/ Generator from EBNF]
* [https://www.sqlite.org/docsrc/finfo?name=art/syntax/bubble-generator.tcl SQLite syntax diagram generator for SQL]
▲* {{en}} [http://www.informatik.uni-freiburg.de/~thiemann/haskell/ebnf2ps/ From EBNF to a postscript file wit the diagrams]
* [https://www.bottlecaps.de/rr Online Railroad Diagram Generator]
* [https://www.yorku.ca/jmason/asdgram.htm Augmented Syntax Diagram (ASD) grammars]
* [http://www.asd-networks.com (ASD) '''Augmented''' Syntax Diagram Application Demo Site ]
* [https://github.com/gbrault/railroad-diagrams/blob/gh-pages/live/doc/readme.md/ SRFB Syntax Diagram representation by Function Basis + svg generation]
[[Category:Formal languages]]
[[Category:Diagrams]]
|