示例#1
0
        public List<string> translate(string text)
        {
            // Create a list of items from a string
            List<Token> collection = collect(text);
            
            // Convert infix to postfix notation for easier tree building
            List<Token> postfixCollection = convertToPostfix(collection);
            
            // Build a tree from postfix-formatted list of tokens
            tree = buildTree(postfixCollection);
            /*
            foreach(Token t in tree)
            {
                Console.WriteLine(t);F(∀x(G(y,z)),∃a(b∧c))
            }*/

            //Console.WriteLine(tree.serialize());

            steps = new List<string>();

            List<Func<TokenTree>> stepFunctions = new List<Func<TokenTree>>()
            {
                tree.replaceEquals,
                tree.replaceImplies,
                tree.restrainNegation,
                tree.removeExistsQuantifier,
                tree.removeForallQuantifier,
                tree.convertAlternativeToConjunctions,

            };
            json = new List<dynamic>();
            foreach(Func<TokenTree> function in stepFunctions)
            {
                function();
                tree.simplify();
                steps.Add(tree.serialize());
                json.Add(tree.root.toJson());
            }
            

            List<Token> separated = tree.separate();
            string final = "";
            foreach(Token t in separated)
            {
                final += t.serialize() + "; ";
            }
            final = final.Substring(0, final.Length - 2).replaceOperators();
            
            steps.Add(final);
            
            return steps;
        }
示例#2
0
 public Translator()
 {
     steps = null;
     tree = null;
     json = null;
 }