Q0 Set up : Get your stuff working under subversion : Go to 310/cs310gpXX/1 : svn export http://unbox.org/wisp/var/timm/10/310/src/gawk/1/c : svn add c : svn commit -m "b ready to go" : For each of the following questions, add lines like this to "run" printf "\n===== 1/c/q1 ========================\n\n" cat myCodeThatAnswersThisQuestion.awk execute : where "execute" is the "test" command shown below. Q1 Write : Write an awk program that prints the total number of upper case : words in a file. Test : gawk -f uppercase.awk english.rules Q2 Write : Write an awk program that print the largest numeric first field and the : line that contains it Test : ls -lsai / | gawk -f largest.awk Q3 (hard: worth 2.5 marks) Write : Adapt story.awk to handle attributed grammars. For such grammars, : some of the productions are not "A -> b c d" but "A=terminal". For : such rules, the rhs is a single terminal. If that rule is selected, : then an attribute is fixed to a value. : : This lets us fix strings and reuse them. To see why that is useful, : consider the following grammar : : Sentence -> Nounphrase Verbphrase : Nounphrase -> Boy : Nounphrase -> Girl : Boy -> john : Boy -> ajit : Girl -> pima : Girl -> barkha : Verbphrase -> Verb Modlist Adverb with Nounphrase : Verb -> runs : Verb -> walks : Modlist -> : Modlist -> very Modlist : Adverb -> quickly : Adverb -> slowly : : Note that now we can select two boys at different parts of the : story. : : But, in the following grammar, once we pick a heroine/ hero then we : always use their name (note the use of "=" in the following). : : Sentence -> Nounphrase Verbphrase : Nounphrase -> Boy : Nounphrase -> Girl : Boy = john : Boy = ajit : Girl = pima : Girl = barkha : Verbphrase -> Verb Modlist Adverb travels with Nounphrase : Verb -> runs : Verb -> walks : Modlist -> : Modlist -> very Modlist : Adverb -> quickly : Adverb -> slowly Note : Of course, the grammar still is "broken" since in this story, : the someone can travel with themselves. : e.g. "pima runs slowly with pima" : What we need is a better : constraint language in our grammar such that we can specify that : someone cannot travel with themselves. We will build such a grammar, : later in the semester. Hint Working memory : Keep a working memory of settings "Setting[Name]". In the above, we : might get "Setting[Boy]=john" and "Setting[Girl]=pima". Before rewriting a terminal : change the generation code such that before it looks up a definition : if checks for "if (Setting[Terminal])". And, if it is there, just : return it. After rewriting a terminal : On return from generating a terminal, if the result is something : defined in as a Setting, then you have to set this Setting. : To test for a key in an array, use (x in Setting). Reading : You will also have to change how story.awk reads in productions. : Now, if we see "Variable = terminal", then we have to: : 1) read it as if it was "Variable -> terminal" : 2) set Setting[Variable]="" : (Btw, if Setting[Variable] is the empty string then : "if : (Setting[Variable])" will return false so the the above "if" : test will work correctly.