Language Parsing Exercises 1 Name ____________________ 1.A. Write out a leftmost derivation of ()(()). The grammar is: L -> (L)L L -> lambda B. Write out leftmost derivation tree for ()(()) 2.A. Determine the First sets for the non-terminals in the grammar: A -> a B First(A) = { } A -> b A -> c B B First(B) = { } B -> a B B -> b A void match(char t) // Function match() matches the current lookahead char. { // If the match is correct, update lookahead to the next if (lookahead==t) // char in the input stream. lookahead = getchar(); else { printf("Error in Match()\n"); exit(1); } } Using match() and First sets, define functions A() and B() for the recursive descent parsing of grammar A. void A() { } void B() { } int main() { lookahead = getchar(); // lookahead is a global char variable A(); // "A" is the start symbol, the first non-terminal // Write a function for each non-terminal. if (lookahead != '\n') ok = 0; // At the end of the input string, there if (ok) printf("Accept\n"); // should be a newline. else printf("Reject\n"); return 0; }