Home arrow Studies arrow Compiler arrow Pascal's Backus Naur Form (BNF)
Backus Naur Form (BNF) of Pascal Language PDF Print


BNF is used in compiler design process. The diagram below summarizes the program writing method in Pascal.
 

 

<prog>            ::= PROGRAM <prog-name> <element> BEGIN <statement list> END.

<prog-name>    ::=  <ident>

<ident>                        ::= <letter> | <letter><digit>

<element>                    ::=  VAR <dec-list> : <type> |

      CONST <dec-list> = <type>

<dec-list>                     ::=  <declaration> | <ident-list> : <type>

<declaration>                ::=  <ident-list> : <type>

<type>                         ::=  INTEGER | STRING | REAL

<ident-list>       ::=  ident | <ident-list>

<statement list>            ::=  <statement> | <statement  list> ; <statement>

<statement>       ::=  <assign> | <input st> | <output st> | <defined loop> | <indefined loop>

<assign>                      ::=  <ident> := <expression>

<expression>                ::=  <term> | <expression> + <term> | <expression> - <term>

<condition statement> ::= IF <comparison> THEN <body> |

       IF <comparison> THEN <body> ELSE <body>

<term>             ::=  <factor> | <term> * <factor> | <term> DIV <factor>

<factor>            ::=  <ident> | int | ( <expression> )

<input st>         ::=  READ ( <ident-list> )

<output st>       ::=  WRITE ( <ident-list> )

<defined loop>  ::=  FOR <ident> := <expression> TO <expression> DO <body>

<indefined loop> ::= WHILE <comparison> DO <body> |

REPEAT <body> UNTIL <comparison>

<comparison> ::= <expression> <relation> <expression>

<relation>         ::=     = | < | <= | >= | <>

<body>             ::=  <statement> | BEGIN <statement-list> END

<letter>            ::=  a | b | ... | z | A | B |  ... | Z

<digit> ::=  0 | 1 | 2 | 3 | ... | 9

<procedure>     ::=  PROCEDURE <proc-name>(<dec-list>) VAR <dec-list> BEGIN

      <statement list> END

<proc-name>  ::=  <ident>

<function>        ::=  FUNCTION <func-name>(<dec-list>):<type> VAR <dec-list> BEGIN

      <statement list> END

<func-name>  ::=  <ident>

 
 

Copyright 2003-2007 by Chasan Chouse.

Locations of visitors to this page