public void outArrayAssignStatement(ArrayAssignStatement node) {
STE ste = this.mCurrentST.lookup( node.getIdLit().getLexeme() );
this.mCurrentST.setNodeSTE( node.getIdLit(), ste);
if((ste == null) || (!(ste instanceof VarSTE))) {
throw new SemanticException(
"Undeclared variable " + node.getIdLit().getLexeme(),
node.getIdLit().getLine(),
node.getIdLit().getPos());
}
VarSTE varEntry = (VarSTE) ste;
Type arrayType = mCurrentST.getExpType(node.getExp());
if((varEntry.getType() != Type.COLOR_ARRAY) && (varEntry.getType() != Type.INT_ARRAY)) {
throw new SemanticException(
"Array reference to non-array type",
node.getIdLit().getLine(),
node.getIdLit().getPos());
}
if ((mCurrentST.getExpType(node.getIndex()) != Type.INT) && (mCurrentST.getExpType(node.getIndex()) != Type.BYTE)) {
throw new SemanticException(
"Index expression type for array reference must be INT or BYTE",
node.getIdLit().getLine(),
node.getIdLit().getPos());
}
if( ((varEntry.getType() == Type.INT_ARRAY) && (arrayType != Type.INT) && (arrayType != Type.BYTE)) || (varEntry.getType() == Type.COLOR_ARRAY) && (arrayType != Type.COLOR) ) {
throw new SemanticException(
"Invalid expression type assigned to variable " + node.getIdLit().getLexeme(),
node.getIdLit().getLine(),
node.getIdLit().getPos());
}
}