private void factb() throws IOException { switch (sta.lastToken()) { case TOKEN_NOT: sta.nextTokenType(); factb(); builder.buildOperator(OP_NOT); break; case TOKEN_OPAR: sta.nextTokenType(); cond(); if (sta.lastToken() != TOKEN_CPAR) throw new InvalidExpressionError("Expected ). Got '" + sta.lastToken() + "' instead."); sta.nextTokenType(); break; case TOKEN_ADD: case TOKEN_SUB: case TOKEN_ID: case TOKEN_NUM: case TOKEN_OSB: expr(); switch (sta.lastToken()) { case TOKEN_EQ: builder.buildOperator(OP_EQ); break; case TOKEN_NE: builder.buildOperator(OP_NE); break; case TOKEN_GT: builder.buildOperator(OP_GT); break; case TOKEN_GE: builder.buildOperator(OP_GE); break; case TOKEN_LT: builder.buildOperator(OP_LT); break; case TOKEN_LE: builder.buildOperator(OP_LE); break; default: throw new InvalidExpressionError( "Expected relational operator (==, !=, >, >=, <, <=). Got '" + sta.lastToken() + "' instead."); } sta.nextTokenType(); expr(); builder.endOperator(); break; default: throw new InvalidExpressionError( "Expected not (!), (, [, +, -, a number or an identifier. Got '" + sta.lastToken() + "' instead."); } }
private void fact() throws IOException { if (sta.lastToken() == TOKEN_ID) { builder.buildOperand(sta.getString()); sta.nextTokenType(); } else if (sta.lastToken() == TOKEN_NUM) { builder.buildOperand(sta.getInt()); sta.nextTokenType(); } else if (sta.lastToken() == TOKEN_OSB) { sta.nextTokenType(); expr(); if (sta.lastToken() != TOKEN_CSB) throw new InvalidExpressionError("Expected ]. Got '" + sta.lastToken() + "' instead."); sta.nextTokenType(); } else throw new InvalidExpressionError( "Expected [, a number or an identifier. Got '" + sta.lastToken() + "' instead."); }