summaryrefslogtreecommitdiff
path: root/src/parser.h
blob: e163212d57b40cef595eefb2a70edf2376a85cd9 (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
#ifndef PARSER_H
#define PARSER_H

#include <bu/list.h>
#include <bu/hash.h>
#include "token.h"
#include "number.h"

namespace Bu
{
    class Stream;
};

class Lexer;

class Parser
{
public:
    Parser( Lexer &lex, Bu::Stream &rOut );
    virtual ~Parser();

    void parse();
    Number getVariable( const Bu::String &sName );
    void setVariable( const Bu::String &sName, const Number &rValue );

private:
    void unwind();
    int reqTokens( Token::Type eType );
    int getPriority( Token::Type eType );
    Number &deref( Token &t );

private:
    Lexer &lex;
    Bu::Stream &rOut;
    typedef Bu::List<Token> TokenStack;
    typedef Bu::Hash<Bu::String, Number> VarHash;
    TokenStack tsTerminal;
    TokenStack tsNonTerminal;
    Number nZero;
    VarHash hVars;
};

#endif