Browse Source

Switched to c89

remotes/origin/HEAD
Seth Stubbs 6 months ago
parent
commit
ea934aa55a
  1. 2
      Makefile
  2. 7
      src/ulex.c
  3. 10
      src/uparse.c

2
Makefile

@ -1,5 +1,5 @@
CC=clang
CFLAGS=-fPIE -Wall -O3 -Isrc -std=c99
CFLAGS=-fPIE -Wall -O3 -Isrc -std=c89
LDFLAGS=-lm #-fsanitize=address
OUT=bin/uxncle

7
src/ulex.c

@ -14,7 +14,7 @@ UReservedWord reservedWords[] = {
};
void UL_initLexState(ULexState *state, const char *src) {
state->current = src;
state->current = (char*)src;
state->line = 1;
state->last = TOKEN_ERR;
}
@ -25,7 +25,7 @@ UToken makeToken(ULexState *state, UTokenType type) {
token.len = state->current - state->start;
token.type = type;
// update the state's last token type
/* update the state's last token type */
state->last = type;
return token;
}
@ -79,10 +79,11 @@ void skipWhitespace(ULexState *state) {
}
UTokenType identifierType(ULexState *state) {
int i;
int len = state->start - state->current;
/* walk through each reserved word and compare it */
for (int i = 0; i < sizeof(reservedWords)/sizeof(UReservedWord); i++) {
for (i = 0; i < sizeof(reservedWords)/sizeof(UReservedWord); i++) {
if (reservedWords[i].len == len && memcmp(state->start, reservedWords[i].word, len))
return reservedWords[i].type;
}

10
src/uparse.c

@ -3,11 +3,11 @@
typedef enum {
PREC_NONE,
PREC_ASSIGNMENT, // =
PREC_TERM, // + -
PREC_FACTOR, // * /
PREC_LITERAL, // literal values
PREC_PRIMARY // everything else
PREC_ASSIGNMENT, /* = */
PREC_TERM, /* + - */
PREC_FACTOR, /* * / */
PREC_LITERAL, /* literal values */
PREC_PRIMARY /* everything else */
} Precedence;
typedef UASTNode* (*ParseFunc)(UParseState *state, UASTNode *left, Precedence currPrec);

Loading…
Cancel
Save