I may follow the order here. https://note.mu/ruiu/n/n00ebc977fd60
- Add/Subtract
- Multiply/Divid
- Local variable
- Function call without arguments
- Function call with arguments
- Function declaration without arguments
- Function declaration with arguments
- Global variable
- Array
- Pointer
- char type
- String literal
- Struct
- #include
Nov 21. So far, p to the middle of 3 is done. Let's implement variable using map and vector.
chmod a+x test.sh
Instead of just git push
, do the following.
git remote add origin https://github.com/moizumi99/9cc.git
git push -u origin master
void error(char *s, int i) {
fprintf(stderr, s, tokens[i].input);
exit(1);
}
###mul()
needs tokens[pos].ty
typedef struct {
Vector *keys;
Vector *vals;
} Map;
void vec_push(Vector *vec, void *elem) {
if (vec->capacity == vec->len) {
vec->capacity *= 2;
vec->data = realloc(vec->data, sizeof(void *) * vec->capacity);
}
vec->data[vec->len++] = elem;
}
program: function program' program': ε | function program'
function: ident "(" expression ")" "{" line "}"
line: assign | line line': ε | assign line'
assign: expr assign' ";" assign': ε | "=" expr assign'
compare: expr compare: expr "==" expr compare: expr "!=" expr expr: mul expr: mul "+" expr expr: mul "-" expr mul: term mul: term "*" term mul: term "/" term term: number | variable | functioncall | "(" expr ")" functioncall: ident "(" arguments ")" variable: ident
arguments: ε | expr
// argument will be like below eventually. // argument: expr argument' // argument': ε | ", " expr argument'