Parens.
This commit is contained in:
parent
bc0c4f33ad
commit
9e8410d4cf
@ -11,7 +11,7 @@
|
||||
- [x] Parse infix operators
|
||||
- [x] Order of operations
|
||||
- [x] Parse function application
|
||||
- [ ] Parse order of operations with parenthesis
|
||||
- [x] Parse order of operations with parenthesis
|
||||
- [ ] Parse variable invocation
|
||||
- [ ] Parse variable definition
|
||||
- [ ] Parse types
|
||||
|
13
src/ast.c
13
src/ast.c
@ -7,8 +7,9 @@
|
||||
extern AST* root;
|
||||
|
||||
static char* asttype_names[] = {
|
||||
[AST_TYPE_CALL] = "CALL",
|
||||
[AST_TYPE_CALL] = "FUNC CALL",
|
||||
[AST_TYPE_NUM] = "NUMBER",
|
||||
[AST_TYPE_VREF] = "VAR REFERENCE"
|
||||
};
|
||||
|
||||
AST* ast_init(ASTType type, void* data) {
|
||||
@ -44,6 +45,7 @@ void ast_print_i(AST* ast, int i) {
|
||||
printf("%s %lf\n", INDENT_spacing->buf, *(ASTNumData*)ast->data);
|
||||
break;
|
||||
case AST_TYPE_CALL: ast_call_print(ast->data, i + 2); break;
|
||||
case AST_TYPE_VREF: ast_vref_print(ast->data, i + 2); break;
|
||||
default: exit(1);
|
||||
}
|
||||
INDENT_FIELD_NONL_END;
|
||||
@ -100,3 +102,12 @@ void ast_call_print(ASTCallData* data, int i) {
|
||||
|
||||
INDENT_END;
|
||||
}
|
||||
|
||||
void ast_vref_print(ASTVrefData* data, int i) {
|
||||
INDENT_BEGIN(i);
|
||||
|
||||
INDENT_TITLE("ASTVrefData", data);
|
||||
INDENT_FIELD("to", "%s", data->to);
|
||||
|
||||
INDENT_END;
|
||||
}
|
||||
|
@ -25,7 +25,7 @@
|
||||
%token RGROUP
|
||||
%token SEP
|
||||
|
||||
%token<strval> CALL
|
||||
%token<strval> WORD
|
||||
%token<fval> NUM
|
||||
|
||||
%token SUB
|
||||
@ -60,8 +60,12 @@ exp:
|
||||
|
||||
| LGROUP exp RGROUP { $$ = $2; }
|
||||
|
||||
// Variable reference.
|
||||
| WORD
|
||||
|
||||
// Function call.
|
||||
// name(thing, thing)
|
||||
| CALL LGROUP exp SEP exp RGROUP {
|
||||
| WORD LGROUP exp SEP exp RGROUP {
|
||||
AST** argv = calloc(2, sizeof(AST*));
|
||||
argv[0] = $3;
|
||||
argv[1] = $5;
|
||||
|
@ -4,8 +4,9 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef enum {
|
||||
AST_TYPE_NUM,
|
||||
AST_TYPE_CALL,
|
||||
AST_TYPE_NUM, // A number.
|
||||
AST_TYPE_CALL, // A function call.
|
||||
AST_TYPE_VREF, // A variable reference.
|
||||
AST_TYPE_MAX = AST_TYPE_CALL
|
||||
} ASTType;
|
||||
|
||||
@ -35,4 +36,12 @@ ASTCallData* ast_call_data_init(char* to, size_t argc, AST** argv);
|
||||
void ast_call_data_destroy(ASTCallData* call);
|
||||
void ast_call_print(ASTCallData*, int i);
|
||||
|
||||
typedef struct {
|
||||
char* to; // What the reference's to.
|
||||
} ASTVrefData;
|
||||
|
||||
ASTCallData* ast_vref_data_init(char* to);
|
||||
void ast_vref_data_destroy(ASTCallData* call);
|
||||
void ast_vref_print(ASTVrefData*, int i);
|
||||
|
||||
#endif
|
||||
|
@ -98,7 +98,7 @@ int yylex() {
|
||||
|
||||
if (isalpha(c)) {
|
||||
yylval.strval = acc_word(c);
|
||||
return CALL;
|
||||
return WORD;
|
||||
}
|
||||
|
||||
switch (c) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user