61 lines
1.2 KiB
C
61 lines
1.2 KiB
C
#ifndef UNDAR_PARSER_H
|
|
#define UNDAR_PARSER_H
|
|
|
|
#include "libc.h"
|
|
#include "list.h"
|
|
#include "lexer.h"
|
|
|
|
typedef enum symbol_type_e {
|
|
VOID,
|
|
BOOL,
|
|
BYTE,
|
|
INT,
|
|
NAT,
|
|
REAL,
|
|
STR,
|
|
U8,
|
|
I8,
|
|
I16,
|
|
U16,
|
|
I32,
|
|
U32,
|
|
F32,
|
|
ARRAY,
|
|
FUNCTION,
|
|
PLEX,
|
|
METHOD,
|
|
TRAIT,
|
|
CONST,
|
|
} SymbolType;
|
|
|
|
typedef struct symbol_s Symbol;
|
|
typedef struct scope_s Scope;
|
|
typedef struct parser_s Parser;
|
|
|
|
#define MAX_SYMBOL_NAME_LENGTH 64
|
|
struct symbol_s {
|
|
char name[MAX_SYMBOL_NAME_LENGTH]; /* ptr to name */
|
|
u8 name_length; /* length of the name, max 64 */
|
|
SymbolType type; /* the type for this symbol */
|
|
SymbolType secondary_type; /* return type for functions/methods, or const if type/plex */
|
|
u32 ref; /* either constant value or pointer to other thing */
|
|
u32 size; /* either size of the plex or length of the array/list/etc. */
|
|
List *args; /* function params or plex constructor args */
|
|
List *fields; /* either plex variable fields, or method signatures */
|
|
};
|
|
|
|
struct scope_s {
|
|
Scope *parent; /* pointer to this scopes parent to "bubble up"*/
|
|
List *symbols; /* list of symbols that live in this scope */
|
|
};
|
|
|
|
struct parser_s {
|
|
Scope *current_scope;
|
|
Token current;
|
|
Token previous;
|
|
};
|
|
|
|
bool compile(char *source);
|
|
|
|
#endif
|