public abstract class DecafLexer extends Object
StringBuffer
objects using Pattern
regular expressions.Constructor and Description |
---|
DecafLexer()
Generic constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addIgnoredPattern(String regex)
Add a regular expression that describes an ignored token.
|
void |
addTokenPattern(Token.Type type,
String regex)
Add a regular expression that describes a particular type of token.
|
void |
discardIgnored(StringBuffer text)
Discard any ignored text.
|
boolean |
extract(Pattern pattern,
StringBuffer text)
Test the given regular expression pattern against the beginning of the
string buffer.
|
String |
getLastMatch()
Return the most recent text match extracted using
extract(java.util.regex.Pattern, java.lang.StringBuffer) . |
Queue<Token> |
lex(BufferedReader input,
String filename)
Perform lexical analysis, converting Decaf source code into a stream of
Token objects. |
Queue<Token> |
lex(File file)
Perform lexical analysis, converting Decaf source code into a stream of
Token objects. |
Queue<Token> |
lex(InputStream input)
Perform lexical analysis, converting Decaf source code into a stream of
Token objects. |
Queue<Token> |
lex(String text)
Perform lexical analysis, converting Decaf source code into a stream of
Token objects. |
Token |
nextToken(StringBuffer text)
Extract a token from the given buffer.
|
public Queue<Token> lex(String text) throws IOException, InvalidTokenException
Token
objects.text
- Input text stringIOException
- Thrown if there is an error reading from the inputInvalidTokenException
- Thrown if an invalid token is encounteredpublic Queue<Token> lex(File file) throws IOException, InvalidTokenException
Token
objects.file
- Input text fileIOException
- Thrown if there is an error reading from the inputInvalidTokenException
- Thrown if an invalid token is encounteredpublic Queue<Token> lex(InputStream input) throws IOException, InvalidTokenException
Token
objects.input
- Input text streamIOException
- Thrown if there is an error reading from the inputInvalidTokenException
- Thrown if an invalid token is encounteredpublic Queue<Token> lex(BufferedReader input, String filename) throws IOException, InvalidTokenException
Token
objects. This is the form of the method that should be
overridden in actual implementations; the other forms of this method
just call this one.input
- Input text readerfilename
- Source file name (for source info)IOException
- Thrown if there is an error reading from the inputInvalidTokenException
- Thrown if an invalid token is encounteredpublic boolean extract(Pattern pattern, StringBuffer text)
getLastMatch()
method. Note that the matching is performed
greedily.pattern
- Regular expressiontext
- Target textpublic String getLastMatch()
extract(java.util.regex.Pattern, java.lang.StringBuffer)
.public void addIgnoredPattern(String regex)
discardIgnored(java.lang.StringBuffer)
is called.regex
- Regular expression stringpublic void discardIgnored(StringBuffer text)
addIgnoredPattern(java.lang.String)
one at a time, discarding any text matched.text
- Target textpublic void addTokenPattern(Token.Type type, String regex)
nextToken(java.lang.StringBuffer)
to extract tokens
from the beginning of a StringBuffer. The order in which this function
is called is significant; patterns that are registered earlier will be
matched first.type
- Token typeregex
- Regular expression stringpublic Token nextToken(StringBuffer text)
addTokenPattern(edu.jmu.decaf.Token.Type, java.lang.String)
one at a time, returning the next
token matched. The patterns are matched in the order that they were
added.text
- Target textCopyright © 2019. All rights reserved.