Exemplo n.º 1
0
        private sign Parse_sign()
        {
            if (_index >= _tokens.Count())
            {
                return(null);
            }                                               // must be first line on any atom

            /*sign:
             *  "+" | "-" */

            var _data   = _tokens[_index];
            var _result = new sign(_data);



            if (_result.is_sign)
            {
                _index++;
                return(_result);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
 public exponent(SpecialToken _ident, digit_sequence _digit_sequence, sign _sign = null)
 {
     ident          = _ident;
     digit_sequence = _digit_sequence;
     sign           = _sign;
     expression     = "E" + sign?.expression + digit_sequence.expression;
 }
Exemplo n.º 3
0
        //-----------------------------------------------------------

        public number Parse_number()
        {
            /*number:
             *  sign? integer-constant
             | sign? floating-point-constant  */
            var _backtrackindex_1 = _index;

            number _self = null;


            List <sign> __sign = new List <sign>();
            var         _sign  = Parse_sign();

            while (_sign != null)
            {
                __sign.Add(_sign); _sign = Parse_sign();
            }
            _sign = new sign(__sign);
            //var _sign = Parse_sign();

            var _backtrackindex_2 = _index;
            var _integer_constant = Parse_integer_constant();

            if (_integer_constant != null && ((_index < _tokens.Count() && _tokens[_index].StringValue != ".") || _index == _tokens.Count()))
            {
                _self = new number(_sign, _integer_constant);

                return(_self);
            }

            if (_index < _tokens.Count())
            {
                _index = _backtrackindex_2;
            }
            else
            {
                return(null);
            }

            var _floating_point_constant = Parse_floating_point_constant();

            if (_floating_point_constant != null)
            {
                _self = new number(_sign, _floating_point_constant);

                return(_self);
            }


            if (_self == null)
            {
                _index = _backtrackindex_1;
            }
            else
            {
                return(null);
            }
            return(_self);
        }
Exemplo n.º 4
0
        // THIS SECTION IS KIND OF CHEATING. I SHOULD DO THIS IN A BNF SEQUENCE.
        // GO BACK AND REDO THIS !!!!
        public sign(List <sign> _sign_sequnce)
        {
            sign   current     = null;
            sign   prev        = null;
            string _expression = string.Empty;

            #region loop
            foreach (var _sign in _sign_sequnce)
            {
                /*
                 *  -- = +
                 ++ = +
                 ++ -+ = -
                 +- = -
                 */

                current      = _sign;
                _expression += current.expression;

                if (prev != null)
                {
                    if (  // do we have a --?
                        current.token.StringValue == "-" && prev.token.StringValue == "-" ||
                        prev.token.StringValue == "-" && current.token.StringValue == "-"
                        // or do we have a ++?
                        || (current.token.StringValue == "+" && prev.token.StringValue == "+") ||
                        (prev.token.StringValue == "+" && current.token.StringValue == "+")
                        )
                    {
                        current = new sign(new SpecialToken('+'));
                    }
                    else
                    {
                        current = new sign(new SpecialToken('-'));
                    }
                }

                prev = current;
            }
            #endregion

            if (_sign_sequnce.Count > 0)
            {
                token      = current.token;
                is_sign    = true;
                expression = _expression;
            }
            else
            {
                is_sign = false;
            }
        }
Exemplo n.º 5
0
 public number(sign _sign, floating_point_constant _floating_point_constant)
 {
     sign = _sign;
     floating_point_constant = _floating_point_constant;
     expression = sign == null ? floating_point_constant.expression : sign.expression + floating_point_constant.expression;
 }
Exemplo n.º 6
0
 public number(sign _sign, integer_constant _integer_constant)
 {
     sign             = _sign;
     integer_constant = _integer_constant;
     expression       = sign == null ? integer_constant.expression : sign.expression + integer_constant.expression;
 }