26#include "Utility/PAssert.h"
36 "A \"MACRO\" command defines a subroutine:\n"
37 "\t<name>(<arguments>):MACRO{<body>}"),
41 body = std::make_shared<MacroStream>(name);
57 throw ParseError(
"MacroCmd::makeInstance()",
"Inconsistent number of macro arguments.");
66 while (!token.
isEOF()) {
70 std::string word = token.
getWord();
72 for (std::vector<std::string>::size_type i = 0; i <
formals.size(); i++) {
74 std::vector<Token> act =
actuals[i];
76 macro->
body->append(t);
84 if (!found) macro->
body->append(token);
85 token =
body->readToken();
96 bool isMacro = statement.
keyword(
"MACRO");
103 if (statement.
atEnd()) {
104 throw ParseError(
"MacroCmd::makeTemplate()",
"MACRO body is not closed.");
108 if (token.
isDel(
'{')) {
110 }
else if (token.
isDel(
'}')) {
111 if (--level == 0)
break;
114 macro->
body->append(token);
118 throw ParseError(
"MacroCmd::makeTemplate()",
"Missing MACRO body, should be \"{...}\".");
virtual Object * makeInstance(const std::string &name, Statement &, const Parser *)
Make a macro instance.
virtual Object * makeTemplate(const std::string &, TokenStream &, Statement &)
Make a macro template.
std::shared_ptr< MacroStream > body
virtual void execute()
Execute the macro command.
Abstract base class for macros.
std::vector< std::vector< Token > > actuals
The actual argument list.
virtual void parseFormals(Statement &)
Parse formal arguments.
std::vector< std::string > formals
The formal argument list.
virtual void parseActuals(Statement &)
Parse actual arguments.
The base class for all OPAL objects.
Interface for abstract language parser.
virtual void run(TokenStream *ts) const =0
Read statements and parse.
Interface for statements.
Token & getCurrent()
Return current token and skip it.
bool keyword(const char *s)
Test for keyword.
bool atEnd() const
Test for end of command.
bool delimiter(char c)
Test for delimiter.
Abstract interface for a stream of input tokens.
Representation of a single input token.
bool isDel(char del) const
Test for delimiter.
bool isWord() const
Test for word.
bool isEOF() const
Test for end of file.
std::string getWord() const
Return word value.