52 lines
1.1 KiB
C
52 lines
1.1 KiB
C
#include "parser.h"
|
|
|
|
bool push(TokenStack *ts, Token t) {
|
|
if (ts->count >= ts->capacity) return false;
|
|
ts->stack[ts->count++] = t;
|
|
return true;
|
|
}
|
|
|
|
Token pop(TokenStack *ts) {
|
|
if (ts->count == 0) return (Token){TOKEN_ERROR, nil, -1, -1};
|
|
return ts->stack[--ts->count];
|
|
}
|
|
|
|
Token top(TokenStack *ts) {
|
|
if (ts->count == 0) return (Token){TOKEN_ERROR, nil, -1, -1};
|
|
return ts->stack[ts->count - 1];
|
|
}
|
|
|
|
bool enqueue(TokenQueue *tq, Token t) {
|
|
if (tq->count >= tq->capacity) return false;
|
|
|
|
tq->queue[tq->end] = t;
|
|
tq->end = (tq->end + 1) % tq->capacity; // Wrap around
|
|
tq->count++;
|
|
return true;
|
|
}
|
|
|
|
Token dequeue(TokenQueue *tq) {
|
|
if (tq->count == 0) return (Token){TOKEN_ERROR, NULL, -1, -1};
|
|
|
|
Token t = tq->queue[tq->start];
|
|
tq->start = (tq->start + 1) % tq->capacity; // Wrap around
|
|
tq->count--;
|
|
return t;
|
|
}
|
|
|
|
Token peek_queue(TokenQueue *tq) {
|
|
if (tq->count == 0) return (Token){TOKEN_ERROR, NULL, -1, -1};
|
|
return tq->queue[tq->start];
|
|
}
|
|
|
|
bool expression() {
|
|
|
|
}
|
|
|
|
bool compile(char *source) {
|
|
TokenStack operators;
|
|
TokenQueue output;
|
|
|
|
return true;
|
|
}
|