Question

1. Given the following context-free grammar (start variable is S), draw the parse tree of string "abaabb". (if you wish to upload an image, please do so by inserting an image in the text-box given to you by Canvas Discussion environment). $ \to aSb|bSa|SS|ab|ba$ 2. Describe an interesting property of strings generated by the CFG mentioned in part 1. 3. Assuming that 12 and 43 are two number tokens and sum is a valid identifier, draw the parse tree for the following statement given the following BNF grammar: "sum = 43 * sum + 12;" <program> $\to$ <stmts> <stmts> $\to$ <stmt> | <stmt> <stmts> <stmt> $\to$ <var> = <expr>; <var> $\to$ identifier <expr> $\to$ number | identifier | <expr> + <expr> | <expr> * <expr> 4. Try drawing another parse tree for part 3.

          1. Given the following context-free grammar (start variable is S), draw the parse tree of string "abaabb". (if you wish to upload an image, please do so by inserting an image in the text-box given to you by Canvas Discussion environment).
$ \to aSb|bSa|SS|ab|ba$
2. Describe an interesting property of strings generated by the CFG mentioned in part 1.
3. Assuming that 12 and 43 are two number tokens and sum is a valid identifier, draw the parse tree for the following statement given the following BNF grammar: "sum = 43 * sum + 12;"
<program> $\to$ <stmts>
<stmts> $\to$ <stmt> | <stmt> <stmts>
<stmt> $\to$ <var> = <expr>;
<var> $\to$ identifier
<expr> $\to$ number | identifier | <expr> + <expr> | <expr> * <expr>
4. Try drawing another parse tree for part 3.
        
Show more…
1. Given the following context-free grammar (start variable is S), draw the parse tree of string "abaabb". (if you wish to upload an image, please do so by inserting an image in the text-box given to you by Canvas Discussion environment).
→ aSb|bSa|SS|ab|ba
2. Describe an interesting property of strings generated by the CFG mentioned in part 1.
3. Assuming that 12 and 43 are two number tokens and sum is a valid identifier, draw the parse tree for the following statement given the following BNF grammar: "sum = 43 * sum + 12;"
<program> → <stmts>
<stmts> → <stmt> | <stmt> <stmts>
<stmt> → <var> = <expr>;
<var> → identifier
<expr> → number | identifier | <expr> + <expr> | <expr> * <expr>
4. Try drawing another parse tree for part 3.

Added by Erica M.

Close

Computer Science and Information Technology
Computer Science and Information Technology
Trishna Knowledge Systems 2018 Edition
AceChat toggle button
Close icon
Ace pointing down

Please give Ace some feedback

Your feedback will help us improve your experience

Thumb up icon Thumb down icon
Thanks for your feedback!
Profile picture
Given the following context-free grammar (start variable is S), draw the parse tree of string "abaabb". (if you wish to upload an image, please do so by inserting an image in the text-box given to you by Canvas Discussion environment). S->aSb|bSa|SS|ab|ba 2. Describe an interesting property of strings generated by the CFG mentioned in part 1. 3. Assuming that 12 and 43 are two number tokens and sum is a valid identifier, draw the parse tree for the following statement given the following BNF grammar: sum=43sum+12; <program>-><stmts> <stmts>-><stmt><stmt><stmts> <stmt>-><var>=<expr>; <var>->identifier <expr>->number|identifier|<expr>+<expr>|<expr>*<expr> 4. Try drawing another parse tree for part 3.
Close icon
Play audio
Feedback
Powered by NumerAI
Kathleen Carty David Collins
Jennifer Stoner verified

Chris Trentman and 52 other subject AP CS educators are ready to help you.

Ask a new question

*

Labs

-

Want to see this concept in action?

NEW

Explore this concept interactively to see how it behaves as you change inputs.

View Labs

*

Key Concepts

-
Key Concept
Premium Feature
Explore the core concept behind this problem.
Play button
Key Concept
Premium Feature
Explore the core concept behind this problem.
Your browser does not support the video tag.

*

Recommended Videos

-
a-construct-a-phrase-structure-grammar-that-generates-all-signed-decimal-numbers-consisting-of-a-sig

a) Construct a phrase-structure grammar that generates all signed decimal numbers, consisting of a sign, either $+$ or $-;$ a nonnegative integer; and a decimal fraction that is either the empty string or a decimal point followed by a positive integer, where initial zeros in an integer are allowed. b) Give the Backus-Naur form of this grammar. c) Construct a derivation tree for $-31.4$ in this grammar.

Discrete Mathematics and its Applications

Modeling Computation

Languages and Grammars

find-a-grammar-that-recognizes-the-following-language-words-that-are-the-concatenation-of-two-words-of-odd-length-with-the-same-middle-symbol-solve-description-to-grammar-problem-problem-fin-54943

Solve Description to Grammar problem Problem Find a grammar that recognizes the following language: words that are the concatenation of two words of odd length with the same middle symbol (e.g., abbaabab, as this is the concatenation of abb and aabab, two words with b as middle letter). HELP: Grammar Syntax Grammar: 1 production per line start nonterminal: left-hand side of first production Productions: form: S -> X Y | a S b | eps left-hand side: a single nonterminal right-hand side: groups of nonterminals and terminals separated by "|" Nonterminals: form: one single upper case character A-Z Terminals: allowed: abcdefghijklmnopqrstuvwxyz()[]{} Empty word: empty word: ε (write epsilon or eps or e)

