Esempio n. 1
0
        /// <summary>
        /// Finds least binding parameter, taking ( and ) into account.
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        private int FindLeastBinding(List <ParseCode> code)
        {
            // Make sure no additional ()s.
            RemoveUnneededGroups(code);

            if (code.Count == 1)
            {
                if (code[0].Id != ParseCodeId.Identifier)
                {
                    throw
                        new InvalidMathExpression("Cannot compile expression, identifier expected.");
                }
                return(0);
            }

            int         index = -1;
            ParseCodeId id    = ParseCodeId.None;
            int         depth = 0;

            for (int i = 0; i < code.Count; i++)
            {
                ParseCode c = code[i];
                if (depth == 0 && c.Id != ParseCodeId.Identifier && c.Id != ParseCodeId.Comma)
                {
                    if ((int)c.Id > (int)id)
                    {
                        index = i;
                        id    = c.Id;
                    }
                }

                // We advance depth.
                if (c.Id == ParseCodeId.Begin || c.Id == ParseCodeId.BeginFunction)
                {
                    depth++;
                }
                if (c.Id == ParseCodeId.End)
                {
                    depth--;
                }
            }

            if (depth != 0)
            {
                throw new InvalidMathExpression("The number of '(' and ')' does not match.");
            }
            if (index == -1)
            {
                throw new InvalidMathExpression("Multiple identifiers, cannot compile.");
            }

            // Least bound returned.
            return(index);
        }
Esempio n. 2
0
 public ParseCode(string id)
 {
     Id = ParseCodeId.Identifier; Identifier = id;
 }
Esempio n. 3
0
 public ParseCode(ParseCodeId code, string id)
 {
     Id = code; Identifier = id;
 }
Esempio n. 4
0
 public ParseCode(ParseCodeId id)
 {
     Id = id;
 }