public abstract class ParseAdditiveOrMultiplicative extends Object
Observation: the only differences between parseMultiplicateExpression
and parseAdditiveExpression
(both private
to
Parser
) are:
As such, we factor out this commonality into a class that treats these above two methods as abstract, and implements the functionality in terms of these abstract methods.
Parser
Constructor and Description |
---|
ParseAdditiveOrMultiplicative() |
Modifier and Type | Method and Description |
---|---|
abstract ParseResult<AST> |
parseBase(int pos)
The "base" thing to parse, that is, the component that parses nested expressions.
|
ParseResult<AST> |
parseExp(int pos)
Actually parses in the expression, using
parseBase and
parseOp in the process. |
abstract ParseResult<Operator> |
parseOp(int pos)
Parser for the operator in play.
|
public abstract ParseResult<AST> parseBase(int pos) throws ParserException
pos
- The position in the input where we start parsingParserException
- when there is a syntax errorpublic abstract ParseResult<Operator> parseOp(int pos) throws ParserException
pos
- The position in the input where we start parsingParserException
- when there is a syntax errorpublic ParseResult<AST> parseExp(int pos) throws ParserException
parseBase
and
parseOp
in the process.pos
- The position in the input where we start parsingParserException
- if there is a syntax error