|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.sc3d.apt.sss.v3.Parser
public class Parser
Represents a parser for a particular Grammar. The algorithm used is a depth-first search using an NDFA. Parsers do not look inside Brackets by default. Subclasses can override the 'postProcess()' method to make Parsers customised for a particular Grammar.
Field Summary | |
---|---|
NDFA |
ndfa
An NDFA that represents the grammar passed to the constructor and used by 'parse()'. |
Constructor Summary | |
---|---|
Parser(Grammar grammar)
Constructs a Parser for 'grammar'. |
Method Summary | |
---|---|
void |
interactiveTest()
Prompts for input on 'System.in', parses it, and prints the parse-tree. |
java.lang.Object |
parse(Sentence sentence)
Parses 'sentence' and returns the result of applying 'postProcess()' to its parse-tree. |
Tree |
parseTokens(NDFA ndfa,
Token[] tokens,
Token after)
Parses 'tokens' according to 'ndfa' and returns its parse-tree. |
java.lang.Object |
postProcess(Tree raw)
Subclasses which are specialised for a paticular Grammar can override this method in order to post-process the parse-tree. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public final NDFA ndfa
Constructor Detail |
---|
public Parser(Grammar grammar)
Method Detail |
---|
public java.lang.Object parse(Sentence sentence)
public Tree parseTokens(NDFA ndfa, Token[] tokens, Token after)
ndfa
- an NDFA representing the grammar.tokens
- the Tokens to parse.after
- the first Token after 'tokens', or 'null' if 'tokens' is a whole Sentence. This provides a place to attach an error message in the case that there is something missing at the end of 'tokens'.
public java.lang.Object postProcess(Tree raw)
raw
- the non-null parse-tree.
public void interactiveTest()
In more detail, this method reads a line at a time until it is given a blank line. It concatenates the non-blank lines into a Sentence, parses it, and prints out the value returned by 'postProcess()'. If 'postProcess()' is not overridden, then the default implementation does not parse inside brackets. The method loops until it finds an "end of file" or encounters an IOException.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |