Programming Language Chapter 3

Assignment from Mr. Tridjoko Wahyono
REVIEW

  1. Define syntax and semantics.(1)
  2. Describe the operation of a general language generator.(3)
  3. Describe the operation of a general language recognizer.(4)
  4. What is the different between a sentence and a sentential form?(5)

  1. Define a left-recursive grammar rule.(6)
  2. What is stored in the state of program for denotational semantics?(17)
  3. Which part of an inference rule is the antecedent?(20)
  4. Give the different between total correctness and partial correctness(29)

Answer

  1. Syntax: Is the form of its expressions, statements, and program units

Semantics: Those expressions, statements, and program units

  1. When the button is pushed is unpredictable, a generator seems to be a device of limited usefulness as a language descriptor.
  2. To define something using the recognition method, we would need to construct the mechanism called a recognition device, capable of reading strings of characters from the alphabet.
  3. Sentence: One or more string in the derivation.

Sentential Form: Every string in the derivation.

  1. Left-recursive: When a grammar rule has its LHS also appearing at the beginning of its RHS
  2. In denotational semantics, programming language construct are mapped to mathematical objects, either sets or, more often, functions.
  3. The top part of the inference rule is called antecedent.
  4. Total correctness: the loop termination can be shown

The other conditions can be met but t5ermination is not guaranteed.

PROBLEM SET

  1. Write EBNF descriptions for following(2)
    1. A java class definition header statement
    2. A java method call statement
    3. A c switch statement
    4. A c union definition
    5. C float literals
    6. How parse tree for each of the  following statement(6):
      1. A=A*(B*(C+A))
      2. B=C*(A+C*B)
      3. A+A+(B*)C))
      4. Convert the BNF to EBNE(15)
      5. Convert the BNF to the EBNE(16)
      6. Proves that the following grammar is ambiguous(8):

<S>-><A>

<A>-><A>*<A>|<id>

<id>->x|y|z

  1. Describe in English the language defined by the following grammar(10):
    1. <S>-><X><Y>
    2. <X>->x<X>|x
    3. <Y>->y<Y>|y

ANSWER

    1. <class_head>{<modifier>}

class <id> [extends class_name][implements <interface_name> {, <interface_name>}] <modifier>public | abstract | final

  1. <class_head>{<modifier>}

class <id> [extends class_name][implements <interface_name> {, <interface_name>}] <modifier>public | abstract | final

  1. <stmt>     ->   switch ( <int expr> ) {

case <int const> :  { <stmt> ; }

case <int const> :  { <stmt> ; }}

default :  { <stmt>  ;  } ]

}

  1. <union_defn> -> union <var_list> <union_identifier>;

<var_list> -> <list_of_data-type specifier> <var>

<list_of_data-type specifier> -> int | float | long |char | double

<union_identifier> -> <var>

  1. float_num> -> <float_lit>

<float_lit> -> 12.4 | 34.98 | 89.67

  1. Answer
    1. Assign   =<id>=<expression>

=<expression>=<id>*<expression>(expression)

=(expression)=<id>*<expression>(expression)

=(expression)=<id>+<expression>

=<expression>=<id>

  1. =<id>=<expression>

=<expression>=<id>*<expression>(expression)

=(expression)=<id>+<expression>

=<expression>=<id>+<expression>

=<expression>=<id>

  1. =<id>=<expression>

=<expression>=<id>+<expression>(expression)

=(expression)=<id>*<expression>(expression)

=(expression)=<id>

  1. <assign>              =<id>

=<id>=<expression>

=<expression>=<id>*<expression>

=<expression>=(expression)

=(expression)= =<id>+<expression>

=<expression>=<id>

  1. <assign>              =<id>

=<id>=<expression>

=<expression>=<expression>+<expression>

=<expression>=<id>

=<expression>=<id>+<expression>

=<expression>=<expression>*<expression>

=<expression>=<id>

=<expression>=<id>+<expression>

=<expression>=<id>

  1.    <S>

<A>

<A>

<A>

<id>

x

+

<A>

<id>

y

+

<A>

<id>

z

  1. the abstraction,<S> is defined as an instance of the abstractions <X>, <Y>, and <Z>,

where <X>,<Y>,<Z> must be defined first. There are two distinct definition listed under

abstractions <X>,<Y> and <Z>. The two definitions are separated by the symbol ‘|’, meaning

logical OR. Abstraction <X> is defined as a recursion of abstraction <X> itself OR a single

character ‘x’. Abstraction <Y> is defined as a recursion of abstraction <Y> itself OR a single

character ‘y’. And finally, abstraction <Z> is defined as a recursion of abstraction <Z>

itself OR a single character ‘z’.

About these ads
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s