Spring 2014

HW1: Syntax and EBNF Grammars

Answer the following questions about the programming language Pascal by referring to its EBNF. You should work individually (with help from the instructor only) and refer to no other Pascal documentation beyond this document.

- Which of the following are legal numbers in Pascal?
For each legal number, provide a parse tree (with the
`number`

abstraction at the root).000 -4 .67 67. 2E-4 0.01E6 1.2E+1.2 2A - Which of the following are legal expressions in Pascal?
For each legal expression, provide a parse tree (with the
`expression`

abstraction at the root).9 = 9 + 2 + - 2 15 * - 10 3 * 2 - 5 a > b > c 3 - 1 < A and B - What is the order of precedence for the operators
`and`,`or`and`not`in Pascal? Confirm your answer by providing a parse tree for the expression:not A and B or C - Describe, in concise English, the format for identifiers (
`identifier`

) in Pascal. That is, what characters may be used? What restrictions (if any) are there on order?

- Are Pascal arrays always indexed with integers? If so, do the integer indices always start at the same number? If not, what types of values can be used to index an array? Justify your answer.

- Are semicolons statement
*terminators*or statement*separators*in Pascal? That is, does every statement in a block end with a semicolon (including the last one), or are there just semicolons between statements (but not after the last one)? Justify your answer.

- How do procedures and functions differ in Pascal? That is, what terminal symbols appear in one that do not appear in the other? Justify your answer.

- Does the dangling-else problem apply to Pascal? Justify your
answer.

- Give an example of a Pascal type declaration (
`type`

) that is as short as possible (in terms of number of tokens).

- Give an example of a Pascal program (
`program`

) that is as short as possible (in terms of number of tokens).