Format code and fix warnings.

main
Deryck Brown 2 years ago
parent 2c426b5b2e
commit a02acc009b
  1. 8
      Triangle.AbstractMachine.Disassembler/src/main/java/Triangle/AbstractMachine/Disassembler.java
  2. 10
      Triangle.AbstractMachine.Interpreter/src/main/java/Triangle/AbstractMachine/Interpreter.java
  3. 80
      Triangle.AbstractMachine/src/main/java/Triangle/AbstractMachine/Machine.java
  4. 3
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/ArrayExpression.java
  5. 7
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/ArrayTypeDenoter.java
  6. 3
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/BinaryExpression.java
  7. 3
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/BinaryOperatorDeclaration.java
  8. 3
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/CallCommand.java
  9. 3
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/CallExpression.java
  10. 3
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/ConstDeclaration.java
  11. 3
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/ConstFormalParameter.java
  12. 3
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/FuncDeclaration.java
  13. 4
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/FuncFormalParameter.java
  14. 3
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/IfCommand.java
  15. 3
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/IfExpression.java
  16. 3
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/MultipleArrayAggregate.java
  17. 4
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/MultipleFieldTypeDenoter.java
  18. 3
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/ProcDeclaration.java
  19. 3
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/ProcFormalParameter.java
  20. 3
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/SequentialDeclaration.java
  21. 3
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/SingleActualParameterSequence.java
  22. 3
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/SingleArrayAggregate.java
  23. 6
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/SingleFieldTypeDenoter.java
  24. 3
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/SingleFormalParameterSequence.java
  25. 3
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/SingleRecordAggregate.java
  26. 3
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/TypeDeclaration.java
  27. 3
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/UnaryExpression.java
  28. 4
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/UnaryOperatorDeclaration.java
  29. 3
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/VarDeclaration.java
  30. 3
      Triangle.Compiler/src/main/java/Triangle/AbstractSyntaxTrees/VarFormalParameter.java
  31. 135
      Triangle.Compiler/src/main/java/Triangle/CodeGenerator/Encoder.java
  32. 38
      Triangle.Compiler/src/main/java/Triangle/Compiler.java
  33. 145
      Triangle.Compiler/src/main/java/Triangle/ContextualAnalyzer/Checker.java
  34. 5
      Triangle.Compiler/src/main/java/Triangle/StdEnvironment.java
  35. 39
      Triangle.Compiler/src/main/java/Triangle/SyntacticAnalyzer/Parser.java
  36. 11
      Triangle.Compiler/src/main/java/Triangle/SyntacticAnalyzer/Scanner.java
  37. 16
      Triangle.Compiler/src/main/java/Triangle/SyntacticAnalyzer/SourceFile.java
  38. 91
      Triangle.Compiler/src/main/java/Triangle/SyntacticAnalyzer/Token.java
  39. 3
      Triangle.Compiler/src/main/java/Triangle/TreeDrawer/DrawerFrame.java
  40. 7
      Triangle.Compiler/src/main/java/Triangle/TreeDrawer/DrawingTree.java
  41. 18
      Triangle.Compiler/src/main/java/Triangle/TreeDrawer/LayoutVisitor.java

