Notes:Possible error 2016 compiler design q2b

From Maths
Jump to: navigation, search

Question

File:Cs3250-2016-with-solutions.pdf - question 2 part b - which can be found on the front page

Examiner's answer

The same as mine, but with a transition via y from my A5 to G2, see bottom of page 5 in File:Cs3250-2016-with-solutions.pdf

Alec's answer

# Production DFA Comment
0 S::= A# Notice that if we just have the input "y" we are stuck on A5, this is accepting so we "construct" (reduce ϵ - nothing - to B) B from an ϵ and go back to the start.

We now have a B on the top of the stack, we shift this and end up at state F, we shift the next top-of-the-stack (the y from before) ending up at G2, this is an accepting state, so:

  • We reduce the y and B on the top of the stack to an A - as per production 2
  • Go back to the start (ie A5)

We then shift the A and shit the # (assuming this means "end of input") then reduce both to the start symbol, which is the accept-the-parse of accepting states, we're done.

There is some abuse of terminology here, but you see what I mean, and we'd usually use numbers for the states.

Regardless we reduce to "logically" get a B from ϵ, shift the y over that, reduce them both to get an A, shift the # over that, reduce them both to get an S, we're done.

1 A::= Az
2 A::= By
3 B::= Ax
4 B::= xy
5 B::= ϵ