|
|
|
@ -115,8 +115,7 @@ public Object visitCallCommand(CallCommand ast, Object o) { |
|
|
|
|
} else if (binding instanceof ProcFormalParameter) { |
|
|
|
|
ast.APS.visit(this, ((ProcFormalParameter) binding).FPS); |
|
|
|
|
} else |
|
|
|
|
reporter.reportError("\"%\" is not a procedure identifier", |
|
|
|
|
ast.I.spelling, ast.I.position); |
|
|
|
|
reporter.reportError("\"%\" is not a procedure identifier", ast.I.spelling, ast.I.position); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -168,8 +167,7 @@ public Object visitWhileCommand(WhileCommand ast, Object o) { |
|
|
|
|
@Override |
|
|
|
|
public Object visitArrayExpression(ArrayExpression ast, Object o) { |
|
|
|
|
TypeDenoter elemType = (TypeDenoter) ast.AA.visit(this, null); |
|
|
|
|
IntegerLiteral il = new IntegerLiteral(Integer.valueOf(ast.AA.elemCount).toString(), |
|
|
|
|
ast.position); |
|
|
|
|
IntegerLiteral il = new IntegerLiteral(Integer.valueOf(ast.AA.elemCount).toString(), ast.position); |
|
|
|
|
ast.type = new ArrayTypeDenoter(il, elemType, ast.position); |
|
|
|
|
return ast.type; |
|
|
|
|
} |
|
|
|
@ -185,20 +183,16 @@ public Object visitBinaryExpression(BinaryExpression ast, Object o) { |
|
|
|
|
reportUndeclared(ast.O); |
|
|
|
|
else { |
|
|
|
|
if (!(binding instanceof BinaryOperatorDeclaration)) |
|
|
|
|
reporter.reportError("\"%\" is not a binary operator", |
|
|
|
|
ast.O.spelling, ast.O.position); |
|
|
|
|
reporter.reportError("\"%\" is not a binary operator", ast.O.spelling, ast.O.position); |
|
|
|
|
BinaryOperatorDeclaration bbinding = (BinaryOperatorDeclaration) binding; |
|
|
|
|
if (bbinding.ARG1 == StdEnvironment.anyType) { |
|
|
|
|
// this operator must be "=" or "\="
|
|
|
|
|
if (!e1Type.equals(e2Type)) |
|
|
|
|
reporter.reportError("incompatible argument types for \"%\"", |
|
|
|
|
ast.O.spelling, ast.position); |
|
|
|
|
reporter.reportError("incompatible argument types for \"%\"", ast.O.spelling, ast.position); |
|
|
|
|
} else if (!e1Type.equals(bbinding.ARG1)) |
|
|
|
|
reporter.reportError("wrong argument type for \"%\"", |
|
|
|
|
ast.O.spelling, ast.E1.position); |
|
|
|
|
reporter.reportError("wrong argument type for \"%\"", ast.O.spelling, ast.E1.position); |
|
|
|
|
else if (!e2Type.equals(bbinding.ARG2)) |
|
|
|
|
reporter.reportError("wrong argument type for \"%\"", |
|
|
|
|
ast.O.spelling, ast.E2.position); |
|
|
|
|
reporter.reportError("wrong argument type for \"%\"", ast.O.spelling, ast.E2.position); |
|
|
|
|
ast.type = bbinding.RES; |
|
|
|
|
} |
|
|
|
|
return ast.type; |
|
|
|
@ -217,8 +211,7 @@ public Object visitCallExpression(CallExpression ast, Object o) { |
|
|
|
|
ast.APS.visit(this, ((FuncFormalParameter) binding).FPS); |
|
|
|
|
ast.type = ((FuncFormalParameter) binding).T; |
|
|
|
|
} else |
|
|
|
|
reporter.reportError("\"%\" is not a function identifier", |
|
|
|
|
ast.I.spelling, ast.I.position); |
|
|
|
|
reporter.reportError("\"%\" is not a function identifier", ast.I.spelling, ast.I.position); |
|
|
|
|
return ast.type; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -238,8 +231,7 @@ public Object visitEmptyExpression(EmptyExpression ast, Object o) { |
|
|
|
|
public Object visitIfExpression(IfExpression ast, Object o) { |
|
|
|
|
TypeDenoter e1Type = (TypeDenoter) ast.E1.visit(this, null); |
|
|
|
|
if (!e1Type.equals(StdEnvironment.booleanType)) |
|
|
|
|
reporter.reportError("Boolean expression expected here", "", |
|
|
|
|
ast.E1.position); |
|
|
|
|
reporter.reportError("Boolean expression expected here", "", ast.E1.position); |
|
|
|
|
TypeDenoter e2Type = (TypeDenoter) ast.E2.visit(this, null); |
|
|
|
|
TypeDenoter e3Type = (TypeDenoter) ast.E3.visit(this, null); |
|
|
|
|
if (!e2Type.equals(e3Type)) |
|
|
|
@ -279,13 +271,11 @@ public Object visitUnaryExpression(UnaryExpression ast, Object o) { |
|
|
|
|
reportUndeclared(ast.O); |
|
|
|
|
ast.type = StdEnvironment.errorType; |
|
|
|
|
} else if (!(binding instanceof UnaryOperatorDeclaration)) |
|
|
|
|
reporter.reportError("\"%\" is not a unary operator", |
|
|
|
|
ast.O.spelling, ast.O.position); |
|
|
|
|
reporter.reportError("\"%\" is not a unary operator", ast.O.spelling, ast.O.position); |
|
|
|
|
else { |
|
|
|
|
UnaryOperatorDeclaration ubinding = (UnaryOperatorDeclaration) binding; |
|
|
|
|
if (!eType.equals(ubinding.ARG)) |
|
|
|
|
reporter.reportError("wrong argument type for \"%\"", |
|
|
|
|
ast.O.spelling, ast.O.position); |
|
|
|
|
reporter.reportError("wrong argument type for \"%\"", ast.O.spelling, ast.O.position); |
|
|
|
|
ast.type = ubinding.RES; |
|
|
|
|
} |
|
|
|
|
return ast.type; |
|
|
|
@ -310,8 +300,7 @@ public Object visitConstDeclaration(ConstDeclaration ast, Object o) { |
|
|
|
|
TypeDenoter eType = (TypeDenoter) ast.E.visit(this, null); |
|
|
|
|
idTable.enter(ast.I.spelling, ast); |
|
|
|
|
if (ast.duplicated) |
|
|
|
|
reporter.reportError("identifier \"%\" already declared", |
|
|
|
|
ast.I.spelling, ast.position); |
|
|
|
|
reporter.reportError("identifier \"%\" already declared", ast.I.spelling, ast.position); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -320,15 +309,13 @@ public Object visitFuncDeclaration(FuncDeclaration ast, Object o) { |
|
|
|
|
ast.T = (TypeDenoter) ast.T.visit(this, null); |
|
|
|
|
idTable.enter(ast.I.spelling, ast); // permits recursion
|
|
|
|
|
if (ast.duplicated) |
|
|
|
|
reporter.reportError("identifier \"%\" already declared", |
|
|
|
|
ast.I.spelling, ast.position); |
|
|
|
|
reporter.reportError("identifier \"%\" already declared", ast.I.spelling, ast.position); |
|
|
|
|
idTable.openScope(); |
|
|
|
|
ast.FPS.visit(this, null); |
|
|
|
|
TypeDenoter eType = (TypeDenoter) ast.E.visit(this, null); |
|
|
|
|
idTable.closeScope(); |
|
|
|
|
if (!ast.T.equals(eType)) |
|
|
|
|
reporter.reportError("body of function \"%\" has wrong type", |
|
|
|
|
ast.I.spelling, ast.E.position); |
|
|
|
|
reporter.reportError("body of function \"%\" has wrong type", ast.I.spelling, ast.E.position); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -336,8 +323,7 @@ public Object visitFuncDeclaration(FuncDeclaration ast, Object o) { |
|
|
|
|
public Object visitProcDeclaration(ProcDeclaration ast, Object o) { |
|
|
|
|
idTable.enter(ast.I.spelling, ast); // permits recursion
|
|
|
|
|
if (ast.duplicated) |
|
|
|
|
reporter.reportError("identifier \"%\" already declared", |
|
|
|
|
ast.I.spelling, ast.position); |
|
|
|
|
reporter.reportError("identifier \"%\" already declared", ast.I.spelling, ast.position); |
|
|
|
|
idTable.openScope(); |
|
|
|
|
ast.FPS.visit(this, null); |
|
|
|
|
ast.C.visit(this, null); |
|
|
|
@ -357,8 +343,7 @@ public Object visitTypeDeclaration(TypeDeclaration ast, Object o) { |
|
|
|
|
ast.T = (TypeDenoter) ast.T.visit(this, null); |
|
|
|
|
idTable.enter(ast.I.spelling, ast); |
|
|
|
|
if (ast.duplicated) |
|
|
|
|
reporter.reportError("identifier \"%\" already declared", |
|
|
|
|
ast.I.spelling, ast.position); |
|
|
|
|
reporter.reportError("identifier \"%\" already declared", ast.I.spelling, ast.position); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -372,8 +357,7 @@ public Object visitVarDeclaration(VarDeclaration ast, Object o) { |
|
|
|
|
ast.T = (TypeDenoter) ast.T.visit(this, null); |
|
|
|
|
idTable.enter(ast.I.spelling, ast); |
|
|
|
|
if (ast.duplicated) |
|
|
|
|
reporter.reportError("identifier \"%\" already declared", |
|
|
|
|
ast.I.spelling, ast.position); |
|
|
|
|
reporter.reportError("identifier \"%\" already declared", ast.I.spelling, ast.position); |
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
@ -411,8 +395,7 @@ public Object visitMultipleRecordAggregate(MultipleRecordAggregate ast, Object o |
|
|
|
|
FieldTypeDenoter rType = (FieldTypeDenoter) ast.RA.visit(this, null); |
|
|
|
|
TypeDenoter fType = checkFieldIdentifier(rType, ast.I); |
|
|
|
|
if (fType != StdEnvironment.errorType) |
|
|
|
|
reporter.reportError("duplicate field \"%\" in record", |
|
|
|
|
ast.I.spelling, ast.I.position); |
|
|
|
|
reporter.reportError("duplicate field \"%\" in record", ast.I.spelling, ast.I.position); |
|
|
|
|
ast.type = new MultipleFieldTypeDenoter(ast.I, eType, rType, ast.position); |
|
|
|
|
return ast.type; |
|
|
|
|
} |
|
|
|
@ -433,8 +416,7 @@ public Object visitConstFormalParameter(ConstFormalParameter ast, Object o) { |
|
|
|
|
ast.T = (TypeDenoter) ast.T.visit(this, null); |
|
|
|
|
idTable.enter(ast.I.spelling, ast); |
|
|
|
|
if (ast.duplicated) |
|
|
|
|
reporter.reportError("duplicated formal parameter \"%\"", |
|
|
|
|
ast.I.spelling, ast.position); |
|
|
|
|
reporter.reportError("duplicated formal parameter \"%\"", ast.I.spelling, ast.position); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -446,8 +428,7 @@ public Object visitFuncFormalParameter(FuncFormalParameter ast, Object o) { |
|
|
|
|
ast.T = (TypeDenoter) ast.T.visit(this, null); |
|
|
|
|
idTable.enter(ast.I.spelling, ast); |
|
|
|
|
if (ast.duplicated) |
|
|
|
|
reporter.reportError("duplicated formal parameter \"%\"", |
|
|
|
|
ast.I.spelling, ast.position); |
|
|
|
|
reporter.reportError("duplicated formal parameter \"%\"", ast.I.spelling, ast.position); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -458,8 +439,7 @@ public Object visitProcFormalParameter(ProcFormalParameter ast, Object o) { |
|
|
|
|
idTable.closeScope(); |
|
|
|
|
idTable.enter(ast.I.spelling, ast); |
|
|
|
|
if (ast.duplicated) |
|
|
|
|
reporter.reportError("duplicated formal parameter \"%\"", |
|
|
|
|
ast.I.spelling, ast.position); |
|
|
|
|
reporter.reportError("duplicated formal parameter \"%\"", ast.I.spelling, ast.position); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -468,8 +448,7 @@ public Object visitVarFormalParameter(VarFormalParameter ast, Object o) { |
|
|
|
|
ast.T = (TypeDenoter) ast.T.visit(this, null); |
|
|
|
|
idTable.enter(ast.I.spelling, ast); |
|
|
|
|
if (ast.duplicated) |
|
|
|
|
reporter.reportError("duplicated formal parameter \"%\"", |
|
|
|
|
ast.I.spelling, ast.position); |
|
|
|
|
reporter.reportError("duplicated formal parameter \"%\"", ast.I.spelling, ast.position); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -501,11 +480,9 @@ public Object visitConstActualParameter(ConstActualParameter ast, Object o) { |
|
|
|
|
TypeDenoter eType = (TypeDenoter) ast.E.visit(this, null); |
|
|
|
|
|
|
|
|
|
if (!(fp instanceof ConstFormalParameter)) |
|
|
|
|
reporter.reportError("const actual parameter not expected here", "", |
|
|
|
|
ast.position); |
|
|
|
|
reporter.reportError("const actual parameter not expected here", "", ast.position); |
|
|
|
|
else if (!eType.equals(((ConstFormalParameter) fp).T)) |
|
|
|
|
reporter.reportError("wrong type for const actual parameter", "", |
|
|
|
|
ast.E.position); |
|
|
|
|
reporter.reportError("wrong type for const actual parameter", "", ast.E.position); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -516,13 +493,10 @@ public Object visitFuncActualParameter(FuncActualParameter ast, Object o) { |
|
|
|
|
Declaration binding = (Declaration) ast.I.visit(this, null); |
|
|
|
|
if (binding == null) |
|
|
|
|
reportUndeclared(ast.I); |
|
|
|
|
else if (!(binding instanceof FuncDeclaration || |
|
|
|
|
binding instanceof FuncFormalParameter)) |
|
|
|
|
reporter.reportError("\"%\" is not a function identifier", |
|
|
|
|
ast.I.spelling, ast.I.position); |
|
|
|
|
else if (!(binding instanceof FuncDeclaration || binding instanceof FuncFormalParameter)) |
|
|
|
|
reporter.reportError("\"%\" is not a function identifier", ast.I.spelling, ast.I.position); |
|
|
|
|
else if (!(fp instanceof FuncFormalParameter)) |
|
|
|
|
reporter.reportError("func actual parameter not expected here", "", |
|
|
|
|
ast.position); |
|
|
|
|
reporter.reportError("func actual parameter not expected here", "", ast.position); |
|
|
|
|
else { |
|
|
|
|
FormalParameterSequence FPS = null; |
|
|
|
|
TypeDenoter T = null; |
|
|
|
@ -534,11 +508,9 @@ public Object visitFuncActualParameter(FuncActualParameter ast, Object o) { |
|
|
|
|
T = ((FuncFormalParameter) binding).T; |
|
|
|
|
} |
|
|
|
|
if (!FPS.equals(((FuncFormalParameter) fp).FPS)) |
|
|
|
|
reporter.reportError("wrong signature for function \"%\"", |
|
|
|
|
ast.I.spelling, ast.I.position); |
|
|
|
|
reporter.reportError("wrong signature for function \"%\"", ast.I.spelling, ast.I.position); |
|
|
|
|
else if (!T.equals(((FuncFormalParameter) fp).T)) |
|
|
|
|
reporter.reportError("wrong type for function \"%\"", |
|
|
|
|
ast.I.spelling, ast.I.position); |
|
|
|
|
reporter.reportError("wrong type for function \"%\"", ast.I.spelling, ast.I.position); |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
@ -550,13 +522,10 @@ public Object visitProcActualParameter(ProcActualParameter ast, Object o) { |
|
|
|
|
Declaration binding = (Declaration) ast.I.visit(this, null); |
|
|
|
|
if (binding == null) |
|
|
|
|
reportUndeclared(ast.I); |
|
|
|
|
else if (!(binding instanceof ProcDeclaration || |
|
|
|
|
binding instanceof ProcFormalParameter)) |
|
|
|
|
reporter.reportError("\"%\" is not a procedure identifier", |
|
|
|
|
ast.I.spelling, ast.I.position); |
|
|
|
|
else if (!(binding instanceof ProcDeclaration || binding instanceof ProcFormalParameter)) |
|
|
|
|
reporter.reportError("\"%\" is not a procedure identifier", ast.I.spelling, ast.I.position); |
|
|
|
|
else if (!(fp instanceof ProcFormalParameter)) |
|
|
|
|
reporter.reportError("proc actual parameter not expected here", "", |
|
|
|
|
ast.position); |
|
|
|
|
reporter.reportError("proc actual parameter not expected here", "", ast.position); |
|
|
|
|
else { |
|
|
|
|
FormalParameterSequence FPS = null; |
|
|
|
|
if (binding instanceof ProcDeclaration) |
|
|
|
@ -564,8 +533,7 @@ public Object visitProcActualParameter(ProcActualParameter ast, Object o) { |
|
|
|
|
else |
|
|
|
|
FPS = ((ProcFormalParameter) binding).FPS; |
|
|
|
|
if (!FPS.equals(((ProcFormalParameter) fp).FPS)) |
|
|
|
|
reporter.reportError("wrong signature for procedure \"%\"", |
|
|
|
|
ast.I.spelling, ast.I.position); |
|
|
|
|
reporter.reportError("wrong signature for procedure \"%\"", ast.I.spelling, ast.I.position); |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
@ -576,14 +544,11 @@ public Object visitVarActualParameter(VarActualParameter ast, Object o) { |
|
|
|
|
|
|
|
|
|
TypeDenoter vType = (TypeDenoter) ast.V.visit(this, null); |
|
|
|
|
if (!ast.V.variable) |
|
|
|
|
reporter.reportError("actual parameter is not a variable", "", |
|
|
|
|
ast.V.position); |
|
|
|
|
reporter.reportError("actual parameter is not a variable", "", ast.V.position); |
|
|
|
|
else if (!(fp instanceof VarFormalParameter)) |
|
|
|
|
reporter.reportError("var actual parameter not expected here", "", |
|
|
|
|
ast.V.position); |
|
|
|
|
reporter.reportError("var actual parameter not expected here", "", ast.V.position); |
|
|
|
|
else if (!vType.equals(((VarFormalParameter) fp).T)) |
|
|
|
|
reporter.reportError("wrong type for var actual parameter", "", |
|
|
|
|
ast.V.position); |
|
|
|
|
reporter.reportError("wrong type for var actual parameter", "", ast.V.position); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -658,8 +623,7 @@ public Object visitSimpleTypeDenoter(SimpleTypeDenoter ast, Object o) { |
|
|
|
|
reportUndeclared(ast.I); |
|
|
|
|
return StdEnvironment.errorType; |
|
|
|
|
} else if (!(binding instanceof TypeDeclaration)) { |
|
|
|
|
reporter.reportError("\"%\" is not a type identifier", |
|
|
|
|
ast.I.spelling, ast.I.position); |
|
|
|
|
reporter.reportError("\"%\" is not a type identifier", ast.I.spelling, ast.I.position); |
|
|
|
|
return StdEnvironment.errorType; |
|
|
|
|
} |
|
|
|
|
return ((TypeDeclaration) binding).T; |
|
|
|
@ -747,8 +711,7 @@ public Object visitDotVname(DotVname ast, Object o) { |
|
|
|
|
else { |
|
|
|
|
ast.type = checkFieldIdentifier(((RecordTypeDenoter) vType).FT, ast.I); |
|
|
|
|
if (ast.type == StdEnvironment.errorType) |
|
|
|
|
reporter.reportError("no field \"%\" in this record type", |
|
|
|
|
ast.I.spelling, ast.I.position); |
|
|
|
|
reporter.reportError("no field \"%\" in this record type", ast.I.spelling, ast.I.position); |
|
|
|
|
} |
|
|
|
|
return ast.type; |
|
|
|
|
} |
|
|
|
@ -773,8 +736,7 @@ public Object visitSimpleVname(SimpleVname ast, Object o) { |
|
|
|
|
ast.type = ((VarFormalParameter) binding).T; |
|
|
|
|
ast.variable = true; |
|
|
|
|
} else |
|
|
|
|
reporter.reportError("\"%\" is not a const or var identifier", |
|
|
|
|
ast.I.spelling, ast.I.position); |
|
|
|
|
reporter.reportError("\"%\" is not a const or var identifier", ast.I.spelling, ast.I.position); |
|
|
|
|
return ast.type; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -788,8 +750,7 @@ public Object visitSubscriptVname(SubscriptVname ast, Object o) { |
|
|
|
|
reporter.reportError("array expected here", "", ast.V.position); |
|
|
|
|
else { |
|
|
|
|
if (!eType.equals(StdEnvironment.integerType)) |
|
|
|
|
reporter.reportError("Integer expression expected here", "", |
|
|
|
|
ast.E.position); |
|
|
|
|
reporter.reportError("Integer expression expected here", "", ast.E.position); |
|
|
|
|
ast.type = ((ArrayTypeDenoter) vType).T; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -890,8 +851,7 @@ public Object visitProgram(Program ast, Object o) { |
|
|
|
|
|
|
|
|
|
ProcDeclaration binding; |
|
|
|
|
|
|
|
|
|
binding = new ProcDeclaration(new Identifier(id, dummyPos), fps, |
|
|
|
|
new EmptyCommand(dummyPos), dummyPos); |
|
|
|
|
binding = new ProcDeclaration(new Identifier(id, dummyPos), fps, new EmptyCommand(dummyPos), dummyPos); |
|
|
|
|
idTable.enter(id, binding); |
|
|
|
|
return binding; |
|
|
|
|
} |
|
|
|
@ -899,13 +859,12 @@ public Object visitProgram(Program ast, Object o) { |
|
|
|
|
// Creates a small AST to represent the "declaration" of a standard
|
|
|
|
|
// type, and enters it in the identification table.
|
|
|
|
|
|
|
|
|
|
private FuncDeclaration declareStdFunc(String id, FormalParameterSequence fps, |
|
|
|
|
TypeDenoter resultType) { |
|
|
|
|
private FuncDeclaration declareStdFunc(String id, FormalParameterSequence fps, TypeDenoter resultType) { |
|
|
|
|
|
|
|
|
|
FuncDeclaration binding; |
|
|
|
|
|
|
|
|
|
binding = new FuncDeclaration(new Identifier(id, dummyPos), fps, resultType, |
|
|
|
|
new EmptyExpression(dummyPos), dummyPos); |
|
|
|
|
binding = new FuncDeclaration(new Identifier(id, dummyPos), fps, resultType, new EmptyExpression(dummyPos), |
|
|
|
|
dummyPos); |
|
|
|
|
idTable.enter(id, binding); |
|
|
|
|
return binding; |
|
|
|
|
} |
|
|
|
@ -918,8 +877,7 @@ public Object visitProgram(Program ast, Object o) { |
|
|
|
|
|
|
|
|
|
UnaryOperatorDeclaration binding; |
|
|
|
|
|
|
|
|
|
binding = new UnaryOperatorDeclaration(new Operator(op, dummyPos), |
|
|
|
|
argType, resultType, dummyPos); |
|
|
|
|
binding = new UnaryOperatorDeclaration(new Operator(op, dummyPos), argType, resultType, dummyPos); |
|
|
|
|
idTable.enter(op, binding); |
|
|
|
|
return binding; |
|
|
|
|
} |
|
|
|
@ -933,8 +891,7 @@ public Object visitProgram(Program ast, Object o) { |
|
|
|
|
|
|
|
|
|
BinaryOperatorDeclaration binding; |
|
|
|
|
|
|
|
|
|
binding = new BinaryOperatorDeclaration(new Operator(op, dummyPos), |
|
|
|
|
arg1Type, arg2type, resultType, dummyPos); |
|
|
|
|
binding = new BinaryOperatorDeclaration(new Operator(op, dummyPos), arg1Type, arg2type, resultType, dummyPos); |
|
|
|
|
idTable.enter(op, binding); |
|
|
|
|
return binding; |
|
|
|
|
} |
|
|
|
@ -986,10 +943,14 @@ public Object visitProgram(Program ast, Object o) { |
|
|
|
|
StdEnvironment.booleanType); |
|
|
|
|
|
|
|
|
|
StdEnvironment.charDecl = declareStdType("Char", StdEnvironment.charType); |
|
|
|
|
StdEnvironment.chrDecl = declareStdFunc("chr", new SingleFormalParameterSequence( |
|
|
|
|
new ConstFormalParameter(dummyI, StdEnvironment.integerType, dummyPos), dummyPos), StdEnvironment.charType); |
|
|
|
|
StdEnvironment.ordDecl = declareStdFunc("ord", new SingleFormalParameterSequence( |
|
|
|
|
new ConstFormalParameter(dummyI, StdEnvironment.charType, dummyPos), dummyPos), StdEnvironment.integerType); |
|
|
|
|
StdEnvironment.chrDecl = declareStdFunc("chr", |
|
|
|
|
new SingleFormalParameterSequence( |
|
|
|
|
new ConstFormalParameter(dummyI, StdEnvironment.integerType, dummyPos), dummyPos), |
|
|
|
|
StdEnvironment.charType); |
|
|
|
|
StdEnvironment.ordDecl = declareStdFunc("ord", |
|
|
|
|
new SingleFormalParameterSequence(new ConstFormalParameter(dummyI, StdEnvironment.charType, dummyPos), |
|
|
|
|
dummyPos), |
|
|
|
|
StdEnvironment.integerType); |
|
|
|
|
StdEnvironment.eofDecl = declareStdFunc("eof", new EmptyFormalParameterSequence(dummyPos), |
|
|
|
|
StdEnvironment.booleanType); |
|
|
|
|
StdEnvironment.eolDecl = declareStdFunc("eol", new EmptyFormalParameterSequence(dummyPos), |
|
|
|
|