midterm1 - Midterm Exam CS131 Programming Languages...

Info icon This preview shows pages 1–4. 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 difficulty, so skip around. Relax! 1
Image of page 1

Info icon This 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 defined. (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. <baseexp> ::= <var> | <const> | ( <exp> ) | ’[’ [<exp> { , <exp> } ] ’]’
Image of page 2
2. (4 points each) It turns out that ML’s boolean operators — orelse , andalso , and not need not be built in to the language. This question explores that idea.
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern