evalexpr: parse: rename recursive parsing function
This commit is contained in:
parent
a92e39dbec
commit
ad56ea521a
2
Makefile
2
Makefile
|
@ -6,7 +6,7 @@ VPATH = src/
|
||||||
SRC = \
|
SRC = \
|
||||||
src/ast/ast.c \
|
src/ast/ast.c \
|
||||||
src/eval/eval.c \
|
src/eval/eval.c \
|
||||||
src/parse/parse.c \
|
src/parse/recursive_parse.c \
|
||||||
|
|
||||||
BIN = evalexpr
|
BIN = evalexpr
|
||||||
OBJ = $(SRC:.c=.o)
|
OBJ = $(SRC:.c=.o)
|
||||||
|
|
|
@ -13,7 +13,7 @@ int main(void)
|
||||||
|
|
||||||
while ((getline(&line, &size, stdin)) > 0)
|
while ((getline(&line, &size, stdin)) > 0)
|
||||||
{
|
{
|
||||||
struct ast_node *ast = parse_string(line);
|
struct ast_node *ast = recursive_parse(line);
|
||||||
|
|
||||||
if (ast == NULL)
|
if (ast == NULL)
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,6 +3,6 @@
|
||||||
|
|
||||||
#include "ast/ast.h"
|
#include "ast/ast.h"
|
||||||
|
|
||||||
struct ast_node *parse_string(const char *input);
|
struct ast_node *recursive_parse(const char *input);
|
||||||
|
|
||||||
#endif /* !PARSE_H */
|
#endif /* !PARSE_H */
|
||||||
|
|
|
@ -26,21 +26,21 @@ static void skip_whitespace(const char **input)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Simple recursive descent using the following grammar, using E as start:
|
* Simple recursive descent using the following grammar, using E as start:
|
||||||
**
|
*
|
||||||
** E : T [ ('+'|'-') T ]*
|
* E : T [ ('+'|'-') T ]*
|
||||||
** T : F [ ('*'|'/') F ]*
|
* T : F [ ('*'|'/') F ]*
|
||||||
** F : [ ('-'|'+') ]* P
|
* F : [ ('-'|'+') ]* P
|
||||||
** P : G [ ('^') F ]*
|
* P : G [ ('^') F ]*
|
||||||
** G : '(' E ')' | CONSTANT [ '!' ]
|
* G : '(' E ')' | CONSTANT [ '!' ]
|
||||||
**
|
*
|
||||||
** Whitespace is ignored in the input string, only serving to delimit numbers.
|
* Whitespace is ignored in the input string, only serving to delimit numbers.
|
||||||
**
|
*
|
||||||
** The input shall consist of a single expression, having a trailing
|
* The input shall consist of a single expression, having a trailing
|
||||||
** expression in the input results in an error.
|
* expression in the input results in an error.
|
||||||
**/
|
*/
|
||||||
|
|
||||||
struct ast_node *parse_string(const char *input)
|
struct ast_node *recursive_parse(const char *input)
|
||||||
{
|
{
|
||||||
if (input == NULL)
|
if (input == NULL)
|
||||||
return NULL;
|
return NULL;
|
Loading…
Reference in a new issue