48 lines
994 B
C
48 lines
994 B
C
#ifndef UNDAR_PARSER_H
|
|
#define UNDAR_PARSER_H
|
|
|
|
#include "common.h"
|
|
#include "lexer.h"
|
|
#include "emit.h"
|
|
|
|
typedef struct scope_s Scope;
|
|
typedef struct parser_s Parser;
|
|
typedef struct parse_rule_s ParseRule;
|
|
|
|
struct scope_s {
|
|
Scope *parent; /* pointer to this scopes parent to "bubble up"*/
|
|
List *symbols; /* list of symbols that live in this scope */
|
|
};
|
|
|
|
typedef enum {
|
|
PREC_NONE,
|
|
PREC_ASSIGNMENT, /* = */
|
|
PREC_OR, /* or */
|
|
PREC_AND, /* and */
|
|
PREC_EQUALITY, /* == != */
|
|
PREC_COMPARISON, /* < > <= >= */
|
|
PREC_TERM, /* + - */
|
|
PREC_FACTOR, /* * / */
|
|
PREC_UNARY, /* ! - */
|
|
PREC_CALL, /* . () */
|
|
PREC_PRIMARY
|
|
} Precedence;
|
|
|
|
typedef void (*ParseFn)();
|
|
|
|
struct parse_rule_s {
|
|
ParseFn prefix;
|
|
ParseFn infix;
|
|
Precedence precedence;
|
|
};
|
|
|
|
struct parser_s {
|
|
Scope *current_scope;
|
|
Token current;
|
|
Token previous;
|
|
};
|
|
|
|
bool compile(Arena *a, Emitter e, char *source);
|
|
|
|
#endif
|