Tiger Compiler Project Parsing, AST & Semantic Tiger Compiler Project By Mu Li
Phases Li, Mu (limu.cn@gmail.com) 2007-3-8
Preliminary We assume you are familiar with according theory backgrounds mentioned in dragon book (or tiger book) Li, Mu (limu.cn@gmail.com) 2007-3-8
Test your scanner Provided in LexerTest.java Li, Mu (limu.cn@gmail.com) 2007-3-8
Parsing Use CUP to implement the parser Easy Only grammar specification is needed Li, Mu (limu.cn@gmail.com) 2007-3-8
Grammar specification Terminals and non-terminals Precedences The grammar Li, Mu (limu.cn@gmail.com) 2007-3-8
The grammar Following the expressions defined in Tiger Manual … Li, Mu (limu.cn@gmail.com) 2007-3-8
Communication between CUP and Jflex (I) Notice %Cup in your tiger.flex, which make Jflex implement java_cup.runtime.Scanner Li, Mu (limu.cn@gmail.com) 2007-3-8
Communication between CUP and Jflex (II) Run CUP, parser.java and sym.java obtained More information, you should read the documents provided by Jflex and CUP Li, Mu (limu.cn@gmail.com) 2007-3-8
Test your parser Provided in CupTest.java Li, Mu (limu.cn@gmail.com) 2007-3-8
Abstract Syntax Tree (AST) (a := 5; a+1) can be translated into Li, Mu (limu.cn@gmail.com) 2007-3-8
Construte AST (I) Tree’s nodes are defined in tiger.absyn Your should make your compiler know the structure by CUP … Li, Mu (limu.cn@gmail.com) 2007-3-8
Constructe AST (II) OpExp defined as: Li, Mu (limu.cn@gmail.com) 2007-3-8
Printing AST Using class tiger.absyn.Print Li, Mu (limu.cn@gmail.com) 2007-3-8
Semantic Check type Li, Mu (limu.cn@gmail.com) 2007-3-8
Error code (I) let type a=b type b=c type c=int var x:a:=3 in a:=“hello world” end Li, Mu (limu.cn@gmail.com) 2007-3-8
Error code (II) let type a=b type b=c type c=a …… in end Li, Mu (limu.cn@gmail.com) 2007-3-8
Error code (III) let function g (a:int , b:string):int = a in g("one") end Li, Mu (limu.cn@gmail.com) 2007-3-8
Error code (IV) let type arrtype = array of int type rectype = {name:string, id: int} var rec := rectype {name="aname", id=0} var arr := arrtype [3] of 0 in if rec <> arr then 3 else 4 end Li, Mu (limu.cn@gmail.com) 2007-3-8
Error code (V) for i:=10 to " " do i := i - 1 Li, Mu (limu.cn@gmail.com) 2007-3-8
Implement (I) Li, Mu (limu.cn@gmail.com) 2007-3-8
Implement (II) Li, Mu (limu.cn@gmail.com) 2007-3-8
Implement (III) Li, Mu (limu.cn@gmail.com) 2007-3-8
Check the types Li, Mu (limu.cn@gmail.com) 2007-3-8
Midterm submit You should print the AST and check the types The specification is on our website Deadline is 30th Mar. NO cheating! Li, Mu (limu.cn@gmail.com) 2007-3-8