DOC PREVIEW
UD CISC 672 - Phase 2 Parser

This preview shows page 1-2-3 out of 9 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Phase 2ParserPhase 2.1Grammar and the .cup fileJava Cup• Cup is a LALR parser generator for Java (Look Ahead Left to Right)• It translates the grammar into Java code.• LR parsers were invented by Knuth in 1965 and are potentially the fastest parsers present.Basic Stepscool.cup• Run parser.JavaCupSym & CoolParser• Compile Sym.java & CoolParser.javatreeNodes.*• Flesh out the .java files for phase2.2Run parser.Parser• Get the AST dump. (yippie!)Cool.cup• Read sections 3 to 7 in the cool manual to understand the grammar. • The grammar here needs to be added to the .cup filee.g. CLASSESclass ::= CLASS TYPEID:n LBRACE feature_list:f RBRACE SEMI{: RESULT = new Class_(curr_lineno(), n, AbstractTable.idtable.addString("Object"), f, curr_filename()); :}| CLASS TYPEID:n INHERITS TYPEID:p LBRACE feature_list:f RBRACE SEMI{: RESULT = new Class_(curr_lineno(), n, p, f, curr_filename()); :} | CLASS OBJECTID error SEMI | CLASS error SEMI ;Phase 2.2Printing out the ast TreetreeNodes• Is a collection of grammatically significant terminals and non terminals.• The Parser generates the AST.• The root node is the node of type treeNode.Program.• Result. dumpWithTypes(out, 0) then calls others recursively.For Block.javapublic void dumpWithTypes(Writer out, int n) throws IOException {dumpLine(out, n);out.write(Utilities.pad(n) + "_block\n");for(AbstractExpression e : body) {e.dumpWithTypes(out, n + 2);}dumpType(out,


View Full Document

UD CISC 672 - Phase 2 Parser

Documents in this Course
Syllabus

Syllabus

18 pages

Load more
Download Phase 2 Parser
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Phase 2 Parser and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Phase 2 Parser 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?