OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
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 <memory>
22#include <string>
23#include <vector>
24#include "OpalParser/Parser.h"
25
26class Object;
27class Token;
28class Statement;
29
30// Class OpalParser
31// ------------------------------------------------------------------------
33// The parser reads a command name and keyword and looks up the keyword
34// in the main directory. If it finds an object, it makes a clone with the
35// name read and calls the parser for the cloned object. If that parser
36// succeeds, it calls the clone's execute() function. As required, it
37// first updates the data structure to ensure that everything is up-to-date.
38// Optionally, command execution is also traced.
39//
40// Derived parsers may have their own directory, thus changing the set
41// of recognized commands.
42
43class OpalParser : public Parser {
44public:
45 OpalParser();
46 virtual ~OpalParser();
47
49 virtual void parse(Statement&) const;
50
52 virtual Statement* readStatement(TokenStream*) const;
53
55 // Read, parse, and execute statements one at a time.
56 virtual void run() const;
57
59 // Switch to given stream, then read, parse, and execute statements
60 // one at a time. Used for CALL statements and macros.
61 virtual void run(TokenStream*) const;
62
64 // Causes [tt]run()[/tt] to return when the next statement should be
65 // read.
66 void stop() const;
67
69 static Token readToken();
70
71protected:
73 void execute(Object*, const std::string&) const;
74
76 virtual Object* find(const std::string&) const;
77
79 virtual void parseAction(Statement&) const;
80
82 virtual void parseAssign(Statement&) const;
83
85 virtual void parseDefine(Statement&) const;
86
88 virtual void parseEnd(Statement&) const;
89
91 virtual void parseMacro(const std::string& name, Statement&) const;
92
94 virtual void printHelp(const std::string&) const;
95
96private:
97 // Not implemented.
99 void operator=(const OpalParser&);
100
101 // Parse a bracketed token list into statement.
102 static void parseBracketList(char close, Statement&);
103
104 // Parse a token list into statement.
105 static void parseTokenList(Statement&);
106
107 // get hint on cause of error
108 static std::string getHint(const std::string&, const std::string& = "attribute");
109
110 // This flag is set by all commands which return from a mode.
111 mutable bool stopFlag;
112
113 // The stack of input streams ("CALL", "MACRO", etc.).
114 static std::vector<std::shared_ptr<TokenStream> > inputStack;
115};
116
117#endif // OPAL_OpalParser_HH
The base class for all OPAL objects.
Definition Object.h:45
The default parser for OPAL-9.
Definition OpalParser.h:43
bool stopFlag
Definition OpalParser.h:111
virtual void parseAssign(Statement &) const
Parse assignment statement.
static Token readToken()
Return next input token.
static void parseTokenList(Statement &)
static std::vector< std::shared_ptr< TokenStream > > inputStack
Definition OpalParser.h:114
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 &)
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.
Interface for abstract language parser.
Definition Parser.h:30
Interface for statements.
Definition Statement.h:37
Abstract interface for a stream of input tokens.
Definition TokenStream.h:30
Representation of a single input token.
Definition Token.h:32