コード例 #1
0
        internal static void AddRoot()
        {
            var rootPrimitives = new Dictionary <string, Evaluable>()
            {
                // MATH --------------------------------------------------------
                { "+", new Primitive(plus, "+") },
                { "-", new Primitive(minus, "-") },
                { "*", new Primitive(times, "*") },
                { "/", new Primitive(divide, "/") },
                { "um*", new Primitive(umStar, "um*") },
                { "*/", new Primitive(timesDiv, "*/") },
                { "mod", new Primitive(mod, "mod") },
                { "um/mod", new Primitive(umMod, "um/mod") },
                { "negate", new Primitive(negate, "negate") },
                { "abs", new Primitive(abs, "abs") },
                { "min", new Primitive(min, "min") },
                { "max", new Primitive(max, "max") },
                { "1-", new Primitive(oneMinus, "1-") },
                { "1+", new Primitive(onePlus, "1-") },
                // STACK --------------------------------------------------------
                { "dup", new Primitive(dup, "dup") },
                { "?dup", new Primitive(qDup, "?dup") },
                { "drop", new Primitive(drop, "drop") },
                { "swap", new Primitive(swap, "swap") },
                { "over", new Primitive(over, "over") },
                { "nip", new Primitive(nip, "nip") },
                { "tuck", new Primitive(tuck, "tuck") },
                { "rot", new Primitive(rot, "rot") },
                { "-rot", new Primitive(minusRot, "-rot") },
                { "pick", new Primitive(pick, "pick") },
                { "2dup", new Primitive(dup2, "2dup") },
                { "2drop", new Primitive(drop2, "2drop") },
                { "2swap", new Primitive(swap2, "2swap") },
                { "2over", new Primitive(over2, "2over") },
                // COMMENTS ------------------------------------------------------
                { "\\", new LookAhead(lineComment, "\\") },
                { "(", new LookAhead(mlComment, "(", true) },
                // COMPARISONS ---------------------------------------------------
                { "<", new Primitive(lt, "<") },
                { ">", new Primitive(gt, ">") },
                { "<=", new Primitive(leq, "<=") },
                { ">=", new Primitive(geq, ">=") },
                { "u<", new Primitive(ult, "u<") },
                { "u>", new Primitive(ugt, "u>") },
                { "=", new Primitive(eq, "=") },
                { "<>", new Primitive(neq, "<>") },
                { "0=", new Primitive(zeq, "0=") },
                { "0<>", new Primitive(zneq, "0<>") },
                { "0>", new Primitive(zgt, "0>") },
                { "0<", new Primitive(zlt, "0<") },
                // LOGICAL OPERATIONS --------------------------------------------
                { "and", new Primitive(and, "and") },
                { "or", new Primitive(or, "or") },
                { "xor", new Primitive(xor, "xor") },
                { "invert", new Primitive(invert, "invert") },
                { "lshift", new Primitive(lshift, "lshift") },
                { "rshift", new Primitive(rshift, "rshift") },
                // DEFINING -------------------------------------------------------
                { ":", new LookAhead(define, ":") },
                { "constant", new LookAhead(constant, "constant") },
                { "variable", new LookAhead(variable, "variable") },
                { "value", new LookAhead(value, "value") },
                { "'", new LookAhead(tick, "'") },
                { "execute", new LookAhead(execute, "execute") },
                // MEMORY ---------------------------------------------------------
                { "@", new Primitive(fetch, "@") },
                { "!", new Primitive(store, "!") },
                { "c@", new Primitive(cFetch, "c@") },
                { "c!", new Primitive(cStore, "c!") },
                { "w@", new Primitive(wFetch, "w@") },
                { "w!", new Primitive(wStore, "w!") },
                { "b@", new Primitive(bFetch, "b@") },
                { "b!", new Primitive(bStore, "b!") },
                { "+!", new Primitive(memAdd, "+!") },
                { "cells", new Primitive(cells, "cells") },
                { "chars", new Primitive(chars, "chars") },
                // FLOW OF CONTROL ---------------------------------------------------
                { "if", new Compilable(iffn) },
                { "do", new Compilable(dofn) },
                { "?do", new Compilable(questDofn) },
                { "begin", new Compilable(begin) },
                { "i", new Primitive(i, "i") },
                { "j", new Primitive(j, "j") },
                { "leave", new ThrowPrimitive(leave, "leave") },
                { "?leave", new ThrowPrimitive(condLeave, "?leave") },
                { "exit", new ThrowPrimitive(exit, "exit") },
                // STRINGS -------------------------------------------------------------
                { "c\"", new Compilable(countedString) },
                { "s\"", new Compilable(stackString) },
                { "[char]", new LookAhead(fromChar, "[char]", true) },
                { "char", new LookAhead(fromChar, "char") },
                { "strhead", new Primitive(strhead, "strhead") },
                { "count", new Primitive(count, "count") },
                { "cstrTo.Net", new Primitive(cstrToDNet, "cstrTo.Net") },
                // MEMORY ALLOTMENT -----------------------------------------------------
                { "create", new LookAhead(create, "create") },
                { ",", new Primitive(comma, ",") },
                { "c,", new Primitive(charComma, "c,") },
                { "here", new Primitive(here, "here") },
                { "allot", new Primitive(allot, "allot") },
                // RETURN STACK ---------------------------------------------------------
                { ">r", new Primitive(ontoR, ">r") },
                { "r>", new Primitive(fromR, "r>") },
                { "r@", new Primitive(copyR, "r@") },
                { "2>r", new Primitive(ontoR2, "2>r") },
                { "2r>", new Primitive(fromR2, "2r>") },
                { "2r@", new Primitive(copyR2, "2r@") },
                // I/O ------------------------------------------------------------------
                { ".", new Primitive(dot, ".") },
                { ".s", new Primitive(dotS, ".s") },
                { "emit", new Primitive(emit, "emit") },
                { "cr", new Primitive(cr, "cr") },
                { "page", new Primitive(page, "page") },
                { "type", new Primitive(type, "type") },
                { "key", new Primitive(key, "key") },
                { "included", new Primitive(included, "included") },
                // .NET -----------------------------------------------------------------
                { "defmeth", new LookAhead(defmeth, "defmeth") },
                { "defcnst", new LookAhead(defcnst, "defcnst") },
                { "defindx", new LookAhead(defindx, "defindx") },
                { "defstat", new LookAhead(defstat, "defstat") },

                { "prop", new LookAhead(prop, "prop") },
                { "sprop", new LookAhead(sprop, "sprop") },
                { "isnull", new Primitive(isnull, "isnull") },
                { "null", new Primitive(pushNull, "null") },
                // Create a .net string and leave it's token on the stack
                { "n\"", new Compilable(netString) },
                // Create a type from the name and leave it's token on the stack
                // If it's a generic type then the types for it's generic arguments
                // should be pushed on the stack ahead when the type is created.
                { "t\"", new Compilable(netType) },
            };

            Vocabulary.AddVocabulary(new Vocabulary(rootPrimitives, "Root"));
            DefineNetTypes();
        }
コード例 #2
0
ファイル: Vocabulary.cs プロジェクト: darrellp/NetForth
 internal static void AddVocabulary(Vocabulary vocabulary)
 {
     _vocabularies.Push(vocabulary);
 }