-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSententialForm.C
More file actions
83 lines (56 loc) · 1.44 KB
/
SententialForm.C
File metadata and controls
83 lines (56 loc) · 1.44 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/****************************************************************
SententialForm.C
Copyright (C)2013 William H. Majoros (martiandna@gmail.com).
This is OPEN SOURCE SOFTWARE governed by the Gnu General Public
License (GPL) version 3, as described at www.opensource.org.
****************************************************************/
#include <iostream>
#include "SententialForm.H"
using namespace std;
using namespace BOOM;
SententialForm::SententialForm()
{
// ctor
}
void SententialForm::append(GrammarSymbol *s)
{
V.push_back(s);
}
int SententialForm::length()
{
return V.size();
}
bool SententialForm::isFinal() const
{
for(Vector<GrammarSymbol*>::const_iterator cur=V.begin(), end=V.end() ;
cur!=end ; ++cur)
if((*cur)->isNonterminal()) return false;
return true;
}
void SententialForm::rewrite(int pos,Production *prod)
{
V.cut(pos);
V.insertByIndex(prod->getRHS(),pos);
}
void SententialForm::printOn(ostream &os) const
{
for(Vector<GrammarSymbol*>::const_iterator cur=V.begin(), end=V.end() ;
cur!=end ; ++cur)
os<<(*cur)->getLexeme()<<" ";
}
ostream &operator<<(ostream &os,const SententialForm &f)
{
f.printOn(os);
return os;
}
int SententialForm::leftmostNonterminal() const
{
int L=length();
for(int i=0 ; i<L ; ++i)
if(V[i]->isNonterminal()) return i;
throw String("no nonterminals found in SententialForm");
}
GrammarSymbol *SententialForm::operator[](int i)
{
return V[i];
}