public double Calc(string input) { var lexems = _lexer.Execute(input); var upn = new UpnConverter(); _sy.Execute(lexems, upn); Console.WriteLine("[{0}]", upn.GetSource()); var engine = new DcEngine(); _sy.Execute(lexems, engine); var result = engine.Stack.Pop(); if (engine.Stack.Count > 0) { throw new InvalidOperationException("Value left on stack"); } return(result); }
static void Main(string[] args) { SetupParser(); List <Lexem> lexems = new List <Lexem> (); foreach (string arg in args) { lexems.AddRange(Lexer.Execute(arg)); } CalcEngine engine = new CalcEngine(); SY.Execute(lexems, engine); Console.WriteLine(engine.Stack.Pop()); if (engine.Stack.Count > 0) { Console.Error.WriteLine("WARNING: Some value(s) left on stack"); } }