|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectminijava.visitor.GJDepthFirst<Type,SymbolTable<Type>>
minijava.typecheck.TypeChecker
public class TypeChecker
A TypeChecker is a depth-first visitor that, when accepted by a
node, returns the logical Type of that node, if it is an expression
or certain statement, and null otherwise. Each visit method is
supplied with a symbol table argument, in a pseudo-functional manner. If
anything in the traversal of the tree does not typecheck, an exception is
thrown.
The minijava grammar that this type checker checks is detailed here, with extra specifications here
SymbolTable,
Type,
TypeException| Constructor Summary | |
|---|---|
TypeChecker()
|
|
| Method Summary | |
|---|---|
void |
setCurrentClass(Class cls)
|
Type |
visit(AllocationExpression n,
SymbolTable<Type> symtable)
nodeToken -> "new" identifier -> Identifier() nodeToken1 -> "(" nodeToken2 -> ")" |
Type |
visit(AndExpression n,
SymbolTable<Type> symtable)
primaryExpression -> PrimaryExpression() nodeToken -> "&&" primaryExpression1 -> PrimaryExpression() |
Type |
visit(ArrayAllocationExpression n,
SymbolTable<Type> symtable)
nodeToken -> "new" nodeToken1 -> "int" nodeToken2 -> "[" expression -> Expression() nodeToken3 -> "]" |
Type |
visit(ArrayAssignmentStatement n,
SymbolTable<Type> symtable)
identifier -> Identifier() nodeToken -> "[" expression -> Expression() nodeToken1 -> "]" nodeToken2 -> "=" expression1 -> Expression() nodeToken3 -> ";" |
Type |
visit(ArrayLength n,
SymbolTable<Type> symtable)
primaryExpression -> PrimaryExpression() nodeToken -> "." nodeToken1 -> "length" |
Type |
visit(ArrayLookup n,
SymbolTable<Type> symtable)
primaryExpression -> PrimaryExpression() nodeToken -> "[" primaryExpression1 -> PrimaryExpression() nodeToken1 -> "]" |
Type |
visit(AssignmentStatement n,
SymbolTable<Type> symtable)
identifier -> Identifier() nodeToken -> "=" expression -> Expression() nodeToken1 -> ";" |
Type |
visit(Block n,
SymbolTable<Type> symtable)
nodeToken -> "{" nodeListOptional -> ( Statement() )* nodeToken1 -> "}" |
Type |
visit(BracketExpression n,
SymbolTable<Type> symtable)
nodeToken -> "(" expression -> Expression() nodeToken1 -> ")" |
Type |
visit(ClassDeclaration n,
SymbolTable<Type> symtable)
nodeToken -> "class" identifier -> Identifier() nodeToken1 -> "{" nodeListOptional -> ( VarDeclaration() )* nodeListOptional1 -> ( MethodDeclaration() )* nodeToken2 -> "}" |
Type |
visit(ClassExtendsDeclaration n,
SymbolTable<Type> symtable)
nodeToken -> "class" identifier -> Identifier() nodeToken1 -> "extends" identifier1 -> Identifier() nodeToken2 -> "{" nodeListOptional -> ( VarDeclaration() )* nodeListOptional1 -> ( MethodDeclaration() )* nodeToken3 -> "}" |
Type |
visit(CompareExpression n,
SymbolTable<Type> symtable)
primaryExpression -> PrimaryExpression() nodeToken -> "<" primaryExpression1 -> PrimaryExpression() |
Type |
visit(ExpressionList n,
SymbolTable<Type> symtable)
expression -> Expression() nodeListOptional -> ( ExpressionRest() )* |
Type |
visit(ExpressionRest n,
SymbolTable<Type> symtable)
nodeToken -> "," expression -> Expression() |
Type |
visit(Expression n,
SymbolTable<Type> symtable)
nodeChoice -> AndExpression() | CompareExpression() | PlusExpression() | MinusExpression() | TimesExpression() | ArrayLookup() | ArrayLength() | MessageSend() | PrimaryExpression() |
Type |
visit(FalseLiteral n,
SymbolTable<Type> symtable)
nodeToken -> "false" |
Type |
visit(Goal n,
SymbolTable<Type> symtable)
mainClass -> MainClass() nodeListOptional -> ( TypeDeclaration() )* nodeToken -> <EOF> |
Type |
visit(Identifier n,
SymbolTable<Type> symtable)
nodeToken -> <IDENTIFIER> |
Type |
visit(IfStatement n,
SymbolTable<Type> symtable)
nodeToken -> "if" nodeToken1 -> "(" expression -> Expression() nodeToken2 -> ")" statement -> Statement() nodeToken3 -> "else" statement1 -> Statement() |
Type |
visit(IntegerLiteral n,
SymbolTable<Type> symtable)
nodeToken -> <INTEGER_LITERAL> |
Type |
visit(MainClass n,
SymbolTable<Type> symtable)
nodeToken -> "class" identifier -> Identifier() nodeToken1 -> "{" nodeToken2 -> "public" nodeToken3 -> "static" nodeToken4 -> "void" nodeToken5 -> "main" nodeToken6 -> "(" nodeToken7 -> "String" nodeToken8 -> "[" nodeToken9 -> "]" identifier1 -> Identifier() nodeToken10 -> ")" nodeToken11 -> "{" nodeListOptional -> ( VarDeclaration() )* nodeListOptional1 -> ( Statement() )* nodeToken12 -> "}" nodeToken13 -> "}" |
Type |
visit(MessageSend n,
SymbolTable<Type> symtable)
primaryExpression -> PrimaryExpression() nodeToken -> "." identifier -> Identifier() nodeToken1 -> "(" nodeOptional -> ( ExpressionList() )? nodeToken2 -> ")" |
Type |
visit(MethodDeclaration n,
SymbolTable<Type> symtable)
nodeToken -> "public" type -> Type() identifier -> Identifier() nodeToken1 -> "(" nodeOptional -> ( FormalParameterList() )? nodeToken2 -> ")" nodeToken3 -> "{" nodeListOptional -> ( VarDeclaration() )* nodeListOptional1 -> ( Statement() )* nodeToken4 -> "return" expression -> Expression() nodeToken5 -> ";" nodeToken6 -> "}" |
Type |
visit(MinusExpression n,
SymbolTable<Type> symtable)
primaryExpression -> PrimaryExpression() nodeToken -> "-" primaryExpression1 -> PrimaryExpression() |
Type |
visit(NotExpression n,
SymbolTable<Type> symtable)
nodeToken -> "!" expression -> Expression() |
Type |
visit(PlusExpression n,
SymbolTable<Type> symtable)
primaryExpression -> PrimaryExpression() nodeToken -> "+" primaryExpression1 -> PrimaryExpression() |
Type |
visit(PrimaryExpression n,
SymbolTable<Type> symtable)
nodeChoice -> IntegerLiteral() | TrueLiteral() | FalseLiteral() | Identifier() | ThisExpression() | ArrayAllocationExpression() | AllocationExpression() | NotExpression() | BracketExpression() |
Type |
visit(PrintStatement n,
SymbolTable<Type> symtable)
nodeToken -> "System.out.println" nodeToken1 -> "(" expression -> Expression() nodeToken2 -> ")" nodeToken3 -> ";" |
Type |
visit(Statement n,
SymbolTable<Type> symtable)
nodeChoice -> Block() | AssignmentStatement() | ArrayAssignmentStatement() | IfStatement() | WhileStatement() | PrintStatement() |
Type |
visit(ThisExpression n,
SymbolTable<Type> symtable)
nodeToken -> "this" |
Type |
visit(TimesExpression n,
SymbolTable<Type> symtable)
primaryExpression -> PrimaryExpression() nodeToken -> "*" primaryExpression1 -> PrimaryExpression() |
Type |
visit(TrueLiteral n,
SymbolTable<Type> symtable)
nodeToken -> "true" |
Type |
visit(WhileStatement n,
SymbolTable<Type> symtable)
nodeToken -> "while" nodeToken1 -> "(" expression -> Expression() nodeToken2 -> ")" statement -> Statement() |
| Methods inherited from class minijava.visitor.GJDepthFirst |
|---|
visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public TypeChecker()
| Method Detail |
|---|
public void setCurrentClass(Class cls)
public Type visit(Goal n,
SymbolTable<Type> symtable)
GJDepthFirstmainClass -> MainClass() nodeListOptional -> ( TypeDeclaration() )* nodeToken -> <EOF>
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
public Type visit(MainClass n,
SymbolTable<Type> symtable)
GJDepthFirst
nodeToken -> "class"
identifier -> Identifier()
nodeToken1 -> "{"
nodeToken2 -> "public"
nodeToken3 -> "static"
nodeToken4 -> "void"
nodeToken5 -> "main"
nodeToken6 -> "("
nodeToken7 -> "String"
nodeToken8 -> "["
nodeToken9 -> "]"
identifier1 -> Identifier()
nodeToken10 -> ")"
nodeToken11 -> "{"
nodeListOptional -> ( VarDeclaration() )*
nodeListOptional1 -> ( Statement() )*
nodeToken12 -> "}"
nodeToken13 -> "}"
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
public Type visit(ClassDeclaration n,
SymbolTable<Type> symtable)
GJDepthFirst
nodeToken -> "class"
identifier -> Identifier()
nodeToken1 -> "{"
nodeListOptional -> ( VarDeclaration() )*
nodeListOptional1 -> ( MethodDeclaration() )*
nodeToken2 -> "}"
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
public Type visit(ClassExtendsDeclaration n,
SymbolTable<Type> symtable)
GJDepthFirst
nodeToken -> "class"
identifier -> Identifier()
nodeToken1 -> "extends"
identifier1 -> Identifier()
nodeToken2 -> "{"
nodeListOptional -> ( VarDeclaration() )*
nodeListOptional1 -> ( MethodDeclaration() )*
nodeToken3 -> "}"
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
public Type visit(MethodDeclaration n,
SymbolTable<Type> symtable)
GJDepthFirst
nodeToken -> "public"
type -> Type()
identifier -> Identifier()
nodeToken1 -> "("
nodeOptional -> ( FormalParameterList() )?
nodeToken2 -> ")"
nodeToken3 -> "{"
nodeListOptional -> ( VarDeclaration() )*
nodeListOptional1 -> ( Statement() )*
nodeToken4 -> "return"
expression -> Expression()
nodeToken5 -> ";"
nodeToken6 -> "}"
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
public Type visit(Statement n,
SymbolTable<Type> symtable)
GJDepthFirst
nodeChoice -> Block()
| AssignmentStatement()
| ArrayAssignmentStatement()
| IfStatement()
| WhileStatement()
| PrintStatement()
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
public Type visit(Block n,
SymbolTable<Type> symtable)
GJDepthFirst
nodeToken -> "{"
nodeListOptional -> ( Statement() )*
nodeToken1 -> "}"
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
public Type visit(AssignmentStatement n,
SymbolTable<Type> symtable)
GJDepthFirstidentifier -> Identifier() nodeToken -> "=" expression -> Expression() nodeToken1 -> ";"
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
public Type visit(ArrayAssignmentStatement n,
SymbolTable<Type> symtable)
GJDepthFirstidentifier -> Identifier() nodeToken -> "[" expression -> Expression() nodeToken1 -> "]" nodeToken2 -> "=" expression1 -> Expression() nodeToken3 -> ";"
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
public Type visit(IfStatement n,
SymbolTable<Type> symtable)
GJDepthFirst
nodeToken -> "if"
nodeToken1 -> "("
expression -> Expression()
nodeToken2 -> ")"
statement -> Statement()
nodeToken3 -> "else"
statement1 -> Statement()
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
public Type visit(WhileStatement n,
SymbolTable<Type> symtable)
GJDepthFirst
nodeToken -> "while"
nodeToken1 -> "("
expression -> Expression()
nodeToken2 -> ")"
statement -> Statement()
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
public Type visit(PrintStatement n,
SymbolTable<Type> symtable)
GJDepthFirst
nodeToken -> "System.out.println"
nodeToken1 -> "("
expression -> Expression()
nodeToken2 -> ")"
nodeToken3 -> ";"
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
public Type visit(Expression n,
SymbolTable<Type> symtable)
GJDepthFirst
nodeChoice -> AndExpression()
| CompareExpression()
| PlusExpression()
| MinusExpression()
| TimesExpression()
| ArrayLookup()
| ArrayLength()
| MessageSend()
| PrimaryExpression()
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
public Type visit(AndExpression n,
SymbolTable<Type> symtable)
GJDepthFirstprimaryExpression -> PrimaryExpression() nodeToken -> "&&" primaryExpression1 -> PrimaryExpression()
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
public Type visit(CompareExpression n,
SymbolTable<Type> symtable)
GJDepthFirstprimaryExpression -> PrimaryExpression() nodeToken -> "<" primaryExpression1 -> PrimaryExpression()
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
public Type visit(PlusExpression n,
SymbolTable<Type> symtable)
GJDepthFirstprimaryExpression -> PrimaryExpression() nodeToken -> "+" primaryExpression1 -> PrimaryExpression()
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
public Type visit(MinusExpression n,
SymbolTable<Type> symtable)
GJDepthFirstprimaryExpression -> PrimaryExpression() nodeToken -> "-" primaryExpression1 -> PrimaryExpression()
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
public Type visit(TimesExpression n,
SymbolTable<Type> symtable)
GJDepthFirstprimaryExpression -> PrimaryExpression() nodeToken -> "*" primaryExpression1 -> PrimaryExpression()
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
public Type visit(ArrayLookup n,
SymbolTable<Type> symtable)
GJDepthFirstprimaryExpression -> PrimaryExpression() nodeToken -> "[" primaryExpression1 -> PrimaryExpression() nodeToken1 -> "]"
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
public Type visit(ArrayLength n,
SymbolTable<Type> symtable)
GJDepthFirstprimaryExpression -> PrimaryExpression() nodeToken -> "." nodeToken1 -> "length"
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
public Type visit(MessageSend n,
SymbolTable<Type> symtable)
GJDepthFirst
primaryExpression -> PrimaryExpression()
nodeToken -> "."
identifier -> Identifier()
nodeToken1 -> "("
nodeOptional -> ( ExpressionList() )?
nodeToken2 -> ")"
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
public Type visit(ExpressionList n,
SymbolTable<Type> symtable)
GJDepthFirstexpression -> Expression() nodeListOptional -> ( ExpressionRest() )*
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
public Type visit(ExpressionRest n,
SymbolTable<Type> symtable)
GJDepthFirstnodeToken -> "," expression -> Expression()
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
public Type visit(PrimaryExpression n,
SymbolTable<Type> symtable)
GJDepthFirst
nodeChoice -> IntegerLiteral()
| TrueLiteral()
| FalseLiteral()
| Identifier()
| ThisExpression()
| ArrayAllocationExpression()
| AllocationExpression()
| NotExpression()
| BracketExpression()
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
public Type visit(IntegerLiteral n,
SymbolTable<Type> symtable)
GJDepthFirstnodeToken -> <INTEGER_LITERAL>
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
public Type visit(TrueLiteral n,
SymbolTable<Type> symtable)
GJDepthFirstnodeToken -> "true"
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
public Type visit(FalseLiteral n,
SymbolTable<Type> symtable)
GJDepthFirstnodeToken -> "false"
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
public Type visit(Identifier n,
SymbolTable<Type> symtable)
GJDepthFirstnodeToken -> <IDENTIFIER>
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
public Type visit(ThisExpression n,
SymbolTable<Type> symtable)
GJDepthFirstnodeToken -> "this"
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
public Type visit(ArrayAllocationExpression n,
SymbolTable<Type> symtable)
GJDepthFirstnodeToken -> "new" nodeToken1 -> "int" nodeToken2 -> "[" expression -> Expression() nodeToken3 -> "]"
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
public Type visit(AllocationExpression n,
SymbolTable<Type> symtable)
GJDepthFirst
nodeToken -> "new"
identifier -> Identifier()
nodeToken1 -> "("
nodeToken2 -> ")"
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
public Type visit(NotExpression n,
SymbolTable<Type> symtable)
GJDepthFirstnodeToken -> "!" expression -> Expression()
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
public Type visit(BracketExpression n,
SymbolTable<Type> symtable)
GJDepthFirst
nodeToken -> "("
expression -> Expression()
nodeToken1 -> ")"
visit in interface GJVisitor<Type,SymbolTable<Type>>visit in class GJDepthFirst<Type,SymbolTable<Type>>
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||