Esempio n. 1
0
        public override string ToString()
        {
            var result = f.ToString();

            if (!(f is IAtomicFormula))
            {
                result = "(" + result + ")";
            }
            result = "!" + result;
            return(result);
        }
Esempio n. 2
0
        private void addObjectReferenceToList(IFormula formula, IDictionary <string, int> list, IObjectReference objectReference)
        {
            var alias = Regex.Replace(objectReference.Alias, @"\s", "_");

            try
            {
                list.Add(alias, idFor(objectReference.Object));
            }
            catch (ArgumentException ex)
            {
                throw new ArgumentException(Error.AliasAlreadyUsedInFormula(alias, formula.ToString()), ex);
            }
        }
Esempio n. 3
0
        protected BinaryConnectiveC(IFormula f1, IFormula f2, bool sort = false)
        {
            if (!sort || f1.ToString().CompareTo(f2.ToString()) >= 0)
            {
                pF1 = f1;
                pF2 = f2;
            }
            else
            {
                pF1 = f2;
                pF2 = f1;
            }

            var fv = new HashSet <LVar>(f1.ffreeVariables);

            fv.UnionWith(f2.ffreeVariables);
            pFreeVariables = fv;
        }
Esempio n. 4
0
 protected override void Context()
 {
     base.Context();
     _dim           = A.Fake <IDimension>();
     _inputReaction = A.Fake <IReaction>();
     _formula       = A.Fake <Formula>();
     _kinetic       = "Kinetic";
     A.CallTo(() => _formula.ToString()).Returns(_kinetic);
     _inputReaction.Dimension = _dim;
     _inputReaction.Formula   = _formula;
     _eductAmount             = A.Fake <IMoleculeAmount>().WithName("Educt");
     _productAmount           = A.Fake <IMoleculeAmount>().WithName("Product");
     _educt = A.Fake <IReactionPartner>();
     A.CallTo(() => _educt.Partner).Returns(_eductAmount);
     A.CallTo(() => _educt.StoichiometricCoefficient).Returns(1);
     _product = A.Fake <IReactionPartner>();
     A.CallTo(() => _product.Partner).Returns(_productAmount);
     A.CallTo(() => _product.StoichiometricCoefficient).Returns(1);
     A.CallTo(() => _inputReaction.Educts).Returns(new[] { _educt });
     A.CallTo(() => _inputReaction.Products).Returns(new[] { _product });
     A.CallTo(() => _stoichiometricStringCreate.CreateFrom(A <IEnumerable <IReactionPartner> > ._, A <IEnumerable <IReactionPartner> > ._))
     .Returns(string.Format("1 {0} => 1 {1}", _eductAmount.Name, _productAmount.Name));
 }
        public ChangeStartValueFormulaCommand(IStartValuesBuildingBlock <T> buildingBlock, T startValue, IFormula newFormula, IFormula oldFormula) : base(buildingBlock)
        {
            _newFormula        = newFormula;
            _oldFormula        = oldFormula;
            _objectBaseId      = _buildingBlock.Id;
            _changedStartValue = startValue;
            ObjectType         = new ObjectTypeResolver().TypeFor(startValue);

            Description = AppConstants.Commands.EditDescription(ObjectType, AppConstants.Captions.FormulaName, _oldFormula?.ToString() ?? AppConstants.NullString, _newFormula?.ToString() ?? AppConstants.NullString, _changedStartValue.Path.PathAsString);

            CommandType = AppConstants.Commands.EditCommand;

            _oldFormulaId = GetFormulaId(_oldFormula);
            _newFormulaId = GetFormulaId(_newFormula);
        }
Esempio n. 6
0
 /// <returns>Mediated formula string</returns>
 public override string ToString() => formula.ToString();
Esempio n. 7
0
        public static void Main(string[] args)
        {
            SaveDir = Application.StartupPath + "/save/";
            if (!Directory.Exists(SaveDir))
            {
                Directory.CreateDirectory(SaveDir);
            }


            RuntimeSetting setting = new RuntimeSetting();
            RuntimeData    data    = new Runtime.RuntimeData(setting);
            IFormula       formula = null;

            Analyzer.Analyzer analyzer = null;

            Console.WriteLine("============================");
            Console.WriteLine("    Func Calc ");
            Console.WriteLine("============================");
            for (;;)
            {
                Console.WriteLine(" 1. New Formula");
                Console.WriteLine(" 2. Show Functions");
                Console.WriteLine(" 3. Show Operators");
                if (formula != null)
                {
                    Console.WriteLine(" 4. Get Result");
                    Console.WriteLine(" 5. Run Addition Formula");
                    Console.WriteLine(" 6. Show DebugInformation");
                    Console.WriteLine(" 7. Show Expression Tree");
                    Console.WriteLine(" 8. Enabled DebugMode");
                }
                Console.WriteLine(" 9. Quit");
                char c = Console.ReadKey(true).KeyChar;
                Console.Clear();

                switch (c)
                {
                case '1':
                    setting = new RuntimeSetting();
                    data    = new RuntimeData(setting);
                    Console.WriteLine("Initialized FormulaRuntime");
                    Console.WriteLine("Input formula");
                    Console.Write("> ");
                    try {
                        analyzer = new Analyzer.Analyzer(Console.ReadLine());
                        Stopwatch sw1 = Stopwatch.StartNew();
                        formula = analyzer.GetResult() as IFormula;
                        sw1.Stop();
                        Console.WriteLine("Success! Time : " + sw1.Elapsed.ToString());
                    }
                    catch (SyntaxException ex) {
                        Console.WriteLine("構文エラーが発生しました。計算式の書式のミスを確認してください。");
                        Console.WriteLine("エラー : " + ex.Message);
                        Console.WriteLine("トークン : {0}", ex.Token);
                        Console.Write("場所 : ");
                        ConsoleColor cc = Console.BackgroundColor;
                        if (analyzer.Tokens == null)
                        {
                            Console.WriteLine("トークン情報がありませんでした");
                        }
                        else
                        {
                            foreach (var t in analyzer.Tokens)
                            {
                                if (t != ex.Token)
                                {
                                    Console.BackgroundColor = cc;
                                }
                                else
                                {
                                    Console.BackgroundColor = ConsoleColor.Red;
                                }
                                Console.Write(t.Text);
                            }
                        }
                        Console.BackgroundColor = cc; Console.WriteLine();
                        Console.WriteLine("詳細: \n{0}", ex.ToString());
                    }
                    catch (RuntimeException ex) {
                        Console.WriteLine("実行エラーが発生しました。");
                        Console.WriteLine("エラー : " + ex.Message);
                        Console.WriteLine("トークン : {0}", ex.Token);
                        Console.WriteLine("詳細: \n{0}", ex.ToString());
                    }
                    break;

                case '2':
                    foreach (var func in data.Functions)
                    {
                        StringBuilder param = new StringBuilder();
                        foreach (var p in func.Value.Parameter)
                        {
                            if (param.Length != 0)
                            {
                                param.Append(", ");
                            }
                            param.Append(p.ToString());
                        }
                        Console.WriteLine("{0}({1}) - {2}",
                                          func.Value.Name, param, func.Value.Description);
                    }
                    break;

                case '3':
                    Console.WriteLine("Prior. L  Op   R - Description");
                    foreach (var op in setting.Spec.Operations.OrderBy(d => d.Value).Reverse())
                    {
                        Console.WriteLine("{0,6} {1} {2,5} {3} - {4}",
                                          op.Value,
                                          op.Key.RequireLeftParameter ? "#" : " ",
                                          op.Key.Text,
                                          op.Key.RequireRightParameter ? "#" : " ",
                                          op.Key.Name);
                    }
                    break;

                case '4':
                    if (formula == null)
                    {
                        continue;
                    }
                    RuntimeData dd  = data.Clone() as RuntimeData;
                    Stopwatch   sw  = Stopwatch.StartNew();
                    var         res = formula.Eval(dd);
                    sw.Stop();
                    Console.WriteLine("Input  : " + analyzer.Line);
                    Console.WriteLine("Formula: " + formula.ToString());
                    Console.WriteLine("Result : " + (res == null ? "戻り値はありませんでした" : res.ToString()));
                    Console.WriteLine("Mathjax: " + (res == null ? "戻り値はありませんでした" : res.Output(OutputType.Mathjax)));
                    Console.WriteLine("Time   : " + sw.Elapsed.ToString());
                    Console.WriteLine("Variables:");
                    foreach (var block in data.Blocks)
                    {
                        foreach (var item in block.Variables)
                        {
                            Console.WriteLine("{0:10} : {1}", item.Key, item.Value);
                        }
                    }
                    break;

                case '5':
                    if (formula == null)
                    {
                        continue;
                    }
                    else
                    {
                        Console.WriteLine("Input Addition Formula:");
                        Console.Write(" >");
                        Analyzer.Analyzer anal = new Analyzer.Analyzer(
                            Console.ReadLine(), setting);
                        Console.WriteLine("Success!");
                        var d    = anal.GetResult();
                        var dres = d.Eval(data);
                        Console.WriteLine("Done. (ReturnVal: " +
                                          (dres == null ? "null" : dres.ToString()) + ")");
                    }
                    break;

                case '6':
                    if (formula == null)
                    {
                        continue;
                    }
                    data.OutputDebug();
                    break;

                case '7':
                    if (formula == null)
                    {
                        continue;
                    }
                    Console.WriteLine("Input  : " + analyzer.Line);
                    Console.WriteLine("Output Expression: " + formula.GetType().Name);
                    OutputFormula(data, formula, 0);
                    break;

                case '8':
                    if (formula == null)
                    {
                        continue;
                    }
                    if (!setting.IsDebug)
                    {
                        setting.IsDebug = true;
                        Console.WriteLine("Debug Enabled!");
                    }
                    else
                    {
                        setting.IsDebug = false;
                        Console.WriteLine("Debug Disabled!");
                    }
                    break;


                case '9': return;

                case 'w':
                    ToWritingMode(data);
                    break;

                default:
                    continue;
                }
                Console.WriteLine();
            }
        }