CSC 533: Organization of Programming Languages
Spring 2017
HW1: Syntax and EBNF Grammars
Answer the following questions about the programming langauge Ada by referring to
its EBNF at the
BNF Web Club.
- Which of the following are legal numeric literals in Ada?
For each legal literal, provide a parse tree (with the
numeric_literal
abstraction at the root).
00 -2.9 16#A# A#16#
2E-4 0.01E12 5.5E+5.5
- Which of the following are simple expressions in Ada?
For each legal expression, provide a parse tree (with the
simple_expression
abstraction at the root).
1 - 3 -1 - 3 -1 - -3 1 - 2 - 3
A A mod B 1 ** 2 ** 3 foo / ** bar
- What is the order of precedence for the operators and, or and
not in Ada? 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 (
ident
)
in Ada. That is, what
characters may be used? What restrictions (if any) are there on order?
- What is the assignment operator in Ada (i.e., the symbol that separates the left and right
sides of an assignment)?
- How are comments specified in Ada?
- Does the dangling-else problem apply to Ada? Justify your
answer.
- Give an example of a subprogram declaration that is as short as
possible, in terms of number of tokens.
- Give an example of a subprogram body that is as short as
possible, in terms of number of tokens.
- What is the difference between a type declaration and a full type declaration? Give an example of an expression that can be derived from one of the abstractions (
type_declaration
or
full_type_declaration
) but not the other.