101 lines
2.1 KiB
C
101 lines
2.1 KiB
C
#ifndef DATA_H_PARSER
|
|
#define DATA_H_PARSER
|
|
|
|
#include "define.h"
|
|
#include <ctype.h>
|
|
#include <stdbool.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
// Token types for lexical analysis
|
|
|
|
typedef enum {
|
|
TOKEN_COMMA, // ,
|
|
TOKEN_PERCENT, // %
|
|
TOKEN_LPAREN, // (
|
|
TOKEN_RPAREN, // )
|
|
TOKEN_SYMBOL, // identifiers/function names
|
|
TOKEN_STRING, // "quoted strings"
|
|
TOKEN_NUMBER, // integers and floats
|
|
TOKEN_BOOLEAN, // true false
|
|
TOKEN_NEWLINE, // \n (statement separator)
|
|
TOKEN_EOF,
|
|
TOKEN_ERROR
|
|
} token_type_t;
|
|
|
|
typedef struct {
|
|
token_type_t type;
|
|
char value[MAX_TOKEN_LENGTH];
|
|
int line;
|
|
int column;
|
|
} token_t;
|
|
|
|
// AST node types
|
|
typedef enum {
|
|
NODE_SYMBOL,
|
|
NODE_STRING,
|
|
NODE_NUMBER,
|
|
NODE_BOOLEAN,
|
|
NODE_FUNCTION_REF, // %function-name
|
|
NODE_FUNCTION_CALL // ,function-name()
|
|
} node_type_t;
|
|
|
|
typedef struct node {
|
|
node_type_t type;
|
|
union {
|
|
char symbol[MAX_SYMBOL_LENGTH];
|
|
char string[MAX_STRING_LENGTH];
|
|
double number;
|
|
bool boolean;
|
|
char function_ref[MAX_SYMBOL_LENGTH];
|
|
struct {
|
|
char function_name[MAX_SYMBOL_LENGTH];
|
|
struct node *args[MAX_ARGS];
|
|
int arg_count;
|
|
} call;
|
|
} data;
|
|
} node_t;
|
|
|
|
// Lexer state
|
|
typedef struct {
|
|
const char *input;
|
|
int pos;
|
|
int line;
|
|
int column;
|
|
char current_char;
|
|
} lexer_t;
|
|
|
|
// Configuration storage
|
|
typedef struct key_mapping {
|
|
char *key_combo;
|
|
char *function_name;
|
|
struct key_mapping *next;
|
|
} key_mapping_t;
|
|
|
|
typedef struct config_var {
|
|
char *name;
|
|
node_t *value;
|
|
struct config_var *next;
|
|
} config_var_t;
|
|
|
|
typedef struct {
|
|
key_mapping_t *key_mappings;
|
|
config_var_t *variables;
|
|
} config_t;
|
|
|
|
void advance_char(lexer_t *lexer);
|
|
void skip_whitespace(lexer_t *lexer);
|
|
void skip_comment(lexer_t *lexer);
|
|
node_t *create_node(node_type_t type);
|
|
node_t *create_symbol_node(const char *symbol);
|
|
node_t *create_string_node(const char *string);
|
|
node_t *create_number_node(double number);
|
|
node_t *create_boolean_node(bool value);
|
|
node_t *create_function_ref_node(const char *function_name);
|
|
node_t *create_function_call_node(const char *function_name);
|
|
|
|
void add_arg_to_call(node_t *call, node_t *args);
|
|
|
|
#endif
|