程序代写代做代考 compiler The TINY Language

The TINY Language

The TINY Language

CS106 — Compiler Principles and Construction
Fall 2011

MUST FIT
Zhiyao Liang

TINY Dr. Zhiyao Liang
1

Sample Program in TINY (Figure 2.11)
{ sample.tny
A sample program in Tiny
language — computes factorial
}
read x; { input an integer}
if x > 0 then { don’t compute if x <= 0 } fact : = 1; repeat fact := fact * x; x := x -1 until x = 0 write fact { output factorial of x } end TINY Dr. Zhiyao Liang 2 Tokens of the TINY Language (Table 2.1) Reserved Words Special Symbols Other if + Number 1 or more digits then - else * end / repeat = Identifier 1 or more letters until < read ( write ) ; := TINY Dr. Zhiyao Liang 3 Informal Description of TINY Program (1.7.1) It is a sequence of statements separated by semicolons. No procedures and no declaration. All variables are of integer type. Variables are declared by assigning values to them. Only two control statements, if and repeat. if … end if … else…end repeat … until Input statement: read output statement: write TINY Dr. Zhiyao Liang 4 Informal Description of TINY Program (1.7.1) cont. Comments are surrounded by { and }. No nested comments. Only two kinds of expressions: Boolean expressions use < and = Only appears as tests in control statements Integer arithmetic expressions use +, -, *, / / is integer division. if and repeat may contain a statement sequence. The last statement in a statement sequence does not end with a semicolon. TINY Dr. Zhiyao Liang 5 DFA of the TINY scanner Scanning Dr. Zhiyao Liang 6 Some character need to be taken from input before DONE, such as =. In other cases, before done, the "other" character which is just read need to be pushed back to the input stream. 6 Syntax of TINY To be continued. TINY Dr. Zhiyao Liang 7 /docProps/thumbnail.jpeg