OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
CompoundStatement.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: CompoundStatement.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.1.1.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: CompoundStatement
10 // Compound statement of the form "{ <statement>; <statement>; }"
11 // (may be used for FOR, IF, or WHILE blocks).
12 //
13 // ------------------------------------------------------------------------
14 //
15 // $Date: 2000/03/27 09:33:43 $
16 // $Author: Andreas Adelmann $
17 //
18 // ------------------------------------------------------------------------
19 
22 #include "Parser/Parser.h"
23 
24 
25 // class CompoundStatement
26 // ------------------------------------------------------------------------
27 
29  Statement("", 0), tokens(0) {
30  Token token = is.readToken();
31  buffer_name = token.getFile();
32  stat_line = token.getLine();
33  tokens = new MacroStream(token.getFile());
34 
35  // Skip opening brace.
36  int level = 1;
37  token = is.readToken();
38 
39  while(! token.isEOF()) {
40  if(token.isDel('{')) {
41  ++level;
42  } else if(token.isDel('}')) {
43  if(--level == 0) return;
44  }
45 
46  tokens->append(token);
47  token = is.readToken();
48  }
49 }
50 
51 
53 {}
54 
55 
56 void CompoundStatement::execute(const Parser &parser) {
57  tokens->start();
58  parser.run(&*tokens);
59 }
Interface for abstract language parser.
Definition: Parser.h:31
virtual void run(TokenStream *ts) const =0
Read statements and parse.
Interface for statements.
Definition: Statement.h:38
int stat_line
Definition: Statement.h:173
std::string buffer_name
Definition: Statement.h:176
Representation of a single input token.
Definition: Token.h:33
bool isDel(char del) const
Test for delimiter.
Definition: Token.cpp:92
bool isEOF() const
Test for end of file.
Definition: Token.cpp:107
int getLine() const
Return the token's line number.
Definition: Token.cpp:215
const std::string & getFile() const
Return the token's file name.
Definition: Token.cpp:210
Abstract interface for a stream of input tokens.
Definition: TokenStream.h:33
virtual Token readToken()=0
Read single token from stream.
Pointer< MacroStream > tokens
virtual void execute(const Parser &)
Execute.
An input buffer for macro commands.
Definition: MacroStream.h:31
void append(Token &)
Append a token to the stream.
Definition: MacroStream.cpp:36
void start()
Reset stream to start.
Definition: MacroStream.cpp:53