DOC PREVIEW
CSU CS 453 - Study Guide

This preview shows page 1 out of 2 pages.

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

Unformatted text preview:

CS453 Intro and PA1 1CS453 Lecture MiniJava Intro 1Plan for Today Structure of the MiniJava Compiler– Lexer– Interface between lexer and parser: Symbol and TokenValue– Parser– Interface between parser and semantic analysis: ast.node.*– Interface between semantic analysis and code generation: symbol tableCS453 Lecture MiniJava Intro 2Structure of the MiniJava Compiler“sentences”SynthesisoptimizationAssem (MIPS)IR code generationAssem (MIPS)Analysischaracter streamlexical analysis“words”tokenssemantic analysissyntactic analysisASTAST and symbol tablecode genMIPSPA3PA4PA5PA6553CS453 Lecture MiniJava Intro 3Specifying Tokens with JFlex JFlex example input file: package mjparser; import java_cup.runtime.Symbol; %% %line %char %cup %public %eofval{ return new Symbol(sym.EOF, newTokenValue("EOF", yyline, yychar)); %eofval} LETTER=[A-Za-z] DIGIT=[0-9] UNDERSCORE="_" LETT_DIG_UND={LETTER}|{DIGIT}|{UNDERSCORE} ID={LETTER}({LETT_DIG_UND})* %% "&&" { return new Symbol(sym.AND, newTokenValue(yytext(), yyline, yychar)); } "boolean" {return newSymbol(sym.BOOLEAN,... {ID} { return new Symbol(sym.ID, new ...CS453 Lecture MiniJava Intro 4Specifying Grammar with JavaCUP JavaCUP example input file: package mjparser; import java_cup.runtime.*; import ast.node.*; ... terminal AND, ASSIGN, INT; terminal mjparser.TokenValue NUMBER; ... non terminal Program program; non terminal List<IClassDecl> class_decl_list; non terminal MainClass main_class; start with program; program ::= main_class:m class_decl_list:l {: RESULT = new Program(m,l); :} ; exp ::= | NUMBER:n {: Token token = new Token(n.text,n.line, n.pos); RESULT = new IntegerExp( token ); :} ...CS453 Intro and PA1 2CS453 Lecture MiniJava Intro 5Abstract Syntax Tree for Memory Layout ExampleCS453 Lecture MiniJava Intro 6Example Symbol Tableclass And { public static void main(String[] a){System.out.println(new Foo().testing(42)); }}class Foo { public int testing(int p) { int x; if (p < 10 && 2 < p) { x = 7; } else { x = 22; } return x;}}CS453 Lecture MiniJava Intro 7Assem(MIPS).textmain:main_framesize=24main_paramsNregsaves=8sw $ra, 0($sp)subu $sp, $sp, 4sw $fp, 0($sp)subu $sp, $sp, 4addu $fp, $sp, main_paramsNregsavessubu $sp, $fp, main_framesize# ExpCALL# ExpCONSTli $t2, 0sw $t2, -8($fp)lw $t2, -8($fp)# push parameter onto stacksw $t2, 0($sp)subu $sp, $sp, 4jal _halloc#StmMOVE(ExpTEMP(t1), e)move $t0, $v0sw $t0, -12($fp)# ExpCALLlw $t2, -12($fp)# push parameter onto stacksw $t2, 0($sp)subu $sp, $sp, 4# ExpCONSTli $t2, 42sw $t2, -16($fp)lw $t2, -16($fp)# push parameter onto stacksw $t2, 0($sp)subu $sp, $sp, 4jal Foo_testing#StmMOVE(ExpTEMP(t1), e)move $t0, $v0sw $t0, -20($fp)# ExpCALLlw $t2, -20($fp)# push parameter onto stacksw $t2, 0($sp)subu $sp, $sp, 4jal _printint# epiloguedone1:lw $ra, 0($fp)move $t0, $fplw $fp, -4($fp)move $sp, $t0jr


View Full Document

CSU CS 453 - Study Guide

Download Study Guide
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 Study Guide 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 Study Guide 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?