Slide 2.4: Context-free grammars vs regular grammars Slide 2.6: Syntax diagrams Home |
whereG
= (Σ
,N
,P
,S
) = ( {+
,-
,*
,(
,)
,number
}, {<exp>
,<op>
},P
,<exp>
)
P
consists of
<exp> ::= <exp> <op> <exp> | ( <exp> ) | number <op> ::= + | – | *The grammar is context-free because only single nonterminals occur on the left sides of the rules. The hyperlink gives the BNF of Pascal.
<stmt-sequence> ::= <stmt> ; <stmt-sequence> | <stmt> <stmt> ::= s ⇓ <stmt-sequence> ::= { <stmt> ; } <stmt> <stmt> ::= s
<statement> ::= <if-stmt> | other <if-stmt> ::= if ( <exp> ) <statement> | if ( <exp> ) <statement> else <statement> <exp> ::= 0 | 1 ⇓ <statement> ::= <if-stmt> | other <if-stmt> ::= if ( <exp> ) <statement> [ else <statement> ] <exp> ::= 0 | 1