Monday, March 25, 2013

Answers of Chapter 3 "Concept of Programming Language"


1. Syntax is the form of programming language's expressions, statements, and program units. Semantics is the meaning of those expressions, statements, and program units
2. Language descriptions is for programming language implementors
3. The general operation of language generator is as same as when a button is pushed and certain languages are generated
4. The general operation of language recognizers is it will scan whether inputted string is inside certain language. If it is, it will accept the string.
5. Sentences are string of a language. Sentential form is each strings in the derivation of each string in sequence.
6.
7. Three common extensions of EBNF : optional part of RHS is delimited by brackets, the enclosed part can be repeated indefinitely or left out left alltogether.
8. static semantics is only indirectly related to the meaning of programs during execution. Dynamic semantics is not universally accepted in notation.
9. Predicates function as boolean expression on the union of the attribute set and a set of literal attribute values
10. Synthesized attributes are used to pass semantic information up a parse tree while inherited attributes pass smenatic information down and acroos a tree
11. the parse tree is evaluated based on its underlying BNF grammar, wit a possibility of having empty set of attributes values attached to each node.
12. Attribute grammars are used to describe more of the structure of a programming language than can be described with a context-free grammar.

Problem Set
1. Example of syntax error in C programming language : while boolean_expr  -> no brackets before and after the boolean expression.
Example of semantics error in C programming language : while (angka) {}  -> but, the variable 'angka' is never defined by user before

2. a. class { }
    b. ( ) ;
    c. switch ( ) { case : }
    d. union { };
    e. float ;

3. -> =
    -> A|B|C
    -> +
                 |
    -> *
                 |
    -> ( )
                    |

4.
5.
6. a.   -> =
          -> A|B|C
          -> +
                       |   * ( )
                       |  ( )
                       |
    b.   -> =
          -> A|B|C
          -> +
                       |   *
                       |  ( )
                       |  < id> *
                       |   +

    c.   -> =
          -> A|B|C
          -> * ( )
                       |   +
                       |  ( )
                       |
15.  expression -> var {(+ | -) var}
16. expr -> expr {(+ | *) expr}
21. a. do{                                            loop: expr1;
          expr1                                         if(expr==0) goto out;
          }while(expr2);                            else goto loop;
                                                            out : ...
     b. expr1;
         loop : if expr2 ==0 goto out
         ...
         expr3;
         goto loop
         out : ...
     c. if expr1==0 then expr2;
         else expr3;
     d. expr1;
         loop : if expr2 ==0 goto out
         ...
         expr3;
         goto loop
         out : ...
     e. if expr1 == 1 then expr2;
        else if expr2 == 1 then expr3;;
        else if expr3 == 1 then expr4;
        ...

No comments:

Post a Comment