What is the BNF paradigm and what is the ebnf paradigm?

Source: Internet
Author: User

Bucos paradigm and its extension
BNF & augmented BNF

What is the bacos paradigm?

The BNF (abbreviated as Backus-Naur Form) paradigm is a set of symbols first introduced by John Backus and Peter Naur to describe computer language syntax.
Now, almost every newProgramming LanguageThe authors of books use the bacos paradigm to define the syntax rules of programming languages.

Contents of the bacos paradigm

The Word ("word") in double quotes represents the characters themselves. Double_quote represents double quotation marks.
Words outside double quotes (which may contain underscores) represent the syntax section.
Required.
The square brackets ([]) are optional.
The braces ({}) contain items that can be repeated 0 to countless times.
Vertical bars (|) indicate either of the left and right sides, which is equivalent to "or.
: = Indicates "defined.

Bucos paradigm example

This is an example of the for Statement defined by BNF in Java:

For_statement: =
"For" "(" (variable_declaration |
(Expression ";") | ";")
[Expression] ";"
[Expression] ";"
")" Statement

This is the definition of BNF in Oracle packages:

package_body :: = "package" package_name "is"
package_obj_body {package_obj_body}
["begin" seq_of_statements]
"end" [package_name] "; "

package_obj_body :: = variable_declaration
| subtype_declaration
| cursor_declaration
| cursor_body
| prediction_declaration
| statement
| procedure_body
| function_body

procedure_body:: = "procedure" procedure_name
["(" argument {"," argument }") "]
" return "return_type
" is "
[" declare "declare_spec"; "{declare_spec "; "}]
" begin "
seq_of_statements
[" exception "exception_handler {exception_handler}]
" end "[procedure_name]"; "

statement :: = comment
| assignment_statement
| exit_statement
| goto_statement
| if_statement
| loop_statement
| null_statement
| raise_statement
| SQL _statement
| plsql_block

This is an example of BNF defined by BNF:

syntax ::={ rule}
rule ::= identifier "::=" expression
Expression :: = term {"|" term}
term: = factor {factor}
factor :: = identifier |
quoted_symbol |
"(" expression ") "|
" ["expression"] "|
" {"expression"} "
identifier :: = letter {letter | digit}
quoted_symbol: = "{any_character}" "


Extended bacos paradigm augmented BNF

Rfc2234 defines the extended bacos Paradigm (ABNF ). ABNF has been widely used in Internet definition in recent years. ABNF has made more improvements. For example, in ABNF, angle brackets are no longer needed.

What is ebnf? Basic (Ebnf) Definition Related Ebnf For more information about the Agreement, see Computing dictionary .
Here is a summary of key points :

"...":Glossary
[...]:Option:Up to once
{...}:Repeated items:Any number of times, including 0
(...):Group
|:Parallel option. You can only select one
Italics:Parameter, which is explained elsewhere
An ebnf application in the card and board category is given in the http://estone.nease.net/sgf/sgf4.html#2. optional <BNF >::=< non-terminator >:=< or item list>
<Or item list >::= <item >|< or item list >|< item>
<Item >::= <Non-terminator >|< Terminator >|< item> <Non-terminator >|< item> <Terminator>
<Non-terminator >::=< non-terminator Name>

(Hopefully someone can understand it :-))

BNF is the abbreviation of the baktel-purl formula,
In the Prehistoric Age of computers (1950 s), a master once laid the foundation of modern computers.
Among the achievements of his elders, he has studied formal language and developed advanced languages:
FORTRAN.
To commemorate his old man's family, we call his method of describing language BNF.

In fact, BNF is very simple: = represents the definition | represents or the non-terminator enclosed by Angle brackets (<> ).
A non-Terminator is an abstract concept in a language, and a terminator can appear directly in
Symbols in Language

For example, the C language statement can be described as BNF:
<Declaration statement >::=< type> <identifier >;|< type> <identifier> [<number>];
In this sentence, the non-Terminator is defined as two forms (the two parts separated by | are used above)
Three terminologies are introduced here: semicolons; left and right square brackets []

<Type >::=< simple type >|< pointer type >|< custom type>
<Pointer type >::= <simple type> * | <custom type> *
<Simple type>: = int | char | double | float | long | short | void
<Custom type >::= Enum <identifier> | struct <identifier> | Union <identifier >|< identifier>
The <type> is clearly defined here.

<Number >::= 0x <Hexadecimal digit string >::= <Octal digit string >::= <octal digit >|< octal digit string> <octal digit>
<Decimal digit string >::=< decimal digit >|< decimal digit string> <decimal digit>
<Hexadecimal number >::=< decimal number> | A | B | c | d | E | f
<Decimal number >::= <octal number> | 8 | 9
<Octal digit>: = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
The <number> is clearly defined here.

<Identifier >::=< letter >|< identifier> <letter/number string>
<Alphanumeric string >::=< letter >|< decimal number >|< letter and digit string> <letter >|< letter and digit string> <decimal number>
<Letter >::=_ | <upper-case letter >|< lower-case letter>
<Lowercase letter>: = A | B | c | d | E | f | G | H | I | J ...... (Stealing laziness)
<Uppercase letter>: = A | B | c | d | E | f | G | H | I | J ......

So far, the entire declaration statement has been defined (that is, there is no non-terminator), although it looks very good
However, the non-terminator defined earlier can be easily reused elsewhere, for example, function declaration.
It can be defined as follows:
<Function declaration statement >::=< type> <identifier> (<parameter table> );
<Parameter table >::=< type> <identifier >|< parameter table>, <parameter table>
BNF is actually much more concise than natural language.
(The entire C language can be clearly described in only 100 or 200 sentences)
It is quite accurate and does not contain the ambiguous expressions in natural languages.
If you are sensitive to BNF, you will find that the identifier in C cannot start with a number.
In addition, the underline in C is treated as a letter (that is, a place where letters can be used)
Can be underlined) for example: (it is best to use an older compiler, such as CC on PDP11)
# Define ____ main
# Define ___
Typedef char *_____;
INT (* ______) (char *,...) = printf; // if this sentence does not work, use the following sentence
/// # Define ______ printf // if you are using C ++, you can try the following:
// Int (* ______) (const char *,...) = printf;

____ (_, Char * _ []) // if your compiler does not eat it, you can change it to int ____ (INT _, char * _ []).
{
___(;_;_--)
{
______ ("% S \ n", _ [_]);
}
}

In addition, there is also an ebnf that is not as good as the authentic BNF, and many people are using it.
Recursive definitions are written {}

For a while, Pascal fans liked to use something called a syntax graph, which was hard to see,
The function is similar to BNF. Now it seems that few people have used it.

Another popular thing in recent years:
Digit = one
0 1 2 3 4 5 6 7 8 9
Here, the non-terminator digit is represented in italic. One of is a quantizer defined in this method (commonly used oblique simhei)
I don't like this because my eyes are not good. I often cannot tell whether it is italic or positive.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.