Show the parse trees for each of the given sentences

Assignment Help Programming Languages
Reference no: EM131538139

Assignment

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.

I need the code and the screenshot of the compiled program.

Attachment:- Token.rar

Reference no: EM131538139

Questions Cloud

Compute free cash flow and estimate the value of stock : Compute Free Cash Flow and Estimate the value of a stock using the following information:
Assuming interest expense is unchanged : Assuming interest expense is unchanged, what level of sales will the firm need to meet the CEO's wishes?
How much interest does fred earn from this account : Fred Flintstone deposits $50 every month into an ordinary annuity. How much interest does Fred earn from this account?
Recognized on the march income statement from this order : In the March income statement, how much revenue is recognized on the March income statement from this order?
Show the parse trees for each of the given sentences : Show the parse trees (which can be generated in ANTLRWorks) for each of the following sentences. Examples of SYNTACTICALLY INVALID Input Strings.
Parental permission to conduct the assessment : Have all materials ready before the assessment session and review procedures for administering the assessment before the child arrives.
Where do cfos get their money news : Where do CFOs get their money news? According to Robert Half International, 47% get their money news from newspapers, 15% get it from communication/colleagues
What is the population of survey : a. What is the population of this survey? 350 b. What is the size of the population? 9500
How many pallet positions are needed : A company has 6,000 cartons to store on pallets. How many pallets are required? How many pallet positions are needed?

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

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