0% found this document useful (0 votes)
13 views11 pages

Hobbit Storry

The document describes a static checker class for analyzing the abstract syntax tree of a program. It contains methods for checking scopes, types, declarations and more. The class utilizes visitor and context patterns to traverse the AST and collect symbol table information.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views11 pages

Hobbit Storry

The document describes a static checker class for analyzing the abstract syntax tree of a program. It contains methods for checking scopes, types, declarations and more. The class utilizes visitor and context patterns to traverse the AST and collect symbol table information.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 11

package bkool.

checker
/**
* Student name:Nguyen Danh Khoi
* Student ID:51301905
*/
import
import
import
import
import
import
import

bkool.parser._
bkool.utils._
java.io.{PrintWriter, File}
org.antlr.v4.runtime.ANTLRFileStream;
org.antlr.v4.runtime.CommonTokenStream;
org.antlr.v4.runtime.tree._
scala.collection.JavaConverters._

class StaticChecker(ast:AST) {
case class SaveClassList(list:List[(String,String,List[(String,Type,Kind,SIKin
d,Boolean)])]) extends Context
case class SaveList(list:List[(String,Type,Kind,SIKind,Boolean)]) extends Cont
ext
def check() = {
val global = new GlobalEnvironment()
val en = global.visitProgram(ast.asInstanceOf[Program],null).asInstanceOf
[List[(String,String,List[(String,Type,Kind,SIKind,Boolean)])]]
val sec = new SecondCheck(en)
val en2 = sec.visitProgram(ast.asInstanceOf[Program], null).asInstanceOf[
List[(String,Type,Kind,SIKind,Boolean)]]
}
trait Utils {
object notValidType extends Type
def UnaryType(a : Any, b : String ) : Type =
(a,b) match{
case (FloatType,"+"|"-")=> FloatType
case (IntType,"+"|"-") => IntType
case (BoolType,"!") => BoolType
case (_,_) => notValidType
}
def check_Is_Const (a :Any , b : Any): Boolean = (a,b) match {
case (true,true)=>true
case (_,_)=>false
}
def BinaryExpGetType(a : Any , c : Any , b : String): Type =(a,b,c) match
{
case
case
case
case
case
case
case
case
case
case
case
case
case
}

(FloatType,"+"|"-"|"*"|"/",IntType) => FloatType


(FloatType,"+"|"-"|"*"|"/",FloatType) => FloatType
(FloatType,">"|"<="|">="|"<"|"=="|"<>",FloatType)=> BoolType
(FloatType,">"|"<="|">="|"<"|"=="|"<>",IntType)=> BoolType
(IntType,"+"|"-"|"*"|"\""|"%",IntType)=> IntType
(IntType,"/",IntType)=> FloatType
(IntType,">"|"<"|">="|"<="|"=="|"<>",IntType) => BoolType
(IntType,"+"|"-"|"*"|"/",FloatType) => FloatType
(IntType,">"|"<="|">="|"<"|"=="|"<>",FloatType)=> BoolType
(BoolType,"=="|"<>"|"&"|"||",BoolType)=>BoolType
(StringType,"^",StringType)=>StringType
(StringType,"=="|"<>",StringType)=>BoolType
(_,_,_) => notValidType

def lookup[T](name:String,list:List[T],func:T=>String):Option[T] = list ma


tch {
case List() => None
case head::tail => if (func(head) == name)
Some(head)
else
lookup(name,tail,func)
}
//return result if found
def find_ID(ID:String, list:List[(String,Type,Kind,SIKind,Boolean)]):(Strin
g,Type,Kind,SIKind,Boolean) = {
val result = list find
{ x => x._3 != Method && x._3 != Attribute && x._1 == ID}
if (result !=None)
(result.get._1,result.get._2,result.get._3,result.get._4,result.get.
_5)
else
null
}
//return null
def find_Static(kindz: Kind, classz: String, name:String, list:List[(String,
String,List[(String,Type,Kind,SIKind,Boolean)])]):Boolean = {
val result = list find {e => e._1 == classz}
if (result.get._2 != "")
{
(result.get._3++searchClass(result.get._2,List(),list))
.exists(x=>x._1 == name && x._4 == Static && x._3 == kindz)
}
else {
result.get._3.exists(x=>x._1 == name && x._4 == Static && x._3 == kindz)
}
}
def find_Member(kindz: Kind, classz: String, name:String, list:List[(String,St
ring,List[(String,Type,Kind,SIKind,Boolean)])]):(Boolean,Type) = {
val a = list find {e => e._1 == classz}
if (a.get._2 != "")
{
val b = a.get._3++searchClass(a.get._2,List(),list)
if (b.exists(x=>x._1 == name && x._3 == kindz))
{
val c = b find {x=>x._1 == name && x._3 == kindz}
(true,c.get._2)
}
else (false,null)
}
else {
if(a.get._3.exists(x=>x._1 == name && x._3 == kindz))
{
val c = a.get._3 find {x=>x._1 == name && x._3 == kindz}
(true,c.get._2)
}
else (false,null)
}
}
def searchClass(name:String, lstclass: List[String], list:List[(String,String,
List[(String,Type,Kind,SIKind,Boolean)])]):List[(String,Type,Kind,SIKind,Boolean
)] = {
val listpa = list find {e => e._1 == name}
val lstnewclass = name::lstclass

if (listpa.get._2 != "" ) {
if (lstnewclass.exists(x=>x == listpa.get._2)) listpa.get._3
else {
listpa.get._3++searchClass(listpa.get._2,listpa.get._2::lstnewclass,list
)
}
}
else listpa.get._3
}
def check_Is_Const(classs:String, name:String, list:List[(String,String,List[(
String,Type,Kind,SIKind,Boolean)])]):Boolean = {
val a = list find {e => e._1 == classs}
if (a.get._2 != "")
{
val b = a.get._3++searchClass(a.get._2,List(),list)
b.exists(x=>x._1 == name && x._4 == Static && x._5 == true)
}
else {
a.get._3.exists(x=>x._1 == name && x._4 == Static && x._5 == true)
}
}
}
class GlobalEnvironment extends Visitor with Utils {
override def visitClassDecl(ast: ClassDecl, c: Context) = {
val env = c.asInstanceOf[SaveClassList].list
if (env.exists(x=>x._1==ast.name.name)) throw Redeclared(Class,ast.name.na
me)
else {
(
ast.name.name,
ast.parent.name,
ast.decl.foldLeft(List[(String,Type,Kind,SIKind,Boolean)]())
(
(x,y) => y match
{
case MethodDecl(a,b,c,d,e) =>
visit(y.asInstanceOf[MethodDecl],SaveList(x)).asInstance
Of[List[(String,Type,Kind,SIKind,Boolean)]]
case AttributeDecl(a,b)
=>
visit(y.asInstanceOf[AttributeDecl],SaveList(x)).asInsta
nceOf[List[(String,Type,Kind,SIKind,Boolean)]]
}
)
)::env
}
}
override def visitMethodDecl(ast: MethodDecl, c: Context) = {
val env = c.asInstanceOf[SaveList].list
if (env.exists(x=>x._1==ast.name.name)) throw Redeclared(Method,ast.name.
name)
else (ast.name.name,ast.returnType,Method,ast.kind, false)::env
}
override def visitAttributeDecl(ast: AttributeDecl, c: Context) = {
val env = c.asInstanceOf[SaveList].list
ast.decl match {
case VarDecl(a,b) =>
if (env.exists(x=>x._1==ast.decl.asInstanceOf[VarDecl].variable.n
ame))

throw Redeclared(Attribute,ast.decl.asInstanceOf[VarDecl].var
iable.name)
else (ast.decl.asInstanceOf[VarDecl].variable.name,ast.decl.asIns
tanceOf[VarDecl].varType, Attribute, if(ast.kind == Static) Static else Instance
,false)::env
case ConstDecl(a,b,c) =>
if (env.exists(x=>x._1==ast.decl.asInstanceOf[ConstDecl].id.name)
)
throw Redeclared(Attribute,ast.decl.asInstanceOf[ConstDecl].i
d.name)
else (ast.decl.asInstanceOf[ConstDecl].id.name,ast.decl.asInstanc
eOf[ConstDecl].constType, Attribute, if(ast.kind == Static) Static else Instance
,true)::env
}
}
override def visitProgram(ast:Program, c:Context) = {
var ioList = List[(String,Type,Kind,SIKind,Boolean)](
("readInt",IntType,Method,Static,false),
("writeInt",VoidType,Method,Static,false),
("writeIntLn",VoidType,Method,Static,false),
("readFloat",FloatType,Method,Static,false),
("writeFloat",VoidType,Method,Static,false),
("writeFloatLn",VoidType,Method,Static,false),
("readBool",BoolType,Method,Static,false),
("writeBool",VoidType,Method,Static,false),
("writeBoolLn",VoidType,Method,Static,false),
("readStr",StringType,Method,Static,false),
("writeStr",VoidType,Method,Static,false),
("writeStrLn",VoidType,Method,Static,false)
)
ast.decl.foldLeft(List[(String,String,List[(String,Type,Kind,SIKind,Bool
ean)])](("io","",ioList)))((x,y) =>
visit(y,SaveClassList(x)).asInstanceOf[List[(String,String,List[(String,
Type,Kind,SIKind,Boolean)])]])
}
override
override
override
override
override
override
override
override
override
override
override
override
override
override
override
override
override
override
override
override
override
override
override

def
def
def
def
def
def
def
def
def
def
def
def
def
def
def
def
def
def
def
def
def
def
def

visitVarDecl(ast: VarDecl, c: Context)=c


visitConstDecl(ast: ConstDecl, c: Context)= c
visitParamDecl(ast: ParamDecl, c: Context)= c
visitId(ast: Id, c: Context)= c
visitIntLiteral(ast: IntLiteral, c: Context)=c
visitFloatLiteral(ast: FloatLiteral, c: Context)= c
visitStringLiteral(ast: StringLiteral, c: Context)= c
visitBooleanLiteral(ast: BooleanLiteral, c: Context)= c
visitNullLiteral(ast: NullLiteral.type, c: Context)= c
visitSelfLiteral(ast: SelfLiteral.type, c: Context)= c
visitInstance(ast: Instance.type, c: Context)= c
visitStatic(ast: Static.type, c: Context)= c
visitIntType(ast: IntType.type, c: Context)= c
visitFloatType(ast: FloatType.type, c: Context)= c
visitBoolType(ast: BoolType.type, c: Context)= c
visitStringType(ast: StringType.type, c: Context)= c
visitVoidType(ast: VoidType.type, c: Context)= c
visitArrayType(ast: ArrayType, c: Context)= c
visitClassType(ast: ClassType, c: Context)= c
visitBinaryOp(ast: BinaryOp, c: Context)= c
visitUnaryOp(ast: UnaryOp, c: Context)= c
visitNewExpr(ast: NewExpr, c: Context)= c
visitCallExpr(ast: CallExpr, c: Context)= c

override
override
override
override
override
override
override
override
override
override

def
def
def
def
def
def
def
def
def
def

visitCall(ast: Call, c: Context)= c


visitArrayCell(ast: ArrayCell, c: Context)= c
visitFieldAccess(ast: FieldAccess, c: Context)= c
visitBlock(ast: Block, c: Context)= c
visitAssign(ast: Assign, c: Context)= c
visitIf(ast: If, c: Context)= c
visitWhile(ast: While, c: Context)= c
visitBreak(ast: Break.type, c: Context)=c
visitContinue(ast: Continue.type, c: Context)= c
visitReturn(ast: Return, c: Context)= c

}
class SecondCheck(genv:List[(String,String,List[(String,Type,Kind,SIKind,Boo
lean)])]) extends Visitor with Utils {
override def visitProgram(ast: Program, c: Context) = ast.decl.map(visit(
_,c))
override def visitVarDecl(ast: VarDecl, c: Context) = {
val env = c.asInstanceOf[SaveList].list
val t = visit(ast.varType,c).asInstanceOf[Type]
if (env.exists(x=>x._1==ast.variable.name))
throw Redeclared(Variable,ast.variable.name)
else (ast.variable.name,t,Variable,null,false)::env
}
override def visitConstDecl(ast: ConstDecl, c: Context) = {
val env = c.asInstanceOf[SaveList].list
val t = visit(ast.constType,c).asInstanceOf[Type]
if (env.exists(x=>x._1==ast.id.name))
throw Redeclared(Constant,ast.id.name)
else (ast.id.name,t,Constant,null,true)::env
}
override def visitParamDecl(ast: ParamDecl, c: Context) = {
val env = c.asInstanceOf[SaveList].list
val t = visit(ast.paramType,c).asInstanceOf[Type]
if (env.exists(x=>x._1==ast.id.name))
throw Redeclared(Parameter,ast.id.name)
else (ast.id.name,t,Parameter,null,false)::env
}
override def visitClassDecl(ast: ClassDecl, c: Context) = {
if (ast.parent.name != "")
if (!genv.exists(x => x._1==ast.parent.name))
throw Undeclared(Class,ast.parent.name)
val listparent = searchClass(ast.name.name,List(),genv)
ast.decl.filter(_.isInstanceOf[AttributeDecl]).map(visit(_,SaveList(listpare
nt)))
ast.decl.filter(_.isInstanceOf[MethodDecl]).map(visit(_,SaveList(listparent)
))
}
override def visitMethodDecl(ast: MethodDecl, c: Context) = {
val env = c.asInstanceOf[SaveList].list
if(ast.returnType != null) visit(ast.returnType,c)
val locenv = ast.param.foldLeft(List[(String,Type,Kind,SIKind,Boolean)]())((
x,y)=>visit(y,SaveList(x)).asInstanceOf[List[(String,Type,Kind,SIKind,Boolean)]]
)
visitOtherBlock(ast.body.asInstanceOf[Block],SaveList(env),SaveList(locenv))
.asInstanceOf[List[(String,Type,Kind,SIKind,Boolean)]]

}
override def visitAttributeDecl(ast: AttributeDecl, c: Context) = {
ast.decl match {
case VarDecl(a,b) => visit(ast.decl.asInstanceOf[VarDecl].varType,c)
case ConstDecl(a,b,cc) => visit(ast.decl.asInstanceOf[ConstDecl].constT
ype,c)
}
}
override def visitInstance(ast: Instance.type, c: Context) = c
override def visitStatic(ast: Static.type, c: Context) = c
override def visitIntType(ast: IntType.type, c: Context) = IntType
override def visitFloatType(ast: FloatType.type, c: Context) = FloatType
override def visitBoolType(ast: BoolType.type, c: Context) = BoolType
override def visitStringType(ast: StringType.type, c: Context) = StringType
override def visitVoidType(ast: VoidType.type, c: Context) = VoidType
override def visitArrayType(ast: ArrayType, c: Context) = visit(ast.eleType,c
)
override def visitClassType(ast: ClassType, c: Context) = {
if (!genv.exists(x=>x._1==ast.classType))
throw Undeclared(Class,ast.classType)
else ast
}
override def visitBinaryOp(ast: BinaryOp, c: Context) = {
val l = visit(ast.left,c)
val l1 = l match {
case(a,b)=> a
}
val l2 = l match {
case(a,b)=> b
}
val r = visit(ast.right,c)
val r1 = r match {
case(a,b)=> a
}
val r2 = r match {
case(a,b)=> b
}
val finall = check_Is_Const(l2,r2)
val op = ast.op
val t = BinaryExpGetType (l1,r1,op)
t match {
case notValidType => throw TypeMismatchInExpression(ast)
case _ => (t,finall)
}
}
override def visitUnaryOp(ast: UnaryOp, c: Context) =
{
val t = visit(ast.body,c)
val ttype = t match {
case (a,b)=>a
}
val op = t match {
case (a,b) => b
}

val operator = ast.op


val check = UnaryType(ttype,operator)
t match {
case notValidType => throw TypeMismatchInExpression(ast)
case _ => (t,op)
}
}
override def visitNewExpr(ast: NewExpr, c: Context) = {
if (!genv.exists(x=>x._1==ast.name.name))
throw Undeclared(Class,ast.name.name)
(ast.name.toString(),false);
}
override def visitCallExpr(ast: CallExpr, c: Context) = {
if (ast.cName == SelfLiteral){
val env = c.asInstanceOf[SaveList].list
if (!env.exists(x=>x._1==ast.method.name && x._3 == Method))
throw Undeclared(Method,ast.method.name)
else
{
//(env find (x=>x._1==ast.method.name && x._3 == Method)).get._2
val t = (env find (x=>x._2==ast.method.name && x._1 == Method)).get._2
val op = (env find (x=>x._2==ast.method.name && x._1 == Method)).get._
5
val n = visit(t,c)
(n,op)
}
}
else
{
if(ast.cName.isInstanceOf[Id])
{
val env = c.asInstanceOf[SaveList].list
val a = find_ID(ast.cName.asInstanceOf[Id].name,env)
if (a != null)
{
if (a._2.isInstanceOf[ClassType]){
val check = find_Member(Method,a._2.asInstanceOf[ClassType].classTyp
e,ast.method.name,genv)
if (!check._1) throw Undeclared(Method,ast.method.name)
else check._2
}
else null
}
else{
if (genv.exists(x=>x._1==ast.cName.asInstanceOf[Id].name)) {
val check = find_Member(Method,ast.cName.asInstanceOf[Id].name,ast.m
ethod.name,genv)
if (!check._1) throw Undeclared(Method,ast.method.name)
else check._2
}
else throw Undeclared(Identifier,ast.cName.asInstanceOf[Id].name)
}
}
else {
val t = visit(ast.cName,c)
if (t.isInstanceOf[ClassType]){
val check = find_Member(Method,t.asInstanceOf[ClassType].classType,ast

.method.name,genv)
if (!check._1) throw Undeclared(Method,ast.method.name)
else check._2
}
else null
}
}
ast.params.map(visit(_,c))
}
override def visitId(ast: Id, c: Context) = {
val env = c.asInstanceOf[SaveList].list
if (!env.exists(x => x._1 == ast.name && x._3 != Attribute && x._3 != Method
))
throw Undeclared(Identifier,ast.name)
null
}
override def visitArrayCell(ast: ArrayCell, c: Context) = {
visit(ast.arr,c)
visit(ast.idx,c)
}
override def visitFieldAccess(ast: FieldAccess, c: Context) = {
if (ast.name == SelfLiteral){
val env = c.asInstanceOf[SaveList].list
if (!env.exists(x=>x._1==ast.field.name && x._3 == Attribute))
throw Undeclared(Attribute,ast.field.name)
else (env find (x=>x._1==ast.field.name && x._3 == Attribute)).get._2
}
else{
if(ast.name.isInstanceOf[Id]== true){
val env = c.asInstanceOf[SaveList].list
val a = find_ID(ast.name.asInstanceOf[Id].name,env)
if (a != null)
{
if (a._2.isInstanceOf[ClassType]){
val check = find_Member(Attribute,a._2.asInstanceOf[ClassType].class
Type,ast.field.name,genv)
if (!check._1)throw Undeclared(Attribute,ast.field.name)
else check._2
}
else null //asas
}
else{
if (genv.exists(x=>x._1==ast.name.asInstanceOf[Id].name)) {
val check = find_Member(Attribute,ast.name.asInstanceOf[Id].name,ast
.field.name,genv)
if (!check._1) throw Undeclared(Attribute,ast.field.name)
else check._2
}
else throw Undeclared(Identifier,ast.name.asInstanceOf[Id].name) //KBI
L
}
}
else {
val t = visit(ast.name,c)
if (t.isInstanceOf[ClassType]){
val check = find_Member(Attribute,t.asInstanceOf[ClassType].classType,
ast.field.name,genv)

if (!check._1)throw Undeclared(Attribute,ast.field.name)
else check._2
}
else null
}
}
}
override def visitBlock(ast: Block, c: Context) =
{
val env = c.asInstanceOf[SaveList].list
val locenv = ast.decl.foldLeft(List[(String,Type,Kind,SIKind,Boolean)]())((x
,y)
=>visit(y,SaveList(x)).asInstanceOf[List[(String,Type,Kind,SIKind,Boolea
n)]])
ast.stmt.map(visit(_,SaveList(locenv++env)))
}
def visitOtherBlock(ast: Block, c: Context, c2: Context) = {
val env = c.asInstanceOf[SaveList].list
val env2 = c2.asInstanceOf[SaveList].list
val locenv = ast.decl.foldLeft(env2)((x,y)=>visit(y,SaveList(x)).asInstanceO
f[List[(String,Type,Kind,SIKind,Boolean)]])
ast.stmt.map(visit(_,SaveList(locenv++env)))
}
override def visitAssign(ast: Assign, c: Context)= {
val env = c.asInstanceOf[SaveList].list
if(ast.leftHandSide.isInstanceOf[Id]) {
//if (env.exists(x=>x._1==ast.leftHandSide.asInstanceOf[Id].name && x._5 =
= true))
//throw CannotAssignToConstant(ast)
if (!env.exists(x=>x._1==ast.leftHandSide.asInstanceOf[Id].name && x._3 !=
Method && x._3 != Attribute))
throw Undeclared(Identifier,ast.leftHandSide.asInstanceOf[Id].name)
//Cannot assign constant
}
else if(ast.leftHandSide.isInstanceOf[FieldAccess]) {
if (ast.leftHandSide.asInstanceOf[FieldAccess].name == SelfLiteral){
val env = c.asInstanceOf[SaveList].list
if (!env.exists(x=>x._1 == ast.leftHandSide.asInstanceOf[FieldAccess].fi
eld.name && x._3 == Attribute))
throw Undeclared(Attribute,ast.leftHandSide.asInstanceOf[FieldAccess].
field.name)
//Cannot assign constant
//if (env.exists(x=>x._1 == ast.leftHandSide.asInstanceOf[FieldAccess].f
ield.name && x._5 == true))
//throw CannotAssignToConstant(ast)
}
else{
if (ast.leftHandSide.asInstanceOf[FieldAccess].name.isInstanceOf[Id])
{
val lhs = ast.leftHandSide.asInstanceOf[FieldAccess]
val env = c.asInstanceOf[SaveList].list
val a = find_ID(lhs.name.asInstanceOf[Id].name,env)
if (a != null)
{
if (a._2.isInstanceOf[ClassType]){
val check = find_Member(Attribute,a._2.asInstanceOf[ClassType].cla
ssType,lhs.field.name,genv)

if (!check._1) throw Undeclared(Attribute,lhs.field.name)


else {
null // Cannot assign constant
}
}
else null //KBIL TypeMissMatch
}
else{
if (genv.exists(x=>x._1==lhs.name.asInstanceOf[Id].name)) {
val check = find_Member(Attribute,lhs.name.asInstanceOf[Id].name,l
hs.field.name,genv)
if (!check._1) throw Undeclared(Attribute,lhs.field.name)
else {
null
// Cannot assign constant
//if (check_Is_Const(lhs.name.asInstanceOf[Id].name,ast.leftHand
Side.asInstanceOf[FieldAccess].field.name,genv))
//throw CannotAssignToConstant(ast)
}
}
else throw Undeclared(Identifier,lhs.name.asInstanceOf[Id].name) //K
BIL
}
}
}
}
else if(ast.leftHandSide.isInstanceOf[ArrayCell]) {
visit(ast.leftHandSide.asInstanceOf[ArrayCell].arr,c)
// KBIL TypeMissMatch
visit(ast.leftHandSide.asInstanceOf[ArrayCell].idx,c)
}
visit(ast.expr.asInstanceOf[Expr],c)
}
override def visitIf(ast: If, c: Context) = {
visit(ast.expr,c)
visit(ast.thenStmt,c)
if (ast.elseStmt != None) visit(ast.elseStmt.get.asInstanceOf[Stmt],c) else
null
}
override def visitCall(ast: Call, c: Context) = {
if (ast.parent == SelfLiteral){
val env = c.asInstanceOf[SaveList].list
if (!env.exists(x=>x._1==ast.method.name && x._3== Method))
throw Undeclared(Method,ast.method.name)
else (env find (x=>x._1==ast.method.name && x._3 == Method)).get._2
}
else
{
if(ast.parent.isInstanceOf[Id]){
val env = c.asInstanceOf[SaveList].list
val a = find_ID(ast.parent.asInstanceOf[Id].name,env)
if (a != null)
{
if (a._2.isInstanceOf[ClassType]){
val check = find_Member(Method,a._2.asInstanceOf[ClassType].classTyp
e,ast.method.name,genv)
if (!check._1) throw Undeclared(Method,ast.method.name)
else check._2

}
else null //KBIL TypeMissMatch
}
else{
if (genv.exists(x=>x._1==ast.parent.asInstanceOf[Id].name)) {
val check = find_Member(Method,ast.parent.asInstanceOf[Id].name,ast.
method.name,genv)
if (!check._1) throw Undeclared(Method,ast.method.name)
else check._2
}
else throw Undeclared(Identifier,ast.parent.asInstanceOf[Id].name) //K
BIL
}
}
else {
val t = visit(ast.parent,c)
if (t.isInstanceOf[ClassType]){
val check = find_Member(Method,t.asInstanceOf[ClassType].classType,ast
.method.name,genv)
if (!check._1) throw Undeclared(Method,ast.method.name)
else check._2
}
else null
}
}
ast.params.map(visit(_,c))
}
override def visitWhile(ast: While, c: Context) = {
visit(ast.expr,c)
visit(ast.loop,c)
}
override def visitBreak(ast: Break.type, c: Context) = Break
override def visitContinue(ast: Continue.type, c: Context) = Continue
override def visitReturn(ast: Return, c: Context) = visit(ast.expr,c)
override
override
override
override
override
override
}

def
def
def
def
def
def

visitIntLiteral(ast: IntLiteral, c: Context) = c


visitFloatLiteral(ast: FloatLiteral, c: Context) = c
visitStringLiteral(ast: StringLiteral, c: Context) = c
visitBooleanLiteral(ast: BooleanLiteral, c: Context)= c
visitNullLiteral(ast: NullLiteral.type, c: Context)= c
visitSelfLiteral(ast: SelfLiteral.type, c: Context) = c

You might also like