Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please complete 1A, 1B, 1C. Will rate positively if all complete/correct. 1A. Write BNF to define the syntax for the language used to assign an

Please complete 1A, 1B, 1C. Will rate positively if all complete/correct.

image text in transcribedimage text in transcribed

1A. Write BNF to define the syntax for the language used to assign an result to 1 or more s implied by the following examples LET x = 1+2; LET x.xaZ = 0; KassignmentStatement> ::- 1 B. Complete the derivation started below of the sentence x +1*x*-2+3. :i= 1 I 2 I 3 1C (Continuing 1B) Draw the corresponding parse tree Can you "see" in the parse tree that the binary * has higher precedence than the binary + but lower precedence than the unary -? Note A parse tree is a "picture" of the derivation of a sentential form with (1) the grammar's goal symbol as the root of the parse tree and (2) the symbols of the right-hand side of the non-terminal's production rule as the children of the non-terminal node-a terminal node is a leaf of the parse tree. Hints The following two extracts were taken from an old version of a text book, Concepts of Programming Languages (10th edition) by Robert Sebesta. When you compare the two grammars, you will find that our BNF uses f... )* metasymbology to "provide" for unlimited repetition while the grammar shown in Sebesta's text book uses recursion. Interesting, isn't it, how iteration and recursion are equally-powerful grammatical tools!? 4.5.1 The Parsing Problem for Bottom-Up Parsers Consider the following grammar for arithmetic expressions: E E+TIT F(E) id Notice that this grammar generates the same arithmetic expressions as the example in Section 4.4. The difference is that this grammar is left recursive, which is acceptable to bottom-up parsers. Also note that grammars for bottom up parsers normally do not include metasymbols such as those used to specify extensions to BNE. The following rightmost derivation illustrates this grammar: => E + T * id ->Ed id > E + id * id =id + id * id Figure 4.3 A parse tree for id 1A. Write BNF to define the syntax for the language used to assign an result to 1 or more s implied by the following examples LET x = 1+2; LET x.xaZ = 0; KassignmentStatement> ::- 1 B. Complete the derivation started below of the sentence x +1*x*-2+3. :i= 1 I 2 I 3 1C (Continuing 1B) Draw the corresponding parse tree Can you "see" in the parse tree that the binary * has higher precedence than the binary + but lower precedence than the unary -? Note A parse tree is a "picture" of the derivation of a sentential form with (1) the grammar's goal symbol as the root of the parse tree and (2) the symbols of the right-hand side of the non-terminal's production rule as the children of the non-terminal node-a terminal node is a leaf of the parse tree. Hints The following two extracts were taken from an old version of a text book, Concepts of Programming Languages (10th edition) by Robert Sebesta. When you compare the two grammars, you will find that our BNF uses f... )* metasymbology to "provide" for unlimited repetition while the grammar shown in Sebesta's text book uses recursion. Interesting, isn't it, how iteration and recursion are equally-powerful grammatical tools!? 4.5.1 The Parsing Problem for Bottom-Up Parsers Consider the following grammar for arithmetic expressions: E E+TIT F(E) id Notice that this grammar generates the same arithmetic expressions as the example in Section 4.4. The difference is that this grammar is left recursive, which is acceptable to bottom-up parsers. Also note that grammars for bottom up parsers normally do not include metasymbols such as those used to specify extensions to BNE. The following rightmost derivation illustrates this grammar: => E + T * id ->Ed id > E + id * id =id + id * id Figure 4.3 A parse tree for id

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions