Wednesday 4 March 2015

3.0 - QA

1. Define syntax and semantics!
= Syntax is the form of expressions, statements, and program units. Semantics is the description of those expressions, statements, and program units.


2. Who are language descriptions for?
Language descriptions are for other language designers, implementers, and programmers (users of the language).

3. Define a left-recursive grammar rule.
= When a grammar rule has its LHS also appearing at the beginning of its RHS, the rule is said to be left-recursive. Left-recursive specifies left associativity. Unfortunately, left recursion disallows the use of some important syntax analysis algorithms. When such algorithms are to be used, the grammar must be modified to remove the left-recursion. This in turn, disallows the grammar from precisely specifying that certain operators are left associative. Fortunately, left associativity can be enforced by the compiler, even though the grammar does not dictate it.

7. What three extensions are common to most EBNFs?
= The first extension denotes an optional part of a RHS, which is delimited by brackets. For example:
<if_stmt> -> if ( <expr> ) stmt [ else <stmt> ]

The second extension is the use of braces in an RHS to indicate that the enclosed part can be repeated indefinitely or left out altogether. For example: <ident_list> -> ident {, <ident> }


The third extension deals with multiple choice options. For example: <term> -> <term> ( *|/|% ) <factor>


8. Distinguish between static and dynamic semantics.

= Static semantics is more on the legal forms of programs (syntax rather semantics) and is only indirectly related to the meaning of the programs during execution. Static semantics is named because the analysis required to check these specifications can be done at compile time. In many cases, the semantic rules of language state its type constraints.

Dynamic semantics is describing the meaning of the programs. Programmers need to know precisely what statements of a language do. Compile writers determine the semantics of a language for which they are writing compilers from English descriptions 


10. What is the difference between a synthesized and an inherited attribute? = The synthesized attributes are the result of the attribute evaluation rules and may also use the values of the inherited attributes. The inherited attributes are passed down from parent nodes. In some approaches, synthesized attributes are used to pass semantic information up the parse tree, while inherited attributes help pass semantic information down it.
For instance, when constructing a language translation tool, such as a compiler, it may be used to assign semantic values to syntax constructions. Also, it is possible to validate semantic checks associated with a grammar, representing the rules of a language not explicitly imparted by the syntax. 


12. What is the primary use of attribute grammars?
= An attribute grammar is a device used to describe more of the structure of a programming language than is possible with a context-free grammar. An attribute grammar is an extension to a context-free grammar. The primary purpose of an attribute grammar is it allows certain language rules to be described, such as type of compatibility. An attribute grammar is a formal way to define attributes for the productions of a formal grammar, associating these attributes to values. The evaluation occurs in the nodes of the abstract syntax tree, when the language is processed by some parser or compiler. 

15. Describe the two levels of uses of operational semantics!
= There are different levels of uses of operational semantics. At the highest level, the interest is in the final result of the execution of a complete program. This is called natural operational semantics. At the lowest level, operational semantics can be used to determine the precise meaning of a program through an examination of the complete sequence of state changes that occur when the program is executed, This use is called structural operational semantics.

16. In denotational semantics, what are the syntactic and semantic domains?
= The mapping functions of a denotational semantics programming language specification, like all functions in mathematics, have a domain and a range.
the syntactic domain is called the domain because it is syntactic structures that are mapped. The domain is the collection of values that are legitimate parameters to the function; the range is the collections of objects to which the parameters are mapped.
the semantic domain is called the range. 

19. What two things must be defined for each language entity in order to construct a denotational description of the language?
= objects and functions

20. Which part of an inference rule is the antecedent?
= The top part of an inference rule is called the antecedent.

21. When a grammar rule said to be left recursive?
= When a grammar rule has its LHS also appearing at the beginning of its RHS, the rule is said to be left-recursive. This left recursion specifies left associativity.
22. Give an example of an ambiguous grammar.
= <program> →<stmts>
<stmts> → <stmt> | <stmt> ; <stmts>
<stmt> → <var> = <expr>
<var> → a | b | c | d
<expr> → <term> + <term> | <term> – <term>
<term> → <var> | const

23. On what branch of mathematics is axiomatic semantics based?
= mathematics logic

25. What is the problem with using a software pure interpreter for operational semantics?
= The detailed characteristics of the particular computer would make actions difficult to understand. Such a semantic definition would be machine-dependent.

26. Explain what the preconditions and postconditions of a given statement mean in axiomatic semantics.
= An assertion before a statement (a precondition) states the relationships and constraints among variables that are true at that point in execution. An assertion following a statement is a postcondition

27. What is loop invariant? Explain with an example.
= The corresponding step in the axiomatic semantics of a while loop is finding an assertion called a loop invariant, which is crucial to finding the weakest precondition. The loop invariant must satisfy a number of requirements to be useful. First, the weakest precondition for the while loop must guarantee the truth of the loop invariant. In turn, the loop invariant must guarantee the truth of the postcondition upon loop termination. These constraints move us from the inference rule to the axiomatic description. During execution of the loop-controlling Boolean expression and the loop body statements. Hence, the name invariant.

28. What is the use of the wp function? Why it is called a predicate transformer?
= 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.

No comments:

Post a Comment