dabeaz / sly

Sly Lex Yacc
Other
816 stars 107 forks source link

understanding debugfile states #65

Open codykingham opened 3 years ago

codykingham commented 3 years ago

Hi all. I'm a newbie to YACC parsing, so apologies if this is trivial.

I'm using the debugfile and need a little help understanding the structure of each state printout.

Here's an example from my file:

state 4
    (3) phrase -> quant .
    $end            reduce using rule 3 (phrase -> quant .)
    CONJ            reduce using rule 3 (phrase -> quant .)
    CARD            reduce using rule 3 (phrase -> quant .)
    ART             reduce using rule 3 (phrase -> quant .)

What I'm confused by: In this particular state the terminals CONJ, CARD, and ART are not mentioned in the first line, but they are mentioned in the actions. Why is this? My impression was that the actions refer back to the position within the parse.

codykingham commented 3 years ago

After doing my homework, I believe I now have a good understanding of what's going on. After the position marker quant ., we may encounter any of the 4 input tokens next (given the grammar), i.e. end of string, CONJ, CARD, or ART. So it doesn't matter that they aren't listed.

I'm not yet clear why the printout sometimes does and doesn't include the next input token in the position string. Maybe this is just for brevity in some cases?

If anyone else is also trying to grasp the parser output, I've found the YACC documentation very instructive (see section 4 of http://dinosaur.compilertools.net/yacc/)