Rule unary(Rule innerRule, Operator... operators) { return Sequence( firstOperatorOf(operators), push(new OperationUnary(((Constant<Operator>) pop()).getValue())), mandatory( Sequence( innerRule, ((OperationUnary) peek(1)).setOperand(simplify(pop())) ), new ParseException("Wrong unary operator syntax") ) ); }
Rule unary(Rule innerRule, Operator... operators) { return Sequence( firstOperatorOf(operators), push(new OperationUnary(((Constant<Operator>) pop()).getValue())), mandatory( Sequence( innerRule, ((OperationUnary) peek(1)).setOperand(simplify(pop())) ), new ParseException("Wrong unary operator syntax") ) ); }
Rule functionWithTwoWordsAsName() { return Sequence( variable(), variable(), push(new FunctionElement(popVariableName(1)+" "+popVariableName())), mandatory( Sequence( expression(), ((FunctionElement) peek(1)).add(pop()) ), new ParseException("Wrong function named with two words syntax") ) ); }
Rule binary(Rule first, Rule rest, Operator... operators) { return Sequence( first, push(new OperationBinary(simplify(pop()))), ZeroOrMore( firstOperatorOf(operators), ((OperationBinary) peek(1)).addOperator(((Constant<Operator>) pop()).getValue()), mandatory( Sequence( rest, ((OperationBinary) peek(1)).add(simplify(pop())) ), new ParseException("Wrong binary operation syntax") ) ) ); }
Rule functionWithTwoWordsAsName() { return Sequence( variable(), variable(), push(new FunctionElement(popVariableName(1)+" "+popVariableName())), mandatory( Sequence( expression(), ((FunctionElement) peek(1)).add(pop()) ), new ParseException("Wrong function named with two words syntax") ) ); }
Rule binary(Rule first, Rule rest, Operator... operators) { return Sequence( first, push(new OperationBinary(simplify(pop()))), ZeroOrMore( firstOperatorOf(operators), ((OperationBinary) peek(1)).addOperator(((Constant<Operator>) pop()).getValue()), mandatory( Sequence( rest, ((OperationBinary) peek(1)).add(simplify(pop())) ), new ParseException("Wrong binary operation syntax") ) ) ); }
Rule ternaryOperation() { return Sequence( elementar(), push(new OperationTernary(pop())), symbol(QUESTION), mandatory( Sequence( expression(), ((OperationTernary) peek(1)).setIfTrueExpression(pop()), symbol(DIV), expression(), ((OperationTernary) peek(1)).setIfFalseExpression(pop()) ), new ParseException("Wring ternary operation syntax") ) ); }
Rule ternaryOperation() { return Sequence( elementar(), push(new OperationTernary(pop())), symbol(QUESTION), mandatory( Sequence( expression(), ((OperationTernary) peek(1)).setIfTrueExpression(pop()), symbol(DIV), expression(), ((OperationTernary) peek(1)).setIfFalseExpression(pop()) ), new ParseException("Wring ternary operation syntax") ) ); }
Rule enumeratedList() { return Sequence( symbol(OPEN_BRACKET), push(new ValueList()), mandatory( Sequence( Optional( expression(), ((ValueList) peek(1)).add(pop()), ZeroOrMore( symbol(COMMA), expression(), ((ValueList) peek(1)).add(pop()) ) ), symbol(CLOSE_BRACKET) ), new ParseException("Wrong list syntax") ) ); }
Rule enumeratedList() { return Sequence( symbol(OPEN_BRACKET), push(new ValueList()), mandatory( Sequence( Optional( expression(), ((ValueList) peek(1)).add(pop()), ZeroOrMore( symbol(COMMA), expression(), ((ValueList) peek(1)).add(pop()) ) ), symbol(CLOSE_BRACKET) ), new ParseException("Wrong list syntax") ) ); }
Rule functionWithBrackets() { return Sequence( variable(), symbol(OPEN_PARENT), push(new FunctionElement(popVariableName())), mandatory( Sequence( expression(), ((FunctionElement) peek(1)).add(pop()), ZeroOrMore( symbol(COMMA), expression(), ((FunctionElement) peek(1)).add(pop()) ), symbol(CLOSE_PARENT) ), new ParseException("Wrong function syntax") ) ); }
Rule functionWithBrackets() { return Sequence( variable(), symbol(OPEN_PARENT), push(new FunctionElement(popVariableName())), mandatory( Sequence( expression(), ((FunctionElement) peek(1)).add(pop()), ZeroOrMore( symbol(COMMA), expression(), ((FunctionElement) peek(1)).add(pop()) ), symbol(CLOSE_PARENT) ), new ParseException("Wrong function syntax") ) ); }