CSCI 360 

Quiz #1, Names, Binding, Syntax and Semantics 

Spring 2008 

 

This quiz should take no more than 20 minutes. Maximum score is 15 points; point values for each question are as shown. All answers and work are to be written in the space provided (use back if necessary). 

 

  1. Name three design issues pertaining to variable names and briefly describe them. [3 points]. 

 

Case Sensitivity – are Foo, fOo and foo the same variable? 

 

Connector Characters – is B A R and BAR the same? 

 

Maximum Length – how long can a name be and are all the characters meaningful? 

 

Reserve Words – are there special keywords that cannot be used as variable names? 

 

 

 

  1. What are attribute grammars and why are the needed? [2 points]

 

 

 

 

  1. What is meant when we say that a grammar is ambiguous [1 point]? 

 

The grammar can produce more than one valid parse tree for some statements. 

 

 

 

  1. What does it mean to say a language is strongly typed [1 point]?

 

Strongly typed programming language place severe restrictions on the intermixing of data and variables of different types. For instance, an arithmetic operation may not be used on character data and procedures which operate up strings may not be used upon numbers. However, the nature and strength of these restrictions is highly variable. 

 

 

  1. What is binding? At what times can binding take place and what are some of the advantages and disadvantages of these times? [3 points]?

 

Binding is the association of an attribute with a variable. For example, a data type, memory address, name, value, etc. The two most common binding times are compile time and run time. Bindings that take place at compile time are usually static attributes. This allows the compiler to check for many common errors or dangerous situations during compilation. Bindings that take place a runtime are usually dynamic, meaning they can be changed at a later time during execution. Dynamic binding is often more convenient for the programmer but can make programs harder to maintain and understand. 

 

  1. Give the following BNF rules 

 

 

 

 

 

 

and EBNF rules 

        Assignment Identifier = Expression;

Expression Term { [ + | - ] Term } *

Term Factor { [‘*’ | / ] Factor } *

Factor Identifier | Literal | ( Expression )

 

Sketch parse trees for the assignment statement z=x+5*y/(x+2); Are the trees the same? Why or why not? [5 points]. 

No, they produce different parse trees because the grammars are different.