Write a program that can take any given CFG as input

Assignment Help Programming Languages
Reference no: EM132251295

Assignment -

Overview - This assignment focuses on context-free grammars (CFGs). CFGs are used in modelling the syntax of programming languages. Compilers for programming languages will embody a parser, i.e., an algorithm to determine whether a given string belongs to the language generated by the CFG. If the string does belong, then the parser will produce a derivation of the string, which the compiler would then use to translate the string into assembly language. Your overall aim in this coursework is to implement a parser for CFGs. Specifically, you are required to:

1. Devise an encoding (i.e., a data structure) for CFGs that can be used to specify any given CFG in a .txt file, which can then be passed to and processed by the programs in parts 2,3 below.

2. Write a program that can take any given CFG as input (specified as a separate.txt file as in part1) and output an equivalent CFG in Chomsky normal form.

3. Extend the program in part 2 so that, after the conversion to Chomsky normal form, it asks the user for an input string and then determines whether or not the string can be generated by the given CFG. If it can be generated, then it should output a derivation of the string.

Note - More details are in attached file.

Parsing for Context-free Grammars

Task 1 - Devise an encoding, i.e., a data structure, for CFGs that can be processed by the programs in tasks 2 and 3 below. The idea is that it should be possible to specify any given CFG in a separate .txt file using this encoding, which can then be fed as an argument via the command line to the programs below. The encoding can be of your choice, but you must effectively incorporate all four ingredients in the definition of CFG.

Describe and explain your encoding, and illustrate it by giving a screen-shot of your encoding of the example CFG G0 given below. In addition, you must submit a .txt file containing its encoding.

Task 2 - Write a program that can take as input any .txt file containing an encoding of any CFG (using the data structure you provided in task 1) and convert it into Chomsky normal form (see lecture 11). You may use the algorithm for this purpose that was outlined in lecture 11. The program must be executable via the command line, with the .txt file encoding passed as an argument. After execution the program should print to the screen a vertical list of rules in Chomsky normal form, that is, a list of rules with each one taking the form of either

A -> BC

or

A -> x

or

S -> e

where A, B, C are any variables of the given CFG (with B,C not being the start variable), x is any terminal of the CFG, S is the start variable of the CFG and e is the character denoting the empty string.

Using your program, or otherwise, give the CFG G0 given above in Chomsky normal form. (Screenshot acceptable if done using the program). Your code will be tested on the .txt ?le encoding of G0 that you provide in Task 1. In addition it will be tested on two other example CFGs G1 and G2 of my choosing (which will be the same for all students).

Task 3 - Extend your program from Task 2 so that, after conversion to Chomsky normal form, it prompts the user for a string, and then (using the algorithm sketched below) determines whether or not that string is generated by the (Chomsky normal form of the) given CFG. If it isn't then the program should just print something like "string XXX is not generated by this CFG". If it is generated, then it should print to the screen a derivation of that string using the Chomsky normal form of the given CFG. The derivation may be printed in the form of a vertical list of strings, ending in the derived string, and such that each string in the list is derived from the previous one using the rules of the converted CFG.

Attachment:- Assignment File.rar

Reference no: EM132251295

Questions Cloud

Have or do you work for an organization : After watching the video and completing the chapter readings, outline your understanding of high performance work teams. If you have a difficult time opening.
How does culture influence the negotiations process : How does culture influence the negotiations process? is it unethical to lie and deceive during negotiations? Why or why not?
What mechanisms are employed to spread power across : Are employers making more of an effort to empower their employees than was the case 20 years ago? What mechanisms are employed to spread power across
Develop a balance scorecard to manage the project : You are a project manager for a large electronics retailer (e.g., Best Buy) who will be implementing a new time keeping system to track hourly and salary.
Write a program that can take any given CFG as input : CM2207 Assignment - Write a program that can take any given CFG as input (specified as a separate.txt file as in part1) and output an equivalent CFG
Why organizational culture must be considered : Visit the following: Creating A Culture Of Recognition: Total Rewards & Recognition Initiative and review the information. After understanding the information.
How is the mesh of levy determined : Who is not a taxpayer - How should one register as a taxpayer and What is meant by a tax-ready operation - How is the mesh of levy determined
Define four-component model of ethical decision making : Consider Scenario C and Scenario D and the four-component model of ethical decision making. At what stage of the model do you think the individuals "went wrong?
What text type did you choose to emulate for your WT : Write the The killing of Gatsby - An article (1920s) responses from Lord of the Flies with your own responses. What text type you choose to emulate for your WT

Reviews

len2251295

3/8/2019 8:55:48 PM

Notes before getting started - The following programming exercises may be implemented using a programming language of your own choice, though all parts must be done using the same language. If you wish to use anything other than Java or Python then please let me know well in advance so I can make sure I have every thing necessary to run your program installed on my computer.

len2251295

3/8/2019 8:55:42 PM

You may use existing software libraries. If you use any other external sources for solving your coursework (e.g. pseudocode from a website), you should add a comment with a reference to these sources and a brief explanation of how they have been used. You are allowed to discuss high-level aspects of your solution with other students, but you should disclose the names of these students in a comment. For the purposes of this coursework, you may assume that the character e is reserved to denote the symbol for the empty string, and is not allowed to be a variable or terminal.

len2251295

3/8/2019 8:55:37 PM

Breakdown of marks for Task 1 (Total 5 marks): 3marks for the encoding, explanation and example (including screen-shot). 2marks for the .txt ?le encoding G0. Breakdown of marks for Task 2 (Total 13 marks): 5marks for providing G0 in Chomsky normal form (whether calculated using your program or not). 5marks if program returns correct output when fed the encoding of G0 provided in Task 1. 3marks if program also gives correct output when fed encodings of additional examples G1 and G2 (1.5 marks for each).

len2251295

3/8/2019 8:55:30 PM

Breakdown of marks for Task 3 (Total 12 marks): 4marks for correctly determining (whether using your program or not) whether each of the given 2 strings is generated by G0 (with derivations provided in case they are). (2 marks for each string) 4marks if program gives the correct answer for each of the 2 strings when fed the encoding of G0 provided in Task 1. (2 marks for each string) 4marks if program also gives correct answers on an additional example strings with G1, G2. (1 mark for each of the 4 pairs of CFG + string).

len2251295

3/8/2019 8:55:25 PM

Summary of what you need to submit - You should submit the following files: zip ?le containing: .txt ?le containing the encoding of G0 for task 1, Program code for tasks 2, 3. Single pdf ?le containing answers for all other parts (screenshots, explanations, etc).

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