summaryrefslogtreecommitdiff
path: root/src/cnp.h
blob: 904e38365054317305521d5e424c2b7453b963ba (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
#ifndef CNP_H
#define CNP_H
#include "str.h"
#include "utf8.h"
#include "bsr.h"
#include "crf.h"

/* We start with implementing some support functions.  These support
   functions are not supposed to be put in the crf.h header file, as
   they are not related to the underlying (static) data structures
   really.  */

typedef struct Environment_s Environment;

/* On error return NULL */
Environment *new_env(Grammar *g, str *string);

HP_ATTR BOOL env_error_p(CCR_MOD(Environment *) env);

P_ATTR bsr *env_bsrp(CCR_MOD(Environment *) env);

P_ATTR Grammar *env_grammar(CCR_MOD(Environment *) env);

HP_ATTR crf *env_crfp(CCR_MOD(Environment *) env);

HP_ATTR procr *env_r(CCR_MOD(Environment *) env);
HP_ATTR procu *env_u(CCR_MOD(Environment *) env);
H_ATTR void env_str(CCR_MOD(Environment *) env,
                    NUM **str, NUM *str_len);

H_ATTR BOOL env_follow_p(CCR_MOD(Environment *) env, NUM X, NUM t);

void env_print_follow(CCR_MOD(Environment *) env, NUM X);

void env_print_first(CCR_MOD(Environment *) env, NUM X);

/* Convenient macro */

#define CHECK_ENV_ERROR(ENV, CLEANUP) do {      \
    if (env_error_p(ENV)) {                     \
      fleprintf0("Error occurs!\n");            \
      { CLEANUP };                              \
    }                                           \
  } while (0)

/* NOTE: Since the grammar pointer just points to the existing grammar
   when we construct it, we shall not destroy the grammar when we
   destroy the environment, so that we can later reuse that grammar,
   should the need arise. */
void destroy_env(Environment *env);

void nt_add(Environment *env, NUM X, NUM j);

BOOL test_select(Environment *env, NUM b, NUM X,
                 CCR_MOD(List *) tnts);

void rtn(Environment *env, NUM X, NUM k, NUM j);

void cnp_call(Environment *env, pair3 label, NUM i, NUM j);

/* On error return NULL */
H_ATTR Environment *cnp_parse(Grammar *g, str *string);

#endif