CS364 Programming Languages Sample Exam 2

For the questions where I ask you to implement parser functions you may assume that you have a working lexical analyzer with a nextToken() function and reasonably named constants defined such as Token.LPAREN, etc..

Answer the following questions about a the CliteExam2 grammar where Statements is the start symbol.

  1. [5] What is the shortest, non-empty, syntacially valid CliteExam2 program? Draw the parse tree for this program. Shortest means the program with the fewest number of tokens.
  2. [5] Rewrite the Statements rule so that it does not use the extended BNF syntax (the metacharacters { }) but still describes the same language.
  3. [5] What is the first set of the non-terminal Expression?
  4. [20] Develop a Java class hierarchy suitable for representing the abstract syntax of CliteExam2 expressions beginning with the non-terminal Expression.
  5. [15] Write a function Addition() that parses CliteExam2 mathematical expressions starting with the non-terminal Addition and constructs an AST defined in the previous question. Don't worry about error checking.
  6. [15] Devleop a class hierarchy suitable for representing the abstract syntax of a CliteExam2  while statement.
  7. [15] Develop a function whileStmt() that parses a Clite while-statement and generates the AST defined in the previous question. You may assume that you can call parser functions expression() and statement().
  8. [2] What is a type error?
  9. [2] Give one example of a type error in Java.
  10. [2] Give one example of a type error in Scheme.
  11. [2] What is a primitive type?
  12. [2] Describe two different language features in in Java (or C++) that allow you to define your own user defined type.
  13. [3] Define what is means for a language to be statically typed.
  14. [3] Define what it means for a language to be strongly typed.
  15. [2] Describe one benefit of strong typing.
  16. [2] Describe one benefit of dynamic typing.