runningwater 2 年之前
父节点
当前提交
ef4fcef197
共有 2 个文件被更改,包括 4 次插入2 次删除
  1. 2 0
      compiler.c
  2. 2 2
      scanner.c

+ 2 - 0
compiler.c

@@ -130,10 +130,12 @@ static void grouping() {
   consume(TOKEN_RIGHT_PAREN, "Expect ')' after expression.");
 }
 /// \brief parse number token
+/// Number literals: 123
 static void number() {
   double value = strtod(parser.previous.start, NULL);
   emitConstant(value);
 }
+/// Unary negation: -123
 static void unary() {
   TokenType operatorType = parser.previous.type;
 

+ 2 - 2
scanner.c

@@ -57,7 +57,7 @@ static Token makeToken(TokenType type) {
   token.type = type;
   token.start = scanner.start;
   token.length = (int) (scanner.current - scanner.start);
-  token.length = scanner.line;
+  token.line = scanner.line;
   return token;
 }
 static Token errorToken(const char *message) {
@@ -65,7 +65,7 @@ static Token errorToken(const char *message) {
   token.type = TOKEN_ERROR;
   token.start = message;
   token.length = (int) strlen(message);
-  token.length = scanner.line;
+  token.line = scanner.line;
   return token;
 }