Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

**In C++ WITHOUT USING THE HEADER** I'm personally trying to implement Thompson's Construction that is slightly altered in my way but I'm very puzzled (The

**In C++ WITHOUT USING THE HEADER**

I'm personally trying to implement Thompson's Construction that is slightly altered in my way but I'm very puzzled(The Question I'm asking you is marked in ***** in between), Say in instance that you have a program that has drawn the following grammar down to both a 1d vector called ID, and a 1d vector called grammar these vectors would often be pushed back to get the following results.

So for instance you've push_back elements into the ID vector that contains:t1, t2, t3,and,t4

and same goes for the grammar vector that contains(p).(q),(a).(b),(c).((c).(c)), and(7)|((a).(z))

this would result in the following output:

We have the following grammar: Token: t1 With the grammar reading: ( p ) . ( q ) Token: t2 With the grammar reading: ( a ) . ( b ) Token: t3 With the grammar reading: ( c ) . ( ( c ) . ( c ) ) Token: t4 With the grammar reading: (7)|((a).(z))

Next, lets layout examples that have differing number of tokens and grammars used (Assume the vectors are free of errors, syntax included, as I've already handeled that)

Example 1:

We have the following grammar: Token: t1 With the grammar reading: a

Example 2 (Union):

We have the following grammar: Token: t3 With the grammar reading: ( d ) | ( e ) Token: t4 With the grammar reading: ( a ) | ( b )

Example 3 (Concatenation):

We have the following grammar: Token: t6 With the grammar reading: ( p ) . ( q ) Token: t7 With the grammar reading: ( a ) . ( b ) Token: t8 With the grammar reading: ( c ) . ( ( c ) . ( c ) )

Example 4 (Concatenation & Union):

We have the following grammar: Token: t9 With the grammar reading: ( ( c ) | ( d ) ) . ( ( a ) | ( b ) )

Example 5 (Kleene Star):

We have the following grammar: Token: t10 With the grammar reading: ( ( ( ( a ) . ( t ) ) . ( e ) ) * ) . ( x )

Example 6 (Kleene Star & Concatenation):

We have the following grammar: Token: t11 With the grammar reading: ( b ) . ( ( a ) * )

*****Can Implement a function, program, or coding in C++ that would convert each of the following grammars to each print out all possible sets of strings that each grammar represents? For instance in the examples above (it's important to display the combinations in 2d vectors too if multiple tokens are present such as Examples 2 & 3 in order to avoid mixups, possibilities of epsilon or an empty string will be mentioned further down below)*****:

Example 1:

Since we have a simple token with simple grammar which reads: \"a\", then our set would contain only 1 string and that is:{a}

Example 2:

We have two tokens representing 2 different grammars, in this case, t3 would read out as{d, e}& t4 would read out as{a, b}

Example 3:

We have three tokens representing 3 grammars, in this case, t6 is read as{pq}, t7 would read as{ab}, and t8 would read out as{ccc}

Example 4:

For this we have combined both Concatenation & Union to form this language, in this case, t9 would read as{ca, cb, da, db}

Example 5: We have a token that features a Kleene Star, as such, our t10 would be read as:{x, atex, ateatex, ateateatex, ateateateatex, ... }and so on, it'd be best to set a limit by your choice or say 50 before moving onto the next set of combinations

Example 6:

For this we have combined both Concatenation & Kleene Star, as such, our t11 would be read as:{b, ba, baa, baaa, baaaa, ... }and so on, it'd be best to set a limit by your choice or say 50 before moving onto the next set of combinations

Next, Let's lay out a specific scenario:

Say we pushed our elements into a vector to get the following:

We have the following grammar: Token: T1 With the grammar reading: ( ( a ) * ) | ( ( b ) * ) Token: T2 With the grammar reading: ( ( a ) | ( b ) ) *

For this, our string sets for each token is read as follows and this even includes an epsilon or an empty string (for this we can make '_' as our epsilon since our combination can possibly output that): T1 grammar has strings of:{_, a, b, aa, bb, aaa, bbb, aaaa, bbbb, ...} T2 grannar has strings of:{_, a, b, aa, ab, ba, bb, aaa, aab, aba, abb, baa, bab, bba, bbb, ...} For this specific purpose, you may want to separate this into another function to check for any epsilon found among the string set, if so, output that particular token as such.

The following token(s) has epsilon in it!: T1 T2

Here's another example:

We have the following grammar: Token: t1 With the grammar reading: ( a ) | ( b ) Token: t2 With the grammar reading: ( a ) | ( ( a ) * )

For this, T1 grammar has strings of:{a, b} T2 grammar has strings of:{a, _, aa, aaa, aaaa, aaaaa, ...}

you can output as such: The following token(s) has epsilon in it!: T2

Here's one last example you try to test your code on:

We have the following grammar: Token: RxDoJ With the grammar reading: ( ( U ) | ( d ) ) . ( ( F ) . ( 4 ) ) Token: Jsdjfk With the grammar reading: ( ( a ) . ( ( b ) * ) ) . ( a )

**In C++ WITHOUT USING THE HEADER**

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Entrepreneurship

Authors: Andrew Zacharakis, William D Bygrave

5th Edition

1119563097, 9781119563099

More Books

Students also viewed these Programming questions

Question

If f is continuous at a, must f be differentiable at a?

Answered: 1 week ago

Question

Describe ERP and how it can create efficiency within a business

Answered: 1 week ago