Syntax chart

advertisement
Computation Theory
Second stage
Lec. (7)
College of Computer Technology
Dept. Software
Syntax chart
Any language, we can do formal definition of its syntax, using Syntax chart
Indicate to nonterminal
indicate to terminal
Syntax chart of natural language is
Noun Phase 
Simple Sentence
Noun Phase
Article
Verb Phase
hits
play
go
Noun
man
Dog
Car

Verb Phase 
Noun
Noun Phase
Article
The
A
An
Any high level programming language we can do its Syntax Chart, for example Identifier
syntax chart is:
letter
letter
a
digit
digit
0
b
1
z
9
BNF
A meta language is a language used to talk about a language (usually a different one).
We can use English as its own meta-language (e.g. describing English grammar in
English).
It is essential to distinguish between the met language terms and the object language
terms.
 BNF stands for either Backus-Naur Form or Backus Normal Form.
 BNF is a met language used to describe the grammar of a programming language.
 BNF is formal and precise.
 BNF is essential in compiler construction
< > indicate a non terminal that needs to be further
expanded, e.g. <variable>
Symbols not enclosed in < > are terminals; they represent themselves, e.g. if, while, …
The symbol ::= means is defined as
The symbol | means or ; it separates alternatives,
Example :
<integer> ::= < digit > | < integer > < digit >
or
< integer > ::= < digit > | < digit > < integer >
< digit > ::=
0|1|2|3|4|5|6|7|8|9
 "Extended BNF" allows repetition as well as recursion.
 Repetition is often more efficient when using BNF to construct a compiler.
Example :
< if statement > ::= if ( < condition > ) < statement > |
if ( < condition > ) < statement > else < statement >
< identifier > ::= < letter > | < identifier > < letter > |
< identifier > < digit >
Download