Question

10. Draw and decorate the parse tree for the following Attribute Grammar for the following statement:...

10. Draw and decorate the parse tree for the following Attribute Grammar for the following

statement:

word = 2.0 ∗ (5 − 10)

*** Assign is your STARTING SYMBOL

Assign =: identifier = Expr

Expr =: Expr + Term | Expr - Term | Term

Term =: Term * Factor | Term / Factor | Factor

Factor =: "(" Expr ")" | integer | float | identifier

Assign =: identifier = Expr [ identifier.value <= Expr.value ]

Assign =: identifier = Expr [ identifier.actual_type ==> Expr.expected_type ]

Expr1 =: Expr2 + Term [ Expr1.value = Expr2.value * Term.value ]

Expr1 =: Expr2 + Term [ Expr1.type <==

if (Expr2.type == Term.type == integer) then integer else float ]

Expr1 =: Expr2 - Term [ Expr1.value = Expr2.value + Term.value ]

Expr1 =: Expr2 - Term [ Expr1.type <==

if (Expr2.type == Term.type == integer) then integer else float ]

Expr =: Term [ Expr.value = Term.value ]

Expr =: Term [ Expr.type = Term.type ]

Term1 =: Term2 * Factor [ Term1.value = Term2.value / Factor.value ]

Term1 =: Term2 * Factor [ Term1.type <==

if (Term2.type == Factor.type == integer) - then integer else float ]

Term1 =: Term2 / Factor [ Term1.value = Term2.value Factor.value ]

Term1 =: Term2 / Factor [ Term1.type <==

if (Term2.type == Factor.type == integer) then integer else float ]

Term =: Factor [ Term.value = Factor.value ]

Term =: Factor [ Term.type = Factor.type ]

Factor =: "(" Expr ")" [ Factor.value = Expr.value ]

Factor =: integer [ Factor.value = strToInt(integer.str) ]

Factor =: float [ Factor.value = strToFloat(float.str) ]

Factor =: identifier [ Factor.value = VARMAP(identifier.str) ]

Homework Answers

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1. Given the Grammar <expr> --> <expr> + <term> | <term> <term> --> <term> * <factor>...
1. Given the Grammar <expr> --> <expr> + <term> | <term> <term> --> <term> * <factor> | <factor> <factor> --> ( <expr> ) | number For the given string 3 * ( 2 + 5 * 6), perform the following: 1. Left-most derivation 2. Draw a parse tree 3. Draw an abstract syntax tree Note: number as a terminal has multiple values
Ex#5: Given the following grammar for a simple assignment statements. <assign> --> <id> = <expr> <id>...
Ex#5: Given the following grammar for a simple assignment statements. <assign> --> <id> = <expr> <id> --> A | B | C <exp> --> <id> + <expr> | <id> * <expr> | (<expr>) | <id> Show a leftmost derivation and a parse tree of the following statement: A = A *(B + (C * A))
Given the following grammar and the right sentential form, draw a parse tree and then specify...
Given the following grammar and the right sentential form, draw a parse tree and then specify and write the phrases, simple phrase(s), and the handle. Grammar: S → aAb | bBA A → ab | aAB B → aB | b Sentential form: aaababb
Given the following grammar and the right sentential form, draw a parse tree and then specify...
Given the following grammar and the right sentential form, draw a parse tree and then specify and write the phrases, simple phrase(s), and the handle. Grammar: S → AbB | bAc A → Ab | aBB B → Ac | cBb | c Sentential form: AbcacAbcbccb
1. Given the following multi-way if statement, provide a switch statement, using proper java syntax, that...
1. Given the following multi-way if statement, provide a switch statement, using proper java syntax, that will provide the same function. Char grade; String tstmsg; if (grade == ‘A’) {   tstmsg = “Excellent”; } else if (grade == ‘B’) {   tstmsg = “Good”; } else if (grade == ‘C’) {   tstmsg = “OK”; } else {   tstmsg = “Study More”; } 2.Write the following for statement as a while statement. for (k = 0; k < 3; k++) {   System.out.println...
4. The _____ case is performed by the switch statement if a match is not found...
4. The _____ case is performed by the switch statement if a match is not found default first second otherwise Answer: 5. When three relational expressions are joined by OR (||) operators, there must be at least _____ of the relational expressions that evaluate to true for the logical expression to evaluate to true. one two three none of the relational expressions evaluate to true Answer: 6. Which of the following items is an acceptable first character in a Java...
##4. What will the following program display? ##def main(): ## x = 1 ## y =...
##4. What will the following program display? ##def main(): ## x = 1 ## y = 3.4 ## print(x, y) ## first printing ## change_us(x, y) ## print(x, y) ##second printing ## ##def change_us(a, b): ## a = 0 ## b = 0 ## print(a, b) ## ##main() ## ##Yes, yes, main() displays ##1 3.4 ##0 0 ##1 3.4 ## The question is: why x and y are still the same while the second printing of (x,y)? ## It seems...
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*;...
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*; import javax.swing.*; public class Clicker extends JFrame implements ActionListener {     int count;     JButton button;     Clicker() {         super("Click Me");         button = new JButton(String.valueOf(count));         add(button);         button.addActionListener(this);         setSize(200,100);         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         setVisible(true);     }     public void actionPerformed(ActionEvent e) {         count++;         button.setText(String.valueOf(count));     }     public static void main(String[] args) { new Clicker(); } } a. add(button);...
Leave comments on code describing what does what Objectives: 1. To introduce pointer variables and their...
Leave comments on code describing what does what Objectives: 1. To introduce pointer variables and their relationship with arrays 2. To introduce the dereferencing operator 3. To introduce the concept of dynamic memory allocation A distinction must always be made between a memory location’s address and the data stored at that location. In this lab, we will look at addresses of variables and at special variables, called pointers, which hold these addresses. The address of a variable is given by...
Forecasting and Estimating Share Value Using the DCF Model Following are the income statement and balance...
Forecasting and Estimating Share Value Using the DCF Model Following are the income statement and balance sheet for Intel Corporation. INTEL CORPORATION Consolidated Statements of Income Year Ended (In millions) Dec. 25, 2010 Dec. 26, 2009 Dec. 27, 2008 Net revenue $ 43,623 $ 35,127 $ 37,586 Cost of sales 15,132 15,566 16,742 Gross margin 28,491 19,561 20,844 Research and development 6,576 5,653 5,722 Marketing, general and administrative 6,309 7,931 5,452 Restructuring and asset impairment charges -- 231 710 Amortization...