aboutsummaryrefslogtreecommitdiffstats
path: root/clox/src/compiler.c
diff options
context:
space:
mode:
Diffstat (limited to 'clox/src/compiler.c')
-rw-r--r--clox/src/compiler.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/clox/src/compiler.c b/clox/src/compiler.c
index ab8fe7d..8606557 100644
--- a/clox/src/compiler.c
+++ b/clox/src/compiler.c
@@ -190,6 +190,11 @@ static void number() {
emitConstant(NUMBER_VAL(value));
}
+static void string() {
+ emitConstant(OBJ_VAL(
+ copyString(parser.previous.start + 1, parser.previous.length - 2)));
+}
+
static void unary() {
TokenType operatorType = parser.previous.type;
@@ -235,7 +240,7 @@ ParseRule rules[] = {
[TOKEN_LESS] = {NULL, binary, PREC_COMPARISON},
[TOKEN_LESS_EQUAL] = {NULL, binary, PREC_COMPARISON},
[TOKEN_IDENTIFIER] = {NULL, NULL, PREC_NONE},
- [TOKEN_STRING] = {NULL, NULL, PREC_NONE},
+ [TOKEN_STRING] = {string, NULL, PREC_NONE},
[TOKEN_NUMBER] = {number, NULL, PREC_NONE},
[TOKEN_AND] = {NULL, NULL, PREC_NONE},
[TOKEN_CLASS] = {NULL, NULL, PREC_NONE},