Tuesday, March 26, 2013

Chapter 3 - Describing Syntax and Semantics

Name : Agata Sri Sartika Servina
NIM : 1601218804
Class: 02PCT
Special thanks to : Mr. Tri Djoko Wahjono, Ir., M.Sc.
Review Question
1. The syntax of a programming language is the form of its expressions, statements, and program units. Semantics is the meaning of those expressions, statements, and program units.
2. A language generator is a device that can be used to generate the sentences of a language. We can think of the generator as having a button that produces a sentence of the language every time it is pushed . In this term, people prefer certain forms of generators over recognizers because they can more easily read and understand them. By contrast, the syntax- checking portion of a compiler is not as useful a language description for a programmer because it can be used only in trial and error mode.
4. Sentence form is a program consists of the special word begin, followed by a list of statements separated by semicolons, followed by the special word end. Sentential form is each of the strings in the derivation, including
6. Synthesized attributes are used to pass semantic information up a parse tree, inherited attributes are used to pass semantic information down and across a tree.
9. The wp function is helpful to treat the process of producing a weakest precondition as a function. It is called a predicate transformer because it takes a predicate, or assertion, as a parameter and returns another predicate.
10. Total correctness is the axiomatic description of the loop when the loop termination is shown Partial correctness is the other condition can be met but termination is not guaranteed.
23. Axiomatic semantics, named because it is based on mathematical logic.
28.A weakest precondition is the least restrictive precondition that will guarantee the postcondition. It is often called a predicate transformer because it takes a predicate, or assertion as a parameter and returns another predicate.
Problem Set
1. Syntax Error: error due to missing colon, semicolon, parenthesis, etc. Syntax is the way in which we construct sentences by following principles and rules.
Examples:
1. int x = “three”;
In C++, this will not compile because it does not follow the syntax of the language and does not make any sense to the compiler.
5. →id = = id | id != id
7. S A {bA}
Aa [b]A
b |
a | ab
8. A fully attributed parse tree is a condition when all the attributed values in parse tree have been computed.
16. =
→ A | B | C
(+ | -)
| ()
|
17. S → A | A B
B → b A | b A B
A → a A | a b A
18. if all the attributed values in a parse tree have been computed. a parse tree of an attributed grammar is the parse tree based on its underlying BNF grammar, with a possibly empty set of attribute values attached to each node.
24. a. a= 2*b+1
b=a-3 {b<0}
b. a= 3*(2*b+a)
b= 2*a-1 {b>5}
2*a-1>5
2*a>6
(a). -> a-3<0
a<3
a=2*b+1 {a<3}
2*b+1<3
2*b<2
b<1
(b). -> a= 3*(2*b+a) {a>3}
3*(2*b+a)>3
6*b+3*a>3
2*b+a>1
b>(1-a)/2

No comments:

Post a Comment