Question

1. In a language, each sentence is a string starting with a capital letter followed by...

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:

1) The types of variables in an expression do not have to be the same. The type of the expression result is that of the first (or leftmost) variable in the expression.

2) If the type of variable to be assigned is integer, the type of the expression must be integer.

3) If the type of variable to be assigned is float, the type of the expression can be integer or float.

<assign> -> <var> = <expr>

<expr> -> <var> + <var>

<expr> -> <var> - <var>

<expr> -> <var>

<var> -> A | B | C

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

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.

ans:-

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:

1) The types of variables in an expression do not have to be the same. The type of the expression result is that of the first (or leftmost) variable in the expression.

2) If the type of variable to be assigned is integer, the type of the expression must be integer.

3) If the type of variable to be assigned is float, the type of the expression can be integer or float.

<assign> -> <var> = <expr>

<expr> -> <var> + <var>

<expr> -> <var> - <var>

<expr> -> <var>

<var> -> A | B | C

ans:

Add a comment
Know the answer?
Add Answer to:
1. In a language, each sentence is a string starting with a capital letter followed by...
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
  • Augment the following BNF to write an attribute grammar. Assume the only possible variable types are...

    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: 1) The types of variables in an expression do not have to be the same. The type of the expression result is that of the first (or leftmost) variable in the expression. 2) If the type of variable to be assigned is integer, the type of the expression must be integer. 3) If the type...

  • (8) (3 marks) Write BNF grammar rules for a language that is comprised only of sentences described as follows: symbol,...

    (8) (3 marks) Write BNF grammar rules for a language that is comprised only of sentences described as follows: symbol, fol symbols orjust onéx symbol, A sequence of one or more occurrences of an a lowed by either zero or morez followed by a sequence of one or more b symbols. (9) (1 mark) The following fragment of grammar describes the syntax of the exponentiation operator. What is the associativity ot the operator as detined here? factor | expr factor...

  • (20 pts) To understand the value of recursion in a programming language: implement the binary search...

    (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...

  • 1. Which of the following statements is true? A. When an input string is being applied...

    1. Which of the following statements is true? A. When an input string is being applied with a set of grammar rules, there is one of derivation. B. Based on a different parse tree, an input string may end up with several different derivations if no precedence or associativity rules are applied. C. Parse tree is done in the lexical analysis stage. D. Grammar design is very forgiving. You may write in whatever style you wish. 2. Modern computers are...

  • Write a parser program for cSub using the method of recursive descent. The main program here...

    Write a parser program for cSub using the method of recursive descent. The main program here will effectively be the main program of the compiler as a whole. The input to the program will be a Csub source file, specified on the command line. The program will construct a parse tree for the program, with one interior node for every nonterminal in the derivation of the program, and one leaf node for each of the id, num, and real tokens...

  • 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...

  • 1. Construct a DFSM to accept the language: L w E ab): w contains at least 3 as and no more than 3 bs) 2. Let E (acgt a...

    1. Construct a DFSM to accept the language: L w E ab): w contains at least 3 as and no more than 3 bs) 2. Let E (acgt and let L be the language of strings consisting of repeated copies of the pairs at, ta, cg. ge. Construct both a DFSM to accept the language and a regular expression that represents the language. 3. Let ab. For a string w E , let w denote the string w with the...

  • Please help me with the coding for LL(1)!! The given grammar was: P → PL |...

    Please help me with the coding for LL(1)!! The given grammar was: P → PL | L L → N; | M; | C N → print E M → print "W" W → TW | ε C → if E {P} | if E {P} else {P} E → (EOE) | V (note: this has a variable O) O → + | - | * V → 0 | 1 | 2 | 3 (note: this has a terminal...

  • 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....

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