aboutsummaryrefslogtreecommitdiff
path: root/src/all.h
blob: c5a983c4f6bc1119f7c9db31cc62dc6ec16d9612 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#pragma once
#include "ivec.h"
#include "node_vec.h"
#include "str.h"
#include <stdbool.h>
#include <stddef.h>

// Lexer

typedef enum {
  LEX_PINC,
  LEX_PDEC,
  LEX_VINC,
  LEX_VDEC,
  LEX_OUT,
  LEX_IN,
  LEX_LB,
  LEX_RB,
  LEX_EOF
} lex_tok_e;

typedef struct {
  str *src;
  size_t pos;
  ivec tokens;
} lexer_t;

lexer_t lex_init(str *src);
void lex_run(lexer_t *lx);
void lex_free(lexer_t *lx);

// Parser/AST

typedef struct ast_node ast_node_t;

typedef enum {
  AST_INC,
  AST_DEC,
  AST_PTR_INC,
  AST_PTR_DEC,
  AST_OUT,
  AST_IN,
  AST_LOOP
} ast_type_e;

struct ast_node {
  ast_type_e type;
  int val;

  node_vec children; // vec<ast_node_t*>
  ast_node_t *next;
};

typedef struct {
  lexer_t *lx;
  size_t pos;
} parser_t;

parser_t parser_init(lexer_t *lx);
ast_node_t *parse_program(parser_t *p);
void ast_free(ast_node_t *node);

// codegen

str gen_code(ast_node_t *ast);