1/*
2** $Id: lptree.h,v 1.3 2016/09/13 18:07:51 roberto Exp $
3*/
4
5#if !defined(lptree_h)
6#define lptree_h
7
8
9#include "lptypes.h"
10
11
12/*
13** types of trees
14*/
15typedef enum TTag {
16 TChar = 0, /* 'n' = char */
17 TSet, /* the set is stored in next CHARSETSIZE bytes */
18 TAny,
19 TTrue,
20 TFalse,
21 TRep, /* 'sib1'* */
22 TSeq, /* 'sib1' 'sib2' */
23 TChoice, /* 'sib1' / 'sib2' */
24 TNot, /* !'sib1' */
25 TAnd, /* &'sib1' */
26 TCall, /* ktable[key] is rule's key; 'sib2' is rule being called */
27 TOpenCall, /* ktable[key] is rule's key */
28 TRule, /* ktable[key] is rule's key (but key == 0 for unused rules);
29 'sib1' is rule's pattern;
30 'sib2' is next rule; 'cap' is rule's sequential number */
31 TGrammar, /* 'sib1' is initial (and first) rule */
32 TBehind, /* 'sib1' is pattern, 'n' is how much to go back */
33 TCapture, /* captures: 'cap' is kind of capture (enum 'CapKind');
34 ktable[key] is Lua value associated with capture;
35 'sib1' is capture body */
36 TRunTime /* run-time capture: 'key' is Lua function;
37 'sib1' is capture body */
38} TTag;
39
40
41/*
42** Tree trees
43** The first child of a tree (if there is one) is immediately after
44** the tree. A reference to a second child (ps) is its position
45** relative to the position of the tree itself.
46*/
47typedef struct TTree {
48 byte tag;
49 byte cap; /* kind of capture (if it is a capture) */
50 unsigned short key; /* key in ktable for Lua data (0 if no key) */
51 union {
52 int ps; /* occasional second child */
53 int n; /* occasional counter */
54 } u;
55} TTree;
56
57
58/*
59** A complete pattern has its tree plus, if already compiled,
60** its corresponding code
61*/
62typedef struct Pattern {
63 union Instruction *code;
64 int codesize;
65 TTree tree[1];
66} Pattern;
67
68
69/* number of children for each tree */
70extern const byte numsiblings[];
71
72/* access to children */
73#define sib1(t) ((t) + 1)
74#define sib2(t) ((t) + (t)->u.ps)
75
76
77
78
79
80
81#endif
82
83