1 / 25

Parsing, AST & Semantic

Parsing, AST & Semantic. Tiger Compiler Project. By Mu Li. Phases. Preliminary. We assume you are familiar with according theory backgrounds mentioned in dragon book (or tiger book). Test your scanner. Provided in LexerTest.java. Parsing. Use CUP to implement the parser Easy

alden
Download Presentation

Parsing, AST & Semantic

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Phases Li, Mu (limu.cn@gmail.com)

  3. Preliminary • We assume you are familiar with according theory backgrounds mentioned in dragon book (or tiger book) Li, Mu (limu.cn@gmail.com)

  4. Test your scanner • Provided in LexerTest.java Li, Mu (limu.cn@gmail.com)

  5. Parsing • Use CUP to implement the parser • Easy • Only grammar specification is needed Li, Mu (limu.cn@gmail.com)

  6. Grammar specification • Terminals and non-terminals • Precedences • The grammar Li, Mu (limu.cn@gmail.com)

  7. The grammar • Following the expressions defined in Tiger Manual … Li, Mu (limu.cn@gmail.com)

  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)

  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 (limu.cn@gmail.com)

  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 (limu.cn@gmail.com)

  12. 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)

  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 (limu.cn@gmail.com)

  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 (limu.cn@gmail.com)

  17. Error code (II) let type a=b type b=c type c=a …… in …… end Li, Mu (limu.cn@gmail.com)

  18. Error code (III) let function g (a:int , b:string):int = a in g("one") end Li, Mu (limu.cn@gmail.com)

  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 (limu.cn@gmail.com)

  20. Error code (V) for i:=10 to " " do i := i - 1 Li, Mu (limu.cn@gmail.com)

  21. Implement (I) Li, Mu (limu.cn@gmail.com)

  22. Implement (II) Li, Mu (limu.cn@gmail.com)

  23. Implement (III) Li, Mu (limu.cn@gmail.com)

  24. Check the types Li, Mu (limu.cn@gmail.com)

  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 (limu.cn@gmail.com)

More Related