Question

In: Computer Science

This is for a Theoretical Foundations of Computer Science course: 1)Show that every LL(1)-language is indeed...

This is for a Theoretical Foundations of Computer Science course:

1)Show that every LL(1)-language is indeed a q-language.

2)Discuss the differences between pushdown automata and top-down parsers. Can parsers be made into pushdown automata?

Solutions

Expert Solution

1)

Any grammar that is LL(1) defines an LL(1) language. By definition, a language is LL(1) if there is some grammar that generates it that is LL(1), so the fact that you have an LL(1) grammar for the language automatically means that the language is LL(1).

To elaborate, a language is a set of strings and a grammar for that language is a means of describing that language. Some languages have LL(1) grammars while others do not. However, the fact that a grammar is not LL(1) does not mean that the language it describes is not. For example, consider this grammar:

A -> ab | ac

This grammar is not LL(1) because it contains a FIRST/FIRST conflict when trying to predict the production for A when seeing terminal a. However, it describes an LL(1) language, since the language is also described by the grammar

A -> aX
X -> b | c

So the language generated by these grammars (which just contains ab and ac) is indeed LL(1).

2) Pushdown Automata & Parsing. Parsing is used to derive a string using the production rules of a grammar. It is used to check the acceptability of a string. ... Top-Down Parser − Top-down parsing starts from the top with the start-symbol and derives a string using a parse tree.

A parser can be of two types −

  • Top-Down Parser − Top-down parsing starts from the top with the start-symbol and derives a string using a parse tree.

  • Bottom-Up Parser − Bottom-up parsing starts from the bottom with the string and comes to the start symbol using a parse tree.

Design of Top-Down Parser

For top-down parsing, a PDA has the following four types of transitions −

  • Pop the non-terminal on the left hand side of the production at the top of the stack and push its right-hand side string.

  • If the top symbol of the stack matches with the input symbol being read, pop it.

  • Push the start symbol ‘S’ into the stack.

  • If the input string is fully read and the stack is empty, go to the final state ‘F’.

Example

Design a top-down parser for the expression "x+y*z" for the grammar G with the following production rules −

P: S → S+X | X, X → X*Y | Y, Y → (S) | id

Solution

If the PDA is (Q, ∑, S, δ, q0, I, F), then the top-down parsing is −

(x+y*z, I) ⊢(x +y*z, SI) ⊢ (x+y*z, S+XI) ⊢(x+y*z, X+XI)

⊢(x+y*z, Y+X I) ⊢(x+y*z, x+XI) ⊢(+y*z, +XI) ⊢ (y*z, XI)

⊢(y*z, X*YI) ⊢(y*z, y*YI) ⊢(*z,*YI) ⊢(z, YI) ⊢(z, zI) ⊢(ε, I)

Design of a Bottom-Up Parser

For bottom-up parsing, a PDA has the following four types of transitions −

  • Push the current input symbol into the stack.

  • Replace the right-hand side of a production at the top of the stack with its left-hand side.

  • If the top of the stack element matches with the current input symbol, pop it.

  • If the input string is fully read and only if the start symbol ‘S’ remains in the stack, pop it and go to the final state ‘F’.

Example

Design a top-down parser for the expression "x+y*z" for the grammar G with the following production rules −

P: S → S+X | X, X → X*Y | Y, Y → (S) | id

Solution

If the PDA is (Q, ∑, S, δ, q0, I, F), then the bottom-up parsing is −

(x+y*z, I) ⊢ (+y*z, xI) ⊢ (+y*z, YI) ⊢ (+y*z, XI) ⊢ (+y*z, SI)

⊢(y*z, +SI) ⊢ (*z, y+SI) ⊢ (*z, Y+SI) ⊢ (*z, X+SI) ⊢ (z, *X+SI)

⊢ (ε, z*X+SI) ⊢ (ε, Y*X+SI) ⊢ (ε, X+SI) ⊢ (ε, SI)

Pushdown automata are used in theories about what can be computed by machines. ... Deterministic pushdown automata can recognize all deterministic context-free languages while nondeterministic ones can recognize all context-free languages, with the former often used in parser design.


Related Solutions

