aboutsummaryrefslogtreecommitdiff
path: root/parser.h
blob: 11a03a5731293bd23f1bf04ce07efec9c9850669 (plain) (blame)
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
#ifndef PARSER_H
#define PARSER_H

#include "model.h"
#include <string>

using std::string;

const int TOKEN_BUFF_SIZE = 65536;
const int PARSE_STACK_SIZE = 65536;

/** @class Tokenizor 
 * Break down the input string stream into tokens
 */
class Tokenizor {
    private:
        FILE *stream;
        char *buff_ptr;
        bool escaping;
    public:
        Tokenizor();
        /** Set the stream to be read from (without setting this, the default
         * would be stdin) */
        void set_stream(FILE *stream);
        /** Extract the next token 
         * @param ret the extracted token
         * @return false if nothing can be read further
         * */
        bool get_token(string &ret);
};

/** @class ASTGenerator
 * Read the tokens and build up an Abstract Syntax Tree (which is in effect a
 * Cons)
 */
class ASTGenerator {
    private:
        /** Convert the string to an internal object */
        static EvalObj* to_obj(const string &);
    public:    
        ASTGenerator();
        /** Read tokens from Tokenizor tk, then return a AST
         * @param tk pointer to a Tokenizor
         * @return Abstract Syntax Tree
         */
        Cons *absorb(Tokenizor *tk); 
};

#endif