forked from rperlste/UniversalCompiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLookAheadSet.h
44 lines (37 loc) · 1.13 KB
/
LookAheadSet.h
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
#ifndef _LookAheadSet
#define _LookAheadSet
#include "Production.h"
#include "GrammarSet.h"
#include "IndexedMap.h"
#include <map>
#include <list>
template< typename Key >
class LookAheadSet : public IndexedMap< Key, GrammarSet >{
public:
// Return true if change occurred, false if none occurred
bool setUnion( const Key& key, const Symbol& grammar );
bool setUnion( const Key& key, const GrammarSet& grammarSet );
};
// Return true if change occurred, false if none occurred
template< typename Key >
bool LookAheadSet<Key>::setUnion( const Key& key, const Symbol& grammar ){
GrammarSet tempGrammarSet;
tempGrammarSet.insert( grammar );
iterator it = this->find( key );
if( it == this->end() ){
return this->insert( key, tempGrammarSet );
} else {
return it->second.setUnion( tempGrammarSet );
}
}
// Return true if change occurred, false if none occurred
template< typename Key >
bool LookAheadSet<Key>::setUnion( const Key& key, const GrammarSet& grammarSet ){
iterator it = this->find( key );
if( it == this->end() ){
return this->insert( key, grammarSet );
} else {
return it->second.setUnion( grammarSet );
}
}
#endif