Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3. (10 points) Either prove or disprove the ambiguity of the following grammar. SA AA+A id id a b c 4. (10 points) Rewrite the

image text in transcribedimage text in transcribedimage text in transcribed

3. (10 points) Either prove or disprove the ambiguity of the following grammar. SA AA+A id id a b c 4. (10 points) Rewrite the following grammar to add the ++ and -- unary operators of Java. assignid=expr id > A | B | C exprexpr+ term factor factor (expr) id 5. (10 points) Using the grammar of Problem 4 above, show a parse tree and a leftmost derivation for the following statement. A=A(B+C) 6. (10 points) Convert the following EBNF to BNF: SA{bA} A a [b]A 7. (10 points) Explain briefly the following terms, or concepts, of the attribute grammar. - attributes - attribute computation functions (also called semantic functions) - predicate functions 8. (15 points) In the Dart programming language (https://dart.dev/), a function has a list of formal parameters (though the parameter list 7. (10 points) Explain briefly the following terms, or concepts, of the attribute grammar. - attributes - attribute computation functions (also called semantic functions) - predicate functions 8. (15 points) In the Dart programming language (https://dart.dev/), a function has a list of formal parameters (though the parameter list may be empty), and the parameters are either "positional" or "named". Positional parameters may be "required" or "optional". All named parameters are optional. zero (); // function with no parameter () identity (x)x; // one required, positional parameter ( x ) add (a,b)a+b;// two required, positional parameters (a,b) increment (x,[ step =1])x+ step; //x is required but step is optional and default to 1 , e.g., // increment (10), increment (10,2) incr ({ value, step: 1})x+ step; // two named (optional) parameters with step defaults to 1 , e.g., // incr(), incr(value: ), incr(step: 2), incr(value:10, step:2) incr (x,{ step: 1})x+ step; //x is positional (required) and step is named (optional) The default value of a positional parameter is specified with = (e.g., x= ) and that of a named parameter is specified with : (e.g., step: 1). A parameter type is optional, e.g., (x) instead of (int x ). A parameter list cannot have both optional (positional) parameters and named parameters, e.g., incr ([x],{ step }). Define the syntax of the formal parameters of a Dart function. You may assume that there are suitable definitions of non-terminals expr (for the default value of a parameter) and (for a parameter name). Assume a few types such as boolean, int, and float for parameter types. Define the syntax of the formal parameters of a Dart function. You may assume that there are suitable definitions of non-terminals a parameter name). Assume a few types such as boolean, int, and float for parameter types. 9. (total 20 points) You are to define the syntax of BNF itself. (a) (10 points) Write a BNF grammar describing the syntax of BNF; i.e., define the syntax of BNF itself using BNF. Use a pair of single quotes to use meta symbols like | and as terminal symbols, e.g., '|' and '->'. You may assume that non-terminals such as and special-symbol> are already defined. (b) (5 points) Is the following a sentence of the language you defined in (a) above? Justify your answer by stating the reason. exprexpr+ term term term >5 (c) (5 points) Based on your answer to (a) above, draw a parse tree of the following sentence. exprexproprexpr 0pr+1 10. (10 bonus points) Write a grammar for the language consisting of strings that have n copies of the letter ' a ' followed by m copies of the letter ' b ', where n and m are any prime numbers. For example, aabb, aabbb, and aaaaabbb are in the language but a,b, ab, and aabbbb, and aaabbbb are not. (Hint: use attribute grammars) 11. (10 bonus points) Use Perl6 (https://per16.org/) grammar facility to check the BNF grammar of Problem 9 above. Show a corresponding Perl6 grammar along with sample outputs

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

More Books

Students also viewed these Databases questions

Question

e. What do you know about your ethnic background?

Answered: 1 week ago

Question

b. Why were these values considered important?

Answered: 1 week ago