comparison anagram/agcore/mrule.h @ 0:13d2b8934445

Import AnaGram (near-)release tree into Mercurial.
author David A. Holland
date Sat, 22 Dec 2007 17:52:45 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:13d2b8934445
1 /*
2 * AnaGram, A System for Syntax Directed Programming
3 * Copyright 1993-2002 Parsifal Software. All Rights Reserved.
4 * See the file COPYING for license and usage terms.
5 *
6 * mrule.h - marked rules
7 */
8
9 #ifndef MRULE_H
10 #define MRULE_H
11
12 #include "rule.h"
13
14 class MarkedRule {
15 public:
16 Rule rule;
17 int index;
18
19 MarkedRule() : rule(0), index(0) {}
20 MarkedRule(const Rule &r, int x) : rule(r), index(x) {}
21 MarkedRule(const Rule &r) : rule(r), index(r->length()) {}
22
23 int operator < (const MarkedRule &r) const {
24 if ((int) rule < (int) r.rule) return 1;
25 if ((int) r.rule < (int) rule) return 0;
26 return index < r.index;
27 }
28
29 Token leftToken() { return rule.token(index - 1); }
30 Token rightToken() { return rule.token(index); }
31 int positionLeft() { return index == 0; }
32 int positionRight() { return (unsigned) index == rule->length(); }
33 MarkedRule nextLeft() { return MarkedRule(rule, index - 1); }
34 MarkedRule nextRight() { return MarkedRule(rule, index + 1); }
35 };
36
37
38 #endif /* MRULE_H */