Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Automata & Computation Expert

Assignment :

Exercise 1: Consider the context-free grammar:

5 → SS + \ss* \ a

and the string aa + a*.

a) Give a leftmost derivation for the string.

b) Give a rightmost derivation for the string.

c) Give a parse tree for the string.

d) Is the grammar ambiguous or unambiguous? Justify your answer.

e) Describe the language generated by this grammar.

Exercise 2: Repeat Exercise 1 for each of the following grammars and strings:

a) S     0 5 1 1 0 1 with string 000111.

Exercise 3: Design grammars for the following languages:

a) The set of all strings of 0s and 1s such that every 0 is immediately followed by at least one 1.

b) The set of all strings of 0s and 1s that are palindromes; that is, the string reads the same backward as forward.

c) The set of all strings of 0s and 1s with an equal number of 0s and 1s.

Exercise 4: The following is a grammar for regular expressions over symbols a and b only, using + in place of I for union, to avoid conflict with the use of vertical bar as a metasymbol in grammars:

rexpr        rexpr + rterm | rterm

rterm        rterm rfactor  \ rfactor

rfactor      rfactor * / rprimary

rprimary    a|b

a) Left factor this grammar.

b) Does left factoring make the grammar suitable for top-down parsing?

c) In addition to left factoring, eliminate left recursion from the original grammar.

d) Is the resulting grammar suitable for top-down parsing?

Programming Assignment:

A moderately simple Scheme (MSS) expression is similar to those of our previous language VSS, but supports the Boolean type in addition to the floating-point type. This includes the literals true and false, in addition to Boolean and relational operators. There is also a conditional if expression. Here is the grammar:

Prog         →   expr+

expr         →   DOUBLE
               |    BOOLEAN
               |    ID
               |   '(' RATOR expr* ')'
               |   '("def ID expr ')'
               |   '("if expri exprz exprj
BOOLEAN  →   'true' | 'false'
RATOR     →   ARITHMETIC I RELATIONAL I BOOLEAN
ARITHMETIC → '+' | '-' | '*' + '/'
RELATIONAL → '=' |'>'|'<'
BOOLEAN     → '&' |'|' |'!'

The conditional expression first evaluates its first expression expr1 to obtain testVal. If testVal is true then the conditional expression evaluates to the value of expr2, and if testVal is false then it evaluates to the value of expr J (it is a semantic error if expri is not of Boolean type).

You may wish to distinguish between Boolean and floating-point values when evaluating expressions to ensure semantic correctness, but I do not require such runtime error checking. It is also not required that you distinguish between Boolean and floating-point expressions in your grammar (e.g., your grammar need not enforce that the conditional's test expression is of type Boolean). Also, it's not required that you implement the Boolean operators (and, or, and not), but you should implement the relational operators (equal, greater-than, and less-than).

I suggest that you revise the representation of values in your interpreter. One way is to define a Val class capable of wrapping a Double or a Boolean value. Your symbol table, which stores variable bindings, would bind identifiers to Val objects, literals and variables would evaluate to Val objects, and operators would input a list of Val arguments and output a Val object.

As in the previous assignment (VSS language), your interpreter evaluates the top-level expressions in order and prints the value of the last expression. For programs that contain more than one top-level expression, all but the last one are generally there for side-effect. Here are some sample runs:

> java run
(def a (if (< 5 7) 2 4))
(* a 6)
^Z
12.0

> java run

(def flag (= 6 (+ 3 5)))
(if flag (+ 1 2) (* 3 4))
^Z
12.0

This illustrates semantics involving the Boolean type:

true => true
(! true) => false
(&) => true // identity for and
(& true) => true
(& true false) => false
(|) => false // identity for or
(| false) => false
(> 7) true // each element is > than its successor
(> 7 5) =>. true
(> 7 5 2) =>. true
(> 7 8 5 3) => false
(< 4 6) =>, true
(= 4 (+ 2 2)) =>, true
(= 3 3 7) => false
(!(< (+ 2 2) (* 2 3))) => false
(if true 3 4)              => 3.0
(if (< 6 3) 5 (* 6 3))  => 18.0
(if (= 3 (+ 2 1))
(if true 4 5)

(if false 6 7)) => 4.0

Automata & Computation, Computer Science

  • Category:- Automata & Computation
  • Reference No.:- M91848616
  • Price:- $90

Priced at Now at $90, Verified Solution

Have any Question?


Related Questions in Automata & Computation

Question - design a state machine that will control a

Question - Design a state machine that will control a vending machine. The vending machine has 4 inputs, N, D indicating a nickel or dime was inserted as well as clk and an active high asynchronous reset. The vending mac ...

Prove or disprove the following proposed inference rules

Prove or disprove the following proposed inference rules for functional dependencies. A proof should be made by using the reflexive, augmentation, transitive, decomposition, union, and pseudotransitive rules. A disproof ...

Iot and data analytics1 analyse the taskanalyse what is

IOT and data analytics 1. Analyse the Task Analyse what is expected of you. This includes careful reading of the assignment task as specified in the Subject Outline. The executive summary of the research project is to be ...

Regular expressions automatacomputabilitytheory of

Regular expressions, automata/computability/theory of computation How would I go about interpreting regular expressions? For example, how would I interpret the following in English: (0+1)*011 0*1*2* 0^(+)1^(+)2^(+)

Question 1a digital computer has a memory unit with 16 bits

Question 1: A digital computer has a memory unit with 16 bits per word. The instruction set consists of 122 different operations. All instructions have an operation code part (opcode) and an address part (allowing for on ...

Prove or disprove the following proposed inference rules

Prove or disprove the following proposed inference rules for functional dependencies. A proof should be made by using the reflexive, augmentation, transitive, decomposition, union, and pseudotransitive rules. A disproof ...

Question - design a task or function that will check the

Question - Design a task or function that will check the parity of a word for odd parity. The input to the task/function is a 5-bit word called data_in. If the parity of input data_in is not odd increment an error count ...

Question 1hoare logic semantics for each of the parts below

Question 1 Hoare Logic Semantics For each of the parts below, justify your answer briefly. 1. For which programs S does {False} S {True} hold? 2. For which programs S does {True} S {False} hold? 3. For which programs S d ...

Models of computation assignment -purpose - to improve and

Models of Computation Assignment - Purpose - To improve and consolidate your understanding of regular and context-free languages, finite-state and pushdown automata. To develop skills in analysis and formal reasoning abo ...

Solve the question given belowprove the following statement

Solve the question given below Prove the following statement using Hall's Theorem. For any bipartite graph G=(U, V, E), if every node (either a left node or a right node) has exactly d neighbors, where d is an arbitrary ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As