public static function rationalFactory(Token $token)
    {
        switch ($token->getType()) {
            case TokenType::PosInt:
            case TokenType::Integer:
                $x = intval($token->getValue());

                return new IntegerNode($x);
            case TokenType::RealNumber:
                $x = floatval(str_replace(',', '.', $token->getValue()));

                return new NumberNode($x);
            case TokenType::Identifier:
                return new VariableNode($token->getValue());
            case TokenType::Constant:
                return new ConstantNode($token->getValue());

            case TokenType::FunctionName:
                return new FunctionNode($token->getValue(), null);
            case TokenType::OpenParenthesis:
                return new SubExpressionNode($token->getValue());

            case TokenType::AdditionOperator:
            case TokenType::SubtractionOperator:
            case TokenType::MultiplicationOperator:
            case TokenType::DivisionOperator:
            case TokenType::ExponentiationOperator:
                return new ExpressionNode(null, $token->getValue(), null);

            case TokenType::FactorialOperator:
                return new PostfixOperatorNode($token->getValue(), null);

            default:
                // echo "Node factory returning null on $token\n";
                return null;
        }
    }
public static function rationalFactory(Token $token)
    {
        switch ($token->getType()) {
            case TokenType::PosInt:
            case TokenType::Integer:
                $x = intval($token->getValue());

                return new IntegerNode($x);
            case TokenType::RealNumber:
                $x = floatval(str_replace(',', '.', $token->getValue()));

                return new NumberNode($x);
            case TokenType::Identifier:
                return new VariableNode($token->getValue());
            case TokenType::Constant:
                return new ConstantNode($token->getValue());

            case TokenType::FunctionName:
                return new FunctionNode($token->getValue(), null);
            case TokenType::OpenParenthesis:
                return new SubExpressionNode($token->getValue());

            case TokenType::AdditionOperator:
            case TokenType::SubtractionOperator:
            case TokenType::MultiplicationOperator:
            case TokenType::DivisionOperator:
            case TokenType::ExponentiationOperator:
                return new ExpressionNode(null, $token->getValue(), null);

            case TokenType::FactorialOperator:
                return new PostfixOperatorNode($token->getValue(), null);

            default:
                // echo "Node factory returning null on $token\n";
                return null;
        }
    }
public static function rationalFactory ( Token $ token ) { switch ( $ token -> getType ( ) ) { case TokenType :: PosInt : case TokenType :: Integer : $ x = intval ( $ token -> getValue ( ) ) ; return new IntegerNode ( $ x ) ; case TokenType :: RealNumber : $ x = floatval ( str_replace ( ',' , '.' , $ token -> getValue ( ) ) ) ; return new NumberNode ( $ x ) ; case TokenType :: Identifier : return new VariableNode ( $ token -> getValue ( ) ) ; case TokenType :: Constant : return new ConstantNode ( $ token -> getValue ( ) ) ; case TokenType :: FunctionName : return new FunctionNode ( $ token -> getValue ( ) , null ) ; case TokenType :: OpenParenthesis : return new SubExpressionNode ( $ token -> getValue ( ) ) ; case TokenType :: AdditionOperator : case TokenType :: SubtractionOperator : case TokenType :: MultiplicationOperator : case TokenType :: DivisionOperator : case TokenType :: ExponentiationOperator : return new ExpressionNode ( null , $ token -> getValue ( ) , null ) ; case TokenType :: FactorialOperator : return new PostfixOperatorNode ( $ token -> getValue ( ) , null ) ; default : // echo "Node factory returning null on $token\n"; return null ; } }
Node factory, creating an appropriate Node from a Token.

Based on the provided Token, returns a TerminalNode if the
token type is PosInt, Integer, RealNumber, Identifier or Constant
otherwise returns null.

@retval Node|null
@param Token $token Provided token
Node factory creating an appropriate Node from a Token .