Quiz 19 Sept 2013 Do all questions:
1) Scanner
write a regular expression for Thai names such as "ประภาส จงสถิตย์วัฒนา"
2) Grammar
Here are examples of the sentences in my "robotic" language:
pick up the blue box
put the box on top of the table
clear the table
where is the big red pyramid?
Write a grammar to define this language
3) Write a recursive program to expand "macro". Given a parse-tree and a
macro. Substitute the macro call in the parse-tree. Here is an example:
main()
a = b + c
b = inc(b)
macro inc(x)
x + 1
The parse-tree for "main" is
(main (do (= a (+ b c)) (= b (macro inc b))))
(macro inc (x) (+ x 1))
To expand a macro, inc(b) is replace by (+ b 1). The b is binded to x and
x + 1 is changed to b + 1. Here is the output after expansion
(main (do (= a (+ b c)) (= b (+ b 1))))
You can write this program in a pseudo code. Your function API is
expand(p1, p2) where p1 is the main, p2 is the macro, it returns the new
parse-tree.
Hand in to Khun Su at the office by 4pm on Monday 23 Sept.