aboutsummaryrefslogtreecommitdiff
path: root/parts/grammar.h
blob: d1bf1764b971c9cc75c937a2b705075e95095c91 (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
36
#ifndef GRAMMAR_H
#define GRAMMAR_H

#include <stddef.h> // size_t

extern struct production {
    symbol LHS;
    symbol *RHS;
    size_t nRHS;
} *grammar;

extern size_t total_productions;

#include <stdio.h>

void grammar_print()
{
    for(size_t i = 0; i < total_productions; i++) {
        printf("%d --> ", grammar[i].LHS);
        for(size_t j = 0; j < grammar[i].nRHS; j++)
            printf("%d ", grammar[i].RHS[j]);
        printf("\n");
    }
}
void grammar_print_cstyle()

{
    for(size_t i = 0; i < total_productions; i++) {
        printf("{%d, (symbol[]){", grammar[i].LHS);
        for(size_t j = 0; j < grammar[i].nRHS; j++)
            printf("%d, ", grammar[i].RHS[j]);
        printf("}, %zu},\n", grammar[i].nRHS);
    }
}

#endif