Computer Science, asked by Robinpreet5233, 1 year ago

Ponit out two rules for type checking in compiler design

Answers

Answered by ShadowLucifer
4
Type Checking Rules

The general form a type checking rule is: 




The rule should be read: In the type environment for objects , methods , and containing class , the expression  has type . The dots above the horizontal bar stand for other statements about the types of sub-expressions of . These other statements are hypotheses of the rule; if the hypotheses are satisfied, then the statement below the bar is true. In the conclusion, the ``turnstile'' separates context from statement.

The rule for object identifiers is simply that if the environment assigns an identifier  type , then has type . 




The rule for assignment to a variable is more complex: 




Note that this type rule--as well as others--use the conformance relation. The rule says that the assigned expression must have a type  that conforms to the type  of the identifier  in the type environment. The type of the whole expression is.

The type rules for constants are all easy: 
















There are two cases for new, one for new SELF_TYPEand one for any other form: 



Dispatch expressions are the most complex to type check. 








To type check a dispatch, each of the subexpressions must first be type checked. The type of  determines which declaration of the method is used. The argument types of the dispatch must conform to the declared argument types. Note that the type of the result of the dispatch is either the declared return type or in the case that the declared return type is . The only difference in type checking a static dispatch is that the class of the method is given in the dispatch, and the type must conform to 

The type checking rules for if and {-} expressions are straightforward. See Section 7.5 for the definition of the  operation. 

Similar questions