OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
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 "OpalParser/Parser.h"
23
24// class CompoundStatement
25// ------------------------------------------------------------------------
26
28 Token token = is.readToken();
29 buffer_name = token.getFile();
30 stat_line = token.getLine();
31 tokens = std::make_shared<MacroStream>(token.getFile());
32
33 // Skip opening brace.
34 int level = 1;
35 token = is.readToken();
36
37 while (!token.isEOF()) {
38 if (token.isDel('{')) {
39 ++level;
40 } else if (token.isDel('}')) {
41 if (--level == 0) return;
42 }
43
44 tokens->append(token);
45 token = is.readToken();
46 }
47}
48
50
52 tokens->start();
53 parser.run(&*tokens);
54}
std::shared_ptr< MacroStream > tokens
virtual void execute(const Parser &)
Execute.
Interface for abstract language parser.
Definition Parser.h:30
virtual void run(TokenStream *ts) const =0
Read statements and parse.
Interface for statements.
Definition Statement.h:37
int stat_line
Definition Statement.h:170
std::string buffer_name
Definition Statement.h:173
Abstract interface for a stream of input tokens.
Definition TokenStream.h:30
virtual Token readToken()=0
Read single token from stream.
Representation of a single input token.
Definition Token.h:32
bool isDel(char del) const
Test for delimiter.
Definition Token.cpp:81
bool isEOF() const
Test for end of file.
Definition Token.cpp:89
int getLine() const
Return the token's line number.
Definition Token.cpp:162
const std::string & getFile() const
Return the token's file name.
Definition Token.cpp:160