aboutsummaryrefslogtreecommitdiff
path: root/demos/sample-files/lalr-defs.c
blob: 61476611638bb60a3443715c87a2a5438a850a61 (plain)
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
#include <stdio.h>
#include <stddef.h>

#include "parts/symbol.h"
enum symbol {
    ID, EQUAL, STAR,
    END_INPUT,
    EP, E, L, R,
    SYMBOLS_END,
};

size_t total_symbols = SYMBOLS_END;

IMPLEMENT_FUNCPTR(int, symbol_is_terminal, (symbol s)) { return s < EP; }
IMPLEMENT_FUNCPTR(int, symbol_is_input_end, (symbol s)) { return s == END_INPUT; }
IMPLEMENT_FUNCPTR(int, symbol_is_valid, (symbol s)) { return s < SYMBOLS_END; }

#include "parts/grammar.h"
#define PROD(LHS, _, ...) {LHS, (symbol[]){__VA_ARGS__}, sizeof((symbol[]){__VA_ARGS__})/sizeof(symbol)}
static struct production _grammar[] = {
    PROD(EP, ->, E, END_INPUT),
    PROD(E, -->, L, EQUAL, R),
    PROD(E, -->, R),
    PROD(L, -->, STAR, R),
    PROD(L, -->, ID),
    PROD(R, -->, L),
};

struct production *grammar = _grammar;
size_t total_productions = sizeof(_grammar)/sizeof(*_grammar);

// #include "???.h"
char **semantic_action_str = (char *([])){
    "", "", "", "", "", "",
};