Evaluating Expressions 7
This commit is contained in:
parent
d937226553
commit
f4338ba51f
6 changed files with 182 additions and 63 deletions
|
|
@ -5,7 +5,7 @@ import std.conv;
|
|||
|
||||
import jlox.token;
|
||||
import jlox.tokentype;
|
||||
import jlox.main : error, report;
|
||||
import jlox.main;
|
||||
|
||||
private bool isAlpha_(dchar c) => c.isAlpha || c == '_';
|
||||
private bool isAlphaNum_(dchar c) => c.isAlphaNum || c == '_';
|
||||
|
|
@ -30,7 +30,7 @@ class Scanner {
|
|||
current++;
|
||||
return true;
|
||||
}
|
||||
private void addToken(TokenType type, TTokenValue literal = TTokenValue.nil(0)){
|
||||
private void addToken(TokenType type, TValue literal = TValue.nil(0)){
|
||||
string text = source[start .. current];
|
||||
tokens ~= new Token(type, text, literal, line);
|
||||
}
|
||||
|
|
@ -49,12 +49,12 @@ class Scanner {
|
|||
advance();
|
||||
}
|
||||
if(isAtEnd){
|
||||
error(line, "Unterminated string.");
|
||||
Lox.error(line, "Unterminated string.");
|
||||
return;
|
||||
}
|
||||
advance();
|
||||
string value = source[start + 1 .. current -1];
|
||||
addToken(TokenType.STRING, TTokenValue.str(value));
|
||||
addToken(TokenType.STRING, TValue.str(value));
|
||||
}
|
||||
private void number(){
|
||||
while(peek().isDigit)
|
||||
|
|
@ -64,7 +64,7 @@ class Scanner {
|
|||
while(peek().isDigit)
|
||||
advance();
|
||||
}
|
||||
addToken(TokenType.NUMBER, TTokenValue.dbl(source[start .. current].to!double));
|
||||
addToken(TokenType.NUMBER, TValue.dbl(source[start .. current].to!double));
|
||||
}
|
||||
private TokenType keywords(string word){
|
||||
with(TokenType) switch(word){
|
||||
|
|
@ -142,7 +142,7 @@ class Scanner {
|
|||
identifier();
|
||||
break;
|
||||
default:
|
||||
error(line, "Unexpected character");
|
||||
Lox.error(line, "Unexpected character");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue