示例#1
0
 private void get_token()
 {
     if (tokenPos < tokensList.Count)
     {
         currentToken = tokensList[tokenPos];
     }
     else
     {
         currentToken = new StiToken();
     }
     tokenPos++;
 }
示例#2
0
 private void MakeTokensList()
 {
     tokensList = new List <StiToken>();
     position   = 0;
     while (true)
     {
         StiToken token = GetNextLexem();
         if (token == null)
         {
             break;
         }
         tokensList.Add(token);
     }
     tokensList = PostProcessTokensList(tokensList);
 }
示例#3
0
 //----------------------------------------
 // Сложение или вычитание двух слагаемых
 //----------------------------------------
 private void eval_exp2()
 {
     eval_exp3();
     while ((currentToken.Type == StiTokenType.Plus) || (currentToken.Type == StiTokenType.Minus))
     {
         StiToken operation = currentToken;
         get_token();
         eval_exp3();
         if (operation.Type == StiTokenType.Minus)
         {
             asmList.Add(new StiAsmCommand(StiAsmCommandType.Sub));
         }
         else if (operation.Type == StiTokenType.Plus)
         {
             asmList.Add(new StiAsmCommand(StiAsmCommandType.Add));
         }
     }
 }
        private void ThrowError(ParserErrorCode code, StiToken token, string message1, string message2, string message3, string message4)
        {
            string errorMessage = "Unknown error";
            int    errorCode    = (int)code;

            if (errorCode < errorsList.Length)
            {
                errorMessage = string.Format(errorsList[errorCode], message1, message2, message3, message4);
            }
            string             fullMessage = "Parser error: " + errorMessage;
            StiParserException ex          = new StiParserException(fullMessage);

            ex.BaseMessage = errorMessage;
            if (token != null)
            {
                ex.Position = expressionPosition + token.Position;
                ex.Length   = token.Length;
            }
            throw ex;
        }
示例#5
0
 //----------------------------------------
 // Обработка присваивания
 //----------------------------------------
 private void eval_exp01()
 {
     if (currentToken.Type == StiTokenType.Variable)
     {
         StiToken variableToken = currentToken;
         get_token();
         if (currentToken.Type != StiTokenType.Assign)
         {
             tokenPos--;
             currentToken = tokensList[tokenPos - 1];
         }
         else
         {
             get_token();
             eval_exp1();
             asmList.Add(new StiAsmCommand(StiAsmCommandType.CopyToVariable, variableToken.Value));
             return;
         }
     }
     eval_exp1();
 }
示例#6
0
 //----------------------------------------
 // Умножение или деление двух множителей
 //----------------------------------------
 private void eval_exp3()
 {
     eval_exp4();
     while (currentToken.Type == StiTokenType.Mult || currentToken.Type == StiTokenType.Div || currentToken.Type == StiTokenType.Percent)
     {
         StiToken operation = currentToken;
         get_token();
         eval_exp4();
         if (operation.Type == StiTokenType.Mult)
         {
             asmList.Add(new StiAsmCommand(StiAsmCommandType.Mult));
         }
         else if (operation.Type == StiTokenType.Div)
         {
             asmList.Add(new StiAsmCommand(StiAsmCommandType.Div));
         }
         if (operation.Type == StiTokenType.Percent)
         {
             asmList.Add(new StiAsmCommand(StiAsmCommandType.Mod));
         }
     }
 }
示例#7
0
        private void ThrowError(ParserErrorCode code, StiToken token, string message1, string message2, string message3, string message4)
        {
            string errorMessage = "Неизвестная ошибка";
            int    errorCode    = (int)code;

            if (errorCode < errorsList.Length)
            {
                errorMessage = string.Format(errorsList[errorCode], message1, message2, message3, message4);
            }
            var fullMessage = "Ошибка парсера: " + errorMessage;
            var ex          = new StiParserException(fullMessage)
            {
                BaseMessage = errorMessage
            };

            if (token == null)
            {
                throw ex;
            }
            ex.Position = expressionPosition + token.Position;
            ex.Length   = token.Length;
            throw ex;
        }
        private List <StiToken> PostProcessTokensList(List <StiToken> tokensList)
        {
            List <StiToken> newList = new List <StiToken>();

            tokenPos = 0;
            while (tokenPos < tokensList.Count)
            {
                StiToken token = tokensList[tokenPos];
                tokenPos++;
                if (token.Type == StiTokenType.Identifier)
                {
                    StiDataSource     ds  = report.Dictionary.DataSources[token.Value];
                    StiBusinessObject bos = report.Dictionary.BusinessObjects[token.Value];

                    #region check for DataSource field
                    if (ds != null)
                    {
                        StringBuilder fieldPath = new StringBuilder(StiNameValidator.CorrectName(token.Value));
                        while (tokenPos + 1 < tokensList.Count && tokensList[tokenPos].Type == StiTokenType.Dot)
                        {
                            token = tokensList[tokenPos + 1];
                            string nextName = StiNameValidator.CorrectName(token.Value);

                            StiDataRelation dr = GetDataRelationByName(nextName, ds);
                            if (dr != null)
                            {
                                ds        = dr.ParentSource;
                                tokenPos += 2;
                                fieldPath.Append(".");
                                fieldPath.Append(dr.NameInSource);
                                continue;
                            }
                            if (ds.Columns.Contains(nextName))
                            {
                                tokenPos += 2;
                                fieldPath.Append(".");
                                fieldPath.Append(nextName);
                                break;
                            }
                            foreach (StiDataColumn column in ds.Columns)
                            {
                                if (StiNameValidator.CorrectName(column.Name) == nextName)
                                {
                                    tokenPos += 2;
                                    fieldPath.Append(".");
                                    fieldPath.Append(column.NameInSource);
                                    break;
                                }
                            }

                            CheckDataSourceField(ds.Name, nextName);
                            tokenPos += 2;
                            fieldPath.Append(".");
                            fieldPath.Append(nextName);

                            //token = tokensList[tokenPos - 1];
                            break;
                        }
                        token.Type = StiTokenType.DataSourceField;
                        //надо оптимизировать и сохранять сразу массив строк !!!!!
                        token.Value = fieldPath.ToString();
                    }
                    #endregion

                    #region check for BusinessObject field
                    else if (bos != null)
                    {
                        StringBuilder fieldPath = new StringBuilder(token.Value);
                        while (tokenPos + 1 < tokensList.Count && tokensList[tokenPos].Type == StiTokenType.Dot)
                        //while (inputExpression[pos2] == '.')
                        {
                            token = tokensList[tokenPos + 1];
                            string nextName = token.Value;

                            if (bos.Columns.Contains(nextName))
                            {
                                tokenPos += 2;
                                fieldPath.Append(".");
                                fieldPath.Append(nextName);
                                break;
                            }
                            bos = bos.BusinessObjects[nextName];
                            if (bos != null)
                            {
                                tokenPos += 2;
                                fieldPath.Append(".");
                                fieldPath.Append(bos.Name);
                                continue;
                            }
                            break;
                        }
                        token.Type = StiTokenType.BusinessObjectField;
                        //надо оптимизировать и сохранять сразу массив строк !!!!!
                        token.Value = fieldPath.ToString();
                    }
                    #endregion

                    else if ((newList.Count > 0) && (newList[newList.Count - 1].Type == StiTokenType.Dot))
                    {
                        if (MethodsList.Contains(token.Value))
                        {
                            token.Type = StiTokenType.Method;
                        }
                        else if (PropertiesList.Contains(token.Value))
                        {
                            token.Type = StiTokenType.Property;
                        }
                        else
                        {
                            ThrowError(ParserErrorCode.FieldMethodOrPropertyNotFound, token, token.Value);
                        }
                    }

                    else if (TypesList.Contains(token.Value))
                    {
                        token.Type = StiTokenType.Cast;

                        if ((tokenPos + 1 < tokensList.Count) && (tokensList[tokenPos].Type == StiTokenType.Dot))
                        {
                            string tempName = token.Value + "." + tokensList[tokenPos + 1].Value;
                            if (FunctionsList.Contains(tempName))
                            {
                                token.Type  = StiTokenType.Function;
                                token.Value = tempName;
                                tokenPos   += 2;
                            }
                            if (SystemVariablesList.Contains(tempName))
                            {
                                token.Type  = StiTokenType.SystemVariable;
                                token.Value = tempName;
                                tokenPos   += 2;
                            }
                        }
                    }

                    else if (ComponentsList.Contains(token.Value))
                    {
                        token.Type = StiTokenType.Component;
                        if ((tokenPos + 1 < tokensList.Count) && (tokensList[tokenPos].Type == StiTokenType.Colon) && ComponentsList.Contains(tokensList[tokenPos + 1].Value))
                        {
                            StiComponent comp = (StiComponent)ComponentsList[tokensList[tokenPos + 1].Value];
                            if (comp != null && comp is StiDataBand)
                            {
                                token.Value = (comp as StiDataBand).DataSourceName;
                                token.Type  = StiTokenType.DataSourceField;
                                tokenPos   += 2;
                            }
                        }
                    }

                    else if (FunctionsList.Contains(token.Value))
                    {
                        while ((StiFunctionType)FunctionsList[token.Value] == StiFunctionType.NameSpace)
                        {
                            if (tokenPos + 1 >= tokensList.Count)
                            {
                                ThrowError(ParserErrorCode.UnexpectedEndOfExpression);
                            }
                            token.Value += "." + tokensList[tokenPos + 1].Value;
                            tokenPos    += 2;
                            if (!FunctionsList.Contains(token.Value))
                            {
                                ThrowError(ParserErrorCode.FunctionNotFound, token, token.Value);
                            }
                        }
                        token.Type = StiTokenType.Function;
                    }

                    else if (SystemVariablesList.Contains(token.Value) && (token.Value != "value" || component is Stimulsoft.Report.CrossTab.StiCrossCell))
                    {
                        token.Type = StiTokenType.SystemVariable;
                    }

                    //else if (token.Value.ToLowerInvariant() == "true" || token.Value.ToLowerInvariant() == "false")
                    //{
                    //    if (token.Value.ToLowerInvariant() == "true")
                    //        token.ValueObject = true;
                    //    else
                    //        token.ValueObject = false;
                    //    token.Type = StiTokenType.Number;
                    //}
                    //else if (token.Value.ToLowerInvariant() == "null")
                    //{
                    //    token.ValueObject = null;
                    //    token.Type = StiTokenType.Number;
                    //}

                    else if (ConstantsList.Contains(token.Value))
                    {
                        while (ConstantsList[token.Value] == namespaceObj)
                        {
                            if (tokenPos + 1 >= tokensList.Count)
                            {
                                ThrowError(ParserErrorCode.UnexpectedEndOfExpression);
                            }
                            string oldTokenValue = token.Value;
                            token.Value += "." + tokensList[tokenPos + 1].Value;
                            tokenPos    += 2;
                            if (!ConstantsList.Contains(token.Value))
                            {
                                ThrowError(ParserErrorCode.ItemDoesNotContainDefinition, token, oldTokenValue, tokensList[tokenPos + 1].Value);
                            }
                        }
                        token.ValueObject = ConstantsList[token.Value];
                        token.Type        = StiTokenType.Number;
                    }

                    else if (report.Dictionary.Variables.Contains(token.Value))
                    {
                        token.Type = StiTokenType.Variable;
                    }
                    else if (token.Value == "or" || token.Value == "and" || token.Value == "not")
                    {
                        if (token.Value == "or")
                        {
                            token.Type = StiTokenType.DoubleOr;
                        }
                        if (token.Value == "and")
                        {
                            token.Type = StiTokenType.DoubleAnd;
                        }
                        if (token.Value == "not")
                        {
                            token.Type = StiTokenType.Not;
                        }
                    }
                    else
                    {
                        if ((tokenPos < tokensList.Count) && (tokensList[tokenPos].Type != StiTokenType.Dot) || (tokenPos == tokensList.Count))
                        {
                            CheckDataSourceField(defaultDataSourceName, token.Value);

                            token.Type  = StiTokenType.DataSourceField;
                            token.Value = defaultDataSourceName + "." + token.Value;
                        }
                        else
                        {
                            if ((tokenPos + 1 < tokensList.Count) && (tokensList[tokenPos].Type == StiTokenType.Dot))
                            {
                                CheckDataSourceField(token.Value, tokensList[tokenPos + 1].Value);

                                token.Type  = StiTokenType.DataSourceField;
                                token.Value = token.Value + "." + tokensList[tokenPos + 1].Value;
                                tokenPos   += 2;
                            }
                            else
                            {
                                ThrowError(ParserErrorCode.NameDoesNotExistInCurrentContext, token, token.Value);
                            }
                        }
                    }
                }
                newList.Add(token);
            }
            return(newList);
        }
        // Получение очередной лексемы.
        private StiToken GetNextLexem()
        {
            //пропустить пробелы, символы табуляции и другие незначащие символы
            while (position < inputExpression.Length && isWhiteSpace(inputExpression[position]))
            {
                position++;
            }
            if (position >= inputExpression.Length)
            {
                return(null);
            }

            StiToken token = null;
            char     ch    = inputExpression[position];

            if (char.IsLetter(ch) || (ch == '_'))
            {
                int pos2 = position + 1;
                while ((pos2 < inputExpression.Length) && (char.IsLetterOrDigit(inputExpression[pos2]) || inputExpression[pos2] == '_'))
                {
                    pos2++;
                }
                token          = new StiToken();
                token.Value    = inputExpression.Substring(position, pos2 - position);
                token.Type     = StiTokenType.Identifier;
                token.Position = position;
                token.Length   = pos2 - position;
                position       = pos2;

                string alias = token.Value;
                if ((token.Position > 0) && (inputExpression[token.Position - 1] == '.'))
                {
                    alias = "." + alias;
                }
                if (hashAliases.ContainsKey(alias))
                {
                    token.Value = (string)hashAliases[alias];
                }

                token.Value = token.Value.ToLowerInvariant();   //FoxPro only

                return(token);
            }
            else if (char.IsDigit(ch))
            {
                token             = new StiToken();
                token.Type        = StiTokenType.Number;
                token.Position    = position;
                token.ValueObject = ScanNumber();
                token.Length      = position - token.Position;
                return(token);
            }
            else if ((ch == '"' || ch == '\'') || ((ch == '@' || ch == '\\') && (position < inputExpression.Length - 1) && (inputExpression[position + 1] == '"')))
            {
                #region "String"
                bool needReplaceBackslash = true;
                if (ch == '@')
                {
                    needReplaceBackslash = false;
                    position++;
                }

                position++;
                int pos2 = position;
                while (pos2 < inputExpression.Length)
                {
                    if (inputExpression[pos2] == '"')
                    {
                        break;
                    }
                    if (inputExpression[pos2] == '\'')
                    {
                        break;
                    }
                    if (inputExpression[pos2] == '\\')
                    {
                        pos2++;
                        if (inputExpression[pos2] == '"')
                        {
                            break;
                        }
                    }
                    pos2++;
                }
                token      = new StiToken();
                token.Type = StiTokenType.String;
                //token.ValueObject = inputExpression.Substring(position, pos2 - position).Replace("\\r", "\r").Replace("\\n", "\n").Replace("\\t", "\t").Replace("\\\"", "\"").Replace("\\'", "'").Replace("\\\\", "\\");
                string st = inputExpression.Substring(position, pos2 - position);
                if (needReplaceBackslash)
                {
                    token.ValueObject = ReplaceBackslash(st);
                }
                else
                {
                    token.ValueObject = st;
                }

                token.Position = position - 1;
                position       = pos2 + 1;
                token.Length   = position - token.Position;
                return(token);

                #endregion
            }
            else
            {
                #region check for alias bracket
                if (ch == '[')
                {
                    int pos2 = inputExpression.IndexOf(']', position);
                    if (pos2 != -1)
                    {
                        pos2++;
                        string alias = inputExpression.Substring(position, pos2 - position);
                        if ((position > 0) && (inputExpression[position - 1] == '.'))
                        {
                            alias = "." + alias;
                        }
                        if (hashAliases.ContainsKey(alias))
                        {
                            token          = new StiToken();
                            token.Value    = ((string)hashAliases[alias]).ToLowerInvariant();
                            token.Type     = StiTokenType.Identifier;
                            token.Position = position;
                            token.Length   = pos2 - position;
                            position       = pos2;
                            return(token);
                        }
                    }
                }
                #endregion

                #region Delimiters
                int tPos = position;
                position++;
                char ch2 = ' ';
                if (position < inputExpression.Length)
                {
                    ch2 = inputExpression[position];
                }
                switch (ch)
                {
                case '.': return(new StiToken(StiTokenType.Dot, tPos, 1));

                case '(': return(new StiToken(StiTokenType.LParenthesis, tPos, 1));

                case ')': return(new StiToken(StiTokenType.RParenthesis, tPos, 1));

                case '[': return(new StiToken(StiTokenType.LBracket, tPos, 1));

                case ']': return(new StiToken(StiTokenType.RBracket, tPos, 1));

                case '+': return(new StiToken(StiTokenType.Plus, tPos, 1));

                case '-': return(new StiToken(StiTokenType.Minus, tPos, 1));

                case '*': return(new StiToken(StiTokenType.Mult, tPos, 1));

                case '/': return(new StiToken(StiTokenType.Div, tPos, 1));

                case '%': return(new StiToken(StiTokenType.Percent, tPos, 1));

                case '^': return(new StiToken(StiTokenType.Xor, tPos, 1));

                case ',': return(new StiToken(StiTokenType.Comma, tPos, 1));

                case ':': return(new StiToken(StiTokenType.Colon, tPos, 1));

                case ';': return(new StiToken(StiTokenType.SemiColon, tPos, 1));

                case '?': return(new StiToken(StiTokenType.Question, tPos, 1));

                case '$': return(new StiToken(StiTokenType.Dollar, tPos, 1));

                case '|':
                    if (ch2 == '|')
                    {
                        position++;
                        return(new StiToken(StiTokenType.DoubleOr, tPos, 2));
                    }
                    else
                    {
                        return(new StiToken(StiTokenType.Or, tPos, 1));
                    }

                case '&':
                    if (ch2 == '&')
                    {
                        position++;
                        return(new StiToken(StiTokenType.DoubleAnd, tPos, 2));
                    }
                    else
                    {
                        return(new StiToken(StiTokenType.And, tPos, 1));
                    }

                case '!':
                    if (ch2 == '=')
                    {
                        position++;
                        return(new StiToken(StiTokenType.NotEqual, tPos, 2));
                    }
                    else
                    {
                        return(new StiToken(StiTokenType.Not, tPos, 1));
                    }

                case '=':
                    return(new StiToken(StiTokenType.Equal, tPos, 1));

                //if (ch2 == '=')
                //{
                //    position++;
                //    return new StiToken(StiTokenType.Equal, tPos, 2);
                //}
                //else return new StiToken(StiTokenType.Assign, tPos, 1);
                case '<':
                    if (ch2 == '<')
                    {
                        position++;
                        return(new StiToken(StiTokenType.Shl, tPos, 2));
                    }
                    else if (ch2 == '=')
                    {
                        position++;
                        return(new StiToken(StiTokenType.LeftEqual, tPos, 2));
                    }
                    else if (ch2 == '>')
                    {
                        position++;
                        return(new StiToken(StiTokenType.NotEqual, tPos, 2));
                    }
                    else
                    {
                        return(new StiToken(StiTokenType.Left, tPos, 1));
                    }

                case '>':
                    if (ch2 == '>')
                    {
                        position++;
                        return(new StiToken(StiTokenType.Shr, tPos, 2));
                    }
                    else if (ch2 == '=')
                    {
                        position++;
                        return(new StiToken(StiTokenType.RightEqual, tPos, 2));
                    }
                    else
                    {
                        return(new StiToken(StiTokenType.Right, tPos, 1));
                    }


                default:
                    token             = new StiToken(StiTokenType.Unknown);
                    token.ValueObject = ch;
                    token.Position    = tPos;
                    token.Length      = 1;
                    return(token);
                }
                #endregion
            }
        }
示例#10
0
        //----------------------------------------
        // Получение значения числа или переменной
        //----------------------------------------
        private void atom()
        {
            switch (currentToken.Type)
            {
            case StiTokenType.Variable:
                asmList.Add(new StiAsmCommand(StiAsmCommandType.PushVariable, currentToken.Value));
                get_token();
                return;

            case StiTokenType.SystemVariable:
                asmList.Add(new StiAsmCommand(StiAsmCommandType.PushSystemVariable, SystemVariablesList[currentToken.Value]));
                get_token();
                return;

            case StiTokenType.Function:
            {
                StiToken           function = currentToken;
                ProryvFunctionType functionType;
                var objFunc = FunctionsList[function.Value];
                if (objFunc != null)
                {
                    functionType = (ProryvFunctionType)objFunc;
                }
                else
                {
                    functionType = (ProryvFunctionType)UserFunctionsList[function.Value];
                }
                asmList.Add(new StiAsmCommand(StiAsmCommandType.PushFunction, functionType, get_args_count(functionType)));
                get_token();
                return;
            }

            case StiTokenType.ProryvFunction:
                var args = get_args();
                asmList.Add(new StiAsmCommand(StiAsmCommandType.PushFunction, ProryvFunctionType.proryvFunction, args.Count));
                get_token();
                return;

            case StiTokenType.ProryvSpreadsheetProperties:
            {
                StiToken function = currentToken;
                asmList.Add(new StiAsmCommand(StiAsmCommandType.ProryvSpreadsheetProperty, _proryvSpreadsheetProperties[function.Value.ToLowerInvariant()]));
                get_token();
                return;
            }

            case StiTokenType.ProryvFreeHierarchyBalanceSignature:
            {
                StiToken function = currentToken;
                asmList.Add(new StiAsmCommand(StiAsmCommandType.ProryvFreeHierarchyBalanceSignature, _proryvFreeHierarchyBalanceSignature[function.Value.ToLowerInvariant()]));
                get_token();
                return;
            }

            case StiTokenType.Method:
                StiToken      method     = currentToken;
                StiMethodType methodType = (StiMethodType)MethodsList[method.Value];
                asmList.Add(new StiAsmCommand(StiAsmCommandType.PushMethod, methodType, get_args_count(methodType) + 1));
                get_token();
                return;

            case StiTokenType.Property:
            {
                StiToken function = currentToken;
                asmList.Add(new StiAsmCommand(StiAsmCommandType.PushProperty, PropertiesList[function.Value]));
                get_token();
                return;
            }

            case StiTokenType.DataSourceField:
                asmList.Add(new StiAsmCommand(StiAsmCommandType.PushDataSourceField, currentToken.Value));
                get_token();
                return;

            case StiTokenType.BusinessObjectField:
                asmList.Add(new StiAsmCommand(StiAsmCommandType.PushBusinessObjectField, currentToken.Value));
                get_token();
                return;

            case StiTokenType.Number:
                asmList.Add(new StiAsmCommand(StiAsmCommandType.PushValue, currentToken.ValueObject));
                get_token();
                return;

            case StiTokenType.String:
                asmList.Add(new StiAsmCommand(StiAsmCommandType.PushValue, currentToken.ValueObject));
                get_token();
                return;

            default:
                if (currentToken.Type == StiTokenType.Empty)
                {
                    ThrowError(ParserErrorCode.UnexpectedEndOfExpression);  //неожиданный конец выражения
                }
                ThrowError(ParserErrorCode.SyntaxError, currentToken);      //cинтаксическая ошибка
                break;
            }
        }
 private void ThrowError(ParserErrorCode code, StiToken token, string message1, string message2, string message3)
 {
     ThrowError(code, token, message1, message2, message3, string.Empty);
 }
 private void ThrowError(ParserErrorCode code, StiToken token)
 {
     ThrowError(code, token, string.Empty, string.Empty, string.Empty, string.Empty);
 }
示例#13
0
 //----------------------------------------
 // Получение значения числа или переменной
 //----------------------------------------
 private void atom()
 {
     if (currentToken.Type == StiTokenType.Variable)
     {
         asmList.Add(new StiAsmCommand(StiAsmCommandType.PushVariable, currentToken.Value));
         get_token();
         return;
     }
     else if (currentToken.Type == StiTokenType.SystemVariable)
     {
         asmList.Add(new StiAsmCommand(StiAsmCommandType.PushSystemVariable, SystemVariablesList[currentToken.Value]));
         get_token();
         return;
     }
     else if (currentToken.Type == StiTokenType.Function)
     {
         StiToken        function     = currentToken;
         StiFunctionType functionType = (StiFunctionType)FunctionsList[function.Value];
         asmList.Add(new StiAsmCommand(StiAsmCommandType.PushFunction, functionType, get_args_count(functionType)));
         get_token();
         return;
     }
     else if (currentToken.Type == StiTokenType.Method)
     {
         StiToken      method     = currentToken;
         StiMethodType methodType = (StiMethodType)MethodsList[method.Value];
         asmList.Add(new StiAsmCommand(StiAsmCommandType.PushMethod, methodType, get_args_count(methodType) + 1));
         get_token();
         return;
     }
     else if (currentToken.Type == StiTokenType.Property)
     {
         StiToken function = currentToken;
         asmList.Add(new StiAsmCommand(StiAsmCommandType.PushProperty, PropertiesList[function.Value]));
         get_token();
         return;
     }
     else if (currentToken.Type == StiTokenType.DataSourceField)
     {
         asmList.Add(new StiAsmCommand(StiAsmCommandType.PushDataSourceField, currentToken.Value));
         get_token();
         return;
     }
     else if (currentToken.Type == StiTokenType.BusinessObjectField)
     {
         asmList.Add(new StiAsmCommand(StiAsmCommandType.PushBusinessObjectField, currentToken.Value));
         get_token();
         return;
     }
     else if (currentToken.Type == StiTokenType.Component)
     {
         asmList.Add(new StiAsmCommand(StiAsmCommandType.PushComponent, ComponentsList[currentToken.Value]));
         get_token();
         return;
     }
     else if (currentToken.Type == StiTokenType.Number)
     {
         asmList.Add(new StiAsmCommand(StiAsmCommandType.PushValue, currentToken.ValueObject));
         get_token();
         return;
     }
     else if (currentToken.Type == StiTokenType.String)
     {
         asmList.Add(new StiAsmCommand(StiAsmCommandType.PushValue, currentToken.ValueObject));
         get_token();
         return;
     }
     else
     {
         if (currentToken.Type == StiTokenType.Empty)
         {
             ThrowError(ParserErrorCode.UnexpectedEndOfExpression); //неожиданный конец выражения
         }
         ThrowError(ParserErrorCode.SyntaxError, currentToken);     //cинтаксическая ошибка
     }
 }
示例#14
0
        private List <StiToken> PostProcessTokensList(List <StiToken> tokensList)
        {
            List <StiToken> newList = new List <StiToken>();

            tokenPos = 0;
            while (tokenPos < tokensList.Count)
            {
                StiToken token = tokensList[tokenPos];
                tokenPos++;
                if (token.Type == StiTokenType.Identifier)
                {
                    if ((newList.Count > 0) && (newList[newList.Count - 1].Type == StiTokenType.Dot))
                    {
                        if (MethodsList.Contains(token.Value))
                        {
                            token.Type = StiTokenType.Method;
                        }
                        //Proryv
                        else if (Equals(token.Value, "Value") || ProryvPropertiesList.Contains(token.Value) || PropertiesList.Contains(token.Value))
                        {
                            token.Type = StiTokenType.Property;
                        }
                        else
                        {
                            ThrowError(ParserErrorCode.FieldMethodOrPropertyNotFound, token, token.Value);
                        }
                    }
                    else if (TypesList.Contains(token.Value))
                    {
                        token.Type = StiTokenType.Cast;

                        if ((tokenPos + 1 < tokensList.Count) && (tokensList[tokenPos].Type == StiTokenType.Dot))
                        {
                            string tempName = token.Value + "." + tokensList[tokenPos + 1].Value;
                            if (FunctionsList.Contains(tempName))
                            {
                                token.Type  = StiTokenType.Function;
                                token.Value = tempName;
                                tokenPos   += 2;
                            }
                            //Proryv
                            else if (ProryvFunctionsList.Contains(tempName))
                            {
                                token.Type  = StiTokenType.ProryvFunction;
                                token.Value = tempName;
                                tokenPos   += 2;
                            }
                            if (SystemVariablesList.Contains(tempName))
                            {
                                token.Type  = StiTokenType.SystemVariable;
                                token.Value = tempName;
                                tokenPos   += 2;
                            }
                        }
                    }

                    //Proryv
                    else if (ProryvFunctionsList.Contains(token.Value))
                    {
                        token.Type = StiTokenType.ProryvFunction;
                    }
                    else if (_proryvSpreadsheetProperties != null && _proryvSpreadsheetProperties.ContainsKey(token.Value.ToLowerInvariant()))
                    {
                        token.Type = StiTokenType.ProryvSpreadsheetProperties;
                    }
                    else if (_proryvFreeHierarchyBalanceSignature != null && _proryvFreeHierarchyBalanceSignature.ContainsKey(token.Value.ToLowerInvariant()))
                    {
                        token.Type = StiTokenType.ProryvFreeHierarchyBalanceSignature;
                    }

                    else if (FunctionsList.Contains(token.Value))
                    {
                        while ((ProryvFunctionType)FunctionsList[token.Value] == ProryvFunctionType.NameSpace)
                        {
                            if (tokenPos + 1 >= tokensList.Count)
                            {
                                ThrowError(ParserErrorCode.UnexpectedEndOfExpression);
                            }
                            var np = tokensList[tokenPos + 1].Value;
                            token.Value += "." + np;
                            tokenPos    += 2;
                            if (!FunctionsList.Contains(token.Value))
                            {
                                if (FunctionsList.Contains(np))
                                {
                                    token.Value = np;
                                }
                                else
                                {
                                    ThrowError(ParserErrorCode.FunctionNotFound, token, token.Value);
                                }
                            }
                        }
                        token.Type = StiTokenType.Function;
                    }

                    else if (SystemVariablesList.Contains(token.Value) && (token.Value != "value"))
                    {
                        token.Type = StiTokenType.SystemVariable;
                    }

                    //else if (token.Value.ToLowerInvariant() == "true" || token.Value.ToLowerInvariant() == "false")
                    //{
                    //    if (token.Value.ToLowerInvariant() == "true")
                    //        token.ValueObject = true;
                    //    else
                    //        token.ValueObject = false;
                    //    token.Type = StiTokenType.Number;
                    //}
                    //else if (token.Value.ToLowerInvariant() == "null")
                    //{
                    //    token.ValueObject = null;
                    //    token.Type = StiTokenType.Number;
                    //}

                    else if (ConstantsList.Contains(token.Value))
                    {
                        while (ConstantsList[token.Value] == namespaceObj)
                        {
                            if (tokenPos + 1 >= tokensList.Count)
                            {
                                ThrowError(ParserErrorCode.UnexpectedEndOfExpression);
                            }
                            string oldTokenValue = token.Value;
                            token.Value += "." + tokensList[tokenPos + 1].Value;
                            tokenPos    += 2;
                            if (!ConstantsList.Contains(token.Value))
                            {
                                ThrowError(ParserErrorCode.ItemDoesNotContainDefinition, token, oldTokenValue, tokensList[tokenPos + 1].Value);
                            }
                        }
                        token.ValueObject = ConstantsList[token.Value];
                        token.Type        = StiTokenType.Number;
                    }

                    else if (UserFunctionsList.Contains(token.Value))
                    {
                        token.Type = StiTokenType.Function;
                    }

                    else
                    {
                        ThrowError(ParserErrorCode.NameDoesNotExistInCurrentContext, token, token.Value);
                    }
                }
                newList.Add(token);
            }
            return(newList);
        }