BNF Grammar: Difference between revisions

5,208 bytes removed ,  11 years ago
m
→‎Pascal: move to pacsal page
m (→‎Pascal: move to pacsal page)
 
(26 intermediate revisions by 17 users not shown)
Line 1:
{{taskDeprecatedTask}}
In computer science, Backus–Naur Form (BNF) is a metasyntax used to express context-free grammars: that is, a formal way to describe formal languages. John Backus and Peter Naur developed a context free grammar to define the syntax of a programming language by using two sets of rules: i.e., lexical rules and syntactic rules.
 
Line 6:
There are many extensions and variants of BNF, including Extended and Augmented Backus–Naur Forms (EBNF and ABNF).
 
'''This is a deprecated task. Please move these grammars to the language's category page, or somewhere else.'''
The task here is establish a BNF grammar for as many languages as possible to facilitate language categorization and translation.
=={{header|Ada}}==
A BNF description of the language syntax is a part of its standard, [http://www.adaic.org/standards/1zrm/html/RM-P.html see Ada Reference Manual, Annex P].
=={{header|ALGOL 60}}==
A BNF description of the language syntax is a part of following,
[http://eli-project.sourceforge.net/a60_html/a60.html#s2 ALGOL 60 ][http://www.masswerk.at/algol60/syntax.txt -Syntax of ALGOL 60]
 
=={{header[[:Category:BASIC|BASIC}}]]==
<div style="height:30ex;overflow:scroll"><pre>
! -----------------------------------------------------------------------
Line 179 ⟶ 174:
| Real
</pre></div>
=={{header[[:Category:BASIC Commodore PET|BASIC Commodore PET}}]]==
<div style="height:30ex;overflow:scroll"><pre>
! -----------------------------------------------------------------------
Line 386 ⟶ 381:
</pre></div>
 
=={{header[[:Category:Brainf***|Brainf***}}]]==
<div style="height:30ex;overflow:scroll"><pre>
! ---------------------------------------------------------------------------
!
! Brainf***
!
!
! As legend states, the Brainf*** Programming Language (also called BF by
! those not wanting to curse) was created by Urban Mueller in 1993.
! The language was designed, in part, so Mueller could create the smallest
! compiler ever. The first BF compiler was written for the Commodore Amiga
! OS 2.0 and was only 240 bytes in size.
!
! BF is a Turing-complete language. This means that any BF program can be
! proved to be equivalent to a Turing Machine.
!
! The system consists of an continuous array of 30,000 bytes (more can be
! added of course, but this is the standard size). Each cell is accessed
! through a single, global, pointer that can either move forward or backward
! on the array. The content of each cell can be modified by either reading a
! new byte from standard input or by incrementing or decrementing the
! current value. The array is initialized with zeroes.
!
!
! The BF Programming Language only consists of 8 different instructions:
!
! > Increment the pointer
! < Decrement the pointer
!
! + Add 1 to the current cell
! - Substract 1 from current cell
!
! . Print the current cell to the screen using its ASCII value.
! , Read a character and store its ASCII value in the current cell
!
! [ Jump forward past the corresponding ] if the current byte is zero
! ] Jump back to the statement after the corresponding [ if the
! current cell is not zero.
!
! In reality, the BF Programming Language is not that different from ANSI C.
! Each of the 8 instructions can be substituted for C statements and
! language constructs.
!
! > becomes p++;
! < becomes p--;
! + becomes *p++;
! - becomes *p--;
! . becomes putchar(*p);
! , becomes *p = getchar();
!
! [ becomes while (*p) { ...
! ] becomes }
!
!
! BF also treats all characters that are not the 8 basic commands as
! comments. In the grammar below, Whitespace is defined to include all the
! printable characters - with the exception of the statements.
!
! Please see http://en.wikipedia.org/wiki/Brainfuck for more information
!
! PLEASE NOTE: This grammar was created for fun. If you want to create a BF
! parser, it is far easier (and much more efficient) to write
! one manually.
!
! ---------------------------------------------------------------------------
 
 
"Name" = 'Brainf***'
"Author" = 'Urban Mueller'
"Version" = '1993'
 
"About" = 'Brainf*** was created by Urban Mueller with the goal to build'
| 'the smallest compiler ever.'
 
"Start Symbol" = <Instructions>
 
! ============================================== Comments
 
{WS} = {Printable} - [<>+-.,'['']']
 
Whitespace = {WS}+
 
 
! ============================================== Statements
 
<Instructions> ::= <Instructions> <Instruction>
|
 
 
<Instruction> ::= '>' ! Increment p
| '<' ! Decrement p
| '+' ! Increment a[p]
| '-' ! Decrement a[p]
| '.' ! Output a[p]
| ',' ! Input a[p]
| '[' <Instructions> ']'
</pre></div>
=={{header|C}}==
The Syntax follows, [http://c.comsci.us/syntax/index.html C Syntax]
 
=={{header|C++}}==
The Syntax follows, [http://cpp.comsci.us/syntax/statement/index.html C++ Syntax]
 
=={{header|C sharp}}==
See the following, [http://csharp.comsci.us/syntax/expression/ebnf.html C-sharp syntax]
 
=={{header|Cobol}}==
See link [http://www.cs.vu.nl/~x/grammars/cobol/ COBOL Grammer]
 
=={{header|Delphi}}==
IEBNF Syntax follows [http://www.felix-colibri.com/papers/compilers/delphi_5_grammar/delphi_5_grammar.html Dephi 6 Syntax]
 
=={{header|Fortran}}==
The BNF description follows, [http://fortran.comsci.us/syntax/statement/index.html Fortran Syntax]
 
=={{header|Java}}==
The BNF description follows, [http://www.cui.unige.ch/db-research/Enseignement/analyseinfo/JAVA/BNFindex.html BNF index of Java Language Grammar]
 
=={{header|JavaScript}}==
The BNF description follows, [http://javascript.comsci.us/syntax/statement/bnf.html JavaScript Syntax]
 
=={{header|Lisp}}==
See link on syntax [http://cui.unige.ch/db-research/Enseignement/analyseinfo/LISP/BNFindex.html Lisp Syntax]
Outside of particularly restricted variants, no static grammar can exactly describe Lisp due to macros and reader-macros.
 
=={{header|Pascal}}==
The [[wp:ISO 7185|ISO 7185]] standard for Pascal uses [[wp:Extended Backus–Naur Form|Extended Backus–Naur Form]].
Also [[wp:Van Wijngaarden grammar|Van Wijngaarden's grammar]] can be used to define
[[Pascal]]'s grammar[http://www-users.cs.york.ac.uk/~fisher/software/yoyovwg/exs/pascal.vwg].
 
=={{header|Perl}}==
The BNF description follows, [http://perl.comsci.us/syntax/statement/index.html Perl Syntax]
 
Code ::= Command Code | <NONE>
=={{header|PHP}}==
Command ::= "+" | "-" | "<" | ">" | "," | "." | "[" Code "]" | <ANY>
The BNF description follows, [http://php.comsci.us/syntax/statement/index.html PHP Syntax]
 
==[[:Category:PARI/GP|PARI/GP]]==
=={{header|Python}}==
[http://pari.math.u-bordeaux.fr/cgi-bin/viewcvs.cgi/trunk/src/language/parse.y?view=markup&revision=12950&root=pari parse.y] contains a grammar for GP. The grammar for PARI is that of [http://c.comsci.us/syntax/ C].
The best EBNF syntax so far is at, [http://www.martinrinehart.com/articles/python-grammar.html Python EBNF Syntax]
=={{header|Ruby}}==
Syntax follows [http://web.njit.edu/all_topics/Prog_Lang_Docs/html/ruby/yacc.html Ruby Syntax]
 
==[[:Category:PowerShell|PowerShell]]==
=={{header|SQL}}==
An annotated version of the PowerShell grammar can be found in Bruce Payette's book ''Windows PowerShell in Action''. The appendix containing the grammar is available in [http://www.manning.com/payette/AppCexcerpt.pdf PDF form] on the publisher's site.
Syntax for SQL follows, [http://savage.net.au/SQL/sql-2003-2.bnf.html BNF Sytax for SQL Database Language]
 
This grammar does not accurately represent the PowerShell language, though, as for example the <code>for</code> loop mandates semicolons in the grammar but in practice does not require them when arguments are omitted. The infinite loop may be represented by
=={{header|Smalltalk}}==
<lang powershell>for () {}</lang>
Smalltalk Syntax follows, [http://github.com/aquasync/ruby-ometa/blob/60deea23abe7eb07d200233dde4213d74041b81f/smalltalk.syntax Smalltalk Syntax]
but the grammar would require
<lang powershell>for (;;) {}</lang>
 
=={{header[[:Category:VBScript|VBScript}}]]==
<div style="height:30ex;overflow:scroll"><pre>
!===============================
Line 1,277 ⟶ 1,141:
</pre></div>
 
=={{header[[:Category:Visual Basic .NET|Visual Basic .NET}}]]==
The following link (Appedix B) has a simple BNF Syntax [http://laser.physics.sunysb.edu/~amol/papers/mollypaper.pdf VB Syntax]
<div style="height:30ex;overflow:scroll"><pre>
Line 1,948 ⟶ 1,812:
<Identifier> ::= ID | QualifiedID !Any type of identifier
</pre></div>
 
{{omit from|Tcl}}<!-- no meaningful grammar at a level that anyone cares about; see talk page -->