Home
 

YPlayer Handout

Handout

YPlayer

program sample;
begin
    i := 123;
    j := 345;
    writeln(i);
    writeln(j)
end.
Starting parse
Entering state 0
Reading a token: Next token is 258 (PROGRAMTK)
Shifting token 258 (PROGRAMTK), Entering state 1
Reading a token: Next token is 264 (IDENTIFIERTK)
Shifting token 264 (IDENTIFIERTK), Entering state 2
Reducing via rule 13 (line 75), IDENTIFIERTK  -> Identifier
state stack now 0 1
Entering state 3
Reading a token: Next token is 261 (SCTK)
Shifting token 261 (SCTK), Entering state 4
[...]
Reducing via rule 1 (line 35), PROGRAMTK Identifier SCTK Block  -> Program
state stack now 0
Entering state 26
Reading a token: Now at end of input.
Shifting token 0 ($), Entering state 27
Now at end of input.
Now at end of input.
Grammar
rule 1    Program -> PROGRAMTK Identifier SCTK Block
rule 2    Block -> BEGINTK StatementSeq ENDTK DOTTK
rule 3    StatementSeq -> Statement
rule 4    StatementSeq -> StatementSeq SCTK Statement
rule 5    Statement ->		/* empty */
rule 6    Statement -> AssignmentStmt
rule 7    Statement -> WriteStmt
rule 8    AssignmentStmt -> Identifier ASGTK Expr
rule 9    WriteStmt -> WRITETK LPARENTK Expr RPARENTK
rule 10   Expr -> Factor
rule 11   Factor -> Number
rule 12   Factor -> Identifier
rule 13   Identifier -> IDENTIFIERTK
rule 14   Number -> NUMLITERALTK

[...]

state 0    PROGRAMTK     shift, and go to state 1
           Program       go to state 26

state 1    Program  ->  PROGRAMTK . Identifier SCTK Block   (rule 1)
           IDENTIFIERTK  shift, and go to state 2
           Identifier    go to state 3

[...]

YPlayer Screenshot (larger)

Parse Tree of Example (larger)