Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tiger Compiler Project

Similar presentations


Presentation on theme: "Tiger Compiler Project"— Presentation transcript:

1 Tiger Compiler Project
Parsing, AST & Semantic Tiger Compiler Project By Mu Li

2 Phases Li, Mu

3 Preliminary We assume you are familiar with according theory backgrounds mentioned in dragon book (or tiger book) Li, Mu

4 Test your scanner Provided in LexerTest.java
Li, Mu

5 Parsing Use CUP to implement the parser Easy
Only grammar specification is needed Li, Mu

6 Grammar specification
Terminals and non-terminals Precedences The grammar Li, Mu

7 The grammar Following the expressions defined in Tiger Manual …
Li, Mu

8 Communication between CUP and Jflex (I)
Notice %Cup in your tiger.flex, which make Jflex implement java_cup.runtime.Scanner Li, Mu

9 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

10 Test your parser Provided in CupTest.java Li, Mu (limu.cn@gmail.com)

11 Abstract Syntax Tree (AST)
(a := 5; a+1) can be translated into Li, Mu

12 Construte AST (I) Tree’s nodes are defined in tiger.absyn
Your should make your compiler know the structure by CUP Li, Mu

13 Constructe AST (II) OpExp defined as: Li, Mu (limu.cn@gmail.com)

14 Printing AST Using class tiger.absyn.Print Li, Mu (limu.cn@gmail.com)

15 Semantic Check type Li, Mu

16 Error code (I) let type a=b type b=c type c=int var x:a:=3 in
a:=“hello world” end Li, Mu

17 Error code (II) let type a=b type b=c type c=a …… in end
Li, Mu

18 Error code (III) let function g (a:int , b:string):int = a in g("one")
end Li, Mu

19 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

20 Error code (V) for i:=10 to " " do i := i - 1
Li, Mu

21 Implement (I) Li, Mu

22 Implement (II) Li, Mu

23 Implement (III) Li, Mu

24 Check the types Li, Mu

25 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


Download ppt "Tiger Compiler Project"

Similar presentations


Ads by Google