|
CS 3723/3721 Programming Languages Fall 2004 Recitation 4 Formal Grammars Week 4: Sep 13-17 Due (on time): 2004-09-20 23:59:59 Due (late): 2004-09-24 23:59:59 |
Recitation 4 must be submitted
following directions at: submissions with deadlines
|
A ---> a A c (A is start symbol)
A ---> b
O ---> a | a E (O is start symbol)
E ---> a O
S ---> A B (S is start symbol)
A ---> a A | a
B ---> b B c | b c
S ---> a B | b A (S is start symbol)
A ---> a S | b A A | a
B ---> b S | a B B | b
A ---> <id> = E E ---> E + T | E - T | T T ---> T * S | T / S | S S ---> F ^ S | F F ---> ( E ) | <id> <id> ---> a | b | c | d | . . .
int <id>;
int <id>, <id>;
int <id>, <id>, <id>;
and so forth with any number of identifiers.
(Here int is a reserved word,
and <id> stands for an identifier token.)
Write a simple (recursive) grammar for this language.
A ---> a (A any non-terminal, a any terminal) A ---> a B (A any non-terminal, a any terminal, B any non-terminal)
digit ----> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 letter ----> a | b | ... | z | A | B | ... | Z
and these rules satisfy the condition for being a regular grammar.]
As in question 3, you will need to use recursion (or the notation from question 3).
Convert the following regular grammar to a finite state machine:
A ---> a A | a B | b B | b B ---> b B | c
A ---> a A b | a b
First give the language described by this grammar.
Then argue that no finite state machine can describe this language. (If there are 10 states in the machine, consider the sentence with 11 a's followed by 11 b's. As the first 11 a's are processed, you must be in the same state twice. From this state you must be able to get to the final state as you use up the remaining a's and all the b's.) Thus this is not a regular grammar.
|
Contents of email submission
for Recitation 4: Last Name, First Name; Course Number; Recitation Number (4). Answers to problems 1, 2, 3, 4, and 5 above (where each has several subparts). Problems should be in the order given and should be clearly labeled, with 1, 2, etc., and a., b., etc.
|