A simple grammar for Chinese may include the following rules:
<S> ::= <NP> <VP>。 <NP> ::= <N> | <Num> <MW> <N> <Num> ::= 一 | 两 <MW> ::= 个 | 条 | 只 | 口 <N> ::= 猫 | 狗 | 猪 <VP> ::= <V> <NP> <V> ::= 吃 | 爱 | 怕
狗前边的一只猫怕狗。Add new rules to accept sentences like this, as well as the simple sentences already handled. The new rules should (in principle) accept (overly complex) sentences such as the following:
猪上边的一条狗上边的一只猫吃老鼠。(``In principle'' here means assume we added the individual words as well.)
The syntax diagrams in the textbook use arrows. More traditionally, ``railroad diagrams'' use curves to show which direcion is permitted: a train can never take a sharp corner. The following example shows a true ``railroad diagram.''
Consider a hypothetical programming language with the following
definition for a ``block'':
(The graphic above doesn't look right in the generated HTML;
there is a missing semicolon after each declaration, and after the
optional declare part is done, it goes down to the
begin-end block.)
Nonterminals are lowercase words in rectangular boxes. Terminals are
either UPPERCASE words in boxes, or literal (quoted) characters in
ovals.
A simple way to convert EBNF to BNF, is to add a new nonterminal
for
each parenthesized sequence. Then the new nonterminal gets new rules
depending on the parenthesization:
This homework is done on paper only. Please put your name and student ID number (学号) on the top. Turn the homework in at the beginning of lecture, March 8th. If you cannot get to lecture ahead of time, please turn it in to my office, 蒙民伟楼 (MMW Building) 312.