|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectrecognizer.Recognizer
public class Recognizer
This class consists of a number of methods that "recognize" strings composed of Tokens that follow the indicated grammar rules for each method.
Each method may have one of three outcomes:
true and
consuming the tokens that make up that particular nonterminal.false and not
consuming any tokens.SyntaxException
| Constructor Summary | |
|---|---|
Recognizer(java.lang.String text)
Constructs a Recognizer for the given string. |
|
| Method Summary | |
|---|---|
Tokenizer |
getTokenizer()
Returns the Tokenizer being used; needed for testing. |
boolean |
isAddOperator()
Tries to recognize an <add_operator>. |
boolean |
isExpression()
Tries to recognize an <expression>. |
boolean |
isFactor()
Tries to recognize a <factor>. |
boolean |
isMultiplyOperator()
Tries to recognize a <multiply_operator>. |
(package private) boolean |
isSymbol(java.lang.String expectedSymbol)
Tests whether the next token is the expected symbol. |
boolean |
isTerm()
Tries to recognize a <term>. |
boolean |
isVariable()
Tries to recognize a <variable>. |
boolean |
nextTokenMatches(TokenType type)
Tests whether the next token has the expected type. |
boolean |
nextTokenMatches(TokenType type,
java.lang.String value)
Tests whether the next token has the expected type and value. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Recognizer(java.lang.String text)
text - The string to be recognized.| Method Detail |
|---|
public Tokenizer getTokenizer()
public boolean isExpression()
<expression> ::= [ <add_operator> ] <term> { <add_operator> <expression> }
A SyntaxException will be thrown if an <add_operator>
is present after the first <term> but not followed by a valid <expression>.
true if an <expression> is recognized.public boolean isTerm()
<term> ::= <factor> { <multiply_operator> <term>}
A SyntaxException will be thrown if the <multiply_operator>
is present but not followed by a valid <term>.
true if a term is recognized.public boolean isFactor()
<factor> ::= <name>
| <number>
| "x"
| "y"
| "(" <expression> ")"
A SyntaxException will be thrown if the opening
parenthesis is present but not followed by a valid
<expression> and a closing parenthesis.
true if a factor is recognized.public boolean isAddOperator()
<add_operator> ::= "+" | "-"
true if an <add_operator> is recognized.public boolean isMultiplyOperator()
<multiply_operator> ::= "*" | "/"
true if a <multiply_operator> is recognized.public boolean isVariable()
<variable> ::= <NAME>
true if a <variable> is recognized.boolean isSymbol(java.lang.String expectedSymbol)
expectedSymbol - The String value of the token we expect
to encounter next.
true if the next token is the expected symbol.public boolean nextTokenMatches(TokenType type)
type - The expected type of the next token.
true if the next token has the expected type.
public boolean nextTokenMatches(TokenType type,
java.lang.String value)
type - The expected type of the next token.value - The expected value of the next token; must
not be null.
true if the next token has the expected type.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||