OPAL (Object Oriented Parallel Accelerator Library) 2024.2
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 OpalParser();
48 virtual ~OpalParser();
49
51 virtual void parse(Statement&) const;
52
54 virtual Statement* readStatement(TokenStream*) const;
55
57 // Read, parse, and execute statements one at a time.
58 virtual void run() const;
59
61 // Switch to given stream, then read, parse, and execute statements
62 // one at a time. Used for CALL statements and macros.
63 virtual void run(TokenStream*) const;
64
66 // Causes [tt]run()[/tt] to return when the next statement should be
67 // read.
68 void stop() const;
69
71 static Token readToken();
72
73protected:
75 void execute(Object*, const std::string&) const;
76
78 virtual Object* find(const std::string&) const;
79
81 virtual void parseAction(Statement&) const;
82
84 virtual void parseAssign(Statement&) const;
85
87 virtual void parseDefine(Statement&) const;
88
90 virtual void parseEnd(Statement&) const;
91
93 virtual void parseMacro(const std::string& name, Statement&) const;
94
96 virtual void printHelp(const std::string&) const;
97
98private:
99 // Not implemented.
101 void operator=(const OpalParser&);
102
103 // Parse a bracketed token list into statement.
104 static void parseBracketList(char close, Statement&);
105
106 // Parse a token list into statement.
107 static void parseTokenList(Statement&);
108
109 // get hint on cause of error
110 static std::string getHint(const std::string&, const std::string& = "attribute");
111
112 // This flag is set by all commands which return from a mode.
113 mutable bool stopFlag;
114
115 // The stack of input streams ("CALL", "MACRO", etc.).
116 static std::vector<Pointer<TokenStream> > inputStack;
117};
118
119#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:113
virtual void parseAssign(Statement &) const
Parse assignment statement.
static Token readToken()
Return next input token.
static void parseTokenList(Statement &)
void operator=(const OpalParser &)
virtual void parseEnd(Statement &) const
Check for end of statement.
virtual void run() const
Read current stream.
virtual Object * find(const std::string &) const
Find object by name in the main directory.
virtual void parseMacro(const std::string &name, Statement &) const
Parse macro definition or call.
static void parseBracketList(char close, Statement &)
static std::vector< Pointer< TokenStream > > inputStack
Definition OpalParser.h:116
virtual Statement * readStatement(TokenStream *) const
Read complete statement from a token stream.
virtual void printHelp(const std::string &) const
Print help on named command.
void execute(Object *, const std::string &) const
Execute or check the current command.
static std::string getHint(const std::string &, const std::string &="attribute")
virtual void parse(Statement &) const
Parse and execute current statement.
void stop() const
Set stop flag.
virtual ~OpalParser()
OpalParser(const OpalParser &)
virtual void parseDefine(Statement &) const
Parse definition.
virtual void parseAction(Statement &) const
Parse executable command.