]> git.lizzy.rs Git - plan9front.git/blob - regimpl.h
8c8ac03a71ffa6029122343eb2c1234bb6c332d6
[plan9front.git] / regimpl.h
1 enum {
2         LANY = 0,
3         LBOL,
4         LCLASS,
5         LEND,
6         LEOL,
7         LLPAR,
8         LOR,
9         LREP,
10         LRPAR,
11         LRUNE,
12
13         TANY = 0,
14         TBOL,
15         TCAT,
16         TCLASS,
17         TEOL,
18         TNOTNL,
19         TOR,
20         TPLUS,
21         TQUES,
22         TRUNE,
23         TSTAR,
24         TSUB,
25
26         NSUBEXPM = 32,
27 };
28
29 typedef struct Parselex Parselex;
30 typedef struct Renode Renode;
31
32 struct Parselex {
33         /* Parse */
34         Renode *next, *nodes;
35         int sub, instrs;
36         jmp_buf exitenv;
37         /* Lex */
38         void (*getnextr)(Parselex*);
39         char *rawexp, *orig;
40         Rune rune;
41         int peek, peeklex, done, literal, nc;
42         Rune cpairs[400+2];
43 };
44
45 struct Renode {
46         int op;
47         Renode *left;
48         Rune r;
49         union {
50                 Rune r1;
51                 int sub;
52                 Renode *right;
53         };
54         int nclass;
55 };
56
57 struct Rethread {
58         Reinst *i;
59         Resub sem[NSUBEXPM];
60         Rethread *next;
61         int gen;
62 };
63
64 struct Reinst {
65         char op;
66         int gen;
67         Reinst *a;
68         union {
69                 Rune r;
70                 int sub;
71         };
72         union {
73                 Rune r1;
74                 Reinst *b;
75         };
76 };
77
78 static int lex(Parselex*);
79 static void getnextr(Parselex*);
80 static void getnextrlit(Parselex*);
81 static void getclass(Parselex*);
82 static Renode *e0(Parselex*);
83 static Renode *e1(Parselex*);
84 static Renode *e2(Parselex*);
85 static Renode *e3(Parselex*);
86 static Renode *buildclass(Parselex*);
87 static Renode *buildclassn(Parselex*);
88 static int pcmp(void*, void*);
89 static Reprog *regcomp1(char*, int, int);
90 static Reinst *compile(Renode*, Reprog*, int);
91 static Reinst *compile1(Renode*, Reinst*, int*, int);
92 static void prtree(Renode*, int, int);