return p;
}
private static Tuple<VecInstruction,String[]> parseExpr(String[] tokens) throws ParseErrorException{
if(tokens[0].equals("NOP") || tokens[0].equals(""))
return new Tuple<VecInstruction,String[]>(new VecInstruction(NOP),Arrays.copyOfRange(tokens,1, tokens.length));
if(tokens[0].equals("SPLIT")){
int operand1;
try{
operand1 = Integer.parseInt(tokens[1]);
}catch(Exception e){
throw new ParseErrorException("parse failed on operands of SPLIT " + tokens[1]);
}
return new Tuple<VecInstruction,String[]>(new VecInstruction(SPLIT,operand1),Arrays.copyOfRange(tokens,2, tokens.length));
}
if(tokens[0].equals("MERGE")){
//tokens = Arrays.copyOfRange(tokens,1, tokens.length);
int operand1, operand2;
try{
operand1 = Integer.parseInt(tokens[1]);
operand2 = Integer.parseInt(tokens[2]);
}catch(Exception e){
throw new ParseErrorException("parse failed on operands of MERGE " + tokens[1] + " " + tokens[2]);
}
return new Tuple<VecInstruction,String[]>(new VecInstruction(MERGE,operand1,operand2),Arrays.copyOfRange(tokens,3, tokens.length));
}
if(tokens[0].equals("MOVE")){
int operand1, operand2;
try{
operand1 = Integer.parseInt(tokens[1]);
operand2 = Integer.parseInt(tokens[2]);
}catch(Exception e){
String toks = "";
for(String s : tokens) toks += ","+s;
throw new ParseErrorException("parse failed on operands of MOVE " + tokens.length + "[" + toks +"]" );
}
return new Tuple<VecInstruction,String[]>(new VecInstruction(MOVE,operand1,operand2),Arrays.copyOfRange(tokens,3, tokens.length));
}
throw new ParseErrorException("Unexpected symbol <" + tokens[0] + ">");
}