Parsing, AST & Semantic
description
Transcript of Parsing, AST & Semantic
Tiger Compiler Project
By Mu Li
2007-3-8Li, Mu ([email protected]) 2
We assume you are familiar with according theory backgrounds mentioned in dragon book (or tiger book)
2007-3-8Li, Mu ([email protected]) 3
Provided in LexerTest.java
2007-3-8Li, Mu ([email protected]) 4
Use CUP to implement the parser◦Easy◦Only grammar specification is needed
2007-3-8Li, Mu ([email protected]) 5
Notice %Cup in your tiger.flex, which make Jflex implement java_cup.runtime.Scanner
2007-3-8Li, Mu ([email protected]) 8
Run CUP, parser.java and sym.java obtained
More information, you should read the documents provided by Jflex and CUP
2007-3-8Li, Mu ([email protected]) 9
Provided in CupTest.java
2007-3-8Li, Mu ([email protected]) 10
(a := 5; a+1) can be translated into
2007-3-8Li, Mu ([email protected]) 11
Tree’s nodes are defined in tiger.absyn
Your should make your compiler know the structure by CUP
2007-3-8Li, Mu ([email protected]) 12
…
…
OpExp defined as:
2007-3-8Li, Mu ([email protected]) 13
Using class tiger.absyn.Print
2007-3-8Li, Mu ([email protected]) 14
Check type
2007-3-8Li, Mu ([email protected]) 15
let type a=btype b=ctype c=intvar x:a:=3
in a:=“hello world”
end
2007-3-8Li, Mu ([email protected]) 16
let
type arrtype = array of inttype rectype = {name:string, id: int}
var rec := rectype {name="aname", id=0}var arr := arrtype [3] of 0
inif rec <> arr then 3 else 4
end
2007-3-8Li, Mu ([email protected]) 19
for i:=10 to " " do i := i - 1
2007-3-8Li, Mu ([email protected]) 20
2007-3-8Li, Mu ([email protected]) 21
2007-3-8Li, Mu ([email protected]) 22
2007-3-8Li, Mu ([email protected]) 23
2007-3-8Li, Mu ([email protected]) 24
You should print the AST and check the types
The specification is on our website Deadline is 30th Mar. NO cheating!
2007-3-8Li, Mu ([email protected]) 25