请输入您要查询的百科知识:

 

词条 Syntax diagram
释义

  1. Principle of syntax diagrams

  2. Example

  3. See also

  4. References

  5. External links

Syntax diagrams (or railroad diagrams) are a way to represent a context-free grammar. They represent a graphical alternative to Backus–Naur form or to EBNF as metalanguages. Early books using syntax diagrams include the "Pascal User Manual" written by Niklaus Wirth [1] (diagrams start at page 47) and the Burroughs CANDE Manual.[2]. In the compilation field, textual representations like BNF or its variants are usually preferred. BNF is text-based, and used by compiler writers and parser generators. Railroad diagrams are visual, and may be more readily understood by laypeople, sometimes incorporated into graphic design. The canonical source defining the JSON data interchange format provides yet another example of a popular modern usage of these diagrams.

Principle of syntax diagrams

The representation of a grammar is made of a set of syntax diagrams. Each diagram defines a non-terminal. There is a main diagram which defines the language in the following way: to belong to the language, a word must describe a path in the main diagram.

Each diagram has an entry point and an end point. The diagram describes possible paths between these two points by going through other nonterminals and terminals. Terminals are represented by round boxes while nonterminals are represented by square boxes.

Example

We use arithmetic expressions as an example. First we provide a simplified BNF grammar:

::= | "+" ::= | "*"

::= | | "(" ")"

::= "x" | "y" | "z"

::= |

::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"

This grammar can also be expressed in EBNF:

expression = term | expression, "+" , term;

term = factor | term, "*" , factor;

factor = constant | variable | "(" , expression , ")";

variable = "x" | "y" | "z";

constant = digit , {digit};

digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";

One possible set of syntax diagrams for this grammar is:

See also

  • Recursive transition network
  • Extended Backus–Naur form (EBNF)

References

1. ^Niklaus Wirth: The Programming Language Pascal. (July 1973)
2. ^Burroughs B6700/B7700 Command AND Edit (CANDE) Language: Information Manual

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 standardpascal.org.

External links

  • {{en icon}} JSON website including syntax diagrams
  • {{en icon}} Generator from EBNF
  • {{en icon}} From EBNF to a postscript file with the diagrams
  • {{en icon}} EBNF Parser & Renderer
  • {{en icon}} Sqlite syntax diagram generator for SQL
  • {{en icon}} Online Railroad Diagram Generator
  • {{en icon}} Augmented Syntax Diagram (ASD) grammars
  • {{en icon}} (ASD) Augmented Syntax Diagram Application Demo Site
  • {{en icon}} [https://github.com/gbrault/railroad-diagrams/blob/gh-pages/live/doc/readme.md/ SRFB Syntax Diagram representation by Function Basis + svg generation]

2 : Formal languages|Diagrams

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/9/20 19:50:07