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.
-
[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.
-
[5] Rewrite the
Statements rule so that it does not use the extended BNF
syntax (the metacharacters { }) but still describes the same language.
-
[5] What is the first set of the non-terminal
Expression?
-
[20] Develop a Java class hierarchy suitable for representing the abstract syntax of
CliteExam2 expressions beginning with the non-terminal
Expression.
-
[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.
-
[15] Devleop a class hierarchy suitable for representing the abstract syntax of a
CliteExam2
while statement.
-
[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().
-
[2] What is a type error?
-
[2] Give one example of a type error in Java.
-
[2] Give one example of a type error in Scheme.
-
[2] What is a primitive type?
-
[2] Describe two different language features in in Java (or C++) that allow you to define your own user defined type.
-
[3] Define what is means for a language to be statically typed.
-
[3] Define what it means for a language to be strongly typed.
-
[2] Describe one benefit of strong typing.
-
[2] Describe one benefit of dynamic typing.