31 "A \"MACRO\" command defines a subroutine:\n"
32 "\t<name>(<arguments>):MACRO{<body>}"),
38 Macro(name, parent), body() {
55 parseActuals(statement);
58 if(formals.size() != actuals.size()) {
60 "Inconsistent number of macro arguments.");
67 Token token = body->readToken();
69 while(! token.
isEOF()) {
73 std::string word = token.
getWord();
75 for(std::vector<std::string>::size_type i = 0;
76 i < formals.size(); i++) {
77 if(word == formals[i]) {
78 std::vector<Token> act = actuals[i];
89 token = body->readToken();
102 assert(statement.
keyword(
"MACRO"));
108 if(statement.
atEnd()) {
110 "MACRO body is not closed.");
114 if(token.isDel(
'{')) {
116 }
else if(token.isDel(
'}')) {
117 if(--level == 0)
break;
125 "Missing MACRO body, should be \"{...}\".");
bool isEOF() const
Test for end of file.
bool keyword(const char *s)
Test for keyword.
virtual void run(TokenStream *ts) const =0
Read statements and parse.
Abstract interface for a stream of input tokens.
bool isWord() const
Test for word.
bool atEnd() const
Test for end of command.
virtual void execute()
Execute the macro command.
Interface for abstract language parser.
virtual void parseFormals(Statement &)
Parse formal arguments.
Encapsulate the buffer for the ``archetypes'' of all macros.
Interface for statements.
Representation of a single input token.
void start()
Reset stream to start.
void append(Token &)
Append a token to the stream.
virtual Object * makeTemplate(const std::string &, TokenStream &, Statement &)
Make a macro template.
An input buffer for macro commands.
Abstract base class for macros.
Pointer< MacroStream > body
The base class for all OPAL objects.
virtual Object * makeInstance(const std::string &name, Statement &, const Parser *)
Make a macro instance.
Token & getCurrent()
Return current token and skip it.
bool delimiter(char c)
Test for delimiter.
std::string getWord() const
Return word value.