-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParserArena.cpp
78 lines (67 loc) · 1.33 KB
/
ParserArena.cpp
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
/*
* ParserArena.cpp
* lex
*
* Created by Alexandru Chiculita on 9/10/09.
*
*/
#include "Platform.h"
#include "ParserArena.h"
#include <string>
#include <sstream>
#include "BytecodeGenerator.h"
extern int yyparse(Arena* arena);
ArenaNode::ArenaNode()
: m_line(0)
, m_endLine(0)
, m_start(0)
, m_end(0)
{
}
Register* ArenaNode::EmitBytecode(BytecodeGenerator* generator, Register* dst)
{
// should not be here
//assert(false);
return 0;
}
PassRef<Accessor> ArenaNode::GetAccessor(BytecodeGenerator* generator)
{
return 0;
}
ArenaNode* Arena::RegisterNode(ArenaNode* ptr)
{
assert(ptr->HasOneRef());
push_back(AdoptRef(ptr));
return ptr;
}
std::string ArenaNode::LocationToString() const
{
std::ostringstream o;
o << '[' << m_line << " to " << m_endLine << " [" << m_start << ':' << m_end << ']';
return o.str();
}
std::string ArenaNode::ToString() const
{
return "[ArenaNode]";
}
Arena::Arena(std::istream* inputStream)
: m_inputStream (inputStream)
{
}
int Arena::Read(char* buffer, int max_size)
{
m_inputStream->read(buffer, max_size);
int len = m_inputStream->gcount();
if (len)
{
m_sourceCode.write(buffer, len);
}
return len;
}
ArenaNode* Arena::Parse()
{
InitScanner();
yyparse(this);
DestroyScanner();
return m_result.Ptr();
}