예제 #1
0
 private void factor() {
   token = lexer.nextToken();
   if (token == Lexer.LEFT) {
     expression();
     if (token != Lexer.RIGHT) {
       throw new MalformedExpressionException(
           String.format("')' instead of <%s> expected.", token));
     } else {
       token = lexer.nextToken();
     }
   } else {
     condition();
   }
 }
예제 #2
0
 private void value() {
   if (token == Lexer.VARIABLE || token == Lexer.NUMBER) {
     root = NodeFactory.createTerminal(token, lexer.getValue());
     if (token == Lexer.VARIABLE && allowedIdentifiers != null) {
       if (!allowedIdentifiers.contains(root.getSymbol()))
         throw new MalformedExpressionException(
             String.format("Unknown identifier '%s'", root.getSymbol()));
     }
     token = lexer.nextToken();
   } else {
     throw new MalformedExpressionException(
         String.format("Value instead of <%s> expected.", token));
   }
 }
예제 #3
0
 @SuppressWarnings("unchecked")
 private void condition() {
   value();
   if (token == Lexer.GREATER
       || token == Lexer.GREATEROREQUAL
       || token == Lexer.LESS
       || token == Lexer.LESSOREQUAL
       || token == Lexer.EQUAL
       || token == Lexer.NOTEQUAL) {
     NonTerminal condition = NodeFactory.createNonTerminal(token);
     condition.setLeft(root);
     token = lexer.nextToken();
     value();
     condition.setRight(root);
     root = condition;
   } else {
     throw new MalformedExpressionException(
         String.format("Conditional operator instead of <%s> expected.", token));
   }
 }