// 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. }
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; }
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; }
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); }
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; }
public AssemblyNameWord(RawWord[] words, ProseRuntime runtime, Assembly assembly ) : base(words) { this.assembly = assembly; isa = new Word[] { runtime.word("@assembly") }; }
public void addWord(Word word) { global_scope.addWord(word); }
public WordBindingAction(RawWord[] rawWordsToBindAsWord, Word wordToInheritFrom) { this.rawWordsToBindAsWord = rawWordsToBindAsWord; parent = wordToInheritFrom; }
// 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; }
public AssemblyNameWord(RawWord[] words, ProseRuntime runtime, Assembly assembly) : base(words) { this.assembly = assembly; isa = new Word[] { runtime.word("@assembly") }; }
public ExclusiveWordBindingAction(RawWord[] rawWordsToBindAsWord, Word wordToInheritFrom) : base(rawWordsToBindAsWord, wordToInheritFrom) { bindingSymbol = "<-"; }
public MethodNameWord(RawWord[] words, ProseRuntime runtime, ProseLanguage.ActionDelegate delegateMethod ) : base(words) { this.delegateMethod = delegateMethod; isa = new Word[] { runtime.word("@method") }; }
public TypeNameWord(RawWord[] words, ProseRuntime runtime, Type type ) : base(words) { this.type = type; isa = new Word[] { runtime.word("@type") }; }
// Put a word we already have public Word addWord(Word word) { wordTrie.putObjectPath(word.RawWords, word); return word; }
public void setChildNode(Word character, Node childNode) { childMap.Add(character, childNode); }
public Node getChildNode(Word character) { Node childNode; if (childMap.TryGetValue(character, out childNode)) return childNode; else return null; }
public Node(Word character, Phrase phrase) { this.character = character; value = new Phrase[0]; addPhrase (phrase); }
public Node(Word character) { this.character = character; value = new Phrase[0]; }