Concepts of Programming language
Convert the following BNF to EBNF
<STMT_LIST> -> <stmt> | <stmt>; <stmt_list>
<stmt> -> <var> = <expr>
<var> -> A | B | C
<EXPR> -> <var> + <var> | <var> - <var> | <var>
STMT_LIST, '->', stmt, '|', stmt, ';'stmt_list;
stmt, '->', var = expr
var, '->', A, '|', B, '|', C
EXPR, '->', var, '+', var, '|', var, '-', var, '|', var
Concepts of Programming language Convert the following BNF to EBNF <STMT_LIST> -> <stmt> | <stmt>; <stmt_list>...
Q3. Convert the following recursive BNF grammar to EBNF: (20%) <assign>-> <id> = <expr> <expr> -> <d>+ <expr> | <id> * <expr> 1 (<expr>) | <i>
Given a CFG in BNF, (50 points) <stmt_list> → <stmt> | <stmt>; <stmt_list> <stmt> → <var> = <expr> <expr> → <var> + <expr> | <var> * <expr> | <var> <var> →a| b| c| d show a derivation for the given sentence a = b*c - d; b = d - a 2. show a parsing tree for a = b*c - d; b = d - a
P2) Given grammar in BNF, answer the following questions (30 points) <stmt-list>→<stmt> | <stmt»; <stmt-list> (a) Rewrite the given grammar into a EBNF (b) Is the given grammar ambiguous? Support your answer to receive the full credit. (c) Given string A-B C-D: B-C-A-D, draw a parsing tree P2) Given grammar in BNF, answer the following questions (30 points) → |
(20 pts) To understand the value of recursion in a programming language: implement the binary search algorithm first as a recursive function and again using a conditional loop. Your program should create an array of characters holding the letters ‘A’ – ‘Z’ and find the index in the array where the letter ‘K’ is stored. You may use any programming language that supports recursion. (5pts) Define syntax and semantics and give an example. (5pts) Why is it important for a...
Design a language description for which a BNF/EBNF based grammar cannot be written. Prove that the grammar cannot be written for the description.
Question 9 (10 points) Consider the following EBNF grammar for a "Calculator Language": <calculation> <expr> = <expr> > <term> (+1-) <expr> <term <term> <factor> (* ) <term> <factor> <factor> > (<expr>) value> <value> → [<sign> ] <unsigned [. <unsigned> ] <unsigned> <digit> { <digit> } <digit → 011121314151617189 <sign → + - which of the following sentences is in the language generated by this grammar? Whx.2 a. 3/+2.5 = b. 5- *3/4= c. (3/-2) + 3 = d. 5++3 =
Question 9 (10 points) Consider the following EBNF grammar for a “Calculator Language": <calculation> → <expr>= <expr> <term> (+1-) <expr> <term> <term> <factor> (* ) <term> <factor> <factor> → (<expr>) <value> <value> → [<sign> ] <unsigned> [. <unsigned> ] <unsigned> <digit> { <digit> } <digit> → 01|2|3|4|567| 8 | 9 <sign> → +|- which of the following sentences is in the language generated by this grammar ? Why? a. 3/+2.5 = b. 5-*3/4= c. (3/-2) + 3 = d. 5...
1. In a language, each sentence is a string starting with a capital letter followed by two or more small letters and ending with three or more digits. Example sentences are Abc001, Zyxw9876 etc. a) Write a BNF grammar for the language. b) Show the derivation and the parse tree of the string Test3501. 2. Augment the following BNF to write an attribute grammar. Assume the only possible variable types are integer and float. The language rules are as follows:...
Choose a statement for a programming language of your choice and write a BNF production that defines the syntax of that statement. Clearly distinguish between the terminal and nonterminals symbols. Then write a Java method that will parse that statement using recursive descent. You may assume that a method getNextToken is available to get the next terminal symbol and that there are methods available to parse each of the nonterminals.
Please answer the questions below: 7. Rewrite the following BNF grammar using the form of EBNF described on the bottom half of page 127 in Sebesta. <import_decl> → import <import_list> ; <import_list> → <package_list> | <package_list> . * <package_list> → <identifier> | <package_list> . <identifier> <identifier> → a | b | c Make the resulting grammar as simple as possible, but keep all four of the original nonterminals, which will now be named ImportDecl, ImportList, PackageList, and Identifier. (Note: There...