public class LeolaParser extends Parser
Parser
for the Leola programming language.Constructor and Description |
---|
LeolaParser(LeolaParser parser)
Copy constructor
|
LeolaParser(Scanner scanner,
ExceptionHandler exceptionHandler) |
Modifier and Type | Method and Description |
---|---|
void |
expectToken(Token currentToken,
LeolaTokenType expectedType,
LeolaErrorCode errorCode)
Expect that the current token is of the supplied
LeolaTokenType . |
Token |
expectTokenNext(Token currentToken,
LeolaTokenType expectedType,
LeolaErrorCode errorCode)
Expect that the current token is of the supplied
LeolaTokenType . |
int |
getErrorCount()
Return the number of syntax errors found by the parser.
|
ASTNode |
parse()
Parse a source program and generate the intermediate code and the symbol
table.
|
protected void |
setLineNumber(ASTNode node,
Token token)
Set the current line number as a statement node attribute.
|
void |
throwParseError(Token token,
LeolaErrorCode errorCode)
Issues a parsing exception.
|
currentToken, getEventDispatcher, getExceptionHandler, getScanner, getSource, nextToken, previousToken
public LeolaParser(Scanner scanner, ExceptionHandler exceptionHandler)
scanner
- public LeolaParser(LeolaParser parser)
parser
- public int getErrorCount()
Parser
getErrorCount
in class Parser
protected void setLineNumber(ASTNode node, Token token)
node
- ICodeNodetoken
- Tokenpublic ASTNode parse() throws Exception
Parser
public void throwParseError(Token token, LeolaErrorCode errorCode)
token
- errorCode
- public void expectToken(Token currentToken, LeolaTokenType expectedType, LeolaErrorCode errorCode)
LeolaTokenType
. If the expected token is
not a match, a parser error is thrown (parserthrowParseError(Token, LeolaErrorCode)
.currentToken
- the current Token
, that will be validatedexpectedType
- the expected LeolaTokenType
, which should match the currentTokenerrorCode
- the LeolaErrorCode
that will be raised if the current token does not match the expected typepublic Token expectTokenNext(Token currentToken, LeolaTokenType expectedType, LeolaErrorCode errorCode) throws IOException
LeolaTokenType
. If the expected token is
not a match, a parser error is thrown (parserthrowParseError(Token, LeolaErrorCode)
. If there is a
match, Parser.nextToken()
is called.currentToken
- the current Token
, that will be validatedexpectedType
- the expected LeolaTokenType
, which should match the currentTokenerrorCode
- the LeolaErrorCode
that will be raised if the current token does not match the expected typeParser.nextToken()
and returns the Token
IOException
Copyright © 2010–2015. All rights reserved.