forked from rperlste/UniversalCompiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGrammar.h
39 lines (31 loc) · 927 Bytes
/
Grammar.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
#ifndef _Grammar
#define _Grammar
#include <list>
#include "CompilerExceptions.h"
#include "GrammarSet.h"
#include "LookAheadSet.h"
#include "MarkedVocabulary.h"
#include "Production.h"
static const Symbol _LAMBDA = "";
struct Grammar {
Productions productions;
GrammarSet nonterminalSet;
GrammarSet terminalSet;
MarkedVocabulary derivesLambda;
LookAheadSet <Symbol> firstSet;
LookAheadSet <Symbol> followSet;
LookAheadSet <Production> predictSet;
// Search through follow sets.
// If follow set is empty, then it is
// the only non-derivable nonterminal.
std::string getStartSymbol(){
for( LookAheadSet<Symbol>::size_type i = 0;
i < followSet.size();
i ++ ){
if( followSet.getValueByIndex(i).size() == 0 )
return followSet.getKeyByIndex(i);
}
throw GrammarException( "Start symbol not found." );
}
};
#endif