36 "A \"MACRO\" command defines a subroutine:\n"
37 "\t<name>(<arguments>):MACRO{<body>}"),
43 Macro(name, parent), body() {
60 parseActuals(statement);
63 if(formals.size() != actuals.size()) {
65 "Inconsistent number of macro arguments.");
72 Token token = body->readToken();
74 while(! token.
isEOF()) {
78 std::string word = token.
getWord();
80 for(std::vector<std::string>::size_type i = 0;
81 i < formals.size(); i++) {
82 if(word == formals[i]) {
83 std::vector<Token> act = actuals[i];
94 token = body->readToken();
107 bool isMacro = statement.
keyword(
"MACRO");
114 if(statement.
atEnd()) {
116 "MACRO body is not closed.");
120 if(token.
isDel(
'{')) {
122 }
else if(token.
isDel(
'}')) {
123 if(--level == 0)
break;
131 "Missing MACRO body, should be \"{...}\".");
bool isEOF() const
Test for end of file.
The base class for all OPAL objects.
Pointer< MacroStream > body
Abstract base class for macros.
void start()
Reset stream to start.
bool atEnd() const
Test for end of command.
Token & getCurrent()
Return current token and skip it.
std::string getWord() const
Return word value.
Abstract interface for a stream of input tokens.
virtual void execute()
Execute the macro command.
void append(Token &)
Append a token to the stream.
Representation of a single input token.
Interface for statements.
bool delimiter(char c)
Test for delimiter.
An input buffer for macro commands.
virtual void parseFormals(Statement &)
Parse formal arguments.
virtual Object * makeTemplate(const std::string &, TokenStream &, Statement &)
Make a macro template.
bool keyword(const char *s)
Test for keyword.
bool isDel(char del) const
Test for delimiter.
Interface for abstract language parser.
virtual Object * makeInstance(const std::string &name, Statement &, const Parser *)
Make a macro instance.
virtual void run(TokenStream *ts) const =0
Read statements and parse.
bool isWord() const
Test for word.