Homework # 1
due Thursday, March 8, 2:00 PM

Natural Language Grammars

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> ::= 吃 | 爱 | 怕

Programming Language Grammars

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'':
\begin{rail}
block : (\vert 'declare' ((ID ':' TYPE (\vert ':=' expr) ';' ) + ()) ) \\ 'begin' (expr + ';') 'end'
\end{rail}
(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.

Submitting Your Work

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.


About this document



John Boyland 2007-03-06