Commit 3e16b077 authored by hrchilds's avatar hrchilds

Update from November 24, 2004

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@369 18c085ea-50e0-402c-830e-de6fd14e8384
parent c1ea3474
......@@ -70,13 +70,17 @@
# I moved winutil into the top level and I moved Exceptions from components
# to here.
#
# Jeremy Meredith, Thu Nov 11 15:47:44 PST 2004
# Refactored the parser into a base directory and a VisIt expression
# language-specific directory.
#
##############################################################################
@SET_MAKE@
@VARIABLES@
@DIRTARGETS@
SUBDIRS=misc Exceptions utility comm state plugin proxybase parser
SUBDIRS=misc Exceptions utility comm state plugin proxybase parser expr
message:
@echo
......
#include "ExprGrammar.h"
#include "ExprToken.h"
//
// VisIt Expression Grammar
//
//
// Written April 5, 2002 by Jeremy Meredith
//
//
// Modifications:
// Jeremy Meredith, Wed Nov 24 11:43:51 PST 2004
// Refactored the parser into a standalone module. This required
// telling some tokens what their display name is instead of
// getting it from a function.
//
// Jeremy Meredith, Wed Nov 24 14:52:41 PST 2004
// Removed Expr => List and added Arg => List because we cannot
// work with lists as expressions just yet. We can change this
// back someday.
//
// ------------------------------------------------------------------------
// TERMINALS
......@@ -22,11 +42,11 @@ Symbol T_Equal ('=');
Symbol T_At ('@');
Symbol T_Comma (',');
Symbol T_Colon (':');
Symbol T_Ident (TT_Identifier);
Symbol T_Integer (TT_IntegerConst);
Symbol T_Float (TT_FloatConst);
Symbol T_String (TT_StringConst);
Symbol T_Bool (TT_BoolConst);
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");
// ------------------------------------------------------------------------
......@@ -79,10 +99,10 @@ ExprGrammar::ExprGrammar() : Grammar()
AddRule(Rule(8, Expr) >> T_LParen + Expr + T_RParen );
AddRule(Rule(9, Expr) >> Constant );
AddRule(Rule(10, Expr) >> Vector );
AddRule(Rule(11, Expr) >> List );
AddRule(Rule(12, Expr) >> Function );
AddRule(Rule(13, Expr) >> Variable );
AddRule(Rule(14, Expr) >> Database );
AddRule(Rule(11, Expr) >> Function );
AddRule(Rule(12, Expr) >> Variable );
AddRule(Rule(13, Expr) >> Database );
//AddRule(Rule(14, Expr) >> List );
// Constant
AddRule(Rule(0, Constant) >> T_Integer );
......@@ -117,6 +137,7 @@ ExprGrammar::ExprGrammar() : Grammar()
// Arg
AddRule(Rule(0, Arg) >> Expr);
AddRule(Rule(1, Arg) >> T_Ident + T_Equal + Expr);
AddRule(Rule(2, Arg) >> List);
// PathSpec
AddRule(Rule(0, PathSpec) >> PathSpec + MultiSlash + T_Ident);
......
#ifndef EXPRGRAMMAR_H
#define EXPRGRAMMAR_H
#include <parser_exports.h>
#include <expr_exports.h>
#include "Grammar.h"
......@@ -13,8 +13,12 @@
// Programmer: Jeremy Meredith
// Creation: April 5, 2002
//
// Modifications:
// Jeremy Meredith, Wed Nov 24 11:45:56 PST 2004
// Refactored the expression-specific stuff to its own library.
//
// ****************************************************************************
class PARSER_API ExprGrammar : public Grammar
class EXPR_API ExprGrammar : public Grammar
{
public:
ExprGrammar();
......@@ -54,22 +58,22 @@ extern Symbol T_Bool;
// ------------------------------------------------------------------------
// NON-TERMINALS
// ------------------------------------------------------------------------
extern PARSER_API Symbol Expr;
extern PARSER_API Symbol Constant;
extern PARSER_API Symbol Vector;
extern PARSER_API Symbol List;
extern PARSER_API Symbol ListElems;
extern PARSER_API Symbol ListElem;
extern PARSER_API Symbol Function;
extern PARSER_API Symbol Args;
extern PARSER_API Symbol Arg;
extern PARSER_API Symbol PathSpec;
extern PARSER_API Symbol MultiSlash;
extern PARSER_API Symbol Variable;
extern PARSER_API Symbol Database;
extern PARSER_API Symbol DBSpec;
extern PARSER_API Symbol PathMachSpec;
extern PARSER_API Symbol MachSpec;
extern PARSER_API Symbol TimeSpec;
extern EXPR_API Symbol Expr;
extern EXPR_API Symbol Constant;
extern EXPR_API Symbol Vector;
extern EXPR_API Symbol List;
extern EXPR_API Symbol ListElems;
extern EXPR_API Symbol ListElem;
extern EXPR_API Symbol Function;
extern EXPR_API Symbol Args;
extern EXPR_API Symbol Arg;
extern EXPR_API Symbol PathSpec;
extern EXPR_API Symbol MultiSlash;
extern EXPR_API Symbol Variable;
extern EXPR_API Symbol Database;
extern EXPR_API Symbol DBSpec;
extern EXPR_API Symbol PathMachSpec;
extern EXPR_API Symbol MachSpec;
extern EXPR_API Symbol TimeSpec;
#endif
#include <stdio.h>
#include <ExprNode.h>
#include <Token.h>
#include <ExprToken.h>
#include <DebugStream.h>
#include <ExpressionException.h>
#include <snprintf.h>
using std::vector;
// Jeremy Meredith, Wed Nov 24 11:46:43 PST 2004
// Made expression language specific tokens have a more specific
// base class. Renamed GrammarNode to ParseTreeNode.
//
// class ConstExpr
ConstExpr::ConstExpr(const Pos &p, Token *t) : ExprNode(p)
ConstExpr::ConstExpr(const Pos &p, ExprToken *t) : ExprNode(p)
{
token = t;
}
......@@ -114,7 +120,7 @@ ListElemExpr::PrintNode(ostream &o)
}
// class ListExpr
ListExpr::ListExpr(const Pos &p, ListElemExpr *e) : ExprGrammarNode(p)
ListExpr::ListExpr(const Pos &p, ListElemExpr *e) : ExprParseTreeNode(p)
{
elems = new vector<ListElemExpr*>;
elems->push_back(e);
......@@ -159,7 +165,7 @@ ArgExpr::PrintNode(ostream &o)
}
// class ArgsExpr
ArgsExpr::ArgsExpr(const Pos &p, ArgExpr *e) : ExprGrammarNode(p)
ArgsExpr::ArgsExpr(const Pos &p, ArgExpr *e) : ExprParseTreeNode(p)
{
args = new vector<ArgExpr*>;
args->push_back(e);
......
#ifndef EXPRNODE_H
#define EXPRNODE_H
#include <parser_exports.h>
#include <expr_exports.h>
#include <vector>
#include <set>
#include <string>
#include <ExprGrammarNode.h>
#include <ExprParseTreeNode.h>
#include <ExprToken.h>
class Identifier;
class Token;
class Pos;
// ****************************************************************************
// Class: ExprNode
// Class: ExprNode and other Expression Grammar parse tree nodes
//
// Purpose:
// Base class for all nodes in VisIt expression trees.
// ExprNode is the base class for all nodes in an Expression tree
// that are themselves expressions. Other things like paths and
// function arguments are not directly Expressions, but can contain
// them -- these derive directly from ExprParseTreeNode.
//
// Programmer: Jeremy Meredith
// Creation: April 5, 2002
//
// Modifications:
// Sean Ahern, Wed Apr 17 17:01:41 PDT 2002
// Made the class able to contact the engine to generate plots.
// Sean Ahern, Wed Apr 17 17:01:41 PDT 2002
// Made the class able to contact the engine to generate plots.
//
// Sean Ahern, Wed Oct 16 16:41:32 PDT 2002
// Removed the engine communication code to a separate set of classes
// owned by the viewer.
// Sean Ahern, Wed Oct 16 16:41:32 PDT 2002
// Removed the engine communication code to a separate set of classes
// owned by the viewer.
//
// Jeremy Meredith, Wed Nov 24 11:47:45 PST 2004
// Made expression language specific tokens have a more specific
// base class. Renamed GrammarNode to ParseTreeNode. Refactored
// expression specific stuff to its own library. Had ArgExpr contain
// the true base class for expressions -- a List is a valid argument
// to a function but currently is not an Expression (i.e. ExprNode).
//
// ****************************************************************************
class PARSER_API ExprNode : public ExprGrammarNode
class EXPR_API ExprNode : public ExprParseTreeNode
{
public:
ExprNode(const Pos &p)
: ExprGrammarNode(p) {}
: ExprParseTreeNode(p) {}
virtual ~ExprNode() { }
virtual std::set<std::string> GetVarLeaves() = 0;
virtual const std::string GetTypeName() = 0;
};
class PARSER_API ConstExpr : public virtual ExprNode
class EXPR_API ConstExpr : public virtual ExprNode
{
public:
ConstExpr(const Pos &p, Token *t);
ConstExpr(const Pos &p, ExprToken *t);
virtual ~ConstExpr() { }
virtual void PrintNode(ostream &o);
virtual std::set<std::string> GetVarLeaves() {return std::set<std::string>();}
virtual const std::string GetTypeName() { return "Const"; }
Token * GetToken() { return token; }
ExprToken * GetToken() { return token; }
protected:
Token *token;
ExprToken *token;
};
class PARSER_API MathExpr : public virtual ExprNode
class EXPR_API MathExpr : public virtual ExprNode
{
public:
MathExpr(const Pos &p, char o)
......@@ -64,7 +73,7 @@ class PARSER_API MathExpr : public virtual ExprNode
char op;
};
class PARSER_API UnaryExpr : public MathExpr
class EXPR_API UnaryExpr : public MathExpr
{
public:
UnaryExpr(const Pos &p, char o, ExprNode *e)
......@@ -78,7 +87,7 @@ class PARSER_API UnaryExpr : public MathExpr
ExprNode *expr;
};
class PARSER_API BinaryExpr : public MathExpr
class EXPR_API BinaryExpr : public MathExpr
{
public:
BinaryExpr(const Pos &p, char o, ExprNode *l, ExprNode *r)
......@@ -92,7 +101,7 @@ class PARSER_API BinaryExpr : public MathExpr
ExprNode *right;
};
class PARSER_API IndexExpr : public virtual ExprNode
class EXPR_API IndexExpr : public virtual ExprNode
{
public:
IndexExpr(const Pos &p, ExprNode *e, int i)
......@@ -107,7 +116,7 @@ class PARSER_API IndexExpr : public virtual ExprNode
int ind;
};
class PARSER_API VectorExpr : public virtual ExprNode
class EXPR_API VectorExpr : public virtual ExprNode
{
public:
VectorExpr(const Pos &p, ExprNode *xi, ExprNode *yi, ExprNode *zi=NULL)
......@@ -120,11 +129,11 @@ class PARSER_API VectorExpr : public virtual ExprNode
ExprNode *x, *y, *z;
};
class PARSER_API ListElemExpr : public ExprGrammarNode
class EXPR_API ListElemExpr : public ExprParseTreeNode
{
public:
ListElemExpr(const Pos &p, ExprNode *b, ExprNode *e=NULL, ExprNode *s=NULL)
: ExprGrammarNode(p), beg(b), end(e), skip(s) {}
: ExprParseTreeNode(p), beg(b), end(e), skip(s) {}
virtual ~ListElemExpr() { }
virtual void PrintNode(ostream &o);
virtual const std::string GetTypeName() { return "ListElem"; }
......@@ -138,7 +147,7 @@ class PARSER_API ListElemExpr : public ExprGrammarNode
ExprNode *skip;
};
class PARSER_API ListExpr : public ExprGrammarNode
class EXPR_API ListExpr : public ExprParseTreeNode
{
public:
ListExpr(const Pos &p, ListElemExpr *e);
......@@ -152,24 +161,24 @@ class PARSER_API ListExpr : public ExprGrammarNode
std::vector<ListElemExpr*> *elems;
};
class PARSER_API ArgExpr : public ExprGrammarNode
class EXPR_API ArgExpr : public ExprParseTreeNode
{
public:
ArgExpr(const Pos &p, ExprNode *e)
: ExprGrammarNode(p), id(NULL), expr(e) {}
ArgExpr(const Pos &p, ExprParseTreeNode *e)
: ExprParseTreeNode(p), id(NULL), expr(e) {}
virtual ~ArgExpr() { }
ArgExpr(const Pos &p, Identifier *i, ExprNode *e)
: ExprGrammarNode(p), id(i), expr(e) {}
ArgExpr(const Pos &p, Identifier *i, ExprParseTreeNode *e)
: ExprParseTreeNode(p), id(i), expr(e) {}
virtual void PrintNode(ostream &o);
Identifier *GetId(void) {return id;};
ExprNode *GetExpr(void) {return expr;};
ExprParseTreeNode *GetExpr(void) {return expr;};
virtual const std::string GetTypeName() { return "Arg"; }
protected:
Identifier *id;
ExprNode *expr;
ExprParseTreeNode *expr;
};
class PARSER_API ArgsExpr : public ExprGrammarNode
class EXPR_API ArgsExpr : public ExprParseTreeNode
{
public:
ArgsExpr(const Pos &p, ArgExpr *e);
......@@ -182,7 +191,7 @@ class PARSER_API ArgsExpr : public ExprGrammarNode
std::vector<ArgExpr*> *args;
};
class PARSER_API FunctionExpr : public virtual ExprNode
class EXPR_API FunctionExpr : public virtual ExprNode
{
public:
FunctionExpr(const Pos &p, Identifier *i, ArgsExpr *e=NULL)
......@@ -196,11 +205,11 @@ class PARSER_API FunctionExpr : public virtual ExprNode
ArgsExpr *args;
};
class PARSER_API PathExpr : public ExprGrammarNode
class EXPR_API PathExpr : public ExprParseTreeNode
{
public:
PathExpr(const Pos &p, const std::string &s)
: ExprGrammarNode(p), basename(s), fullpath(s) {}
: ExprParseTreeNode(p), basename(s), fullpath(s) {}
virtual ~PathExpr() { }
void Append(const std::string&);
virtual void PrintNode(ostream &o);
......@@ -214,11 +223,11 @@ class PARSER_API PathExpr : public ExprGrammarNode
std::string fullpath;
};
class PARSER_API MachExpr : public ExprGrammarNode
class EXPR_API MachExpr : public ExprParseTreeNode
{
public:
MachExpr(const Pos &p, Identifier *i)
: ExprGrammarNode(p), host(i) {}
: ExprParseTreeNode(p), host(i) {}
virtual ~MachExpr() { }
virtual void PrintNode(ostream &o);
virtual const std::string GetTypeName() { return "Mach"; }
......@@ -226,12 +235,12 @@ class PARSER_API MachExpr : public ExprGrammarNode
Identifier *host;
};
class PARSER_API TimeExpr : public ExprGrammarNode
class EXPR_API TimeExpr : public ExprParseTreeNode
{
public:
enum Type { Cycle, Time, Index, Unknown };
TimeExpr(const Pos &p, ListExpr *l, Type t=Unknown)
: ExprGrammarNode(p), type(t), list(l) {}
: ExprParseTreeNode(p), type(t), list(l) {}
virtual ~TimeExpr() { }
virtual void PrintNode(ostream &o);
virtual const std::string GetTypeName() { return "Time"; }
......@@ -240,11 +249,11 @@ class PARSER_API TimeExpr : public ExprGrammarNode
ListExpr *list;
};
class PARSER_API DBExpr : public ExprGrammarNode
class EXPR_API DBExpr : public ExprParseTreeNode
{
public:
DBExpr(const Pos &p, PathExpr *f, MachExpr *m, TimeExpr *t)
: ExprGrammarNode(p), file(f), mach(m), time(t) {}
: ExprParseTreeNode(p), file(f), mach(m), time(t) {}
virtual ~DBExpr() { }
virtual void PrintNode(ostream &o);
virtual const std::string GetTypeName() { return "DBExpr"; }
......@@ -254,7 +263,7 @@ class PARSER_API DBExpr : public ExprGrammarNode
TimeExpr *time;
};
class PARSER_API VarExpr : public virtual ExprNode
class EXPR_API VarExpr : public virtual ExprNode
{
public:
VarExpr(const Pos &p, DBExpr *d, PathExpr *v, bool exp)
......@@ -269,4 +278,5 @@ class PARSER_API VarExpr : public virtual ExprNode
bool canexpand;
};
#endif
#ifndef EXPRNODEFACTORY_H
#define EXPRNODEFACTORY_H
#include <parser_exports.h>
#include <expr_exports.h>
#include <ExprNode.h>
#include <Pos.h>
class Token;
class PARSER_API ExprNodeFactory
// Modifications:
// Jeremy Meredith, Wed Nov 24 12:22:32 PST 2004
// Expression-language specific tokens are in a new,
// more specific base class.
//
class EXPR_API ExprNodeFactory
{
public:
ExprNodeFactory() {}
virtual ~ExprNodeFactory() {}
virtual ConstExpr*
CreateConstExpr(const Pos & p, Token * t)
CreateConstExpr(const Pos & p, ExprToken * t)
{ return new ConstExpr(p, t); }
virtual UnaryExpr*
......
// ************************************************************************* //
// ExprParseTreeNode.C //
// ************************************************************************* //
#include <ExprParseTreeNode.h>
// ************************************************************************* //
// ExprGrammarNode.h //
// ExprParseTreeNode.h //
// ************************************************************************* //
#ifndef EXPRGRAMMARNODE_H
#define EXPRGRAMMARNODE_H
#ifndef EXPRPARSETREENODE_H
#define EXPRPARSETREENODE_H
#include <parser_exports.h>
#include <expr_exports.h>
#include <vector>
#include <Pos.h>
#include <set>
#include <ParseTreeNode.h>
class Identifier;
class Token;
// ****************************************************************************
// Class: ExprGrammarNode
// Class: ExprParseTreeNode
//
// Purpose:
// Base class for all grammar nodes in VisIt expression trees.
......@@ -28,21 +30,18 @@ class Token;
// Hank Childs, Thu Aug 14 08:21:14 PDT 2003
// Un-inlined Print method, since it contained statics.
//
// Jeremy Meredith, Thu Nov 11 12:35:11 PST 2004
// Refactored the non-expression related things to another class.
//
// ****************************************************************************
class PARSER_API ExprGrammarNode
class EXPR_API ExprParseTreeNode : public ParseTreeNode
{
public:
ExprGrammarNode(const Pos &p) : pos(p) { }
virtual ~ExprGrammarNode() { }
const Pos &GetPos() const {return pos;}
Pos &GetPos() {return pos;}
virtual const std::string GetTypeName() {return "ExprGrammarNode";}
ExprParseTreeNode(const Pos &p) : ParseTreeNode(p) { }
virtual ~ExprParseTreeNode() { }
virtual const std::string GetTypeName() {return "ExprParseTreeNode";}
virtual std::set<std::string> GetVarLeaves()
{return std::set<std::string>();}
virtual void Print(ostream &o, std::string s="");
virtual void PrintNode(ostream &o) = 0;
protected:
Pos pos;
};
#endif
......@@ -16,10 +16,10 @@ using std::vector;
ExprParser::ErrorMessageTarget ExprParser::errorMessageTarget = EMT_EXCEPTION;
class DummyNode : public ExprGrammarNode
class DummyNode : public ExprParseTreeNode
{
public:
DummyNode(const Pos &p) : ExprGrammarNode(p) { }
DummyNode(const Pos &p) : ExprParseTreeNode(p) { }
virtual void PrintNode(ostream &o) { o << "DummyNode\n"; }
};
......@@ -30,7 +30,7 @@ class DummyNode : public ExprGrammarNode
// Creation: April 5, 2002
//
// ****************************************************************************
ExprParser::ExprParser(ExprNodeFactory *f) : ParserBase(), factory(f)
ExprParser::ExprParser(ExprNodeFactory *f) : Parser(), factory(f)
{
Grammar *G = new ExprGrammar;
if (!G->Initialize())
......@@ -54,11 +54,14 @@ ExprParser::ExprParser(ExprNodeFactory *f) : ParserBase(), factory(f)
// Arguments:
// sym the LHS of the rule
// rule the rule to apply
// E an array of ExprGrammarNodes as long as the length of the rule's RHS
// E an array of ExprParseTreeNodes as long as the length
// of the rule's RHS
// T an array of Tokens as long as the length of the rule's RHS
// note that many of these may be NULL
// p the position encompassing the sequence in the expression
//
// Note:
// All ExprGrammarNodes must be downcasted here. One must be careful that they
// All ExprParseTreeNodes must be downcasted here. One must be careful that they
// create the right types of nodes for what they are expecting in later
// reductions.
//
......@@ -66,81 +69,87 @@ ExprParser::ExprParser(ExprNodeFactory *f) : ParserBase(), factory(f)
// Creation: April 5, 2002
//
// Modifications:
// Sean Ahern, Wed Oct 16 14:11:22 PDT 2002
// Changed to use an ExprNodeFactory.
// Sean Ahern, Wed Oct 16 14:11:22 PDT 2002
// Changed to use an ExprNodeFactory.
//
// Jeremy Meredith, Mon Jul 28 16:03:49 PDT 2003
// Added more info to the error message in the TimeSpec.
//
// Jeremy Meredith, Tue Nov 23 14:51:51 PST 2004
// Refactored. Removed the dynamic cast.
//
// Jeremy Meredith, Wed Nov 24 15:36:34 PST 2004
// Removed Expr => List and added Arg => Expr. Lists are not
// derived from ExprNode in the chain, and this seems more correct
// since no filter can yet support expressions anyway. We can
// change it back later if we ever support it.
//
// ****************************************************************************
ExprGrammarNode*