예제 #1
0
파일: WordTrie.cs 프로젝트: FizzyP/Prose
        //    Map a given object path to a value in the Trie.
        public bool putObjectString(Word[] characters, Phrase phrase)
        {
            Node p = root;

            for (int n=0; n < characters.Length; n++)
            {

                Word character = characters[n];
                //	Try to get a pointer to the next node
                Node child = p.getChildNode(character);
                //	If there is no next node, then make it.
                if (child == null)
                {
                    if (n == characters.Length - 1)
                    {
                        p.setChildNode(character, new Node(character, phrase));
                        return false;	//	False: it wasn't here already.
                    }
                    else
                    {
                        p.setChildNode(character, new Node(character));
                    }
                }
                else
                {
                    //	Move the pointer down the Trie.
                    p = child;
                }
            }
            //	If we get to this point, then the final node wasn't new (or we would have returned).
            //	So, we just need to overwrite the value in that location.
            p.addPhrase(phrase);
            return true;	//	true because we overwrote what was there.
        }
예제 #2
0
 public virtual void performAction(ProseRuntime runtime)
 {
     //	Create/fetc a possibly new word object representing the words.
     Word newWord = runtime.addWordFromRawWords(rawWordsToBindAsWord);
     //	Bind the word using inheritence
     Word[] newIsa = new Word[newWord.isa.Length + 1];		//	Copy all the old inherited words.
     Array.Copy(newWord.isa, newIsa, newWord.isa.Length);
     newIsa[newWord.isa.Length] = parent;					//	Add this new one.
     newWord.isa = newIsa;
 }
예제 #3
0
파일: WordTrie.cs 프로젝트: FizzyP/Prose
        public Phrase[] getValue(Word[] objectString)
        {
            Node p = root;

            foreach (Word character in objectString)
            {
                p = p.getChildNode(character);
                if (p == null)
                    return null;
            }
            return p.Value;
        }
예제 #4
0
        public ProseRuntime()
        {
            global_scope.addProseLanguageWords();

            //	Built-in Words
            word_word = global_scope.addWordFromRawWord(ProseLanguage.Raw.word);
            word_phrase = global_scope.addWordFromRawWord(ProseLanguage.Raw.phrase);

            //@ words
            @PROSE = global_scope.addWordFromRawWord(ProseLanguage.Raw.@prose);
            @TEXT = global_scope.addWordFromRawWord(ProseLanguage.Raw.@text);
            @STRING = global_scope.addWordFromRawWord(ProseLanguage.Raw.@string);
            @RAW = global_scope.addWordFromRawWord(ProseLanguage.Raw.@raw);
            @PATTERN = global_scope.addWordFromRawWord(ProseLanguage.Raw.@pattern);
            @ACTION = global_scope.addWordFromRawWord(ProseLanguage.Raw.@action);
            @BREAK = global_scope.addWordFromRawWord(ProseLanguage.Raw.@break);

            //	Assign the private symbols at construction time
            COLON = global_scope.addWordFromRawWord(ProseLanguage.Raw.Colon);
            PERIOD = global_scope.addWordFromRawWord(ProseLanguage.Raw.Period);
            SEMICOLON = global_scope.addWordFromRawWord(ProseLanguage.Raw.Semicolon);
            COMMA = global_scope.addWordFromRawWord(ProseLanguage.Raw.Comma);
            QUADQUOTE = global_scope.addWordFromRawWord(ProseLanguage.Raw.Quadquote);

            LEFT_PAREN = global_scope.addWordFromRawWord(ProseLanguage.Raw.LeftParenthesis);
            RIGHT_PAREN = global_scope.addWordFromRawWord(ProseLanguage.Raw.RightParenthesis);
            LEFT_SQ_BRACKET = global_scope.addWordFromRawWord(ProseLanguage.Raw.LeftSquareBracket);
            RIGHT_SQ_BRACKET = global_scope.addWordFromRawWord(ProseLanguage.Raw.RightSquareBracket);
            LEFT_CURLY_BRACKET = global_scope.addWordFromRawWord(ProseLanguage.Raw.LeftCurlyBracket);
            RIGHT_CURLY_BRACKET = global_scope.addWordFromRawWord(ProseLanguage.Raw.RightCurlyBracket);

            PLUS_COLON = global_scope.addWordFromRawWord(ProseLanguage.Raw.PlusColon);
            MINUS_COLON = global_scope.addWordFromRawWord(ProseLanguage.Raw.MinusColon);
            LEFT_ARROW = global_scope.addWordFromRawWord(ProseLanguage.Raw.LeftArrow);

            COLON_PLUS = global_scope.addWordFromRawWord(ProseLanguage.Raw.ColonPlus);
            COLON_MINUS = global_scope.addWordFromRawWord(ProseLanguage.Raw.ColonMinus);
            RIGHT_ARROW = global_scope.addWordFromRawWord(ProseLanguage.Raw.RightArrow);

            //	Build the built-in inheritence
            ProseLanguage.constructInitialInheritance(this);

            //	Build the built-in phrases
            ProseLanguage.constructInitialPatternTrie(this);
        }
