summaryrefslogtreecommitdiff
path: root/src/helper.h
blob: 37cd7fd2d592cfdb9d52edcc2b6407b781c8e7ea (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
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef HELPER_H
#define HELPER_H

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
#include "big_endian.h"

struct SignedVec {
  unsigned char *len;
  unsigned char *capacity;
  char *data;
};

struct UnsignedVec {
  unsigned char *len;
  unsigned char *capacity;
  unsigned char *data;
};

struct parser;

struct parser *new_parser(char *grammar_string,
                          struct SignedVec *error_vec);

void clean_parser(void *parser);

int parser_recognize(struct parser *parser,
                     struct UnsignedVec *input_vec,
                     struct SignedVec *error_vec,
                     unsigned char reset_p);

struct UnsignedVec *
parser_parse
(struct parser *parser,
 struct UnsignedVec *input_vec,
 struct SignedVec *error_vec,
 unsigned char reset_p);

void clean_signed(struct SignedVec *vec, unsigned char flag);
void clean_unsigned(struct UnsignedVec *vec, unsigned char flag);

typedef enum Status {
  Plain = 0,
  Packed = 1,
  Clone = 2,
} Status;

typedef enum Variant {
  Terminal = 0,
  Nonterminal = 1,
  Rule = 2,
} Variant;

struct Label {
  Status status;
  uint64_t clone_index;
  uint64_t start;
  uint64_t end;
  Variant variant;
  uint64_t content;
};

struct Label read_label(unsigned char *ptr);

void print_label(struct Label label);

// TODO: Add functions for verifying the format of the forest.
//
// And add functions to query the number from the terminal name, or
// the non-terminal name.
//
// And add functions for queryinf information from the forest.

// TODO: Declare opaque struct standing for forests, and connect to
// the function for printing labels of forests.
//
// This can be used in debuggers to help us diagnose the situation.

struct CForest;

void print_forest_node(struct CForest *forest, unsigned char *node);

void print_node(struct CForest *forest, uint64_t node);

#endif