UW-Madison CS 536 - Type Checking Returns (5 pages)

Previewing pages 1, 2 of 5 page document View the full content.
View Full Document

Type Checking Returns



Previewing pages 1, 2 of actual document.

View the full content.
View Full Document
View Full Document

Type Checking Returns

50 views

Lecture Notes


Pages:
5
School:
University of Wisconsin, Madison
Course:
Cs 536 - Introduction to Programming Languages and Compilers

Unformatted text preview:

Type Checking Returns Type Checking Method Declarations returnNode methodDeclNode identNode typeNode expr tree args tree It is useful to arrange that a static field named currentMethod will always point to the methodDeclNode of the method we are currently checking Type checking steps 1 If returnVal is a null node check that currentMethod returnType is Void 2 If returnVal an expr is not null then check that returnVal s kind is scalar and returnVal s type is currentMethod returnType stmts tree Type checking steps 1 Create a new symbol table entry m with type typeNode type and kind Method 2 Check that identNode idname is not already in the symbol table if it isn t enter m using identNode idname 3 Create a new scope in the symbol table 4 Set currentMethod this methodDeclNode CS 536 Spring 2008 decls tree 390 5 Type check the args subtree 6 Build a list of the symbol table nodes corresponding to the args subtree store it in m 7 Type check the decls subtree 8 Type check the stmts subtree 9 Close the current scope at the top of the symbol table CS 536 Spring 2008 391 Type Checking Method Calls callNode identNode args tree We consider calls of procedures in a statement Calls of functions in an expression are very similar Type checking steps 1 Check that identNode idname is declared in the symbol table Its type should be Void and kind should be Method 2 Type check the args subtree 3 Build a list of the expression nodes found in the args subtree CS 536 Spring 2008 392 CS 536 Spring 2008 393 4 Get the list of parameter symbols declared for the method stored in the method s symbol table entry 5 Check that the arguments list and the parameter symbols list both have the same length 6 Compare each argument node with its corresponding parameter symbol a Both should have the same type b A Variable Value or ScalarParm kind in an argument node matches a ScalarParm parameter An Array or ArrayParm kind in an argument node matches an ArrayParm parameter Reading Assignment Read Chapter 9



View Full Document

Access the best Study Guides, Lecture Notes and Practice Exams

Loading Unlocking...
Login

Join to view Type Checking Returns 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 Type Checking Returns 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?