예제 #5
0
        private MatcherState stateFromAtWord(Word word)
        {
            if (word == runtime.@prose) {
                return MatcherState.MATCHING_PROSE;
            }
            else if (word == runtime.@text) {
                return MatcherState.MATCHING_TEXT;
            }
            else if (word == runtime.@pattern) {
                return MatcherState.MATCHING_PATTERN;
            }

            return MatcherState.MATCHING_OBJECT;
        }
예제 #6
0
 public AssemblyNameWord(RawWord[] words, ProseRuntime runtime, Assembly assembly )
     : base(words)
 {
     this.assembly = assembly;
     isa = new Word[] { runtime.word("@assembly") };
 }
예제 #7
0
 public void addWord(Word word)
 {
     global_scope.addWord(word);
 }
예제 #8
0
 public WordBindingAction(RawWord[] rawWordsToBindAsWord, Word wordToInheritFrom)
 {
     this.rawWordsToBindAsWord = rawWordsToBindAsWord;
     parent = wordToInheritFrom;
 }
예제 #9
0
파일: ProseScope.cs 프로젝트: FizzyP/Prose
 //    Return an object depending only on the contents of the words.
 public Word new_WordFromWords(RawWord[] words)
 {
     //	Look for the word in the trie
     Word foundWord = wordTrie.getValue(words);
     //	If it isn't there, add it
     if (foundWord == null)
     {
         Word newWord = new Word(words);				//	Create the word
         wordTrie.putObjectPath(words, newWord);	//	Put the word into the Trie with address = words
         return newWord;
     }
     else
         return foundWord;
 }
예제 #10
0
 public AssemblyNameWord(RawWord[] words, ProseRuntime runtime, Assembly assembly)
     : base(words)
 {
     this.assembly = assembly;
     isa           = new Word[] { runtime.word("@assembly") };
 }
예제 #11
0
 public ExclusiveWordBindingAction(RawWord[] rawWordsToBindAsWord, Word wordToInheritFrom)
     : base(rawWordsToBindAsWord, wordToInheritFrom)
 {
     bindingSymbol = "<-";
 }
예제 #12
0
 public MethodNameWord(RawWord[] words, ProseRuntime runtime, ProseLanguage.ActionDelegate delegateMethod )
     : base(words)
 {
     this.delegateMethod = delegateMethod;
     isa = new Word[] { runtime.word("@method") };
 }
예제 #13
0
 public TypeNameWord(RawWord[] words, ProseRuntime runtime, Type type )
     : base(words)
 {
     this.type = type;
     isa = new Word[] { runtime.word("@type") };
 }
예제 #14
0
파일: ProseScope.cs 프로젝트: FizzyP/Prose
 //    Put a word we already have
 public Word addWord(Word word)
 {
     wordTrie.putObjectPath(word.RawWords, word);
     return word;
 }
예제 #15
0
파일: WordTrie.cs 프로젝트: FizzyP/Prose
 public void setChildNode(Word character, Node childNode)
 {
     childMap.Add(character, childNode);
 }
예제 #16
0
파일: WordTrie.cs 프로젝트: FizzyP/Prose
 public Node getChildNode(Word character)
 {
     Node childNode;
     if (childMap.TryGetValue(character, out childNode))
         return childNode;
     else
         return null;
 }
예제 #17
0
파일: WordTrie.cs 프로젝트: FizzyP/Prose
 public Node(Word character, Phrase phrase)
 {
     this.character = character;
     value = new Phrase[0];
     addPhrase (phrase);
 }
예제 #18
0
파일: WordTrie.cs 프로젝트: FizzyP/Prose
 public Node(Word character)
 {
     this.character = character;
     value = new Phrase[0];
 }