Due: before class on Monday 15 September
Looking back
-
In C++, you use angle brackets
<>to specify the type of each element of a container, likevector<int> vector_of_integers;The problem is when these types become nested, like when you want a vector of vectors:
vector< vector<int> > two_d_array;What I wrote above is fine, but (until the c++11 version), the following would not work:
vector<vector<int>> two_d_array;The only difference is the spacing. But we know that whitespace is ignored in C++, so what is going on here?
Specifically, use what you know about scanning to say what you think would go wrong with the second syntax (without the extra space), and why adding the space makes it work.
-
Consider a language with the following four token types, in priority order:
BIND: BB SHOW: S NUM: [IVXL] GLYPH: [A-Z][a-z]*The language also ignores all whitespace.
-
Draw the scanner DFA for this language.
You do not need to draw the trap state or handle whitespace in the DFA.
-
Give the complete token stream that would result from scanning the following program in this language:
TenXBBSeventyTenLXBBSSeventyTwenty
-
-
Here is a grammar for a language containing the tokens from the previous problem.
program -> assignments print assignments -> assignments assign assignments -> ε assign -> GLYPH value BIND print -> SHOW value value -> NUM value -> GLYPH value -> value valueDraw the complete parse tree resulting from the program in problem 2b according to this grammar.
Looking ahead
- Come up with an example program and two different parse trees to show that the grammar in problem 3 is ambiguous. Try to come up with the smallest/shortest example you can.