Draw the syntax diagrams for each of the grammar elements

Assignment Help Programming Languages
Reference no: EM131227747

Assume we start with a simple "sentence" grammar as follows:

<S> ::= <NP><V><NP>
<NP> ::= <A><N>
<V> ::= loves | hates | eats
<A> ::= a | the
<N> ::= dog | cat | rat

Part A:

Show the BNF above with the following additional grammar elements:

• Adjectives: (0 or more Adjectives separated by commas may precede any Noun. A comma may or may not be preceded by a space.)

o furry
o fast
o slow
o delicious

• Adverbs: (0 or 1 Adverb may precede any Verb)

o quickly
o secretly

• Conjunctions: (0 or more may appear in any sentence

o and
o or

• Sentence terminator (The terminator may or may not be preceded by a space.)

o . (a single period)
o ! (a single period)

Part B:

Show/Draw the syntax diagrams for each of the grammar elements above. Hyperlink reference not valid.

Part C:

Show the parse trees (which can be generated in ANTLRWorks) for each of the following sentences:

Examples of SYNTACTICALLY VALID Input Strings:

a dog loves the cat.

the cat eats the slow rat and the slow , furry dog secretly hates the cat and a dog loves the rat !

Examples of SYNTACTICALLY INVALID Input Strings (where do they fail):

a dog barks at the cat.
the fast furry cat eats quickly

NOTE: You can generate the full parse treesfrom ANTLRWorks (as can be done with the attached sample for the base grammar) or simply draw out the cooresponding AST's (Abstract Syntax Trees) "by hand" on paper or with a simple drawing tool. The point of this is to have something that you can then verify against the parse trees generated by your own code (in the next part).

Part D:

Modify the (attached) sample code to accept valid sentences based upon the newly defined grammar above. The parser should also "reject" invalid sentences with a descriptive error message. Note that the program should still accept a filename from the "Command Line" as illustrated in the example. Please no HARD-CODED file paths in the source.

Attachment:- Token.rar

Reference no: EM131227747

Questions Cloud

How the biological personality theory affects : Explain how the biological personality theory affects an individual's personality. Explain it's strengths and weaknesses.
What an educator can do to enhance learning and literacy : Locate an article in the Ashford Online Library that investigates research in brain development and its relation to learning and literacy. Provide a summary of the article and explain how the findings can be translated into what an educator can do..
What amount should the last two deposits : After having made the first 4 deposits as planned, you learn that tuition will actually be $48,000 a year for the four years. Two more of the original planned deposits will not be enough to pay for the four years of tuition. Instead of the last tw..
Draw a demand for money curve and a supply of money : Draw a demand for money curve and a supply of money at $2 trillion. Identify the rate of interest at which people would hold this quantity of money. Illustrate the effect of an increase in the supply of money by the Fed.
Draw the syntax diagrams for each of the grammar elements : Show/Draw the syntax diagrams for each of the grammar elements above. Hyperlink reference not valid. Show the parse trees (which can be generated in ANTLRWorks) for each of the following sentences.
Should the fed increase or decrease the money supply : Determine whether each of the following increases, decreases, or remains unchanged in the short run: the market interest rate, the quantity of money demanded, investment spending, aggregate demand, potential output, the price level, and equilibriu..
Compute capitalized costs and deductions by year : LPC is an independent oil and gas company. -Determine how the all costs should be treated and compute capitalized costs and deductions by year.
Explain the short-run and long-run impacts of money supply : (Monetary Policy and Aggregate Supply) Assume that the economy is initially in long-run equilibrium. Using an AD-AS diagram, illustrate and explain the short-run and long-run impacts of an increase in the money supply.
Explain what abnormal and normal behavior is : PSY-102 - Topic Mental Health and Wellness Worksheet what recommendations could be madeto help reduce his anxiety and what other types of therapy may assist John to reduce his symptoms of compulsion?

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a program to find the common songs in these lists

Write a program to find the common songs in these lists. Let user enter the list sizes n and m and the songs. While testing your program for submission, make sure that the lists are different but they do intersect in some songs.

  Challenges of incorporating natural command language

From the e-Activity, Amore's and Quesada's article discusses the challenges of incorporating Natural Command Language Dialogs (NCLDs) into a phone system

  Deck of cards programming class

Write a complete program using "ECLIPS" that implements the functionality of a deck of cards. In writing your program, use the provided DeckDriver and Card classes shown below. Write your own Deck class so that it works in conjunction with the two..

  Using datagrid in an application

Update the field named fldQuestionDescription.

  Write program which uses while loops to input two integers

Write the program which uses while loops to perform the following steps: prompt the user to input two integers: firstNum and secondNum.(firstNum must be less than secondNum.

  Distinguish between open and closed applications.

What applications are being used to make the applications on the web faster and easier to access?

  Write the code for adding a task

write the code for adding a task to this array when the user enters a task in the first text box and clicks the Add Task button. This code should also blank out the text box. At this point, don't worry about displaying the tasks in the text area f..

  Define the alert function

I have this file and I'm trying to Modify the display_alert() function to also display a line of the countdown on the web page.

  Design and implement program catches and handles exception

Design and implement a program that creates an exception class called StringTooLongException, designed to be thrown when a string is discovered that has too many characters in it.

  Assignment - file access and pseudocode

Assignment - File Access and Pseudocode, When a program needs to save data for later use, it writes the data in a file. The data can be read from the file at a later time

  Create memo to grace to outline purposes of organization

Create a memo to Grace in which you outline purposes of organization and costs and benefits of becoming a member.

  How the app may lead to a career in mobile technology

CP3307/CP5307 Coding Project Specification - Discuss the design, implementation, and testing of your app - how to rotate and move the blocks so the picture is correctly formed.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd