summaryrefslogtreecommitdiff
path: root/cpp/test/Freeze/complex/Parser.cpp
blob: f9a25dfc4aebf630f280f64d1b6fad41b1267f43 (plain)
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
// **********************************************************************
//
// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

#include <IceUtil/DisableWarnings.h>
#include <Parser.h>

using namespace std;

//
// The current bison/flex parser
//
Parser* parser = 0;

Parser::Parser()
{
}

Parser::~Parser()
{
}

Complex::NodePtr
Parser::parse(const string& commands, bool debug)
{
    extern int yydebug;
    yydebug = debug ? 1 : 0;

    _result = 0;
    _errors = 0;
    _buf = commands;
    assert(!_buf.empty());
    extern FILE* yyin;
    yyin = 0;

    assert(!parser);
    parser = this;
    yyparse();
    parser = 0;

    if(_errors)
    {
	return 0;
    }

    return _result;
}

void
Parser::error(const char* s)
{
    cerr << "error: " << s << endl;
    _errors++;
}

void
Parser::error(const std::string& s)
{
    error(s.c_str());
}

void
Parser::getInput(char* buf, int& result, int maxSize)
{
    if(!_buf.empty())
    {
#if defined(_MSC_VER) && !defined(_STLP_MSVC)
	// COMPILERBUG: Stupid Visual C++ defines min and max as macros
	result = _MIN(maxSize, static_cast<int>(_buf.length()));
#else
	result = min(maxSize, static_cast<int>(_buf.length()));
#endif
	strncpy(buf, _buf.c_str(), result);
	_buf.erase(0, result);
    }
    else
    {
	result = 0;
    }
}

void
Parser::setResult(const Complex::NodePtr& node)
{
    _result = node;
}