Aarya B.

list-list-digit-list-list-digit-list-digit-digit-0123456789-1-use-the-grammar-above-follow-derivation-on-chapter-2-slide-15-to-apply-the-production-to-following-expression-3-19-42-39-2-how-t-62793

Text: list -> list + digit list -> list - digit list -> digit digit -> 0|1|2|3|4|5|6|7|8|9 1. Use the grammar above, follow derivation on chapter 2 slide 15 to apply the production to the following expression 3-1+9, 4+2-3+9 2. How to modify the grammar above to right associative? Use the modified grammar to draw the parse tree for 4+2-3+9 3. Use the grammar on compiler design slide 25 to draw the parse tree for 3-2*8+5/3, and 3-2*(4+7)/5 4. Transform the following expressions to postfix notation (4+2-9)/3+7*4, ((2+8/3)+4)*3-9 5. Use the Syntax-directed definition on compiler design slide 36 to translate (4+2-9)/3+7*4 to postfix notation. Show the parse tree with synthesized attributes

Akash M.


*

Recommended Textbooks

-
Computer Science and Information Technology

Computer Science and Information Technology

Trishna Knowledge Systems 2018 Edition
achievement 1,115 solutions
Introduction to Programming Using Python

Introduction to Programming Using Python

Y. Daniel Liang 1st Edition
achievement 1,917 solutions
Computer Science - An Overview

Computer Science - An Overview

Glenn Brookshear, Dennis Brylow 12th Edition
achievement 1,549 solutions

*

Transcript

-
00:01 We're asked to construct a phrase structure grammar that generates all signed decimal numbers consisting of a sign either plus or minus, a non -negative integer, and the decimal fraction that is either the empty string or a decimal point followed by a positive integer, where initial zeros in an integer are allowed.
00:31 So this is actually pretty straightforward.
00:40 We have that from our start symbol s will produce sign followed by integer.
01:01 From our start symbol s, we could also produce sine integer.
01:12 So bracket, sign, bracket integer, and then a decimal point followed by bracket positive integer.
01:26 Now for sign, we have that bracket sign produces plus or bracket sign produces minus.
02:00 For integer, we have bracket integer produces bracket integer, bracket digit, i guess bracket digit, bracket digit.
02:23 We have that it can also produce bracket integer, can produce bracket digit.
02:44 In case our integer is only one digit.
02:57 Now, for a positive integer, we have bracket positive integer.
03:18 This can produce, i think here to keep continuity.
03:22 I'll actually change some things around.
03:24 So before we add integer, bracket integer produces digit integer.
03:29 Inside we have, let's do bracket integer produces integer digit.
03:33 We'll see why in just a second.
03:42 So bracket positive integer produces integer followed by 9.
03:52 0 digit followed by integer.
04:13 We also have the positive integer produces in the case that we just end with a non -zero digit integer followed by non -zero digit and finally when we have the two other cases positive integer produces non -zero digit followed by integer and finally we have positive integer produces a non -zero digit this is in the case that our decimal only has one digit after the decimal point.
05:59 Now we know that digit can produce a non -zero digit, although it won't always, because in the other case, we have a digit will be producing a zero.
06:18 And this is a terminal symbol.
06:22 And we know that non -zero digits are obviously going to produce digits 1 through 9.
06:27 So non -zero digit produces one, non -zero digit, produces a 2 and here i'm just going to skip instead of writing all these non -zero digit produces a 9 so 1 through 9 and so this is going to be the grammar for part a now in part b we're asked to give the bacchus naur form of this grammar this is pretty easy to do all we have to do is combine productions from the previous answer that all have the same left -hand side and we'll change the notation.
07:32 So for example, starting off with signed decimal number, well we saw earlier that this produced, this was really our start state s, this produced sign integer on the one hand, or sorry, sine integer.
08:36 Of course, i could also produce sign, bracket, integer, decimal point, bracket, positive number, or positive integer.
09:03 And that vertical line just means that either outcome gives a possible production.
09:10 Now for sign, you see bracket, sign has two columns, followed by an equals sign, and then sign can be plus, or can be minus.
09:23 We have the vertical line, and then we have a minus.
09:30 So for integer, see the integer produces either integer digit or produces digit...
Need help? Use Ace
Ace is your personal tutor. It breaks down any question with clear steps so you can learn.
Start Using Ace
Ace is your personal tutor for learning
Step-by-step explanations
Instant summaries
Summarize YouTube videos
Understand textbook images or PDFs
Study tools like quizzes and flashcards
Listen to your notes as a podcast
Continue solving this problem
Create a free account to:
  • View full step-by-step solution
  • Ask follow-up questions with Ace AI
  • Save progress and study later
Continue Free
Numerade

Get step-by-step video solution
from top educators

Continue with Clever
or



By creating an account, you agree to the Terms of Service and Privacy Policy
Already have an account? Log In

A free answer
just for you

Watch the video solution with this free unlock.

Numerade

Log in to watch this video
...and 100,000,000 more!


EMAIL

PASSWORD

OR
Continue with Clever