PL/0 Parser

Post on 21-Jan-2016

56 views 1 download

Tags:

description

PL/0 Parser. COP 3402 System Software Fall 2013. The Parsing Problem. Take a string of symbols in a language (tokens) and a grammar for that language to construct the parse tree or report that the sentence is syntactically incorrect . Two ways to do this: - PowerPoint PPT Presentation

Transcript of PL/0 Parser

PL/0 Parser

COP 3402 System SoftwareFall 2013

The Parsing Problem• Take a string of symbols in a language (tokens)

and a grammar for that language to construct the parse tree or report that the sentence is syntactically incorrect.

• Two ways to do this:– Top-Down (recursive descending parser).– Buttom-Up. (We don’t focus on this).

Top-Down Approach• Uses recursive procedures to model the parse

tree.• Beginning with the start symbol, for every

non-terminal (syntactic class) a procedure which parses that syntactic class is created.

PL/0 Grammar <program> ::= <block> . <block> ::= <const-decl> <var-decl> <proc-decl> <statement> <const-decl> ::= const <const-assignment-list> ; | e <const-assignment-list> ::= <ident> = <number> | <const-assignment-list> , <ident> = <number> <var-decl> ::= var <ident-list> ; | e <ident-list> ::= <ident> | <ident-list> , <ident> <proc-decl> ::= <proc-decl> procedure <ident> ; <block> ; | e <statement> ::= <ident> := <expression> | call <ident> | begin <statement-list> end | if <condition> then <statement> | while <condition> do <statement> | e <statement-list> ::= <statement> | <statement-list> ; <statement> <condition> ::= odd <expression> | <expression> <relation> <expression> <relation> ::= = | <> | < | > | <= | >= <expression> ::= <term> | <adding-operator> <term> | <expression> <adding-operator> <term> <adding-operator> ::= + | - <term> ::= <factor> | <term> <multiplying-operator> <factor> <multiplying-operator> ::= * | / <factor> ::= <ident> | <number> | ( <expression> )

PL/0 GrammarNon-Terminals

<program> <block> <const-decl> <var-decl> <proc-decl> <statement> <const-assignment-list> <ident> <number > <ident-list> <expression> <statement-list> <condition> <relation> <term> <adding-operator> <factor> <multiplying-operator>

Terminals

const, var, procedure, call, begin, end, if, then, while, do, odd

<> < > <= >= + - * / =

, ; e

We must implement a procedure for each one of this non-terminals.

In this parser we use:• TOKEN –a global variable that stores the current

token to analyze.• GET_TOKEN() – a procedure that takes the next

token in the string and stores it in TOKEN.• ENTER(type, name, params) – a procedure that

stores a new symbol into the Symbol Table.• ERROR() – a procedure that stops parsing, and shows

an error message.

<program> Procedure

procedure PROGRAM;begin

GET_TOKEN();BLOCK();if TOKEN <> "." then ERROR (No Period at end of file)

end;

<program> ::= <block> .

<block> Procedure

procedure BLOCK;begin

if TOKEN = “const” then CONST-DECL();if TOKEN = “var” then VAR-DECL();if TOKEN = “procedure” then PROC-DECL();STATEMENT;

end;

<block> ::= <const-decl> <var-decl> <proc-decl> <statement>

<const-decl> Procedure

procedure CONST-DECL;begin

repeatGET_TOKEN;if TOKEN <> IDENT then ERROR (missing identifier);GET_TOKEN;if TOKEN <> "=" then ERROR (identifier should be followed by =);GET_TOKEN;if TOKEN <> NUMBER then ERROR (= should be followed by number);ENTER(constant, ident, number);GET_TOKEN;

until TOKEN <> ",";if TOKEN <> ";" then ERROR (declaration must end with ;);GET_TOKEN;

end;

<const-decl> ::= const <const-assignment-list> ; | e<const-assignment-list> ::= <ident> = <number> | <const-assignment-list> , <ident> = <number>

<var-decl> Procedure

procedure VAR-DECL;begin

repeatGET_TOKEN;

if TOKEN <> IDENT then ERROR (missing identifier);GET_TOKEN;ENTER(variable, ident, level);

until TOKEN <> ",";if TOKEN <> ";" then ERROR (declaration must end with ;);GET_TOKEN;

end;

<var-decl> ::= var <ident-list> ; | e<ident-list> ::= <ident> | <ident-list> , <ident>

<proc-decl> Procedure

procedure PROC-DECL;begin while TOKEN = "procedure" do begin GET_TOKEN;

if TOKEN <> IDENT then ERROR (missing procedure declaration);ENTER(procedure, ident);GET_TOKEN;if TOKEN <> ";" then ERROR (procedure declaration must end with ;);GET_TOKEN;BLOCK(level+1);if TOKEN <> ";" then ERROR (no ; at the end of block);GET_TOKEN;

end;end;

<proc-decl> ::= <proc-decl> procedure <ident> ; <block> ; | e

<statement> Procedure

procedure STATEMENT;begin

if TOKEN = IDENT then beginGET_TOKEN();If TOKEN <> ":=" then ERROR (:= missing in statement);GET_TOKEN();EXPRESSION();

endelse if TOKEN = "call" then begin

GET_TOKEN();if TOKEN <> IDENT then ERROR (missing identifier);GET_TOKEN();

end…

<statement> ::= <ident> := <expression> | call <ident> | begin <statement-list> end | if <condition> then <statement> | while <condition> do <statement> | e<statement-list> ::= <statement> | <statement-list> ; <statement>

<statement> Procedure

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then ERROR (begin must be closed with end);GET_TOKEN();

end;…

<statement> ::= <ident> := <expression> | call <ident> | begin <statement-list> end | if <condition> then <statement> | while <condition> do <statement> | e<statement-list> ::= <statement> | <statement-list> ; <statement>

<statement> Procedure

procedure STATEMENT;…

else if TOKEN = "if" then beginGET_TOKEN();CONDITION();if TOKEN <> "then" then ERROR (if condition must be followed by then);GET_TOKEN();STATEMENT();

end;…

<statement> ::= <ident> := <expression> | call <ident> | begin <statement-list> end | if <condition> then <statement> | while <condition> do <statement> | e<statement-list> ::= <statement> | <statement-list> ; <statement>

<statement> Procedure

procedure STATEMENT;…

else if TOKEN = "while" then beginGET_TOKEN();CONDITION();if TOKEN <> "do" then ERROR (while condition must be followed by do);GET_TOKEN();STATEMENT();

endend;

<statement> ::= <ident> := <expression> | call <ident> | begin <statement-list> end | if <condition> then <statement> | while <condition> do <statement> | e<statement-list> ::= <statement> | <statement-list> ; <statement>

<condition> Procedure

procedure CONDITION;begin

if TOKEN = "odd" then beginGET_TOKEN();EXPRESSION();

else beginEXPRESSION();if TOKEN <> RELATION then ERROR (relational operator missing in conditional

statement);GET_TOKEN();EXPRESSION();

endend;

<condition> ::= odd <expression> | <expression> <relation> <expression>

<expression> Procedure

procedure EXPRESSION;begin

if TOKEN = ADDING_OPERATOR then GET_TOKEN();TERM();while TOKEN = ADDING_OPERATOR do begin

GET_TOKEN();TERM();

endend;

<expression> ::= <term> | <adding-operator> <term> | <expression> <adding-operator> <term>

<term> Procedure

procedure TERM;begin

FACTOR();while TOKEN = MULTIPLYING_OPERATOR do begin

GET_TOKEN();FACTOR();

endend;

<term> ::= <factor> | <term> <multiplying-operator> <factor>

<factor> Procedure

procedure FACTOR;begin

if TOKEN = IDENTIFIER thenGET_TOKEN();

else if TOKEN = NUMBER thenGET_TOKEN();

else if TOKEN = "(" then beginGET_TOKEN();EXPRESSION();if TOKEN <> ")" then ERROR( left ( has not been closed );GET_TOKEN();

endelse ERROR (identifier, ( or number expected);

end;

<factor> ::= <ident> | <number> | ( <expression> )

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

procedure PROGRAM;begin

GET_TOKEN();BLOCK();if TOKEN <> "." then ERROR (No

Period at end of file)end;

program()TOKEN=

Recursion stack

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

procedure PROGRAM;begin

GET_TOKEN();BLOCK();if TOKEN <> "." then ERROR (No

Period at end of file)end;

program()TOKEN= const

Recursion stack

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block()

TOKEN= const

procedure BLOCK;begin

if TOKEN = “const” then CONST-DECL();if TOKEN = “var” then VAR-DECL();if TOKEN = “procedure” then PROC-DECL();STATEMENT;

end;

Recursion stack

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block()const-decl()

TOKEN= const

procedure CONST-DECL;begin

repeatGET_TOKEN();if TOKEN <> IDENT then

ERROR ();GET_TOKEN();if TOKEN <> "=" then ERROR

();GET_TOKEN();if TOKEN <> NUMBER then

ERROR);ENTER(constant, ident,

number);GET_TOKEN();

until TOKEN <> ",";if TOKEN <> ";" then ERROR ();GET_TOKEN;

end;

Recursion stack

Symbol Table

procedure CONST-DECL;begin

repeatGET_TOKEN();if TOKEN <> IDENT then

ERROR ();GET_TOKEN();if TOKEN <> "=" then ERROR

();GET_TOKEN();if TOKEN <> NUMBER then

ERROR);ENTER(constant, ident,

number);GET_TOKEN();

until TOKEN <> ",";if TOKEN <> ";" then ERROR ();GET_TOKEN;

end;

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block()const-decl()

TOKEN= m

Recursion stack

Symbol Table

procedure CONST-DECL;begin

repeatGET_TOKEN();if TOKEN <> IDENT then

ERROR ();GET_TOKEN();if TOKEN <> "=" then ERROR

();GET_TOKEN();if TOKEN <> NUMBER then

ERROR);ENTER(constant, ident,

number);GET_TOKEN();

until TOKEN <> ",";if TOKEN <> ";" then ERROR ();GET_TOKEN;

end;

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block()const-decl()

TOKEN= =

Recursion stack

Symbol Table

procedure CONST-DECL;begin

repeatGET_TOKEN();if TOKEN <> IDENT then

ERROR ();GET_TOKEN();if TOKEN <> "=" then ERROR

();GET_TOKEN();if TOKEN <> NUMBER then

ERROR);ENTER(constant, ident,

number);GET_TOKEN();

until TOKEN <> ",";if TOKEN <> ";" then ERROR ();GET_TOKEN;

end;

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block()const-decl()

TOKEN= 8

Recursion stack

Symbol Table

procedure CONST-DECL;begin

repeatGET_TOKEN();if TOKEN <> IDENT then

ERROR ();GET_TOKEN();if TOKEN <> "=" then ERROR

();GET_TOKEN();if TOKEN <> NUMBER then

ERROR);ENTER(constant, ident,

number);GET_TOKEN();

until TOKEN <> ",";if TOKEN <> ";" then ERROR ();GET_TOKEN;

end;

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block()const-decl()

TOKEN= 8

Recursion stack

m=8;

Symbol Table

procedure CONST-DECL;begin

repeatGET_TOKEN();if TOKEN <> IDENT then

ERROR ();GET_TOKEN();if TOKEN <> "=" then ERROR

();GET_TOKEN();if TOKEN <> NUMBER then

ERROR);ENTER(constant, ident,

number);GET_TOKEN();

until TOKEN <> ",";if TOKEN <> ";" then ERROR ();GET_TOKEN();

end;

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block()const-decl()

TOKEN= ;

Recursion stack

m=8;

Symbol Table

procedure CONST-DECL;begin

repeatGET_TOKEN();if TOKEN <> IDENT then

ERROR ();GET_TOKEN();if TOKEN <> "=" then ERROR

();GET_TOKEN();if TOKEN <> NUMBER then

ERROR);ENTER(constant, ident,

number);GET_TOKEN();

until TOKEN <> ",";if TOKEN <> ";" then ERROR ();GET_TOKEN();

end;

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block()const-decl()

TOKEN= var

Recursion stack

m=8;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block()

TOKEN= var

procedure BLOCK;begin

if TOKEN = “const” then CONST-DECL();if TOKEN = “var” then VAR-DECL();if TOKEN = “procedure” then PROC-DECL();STATEMENT;

end;

Recursion stack

m=8;

Symbol Table

procedure VAR-DECL;begin

repeatGET_TOKEN();

if TOKEN <> IDENT then ERROR ();

GET_TOKEN();ENTER(variable, ident, level);

until TOKEN <> ",";if TOKEN <> ";" then ERROR ();GET_TOKEN();

end;

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block()var-decl()

TOKEN= var

Recursion stack

m=8;

Symbol Table

procedure VAR-DECL;begin

repeatGET_TOKEN();

if TOKEN <> IDENT then ERROR ();

GET_TOKEN();ENTER(variable, ident, level);

until TOKEN <> ",";if TOKEN <> ";" then ERROR ();GET_TOKEN();

end;

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block()var-decl()

TOKEN= a

Recursion stack

m=8;

Symbol Table

procedure VAR-DECL;begin

repeatGET_TOKEN();

if TOKEN <> IDENT then ERROR ();

GET_TOKEN();ENTER(variable, ident, level);

until TOKEN <> ",";if TOKEN <> ";" then ERROR ();GET_TOKEN();

end;

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block()var-decl()

TOKEN= ,

Recursion stack

m=8;

Symbol Table

procedure VAR-DECL;begin

repeatGET_TOKEN();

if TOKEN <> IDENT then ERROR ();

GET_TOKEN();ENTER(variable, ident, level);

until TOKEN <> ",";if TOKEN <> ";" then ERROR ();GET_TOKEN();

end;

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block()var-decl()

TOKEN= ,

Recursion stack

m=8; a;

Symbol Table

procedure VAR-DECL;begin

repeatGET_TOKEN();

if TOKEN <> IDENT then ERROR ();

GET_TOKEN();ENTER(variable, ident, level);

until TOKEN <> ",";if TOKEN <> ";" then ERROR ();GET_TOKEN();

end;

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block()var-decl()

TOKEN= b

Recursion stack

m=8; a;

Symbol Table

procedure VAR-DECL;begin

repeatGET_TOKEN();

if TOKEN <> IDENT then ERROR ();

GET_TOKEN();ENTER(variable, ident, level);

until TOKEN <> ",";if TOKEN <> ";" then ERROR ();GET_TOKEN();

end;

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block()var-decl()

TOKEN= ,

Recursion stack

m=8; a;

Symbol Table

procedure VAR-DECL;begin

repeatGET_TOKEN();

if TOKEN <> IDENT then ERROR ();

GET_TOKEN();ENTER(variable, ident, level);

until TOKEN <> ",";if TOKEN <> ";" then ERROR ();GET_TOKEN();

end;

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block()var-decl()

TOKEN= ,

Recursion stack

m=8; a; b;

Symbol Table

procedure VAR-DECL;begin

repeatGET_TOKEN();

if TOKEN <> IDENT then ERROR ();

GET_TOKEN();ENTER(variable, ident, level);

until TOKEN <> ",";if TOKEN <> ";" then ERROR ();GET_TOKEN();

end;

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block()var-decl()

TOKEN= c

Recursion stack

m=8; a; b;

Symbol Table

procedure VAR-DECL;begin

repeatGET_TOKEN();

if TOKEN <> IDENT then ERROR ();

GET_TOKEN();ENTER(variable, ident, level);

until TOKEN <> ",";if TOKEN <> ";" then ERROR ();GET_TOKEN();

end;

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block()var-decl()

TOKEN= ;

Recursion stack

m=8; a; b;

Symbol Table

procedure VAR-DECL;begin

repeatGET_TOKEN();

if TOKEN <> IDENT then ERROR ();

GET_TOKEN();ENTER(variable, ident, level);

until TOKEN <> ",";if TOKEN <> ";" then ERROR ();GET_TOKEN();

end;

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block()var-decl()

TOKEN= ;

Recursion stack

m=8; a; b; c;

Symbol Table

procedure VAR-DECL;begin

repeatGET_TOKEN();

if TOKEN <> IDENT then ERROR ();

GET_TOKEN();ENTER(variable, ident, level);

until TOKEN <> ",";if TOKEN <> ";" then ERROR ();GET_TOKEN();

end;

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block()var-decl()

TOKEN= procedure

Recursion stack

m=8; a; b; c;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block()

TOKEN= procedure

procedure BLOCK;begin

if TOKEN = “const” then CONST-DECL();if TOKEN = “var” then VAR-DECL();if TOKEN = “procedure” then PROC-DECL();STATEMENT;

end;

Recursion stack

m=8; a; b; c;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block()proc-decl()

TOKEN= procedure

procedure PROC-DECL;begin while TOKEN = "procedure" do begin GET_TOKEN();

if TOKEN <> IDENT then ERROR ();ENTER(procedure, ident);GET_TOKEN();if TOKEN <> ";" then ERROR ();GET_TOKEN();BLOCK(level+1);if TOKEN <> ";" then ERROR ();GET_TOKEN();

end;end;

Recursion stack

m=8; a; b; c;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block()proc-decl()

TOKEN= ratio

procedure PROC-DECL;begin while TOKEN = "procedure" do begin GET_TOKEN();

if TOKEN <> IDENT then ERROR ();ENTER(procedure, ident);GET_TOKEN();if TOKEN <> ";" then ERROR ();GET_TOKEN();BLOCK(level+1);if TOKEN <> ";" then ERROR ();GET_TOKEN();

end;end;

Recursion stack

m=8; a; b; c;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block()proc-decl()

TOKEN= ratio

procedure PROC-DECL;begin while TOKEN = "procedure" do begin GET_TOKEN();

if TOKEN <> IDENT then ERROR ();ENTER(procedure, ident);GET_TOKEN();if TOKEN <> ";" then ERROR ();GET_TOKEN();BLOCK(level+1);if TOKEN <> ";" then ERROR ();GET_TOKEN();

end;end;

Recursion stack

m=8; a; b; c; ratio;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block()proc-decl()

TOKEN= ;

procedure PROC-DECL;begin while TOKEN = "procedure" do begin GET_TOKEN();

if TOKEN <> IDENT then ERROR ();ENTER(procedure, ident);GET_TOKEN();if TOKEN <> ";" then ERROR ();GET_TOKEN();BLOCK(level+1);if TOKEN <> ";" then ERROR ();GET_TOKEN();

end;end;

Recursion stack

m=8; a; b; c; ratio;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block()proc-decl()

TOKEN= var

procedure PROC-DECL;begin while TOKEN = "procedure" do begin GET_TOKEN();

if TOKEN <> IDENT then ERROR ();ENTER(procedure, ident);GET_TOKEN();if TOKEN <> ";" then ERROR ();GET_TOKEN();BLOCK(level+1);if TOKEN <> ";" then ERROR ();GET_TOKEN();

end;end;

Recursion stack

m=8; a; b; c; ratio;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)

TOKEN= var

procedure BLOCK;begin

if TOKEN = “const” then CONST-DECL();if TOKEN = “var” then VAR-DECL();if TOKEN = “procedure” then PROC-

DECL();STATEMENT;

end;

Recursion stack

m=8; a; b; c; ratio;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)

TOKEN= var

procedure BLOCK;begin

if TOKEN = “const” then CONST-DECL();if TOKEN = “var” then VAR-DECL();if TOKEN = “procedure” then PROC-

DECL();STATEMENT;

end;

Recursion stack

m=8; a; b; c; ratio;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)var-decl(2)

TOKEN= var

procedure VAR-DECL;begin

repeatGET_TOKEN;

if TOKEN <> IDENT then ERROR ();

GET_TOKEN;ENTER(variable, ident, level);

until TOKEN <> ",";if TOKEN <> ";" then ERROR ();GET_TOKEN;

end;

Recursion stack

m=8; a; b; c; ratio;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)var-decl(2)

TOKEN= x

procedure VAR-DECL;begin

repeatGET_TOKEN;

if TOKEN <> IDENT then ERROR ();

GET_TOKEN;ENTER(variable, ident, level);

until TOKEN <> ",";if TOKEN <> ";" then ERROR ();GET_TOKEN;

end;

Recursion stack

m=8; a; b; c; ratio;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)var-decl(2)

TOKEN= ,

procedure VAR-DECL;begin

repeatGET_TOKEN;

if TOKEN <> IDENT then ERROR ();

GET_TOKEN;ENTER(variable, ident, level);

until TOKEN <> ",";if TOKEN <> ";" then ERROR ();GET_TOKEN;

end;

Recursion stack

m=8; a; b; c; ratio;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)var-decl(2)

TOKEN= ,

procedure VAR-DECL;begin

repeatGET_TOKEN;

if TOKEN <> IDENT then ERROR ();

GET_TOKEN;ENTER(variable, ident, level);

until TOKEN <> ",";if TOKEN <> ";" then ERROR ();GET_TOKEN;

end;

Recursion stack

m=8; a; b; c; ratio; x;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)var-decl(2)

TOKEN= y

procedure VAR-DECL;begin

repeatGET_TOKEN;

if TOKEN <> IDENT then ERROR ();

GET_TOKEN;ENTER(variable, ident, level);

until TOKEN <> ",";if TOKEN <> ";" then ERROR ();GET_TOKEN;

end;

Recursion stack

m=8; a; b; c; ratio; x;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)var-decl(2)

TOKEN= ;

procedure VAR-DECL;begin

repeatGET_TOKEN;

if TOKEN <> IDENT then ERROR ();

GET_TOKEN;ENTER(variable, ident, level);

until TOKEN <> ",";if TOKEN <> ";" then ERROR ();GET_TOKEN;

end;

Recursion stack

m=8; a; b; c; ratio; x;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)var-decl(2)

TOKEN= ;

procedure VAR-DECL;begin

repeatGET_TOKEN;

if TOKEN <> IDENT then ERROR ();

GET_TOKEN;ENTER(variable, ident, level);

until TOKEN <> ",";if TOKEN <> ";" then ERROR ();GET_TOKEN;

end;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)var-decl(2)

TOKEN= begin

procedure VAR-DECL;begin

repeatGET_TOKEN;

if TOKEN <> IDENT then ERROR ();

GET_TOKEN;ENTER(variable, ident, level);

until TOKEN <> ",";if TOKEN <> ";" then ERROR ();GET_TOKEN;

end;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)

TOKEN= begin

procedure BLOCK;begin

if TOKEN = “const” then CONST-DECL();if TOKEN = “var” then VAR-DECL();if TOKEN = “procedure” then PROC-

DECL();STATEMENT;

end;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)

TOKEN= begin

procedure BLOCK;begin

if TOKEN = “const” then CONST-DECL();if TOKEN = “var” then VAR-DECL();if TOKEN = “procedure” then PROC-

DECL();STATEMENT;

end;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)

TOKEN= begin

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)

TOKEN= x

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)

TOKEN= x

procedure STATEMENT;begin

if TOKEN = IDENT then beginGET_TOKEN();If TOKEN <> ":=" then ERROR

();GET_TOKEN();EXPRESSION();

end…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)

TOKEN= =

procedure STATEMENT;begin

if TOKEN = IDENT then beginGET_TOKEN();If TOKEN <> ":=" then ERROR

();GET_TOKEN();EXPRESSION();

end…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)

TOKEN= a

procedure STATEMENT;begin

if TOKEN = IDENT then beginGET_TOKEN();If TOKEN <> ":=" then ERROR

();GET_TOKEN();EXPRESSION();

end…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)expression(2)

TOKEN= a

procedure EXPRESSION;begin

if TOKEN = ADDING_OPERATOR then GET_TOKEN();

TERM();while TOKEN = ADDING_OPERATOR do begin

GET_TOKEN();TERM();

endend;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)expression(2)term(2)

TOKEN= a

procedure TERM;begin

FACTOR();while TOKEN = MULTIPLYING_OPERATOR do

beginGET_TOKEN();FACTOR();

endend;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)expression(2)term(2)factor(2)

TOKEN= a

procedure FACTOR;begin

if TOKEN = IDENTIFIER thenGET_TOKEN();

else if TOKEN = NUMBER thenGET_TOKEN();

else if TOKEN = "(" then beginGET_TOKEN();EXPRESSION();if TOKEN <> ")" then ERROR );GET_TOKEN();

endelse ERROR ();

end;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)expression(2)term(2)factor(2)

TOKEN= ;

procedure FACTOR;begin

if TOKEN = IDENTIFIER thenGET_TOKEN();

else if TOKEN = NUMBER thenGET_TOKEN();

else if TOKEN = "(" then beginGET_TOKEN();EXPRESSION();if TOKEN <> ")" then ERROR );GET_TOKEN();

endelse ERROR ();

end;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)expression(2)term(2)

TOKEN= ;

procedure TERM;begin

FACTOR();while TOKEN = MULTIPLYING_OPERATOR do

beginGET_TOKEN();FACTOR();

endend;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)expression(2)

TOKEN= ;

procedure EXPRESSION;begin

if TOKEN = ADDING_OPERATOR then GET_TOKEN();

TERM();while TOKEN = ADDING_OPERATOR do begin

GET_TOKEN();TERM();

endend;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)

TOKEN= ;

procedure STATEMENT;begin

if TOKEN = IDENT then beginGET_TOKEN();If TOKEN <> ":=" then ERROR

();GET_TOKEN();EXPRESSION();

end…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)

TOKEN= ;

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)

TOKEN= ;

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)

TOKEN= y

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)

TOKEN= y

procedure STATEMENT;begin

if TOKEN = IDENT then beginGET_TOKEN();If TOKEN <> ":=" then ERROR

();GET_TOKEN();EXPRESSION();

end…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)

TOKEN= =

procedure STATEMENT;begin

if TOKEN = IDENT then beginGET_TOKEN();If TOKEN <> ":=" then ERROR

();GET_TOKEN();EXPRESSION();

end…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)

TOKEN= b

procedure STATEMENT;begin

if TOKEN = IDENT then beginGET_TOKEN();If TOKEN <> ":=" then ERROR

();GET_TOKEN();EXPRESSION();

end…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)expression(2)

TOKEN= b

procedure EXPRESSION;begin

if TOKEN = ADDING_OPERATOR then GET_TOKEN();

TERM();while TOKEN = ADDING_OPERATOR do begin

GET_TOKEN();TERM();

endend;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)expression(2)term(2)

TOKEN= b

procedure TERM;begin

FACTOR();while TOKEN = MULTIPLYING_OPERATOR do

beginGET_TOKEN();FACTOR();

endend;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)expression(2)term(2)factor(2)

TOKEN= b

procedure FACTOR;begin

if TOKEN = IDENTIFIER thenGET_TOKEN();

else if TOKEN = NUMBER thenGET_TOKEN();

else if TOKEN = "(" then beginGET_TOKEN();EXPRESSION();if TOKEN <> ")" then ERROR );GET_TOKEN();

endelse ERROR ();

end;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)expression(2)term(2)factor(2)

TOKEN= ;

procedure FACTOR;begin

if TOKEN = IDENTIFIER thenGET_TOKEN();

else if TOKEN = NUMBER thenGET_TOKEN();

else if TOKEN = "(" then beginGET_TOKEN();EXPRESSION();if TOKEN <> ")" then ERROR );GET_TOKEN();

endelse ERROR ();

end;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)expression(2)term(2)

TOKEN= ;

procedure TERM;begin

FACTOR();while TOKEN = MULTIPLYING_OPERATOR do

beginGET_TOKEN();FACTOR();

endend;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)expression(2)

TOKEN= ;

procedure EXPRESSION;begin

if TOKEN = ADDING_OPERATOR then GET_TOKEN();

TERM();while TOKEN = ADDING_OPERATOR do begin

GET_TOKEN();TERM();

endend;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)

TOKEN= ;

procedure STATEMENT;begin

if TOKEN = IDENT then beginGET_TOKEN();If TOKEN <> ":=" then ERROR

();GET_TOKEN();EXPRESSION();

end…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)

TOKEN= ;

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)

TOKEN= ;

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)

TOKEN= if

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)

TOKEN= if

procedure STATEMENT;…

else if TOKEN = "if" then beginGET_TOKEN();CONDITION();if TOKEN <> "then" then

ERROR ();GET_TOKEN();STATEMENT();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)

TOKEN= b

procedure STATEMENT;…

else if TOKEN = "if" then beginGET_TOKEN();CONDITION();if TOKEN <> "then" then

ERROR ();GET_TOKEN();STATEMENT();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)condition(2)

TOKEN= b

procedure CONDITION;begin

if TOKEN = "odd" then beginGET_TOKEN();EXPRESSION();

else beginEXPRESSION();if TOKEN <> RELATION then

ERROR ();GET_TOKEN();EXPRESSION();

endend;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)condition(2)

TOKEN= b

procedure CONDITION;begin

if TOKEN = "odd" then beginGET_TOKEN();EXPRESSION();

else beginEXPRESSION();if TOKEN <> RELATION then

ERROR ();GET_TOKEN();EXPRESSION();

endend;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)condition(2)

TOKEN= >

procedure CONDITION;begin

if TOKEN = "odd" then beginGET_TOKEN();EXPRESSION();

else beginEXPRESSION();if TOKEN <> RELATION then

ERROR ();GET_TOKEN();EXPRESSION();

endend;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)condition(2)

TOKEN= a

procedure CONDITION;begin

if TOKEN = "odd" then beginGET_TOKEN();EXPRESSION();

else beginEXPRESSION();if TOKEN <> RELATION then

ERROR ();GET_TOKEN();EXPRESSION();

endend;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)condition(2)

TOKEN= then

procedure CONDITION;begin

if TOKEN = "odd" then beginGET_TOKEN();EXPRESSION();

else beginEXPRESSION();if TOKEN <> RELATION then

ERROR ();GET_TOKEN();EXPRESSION();

endend;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)

TOKEN= then

procedure STATEMENT;…

else if TOKEN = "if" then beginGET_TOKEN();CONDITION();if TOKEN <> "then" then

ERROR ();GET_TOKEN();STATEMENT();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)

TOKEN= begin

procedure STATEMENT;…

else if TOKEN = "if" then beginGET_TOKEN();CONDITION();if TOKEN <> "then" then

ERROR ();GET_TOKEN();STATEMENT();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)statement(2)

TOKEN= begin

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)statement(2)

TOKEN= x

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)statement(2)

TOKEN= ;

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)statement(2)

TOKEN= y

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)statement(2)

TOKEN= ;

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)statement(2)

TOKEN= ;

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)statement(2)

TOKEN= end

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

end;c = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)statement(2)

TOKEN= end

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

end;c = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)statement(2)

TOKEN= ;

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

end;c = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)

TOKEN= ;

procedure STATEMENT;…

else if TOKEN = "if" then beginGET_TOKEN();CONDITION();if TOKEN <> "then" then

ERROR ();GET_TOKEN();STATEMENT();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

end;c = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)

TOKEN= ;

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

end;c = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)

TOKEN= ;

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

end;c = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)

TOKEN= c

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

end;c = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)

TOKEN= c

procedure STATEMENT;begin

if TOKEN = IDENT then beginGET_TOKEN();If TOKEN <> ":=" then ERROR);GET_TOKEN();EXPRESSION();

end

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

end;c = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)

TOKEN= =

procedure STATEMENT;begin

if TOKEN = IDENT then beginGET_TOKEN();If TOKEN <> ":=" then ERROR);GET_TOKEN();EXPRESSION();

end

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

end;c = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)

TOKEN= x

procedure STATEMENT;begin

if TOKEN = IDENT then beginGET_TOKEN();If TOKEN <> ":=" then ERROR);GET_TOKEN();EXPRESSION();

end

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

end;c = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)expression(2)

TOKEN= x

procedure EXPRESSION;begin

if TOKEN = ADDING_OPERATOR then GET_TOKEN();

TERM();while TOKEN = ADDING_OPERATOR do begin

GET_TOKEN();TERM();

endend;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

end;c = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)expression(2)term(2)

TOKEN= x

procedure TERM;begin

FACTOR();while TOKEN = MULTIPLYING_OPERATOR do

beginGET_TOKEN();FACTOR();

endend;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

end;c = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)expression(2)term(2)factor(2)

TOKEN= x

procedure FACTOR;begin

if TOKEN = IDENTIFIER thenGET_TOKEN();

else if TOKEN = NUMBER thenGET_TOKEN();

else if TOKEN = "(" then beginGET_TOKEN();EXPRESSION();if TOKEN <> ")" then ERROR ();GET_TOKEN();

endelse ERROR ();

end;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

end;c = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)expression(2)term(2)factor(2)

TOKEN= /

procedure FACTOR;begin

if TOKEN = IDENTIFIER thenGET_TOKEN();

else if TOKEN = NUMBER thenGET_TOKEN();

else if TOKEN = "(" then beginGET_TOKEN();EXPRESSION();if TOKEN <> ")" then ERROR ();GET_TOKEN();

endelse ERROR ();

end;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

end;c = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)expression(2)term(2)

TOKEN= /

procedure TERM;begin

FACTOR();while TOKEN = MULTIPLYING_OPERATOR do

beginGET_TOKEN();FACTOR();

endend;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

end;c = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)expression(2)term(2)

TOKEN= y

procedure TERM;begin

FACTOR();while TOKEN = MULTIPLYING_OPERATOR do

beginGET_TOKEN();FACTOR();

endend;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

end;c = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)expression(2)term(2)

TOKEN= ;

procedure TERM;begin

FACTOR();while TOKEN = MULTIPLYING_OPERATOR do

beginGET_TOKEN();FACTOR();

endend;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

end;c = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)expression(2)

TOKEN= ;

procedure EXPRESSION;begin

if TOKEN = ADDING_OPERATOR then GET_TOKEN();

TERM();while TOKEN = ADDING_OPERATOR do begin

GET_TOKEN();TERM();

endend;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

end;c = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)statement(2)

TOKEN= ;

procedure STATEMENT;begin

if TOKEN = IDENT then beginGET_TOKEN();If TOKEN <> ":=" then ERROR);GET_TOKEN();EXPRESSION();

end

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

end;c = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)

TOKEN= ;

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

end;c = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)

TOKEN= ;

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

end;c = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)

TOKEN= end

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

end;c = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)

TOKEN= end

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

end;c = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)statement(2)

TOKEN= ;

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)block(2)

TOKEN= ;

procedure BLOCK;begin

if TOKEN = “const” then CONST-DECL();if TOKEN = “var” then VAR-DECL();if TOKEN = “procedure” then PROC-

DECL();STATEMENT();

end;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)

TOKEN= ;

procedure PROC-DECL;begin while TOKEN = "procedure" do begin GET_TOKEN();

if TOKEN <> IDENT then ERROR ();ENTER(procedure, ident);GET_TOKEN();if TOKEN <> ";" then ERROR ();GET_TOKEN();BLOCK(level+1);if TOKEN <> ";" then ERROR ();GET_TOKEN();

end;end;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)proc-decl(1)

TOKEN= begin

procedure PROC-DECL;begin while TOKEN = "procedure" do begin GET_TOKEN();

if TOKEN <> IDENT then ERROR ();ENTER(procedure, ident);GET_TOKEN();if TOKEN <> ";" then ERROR ();GET_TOKEN();BLOCK(level+1);if TOKEN <> ";" then ERROR ();GET_TOKEN();

end;end;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)

TOKEN= begin

procedure BLOCK;begin

if TOKEN = “const” then CONST-DECL();if TOKEN = “var” then VAR-DECL();if TOKEN = “procedure” then PROC-DECL();STATEMENT;

end;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)statement(1)

TOKEN= begin

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)statement(1)

TOKEN= a

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)statement(1)

TOKEN= ;

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)statement(1)

TOKEN= ;

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)statement(1)

TOKEN= b

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)statement(1)

TOKEN= ;

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)statement(1)

TOKEN= call

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)statement(1)

TOKEN= ;

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)statement(1)

TOKEN= end

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)statement(1)

TOKEN= end

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)statement(1)

TOKEN= .

procedure STATEMENT;…

else if TOKEN = "begin" then beginGET TOKEN();STATEMENT();while TOKEN = ";" do begin

GET_TOKEN();STATEMENT();

end;if TOKEN <> "end" then

ERROR ();GET_TOKEN();

end;…

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

program()block(1)

TOKEN= .

procedure BLOCK;begin

if TOKEN = “const” then CONST-DECL();if TOKEN = “var” then VAR-DECL();if TOKEN = “procedure” then PROC-DECL();STATEMENT;

end;

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table

Small Exampleconst m = 8;var a, b, c;procedure ratio;var x, y;begin

x = a; y = b;if b > a then begin

x = b;y = a;

endc = x / y;

end;begin

a = m;b = 4;call ratio;

end.

procedure PROGRAM;begin

GET_TOKEN();BLOCK();if TOKEN <> "." then ERROR ()

end;

program()TOKEN= .

Recursion stack

m=8; a; b; c; ratio; x; y;

Symbol Table