OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
OpalParser.h
Go to the documentation of this file.
1 #ifndef OPAL_OpalParser_HH
2 #define OPAL_OpalParser_HH
3 
4 // ------------------------------------------------------------------------
5 // $RCSfile: OpalParser.h,v $
6 // ------------------------------------------------------------------------
7 // $Revision: 1.1.1.1 $
8 // ------------------------------------------------------------------------
9 // Copyright: see Copyright.readme
10 // ------------------------------------------------------------------------
11 //
12 // Class OpalParser:
13 //
14 // ------------------------------------------------------------------------
15 //
16 // $Date: 2000/03/27 09:33:43 $
17 // $Author: Andreas Adelmann $
18 //
19 // ------------------------------------------------------------------------
20 
21 #include "Parser/Parser.h"
23 #include <string>
24 #include <vector>
25 
26 class Object;
27 class Token;
28 class Statement;
29 
30 
31 // Class OpalParser
32 // ------------------------------------------------------------------------
34 // The parser reads a command name and keyword and looks up the keyword
35 // in the main directory. If it finds an object, it makes a clone with the
36 // name read and calls the parser for the cloned object. If that parser
37 // succeeds, it calls the clone's execute() function. As required, it
38 // first updates the data structure to ensure that everything is up-to-date.
39 // Optionally, command execution is also traced.
40 //
41 // Derived parsers may have their own directory, thus changing the set
42 // of recognized commands.
43 
44 class OpalParser: public Parser {
45 
46 public:
47 
48  OpalParser();
49  virtual ~OpalParser();
50 
52  virtual void parse(Statement &) const;
53 
55  virtual Statement *readStatement(TokenStream *) const;
56 
58  // Read, parse, and execute statements one at a time.
59  virtual void run() const;
60 
62  // Switch to given stream, then read, parse, and execute statements
63  // one at a time. Used for CALL statements and macros.
64  virtual void run(TokenStream *) const;
65 
67  // Causes [tt]run()[/tt] to return when the next statement should be
68  // read.
69  void stop() const;
70 
72  static Token readToken();
73 
74 protected:
75 
77  void execute(Object *, const std::string &) const;
78 
80  virtual Object *find(const std::string &) const;
81 
83  virtual void parseAction(Statement &) const;
84 
86  virtual void parseAssign(Statement &) const;
87 
89  virtual void parseDefine(Statement &) const;
90 
92  virtual void parseEnd(Statement &) const;
93 
95  virtual void parseMacro(const std::string &name, Statement &) const;
96 
98  virtual void printHelp(const std::string &) const;
99 
100 private:
101 
102  // Not implemented.
103  OpalParser(const OpalParser &);
104  void operator=(const OpalParser &);
105 
106  // Parse a bracketed token list into statement.
107  static void parseBracketList(char close, Statement &);
108 
109  // Parse a token list into statement.
110  static void parseTokenList(Statement &);
111 
112  // get hint on cause of error
113  static std::string getHint(const std::string &, const std::string & = "attribute");
114 
115  // This flag is set by all commands which return from a mode.
116  mutable bool stopFlag;
117 
118  // The stack of input streams ("CALL", "MACRO", etc.).
119  static std::vector<Pointer<TokenStream> > inputStack;
120 };
121 
122 #endif // OPAL_OpalParser_HH
void execute(Object *, const std::string &) const
Execute or check the current command.
Definition: OpalParser.cpp:125
Abstract interface for a stream of input tokens.
Definition: TokenStream.h:33
bool stopFlag
Definition: OpalParser.h:116
virtual void parseMacro(const std::string &name, Statement &) const
Parse macro definition or call.
Definition: OpalParser.cpp:388
static void parseTokenList(Statement &)
Definition: OpalParser.cpp:477
The default parser for OPAL-9.
Definition: OpalParser.h:44
void stop() const
Set stop flag.
Definition: OpalParser.cpp:637
Interface for abstract language parser.
Definition: Parser.h:31
static std::vector< Pointer< TokenStream > > inputStack
Definition: OpalParser.h:119
static std::string getHint(const std::string &, const std::string &="attribute")
Definition: OpalParser.cpp:641
Interface for statements.
Definition: Statement.h:38
virtual Statement * readStatement(TokenStream *) const
Read complete statement from a token stream.
Definition: OpalParser.cpp:507
Representation of a single input token.
Definition: Token.h:33
virtual ~OpalParser()
Definition: OpalParser.cpp:61
virtual void parseAssign(Statement &) const
Parse assignment statement.
Definition: OpalParser.cpp:191
static Token readToken()
Return next input token.
Definition: OpalParser.cpp:498
static void parseBracketList(char close, Statement &)
Definition: OpalParser.cpp:456
virtual void run() const
Read current stream.
Definition: OpalParser.cpp:601
virtual void parseAction(Statement &) const
Parse executable command.
Definition: OpalParser.cpp:155
virtual void printHelp(const std::string &) const
Print help on named command.
Definition: OpalParser.cpp:444
The base class for all OPAL objects.
Definition: Object.h:48
virtual void parseEnd(Statement &) const
Check for end of statement.
Definition: OpalParser.cpp:372
const std::string name
virtual void parseDefine(Statement &) const
Parse definition.
Definition: OpalParser.cpp:325
void operator=(const OpalParser &)
virtual void parse(Statement &) const
Parse and execute current statement.
Definition: OpalParser.cpp:65
virtual Object * find(const std::string &) const
Find object by name in the main directory.
Definition: OpalParser.cpp:150