Ejemplo n.º 1
0
        public signed_function Parse_signed_function()
        {
            signed_function _self = null;

            var _backtrack = _index;

            List <minus> __minus = new List <minus>();
            var          _minus  = Parse_minus();

            while (_minus != null)
            {
                __minus.Add(_minus); _minus = Parse_minus();;
            }
            if (__minus.Count > 0)
            {
                _minus = new minus(__minus);
            }

            //minus _minus = null;
            //_minus = Parse_minus();

            var _function = Parse_function();

            if (_function == null)
            {
                _index = _backtrack; return(null);
            }

            _self = new signed_function(_minus, _function);
            return(_self);
        }
Ejemplo n.º 2
0
        public function_parameter(minus _minus, paren _ident_lhs, parameter_sequence _parameter_sequence, paren _ident_rhs)
        {
            minus              = _minus;
            ident_lhs          = _ident_lhs;
            ident_rhs          = _ident_rhs;
            parameter_sequence = _parameter_sequence;

            // if (!error())
            expression = _minus?.expression + ident_lhs?.expression + parameter_sequence?.expression + ident_rhs?.expression;
        }
Ejemplo n.º 3
0
        public minus(List <minus> _minus_sequnce)
        {
            minus  current     = null;
            minus  prev        = null;
            string _expression = string.Empty;

            #region loop
            foreach (var _minus in _minus_sequnce)
            {
                /*
                 *  -- = +
                 ++ = +
                 ++ -+ = -
                 +- = -
                 */

                current      = _minus;
                _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 minus(new SpecialToken('+'));
                    }
                    else
                    {
                        current = new minus(new SpecialToken('-'));
                    }
                }

                prev = current;
            }
            #endregion

            if (_minus_sequnce.Count > 0)
            {
                token                 = current.token;
                is_minus              = true;
                expression            = _expression;
                functional_expression = current.expression;
            }
            else
            {
                is_minus = false;
            }
        }
Ejemplo n.º 4
0
        private function_parameter Parse_function_parameter()
        {
            function_parameter _self = null;

            List <minus> __minus = new List <minus>();
            var          _minus  = Parse_minus();

            while (_minus != null)
            {
                __minus.Add(_minus); _minus = Parse_minus();;
            }
            if (__minus.Count > 0)
            {
                _minus = new minus(__minus);
            }



            var _ident_lhs = Parse_Paren();

            var _ident_rhs = Parse_Paren(); if (_ident_rhs != null && _ident_rhs.expression == "(")

            {
                _ident_rhs = null; _index--;
            }

            // this allows us to have functions with no parameters by checking for back to back of opposite direction.

            if (_ident_lhs != null && _ident_rhs == null)
            {
                var _parameter_sequence = Parse_parameter_sequence();
                _ident_rhs = Parse_Paren();                                                                                                       // this checks to see if after _parameter_sequence maybe we have a closing param

                if ((_parameter_sequence == null && _ident_rhs != null) || (_parameter_sequence != null && _ident_rhs != null) || _minus != null) // however, if we are missing a parameter we must have a closing ) to fill out a paramless function or we may have a leading minus as in --(-6+2)
                {
                    _self = new function_parameter(_minus, _ident_lhs, _parameter_sequence, _ident_rhs);
                }
            }
            else if (_ident_lhs != null && _ident_rhs != null)
            {
                _self = new function_parameter(_minus, _ident_lhs, null, _ident_rhs);
            }


            return(_self);
        }
Ejemplo n.º 5
0
        private minus Parse_minus()
        {
            if (_index >= _tokens.Count())
            {
                return(null);
            }                                               // must be first line on any atom

            /*  "-" */

            var _data = _tokens[_index];
            var _self = new minus(_data);



            if (_self.is_minus)
            {
                _index++;
                return(_self);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 6
0
 public signed_function(minus _minus, function _function)
 {
     minus      = _minus;
     function   = _function;
     expression = minus?.expression + function.expression;
 }