Review of Concepts Answer the Questions Below About Concepts and Vocabulary From Chapter 7

Concepts of Programming Languages – Chapter three Answers

Review Questions

1. Define syntax and semantics.

  • Syntax is the grade of its expressions, statements, and plan units.
  • Semantics is the meaning of those expressions, statements, and programme units.

2. Who are language descriptions for?
It is for every users of the language(programmers and linguistic communication designers)

three. Describe the functioning of a general language generator.
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 fourth dimension it is pushed. Because the detail judgement that is produced by a generator when its button is pushed is unpredictable, a generator seems to be a device of limited usefulness as a language descriptor

4. Depict the functioning of a language recognizer.
Suppose nosotros have a linguistic communication L that uses an alphabet Σ of characters. To ascertain L formally using the recognition method, nosotros would demand to construct a mechanism R, called a recognition device, capable of reading strings of characters from the alphabet Σ. R would betoken whether a given input cord was or was non in 50. In event, R would either have or pass up the given string. Such devices are like filters, separating legal sentences from those that are incorrectly formed. If R, when fed any cord of characters over Σ, accepts information technology only if information technology is in L, so R is a description of 50. Because most useful languages are, for all applied purposes, infinite, this might seem like a lengthy and ineffective process. Recognition devices, nonetheless, are not used to enumerate all of the sentences of a language—they accept a different purpose. The syntax analysis part of a compiler is a recognizer for the language the compiler translates. In this role, the recognizer demand non test all possible strings of characters from some set to determine whether each is in the language. Rather, it need only determine whether given programs are in the language. In effect then, the syntax analyzer determines whether the given programs are syntactically correct.

7. What three extensions are common to nearly EBNFs?

  • The start extension denotes an optional role of a RHS, which is delimited past brackets. For case: <if_stmt> -> if (<expression>) < argument > [else <statement >]
  • The 2d extension is the use of braces in an RHS to point that the enclosed part can be repeated indefinitely or left out birthday. For example: <ident_list> -> <identifier> {,  <identifier> }
  • The third extension deals with multiple pick options. For case: <term> -> <term> (  * | / | % ) <factor>

12. What is the primary employ of attribute grammars?
An attribute grammer is a device used to draw more than of the construction of a programming language than tin can be described with a context-free grammar. An attribute grammar is an extension to a context-complimentary grammer. The extension allows certain linguistic communication rules to be conveniently described, such every bit type compatibility. Earlier we formally define the form of attribute grammars, we must analyze the concept of static semantics.

15. Describe the two levels of uses of operational semantics.
There are dissimilar 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 test of the complete sequence of land changes that occur when the plan is executed, This use is called structural operational semantics.

xvi. In denotational semantics, what are the syntactic and semantic domains?

  • The syntactic domain is called the domain because it is syntactic structures that are mapped.
  • The semantic domain is called the range.

22. Requite an instance of an ambiguous grammer.
<assign> -> <id> = <expr>
<id> -> A | B | C
<expr> -> <expr> + <expr>
| <expr> * <expr>
|  (  <expr>  )
| <id>

the grammar of this example is ambiguous considering A = B + C * A has two distinct parse trees.

24. Give an unambiguous grammar for if-and so-else.
<if_stmt> ->if <logic_expr>then<stmt>
                           if <logic_expr>then <stmt>else <stmt>


Problem Set

i. Syntax error and semantic error are two types of compilation error. Explicate the difference between the two in a program with examples.
a) Syntax Error: it is a code error.Error due to wrong use of function or missing tokens, misspelling , missing semicolon, missing parenthesis, etc.
example:

  • printf(Hello Globe);
  • if x>5 printf("Truthful");

b) Semantic Error: it is a logical error. It is due to incorrect logical statements. A semantic error would compile, but exist incorrect logically.
example:

  • area = width + length //area should be a multiply of width by length.
  • pi=one.23 //we all know pi has a abiding value that is three.14.

iii. Rewrite the BNF of Case iii.4 to stand for operator – and operator / instead of operator + and operator *.
<assign> → <id> = <expr>
<id> → A | B | C
<expr> → <expr> – <term>
׀ <term>
<term> → <term> / <gene>
׀ <gene>
<cistron> → ( <expr> )
׀ <id>

half-dozen. Using the grammer in Example iii.two, evidence a parse tree for each of the following statements:
a. A = A * (B + (C * A))

Problm Set: Chap3 no 6a

Problm Set: Chap3 no 6a

b. B = C * (A * C + B)

Problm Set: Chap3 no 6b

Problm Set up: Chap3 no 6b

c. A = A * (B + (C))

Problm Set: Chap3 no 6c

Problm Set: Chap3 no 6c

vii. Using the grammar in Example 3.iv, prove a parse tree for each of the post-obit statements:
a. A = ( A * B ) + C

Problm Set: Chap3 no 7a

Problm Set: Chap3 no 7a

b. A = B * C + A

Problm Set: Chap3 no 7b

Problm Gear up: Chap3 no 7b

c. A = A + (B * C)

Problm Set: Chap3 no 7c

Problm Prepare: Chap3 no 7c

d. A = B * (C + (A * B))

Problm Set: Chap3 no 7d

Problm Gear up: Chap3 no 7d

8. Prove that the following grammar is ambiguous:
<Southward> ->  <A>
<A> ->  <A>*<A>|<id>
<id> ->   ten|y|z

It is ambiguous because it can has ii distinct parse tree

Problm Set: Chap3 no 8

Problm Set: Chap3 no 8

9. Modify the grammar of Case 3.4 to add together a unary minus operator that has higher precedence than either + or *.

Presume that the unary operators can precede whatsoever operand. Replace the rule
<factor> → <id>
with
<factor> → + <id>
| – <id>

thirteen. Write a grammar for the language consisting of strings that have n copies of the letter a followed past the aforementioned number of copies of the letter b, where n > 0. For example, the strings abb, aabbbb, and aaaabbbbbbbb are in the language only a, aabb, ba, and aaabb are non.

South → a S b b | a b b

14. Draw parse trees for the sentences abb and aabbbb, as derived form the grammar of Trouble thirteen.

Problm Set: Chap3 no 14a

Problm Set: Chap3 no 14a

Problm Set: Chap3 no 14b

Problm Prepare: Chap3 no 14b

16. Catechumen the BNF of Example 3.three to EBNF.
<assign> → <id> = <expr>
<id> → A | B | C
<expr> → <expr> {(+ | *) <expr>}
| <id>

18. What is a fully attributed parse tree?
If all the attribute values in a parse tree have been computed.

oakesbareat.blogspot.com

Source: https://j032.wordpress.com/2013/03/26/concepts-of-programming-languages-chapter-3-answers/

0 Response to "Review of Concepts Answer the Questions Below About Concepts and Vocabulary From Chapter 7"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel