Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Extended Backus–Naur form
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Examples== ===Syntax diagram=== [[File:Ebnf-syntax-diagram.png|thumb|alt=One possible EBNF syntax diagram |One possible EBNF [[syntax diagram]]]] ===EBNF=== Even EBNF can be described using EBNF. Consider below grammar (using conventions such as "-" to indicate set disjunction, "+" to indicate one or more matches, and "?" for optionality): <syntaxhighlight lang="ebnf"> letter = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z" | "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z" ; digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ; symbol = "[" | "]" | "{" | "}" | "(" | ")" | "<" | ">" | "'" | '"' | "=" | "|" | "." | "," | ";" | "-" | "+" | "*" | "?" | "\n" | "\t" | "\r" | "\f" | "\b" ; character = letter | digit | symbol | "_" | " " ; identifier = letter , { letter | digit | "_" } ; S = { " " | "\n" | "\t" | "\r" | "\f" | "\b" } ; terminal = "'" , character - "'" , { character - "'" } , "'" | '"' , character - '"' , { character - '"' } , '"' ; terminator = ";" | "." ; term = "(" , S , rhs , S , ")" | "[" , S , rhs , S , "]" | "{" , S , rhs , S , "}" | terminal | identifier ; factor = term , S , "?" | term , S , "*" | term , S , "+" | term , S , "-" , S , term | term , S ; concatenation = ( S , factor , S , "," ? ) + ; alternation = ( S , concatenation , S , "|" ? ) + ; rhs = alternation ; lhs = identifier ; rule = lhs , S , "=" , S , rhs , S , terminator ; grammar = ( S , rule , S ) * ; </syntaxhighlight> ===Pascal=== A [[Pascal (programming language)|Pascal]]-like programming language that allows only assignments can be defined in EBNF as follows: <syntaxhighlight lang="ebnf"> (* a simple program syntax in EBNF - Wikipedia *) program = 'PROGRAM', white space, identifier, white space, 'BEGIN', white space, { assignment, ";", white space }, 'END.' ; identifier = alphabetic character, { alphabetic character | digit } ; number = [ "-" ], digit, { digit } ; string = '"' , { all characters - '"' }, '"' ; assignment = identifier , ":=" , ( number | identifier | string ) ; alphabetic character = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z" ; digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ; white space = ? white space characters ? ; all characters = ? all visible characters ? ; </syntaxhighlight> For example, a syntactically correct program then could be: <syntaxhighlight lang="pascal"> PROGRAM DEMO1 BEGIN A:=3; B:=45; H:=-100023; C:=A; D123:=B34A; BABOON:=GIRAFFE; TEXT:="Hello world!"; END. </syntaxhighlight> The language can easily be extended with [[control flow]]s, arithmetical expressions, and Input/Output instructions. Then a small, usable programming language would be developed.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)