Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
7):
To be determined
Time
Week 6,7,8
venue
Week 6,7,8
Due date
Experiment 1 Implementing a
Scanner for TINY+: by the end of
week 10(11.09)
1
2
3
4
TINY Compiler
Syntax description
A program is a sequence of
statements separated by semicolons
Declarations
No procedures and no declarations
Data Type
All variables are integer variables,
and variables are declared by
assigning values to them
Statement
Two control statements: if-statement and
repeat-statement, read and write statements
Expression
Boolean and integer arithmetic expressions
Comment
Comments are allowed within curly bracket
Example
{sample program in TINY languagecomputes factorial}
read x; { input an integer }
if 0<x then { dont compute if x<=0 }
fact:=1;
repeat
fact := fact*x;
x := x-1
until x=0;
write fact{output factorial of x}
end
Four-pass compiler
2. Implementation of a TINY
Scanner
Reserved Words
if then else end
repeat until
read write
Explanation:
All accepting states are collected into
one state DONE, the different token
recognized is saved in a variable
Construct a table of reserved words,
reserved words are considered only
after an identifier has been
recognized, and then to look up the
identifier in the table
The implementation of the DFA uses
the doubly nested case analysis
2 An if-statement
;
;
s
s
s
seq
s
3 A repeat-statement
4 An assign-statement
5 A write-statement
6 An operator-expression
4 A Recursive-Descent Parser
for TINY
For example
5: read x;
6: if x>0 then
7:
fact:=1;
8:
repeat
9:
fact:=fact*x;
10:
x:=x-1
11: until x=0;
12: write fact
13:end
The symbol table for this program
Variable
Name
x
5,6,9,10,10,11
top of memory
temp1
temp2
temp3
free
memory
w
z
y
x
3
2
1
0
bottom of memory
Runtime environment of TINY