Program: 61820
Project: 61820
Buggy source:
private GraphTargetItem expression(boolean allowEmpty,HashMap<String,Integer> registerVars,boolean inFunction,boolean inMethod,boolean allowRemainder,List<VariableActionItem> variables) throws IOException, ParseException {
  if (debugMode) {
    System.out.println("String_Node_Str");
  }
  GraphTargetItem ret=null;
  ParsedSymbol s=lex();
  boolean existsRemainder=false;
  boolean assocRight=false;
switch (s.type) {
case MINUS:
    GraphTargetItem num=expression(registerVars,inFunction,inMethod,true,variables);
  if ((num instanceof DirectValueActionItem) && (((DirectValueActionItem)num).value instanceof Long)) {
    ((DirectValueActionItem)num).value=-(Long)((DirectValueActionItem)num).value;
    ret=num;
  }
 else   if ((num instanceof DirectValueActionItem) && (((DirectValueActionItem)num).value instanceof Double)) {
    Double d=(Double)((DirectValueActionItem)num).value;
    if (d.isInfinite()) {
      ((DirectValueActionItem)num).value=Double.NEGATIVE_INFINITY;
    }
 else {
      ((DirectValueActionItem)num).value=-d;
    }
    ret=(num);
  }
 else   if ((num instanceof DirectValueActionItem) && (((DirectValueActionItem)num).value instanceof Float)) {
    ((DirectValueActionItem)num).value=-(Float)((DirectValueActionItem)num).value;
    ret=(num);
  }
 else {
    ;
    ret=(new SubtractActionItem(null,new DirectValueActionItem(null,0,(Long)0L,new ArrayList<String>()),num));
  }
break;
case TYPEOF:
expectedType(SymbolType.PARENT_OPEN);
ret=new TypeOfActionItem(null,expression(registerVars,inFunction,inMethod,true,variables));
expectedType(SymbolType.PARENT_CLOSE);
existsRemainder=true;
break;
case TRUE:
ret=new DirectValueActionItem(null,0,Boolean.TRUE,new ArrayList<String>());
existsRemainder=true;
break;
case NULL:
ret=new DirectValueActionItem(null,0,new Null(),new ArrayList<String>());
existsRemainder=true;
break;
case UNDEFINED:
ret=new DirectValueActionItem(null,0,new Undefined(),new ArrayList<String>());
break;
case FALSE:
ret=new DirectValueActionItem(null,0,Boolean.FALSE,new ArrayList<String>());
existsRemainder=true;
break;
case CURLY_OPEN:
s=lex();
List<GraphTargetItem> objectNames=new ArrayList<>();
List<GraphTargetItem> objectValues=new ArrayList<>();
while (s.type != SymbolType.CURLY_CLOSE) {
if (s.type != SymbolType.COMMA) {
lexer.pushback(s);
}
s=lex();
expected(s,lexer.yyline(),SymbolType.IDENTIFIER);
objectNames.add(0,pushConst((String)s.value));
expectedType(SymbolType.COLON);
objectValues.add(0,expression(registerVars,inFunction,inMethod,true,variables));
s=lex();
if (!s.isType(SymbolType.COMMA,SymbolType.CURLY_CLOSE)) {
expected(s,lexer.yyline(),SymbolType.COMMA,SymbolType.CURLY_CLOSE);
}
}
ret=new InitObjectActionItem(null,objectNames,objectValues);
break;
case BRACKET_OPEN:
lexer.pushback(s);
List<GraphTargetItem> inBrackets=new ArrayList<>();
int arrCnt=brackets(inBrackets,registerVars,inFunction,inMethod,variables);
ret=new InitArrayActionItem(null,inBrackets);
break;
case FUNCTION:
s=lexer.lex();
String fname="String_Node_Str";
if (s.type == SymbolType.IDENTIFIER) {
fname=s.value.toString();
}
 else {
lexer.pushback(s);
}
ret=function(true,fname,false,variables);
break;
case STRING:
ret=pushConst(s.value.toString());
ret=memberOrCall(ret,registerVars,inFunction,inMethod,variables);
existsRemainder=true;
break;
case NEWLINE:
ret=new DirectValueActionItem(null,0,"String_Node_Str",new ArrayList<String>());
existsRemainder=true;
break;
case NAN:
ret=new DirectValueActionItem(null,0,Double.NaN,new ArrayList<String>());
existsRemainder=true;
break;
case INFINITY:
ret=new DirectValueActionItem(null,0,Double.POSITIVE_INFINITY,new ArrayList<String>());
existsRemainder=true;
break;
case INTEGER:
case DOUBLE:
ret=new DirectValueActionItem(null,0,s.value,new ArrayList<String>());
existsRemainder=true;
break;
case DELETE:
GraphTargetItem varDel=variable(registerVars,inFunction,inMethod,variables);
if (varDel instanceof GetMemberActionItem) {
GetMemberActionItem gm=(GetMemberActionItem)varDel;
ret=new DeleteActionItem(null,gm.object,gm.memberName);
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
break;
case INCREMENT:
case DECREMENT:
GraphTargetItem prevar=variable(registerVars,inFunction,inMethod,variables);
if (s.type == SymbolType.INCREMENT) {
ret=new PreIncrementActionItem(null,prevar);
}
if (s.type == SymbolType.DECREMENT) {
ret=new PreDecrementActionItem(null,prevar);
}
existsRemainder=true;
break;
case NOT:
ret=new NotItem(null,expression(registerVars,inFunction,inMethod,true,variables));
existsRemainder=true;
break;
case PARENT_OPEN:
ret=new ParenthesisItem(null,expression(registerVars,inFunction,inMethod,true,variables));
expectedType(SymbolType.PARENT_CLOSE);
ret=memberOrCall(ret,registerVars,inFunction,inMethod,variables);
existsRemainder=true;
break;
case NEW:
GraphTargetItem newvar=variable(registerVars,inFunction,inMethod,variables);
expectedType(SymbolType.PARENT_OPEN);
if (newvar instanceof GetMemberActionItem) {
GetMemberActionItem mem=(GetMemberActionItem)newvar;
ret=new NewMethodActionItem(null,mem.object,mem.memberName,call(registerVars,inFunction,inMethod,variables));
}
 else if (newvar instanceof VariableActionItem) {
ret=new NewObjectActionItem(null,newvar,call(registerVars,inFunction,inMethod,variables));
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
existsRemainder=true;
break;
case IDENTIFIER:
case THIS:
case EVAL:
GraphTargetItem var;
if (s.type == SymbolType.EVAL) {
expectedType(SymbolType.PARENT_OPEN);
var=new EvalActionItem(null,expression(registerVars,inFunction,inMethod,true,variables));
expectedType(SymbolType.PARENT_CLOSE);
var=memberOrCall(var,registerVars,inFunction,inMethod,variables);
}
 else {
lexer.pushback(s);
var=variable(registerVars,inFunction,inMethod,variables);
}
VariableActionItem gva=null;
GetMemberActionItem gmb=null;
RegisterNumber reg=null;
if (var instanceof VariableActionItem) {
gva=(VariableActionItem)var;
}
 else if (var instanceof GetMemberActionItem) {
gmb=(GetMemberActionItem)var;
}
s=lex();
switch (s.type) {
case ASSIGN:
GraphTargetItem varval=expression(registerVars,inFunction,inMethod,true,variables);
if (gva != null) {
ret=new VariableActionItem(gva.getVariableName(),varval,false);
variables.add((VariableActionItem)ret);
}
 else if (gmb != null) {
ret=new SetMemberActionItem(null,gmb.object,gmb.memberName,varval);
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
existsRemainder=true;
assocRight=true;
break;
case ASSIGN_BITAND:
case ASSIGN_BITOR:
case ASSIGN_DIVIDE:
case ASSIGN_MINUS:
case ASSIGN_MODULO:
case ASSIGN_MULTIPLY:
case ASSIGN_PLUS:
case ASSIGN_XOR:
if (gva == null && gmb == null) {
throw new ParseException("String_Node_Str",lexer.yyline());
}
GraphTargetItem varval2=expression(registerVars,inFunction,inMethod,true,variables);
switch (s.type) {
case ASSIGN_BITAND:
if (gva != null) {
ret=new VariableActionItem(gva.getVariableName(),new BitAndActionItem(null,gva,varval2),false);
variables.add((VariableActionItem)ret);
}
 else {
ret=new SetMemberActionItem(null,gmb.object,gmb.memberName,new BitAndActionItem(null,gmb,varval2));
}
break;
case ASSIGN_BITOR:
if (gva != null) {
ret=new VariableActionItem(gva.getVariableName(),new BitOrActionItem(null,gva,varval2),false);
variables.add((VariableActionItem)ret);
}
 else {
ret=new SetMemberActionItem(null,gmb.object,gmb.memberName,new BitOrActionItem(null,gmb,varval2));
}
break;
case ASSIGN_DIVIDE:
if (gva != null) {
ret=new VariableActionItem(gva.getVariableName(),new DivideActionItem(null,gva,varval2),false);
variables.add((VariableActionItem)ret);
}
 else {
ret=new SetMemberActionItem(null,gmb.object,gmb.memberName,new DivideActionItem(null,gmb,varval2));
}
break;
case ASSIGN_MINUS:
if (gva != null) {
ret=new VariableActionItem(gva.getVariableName(),new SubtractActionItem(null,gva,varval2),false);
variables.add((VariableActionItem)ret);
}
 else {
ret=new SetMemberActionItem(null,gmb.object,gmb.memberName,new SubtractActionItem(null,gmb,varval2));
}
break;
case ASSIGN_MODULO:
if (gva != null) {
ret=new VariableActionItem(gva.getVariableName(),new ModuloActionItem(null,gva,varval2),false);
variables.add((VariableActionItem)ret);
}
 else {
ret=new SetMemberActionItem(null,gmb.object,gmb.memberName,new ModuloActionItem(null,gmb,varval2));
}
break;
case ASSIGN_MULTIPLY:
if (gva != null) {
ret=new VariableActionItem(gva.getVariableName(),new MultiplyActionItem(null,gva,varval2),false);
variables.add((VariableActionItem)ret);
}
 else {
ret=new SetMemberActionItem(null,gmb.object,gmb.memberName,new MultiplyActionItem(null,gmb,varval2));
}
break;
case ASSIGN_PLUS:
if (gva != null) {
ret=new VariableActionItem(gva.getVariableName(),new AddActionItem(null,gva,varval2,true),false);
variables.add((VariableActionItem)ret);
}
 else {
ret=new SetMemberActionItem(null,gmb.object,gmb.memberName,new AddActionItem(null,gmb,varval2,true));
}
break;
}
existsRemainder=true;
assocRight=true;
break;
case INCREMENT:
if (gva == null && gmb == null) {
throw new ParseException("String_Node_Str",lexer.yyline());
}
ret=new PostIncrementActionItem(null,var);
break;
case DECREMENT:
if (gva == null && gmb == null) {
throw new ParseException("String_Node_Str",lexer.yyline());
}
ret=new PostDecrementActionItem(null,var);
break;
case PARENT_OPEN:
lexer.pushback(s);
ret=memberOrCall(var,registerVars,inFunction,inMethod,variables);
existsRemainder=true;
break;
default :
ret=var;
lexer.pushback(s);
existsRemainder=true;
}
break;
default :
GraphTargetItem excmd=expressionCommands(s,registerVars,inFunction,inMethod,-1,variables);
if (excmd != null) {
existsRemainder=true;
ret=excmd;
break;
}
lexer.pushback(s);
}
if (allowRemainder && existsRemainder) {
GraphTargetItem rem=ret;
do {
rem=expressionRemainder(rem,registerVars,inFunction,inMethod,assocRight,variables);
if (rem != null) {
ret=rem;
}
}
 while ((!assocRight) && (rem != null));
}
if (debugMode) {
System.out.println("String_Node_Str");
}
return ret;
}

Fixed version (ground truth):
private GraphTargetItem expression(boolean allowEmpty,HashMap<String,Integer> registerVars,boolean inFunction,boolean inMethod,boolean allowRemainder,List<VariableActionItem> variables) throws IOException, ParseException {
  if (debugMode) {
    System.out.println("String_Node_Str");
  }
  GraphTargetItem ret=null;
  ParsedSymbol s=lex();
  boolean existsRemainder=false;
  boolean assocRight=false;
switch (s.type) {
case MINUS:
    s=lex();
  if (s.isType(SymbolType.DOUBLE)) {
    ret=new DirectValueActionItem(null,0,-(double)(Double)s.value,new ArrayList<String>());
    existsRemainder=true;
  }
 else   if (s.isType(SymbolType.INTEGER)) {
    ret=new DirectValueActionItem(null,0,-(long)(Long)s.value,new ArrayList<String>());
    existsRemainder=true;
  }
 else {
    lexer.pushback(s);
    GraphTargetItem num=expression(registerVars,inFunction,inMethod,true,variables);
    if ((num instanceof DirectValueActionItem) && (((DirectValueActionItem)num).value instanceof Long)) {
      ((DirectValueActionItem)num).value=-(Long)((DirectValueActionItem)num).value;
      ret=num;
    }
 else     if ((num instanceof DirectValueActionItem) && (((DirectValueActionItem)num).value instanceof Double)) {
      Double d=(Double)((DirectValueActionItem)num).value;
      if (d.isInfinite()) {
        ((DirectValueActionItem)num).value=Double.NEGATIVE_INFINITY;
      }
 else {
        ((DirectValueActionItem)num).value=-d;
      }
      ret=(num);
    }
 else     if ((num instanceof DirectValueActionItem) && (((DirectValueActionItem)num).value instanceof Float)) {
      ((DirectValueActionItem)num).value=-(Float)((DirectValueActionItem)num).value;
      ret=(num);
    }
 else {
      ;
      ret=(new SubtractActionItem(null,new DirectValueActionItem(null,0,(Long)0L,new ArrayList<String>()),num));
    }
  }
break;
case TYPEOF:
expectedType(SymbolType.PARENT_OPEN);
ret=new TypeOfActionItem(null,expression(registerVars,inFunction,inMethod,true,variables));
expectedType(SymbolType.PARENT_CLOSE);
existsRemainder=true;
break;
case TRUE:
ret=new DirectValueActionItem(null,0,Boolean.TRUE,new ArrayList<String>());
existsRemainder=true;
break;
case NULL:
ret=new DirectValueActionItem(null,0,new Null(),new ArrayList<String>());
existsRemainder=true;
break;
case UNDEFINED:
ret=new DirectValueActionItem(null,0,new Undefined(),new ArrayList<String>());
break;
case FALSE:
ret=new DirectValueActionItem(null,0,Boolean.FALSE,new ArrayList<String>());
existsRemainder=true;
break;
case CURLY_OPEN:
s=lex();
List<GraphTargetItem> objectNames=new ArrayList<>();
List<GraphTargetItem> objectValues=new ArrayList<>();
while (s.type != SymbolType.CURLY_CLOSE) {
if (s.type != SymbolType.COMMA) {
lexer.pushback(s);
}
s=lex();
expected(s,lexer.yyline(),SymbolType.IDENTIFIER);
objectNames.add(0,pushConst((String)s.value));
expectedType(SymbolType.COLON);
objectValues.add(0,expression(registerVars,inFunction,inMethod,true,variables));
s=lex();
if (!s.isType(SymbolType.COMMA,SymbolType.CURLY_CLOSE)) {
expected(s,lexer.yyline(),SymbolType.COMMA,SymbolType.CURLY_CLOSE);
}
}
ret=new InitObjectActionItem(null,objectNames,objectValues);
break;
case BRACKET_OPEN:
lexer.pushback(s);
List<GraphTargetItem> inBrackets=new ArrayList<>();
int arrCnt=brackets(inBrackets,registerVars,inFunction,inMethod,variables);
ret=new InitArrayActionItem(null,inBrackets);
break;
case FUNCTION:
s=lexer.lex();
String fname="String_Node_Str";
if (s.type == SymbolType.IDENTIFIER) {
fname=s.value.toString();
}
 else {
lexer.pushback(s);
}
ret=function(true,fname,false,variables);
break;
case STRING:
ret=pushConst(s.value.toString());
ret=memberOrCall(ret,registerVars,inFunction,inMethod,variables);
existsRemainder=true;
break;
case NEWLINE:
ret=new DirectValueActionItem(null,0,"String_Node_Str",new ArrayList<String>());
existsRemainder=true;
break;
case NAN:
ret=new DirectValueActionItem(null,0,Double.NaN,new ArrayList<String>());
existsRemainder=true;
break;
case INFINITY:
ret=new DirectValueActionItem(null,0,Double.POSITIVE_INFINITY,new ArrayList<String>());
existsRemainder=true;
break;
case INTEGER:
case DOUBLE:
ret=new DirectValueActionItem(null,0,s.value,new ArrayList<String>());
existsRemainder=true;
break;
case DELETE:
GraphTargetItem varDel=variable(registerVars,inFunction,inMethod,variables);
if (varDel instanceof GetMemberActionItem) {
GetMemberActionItem gm=(GetMemberActionItem)varDel;
ret=new DeleteActionItem(null,gm.object,gm.memberName);
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
break;
case INCREMENT:
case DECREMENT:
GraphTargetItem prevar=variable(registerVars,inFunction,inMethod,variables);
if (s.type == SymbolType.INCREMENT) {
ret=new PreIncrementActionItem(null,prevar);
}
if (s.type == SymbolType.DECREMENT) {
ret=new PreDecrementActionItem(null,prevar);
}
existsRemainder=true;
break;
case NOT:
ret=new NotItem(null,expression(registerVars,inFunction,inMethod,true,variables));
existsRemainder=true;
break;
case PARENT_OPEN:
ret=new ParenthesisItem(null,expression(registerVars,inFunction,inMethod,true,variables));
expectedType(SymbolType.PARENT_CLOSE);
ret=memberOrCall(ret,registerVars,inFunction,inMethod,variables);
existsRemainder=true;
break;
case NEW:
GraphTargetItem newvar=variable(registerVars,inFunction,inMethod,variables);
expectedType(SymbolType.PARENT_OPEN);
if (newvar instanceof GetMemberActionItem) {
GetMemberActionItem mem=(GetMemberActionItem)newvar;
ret=new NewMethodActionItem(null,mem.object,mem.memberName,call(registerVars,inFunction,inMethod,variables));
}
 else if (newvar instanceof VariableActionItem) {
ret=new NewObjectActionItem(null,newvar,call(registerVars,inFunction,inMethod,variables));
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
existsRemainder=true;
break;
case IDENTIFIER:
case THIS:
case EVAL:
GraphTargetItem var;
if (s.type == SymbolType.EVAL) {
expectedType(SymbolType.PARENT_OPEN);
var=new EvalActionItem(null,expression(registerVars,inFunction,inMethod,true,variables));
expectedType(SymbolType.PARENT_CLOSE);
var=memberOrCall(var,registerVars,inFunction,inMethod,variables);
}
 else {
lexer.pushback(s);
var=variable(registerVars,inFunction,inMethod,variables);
}
VariableActionItem gva=null;
GetMemberActionItem gmb=null;
RegisterNumber reg=null;
if (var instanceof VariableActionItem) {
gva=(VariableActionItem)var;
}
 else if (var instanceof GetMemberActionItem) {
gmb=(GetMemberActionItem)var;
}
s=lex();
switch (s.type) {
case ASSIGN:
GraphTargetItem varval=expression(registerVars,inFunction,inMethod,true,variables);
if (gva != null) {
ret=new VariableActionItem(gva.getVariableName(),varval,false);
variables.add((VariableActionItem)ret);
}
 else if (gmb != null) {
ret=new SetMemberActionItem(null,gmb.object,gmb.memberName,varval);
}
 else {
throw new ParseException("String_Node_Str",lexer.yyline());
}
existsRemainder=true;
assocRight=true;
break;
case ASSIGN_BITAND:
case ASSIGN_BITOR:
case ASSIGN_DIVIDE:
case ASSIGN_MINUS:
case ASSIGN_MODULO:
case ASSIGN_MULTIPLY:
case ASSIGN_PLUS:
case ASSIGN_XOR:
if (gva == null && gmb == null) {
throw new ParseException("String_Node_Str",lexer.yyline());
}
GraphTargetItem varval2=expression(registerVars,inFunction,inMethod,true,variables);
switch (s.type) {
case ASSIGN_BITAND:
if (gva != null) {
ret=new VariableActionItem(gva.getVariableName(),new BitAndActionItem(null,gva,varval2),false);
variables.add((VariableActionItem)ret);
}
 else {
ret=new SetMemberActionItem(null,gmb.object,gmb.memberName,new BitAndActionItem(null,gmb,varval2));
}
break;
case ASSIGN_BITOR:
if (gva != null) {
ret=new VariableActionItem(gva.getVariableName(),new BitOrActionItem(null,gva,varval2),false);
variables.add((VariableActionItem)ret);
}
 else {
ret=new SetMemberActionItem(null,gmb.object,gmb.memberName,new BitOrActionItem(null,gmb,varval2));
}
break;
case ASSIGN_DIVIDE:
if (gva != null) {
ret=new VariableActionItem(gva.getVariableName(),new DivideActionItem(null,gva,varval2),false);
variables.add((VariableActionItem)ret);
}
 else {
ret=new SetMemberActionItem(null,gmb.object,gmb.memberName,new DivideActionItem(null,gmb,varval2));
}
break;
case ASSIGN_MINUS:
if (gva != null) {
ret=new VariableActionItem(gva.getVariableName(),new SubtractActionItem(null,gva,varval2),false);
variables.add((VariableActionItem)ret);
}
 else {
ret=new SetMemberActionItem(null,gmb.object,gmb.memberName,new SubtractActionItem(null,gmb,varval2));
}
break;
case ASSIGN_MODULO:
if (gva != null) {
ret=new VariableActionItem(gva.getVariableName(),new ModuloActionItem(null,gva,varval2),false);
variables.add((VariableActionItem)ret);
}
 else {
ret=new SetMemberActionItem(null,gmb.object,gmb.memberName,new ModuloActionItem(null,gmb,varval2));
}
break;
case ASSIGN_MULTIPLY:
if (gva != null) {
ret=new VariableActionItem(gva.getVariableName(),new MultiplyActionItem(null,gva,varval2),false);
variables.add((VariableActionItem)ret);
}
 else {
ret=new SetMemberActionItem(null,gmb.object,gmb.memberName,new MultiplyActionItem(null,gmb,varval2));
}
break;
case ASSIGN_PLUS:
if (gva != null) {
ret=new VariableActionItem(gva.getVariableName(),new AddActionItem(null,gva,varval2,true),false);
variables.add((VariableActionItem)ret);
}
 else {
ret=new SetMemberActionItem(null,gmb.object,gmb.memberName,new AddActionItem(null,gmb,varval2,true));
}
break;
}
existsRemainder=true;
assocRight=true;
break;
case INCREMENT:
if (gva == null && gmb == null) {
throw new ParseException("String_Node_Str",lexer.yyline());
}
ret=new PostIncrementActionItem(null,var);
break;
case DECREMENT:
if (gva == null && gmb == null) {
throw new ParseException("String_Node_Str",lexer.yyline());
}
ret=new PostDecrementActionItem(null,var);
break;
case PARENT_OPEN:
lexer.pushback(s);
ret=memberOrCall(var,registerVars,inFunction,inMethod,variables);
existsRemainder=true;
break;
default :
ret=var;
lexer.pushback(s);
existsRemainder=true;
}
break;
default :
GraphTargetItem excmd=expressionCommands(s,registerVars,inFunction,inMethod,-1,variables);
if (excmd != null) {
existsRemainder=true;
ret=excmd;
break;
}
lexer.pushback(s);
}
if (allowRemainder && existsRemainder) {
GraphTargetItem rem=ret;
do {
rem=expressionRemainder(rem,registerVars,inFunction,inMethod,assocRight,variables);
if (rem != null) {
ret=rem;
}
}
 while ((!assocRight) && (rem != null));
}
if (debugMode) {
System.out.println("String_Node_Str");
}
return ret;
}