-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQSpawnStatement.cpp
More file actions
103 lines (77 loc) · 2.15 KB
/
QSpawnStatement.cpp
File metadata and controls
103 lines (77 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <assert.h>
#include <iostream>
#include "FileLexer.h"
#include "Type.h"
#include "Expression.h"
#include "CompilerHelpers.h"
#include "logging.h"
SET_LOG_CAT( LOG_CAT_ALL );
SET_LOG_LEVEL( LOG_LVL_NOISE );
using namespace QLang;
using namespace std;
SpawnStatement *SpawnStatement::Parse( Lexer &l, Scope *scope )
{
TRACE_BEGIN( LOG_LVL_INFO );
// Consume 'spawn' keyword
int sym = l.getSymbol();
if ( sym != Lexer::KEYWORD_SPAWN )
{
COMPILE_ERROR( l, "Internal Error: expected 'spawn' keyword" );
}
SpawnStatement *statement = new SpawnStatement;
// Create anonymous scope for spawn body
Scope *spawn_scope = new Scope( Scope::kScope_Anonymous );
spawn_scope->setParent( scope );
// Expect '{' and parse Block
if ( l.peekSymbol() != '{' )
{
COMPILE_ERROR( l, "Expected '{' after 'spawn'" );
}
statement->mBody = Block::Parse( l, spawn_scope );
cout << "Completed spawn statement parse" << endl;
return statement;
}
WaitStatement *WaitStatement::Parse( Lexer &l, Scope *scope )
{
TRACE_BEGIN( LOG_LVL_INFO );
// Consume 'wait' keyword
int sym = l.getSymbol();
if ( sym != Lexer::KEYWORD_WAIT )
{
COMPILE_ERROR( l, "Internal Error: expected 'wait' keyword" );
}
WaitStatement *statement = new WaitStatement;
// Parse the expression (Task variable to wait on)
statement->mExpr = Expression::ParseExpr( l, scope, 0 );
if ( statement->mExpr == nullptr )
{
COMPILE_ERROR( l, "Expected expression after 'wait'" );
}
// Expect semicolon
sym = l.getSymbol();
if ( sym != ';' )
{
COMPILE_ERROR( l, "Expected ';' after wait expression" );
}
cout << "Completed wait statement parse" << endl;
return statement;
}
WaitAllStatement *WaitAllStatement::Parse( Lexer &l, Scope *scope )
{
TRACE_BEGIN( LOG_LVL_INFO );
// Consume 'wait_all' keyword
int sym = l.getSymbol();
if ( sym != Lexer::KEYWORD_WAIT_ALL )
{
COMPILE_ERROR( l, "Internal Error: expected 'wait_all' keyword" );
}
WaitAllStatement *statement = new WaitAllStatement;
// Expect semicolon
sym = l.getSymbol();
if ( sym != ';' )
{
COMPILE_ERROR( l, "Expected ';' after wait_all" );
}
cout << "Completed wait_all statement parse" << endl;
return statement;
}