private Expression factor() { Expression retVal; Expression thisVal; Token id; bool includeThis; switch (lookAhead.TokenType) { case '(': accept(); retVal = expr(); match(')'); break; case TokenType.TOKEN_ID: int line = l.currentLine; Expression lVal = leftVal(out thisVal, out includeThis); if (lookAhead.TokenType == '(' || includeThis) // function call { match('('); List <Expression> argss = args(includeThis, thisVal); match(')'); retVal = new exp_functioncall(m, line, argss, lVal); } else { retVal = lVal; } break; case TokenType.TOKEN_NUMBER: id = match(TokenType.TOKEN_NUMBER); return(new exp_number(m, l.currentLine, id.numToken)); case '[': accept(); retVal = newTable(); match(']'); break; //return new exp_new_table(m, l.currentLine); case '!': accept(); return(new exp_not(m, l.currentLine, factor())); case '-': accept(); return(new exp_arith(m, l.currentLine, new exp_number(m, l.currentLine, 0.0), factor(), OpCode.ARITH_SUB)); case TokenType.TOKEN_STRING: id = match(TokenType.TOKEN_STRING); return(new exp_string(m, l.currentLine, m.parser_checkStringMap(id.strToken, true))); default: throw new CompileException(l.currentLine, "Unexpected Token " + TokenType.getTokenTypeString(lookAhead.TokenType)); } return(retVal); }
private Expression factor() { Expression retVal; int local; Token id; switch (lookAhead.TokenType) { case '(': accept(); retVal = expr(); match(')'); break; case TokenType.TOKEN_ID: id = match(TokenType.TOKEN_ID); local = m.GetLocalIDByName(id.strToken); if (lookAhead.TokenType == '(') //function call { int line = l.currentLine; accept(); List <Expression> argss = args(); match(')'); if (local != -1) { retVal = new exp_functioncall(m, line, argss, local, true); } else { retVal = new exp_functioncall(m, line, argss, m.parser_checkStringMap(id.strToken, true), false); } } else { if (local != -1) { retVal = new exp_local_var_right(m, l.currentLine, local); } else { retVal = new exp_var_right(m, l.currentLine, m.parser_checkStringMap(id.strToken, true)); } } break; case TokenType.TOKEN_IN: accept(); match('('); retVal = new exp_in(m, l.currentLine, expr()); match(')'); break; case TokenType.TOKEN_NUMBER: id = match(TokenType.TOKEN_NUMBER); return(new exp_number(m, l.currentLine, id.numToken)); case '!': accept(); return(new exp_not(m, l.currentLine, factor())); case '-': accept(); return(new exp_arith(m, l.currentLine, new exp_number(m, l.currentLine, 0.0), factor(), OpCode.ARITH_SUB)); case TokenType.TOKEN_STRING: id = match(TokenType.TOKEN_STRING); return(new exp_string(m, l.currentLine, m.parser_checkStringMap(id.strToken, true))); default: throw new CompileException(l.currentLine, "Unexpected Token " + TokenType.getTokenTypeString(lookAhead.TokenType)); } return(retVal); }