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