midterm1 - Midterm Exam CS131 Programming Languages...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Midterm Exam CS131: Programming Languages Wednesday, February 9, 2005 Name: ID: Rules of the game: Write your name and ID number above. The exam is closed-book and closed-notes. Please write your answers directly on the exam. Do not turn in anything else. When writing code, using good ML style matters. If you have any questions, please ask. The exam ends promptly at 11:50am. A bit of advice: Read questions carefully. Understand a question before you start writing. Write down thoughts and intermediate steps so you can get partial credit. The questions are not necessarily in order of diFculty, so skip around. Relax! 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
1. (4 points each) Consider this partial grammar for the syntax of Standard ML expressions, where <var> and <const> are non-terminal symbols representing variables and constants, respectively: <exp> ::= <exp> + <baseexp> | <baseexp> <baseexp> ::= <var> | <const> | ( <exp> ) This question asks you to extend the grammar in several ways. You may use either BNF or EBNF notation. Be sure to clearly distinguish metasymbols from the symbols in the grammar being de±ned. (a) Add the syntax for ML’s unary negation operator ~ at higher precedence than + . <exp> ::= <exp> + <negexp> | <negexp> <negexp> ::= <negexp> | <baseexp> <baseexp> ::= <var> | <const> | ( <exp> ) (b) Add the syntax for ML’s right-associative cons operator :: at precedence level lower than both + and ~ . <exp> ::= <plusexp> :: <exp> | <plusexp> <plusexp> ::= <plusexp> + <negexp> | <negexp> <negexp> ::= <negexp> | <baseexp> <baseexp> ::= <var> | <const> | ( <exp> ) (c) Add the syntax for ML’s list expression to the grammar for base expressions <baseexp> . A list expression can have zero or more comma-separated element expressions.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 9

midterm1 - Midterm Exam CS131 Programming Languages...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online