-
Notifications
You must be signed in to change notification settings - Fork 28
Conversation
Thanks ;) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! Noted a few things to make the parser integration smooth.
@Override | ||
public Token getToken() { | ||
|
||
if (tokenText.isEmpty() && reader.isEOF()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All this logic should be moved to advance
. All this method should do is to return the value of a member variable, that holds the current token.
} | ||
|
||
// read token chars | ||
while (!reader.isEOF() && reader.getChar() != ' ' && reader.getChar() != '\n' && reader.getChar() != '\t') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is not always a whitespace between tokens. Think of parentheses, which are also tokens. This should also work if there is no whitespace.
What advance
needs to do is, to match the input against all available state machines and the state machine, which can match the largest number of chars, gets to consume the input and create the respective token.
} | ||
|
||
private void advanceStringLiteral() { | ||
do { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The StringLiteralStateMachine should do this part.
|
||
@Override | ||
public void close() throws IOException { | ||
inputStream.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool approach! This should close the input stream if anything exceptional occurs, right?
src/test/java/com/auberer/compilerdesignlectureproject/lexer/LexerTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/auberer/compilerdesignlectureproject/lexer/LexerTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/auberer/compilerdesignlectureproject/reader/ReaderTest.java
Outdated
Show resolved
Hide resolved
src/main/java/com/auberer/compilerdesignlectureproject/lexer/Lexer.java
Outdated
Show resolved
Hide resolved
b3aaf07
to
8e92f0a
Compare
No description provided.