@ -20,8 +20,8 @@ import java.io.FileNotFoundException;
import java.io.IOException;
/**
* Disassembles the TAM code in the given file, and displays the
* instructions on standard output.
* Disassembles the TAM code in the given file, and displays the instructions on
* standard output.
*
* For example:
*
@ -43,8 +43,8 @@ public class Disassembler {
static int CT;
/**
* Writes the r-field of an instruction in the form "l<I>reg</I>r", where
* l and r are the bracket characters to use.
* Writes the r-field of an instruction in the form "l<I>reg</I>r", where l and
* r are the bracket characters to use.
*
* @param leftbracket the character to print before the register.
* @param r the number of the register.

@ -29,16 +29,13 @@ public class Interpreter {
// DATA STORE REGISTERS AND OTHER REGISTERS
final static int CB = 0,
SB = 0,
HB = 1024; // = upper bound of data array + 1
final static int CB = 0, SB = 0, HB = 1024; // = upper bound of data array + 1
static int CT, CP, ST, HT, LB, status;
// status values
final static int running = 0, halted = 1, failedDataStoreFull = 2, failedInvalidCodeAddress = 3,
failedInvalidInstruction = 4, failedOverflow = 5, failedZeroDivide = 6,
failedIOError = 7;
failedInvalidInstruction = 4, failedOverflow = 5, failedZeroDivide = 6, failedIOError = 7;
static long accumulator;
@ -88,8 +85,7 @@ public class Interpreter {
static void dump() {
// Writes a summary of the machine state.
int addr, staticLink, dynamicLink,
localRegNum;
int addr, staticLink, dynamicLink, localRegNum;
System.out.println("");
System.out.println("State of data store and registers:");

@ -32,21 +32,8 @@ public final class Machine {
// INSTRUCTIONS
// Operation codes
public final static int LOADop = 0,
LOADAop = 1,
LOADIop = 2,
LOADLop = 3,
STOREop = 4,
STOREIop = 5,
CALLop = 6,
CALLIop = 7,
RETURNop = 8,
PUSHop = 10,
POPop = 11,
JUMPop = 12,
JUMPIop = 13,
JUMPIFop = 14,
HALTop = 15;
public final static int LOADop = 0, LOADAop = 1, LOADIop = 2, LOADLop = 3, STOREop = 4, STOREIop = 5, CALLop = 6,
CALLIop = 7, RETURNop = 8, PUSHop = 10, POPop = 11, JUMPop = 12, JUMPIop = 13, JUMPIFop = 14, HALTop = 15;
// CODE STORE
@ -54,72 +41,31 @@ public final class Machine {
// CODE STORE REGISTERS
public final static int CB = 0,
PB = 1024, // = upper bound of code array + 1
public final static int CB = 0, PB = 1024, // = upper bound of code array + 1
PT = 1052; // = PB + 28
// REGISTER NUMBERS
public final static int CBr = 0,
CTr = 1,
PBr = 2,
PTr = 3,
SBr = 4,
STr = 5,
HBr = 6,
HTr = 7,
LBr = 8,
L1r = LBr + 1,
L2r = LBr + 2,
L3r = LBr + 3,
L4r = LBr + 4,
L5r = LBr + 5,
L6r = LBr + 6,
CPr = 15;
public final static int CBr = 0, CTr = 1, PBr = 2, PTr = 3, SBr = 4, STr = 5, HBr = 6, HTr = 7, LBr = 8,
L1r = LBr + 1, L2r = LBr + 2, L3r = LBr + 3, L4r = LBr + 4, L5r = LBr + 5, L6r = LBr + 6, CPr = 15;
// DATA REPRESENTATION
public final static int booleanSize = 1,
characterSize = 1,
integerSize = 1,
addressSize = 1,
public final static int booleanSize = 1, characterSize = 1, integerSize = 1, addressSize = 1,
closureSize = 2 * addressSize,
linkDataSize = 3 * addressSize,
falseRep = 0,
trueRep = 1,
maxintRep = 32767;
falseRep = 0, trueRep = 1, maxintRep = 32767;
// ADDRESSES OF PRIMITIVE ROUTINES
public final static int idDisplacement = 1,
notDisplacement = 2,
andDisplacement = 3,
orDisplacement = 4,
succDisplacement = 5,
predDisplacement = 6,
negDisplacement = 7,
addDisplacement = 8,
subDisplacement = 9,
multDisplacement = 10,
divDisplacement = 11,
modDisplacement = 12,
ltDisplacement = 13,
leDisplacement = 14,
geDisplacement = 15,
gtDisplacement = 16,
eqDisplacement = 17,
neDisplacement = 18,
eolDisplacement = 19,
eofDisplacement = 20,
getDisplacement = 21,
putDisplacement = 22,
geteolDisplacement = 23,
puteolDisplacement = 24,
getintDisplacement = 25,
putintDisplacement = 26,
newDisplacement = 27,
public final static int idDisplacement = 1, notDisplacement = 2, andDisplacement = 3, orDisplacement = 4,
succDisplacement = 5, predDisplacement = 6, negDisplacement = 7, addDisplacement = 8, subDisplacement = 9,
multDisplacement = 10, divDisplacement = 11, modDisplacement = 12, ltDisplacement = 13, leDisplacement = 14,
geDisplacement = 15, gtDisplacement = 16, eqDisplacement = 17, neDisplacement = 18, eolDisplacement = 19,
eofDisplacement = 20, getDisplacement = 21, putDisplacement = 22, geteolDisplacement = 23,
puteolDisplacement = 24, getintDisplacement = 25, putintDisplacement = 26, newDisplacement = 27,
disposeDisplacement = 28;
}

@ -18,8 +18,7 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class ArrayExpression extends Expression {
public ArrayExpression(ArrayAggregate aaAST,
SourcePosition thePosition) {
public ArrayExpression(ArrayAggregate aaAST, SourcePosition thePosition) {
super(thePosition);
AA = aaAST;
}

@ -18,8 +18,7 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class ArrayTypeDenoter extends TypeDenoter {
public ArrayTypeDenoter(IntegerLiteral ilAST, TypeDenoter tAST,
SourcePosition thePosition) {
public ArrayTypeDenoter(IntegerLiteral ilAST, TypeDenoter tAST, SourcePosition thePosition) {
super(thePosition);
IL = ilAST;
T = tAST;
@ -35,8 +34,8 @@ public boolean equals(Object obj) {
if (obj != null && obj instanceof ErrorTypeDenoter)
return true;
else if (obj != null && obj instanceof ArrayTypeDenoter)
return this.IL.spelling.compareTo(((ArrayTypeDenoter) obj).IL.spelling) == 0 &&
this.T.equals(((ArrayTypeDenoter) obj).T);
return this.IL.spelling.compareTo(((ArrayTypeDenoter) obj).IL.spelling) == 0
&& this.T.equals(((ArrayTypeDenoter) obj).T);
else
return false;
}

@ -18,8 +18,7 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class BinaryExpression extends Expression {
public BinaryExpression(Expression e1AST, Operator oAST, Expression e2AST,
SourcePosition thePosition) {
public BinaryExpression(Expression e1AST, Operator oAST, Expression e2AST, SourcePosition thePosition) {
super(thePosition);
O = oAST;
E1 = e1AST;

@ -18,8 +18,7 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class BinaryOperatorDeclaration extends Declaration {
public BinaryOperatorDeclaration(Operator oAST, TypeDenoter arg1AST,
TypeDenoter arg2AST, TypeDenoter resultAST,
public BinaryOperatorDeclaration(Operator oAST, TypeDenoter arg1AST, TypeDenoter arg2AST, TypeDenoter resultAST,
SourcePosition thePosition) {
super(thePosition);
O = oAST;

@ -18,8 +18,7 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class CallCommand extends Command {
public CallCommand(Identifier iAST, ActualParameterSequence apsAST,
SourcePosition thePosition) {
public CallCommand(Identifier iAST, ActualParameterSequence apsAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
APS = apsAST;

@ -18,8 +18,7 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class CallExpression extends Expression {
public CallExpression(Identifier iAST, ActualParameterSequence apsAST,
SourcePosition thePosition) {
public CallExpression(Identifier iAST, ActualParameterSequence apsAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
APS = apsAST;

@ -18,8 +18,7 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class ConstDeclaration extends Declaration {
public ConstDeclaration(Identifier iAST, Expression eAST,
SourcePosition thePosition) {
public ConstDeclaration(Identifier iAST, Expression eAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
E = eAST;

@ -18,8 +18,7 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class ConstFormalParameter extends FormalParameter {
public ConstFormalParameter(Identifier iAST, TypeDenoter tAST,
SourcePosition thePosition) {
public ConstFormalParameter(Identifier iAST, TypeDenoter tAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
T = tAST;

@ -18,8 +18,7 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class FuncDeclaration extends Declaration {
public FuncDeclaration(Identifier iAST, FormalParameterSequence fpsAST,
TypeDenoter tAST, Expression eAST,
public FuncDeclaration(Identifier iAST, FormalParameterSequence fpsAST, TypeDenoter tAST, Expression eAST,
SourcePosition thePosition) {
super(thePosition);
I = iAST;

@ -18,8 +18,8 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class FuncFormalParameter extends FormalParameter {
public FuncFormalParameter(Identifier iAST, FormalParameterSequence fpsAST,
TypeDenoter tAST, SourcePosition thePosition) {
public FuncFormalParameter(Identifier iAST, FormalParameterSequence fpsAST, TypeDenoter tAST,
SourcePosition thePosition) {
super(thePosition);
I = iAST;
FPS = fpsAST;

@ -18,8 +18,7 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class IfCommand extends Command {
public IfCommand(Expression eAST, Command c1AST, Command c2AST,
SourcePosition thePosition) {
public IfCommand(Expression eAST, Command c1AST, Command c2AST, SourcePosition thePosition) {
super(thePosition);
E = eAST;
C1 = c1AST;

@ -18,8 +18,7 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class IfExpression extends Expression {
public IfExpression(Expression e1AST, Expression e2AST, Expression e3AST,
SourcePosition thePosition) {
public IfExpression(Expression e1AST, Expression e2AST, Expression e3AST, SourcePosition thePosition) {
super(thePosition);
E1 = e1AST;
E2 = e2AST;

@ -18,8 +18,7 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class MultipleArrayAggregate extends ArrayAggregate {
public MultipleArrayAggregate(Expression eAST, ArrayAggregate aaAST,
SourcePosition thePosition) {
public MultipleArrayAggregate(Expression eAST, ArrayAggregate aaAST, SourcePosition thePosition) {
super(thePosition);
E = eAST;
AA = aaAST;

@ -35,9 +35,7 @@ public Object visit(Visitor v, Object o) {
public boolean equals(Object obj) {
if (obj != null && obj instanceof MultipleFieldTypeDenoter) {
MultipleFieldTypeDenoter ft = (MultipleFieldTypeDenoter) obj;
return (this.I.spelling.compareTo(ft.I.spelling) == 0) &&
this.T.equals(ft.T) &&
this.FT.equals(ft.FT);
return (this.I.spelling.compareTo(ft.I.spelling) == 0) && this.T.equals(ft.T) && this.FT.equals(ft.FT);
} else
return false;
}

@ -18,8 +18,7 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class ProcDeclaration extends Declaration {
public ProcDeclaration(Identifier iAST, FormalParameterSequence fpsAST,
Command cAST, SourcePosition thePosition) {
public ProcDeclaration(Identifier iAST, FormalParameterSequence fpsAST, Command cAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
FPS = fpsAST;

@ -18,8 +18,7 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class ProcFormalParameter extends FormalParameter {
public ProcFormalParameter(Identifier iAST, FormalParameterSequence fpsAST,
SourcePosition thePosition) {
public ProcFormalParameter(Identifier iAST, FormalParameterSequence fpsAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
FPS = fpsAST;

@ -18,8 +18,7 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class SequentialDeclaration extends Declaration {
public SequentialDeclaration(Declaration d1AST, Declaration d2AST,
SourcePosition thePosition) {
public SequentialDeclaration(Declaration d1AST, Declaration d2AST, SourcePosition thePosition) {
super(thePosition);
D1 = d1AST;
D2 = d2AST;

@ -18,8 +18,7 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class SingleActualParameterSequence extends ActualParameterSequence {
public SingleActualParameterSequence(ActualParameter apAST,
SourcePosition thePosition) {
public SingleActualParameterSequence(ActualParameter apAST, SourcePosition thePosition) {
super(thePosition);
AP = apAST;
}

@ -18,8 +18,7 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class SingleArrayAggregate extends ArrayAggregate {
public SingleArrayAggregate(Expression eAST,
SourcePosition thePosition) {
public SingleArrayAggregate(Expression eAST, SourcePosition thePosition) {
super(thePosition);
E = eAST;
}

@ -18,8 +18,7 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class SingleFieldTypeDenoter extends FieldTypeDenoter {
public SingleFieldTypeDenoter(Identifier iAST, TypeDenoter tAST,
SourcePosition thePosition) {
public SingleFieldTypeDenoter(Identifier iAST, TypeDenoter tAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
T = tAST;
@ -34,8 +33,7 @@ public Object visit(Visitor v, Object o) {
public boolean equals(Object obj) {
if (obj != null && obj instanceof SingleFieldTypeDenoter) {
SingleFieldTypeDenoter ft = (SingleFieldTypeDenoter) obj;
return (this.I.spelling.compareTo(ft.I.spelling) == 0) &&
this.T.equals(ft.T);
return (this.I.spelling.compareTo(ft.I.spelling) == 0) && this.T.equals(ft.T);
} else
return false;
}

@ -18,8 +18,7 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class SingleFormalParameterSequence extends FormalParameterSequence {
public SingleFormalParameterSequence(FormalParameter fpAST,
SourcePosition thePosition) {
public SingleFormalParameterSequence(FormalParameter fpAST, SourcePosition thePosition) {
super(thePosition);
FP = fpAST;
}

@ -18,8 +18,7 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class SingleRecordAggregate extends RecordAggregate {
public SingleRecordAggregate(Identifier iAST, Expression eAST,
SourcePosition thePosition) {
public SingleRecordAggregate(Identifier iAST, Expression eAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
E = eAST;

@ -18,8 +18,7 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class TypeDeclaration extends Declaration {
public TypeDeclaration(Identifier iAST, TypeDenoter tAST,
SourcePosition thePosition) {
public TypeDeclaration(Identifier iAST, TypeDenoter tAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
T = tAST;

@ -18,8 +18,7 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class UnaryExpression extends Expression {
public UnaryExpression(Operator oAST, Expression eAST,
SourcePosition thePosition) {
public UnaryExpression(Operator oAST, Expression eAST, SourcePosition thePosition) {
super(thePosition);
O = oAST;
E = eAST;

@ -18,8 +18,8 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class UnaryOperatorDeclaration extends Declaration {
public UnaryOperatorDeclaration(Operator oAST, TypeDenoter argAST,
TypeDenoter resultAST, SourcePosition thePosition) {
public UnaryOperatorDeclaration(Operator oAST, TypeDenoter argAST, TypeDenoter resultAST,
SourcePosition thePosition) {
super(thePosition);
O = oAST;
ARG = argAST;

@ -18,8 +18,7 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class VarDeclaration extends Declaration {
public VarDeclaration(Identifier iAST, TypeDenoter tAST,
SourcePosition thePosition) {
public VarDeclaration(Identifier iAST, TypeDenoter tAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
T = tAST;

@ -18,8 +18,7 @@ import Triangle.SyntacticAnalyzer.SourcePosition;
public class VarFormalParameter extends FormalParameter {
public VarFormalParameter(Identifier iAST, TypeDenoter tAST,
SourcePosition thePosition) {
public VarFormalParameter(Identifier iAST, TypeDenoter tAST, SourcePosition thePosition) {
super(thePosition);
I = iAST;
T = tAST;

@ -97,8 +97,7 @@ public final class Encoder implements Visitor {
public Object visitAssignCommand(AssignCommand ast, Object o) {
Frame frame = (Frame) o;
Integer valSize = (Integer) ast.E.visit(this, frame);
encodeStore(ast.V, new Frame(frame, valSize.intValue()),
valSize.intValue());
encodeStore(ast.V, new Frame(frame, valSize.intValue()), valSize.intValue());
return null;
}
@ -193,8 +192,7 @@ public Object visitCallExpression(CallExpression ast, Object o) {
}
@Override
public Object visitCharacterExpression(CharacterExpression ast,
Object o) {
public Object visitCharacterExpression(CharacterExpression ast, Object o) {
Frame frame = (Frame) o;
Integer valSize = (Integer) ast.type.visit(this, null);
emit(Machine.LOADLop, 0, 0, ast.CL.spelling.charAt(1));
@ -270,8 +268,7 @@ public Object visitVnameExpression(VnameExpression ast, Object o) {
// Declarations
@Override
public Object visitBinaryOperatorDeclaration(BinaryOperatorDeclaration ast,
Object o) {
public Object visitBinaryOperatorDeclaration(BinaryOperatorDeclaration ast, Object o) {
return Integer.valueOf(0);
}
@ -282,12 +279,10 @@ public Object visitConstDeclaration(ConstDeclaration ast, Object o) {
if (ast.E instanceof CharacterExpression) {
CharacterLiteral CL = ((CharacterExpression) ast.E).CL;
ast.entity = new KnownValue(Machine.characterSize,
characterValuation(CL.spelling));
ast.entity = new KnownValue(Machine.characterSize, characterValuation(CL.spelling));
} else if (ast.E instanceof IntegerExpression) {
IntegerLiteral IL = ((IntegerExpression) ast.E).IL;
ast.entity = new KnownValue(Machine.integerSize,
Integer.parseInt(IL.spelling));
ast.entity = new KnownValue(Machine.integerSize, Integer.parseInt(IL.spelling));
} else {
int valSize = ((Integer) ast.E.visit(this, frame)).intValue();
ast.entity = new UnknownValue(valSize, frame.level, frame.size);
@ -326,8 +321,7 @@ public Object visitProcDeclaration(ProcDeclaration ast, Object o) {
int argsSize = 0;
emit(Machine.JUMPop, 0, Machine.CBr, 0);
ast.entity = new KnownRoutine(Machine.closureSize, frame.level,
nextInstrAddr);
ast.entity = new KnownRoutine(Machine.closureSize, frame.level, nextInstrAddr);
writeTableDetails(ast);
if (frame.level == Machine.maxRoutineLevel)
reporter.reportRestriction("can't nest routines so deeply");
@ -361,8 +355,7 @@ public Object visitTypeDeclaration(TypeDeclaration ast, Object o) {
}
@Override
public Object visitUnaryOperatorDeclaration(UnaryOperatorDeclaration ast,
Object o) {
public Object visitUnaryOperatorDeclaration(UnaryOperatorDeclaration ast, Object o) {
return Integer.valueOf(0);
}
@ -380,8 +373,7 @@ public Object visitVarDeclaration(VarDeclaration ast, Object o) {
// Array Aggregates
@Override
public Object visitMultipleArrayAggregate(MultipleArrayAggregate ast,
Object o) {
public Object visitMultipleArrayAggregate(MultipleArrayAggregate ast, Object o) {
Frame frame = (Frame) o;
int elemSize = ((Integer) ast.E.visit(this, frame)).intValue();
Frame frame1 = new Frame(frame, elemSize);
@ -396,8 +388,7 @@ public Object visitSingleArrayAggregate(SingleArrayAggregate ast, Object o) {
// Record Aggregates
@Override
public Object visitMultipleRecordAggregate(MultipleRecordAggregate ast,
Object o) {
public Object visitMultipleRecordAggregate(MultipleRecordAggregate ast, Object o) {
Frame frame = (Frame) o;
int fieldSize = ((Integer) ast.E.visit(this, frame)).intValue();
Frame frame1 = new Frame(frame, fieldSize);
@ -406,8 +397,7 @@ public Object visitMultipleRecordAggregate(MultipleRecordAggregate ast,
}
@Override
public Object visitSingleRecordAggregate(SingleRecordAggregate ast,
Object o) {
public Object visitSingleRecordAggregate(SingleRecordAggregate ast, Object o) {
return ast.E.visit(this, o);
}
@ -425,8 +415,7 @@ public Object visitConstFormalParameter(ConstFormalParameter ast, Object o) {
public Object visitFuncFormalParameter(FuncFormalParameter ast, Object o) {
Frame frame = (Frame) o;
int argsSize = Machine.closureSize;
ast.entity = new UnknownRoutine(Machine.closureSize, frame.level,
-frame.size - argsSize);
ast.entity = new UnknownRoutine(Machine.closureSize, frame.level, -frame.size - argsSize);
writeTableDetails(ast);
return Integer.valueOf(argsSize);
}
@ -435,8 +424,7 @@ public Object visitFuncFormalParameter(FuncFormalParameter ast, Object o) {
public Object visitProcFormalParameter(ProcFormalParameter ast, Object o) {
Frame frame = (Frame) o;
int argsSize = Machine.closureSize;
ast.entity = new UnknownRoutine(Machine.closureSize, frame.level,
-frame.size - argsSize);
ast.entity = new UnknownRoutine(Machine.closureSize, frame.level, -frame.size - argsSize);
writeTableDetails(ast);
return Integer.valueOf(argsSize);
}
@ -445,21 +433,18 @@ public Object visitProcFormalParameter(ProcFormalParameter ast, Object o) {
public Object visitVarFormalParameter(VarFormalParameter ast, Object o) {
Frame frame = (Frame) o;
ast.T.visit(this, null);
ast.entity = new UnknownAddress(Machine.addressSize, frame.level,
-frame.size - Machine.addressSize);
ast.entity = new UnknownAddress(Machine.addressSize, frame.level, -frame.size - Machine.addressSize);
writeTableDetails(ast);
return Integer.valueOf(Machine.addressSize);
}
@Override
public Object visitEmptyFormalParameterSequence(
EmptyFormalParameterSequence ast, Object o) {
public Object visitEmptyFormalParameterSequence(EmptyFormalParameterSequence ast, Object o) {
return Integer.valueOf(0);
}
@Override
public Object visitMultipleFormalParameterSequence(
MultipleFormalParameterSequence ast, Object o) {
public Object visitMultipleFormalParameterSequence(MultipleFormalParameterSequence ast, Object o) {
Frame frame = (Frame) o;
int argsSize1 = ((Integer) ast.FPS.visit(this, frame)).intValue();
Frame frame1 = new Frame(frame, argsSize1);
@ -468,8 +453,7 @@ public Object visitMultipleFormalParameterSequence(
}
@Override
public Object visitSingleFormalParameterSequence(
SingleFormalParameterSequence ast, Object o) {
public Object visitSingleFormalParameterSequence(SingleFormalParameterSequence ast, Object o) {
return ast.FP.visit(this, o);
}
@ -489,8 +473,8 @@ public Object visitFuncActualParameter(FuncActualParameter ast, Object o) {
emit(Machine.LOADAop, 0, Machine.CBr, address.displacement);
} else if (ast.I.decl.entity instanceof UnknownRoutine) {
ObjectAddress address = ((UnknownRoutine) ast.I.decl.entity).address;
emit(Machine.LOADop, Machine.closureSize, displayRegister(frame.level,
address.level), address.displacement);
emit(Machine.LOADop, Machine.closureSize, displayRegister(frame.level, address.level),
address.displacement);
} else if (ast.I.decl.entity instanceof PrimitiveRoutine) {
int displacement = ((PrimitiveRoutine) ast.I.decl.entity).displacement;
// static link, code address
@ -510,8 +494,8 @@ public Object visitProcActualParameter(ProcActualParameter ast, Object o) {
emit(Machine.LOADAop, 0, Machine.CBr, address.displacement);
} else if (ast.I.decl.entity instanceof UnknownRoutine) {
ObjectAddress address = ((UnknownRoutine) ast.I.decl.entity).address;
emit(Machine.LOADop, Machine.closureSize, displayRegister(frame.level,
address.level), address.displacement);
emit(Machine.LOADop, Machine.closureSize, displayRegister(frame.level, address.level),
address.displacement);
} else if (ast.I.decl.entity instanceof PrimitiveRoutine) {
int displacement = ((PrimitiveRoutine) ast.I.decl.entity).displacement;
// static link, code address
@ -528,14 +512,12 @@ public Object visitVarActualParameter(VarActualParameter ast, Object o) {
}
@Override
public Object visitEmptyActualParameterSequence(
EmptyActualParameterSequence ast, Object o) {
public Object visitEmptyActualParameterSequence(EmptyActualParameterSequence ast, Object o) {
return Integer.valueOf(0);
}
@Override
public Object visitMultipleActualParameterSequence(
MultipleActualParameterSequence ast, Object o) {
public Object visitMultipleActualParameterSequence(MultipleActualParameterSequence ast, Object o) {
Frame frame = (Frame) o;
int argsSize1 = ((Integer) ast.AP.visit(this, frame)).intValue();
Frame frame1 = new Frame(frame, argsSize1);
@ -544,8 +526,7 @@ public Object visitMultipleActualParameterSequence(
}
@Override
public Object visitSingleActualParameterSequence(
SingleActualParameterSequence ast, Object o) {
public Object visitSingleActualParameterSequence(SingleActualParameterSequence ast, Object o) {
return ast.AP.visit(this, o);
}
@ -592,8 +573,7 @@ public Object visitErrorTypeDenoter(ErrorTypeDenoter ast, Object o) {
}
@Override
public Object visitSimpleTypeDenoter(SimpleTypeDenoter ast,
Object o) {
public Object visitSimpleTypeDenoter(SimpleTypeDenoter ast, Object o) {
return Integer.valueOf(0);
}
@ -619,8 +599,7 @@ public Object visitRecordTypeDenoter(RecordTypeDenoter ast, Object o) {
}
@Override
public Object visitMultipleFieldTypeDenoter(MultipleFieldTypeDenoter ast,
Object o) {
public Object visitMultipleFieldTypeDenoter(MultipleFieldTypeDenoter ast, Object o) {
int offset = ((Integer) o).intValue();
int fieldSize;
@ -637,8 +616,7 @@ public Object visitMultipleFieldTypeDenoter(MultipleFieldTypeDenoter ast,
}
@Override
public Object visitSingleFieldTypeDenoter(SingleFieldTypeDenoter ast,
Object o) {
public Object visitSingleFieldTypeDenoter(SingleFieldTypeDenoter ast, Object o) {
int offset = ((Integer) o).intValue();
int fieldSize;
@ -663,12 +641,11 @@ public Object visitIdentifier(Identifier ast, Object o) {
Frame frame = (Frame) o;
if (ast.decl.entity instanceof KnownRoutine) {
ObjectAddress address = ((KnownRoutine) ast.decl.entity).address;
emit(Machine.CALLop, displayRegister(frame.level, address.level),
Machine.CBr, address.displacement);
emit(Machine.CALLop, displayRegister(frame.level, address.level), Machine.CBr, address.displacement);
} else if (ast.decl.entity instanceof UnknownRoutine) {
ObjectAddress address = ((UnknownRoutine) ast.decl.entity).address;
emit(Machine.LOADop, Machine.closureSize, displayRegister(frame.level,
address.level), address.displacement);
emit(Machine.LOADop, Machine.closureSize, displayRegister(frame.level, address.level),
address.displacement);
emit(Machine.CALLIop, 0, 0, 0);
} else if (ast.decl.entity instanceof PrimitiveRoutine) {
int displacement = ((PrimitiveRoutine) ast.decl.entity).displacement;
@ -692,12 +669,11 @@ public Object visitOperator(Operator ast, Object o) {
Frame frame = (Frame) o;
if (ast.decl.entity instanceof KnownRoutine) {
ObjectAddress address = ((KnownRoutine) ast.decl.entity).address;
emit(Machine.CALLop, displayRegister(frame.level, address.level),
Machine.CBr, address.displacement);
emit(Machine.CALLop, displayRegister(frame.level, address.level), Machine.CBr, address.displacement);
} else if (ast.decl.entity instanceof UnknownRoutine) {
ObjectAddress address = ((UnknownRoutine) ast.decl.entity).address;
emit(Machine.LOADop, Machine.closureSize, displayRegister(frame.level,
address.level), address.displacement);
emit(Machine.LOADop, Machine.closureSize, displayRegister(frame.level, address.level),
address.displacement);
emit(Machine.CALLIop, 0, 0, 0);
} else if (ast.decl.entity instanceof PrimitiveRoutine) {
int displacement = ((PrimitiveRoutine) ast.decl.entity).displacement;
@ -749,8 +725,7 @@ public Object visitSubscriptVname(SubscriptVname ast, Object o) {
indexSize = ((Integer) ast.E.visit(this, frame)).intValue();
if (elemSize != 1) {
emit(Machine.LOADLop, 0, 0, elemSize);
emit(Machine.CALLop, Machine.SBr, Machine.PBr,
Machine.multDisplacement);
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.multDisplacement);
}
if (ast.indexed)
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.addDisplacement);
@ -785,8 +760,7 @@ public Object visitProgram(Program ast, Object o) {
}
// Decides run-time representation of a standard constant.
private final void elaborateStdConst(Declaration constDeclaration,
int value) {
private final void elaborateStdConst(Declaration constDeclaration, int value) {
if (constDeclaration instanceof ConstDeclaration) {
ConstDeclaration decl = (ConstDeclaration) constDeclaration;
@ -797,20 +771,17 @@ public Object visitProgram(Program ast, Object o) {
}
// Decides run-time representation of a standard routine.
private final void elaborateStdPrimRoutine(Declaration routineDeclaration,
int routineOffset) {
private final void elaborateStdPrimRoutine(Declaration routineDeclaration, int routineOffset) {
routineDeclaration.entity = new PrimitiveRoutine(Machine.closureSize, routineOffset);
writeTableDetails(routineDeclaration);
}
private final void elaborateStdEqRoutine(Declaration routineDeclaration,
int routineOffset) {
private final void elaborateStdEqRoutine(Declaration routineDeclaration, int routineOffset) {
routineDeclaration.entity = new EqualityRoutine(Machine.closureSize, routineOffset);
writeTableDetails(routineDeclaration);
}
private final void elaborateStdRoutine(Declaration routineDeclaration,
int routineOffset) {
private final void elaborateStdRoutine(Declaration routineDeclaration, int routineOffset) {
routineDeclaration.entity = new KnownRoutine(Machine.closureSize, 0, routineOffset);
writeTableDetails(routineDeclaration);
}
@ -947,18 +918,17 @@ public Object visitProgram(Program ast, Object o) {
if (baseObject instanceof KnownAddress) {
ObjectAddress address = ((KnownAddress) baseObject).address;
if (V.indexed) {
emit(Machine.LOADAop, 0, displayRegister(frame.level, address.level),
address.displacement + V.offset);
emit(Machine.LOADAop, 0, displayRegister(frame.level, address.level), address.displacement + V.offset);
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.addDisplacement);
emit(Machine.STOREIop, valSize, 0, 0);
} else {
emit(Machine.STOREop, valSize, displayRegister(frame.level,
address.level), address.displacement + V.offset);
emit(Machine.STOREop, valSize, displayRegister(frame.level, address.level),
address.displacement + V.offset);
}
} else if (baseObject instanceof UnknownAddress) {
ObjectAddress address = ((UnknownAddress) baseObject).address;
emit(Machine.LOADop, Machine.addressSize, displayRegister(frame.level,
address.level), address.displacement);
emit(Machine.LOADop, Machine.addressSize, displayRegister(frame.level, address.level),
address.displacement);
if (V.indexed)
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.addDisplacement);
if (V.offset != 0) {
@ -988,22 +958,20 @@ public Object visitProgram(Program ast, Object o) {
// presumably offset = 0 and indexed = false
int value = ((KnownValue) baseObject).value;
emit(Machine.LOADLop, 0, 0, value);
} else if ((baseObject instanceof UnknownValue) ||
(baseObject instanceof KnownAddress)) {
} else if ((baseObject instanceof UnknownValue) || (baseObject instanceof KnownAddress)) {
ObjectAddress address = (baseObject instanceof UnknownValue) ? ((UnknownValue) baseObject).address
: ((KnownAddress) baseObject).address;
if (V.indexed) {
emit(Machine.LOADAop, 0, displayRegister(frame.level, address.level),
address.displacement + V.offset);
emit(Machine.LOADAop, 0, displayRegister(frame.level, address.level), address.displacement + V.offset);
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.addDisplacement);
emit(Machine.LOADIop, valSize, 0, 0);
} else
emit(Machine.LOADop, valSize, displayRegister(frame.level,
address.level), address.displacement + V.offset);
emit(Machine.LOADop, valSize, displayRegister(frame.level, address.level),
address.displacement + V.offset);
} else if (baseObject instanceof UnknownAddress) {
ObjectAddress address = ((UnknownAddress) baseObject).address;
emit(Machine.LOADop, Machine.addressSize, displayRegister(frame.level,
address.level), address.displacement);
emit(Machine.LOADop, Machine.addressSize, displayRegister(frame.level, address.level),
address.displacement);
if (V.indexed)
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.addDisplacement);
if (V.offset != 0) {
@ -1026,14 +994,13 @@ public Object visitProgram(Program ast, Object o) {
// If indexed = true, code will have been generated to load an index value.
if (baseObject instanceof KnownAddress) {
ObjectAddress address = ((KnownAddress) baseObject).address;
emit(Machine.LOADAop, 0, displayRegister(frame.level, address.level),
address.displacement + V.offset);
emit(Machine.LOADAop, 0, displayRegister(frame.level, address.level), address.displacement + V.offset);
if (V.indexed)
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.addDisplacement);
} else if (baseObject instanceof UnknownAddress) {
ObjectAddress address = ((UnknownAddress) baseObject).address;
emit(Machine.LOADop, Machine.addressSize, displayRegister(frame.level,
address.level), address.displacement);
emit(Machine.LOADop, Machine.addressSize, displayRegister(frame.level, address.level),
address.displacement);
if (V.indexed)
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.addDisplacement);
if (V.offset != 0) {

@ -46,27 +46,22 @@ public class Compiler {
/**
* Compile the source program to TAM machine code.
*
* @param sourceName the name of the file containing the
* source program.
* @param objectName the name of the file containing the
* object program.
* @param showingAST true iff the AST is to be displayed after
* contextual analysis (not currently implemented).
* @param showingTable true iff the object description details are to
* be displayed during code generation (not
* currently implemented).
* @return true iff the source program is free of compile-time errors,
* otherwise false.
* @param sourceName the name of the file containing the source program.
* @param objectName the name of the file containing the object program.
* @param showingAST true iff the AST is to be displayed after contextual
* analysis (not currently implemented).
* @param showingTable true iff the object description details are to be
* displayed during code generation (not currently
* implemented).
* @return true iff the source program is free of compile-time errors, otherwise
* false.
*/
static boolean compileProgram(String sourceName, String objectName,
boolean showingAST, boolean showingTable) {
static boolean compileProgram(String sourceName, String objectName, boolean showingAST, boolean showingTable) {
System.out.println("********** " +
"Triangle Compiler (Java Version 2.1)" +
" **********");
System.out.println("********** " + "Triangle Compiler (Java Version 2.1)" + " **********");
System.out.println("Syntactic Analysis ...");
SourceFile source = new SourceFile(sourceName);
SourceFile source = SourceFile.ofPath(sourceName);
if (source == null) {
System.out.println("Can't access source file " + sourceName);
@ -110,11 +105,10 @@ public class Compiler {
/**
* Triangle compiler main program.
*
* @param args the only command-line argument to the program specifies
* the source filename.
* @param args the only command-line argument to the program specifies the
* source filename.
*/
public static void main(String[] args) {
boolean compiledOK;
if (args.length != 1) {
System.out.println("Usage: tc filename");
@ -122,6 +116,8 @@ public class Compiler {
}
String sourceName = args[0];
compiledOK = compileProgram(sourceName, objectName, false, false);
var compiledOK = compileProgram(sourceName, objectName, false, false);
System.exit(compiledOK ? 0 : 1);
}
}

@ -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),

@ -36,9 +36,8 @@ public final class StdEnvironment {
public static UnaryOperatorDeclaration notDecl;
public static BinaryOperatorDeclaration andDecl, orDecl,
addDecl, subtractDecl, multiplyDecl, divideDecl, moduloDecl,
equalDecl, unequalDecl, lessDecl, notlessDecl, greaterDecl, notgreaterDecl;
public static BinaryOperatorDeclaration andDecl, orDecl, addDecl, subtractDecl, multiplyDecl, divideDecl,
moduloDecl, equalDecl, unequalDecl, lessDecl, notlessDecl, greaterDecl, notgreaterDecl;
public static ProcDeclaration getDecl, putDecl, getintDecl, putintDecl, geteolDecl, puteolDecl;

@ -153,8 +153,7 @@ public class Parser {
Command cAST = parseCommand();
programAST = new Program(cAST, previousTokenPosition);
if (currentToken.kind != Token.EOT) {
syntacticError("\"%\" not expected after end of program",
currentToken.spelling);
syntacticError("\"%\" not expected after end of program", currentToken.spelling);
}
} catch (SyntaxError s) {
return null;
@ -342,8 +341,7 @@ public class Parser {
break;
default:
syntacticError("\"%\" cannot start a command",
currentToken.spelling);
syntacticError("\"%\" cannot start a command", currentToken.spelling);
break;
}
@ -405,8 +403,7 @@ public class Parser {
while (currentToken.kind == Token.OPERATOR) {
Operator opAST = parseOperator();
Expression e2AST = parsePrimaryExpression();
expressionAST = new BinaryExpression(expressionAST, opAST, e2AST,
expressionPos);
expressionAST = new BinaryExpression(expressionAST, opAST, e2AST, expressionPos);
}
return expressionAST;
}
@ -483,8 +480,7 @@ public class Parser {
break;
default:
syntacticError("\"%\" cannot start an expression",
currentToken.spelling);
syntacticError("\"%\" cannot start an expression", currentToken.spelling);
break;
}
@ -550,8 +546,7 @@ public class Parser {
vnamePos = identifierAST.position;
Vname vAST = new SimpleVname(identifierAST, vnamePos);
while (currentToken.kind == Token.DOT ||
currentToken.kind == Token.LBRACKET) {
while (currentToken.kind == Token.DOT || currentToken.kind == Token.LBRACKET) {
if (currentToken.kind == Token.DOT) {
acceptIt();
@ -584,8 +579,7 @@ public class Parser {
acceptIt();
Declaration d2AST = parseSingleDeclaration();
finish(declarationPos);
declarationAST = new SequentialDeclaration(declarationAST, d2AST,
declarationPos);
declarationAST = new SequentialDeclaration(declarationAST, d2AST, declarationPos);
}
return declarationAST;
}
@ -642,8 +636,7 @@ public class Parser {
accept(Token.IS);
Expression eAST = parseExpression();
finish(declarationPos);
declarationAST = new FuncDeclaration(iAST, fpsAST, tAST, eAST,
declarationPos);
declarationAST = new FuncDeclaration(iAST, fpsAST, tAST, eAST, declarationPos);
}
break;
@ -658,8 +651,7 @@ public class Parser {
break;
default:
syntacticError("\"%\" cannot start a declaration",
currentToken.spelling);
syntacticError("\"%\" cannot start a declaration", currentToken.spelling);
break;
}
@ -698,8 +690,7 @@ public class Parser {
acceptIt();
FormalParameterSequence fpsAST = parseProperFormalParameterSequence();
finish(formalsPos);
formalsAST = new MultipleFormalParameterSequence(fpAST, fpsAST,
formalsPos);
formalsAST = new MultipleFormalParameterSequence(fpAST, fpsAST, formalsPos);
} else {
finish(formalsPos);
@ -760,8 +751,7 @@ public class Parser {
break;
default:
syntacticError("\"%\" cannot start a formal parameter",
currentToken.spelling);
syntacticError("\"%\" cannot start a formal parameter", currentToken.spelling);
break;
}
@ -795,8 +785,7 @@ public class Parser {
acceptIt();
ActualParameterSequence apsAST = parseProperActualParameterSequence();
finish(actualsPos);
actualsAST = new MultipleActualParameterSequence(apAST, apsAST,
actualsPos);
actualsAST = new MultipleActualParameterSequence(apAST, apsAST, actualsPos);
} else {
finish(actualsPos);
actualsAST = new SingleActualParameterSequence(apAST, actualsPos);
@ -853,8 +842,7 @@ public class Parser {
break;
default:
syntacticError("\"%\" cannot start an actual parameter",
currentToken.spelling);
syntacticError("\"%\" cannot start an actual parameter", currentToken.spelling);
break;
}
@ -902,8 +890,7 @@ public class Parser {
break;
default:
syntacticError("\"%\" cannot start a type denoter",
currentToken.spelling);
syntacticError("\"%\" cannot start a type denoter", currentToken.spelling);
break;
}

@ -34,10 +34,8 @@ public final class Scanner {
// isOperator returns true iff the given character is an operator character.
private boolean isOperator(char c) {
return (c == '+' || c == '-' || c == '*' || c == '/' ||
c == '=' || c == '<' || c == '>' || c == '\\' ||
c == '&' || c == '@' || c == '%' || c == '^' ||
c == '?');
return (c == '+' || c == '-' || c == '*' || c == '/' || c == '=' || c == '<' || c == '>' || c == '\\'
|| c == '&' || c == '@' || c == '%' || c == '^' || c == '?');
}
///////////////////////////////////////////////////////////////////////////////
@ -249,10 +247,7 @@ public final class Scanner {
int kind;
currentlyScanningToken = false;
while (currentChar == '!'
|| currentChar == ' '
|| currentChar == '\n'
|| currentChar == '\r'
while (currentChar == '!' || currentChar == ' ' || currentChar == '\n' || currentChar == '\r'
|| currentChar == '\t')
scanSeparator();

@ -23,16 +23,18 @@ public class SourceFile {
java.io.FileInputStream source;
int currentLine;
public SourceFile(String filename) {
public static SourceFile ofPath(String pathname) {
try {
sourceFile = new java.io.File(filename);
source = new java.io.FileInputStream(sourceFile);
currentLine = 1;
return new SourceFile(pathname);
} catch (java.io.IOException s) {
sourceFile = null;
source = null;
currentLine = 0;
return null;
}
}
private SourceFile(String pathname) throws java.io.FileNotFoundException {
sourceFile = new java.io.File(pathname);
source = new java.io.FileInputStream(sourceFile);
currentLine = 1;
}
char getSource() {

@ -52,8 +52,7 @@ final class Token extends Object {
@Override
public String toString() {
return "Kind=" + kind + ", spelling=" + spelling +
", position=" + position;
return "Kind=" + kind + ", spelling=" + spelling + ", position=" + position;
}
// Token classes...
@ -61,89 +60,25 @@ public String toString() {
public static final int
// literals, identifiers, operators...
INTLITERAL = 0,
CHARLITERAL = 1,
IDENTIFIER = 2,
OPERATOR = 3,
INTLITERAL = 0, CHARLITERAL = 1, IDENTIFIER = 2, OPERATOR = 3,
// reserved words - must be in alphabetical order...
ARRAY = 4,
BEGIN = 5,
CONST = 6,
DO = 7,
ELSE = 8,
END = 9,
FUNC = 10,
IF = 11,
IN = 12,
LET = 13,
OF = 14,
PROC = 15,
RECORD = 16,
THEN = 17,
TYPE = 18,
VAR = 19,
WHILE = 20,
ARRAY = 4, BEGIN = 5, CONST = 6, DO = 7, ELSE = 8, END = 9, FUNC = 10, IF = 11, IN = 12, LET = 13, OF = 14,
PROC = 15, RECORD = 16, THEN = 17, TYPE = 18, VAR = 19, WHILE = 20,
// punctuation...
DOT = 21,
COLON = 22,
SEMICOLON = 23,
COMMA = 24,
BECOMES = 25,
IS = 26,
DOT = 21, COLON = 22, SEMICOLON = 23, COMMA = 24, BECOMES = 25, IS = 26,
// brackets...
LPAREN = 27,
RPAREN = 28,
LBRACKET = 29,
RBRACKET = 30,
LCURLY = 31,
RCURLY = 32,
LPAREN = 27, RPAREN = 28, LBRACKET = 29, RBRACKET = 30, LCURLY = 31, RCURLY = 32,
// special tokens...
EOT = 33,
ERROR = 34;
private static String[] tokenTable = new String[] {
"<int>",
"<char>",
"<identifier>",
"<operator>",
"array",
"begin",
"const",
"do",
"else",
"end",
"func",
"if",
"in",
"let",
"of",
"proc",
"record",
"then",
"type",
"var",
"while",
".",
":",
";",
",",
":=",
"~",
"(",
")",
"[",
"]",
"{",
"}",
"",
"<error>"
};
private final static int firstReservedWord = Token.ARRAY,
lastReservedWord = Token.WHILE;
EOT = 33, ERROR = 34;
private static String[] tokenTable = new String[] { "<int>", "<char>", "<identifier>", "<operator>", "array",
"begin", "const", "do", "else", "end", "func", "if", "in", "let", "of", "proc", "record", "then", "type",
"var", "while", ".", ":", ";", ",", ":=", "~", "(", ")", "[", "]", "{", "}", "", "<error>" };
private final static int firstReservedWord = Token.ARRAY, lastReservedWord = Token.WHILE;
}

@ -42,8 +42,7 @@ public DrawerFrame(JPanel panel) {
// Image img = tk.getImage("icon.gif");
// setIconImage(img);
addWindowListener(
new WindowAdapter() {
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);

@ -53,8 +53,7 @@ public class DrawingTree {
graphics.fillRect(pos.x, pos.y, width, height);
graphics.setColor(Color.black);
graphics.drawRect(pos.x, pos.y, width - 1, height - 1);
graphics.drawString(caption, pos.x + 2,
pos.y + (height + FIXED_FONT_HEIGHT) / 2);
graphics.drawString(caption, pos.x + 2, pos.y + (height + FIXED_FONT_HEIGHT) / 2);
if (children != null) {
for (DrawingTree child : children) {
@ -63,9 +62,7 @@ public class DrawingTree {
}
if (parent != null) {
graphics.drawLine(pos.x + width / 2, pos.y,
parent.pos.x + parent.width / 2,
parent.pos.y + parent.height);
graphics.drawLine(pos.x + width / 2, pos.y, parent.pos.x + parent.width / 2, parent.pos.y + parent.height);
}
}

@ -404,8 +404,7 @@ public Object visitSimpleVname(SimpleVname ast, Object obj) {
@Override
public Object visitSubscriptVname(SubscriptVname ast, Object obj) {
return layoutBinary("Sub.Vname",
ast.V, ast.E);
return layoutBinary("Sub.Vname", ast.V, ast.E);
}
// Programs
@ -446,8 +445,7 @@ public Object visitProgram(Program ast, Object obj) {
return dt;
}
private DrawingTree layoutTernary(String name, AST child1, AST child2,
AST child3) {
private DrawingTree layoutTernary(String name, AST child1, AST child2, AST child3) {
DrawingTree dt = layoutCaption(name);
DrawingTree d1 = (DrawingTree) child1.visit(this, null);
DrawingTree d2 = (DrawingTree) child2.visit(this, null);
@ -457,8 +455,7 @@ public Object visitProgram(Program ast, Object obj) {
return dt;
}
private DrawingTree layoutQuaternary(String name, AST child1, AST child2,
AST child3, AST child4) {
private DrawingTree layoutQuaternary(String name, AST child1, AST child2, AST child3, AST child4) {
DrawingTree dt = layoutCaption(name);
DrawingTree d1 = (DrawingTree) child1.visit(this, null);
DrawingTree d2 = (DrawingTree) child2.visit(this, null);
@ -476,10 +473,8 @@ public Object visitProgram(Program ast, Object obj) {
dt.children[0].offset.y = y + dt.height;
dt.children[0].offset.x = x1;
dt.contour.upper_head = new Polyline(0, dt.height,
new Polyline(x1, y, dt.contour.upper_head));
dt.contour.lower_head = new Polyline(0, dt.height,
new Polyline(x2, y, dt.contour.lower_head));
dt.contour.upper_head = new Polyline(0, dt.height, new Polyline(x1, y, dt.contour.upper_head));
dt.contour.lower_head = new Polyline(0, dt.height, new Polyline(x2, y, dt.contour.lower_head));
}
private int join(DrawingTree dt) {
@ -573,8 +568,7 @@ public Object visitProgram(Program ast, Object obj) {
}
}
private Polyline bridge(Polyline line1, int x1, int y1,
Polyline line2, int x2, int y2) {
private Polyline bridge(Polyline line1, int x1, int y1, Polyline line2, int x2, int y2) {
int dy, dx, s;
Polyline r;