Commit d612512a authored by hrchilds's avatar hrchilds

Update from June 8, 2005

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@481 18c085ea-50e0-402c-830e-de6fd14e8384
parent 0736d4bb
......@@ -19,56 +19,61 @@
// work with lists as expressions just yet. We can change this
// back someday.
//
// Jeremy Meredith, Wed Jun 8 17:04:23 PDT 2005
// Made symbols all be associated with a dictionary.
//
Dictionary D;
// ------------------------------------------------------------------------
// TERMINALS
// ------------------------------------------------------------------------
Symbol T_Plus ('+');
Symbol T_Mult ('*');
Symbol T_Minus ('-');
Symbol T_Slash ('/');
Symbol T_Exp ('^');
Symbol T_Mod ('%');
Symbol T_LBracket ('[');
Symbol T_RBracket (']');
Symbol T_LParen ('(');
Symbol T_RParen (')');
Symbol T_LCarat ('<');
Symbol T_RCarat ('>');
Symbol T_LBrace ('{');
Symbol T_RBrace ('}');
Symbol T_Pound ('#');
Symbol T_Equal ('=');
Symbol T_At ('@');
Symbol T_Comma (',');
Symbol T_Colon (':');
Symbol T_Ident (TT_Identifier, "Identifier");
Symbol T_Integer (TT_IntegerConst, "Integer");
Symbol T_Float (TT_FloatConst, "Float");
Symbol T_String (TT_StringConst, "String");
Symbol T_Bool (TT_BoolConst, "Bool");
Symbol T_Plus (D, '+');
Symbol T_Mult (D, '*');
Symbol T_Minus (D, '-');
Symbol T_Slash (D, '/');
Symbol T_Exp (D, '^');
Symbol T_Mod (D, '%');
Symbol T_LBracket (D, '[');
Symbol T_RBracket (D, ']');
Symbol T_LParen (D, '(');
Symbol T_RParen (D, ')');
Symbol T_LCarat (D, '<');
Symbol T_RCarat (D, '>');
Symbol T_LBrace (D, '{');
Symbol T_RBrace (D, '}');
Symbol T_Pound (D, '#');
Symbol T_Equal (D, '=');
Symbol T_At (D, '@');
Symbol T_Comma (D, ',');
Symbol T_Colon (D, ':');
Symbol T_Ident (D, TT_Identifier, "Identifier");
Symbol T_Integer (D, TT_IntegerConst, "Integer");
Symbol T_Float (D, TT_FloatConst, "Float");
Symbol T_String (D, TT_StringConst, "String");
Symbol T_Bool (D, TT_BoolConst, "Bool");
// ------------------------------------------------------------------------
// NON-TERMINALS
// ------------------------------------------------------------------------
Symbol Expr ( "Expr" );
Symbol Constant ( "Constant" );
Symbol Vector ( "Vector" );
Symbol List ( "List" );
Symbol ListElems ( "ListElems" );
Symbol ListElem ( "ListElem" );
Symbol Function ( "Function" );
Symbol Args ( "Args" );
Symbol Arg ( "Arg" );
Symbol PathSpec ( "PathSpec" );
Symbol MultiSlash ( "MultiSlash" );
Symbol Variable ( "Variable" );
Symbol Database ( "Database" );
Symbol DBSpec ( "DBSpec" );
Symbol PathMachSpec ( "PathMachSpec" );
Symbol MachSpec ( "MachSpec" );
Symbol TimeSpec ( "TimeSpec" );
Symbol Expr (D, "Expr" );
Symbol Constant (D, "Constant" );
Symbol Vector (D, "Vector" );
Symbol List (D, "List" );
Symbol ListElems (D, "ListElems" );
Symbol ListElem (D, "ListElem" );
Symbol Function (D, "Function" );
Symbol Args (D, "Args" );
Symbol Arg (D, "Arg" );
Symbol PathSpec (D, "PathSpec" );
Symbol MultiSlash (D, "MultiSlash" );
Symbol Variable (D, "Variable" );
Symbol Database (D, "Database" );
Symbol DBSpec (D, "DBSpec" );
Symbol PathMachSpec (D, "PathMachSpec" );
Symbol MachSpec (D, "MachSpec" );
Symbol TimeSpec (D, "TimeSpec" );
// ****************************************************************************
......@@ -78,7 +83,7 @@ Symbol TimeSpec ( "TimeSpec" );
// Creation: April 5, 2002
//
// ****************************************************************************
ExprGrammar::ExprGrammar() : Grammar()
ExprGrammar::ExprGrammar() : Grammar(D)
{
// ----------------------------------------------------------------------
......
This diff is collapsed.
......@@ -90,8 +90,9 @@ clean:
##
## Intermediate targets...
##
.NO_CONFIG_REC: $(INITSRC)
.NO_WINK_IN: $(INITSRC)
.NO_DO_FOR_SIBLING: $(INITSRC)
.NO_CONFIG_REC: $(INITSRC)
.NO_WINK_IN: $(INITSRC)
$(INITSRC):
./$(CONFIGPROG) $(INITSRC)
......@@ -99,13 +100,13 @@ init: $(CONFIGPROG)
env LD_LIBRARY_PATH=../../lib:${LD_LIBRARY_PATH} ./$(CONFIGPROG) $(INITSRC)
$(CONFIGPROG): $(COMMONOBJ) $(CONFIGOBJ)
$(CXX) -o $@ $(LDFLAGS) $(COMMONOBJ) $(CONFIGOBJ) -lparser $(LIBS)
$(CXX) -o $@ $(LDFLAGS) $(COMMONOBJ) $(CONFIGOBJ) -lparser $(LIBS) @PTHREAD_LIB@
##
## Test targets...
##
$(TESTPROG1) test: $(INITOBJ) $(TESTOBJ1) $(LIBSHARED)
$(CXX) -o $(TESTPROG1) $(LDFLAGS) -lexpr -lparser $(TESTOBJ1) $(LIBS)
$(CXX) -o $(TESTPROG1) $(LDFLAGS) -lexpr -lparser $(TESTOBJ1) $(LIBS) @PTHREAD_LIB@
##
......
#include "Dictionary.h"
#include "Symbol.h"
// ****************************************************************************
// Constructor: Dictionary::Dictionary
//
// Arguments:
// none
//
// Programmer: Jeremy Meredith
// Creation: June 8, 2005
//
// ****************************************************************************
Dictionary::Dictionary()
{
nsymbols = 0;
}
// ****************************************************************************
// Method: Dictionary::AddTerminal
//
// Purpose:
// Adds a terminal symbol to the dictionary.
//
// Arguments:
// s the symbol
//
// Programmer: Jeremy Meredith
// Creation: June 8, 2005
//
// ****************************************************************************
int
Dictionary::AddTerminal(Symbol *s)
{
int index = nsymbols++;
if (nsymbols > MAXSYMBOLS)
{
cerr << "Too many symbols! Increase MAXSYMBOLS" << endl;
exit(-1);
}
allterminals[s->GetTerminalType()] = s;
return index;
}
// ****************************************************************************
// Method: Dictionary::AddNonTerminal
//
// Purpose:
// Adds a nonterminal symbol to the dictionary.
//
// Arguments:
// s the symbol
//
// Programmer: Jeremy Meredith
// Creation: June 8, 2005
//
// ****************************************************************************
int
Dictionary::AddNonTerminal(Symbol *s)
{
int index = nsymbols++;
if (nsymbols > MAXSYMBOLS)
{
cerr << "Too many symbols! Increase MAXSYMBOLS" << endl;
exit(-1);
}
allnonterminals[s->GetDisplayString()] = s;
return index;
}
// ****************************************************************************
// Method: Dictionary::Get
//
// Purpose:
// Finds a terminal by the token type.
//
// Programmer: Jeremy Meredith
// Creation: June 8, 2005
//
// ****************************************************************************
Symbol*
Dictionary::Get(int tt)
{
return allterminals[tt];
}
// ****************************************************************************
// Method: Dictionary::Get
//
// Purpose:
// Finds a nonterminal by its name.
//
// Programmer: Jeremy Meredith
// Creation: June 8, 2005
//
// ****************************************************************************
Symbol*
Dictionary::Get(const std::string &s)
{
return allnonterminals[s];
}
#ifndef DICTIONARY_H
#define DICTIONARY_H
#include <parser_exports.h>
#include <vector>
#include <string>
#include <map>
class Symbol;
// ****************************************************************************
// Class: Dictionary
//
// Purpose:
// Used to keep track of all the symbols in a grammar.
//
// Programmer: Jeremy Meredith
// Creation: June 8, 2005
//
// ****************************************************************************
class PARSER_API Dictionary
{
public:
Dictionary();
Symbol *Get(int tt);
Symbol *Get(const std::string &s);
int AddTerminal(Symbol *s);
int AddNonTerminal(Symbol *s);
private:
std::map<int,Symbol*> allterminals;
std::map<std::string,Symbol*> allnonterminals;
int nsymbols;
};
#endif
......@@ -9,17 +9,21 @@ using std::set;
using std::string;
using std::vector;
Symbol Grammar::eof(EOF_TOKEN_ID); // TT_EOF==256 for all grammars
Symbol Grammar::start("START");
// ****************************************************************************
// Constructor: Grammar::Grammar
//
// Programmer: Jeremy Meredith
// Creation: April 5, 2002
//
// Modifications:
// Jeremy Meredith, Wed Jun 8 17:05:56 PDT 2005
// Added a symbol dictionary.
//
// ****************************************************************************
Grammar::Grammar()
Grammar::Grammar(Dictionary &d)
: dictionary(d),
eof(dictionary, EOF_TOKEN_ID), // TT_EOF==256 for all grammars
start(dictionary, "START")
{
out = NULL;
rules.push_back(NULL);
......@@ -196,6 +200,22 @@ Grammar::GetRule(int i)
return rules[i];
}
// ****************************************************************************
// Method: Grammar::GetDictionary
//
// Purpose:
// Returns the symbol dictionary.
//
// Programmer: Jeremy Meredith
// Creation: June 8, 2005
//
// ****************************************************************************
Dictionary&
Grammar::GetDictionary()
{
return dictionary;
}
// ****************************************************************************
// Method: Grammar::Configure
//
......@@ -363,6 +383,9 @@ Grammar::Configure()
// Brad Whitlock, Fri Jun 28 15:12:49 PST 2002
// Made it work on Windows.
//
// Jeremy Meredith, Wed Jun 8 17:06:40 PDT 2005
// Added a symbol dictionary to remove static data.
//
// ****************************************************************************
void
......@@ -390,7 +413,7 @@ Grammar::WriteStateInitialization(const string &name, ostream &o)
for (i=0; i<states.size(); i++)
{
o << "static void InitState_"<<i<<"(State &s)" << endl;
o << "static void InitState_"<<i<<"(Dictionary &d, State &s)" << endl;
o << "{" << endl;
// Write out the shift state symbol map
......@@ -407,7 +430,7 @@ Grammar::WriteStateInitialization(const string &name, ostream &o)
int tt = s->GetTerminalType();
o << " SetShiftState(s,"<<str<<", Symbol::Get(";
o << " SetShiftState(s,"<<str<<", d.Get(";
if (s->IsNonTerminal())
o << "\"" << s->GetDisplayString() << "\"";
else
......@@ -448,7 +471,7 @@ Grammar::WriteStateInitialization(const string &name, ostream &o)
int tt = s->GetTerminalType();
o << " SetReduceRule(s,"<<str<<", Symbol::Get(";
o << " SetReduceRule(s,"<<str<<", d.Get(";
if (s->IsNonTerminal())
o << "\"" << s->GetDisplayString() << "\"";
else
......@@ -468,7 +491,7 @@ Grammar::WriteStateInitialization(const string &name, ostream &o)
o << endl;
for (i=0; i<states.size(); i++)
{
o << " InitState_"<<i<<"(states[" << i << "]);" << endl;
o << " InitState_"<<i<<"(dictionary, states[" << i << "]);" << endl;
}
o << endl;
o << " return true;" << endl;
......
......@@ -6,6 +6,7 @@
#include "Rule.h"
#include "ConfiguratingSet.h"
#include "State.h"
#include "Dictionary.h"
// ****************************************************************************
// Class: Grammar
......@@ -22,13 +23,17 @@
// Programmer: Jeremy Meredith
// Creation: April 5, 2002
//
// Modifications:
// Jeremy Meredith, Wed Jun 8 17:07:55 PDT 2005
// Added a symbol dictionary.
//
// ****************************************************************************
class PARSER_API Grammar
{
public:
enum Associativity { Left, Right, NonAssoc };
Grammar();
Grammar(Dictionary&);
virtual ~Grammar();
void Print(ostream&);
......@@ -41,6 +46,7 @@ class PARSER_API Grammar
bool Configure();
virtual bool Initialize() = 0;
Dictionary &GetDictionary();
const Symbol *GetStartSymbol();
const Rule *GetRule(int i);
State &GetState(int i);
......@@ -50,10 +56,11 @@ class PARSER_API Grammar
void WriteStateInitialization(const std::string&, ostream&);
protected:
Dictionary &dictionary;
ostream *out;
static Symbol eof;
static Symbol start;
Symbol eof;
Symbol start;
Rule startrule;
std::vector<const Rule*> rules;
......
......@@ -59,6 +59,9 @@
# Brad Whitlock, Tue Jan 4 14:23:16 PST 2005
# Added Scanner.C
#
# Jeremy Meredith, Wed Jun 8 11:27:24 PDT 2005
# Added Dictionary.
#
##############################################################################
##
......@@ -78,6 +81,7 @@ TESTSRC1=testparser.C
COMMONSRC = \
ConfiguratingItem.C \
ConfiguratingSet.C \
Dictionary.C \
Grammar.C \
ParseTreeNode.C \
Parser.C \
......@@ -111,7 +115,7 @@ clean:
## Test targets...
##
$(TESTPROG1) test: $(TESTOBJ1) $(LIBSHARED)
$(CXX) -o $(TESTPROG1) $(LDFLAGS) -lparser $(TESTOBJ1) @LIBS@
$(CXX) -o $(TESTPROG1) $(LDFLAGS) -lparser $(TESTOBJ1) -lmisc @LIBS@
##
......
......@@ -55,6 +55,10 @@ Parser::Init()
// Programmer: Jeremy Meredith
// Creation: April 5, 2002
//
// Modifications:
// Jeremy Meredith, Wed Jun 8 17:08:35 PDT 2005
// Added a symbol dictionary.
//
// ****************************************************************************
void
Parser::Shift(Token *t, int s)
......@@ -62,7 +66,7 @@ Parser::Shift(Token *t, int s)
#ifdef MOREDEBUG
cerr << "Shifting token "; t->PrintNode(cerr); cerr << endl;
#endif
elems.push_back(ParseElem(t));
elems.push_back(ParseElem(G->GetDictionary().Get(t->GetType()), t));
states.push_back(s);
PrintState(cerr);
......@@ -183,11 +187,14 @@ Parser::PrintState(ostream &o)
// Hank Childs, Fri Jan 28 13:19:33 PST 2005
// Use exception macros.
//
// Jeremy Meredith, Wed Jun 8 17:08:35 PDT 2005
// Added a symbol dictionary.
//
// ****************************************************************************
void
Parser::ParseOneToken(Token *t)
{
const Symbol *tokensym = Symbol::Get(t->GetType());
const Symbol *tokensym = G->GetDictionary().Get(t->GetType());
#ifdef MOREDEBUG
if (!tokensym)
{
......
......@@ -3,7 +3,8 @@
using std::vector;
static const char dotchar = 183;
//static const char dotchar = 183;
static const char dotchar = 'o';
static std::string dot = std::string() + TermBold + TermGreen + dotchar + TermReset;
......
#include "Symbol.h"
#include "Dictionary.h"
#include "Rule.h"
#include "Token.h"
using std::vector;
using std::string;
using std::map;
map<int,Symbol*> *Symbol::allterminals = NULL;
map<string,Symbol*> *Symbol::allnonterminals = NULL;
int Symbol::nsymbols = 0;
// ****************************************************************************
// Constructor: Symbol::Symbol
//
......@@ -19,14 +15,15 @@ int Symbol::nsymbols = 0;
// Programmer: Jeremy Meredith
// Creation: April 5, 2002
//
// Modifications:
// Jeremy Meredith, Wed Jun 8 17:08:35 PDT 2005
// All symbols are now added to a dictionary instead of static members.
//
// ****************************************************************************
Symbol::Symbol(int tt)
Symbol::Symbol(Dictionary &dict, int tt)
: type(Terminal), terminaltype(tt), displaystring(GetTokenTypeString(tt))
{
InitStatic();
if (nsymbols>=MAXSYMBOLS) { cerr << "Too many symbols! Increase MAXSYMBOLS\n"; exit(-1); }
index=nsymbols++;
(*allterminals)[tt] = this;
index = dict.AddTerminal(this);
}
// ****************************************************************************
......@@ -39,14 +36,15 @@ Symbol::Symbol(int tt)
// Programmer: Jeremy Meredith
// Creation: November 24, 2004
//
// Modifications:
// Jeremy Meredith, Wed Jun 8 17:08:35 PDT 2005
// All symbols are now added to a dictionary instead of static members.
//
// ****************************************************************************
Symbol::Symbol(int tt, const string &s)
Symbol::Symbol(Dictionary &dict, int tt, const string &s)
: type(Terminal), terminaltype(tt), displaystring(s)
{
InitStatic();
if (nsymbols>=MAXSYMBOLS) { cerr << "Too many symbols! Increase MAXSYMBOLS\n"; exit(-1); }
index=nsymbols++;
(*allterminals)[tt] = this;
index = dict.AddTerminal(this);
}
// ****************************************************************************
......@@ -58,46 +56,15 @@ Symbol::Symbol(int tt, const string &s)
// Programmer: Jeremy Meredith
// Creation: April 5, 2002
//
// ****************************************************************************
Symbol::Symbol(const string &s)
: type(NonTerminal), terminaltype(0), displaystring(s)
{
InitStatic();
if (nsymbols>=MAXSYMBOLS) { cerr << "Too many symbols! Increase MAXSYMBOLS\n"; exit(-1); }
index=nsymbols++;
(*allnonterminals)[s] = this;
}
// ****************************************************************************
// Method: Symbol::Get
//
// Purpose:
// Finds a terminal by the token type.
//
// Programmer: Jeremy Meredith
// Creation: April 5, 2002
//
// ****************************************************************************
Symbol*
Symbol::Get(int tt)
{
return (*allterminals)[tt];
}
// ****************************************************************************
// Method: Symbol::Get
//
// Purpose:
// Finds a nonterminal by its name.
//
// Programmer: Jeremy Meredith
// Creation: April 5, 2002
// Modifications:
// Jeremy Meredith, Wed Jun 8 17:08:35 PDT 2005
// All symbols are now added to a dictionary instead of static members.
//
// ****************************************************************************
Symbol*
Symbol::Get(const string &s)
Symbol::Symbol(Dictionary &dict, const string &s)
: type(NonTerminal), terminaltype(0), displaystring(s)
{
return (*allnonterminals)[s];
index = dict.AddNonTerminal(this);
}
// ****************************************************************************
......@@ -116,27 +83,6 @@ Symbol::operator==(const Symbol &rhs) const
return displaystring == rhs.displaystring;
}
// ****************************************************************************
// Method: Symbol::InitStatic
//
// Purpose:
// Inits all the static data if it hasn't been done yet.
//
// Programmer: Jeremy Meredith