Write a java program which will allow a s-grammar

Assignment Help Theory of Computation
Reference no: EM132375291

Assignment

1. Purpose

The purpose of this assignment is to write a Java program which will allow a s-grammar (see slide 15 of the CFL slide set) G = (V,T,S,P) and a string to be inputted. The program should check that the grammar is a valid s-grammar and then parse the string to determine whether the string is a member of the language that is defined by the grammar.

All elements in the set V of variables and set T of terminals consist of single characters. Variables in V consist of upper-case alphabetic characters. Terminals in T consist of lower-case alphabetic characters and special characters like { = + etc. The set P of production rules do not include ,-productions, but otherwise can include any valid s-grammar rules.

2. Program Details
The program must have a GUI interface which will allow the grammar to be inputted. The program should then check that the grammar is a valid s-grammar. If it is, strings should be inputted and the program should then parse them, i.e. check whether they belong to the language that the grammar defines, by performing a leftmost derivation on them. The program must also have a facility to display each step of the leftmost derivation as it is occurring.

You might find it useful to check out JFlap's Grammar option which has quite a nice interface. Any s-grammar (like grammars G1 and G2 in section 3 below) is actually usable in JFLap as an LL(1) grammar, since s-grammars are special cases of LL(1) grammars.

In addition, s-grammars and strings to be parsed must be able to be read in from a data file.

You should use a common internal representation for s-grammars and strings to be parsed, so that it will make no difference to your program whether they are inputted via the GUI interface or via a data file.

3. Testing

You must test your code on the following two s-grammars, though of course you can (and should) create or find others as well on which to test your code. Note that all productions in these grammars follow the requirements for s-grammars in that
• there is a single variable on the left hand side of a production.
• the right hand side of a production starts with a single terminal and is followed by 0 or more variables.
• if there are two or more productions with the same variable on the left hand side, the right hand of each of these productions starts with a different terminal.

G1 is a s-grammar
G1 = ( { S,A,B }, { a,b }, S, P )

for the language L = {anbn+1 : n $1}, with the elements of P being the productions

S          6    aAB

A          6    aAB | b

B           6    b

G2 is a s-grammar

G2 = ( { S,R,L,C,A,Y,P,Z,X,T,D }, { {,},x,=,y,+,z,i,t,e,d }, S, P }

for a fragment of a programming language, with the elements of P being the productions

S          6    {LR

R          6    }

L          6    xAYPZ | iXTLC

C          6    d | eLD

A         6    =

Y         6    y

P          6    +

Z          6    z

X         6    x

T          6    t

D         6    d

A program fragment takes the form

{ Stmt }

where Stmt can have the one of the forms

(i) x = y + z

(ii) if x then Stmt endif

(iii) if x then Stmt else Stmt endif

E.g a program fragment might be

{ if x then
x = y + z
else
if x then
x = y + z
endif endif }

Obviously, since both variables and terminals are specified to consist of single characters only, any multi-character variables or terminals like Stmt or endif must be represented by single characters. The following scheme is used

word            symbol

 

Stmt               L

 

if                         i

then               t

else                   e

 

endif                 d

The above program fragment is then represented by the string

{ixtx=y+zeixtx=y+zdd}

You could decide in your implementation that whitespace is not significant within strings to be parsed. If that were the case, then the string might have the (slightly) more user-friendly format

{ i x t x=y+z e i x t x=y+z d d }

4. Data Structures and Algorithms

In any leftmost derivation, the essential requirement is to replace the leftmost variable in the current sentential form with the right hand side of a production with that variable on the left hand side. In an s-grammar, the choice of which production to use is made very simple. If a is the next symbol in the input string being parsed, and A is the leftmost variable in the current sentential form, we have to find a production with A on the left hand side whose right hand side starts with a. By the nature of an s-grammar there can be only one such production. If there is no such production the string cannot be a member of the language that the grammar defines.

Design decisions you should consider include
- how sentential forms should be represented so that it is easy to find and replace the leftmost variable in the sentential form.
- how productions should be represented so that it is easy to find the production that is to be used in the replacement of the leftmost variable in the sentential form. The restriction that variables must consist of uppercase single characters means there can be no more than 26 variables here, but in a real grammar there may be dozens or even hundreds of variables. A method of representing and retrieving productions efficiently is therefore important.

Reference no: EM132375291

Questions Cloud

Explain how the types of threats discussed in the article : Attacks on our national infrastructure are already happening. And the expectation is that they will continue to increase at an accelerated rate.
Name the key stakeholders you will consult : Name the key stakeholders you will consult when developing the policy. How will you explain the benefits of the policy to them?
Devices such as wireless access points : As a business's networking needs expand, the need for managed switches increases.
Symbolism of name black cat and symbolism of cat in story : Introduction has to have brief sum up of chosen work and authors background mentioned in text. symbolism of name black cat and symbolism of cat in story
Write a java program which will allow a s-grammar : COMP314 - Operating Systems - Athabasca University - Write a Java program which will allow a s-grammar (see slide 15 of the CFL slide set) G = (V,T,S,P)
Information collected from the commercial guide : What would be the most appropriate entry method or methods, supporting your decision with the information collected from the commercial guide?
Research myths surrounding one of less-known constellations : You will research the myths surrounding one of the less-known constellations. Do not include any of the Zodiacal constellations, or better-known constellations.
Ontario fault determination rules : 1. Referring to the Ontario Fault Determination Rules start by determining fault in this scenario.
Explain how you will test performance management systems : Explain how you will test performance management systems.

Reviews

len2375291

9/23/2019 11:43:29 PM

You will need to submit the properly documented source code of your classes together with a record of the testing you undertook to show the correctness of your code, including the data files. These must all be in the Eclipse project file. Submit through Moodle by clicking on the Assignment 1 topic on the front page and uploading your single zipped project file. You can resubmit as often as you like, but only the last submission is kept.

len2375291

9/23/2019 11:43:20 PM

The completed assignment is to be submitted as a single exported Eclipse .zip project file, though of course you can have multiple classes within the project. You must ensure that your project file can be imported into Eclipse and run without any changes needing to be made to it. The markers don’t have the time to do this for you! The name of your project file must be yoursurname_yourinitials_yourregno_Assignment_1.zip. The main method through which the assignment is run must be in a class called RunAssignmnent.

Write a Review

Theory of Computation Questions & Answers

  1 firstly critically discuss how job design can contribute

1. firstly critically discuss how job design can contribute to the growth and development of the individual skill

  Draw a turing machine that decides the language

CO519 Theory of Computing - Draw a Turing machine that decides the language of all words over the alphabet {a, b} that have an odd number of a's

  Part -1q1 what do you consider were the three most

part -1q1 what do you consider were the three most important things planned or unplanned that you learned last year?

  In an internet retailer you will find a wide range of job

in an internet retailer you will find a wide range of job functions. leaders frequently need to adjust their own

  Write an unambiguous grammar

Write an unambiguous grammar for the given languages- You have to prepare unambiguous grammar for the above languages. Please help! I am stuck on this question

  Write first four strings in lexicographic enumeration

Consider the language L = L1 ∩ L2, where L1 = {ww^R : w ∈ {a, b}* and L2 = {a^n b*a^n: n ≥ 0}. Write the first four strings in the lexicographic enumeration of L?

  What is the significance of nevis island

What is the significance of Nevis Island? Did the significance sway your decision? If yes why? If no why - What is the significance of Audrey's message

  A coinductive calculus of binary trees

The assignment consists of writing an extended abstract of the article  - A coinductive calculus of binary trees

  The challenges of antonios wayfive basic goals often

the challenges of antonios wayfive basic goals often referred to as the backbone of antonios way were posted in

  Propositional and predicate logic

Write down a structural induction principle for the PlayTree free type

  A new manager is starting in the organisation shortly you

a new manager is starting in the organisation shortly. you have been asked to provide an outline to this new-starter so

  What is the mealy machine

Given the state table of a Mealy machine and an input string, produce the output string generated by the machine.

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