Use rules of inference to show that the hypotheses “Every student in Computer science major needs...
Use rules of inference to show that the hypotheses “Every student in Computer science major needs to take CSCI2000,” “Every student who takes CSCI2000 knows how to program in JAVA” imply the conclusion “Every student in Computer science major knows how to program in JAVA.”
In this course, you have learned that computer programming is key to computer science. The ability...
In this course, you have learned that computer programming is key to computer science. The ability to program a succession of instructions to resolve a computing problem is a valuable skill that is integral to many aspects of modern life. You have also seen the versatility and distinguishing characteristics that make Python 3 a popular choice for programmers. End-of-Course Essay Write a 1- to 2-page essay in which you connect this course to your own career or personal life. Imagine...
Assignment Content In this course, you have learned that computer programming is key to computer science....
Assignment Content In this course, you have learned that computer programming is key to computer science. The ability to program a succession of instructions to resolve a computing problem is a valuable skill that is integral to many aspects of modern life. You have also seen the versatility and distinguishing characteristics that make Python 3 a popular choice for programmers. End-of-Course Essay Write a 1- to 2-page essay in which you connect this course to your own career or personal...
COP3014-Foundations of Computer Science Assignment #6 You will implement a program called "nursery_inv3.cpp" to process customer...
COP3014-Foundations of Computer Science Assignment #6 You will implement a program called "nursery_inv3.cpp" to process customer purchase orders (orders) for a nursery. You will read the data stored in a data file into a static array of purchase orders records, then process each purchase order record in the array, and finally print the array of purchase order records to a datafile. The purchase orders will be stored in order records. Each order record contains nine fields, which are as follows:...
I'm in a computer science course and I have an assignment that asks me to implement...
I'm in a computer science course and I have an assignment that asks me to implement a CPU scheduler in Java. Here are some details for the task: The program should ask for the number of processes. Then the program will ask for burst and arrival times for each process. Using that information, the program should schedule the processes using the following scheduling algorithms: First Come First Serve (FCFS) Shortest Jobs First (SJF) Shortest Remaining Time First (SRTF) The output...
I am working on a project for my Computer Science course. I am trying to create...
I am working on a project for my Computer Science course. I am trying to create a Battleship game where a user names two coordinates on a grid and is then told whether this results in a "Hit" or a "Miss". Once the ship has been hit a certain number of times (based on the size of the ship) the ship is sunk. I have written all the code but it now fails to execute when I try to run...
Accounting Theory 1. In terms of theoretical foundations, how do you compare accounting to other disciplines...
Accounting Theory 1. In terms of theoretical foundations, how do you compare accounting to other disciplines such as economics, physics, mathematics, etc.? 2. Discuss three major challenges facing fair value accounting practices and their implications to the future fair value accounting. 3. Assuming the above challenges to fair value accounting were solved, why would you prefer fair value accounting over historical cost accounting? 4. Explain why we would not need an income statement if everything was accounted for under the...
Hi, I found this in the book balanced introduction to computer science,Javascript language, ⌈Log2(N)⌉ determine the...
Hi, I found this in the book balanced introduction to computer science,Javascript language, ⌈Log2(N)⌉ determine the number of checks it takes for binary search to find an item. I also saw this ⌈Log2(N)⌉+1 to find the number of checks, what is the difference between these 2, which one should I use?
Interactive computer graphics course. by java language, no need to explain. Q1: Draw a line between...
Interactive computer graphics course. by java language, no need to explain. Q1: Draw a line between P0 and Pe P0= (x,y)=(2,5) Pe=(xe,ye)=(7,9) Q2: P=(3,5) Scale P by (5,7) and then sheer by -3 along y-axis
These questions are about the Nicaraguan Sign Language Senghas (2004) article. 1.) What is the theoretical...
These questions are about the Nicaraguan Sign Language Senghas (2004) article. 1.) What is the theoretical postion on the Nicaraguan Sign Language? 2.) What are the 2 properties of language focused on in the Senghas (2004) article? Can you explain what each of them are and why they are important? 3.) How many NSL signers were studied in each of the 3 cohorts that were sampled a.)How did their linguistic environments differ? b.)How did their signs differ? 4.)What do you...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT