public abstract class DecafParser extends Object
Constructor and Description |
---|
DecafParser() |
Modifier and Type | Method and Description |
---|---|
void |
consumeNextToken(Queue<Token> tokens)
Discard the next token.
|
SourceInfo |
getCurrentSourceInfo(Queue<Token> tokens)
Retrieve the source info associated with the token at the head of the
queue.
|
boolean |
isNextToken(Queue<Token> tokens,
Token.Type type)
Returns true if and only if the head of the queue is a token of the
expected type.
|
boolean |
isNextTokenKeyword(Queue<Token> tokens,
String keyword)
Returns true if and only if the head of the queue is a keyword token with
the expected text.
|
boolean |
isNextTokenSymbol(Queue<Token> tokens,
String symbol)
Returns true if and only if the head of the queue is a symbol token with
the expected text.
|
void |
matchKeyword(Queue<Token> tokens,
String keyword)
Match and discard the given keyword from the head of the token queue.
|
void |
matchSymbol(Queue<Token> tokens,
String symbol)
Match and discard the given symbol from the head of the token queue.
|
ASTProgram |
parse(Queue<Token> tokens)
Perform syntax analysis, converting a stream of
Token objects
into an ASTProgram . |
public ASTProgram parse(Queue<Token> tokens) throws InvalidSyntaxException
Token
objects
into an ASTProgram
.tokens
- Input token queueInvalidSyntaxException
- Thrown if a syntax error is encounteredpublic void matchSymbol(Queue<Token> tokens, String symbol) throws InvalidSyntaxException
tokens
- Input token queuesymbol
- Expected symbol textInvalidSyntaxException
- Thrown if the queue is empty or the token
does not matchpublic void matchKeyword(Queue<Token> tokens, String keyword) throws InvalidSyntaxException
tokens
- Input token queuekeyword
- Expected keyword textInvalidSyntaxException
- Thrown if the queue is empty or the token
does not matchpublic boolean isNextToken(Queue<Token> tokens, Token.Type type)
tokens
- Input token queuetype
- Expected token typepublic boolean isNextTokenSymbol(Queue<Token> tokens, String symbol)
tokens
- Input token queuesymbol
- Expected symbol textpublic boolean isNextTokenKeyword(Queue<Token> tokens, String keyword)
tokens
- Input token queuekeyword
- Expected keyword textpublic void consumeNextToken(Queue<Token> tokens) throws InvalidSyntaxException
tokens
- Input token queueInvalidSyntaxException
- Thrown if the queue is emptypublic SourceInfo getCurrentSourceInfo(Queue<Token> tokens)
tokens
- Input token queueCopyright © 2019. All rights reserved.