aboutsummaryrefslogtreecommitdiff
path: root/src/include/parser.h
blob: 59cd0aed7767683274643b5ffd2486ddefc267f1 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef PARSER_H
#define PARSER_H

#include "util.h"
#include "tree.h"
#include "token.h"

typedef struct PARSER {
   /* The token list being consumed. */
   token_t* token;
   
   /* The AST being produced. */
   tree_t* tree;

   /* Pointer to the part of the tree the parser is currently working on. */
} parser_t;

/* Creates a new parser. */
parser_t* parser_init(token_t* token);

/* 
   Destroys a parser.
   - Does not free the token list.
   - Does not free the AST.
*/
void parser_destroy(parser_t* parser);

/* Step the parser forward by 1 token. */
int parser_nxt_token(parser_t* parser);

/* 
   Check whether the current token matches the given type.
   - If it doesn't, return 0 and throw error.
*/
int parser_match(parser_t* parser, token_type_t type);

/* Steps the parser forward by one token, then check whether the new token matches the given type. */
int parser_nxt_token_match(parser_t* parser, token_type_t type);

/* Return the tree for an integer. */
tree_t* parser_parse_lint(parser_t* parser);

/* Return the tree for a string.  */
tree_t* parser_parse_lstr(parser_t* parser);

/* Return the tree for an expression.*/
tree_t* parser_parse_expr(parser_t* parser);

/* Return the tree for an expression. */
tree_t* parser_parse_block(parser_t* parser);

/* Return the tree for a definition's arguments. */
tree_t* parser_parse_darg(parser_t* parser);

/* Return the tree for a definition. */
tree_t* parser_parse_def(parser_t* parser);

/* Return the tree for a call's arguments. */
tree_t* parser_parse_carg(parser_t* parser);

/* Return the tree for a call. */
tree_t* parser_parse_call(parser_t* parser);

/* Parse. */
tree_t* parser_parse(parser_t* parser);

/* Parse with the given parser. */
void parser_run(parser_t* parser);

#endif