예제 #1
0
        public ProgramNode Parse(XElement xe)
        {
            switch (xe.Name.ToString())
            {
            case "TerminalNode":
                throw(new FormatException("TerminalNode is abstract node!"));

            case "NonterminalNode":
            {
                var ruleName    = xe.Attribute("rule").Value;
                var grammarRule = (NonterminalRule)grammar.Rule(ruleName);
                var children    = new ProgramNode[xe.Elements().Count()];
                int index       = 0;
                foreach (var childXe in xe.Elements())
                {
                    children[index] = Parse(childXe);
                    index++;
                }
                var node = new NonterminalNode(grammarRule, children);
                return(node);
            }

            case "Hole":
                throw(new NotImplementedException("Hole is not supported yet!"));

            case "LiteralNode":
            {
                var symbolName = xe.Attribute("symbol").Value;
                var node       = new LiteralNode(grammar.Symbol(symbolName), makeObject(xe));
                return(node);
            }

            case "VariableNode":
            {
                var symbolName = xe.Attribute("symbol").Value;
                var node       = new VariableNode(grammar.Symbol(symbolName));
                return(node);
            }

            case "LambdaNode":
                throw(new NotImplementedException("LambdaNode is not supported yet!"));

            case "LetNode":
                throw(new NotImplementedException("LetNode is not supported yet!"));

            default:
                throw(new FormatException("Unknown XML node label!"));
            }
        }
예제 #2
0
        public ActionResult RunProgram(string encoded, HttpPostedFileBase run_file)
        {
            var pNode = new NonterminalNode(SNTSBackend.Learner.Instance.Grammar.Rules[0] as NonterminalRule);

            if (UploadFile(run_file))
            {
                ViewBag.Message   = "Files Uploaded Successfully!!";
                ViewBag.InputFile = "out-" + Path.GetFileName(run_file.FileName);
                var inputTable  = OpenFile(Path.GetFileName(run_file.FileName));
                var outputTable = SNTSBackend.Learner.Instance.Invoke(pNode, inputTable);
                SNTSBackend.Parser.DatatableToCSVWriter.Write(outputTable, Path.Combine(Server.MapPath("~/Uploads/"), $"out-{run_file.FileName}"));
            }
            else
            {
                ViewBag.Message = "Files Not Uploaded!!";
            }
            return(View());
        }
예제 #3
0
        public double Multiply(VariableNode v, NonterminalNode start, NonterminalNode end)
        {
            int multiple = 1;

            foreach (ProgramNode p in start.Children)
            {
                if (p.Symbol.IsTerminal)
                {
                    multiple *= 10;
                    break;
                }
            }
            foreach (ProgramNode p in end.Children)
            {
                if (p.Symbol.IsTerminal)
                {
                    multiple *= 10;
                    break;
                }
            }
            return((double)start.GetFeatureValue(this) * (double)end.GetFeatureValue(this) * multiple);
        }