Files
clox/scanner.c
T

55 lines
987 B
C

#include "scanner.h"
#include <string.h>
const char* source_code;
//Start and Current hold the offsets that index into the string source_code.
int start; //Points to the first character in the lexeme being scanned.
int current; //points to the character currently being considered.
int length;
int line = 1;
char Advance(void);
int IsAtend(void);
void ScanToken(void);
void ScanTokens(const char* source) {
if (!source) return;
source_code = source;
length = strlen(source);
if (length == 0) return;
while(!IsAtend()) {
start = current;
ScanToken();
}
//Add EOF token and return list once that's set up.
}
void ScanToken() {
char c = Advance();
switch (c) {
case '(':
case ')':
case '{':
case '}':
case ',':
case '.':
case '-':
case '+':
case ';':
case '*':
break;
}
}
int IsAtEnd() {
return current >= length;
}
char Advance() {
return source_code[current++];
}