diff options
Diffstat (limited to '21sh/ll-expr/src/parser/parser.h')
| -rw-r--r-- | 21sh/ll-expr/src/parser/parser.h | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/21sh/ll-expr/src/parser/parser.h b/21sh/ll-expr/src/parser/parser.h new file mode 100644 index 0000000..057c6bc --- /dev/null +++ b/21sh/ll-expr/src/parser/parser.h @@ -0,0 +1,46 @@ +#ifndef PARSER_H +#define PARSER_H + +#include "ast.h" +#include "lexer.h" + +enum parser_status +{ + PARSER_OK, + PARSER_UNEXPECTED_TOKEN, +}; + +/** + * \brief Parses an expression or nothing. + * + * input = EOF + * | exp EOF ; + */ +struct ast *parse(enum parser_status *status, struct lexer *lexer); + +/** + * \brief Parses sexp expressions separated by + and -. + * + * exp = sexp { ( '+' | '-' ) sexp } ; + */ +struct ast *parse_exp(enum parser_status *status, struct lexer *lexer); + +/** + * \brief Parses texp expressions separated by * and /. + * + * sexp = texp { ('*' | '/' ) texp } ; + */ +struct ast *parse_sexp(enum parser_status *status, struct lexer *lexer); + +/** + * \brief Parses a number, a - a number, or a parenthesized expression. + * + * texp = NUMBER + * | '-' NUMBER + * | '-' '(' exp ')' + * | '(' exp ')' + * ; + */ +struct ast *parse_texp(enum parser_status *status, struct lexer *lexer); + +#endif /* !PARSER_H */ |
