GrammarProdclass | gramprod.h[44] |
Superclass Tree | Subclass Tree | Global Objects | Property Summary | Method Summary | Property Details | Method Details |
GrammarProd implements a "parser" in a limited computerese sense, which is essentially a program that produces "sentence diagrams" a la elementary school grammar lessons. GrammarProd is thus only a small part of what we think of as "the parser" in an IF context. The broader parser starts with the sentence diagrams that GrammarProd produces, and must then interpret their meanings and carry out the intentions they express.
Parsers built with GrammarProd trees can handle grammars with left or right recursion, and can handle ambiguous grammars (meaning that a single input can have multiple ways of matching the grammar). This is especially important for natural language parsing, since virtually all natural languages have ambiguous grammars. When a match is ambiguous, a GrammarProd parser builds all of the possible match trees, allowing you to choose the best match based on context and semantic content.
You can also create new productions dynamically with new GrammarProd(). Use addAlt() to populate a new production with token matching rules.
intrinsic class
GrammarProd : Object
GrammarProd
Object
addAlt
clearAlts
deleteAlt
getGrammarInfo
parseTokens
Inherited from Object
:
callInherited
createIterator
createLiveIterator
forEach
getPropList
getPropParams
getSuperclassList
isClass
isTransient
mapAll
ofKind
propDefined
propInherited
propType
valToSymbol
addAlt (alt, matchObj, dict?, symtab?) | gramprod.h[84] |
'alt' is a string with the token list specifying the alternative(s) to add. This uses the same syntax as the rule list in a static 'grammar' statement. You can use '|' symbols to add multiple alternatives.
'matchObj' is the match object class, which is the class of the object that parseTokens() reutrns in the match list to represent a match to this production. This corresponds to the base class defined in a static 'grammar' statement.
'dict' is an optional Dictionary object. Literal tokens used in the token list will be automatically added to the dictionary if they're not already defined.
'symtab' is an optional LookupTable with the global symbol table. This must be provided if any symbolic tokens are used in the rule list (property names, sub-production names, etc). In most cases this is simply the symbol table that t3GetGlobalSymbols() returns during preinit.
clearAlts (dict?) | gramprod.h[123] |
'dict' is an optional Dictionary object to adjust for the deletion. If a non-nil 'dict' is given, we'll remove all of the production's literals from the dictionary.
deleteAlt (id, dict?) | gramprod.h[111] |
- By tag: if 'id' is a string, the method deletes each alternative whose match object's grammarTag property equals 'id'. For static rules defined with 'grammar' statements, the compiler sets grammarTag to the tag used in the statement defining the rule. This makes it easy to delete all of the rules defined by a given 'grammar' statement.
- By match object class: if 'id' is an object, the method deletes every alternative whose match object equals 'id' or is a subclass of 'id'. This makes it easy to delete a group of dynamically added rules that share a match object.
- By index: if 'id' is an integer, it gives the index of the rule to delete. This corresponds to an index in the list returned by getGrammarInfo().
'dict' is an optional Dictionary object to adjust for the deletion. If a non-nil 'dict' is given, we'll remove literals from the dictionary that were defined by the alternative and no longer used in the production.
getGrammarInfo ( ) | gramprod.h[58] |
parseTokens (tokenList, dict) | gramprod.h[51] |