Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kirby Cravens Pull Request #16

Closed
wants to merge 23 commits into from
Closed

Conversation

kirbycravens
Copy link

Kirby Cravens
47320134

B -> S
B -> "r"
B -> "g"
B -> "b"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0

Sorry, but this is way off... I was looking for something like

       S -> r | g | b
       S -> r  S  r
       S -> g  S  g
       S -> b  S  b

@@ -53,7 +61,7 @@ In one sentence, explain why.

## A1.2

«replace this with your answer»
O(n) because the graph of this problem will grow linearly as the length of the path increases.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1

I don't understand what "the graph...will increase means".

Basically, it it O(n) because you have to keep at least half the input on the stack while processing.

< a > ::= "lazy"|"smelly"
< noun > ::= "dog"|"cat"
< verb > ::= "ate"|"ran"
< adverb > ::= ""|"slowly"|"noisily"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4

There doesn't seem to be a sentence here.

Also,

< adjective >   ::=     ""|< a >|< adjective > < a >  

is actually ambiguous, because could be "", so the second and third clauses on the RHS could both match. Better would be

< adjective >   ::=     "" | < adjective > < a >  

< adjective > ::= [{"lazy"|"smelly"}]
< noun > ::= "dog"|"cat"
< verb > ::= "ate"|"ran"
< adverb > ::= ["slowly"|"noisily"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3

Again no sentence. And what is [{"lazy"|"smelly"}]? {} means zero or more, and [] means optional.

@@ -109,7 +124,7 @@ Write this grammar using EBNF with common extensions

## A2.3

«replace this with your answer»
FSMDiagram.jpeg
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3

The lines between states in the diagram represent events. In your diagram, what event gets me from S1 to S2? And how do I get from S4 to the END is there is no adverb (because if there's no input after the verb, then the event is EOI).

S4 | | S4
S4 | slowly | S4
S4 | noisily | S5
S5 | EOI | END
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5

This table seems to be an accurate transcription of your diagram. But the blank entries in the "next word" column should have tipped you off that something was not right...

@@ -145,7 +173,7 @@ code, include a script or makefile that will do the job.

## A2.5

«replace this with your answer»
main.cpp
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3

This code is a correct solution to the wrong problem (which is a shame, because it's a cool idea).

The question called for you to feed sentences INTO the state machine and see if they matched. Your code generates random sentences based on the grammar.

Also, your generation doesn't really use the state machine properly. It simply iterates through the states, ignoring the next state. As a result, you can only ever get two adjectives out of a run, and they'll always be in the order "lazy" "sme;lly".

@@ -154,7 +182,7 @@ How many valid sentences are there in this language?

## A2.6

«replace this with your answer»
48
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0

actually there are an infinite number

@@ -164,4 +192,4 @@ explain why.

## A2.7

«replace this with your answer»
This is a level 2 language because its context-free and can be passed down a finite state machine.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0

It's a type-3 language because it is regular, and can be parsed using a state machine.

@pragdave pragdave closed this Nov 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants