Exemple #1
0
        private void operand(ref Variant FValue)
        {
            EvalIdentifier iden = null;

            switch (FParser.Token)
            {
            case TokenType.Symbol:
                iden = SearchIdentifier(FParser.TokenString());
                if (iden == null)
                {
                    throw new EvalException(Translator.TranslateStr(440) + FParser.TokenString(),
                                            FParser.SourceLine, FParser.SourcePos, "");
                }
                FValue = iden.Value;
                FParser.NextToken();
                break;

            case TokenType.String:
                FValue = FParser.TokenString();
                FParser.NextToken();
                break;

            case TokenType.Integer:
                FValue = FParser.AsInteger;
                FParser.NextToken();
                break;

            case TokenType.Double:
                FValue = FParser.AsDouble;
                FParser.NextToken();
                break;

            case TokenType.Decimal:
                FValue = FParser.AsDecimal;
                FParser.NextToken();
                break;

            default:
                throw new EvalException(Translator.TranslateStr(449),
                                        FParser.SourceLine, FParser.SourcePos, "");
            }
        }
Exemple #2
0
        public EvalIdentifier FindField(string fieldname, string datasetname, ref bool duplicated)
        {
            duplicated = false;
            EvalIdentifier iden = null;
            DataTable      adatatable;
            DataTable      adata       = null;
            string         acolumn     = null;
            int            acurrentrow = 0;

            int i, index;

            if (datasetname.Length == 0)
            {
                for (i = 0; i < FList.Count; i++)
                {
                    adatatable = FList[i].Data;
                    if (adatatable != null)
                    {
                        index = adatatable.Columns.IndexOf(fieldname);
                        if (index >= 0)
                        {
                            if (acolumn != null)
                            {
                                duplicated = true;
                                break;
                            }
                            acolumn     = fieldname;
                            adata       = adatatable;
                            acurrentrow = FList[i].CurrentRow;
                        }
                    }
                    if (duplicated)
                    {
                        break;
                    }
                }
            }
            else
            {
                for (i = 0; i < FList.Count; i++)
                {
                    if (FList[i].Alias == datasetname)
                    {
                        adatatable = FList[i].Data;
                        if (adatatable != null)
                        {
                            index = adatatable.Columns.IndexOf(fieldname);
                            if (index >= 0)
                            {
                                adata       = adatatable;
                                acolumn     = fieldname;
                                acurrentrow = FList[i].CurrentRow;
                                break;
                            }
                        }
                    }
                    if (acolumn != null)
                    {
                        break;
                    }
                }
            }
            if (acolumn != null)
            {
                FIden.Field      = acolumn;
                FIden.Data       = adata;
                FIden.CurrentRow = acurrentrow;
                iden             = FIden;
            }
            return(iden);
        }
Exemple #3
0
 /// <summary>
 /// Add a variable to the evaluator
 /// </summary>
 /// <param name="name1">Variable name</param>
 /// <param name="iden">Identifier object, usually a IdenVariable typed object</param>
 public void AddVariable(string name1, EvalIdentifier iden)
 {
     iden.Name = name1.ToUpper();
     FIdentifierList.Add("M." + iden.Name, iden);
 }
Exemple #4
0
        // Unary operators, NOT, unary - and functions
        private void dosign(ref Variant FValue)
        {
            string         aoperator = "";
            EvalIdentifier iden      = null;
            IdenFunction   idenf     = null;

            if (FParser.Token == TokenType.Operator)
            {
                aoperator = FParser.TokenString();
                if ((aoperator == "-") || (aoperator == "+") ||
                    (aoperator == "NOT") || (aoperator == "IIF"))
                {
                    FParser.NextToken();
                }
            }
            else
            if (FParser.Token == TokenType.Symbol)
            {
                iden = SearchIdentifier(FParser.TokenString());
                if (iden == null)
                {
                    throw new EvalException(Translator.TranslateStr(440) + FParser.TokenString(),
                                            FParser.SourceLine, FParser.SourcePos, "");
                }
                // Process parameters
                if (iden is IdenFunction)
                {
                    idenf = (IdenFunction)iden;
                    int i;

                    if (idenf.ParamCount > 0)
                    {
                        FParser.NextToken();
                        if (FParser.Token != TokenType.Operator)
                        {
                            throw new EvalException(Translator.TranslateStr(441),
                                                    FParser.SourceLine, FParser.SourcePos, "");
                        }
                        if (FParser.TokenString() != "(")
                        {
                            throw new EvalException(Translator.TranslateStr(441),
                                                    FParser.SourceLine, FParser.SourcePos, "");
                        }
                    }
                    for (i = 0; i < idenf.ParamCount; i++)
                    {
                        FParser.NextToken();
                        // Looks for the param
                        separator(ref idenf.Params[i]);
                        // Parameter separator
                        if (idenf.ParamCount > i + 1)
                        {
                            aoperator = "";
                            if (FParser.Token == TokenType.Operator)
                            {
                                aoperator = FParser.TokenString();
                            }
                            if (aoperator != ",")
                            {
                                throw new EvalException(String.Format(Translator.TranslateStr(448), ","),
                                                        FParser.SourceLine, FParser.SourcePos, "");
                            }
                        }
                    }

                    if (idenf.ParamCount > 0)
                    {
                        if (FParser.Token != TokenType.Operator)
                        {
                            throw new EvalException(Translator.TranslateStr(441),
                                                    FParser.SourceLine, FParser.SourcePos, "");
                        }
                        if (FParser.TokenString() != ")")
                        {
                            throw new EvalException(Translator.TranslateStr(441),
                                                    FParser.SourceLine, FParser.SourcePos, "");
                        }
                        FParser.NextToken();
                    }
                }
                else
                {
                    iden = null;
                }
                aoperator = "";
            }
            if (iden == null)
            {
                if (aoperator == "IIF")
                {
                    ExecuteIIF(ref FValue);
                }
                else
                {
                    parentesis(ref FValue);
                }
            }
            else
            {
                if (idenf.ParamCount < 1)
                {
                    FParser.NextToken();
                }
            }
            if (iden != null)
            {
                // Execute the function
                if (!FChecking)
                {
                    FValue = idenf.Value;
                }
                else
                {
                    FValue = new Variant();
                }
            }
            else
            {
                if (aoperator == "-")
                {
                    if (!FChecking)
                    {
                        FValue = -FValue;
                    }
                }
                else
                if (aoperator == "NOT")
                {
                    if (!FChecking)
                    {
                        FValue = !FValue;
                    }
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Obtains a memory stream from an expression resulting in a file name path or
        /// a database field
        /// </summary>
        /// <param name="expre">Expression to evaluate</param>
        /// <returns>A Memory stream or null if the result is not a stream</returns>
        public MemoryStream GetStreamFromExpression(string expre)
        {
            EvalIdentifier iden      = SearchIdentifier(expre);
            MemoryStream   memstream = null;

            if (iden != null)
            {
                if (iden is IdenField)
                {
                    Variant avalue = iden.Value;
                    if (avalue.VarType == VariantType.Binary)
                    {
                        memstream = avalue.GetStream();
                        memstream.Seek(0, System.IO.SeekOrigin.Begin);
                        // Search for Paradox graphic header

                        if (memstream.Length > 8)
                        {
                            byte[] buf = new byte[8];
                            memstream.Read(buf, 0, 8);
                            ParadoxGraphicHeader hd = new ParadoxGraphicHeader();
                            hd.Count = StreamUtil.ByteArrayToShort(buf, 0, 2);
                            hd.HType = StreamUtil.ByteArrayToShort(buf, 2, 2);
                            hd.Size  = StreamUtil.ByteArrayToInt(buf, 4, 4);
                            if ((hd.Count == 1) && (hd.HType == 0x0100))
                            {
                                MemoryStream astream = new MemoryStream();
                                buf = new byte[hd.Size];
                                int readed = memstream.Read(buf, 0, hd.Size);
                                astream.Write(buf, 0, readed);
                                memstream = astream;
                            }
                            memstream.Seek(0, System.IO.SeekOrigin.Begin);
                        }
                    }
                    else
                    if (avalue.VarType != VariantType.Null)
                    {
                        iden = null;
                    }
                }
                else
                {
                    iden = null;
                }
            }
            if (iden == null)
            {
                Variant avalue = EvaluateText(expre);
                if (avalue.VarType != VariantType.String)
                {
                    throw new NamedException("Field or file not found:" + expre, expre);
                }
                System.IO.FileInfo finfo = new System.IO.FileInfo(avalue.AsString);
                if (!finfo.Exists)
                {
                    throw new NamedException("File not found:" + avalue.AsString, avalue.AsString);
                }
                memstream = new MemoryStream();
                FileStream afile = new FileStream(avalue.AsString,
                                                  System.IO.FileMode.Open, System.IO.FileAccess.Read);
                try
                {
                    byte[] buf    = new byte[120000];
                    int    readed = afile.Read(buf, 0, 120000);
                    while (readed > 0)
                    {
                        memstream.Write(buf, 0, readed);
                        readed = afile.Read(buf, 0, 120000);
                    }
                }
                finally
                {
                    afile.Close();
                }
            }
            return(memstream);
        }
Exemple #6
0
        /// <summary>
        /// Looks for an identifier, returns null if not found
        /// </summary>
        /// <param name="idenname">Identifier name</param>
        /// <returns>Identifier found or null</returns>
        public EvalIdentifier SearchIdentifier(string idenname)
        {
            EvalIdentifier iden = null;

            idenname = idenname.ToUpper();
            // Looks for field in a dataset
            string sdataset, sfield;

            sdataset = "";
            sfield   = idenname;
            int index = idenname.IndexOf(".");

            if (index < 0)
            {
                // If is not a funcion, can be a variable
                index = FIdentifierList.IndexOfKey(idenname);
                if (index >= 0)
                {
                    return(FIdentifierList[idenname]);
                }
                sfield = idenname;
            }
            else
            {
                sdataset = idenname.Substring(0, index);
                sfield   = idenname.Substring(index + 1, idenname.Length - index - 1);
                if (sdataset == "M")
                {
                    string fieldm2 = "M." + sfield;
                    if (FIdentifierList.IndexOfKey(fieldm2) >= 0)
                    {
                        return(FIdentifierList["M." + sfield]);
                    }
                }
            }
            if (sdataset == "")
            {
                string fieldm = "M." + sfield;
                if (FIdentifierList.IndexOfKey(fieldm) >= 0)
                {
                    iden = FIdentifierList[fieldm];
                }
            }
            if (FAliasList != null)
            {
                bool           duplicated = false;
                EvalIdentifier idenfield  = FAliasList.FindField(sfield, sdataset, ref duplicated);
                if (duplicated)
                {
                    throw new NamedException("Especify variable or file:" + sfield, sfield);
                }
                if (idenfield != null)
                {
                    if (iden != null)
                    {
                        throw new NamedException("Especify variable or file:" + sfield, sfield);
                    }
                    else
                    {
                        iden = idenfield;
                    }
                }
            }
            return(iden);
        }
Exemple #7
0
 /// <summary>
 /// Addd any identifier object to the evaluator
 /// </summary>
 /// <param name="name1">Identifier name</param>
 /// <param name="iden">Identifier object</param>
 public void AddIden(string name1, EvalIdentifier iden)
 {
     iden.Name = name1.ToUpper();
     FIdentifierList.Add(iden.Name, iden);
 }
Exemple #8
0
 public void Add(string key, EvalIdentifier obj)
 {
     FItems.Add(key, obj);
 }