Question

(a) Give an unambiguous CFG for arithmetic expression consisting of the four operations +,-,*,/ and a...

(a) Give an unambiguous CFG for arithmetic expression consisting of the four operations +,-,*,/ and a start symbol S and terminal symbols 0,1,2,...9. Assume that *,/ havbe higher precedence than +,-.

(b) Show the leftmost derivation tree of the expression 2 + 3 ∗ 5/6 − 1 using your grammar.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

GRAMMAR

S -> S + A | S - A | A
A -> A * N | A / N | N
N -> 0 | 1 | ... | 9

EXPLANATION

N is for a number
A is for * and / having higher precedence
S is for + and - having lower precedence

Left Most Derivation

Please up vote

Add a comment
Know the answer?
Add Answer to:
(a) Give an unambiguous CFG for arithmetic expression consisting of the four operations +,-,*,/ and a...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1.)    Consider the following grammar in which S, A, and B are nonterminal symbols and S...

    1.)    Consider the following grammar in which S, A, and B are nonterminal symbols and S is the start symbol. S → 1A | 0B A → A0 | 1B B → 10A| 1 Show that the grammar is ambiguous by showing two parse trees for the sentence 1110110 using leftmost derivation.

  • 3 points) Question Three Consider the context-free grammar S >SS+1 SS 1a and the string aa...

    3 points) Question Three Consider the context-free grammar S >SS+1 SS 1a and the string aa Give a leftmost derivation for the string. 3 points) (4 poiots) (5 points) (3 points) sECTION IWOLAttcmpt.any 3.(or 2) questions from this.scction Suppose we have two tokens: (1) the keyword if, and (2) id-entifiers, which are strings of letters other than if. Show the DFA for these tokens. Give a nightmost derivation for the string. Give a parse tree for the string i) Is...

  • The questions in this section are based on the grammar given as the following: prog ->...

    The questions in this section are based on the grammar given as the following: prog -> assign | expr assign -> id = expr expr -> expr + term | expr - term | term term -> factor | factor * term factor -> ( expr ) | id | num id -> A | B | C num -> 0 | 1 | 2 | 3 (2a) What is the associativity of the * operator? (5 points) (2b) What...

  • The questions in this section are based on the grammar given as the following: prog ->...

    The questions in this section are based on the grammar given as the following: prog -> assign | expr assign -> id = expr expr -> expr + term | expr - term | term term -> factor | factor * term factor -> ( expr ) | id | num id -> A | B | C num -> 0 | 1 | 2 | 3 (2a) What is the associativity of the * operator? (5 points) (2b) What...

  • Give a CFG that generates the language L(a*b*c*) \ { anbncn | n is a non-negative integer }. This...

    Give a CFG that generates the language L(a*b*c*) \ { anbncn | n is a non-negative integer }. This question is quite challenging; you will first need to devise a good strategy for how the CFG should work and then create the CFG to implement the strategy. You might want to do the other questions first. I'm so stuck on this question, can someone pls help me? The following questions ask you to write CFGs. An example illustrates the encoding...

  • I need help with the following problems, any help you can provide is deeply appreciated! CSC...

    I need help with the following problems, any help you can provide is deeply appreciated! CSC 404 Exam 1 Question I continued - 9. The syntax rules for most languages ignore spaces. An exception is which tises indents and therefore spaces to form the indents) to group statements (a) FORTRAN (6) Pascal (e) Python (d) Lip (e) C++ 10. Identifiers, constants and operators are typical examples of (a) tokens. (b) leafons. (c) signifiers. (d) lexicons. (e) parsicles. 0) non-terminals. 11....

  • Please use the JAVA code attached as an input to the program that must be created IN JAVA. Instru...

    Please use the JAVA code attached as an input to the program that must be created IN JAVA. Instructions of the program: java code: /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * */ import java.util.Random; public class Rand_Z3_Exp { /** * @param args the command line arguments */ public static void main(String[] args) {...

  • Please use the JAVA code attached as an input to the program that must be created...

    Please use the JAVA code attached as an input to the program that must be created IN JAVA. Instructions of the program: java code: /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * */ import java.util.Random; public class Rand_Z3_Exp { /** * @param args the command line arguments */ public static void main(String[] args) {...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT