PL/0 Parser
description
Transcript of PL/0 Parser
![Page 1: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/1.jpg)
PL/0 Parser
COP 3402 System SoftwareFall 2013
![Page 2: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/2.jpg)
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).
![Page 3: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/3.jpg)
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.
![Page 4: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/4.jpg)
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> )
![Page 5: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/5.jpg)
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.
![Page 6: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/6.jpg)
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.
![Page 7: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/7.jpg)
<program> Procedure
procedure PROGRAM;begin
GET_TOKEN();BLOCK();if TOKEN <> "." then ERROR (No Period at end of file)
end;
<program> ::= <block> .
![Page 8: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/8.jpg)
<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>
![Page 9: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/9.jpg)
<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>
![Page 10: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/10.jpg)
<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>
![Page 11: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/11.jpg)
<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
![Page 12: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/12.jpg)
<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>
![Page 13: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/13.jpg)
<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>
![Page 14: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/14.jpg)
<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>
![Page 15: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/15.jpg)
<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>
![Page 16: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/16.jpg)
<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>
![Page 17: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/17.jpg)
<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>
![Page 18: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/18.jpg)
<term> Procedure
procedure TERM;begin
FACTOR();while TOKEN = MULTIPLYING_OPERATOR do begin
GET_TOKEN();FACTOR();
endend;
<term> ::= <factor> | <term> <multiplying-operator> <factor>
![Page 19: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/19.jpg)
<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> )
![Page 20: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/20.jpg)
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
![Page 21: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/21.jpg)
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
![Page 22: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/22.jpg)
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
![Page 23: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/23.jpg)
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
![Page 24: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/24.jpg)
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
![Page 25: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/25.jpg)
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
![Page 26: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/26.jpg)
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
![Page 27: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/27.jpg)
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
![Page 28: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/28.jpg)
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
![Page 29: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/29.jpg)
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
![Page 30: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/30.jpg)
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
![Page 31: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/31.jpg)
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
![Page 32: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/32.jpg)
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
![Page 33: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/33.jpg)
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
![Page 34: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/34.jpg)
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
![Page 35: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/35.jpg)
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
![Page 36: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/36.jpg)
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
![Page 37: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/37.jpg)
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
![Page 38: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/38.jpg)
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
![Page 39: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/39.jpg)
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
![Page 40: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/40.jpg)
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
![Page 41: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/41.jpg)
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
![Page 42: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/42.jpg)
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
![Page 43: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/43.jpg)
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
![Page 44: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/44.jpg)
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
![Page 45: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/45.jpg)
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
![Page 46: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/46.jpg)
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
![Page 47: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/47.jpg)
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
![Page 48: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/48.jpg)
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
![Page 49: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/49.jpg)
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
![Page 50: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/50.jpg)
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
![Page 51: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/51.jpg)
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
![Page 52: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/52.jpg)
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
![Page 53: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/53.jpg)
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
![Page 54: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/54.jpg)
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
![Page 55: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/55.jpg)
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
![Page 56: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/56.jpg)
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
![Page 57: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/57.jpg)
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
![Page 58: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/58.jpg)
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
![Page 59: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/59.jpg)
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
![Page 60: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/60.jpg)
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
![Page 61: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/61.jpg)
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
![Page 62: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/62.jpg)
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
![Page 63: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/63.jpg)
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
![Page 64: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/64.jpg)
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
![Page 65: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/65.jpg)
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
![Page 66: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/66.jpg)
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
![Page 67: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/67.jpg)
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
![Page 68: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/68.jpg)
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
![Page 69: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/69.jpg)
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
![Page 70: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/70.jpg)
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
![Page 71: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/71.jpg)
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
![Page 72: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/72.jpg)
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
![Page 73: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/73.jpg)
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
![Page 74: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/74.jpg)
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
![Page 75: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/75.jpg)
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
![Page 76: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/76.jpg)
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
![Page 77: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/77.jpg)
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
![Page 78: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/78.jpg)
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
![Page 79: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/79.jpg)
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
![Page 80: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/80.jpg)
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
![Page 81: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/81.jpg)
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
![Page 82: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/82.jpg)
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
![Page 83: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/83.jpg)
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
![Page 84: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/84.jpg)
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
![Page 85: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/85.jpg)
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
![Page 86: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/86.jpg)
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
![Page 87: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/87.jpg)
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
![Page 88: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/88.jpg)
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
![Page 89: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/89.jpg)
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
![Page 90: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/90.jpg)
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
![Page 91: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/91.jpg)
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
![Page 92: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/92.jpg)
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
![Page 93: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/93.jpg)
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
![Page 94: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/94.jpg)
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
![Page 95: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/95.jpg)
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
![Page 96: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/96.jpg)
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
![Page 97: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/97.jpg)
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
![Page 98: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/98.jpg)
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
![Page 99: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/99.jpg)
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
![Page 100: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/100.jpg)
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
![Page 101: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/101.jpg)
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
![Page 102: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/102.jpg)
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
![Page 103: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/103.jpg)
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
![Page 104: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/104.jpg)
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
![Page 105: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/105.jpg)
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
![Page 106: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/106.jpg)
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
![Page 107: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/107.jpg)
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
![Page 108: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/108.jpg)
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
![Page 109: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/109.jpg)
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
![Page 110: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/110.jpg)
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
![Page 111: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/111.jpg)
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
![Page 112: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/112.jpg)
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
![Page 113: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/113.jpg)
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
![Page 114: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/114.jpg)
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
![Page 115: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/115.jpg)
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
![Page 116: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/116.jpg)
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
![Page 117: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/117.jpg)
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
![Page 118: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/118.jpg)
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
![Page 119: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/119.jpg)
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
![Page 120: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/120.jpg)
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
![Page 121: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/121.jpg)
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
![Page 122: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/122.jpg)
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
![Page 123: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/123.jpg)
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
![Page 124: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/124.jpg)
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
![Page 125: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/125.jpg)
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
![Page 126: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/126.jpg)
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
![Page 127: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/127.jpg)
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
![Page 128: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/128.jpg)
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
![Page 129: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/129.jpg)
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
![Page 130: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/130.jpg)
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
![Page 131: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/131.jpg)
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
![Page 132: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/132.jpg)
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
![Page 133: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/133.jpg)
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
![Page 134: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/134.jpg)
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
![Page 135: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/135.jpg)
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
![Page 136: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/136.jpg)
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
![Page 137: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/137.jpg)
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
![Page 138: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/138.jpg)
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
![Page 139: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/139.jpg)
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
![Page 140: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/140.jpg)
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
![Page 141: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/141.jpg)
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
![Page 142: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/142.jpg)
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
![Page 143: PL/0 Parser](https://reader031.fdocuments.us/reader031/viewer/2022020208/5681505f550346895dbe6163/html5/thumbnails/143.jpg)
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