OPAL (Object Oriented Parallel Accelerator Library) 2022.1
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
26class Object;
27class Token;
28class 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
44class OpalParser: public Parser {
45
46public:
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
74protected:
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
100private:
101
102 // Not implemented.
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
const std::string name
The base class for all OPAL objects.
Definition: Object.h:48
Interface for abstract language parser.
Definition: Parser.h:31
Interface for statements.
Definition: Statement.h:38
Representation of a single input token.
Definition: Token.h:33
Abstract interface for a stream of input tokens.
Definition: TokenStream.h:33
The default parser for OPAL-9.
Definition: OpalParser.h:44
bool stopFlag
Definition: OpalParser.h:116
virtual void parseAssign(Statement &) const
Parse assignment statement.
Definition: OpalParser.cpp:192
static Token readToken()
Return next input token.
Definition: OpalParser.cpp:499
static void parseTokenList(Statement &)
Definition: OpalParser.cpp:478
void operator=(const OpalParser &)
virtual void parseEnd(Statement &) const
Check for end of statement.
Definition: OpalParser.cpp:373
virtual void run() const
Read current stream.
Definition: OpalParser.cpp:602
virtual Object * find(const std::string &) const
Find object by name in the main directory.
Definition: OpalParser.cpp:151
virtual void parseMacro(const std::string &name, Statement &) const
Parse macro definition or call.
Definition: OpalParser.cpp:389
static void parseBracketList(char close, Statement &)
Definition: OpalParser.cpp:457
static std::vector< Pointer< TokenStream > > inputStack
Definition: OpalParser.h:119
virtual Statement * readStatement(TokenStream *) const
Read complete statement from a token stream.
Definition: OpalParser.cpp:508
virtual void printHelp(const std::string &) const
Print help on named command.
Definition: OpalParser.cpp:445
void execute(Object *, const std::string &) const
Execute or check the current command.
Definition: OpalParser.cpp:126
static std::string getHint(const std::string &, const std::string &="attribute")
Definition: OpalParser.cpp:642
virtual void parse(Statement &) const
Parse and execute current statement.
Definition: OpalParser.cpp:66
void stop() const
Set stop flag.
Definition: OpalParser.cpp:638
virtual ~OpalParser()
Definition: OpalParser.cpp:62
OpalParser(const OpalParser &)
virtual void parseDefine(Statement &) const
Parse definition.
Definition: OpalParser.cpp:326
virtual void parseAction(Statement &) const
Parse executable command.
Definition: OpalParser.cpp:156