-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlisp_parser.h
63 lines (51 loc) · 1.53 KB
/
lisp_parser.h
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
#ifndef _LISP_PARSER_H_
#define _LISP_PARSER_H_
/**
* This defines everything for our parser, which does not evaluate anything.
*/
// Standard headers
#include <stdlib.h>
#include <stdio.h>
#include <inttypes.h>
#include <string.h>
// Project headers
#include "lisp.h"
// States for the parser's loop
#define LP_STATE_RDY 0
// Status codes used by the token finding routine
#define NO_TOKEN 0
#define FOUND_TOKEN 1
// Status codes used by the S-expression parser
#define SEP_ERROR 0
#define SEP_SUCCESS 1
// Token types
#define LPT_NULL 0
#define LPT_OPEN_PAREN 1
#define LPT_CLOSE_PAREN 2
#define LPT_OPEN_BRACKET 3
#define LPT_CLOSE_BRACKET 4
#define LPT_QUOTE 5
#define LPT_DOUBLE_QUOTE 6
#define LPT_SYMBOL 7
#define LPT_START 8
// Linked list for storing all of the top-level s-expressions
struct s_list {
struct s_exp *exp;
struct s_list *next;
};
// Structure for storing a token that was read out during parsing, these get chained together
struct lp_token {
uint32_t type;
char *text;
uint32_t lineNumber;
struct lp_token *next;
};
// Parsing interface--parses lines and files
struct s_list *lisp_parse_file(FILE *fp);
// Helper functions, used internally
struct lp_token *tokenize_line(char *line, int lineNumber, struct lp_token *prevToken);
int find_next_token(char *buf, struct lp_token **token, char **nextBuf);
int parse_s_expression(struct lp_token *startToken, struct s_exp **newExp, struct lp_token **nextStartToken);
// Debugging functions
void describe_token(struct lp_token *token);
#endif