projects/07/src/parser.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
#ifndef _PARSER_H #define _PARSER_H // 'parser.h' roughly corresponds to the 'Parser' module specified in // nand2tetris, with a few liberties taken. #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define DBGLOG printf //#define DBGLOG(...) #define MAX_LINE_LEN 256 // TODO need to be redefined here? (remove me) enum vm_command_t { C_ARITHMETIC, C_PUSH, C_POP, C_LABEL, C_GOTO, C_IF, C_FUNCTION, C_RETURN, C_CALL }; struct vm_instruction_t { enum vm_command_t cmd; char *arg1; uint16_t arg2; const char *original_vm_line; }; bool parse_command_type(struct vm_instruction_t *vm_instr) { return true; // STUB TODO implement } bool parse_arg1(struct vm_instruction_t *vm_instr) { return true; // STUB TODO implement } bool parse_arg2(struct vm_instruction_t *vm_instr) { return true; // STUB TODO implement } bool parse_line(const char *line, struct vm_instruction_t *vm_instr) { vm_instr->original_vm_line = line; DBGLOG("// %s\n", vm_instr->original_vm_line); if (!parse_command_type(vm_instr)) return false; if (!parse_arg1(vm_instr)) return false; if (!parse_arg2(vm_instr)) return false; return true; } #endif // _PARSER_H |