1 /* pkl-parser.h - Parser for Poke.  */
2 
3 /* Copyright (C) 2019, 2020, 2021 Jose E. Marchesi */
4 
5 /* This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef PKL_PARSER_H
20 #define PKL_PARSER_H
21 
22 #include <config.h>
23 #include <stdio.h>
24 
25 #include "pkl.h"
26 #include "pkl-env.h"
27 #include "pkl-ast.h"
28 
29 /* The `pkl_parser' struct holds the parser state.
30 
31    SCANNER is a flex scanner.
32    AST is the abstract syntax tree created by the bison parser.
33 
34    BOOTSTRAPPED is 1 if the compiler has been bootstrapped.  0
35    otherwise.
36 
37    IN_METHOD_P is 1 if we are parsing the declaration of a struct
38    method.  0 otherwise.  */
39 
40 struct pkl_parser
41 {
42   void *scanner;
43   pkl_env env;
44   pkl_ast ast;
45   pkl_compiler compiler;
46   int interactive;
47   char *filename;
48   int start_token;
49   size_t nchars;
50   int bootstrapped;
51   int in_method_decl_p;
52   char *alien_errmsg;
53 };
54 
55 /* Public interface.  */
56 
57 #define PKL_PARSE_PROGRAM 0
58 #define PKL_PARSE_EXPRESSION 1
59 #define PKL_PARSE_DECLARATION 2
60 #define PKL_PARSE_STATEMENT 3
61 
62 int pkl_parse_file (pkl_compiler compiler, pkl_env *env, pkl_ast *ast,
63                     FILE *fp, const char *fname);
64 
65 int pkl_parse_buffer (pkl_compiler compiler, pkl_env *env, pkl_ast *ast,
66                       int what, const char *buffer, const char **end);
67 
68 
69 
70 #endif /* !PKL_PARSER_H */
71