From 6181bc4f019faea5f0fdc33542ec5bcc42f28b89 Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Sat, 3 Aug 2024 17:49:31 -0400 Subject: Modules again --- tnslc/build.sh | 2 +- tnslc/out.txt | 1144 ++++++++++++++++++++++++++++++++++++++++++++++++++ tnslc/parse/ast.tnsl | 173 ++++++-- 3 files changed, 1289 insertions(+), 30 deletions(-) create mode 100644 tnslc/out.txt (limited to 'tnslc') diff --git a/tnslc/build.sh b/tnslc/build.sh index 6bee3fc..1f85a60 100755 --- a/tnslc/build.sh +++ b/tnslc/build.sh @@ -7,7 +7,7 @@ mkdir -p $BUILD_DIR mkdir -p $ARTIFACT_DIR filename=tnslc.tnsl filename="${filename%.*}" -./ctc $filename.tnsl $ARTIFACT_DIR/$filename.asm +valgrind ./ctc $filename.tnsl $ARTIFACT_DIR/$filename.asm nasm -g -f elf64 -o $ARTIFACT_DIR/$filename.o $ARTIFACT_DIR/$filename.asm gcc -ggdb -o $BUILD_DIR/$filename $ARTIFACT_DIR/$filename.o diff --git a/tnslc/out.txt b/tnslc/out.txt new file mode 100644 index 0000000..def2bd1 --- /dev/null +++ b/tnslc/out.txt @@ -0,0 +1,1144 @@ +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {:, line: 1, col: 1, type: UNKNOWN} + +Importing utils/utils.tnsl +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {:, line: 1, col: 1, type: UNKNOWN} + +Importing utils/c_wrap_linux.tnsl +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {"Alert!\n\0", line: 4, col: 18, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {"0\n\0", line: 5, col: 16, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {"(nil)\n\0", line: 6, col: 16, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {0, line: 8, col: 14, type: LITRL} + +Block being skipped. Parsing will pick up after the end: + Token {_alloc, line: 9, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_realloc, line: 34, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_delete, line: 59, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_printf, line: 79, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_print_num, line: 99, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_create_file, line: 121, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_open_file, line: 145, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_close_file, line: 168, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_read_byte, line: 182, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_fseek, line: 204, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_write_byte, line: 228, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_perror, line: 249, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {print_alert, line: 269, col: 4, type: USRWD} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {:, line: 5, col: 2, type: UNKNOWN} + +Importing utils/vector.tnsl +Expected ',' to continue the declaration list or a closing delimiter: + Token {data, line: 2, col: 8, type: USRWD} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {,, line: 2, col: 12, type: SEP} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {}, line: 7, col: 1, type: DELIM} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {4, line: 9, col: 28, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {256, line: 10, col: 24, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {"Num 0\n\0", line: 12, col: 18, type: LITRL} + +Block being skipped. Parsing will pick up after the end: + Token {Vector, line: 14, col: 11, type: USRWD} + +Expected ',' to continue the declaration list or a closing delimiter: + Token {strings, line: 100, col: 10, type: USRWD} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {,, line: 100, col: 17, type: SEP} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {}, line: 104, col: 1, type: DELIM} + +Block being skipped. Parsing will pick up after the end: + Token {Artifact, line: 106, col: 11, type: USRWD} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {:, line: 6, col: 2, type: UNKNOWN} + +Importing utils/file.tnsl +Expected ',' to continue the declaration list or a closing delimiter: + Token {Artifact, line: 2, col: 2, type: USRWD} + +Expected variable name in declaration: + Token {,, line: 2, col: 15, type: SEP} + +Expected variable name in declaration: + Token {uint, line: 4, col: 2, type: KEYTP} + +Expected variable name in declaration: + Token {,, line: 4, col: 10, type: SEP} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {}, line: 6, col: 1, type: DELIM} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {"Handle: (nil)\n\0", line: 8, col: 20, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {"..", line: 9, col: 21, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {".", line: 10, col: 22, type: LITRL} + +Block being skipped. Parsing will pick up after the end: + Token {File, line: 12, col: 11, type: USRWD} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {:, line: 7, col: 2, type: UNKNOWN} + +Importing utils/algo.tnsl +Block being skipped. Parsing will pick up after the end: + Token {strcmp, line: 2, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {strlen, line: 12, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {base_for_char, line: 17, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {decode_bin, line: 29, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {decode_oct, line: 35, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {decode_hex, line: 41, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {decode_dec, line: 51, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {cstr_to_int, line: 58, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {cstr_to_uint, line: 91, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {reverse_str, line: 122, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {uint_to_hex_str, line: 132, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {int_to_str, line: 158, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {strcpy, line: 186, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {unquote_cha, line: 192, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {unquote_str, line: 215, col: 4, type: USRWD} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {:, line: 8, col: 2, type: UNKNOWN} + +Importing utils/iterator.tnsl +Expected ',' to continue the declaration list or a closing delimiter: + Token {v, line: 2, col: 10, type: USRWD} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {,, line: 2, col: 11, type: SEP} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {}, line: 4, col: 1, type: DELIM} + +Block being skipped. Parsing will pick up after the end: + Token {Iterator, line: 6, col: 11, type: USRWD} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {:, line: 2, col: 1, type: UNKNOWN} + +Importing parse/parse.tnsl +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {:, line: 2, col: 2, type: UNKNOWN} + +Importing parse/tokenizer.tnsl +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {0, line: 2, col: 20, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {1, line: 2, col: 40, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {2, line: 3, col: 20, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {3, line: 4, col: 20, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {4, line: 5, col: 20, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {5, line: 6, col: 20, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {6, line: 7, col: 20, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {7, line: 8, col: 20, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {998, line: 10, col: 22, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {999, line: 11, col: 20, type: LITRL} + +Expected ',' to continue the declaration list or a closing delimiter: + Token {_type, line: 14, col: 7, type: USRWD} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {,, line: 14, col: 12, type: SEP} + +Expected variable name in declaration: + Token {uint, line: 16, col: 2, type: KEYTP} + +Expected variable name in declaration: + Token {,, line: 17, col: 7, type: SEP} + +Expected variable name in declaration: + Token {}, line: 19, col: 1, type: DELIM} + +Block being skipped. Parsing will pick up after the end: + Token {Token, line: 21, col: 11, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_in_csv, line: 31, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_str_contains, line: 47, col: 4, type: USRWD} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {"import,using,module,export,struct,method,implements,interface,operator,enum,if,else,loop,continue,break,return,label,goto,asm\0", line: 57, col: 21, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {"uint8,uint16,uint32,uint64,uint,int8,int16,int32,int64,int,float32,float64,float,bool,void,vect,type\0", line: 58, col: 21, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {"false,true,null\0", line: 59, col: 21, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {"~`!@#$%^&*()[]{}-+=\"\'\\|;:/?.>,<\0", line: 61, col: 21, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {"`~!%^&|*-=+./><\0", line: 63, col: 21, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {"==,&&,||,^^,!==,!&&,!||,!^^,!<,!>,<<,>>,!&,!|,!^,++,--,>==,<==\0", line: 64, col: 21, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {3, line: 65, col: 21, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {"is,len\0", line: 66, col: 21, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {"()[]{}\0", line: 68, col: 21, type: LITRL} + +Block being skipped. Parsing will pick up after the end: + Token {produce_word_token, line: 71, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {produce_string_token, line: 105, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {comment_line, line: 136, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {comment_block, line: 148, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {is_comment_block, line: 166, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {is_multi_delim, line: 170, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {produce_reserved_token, line: 181, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {produce_numeric_token, line: 244, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {is_whitespace, line: 290, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {is_reserved, line: 299, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {is_numeric, line: 303, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {produce_next_token, line: 310, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {produce_first_token, line: 348, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {gen_token_list, line: 357, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {print_token_type, line: 379, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {print_token, line: 405, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {print_token_list, line: 414, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {end_token_list, line: 422, col: 4, type: USRWD} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {:, line: 3, col: 2, type: UNKNOWN} + +Importing parse/ast.tnsl +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {0, line: 2, col: 23, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {1, line: 2, col: 46, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {2, line: 3, col: 23, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {3, line: 4, col: 21, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {4, line: 5, col: 19, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {5, line: 6, col: 23, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {6, line: 7, col: 23, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {7, line: 8, col: 24, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {8, line: 9, col: 25, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {9, line: 10, col: 23, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {10, line: 11, col: 22, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {11, line: 12, col: 22, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {12, line: 13, col: 22, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {13, line: 14, col: 24, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {14, line: 15, col: 25, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {15, line: 16, col: 21, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {16, line: 17, col: 21, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {998, line: 18, col: 20, type: LITRL} + +Expected ',' to continue the declaration list or a closing delimiter: + Token {_type, line: 21, col: 9, type: USRWD} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {,, line: 21, col: 14, type: SEP} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {., line: 23, col: 7, type: AUG} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {}, line: 24, col: 1, type: DELIM} + +Block being skipped. Parsing will pick up after the end: + Token {Node, line: 26, col: 11, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_get_closing_delim, line: 46, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_advance_check, line: 58, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_ast_print_err, line: 68, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_ast_value, line: 80, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_type_helper_pre, line: 88, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_type_helper_func, line: 135, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_type_helper_usertype, line: 145, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_ast_type, line: 172, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_maybe_helper_decl, line: 221, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_ast_list_decl, line: 225, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_ast_list_enum, line: 258, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_ast_list_type, line: 299, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_ast_method, line: 335, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_ast_function, line: 338, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_ast_import, line: 343, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_ast_asm, line: 373, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_ast_struct, line: 394, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_ast_enum, line: 433, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_ast_decl, line: 480, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_ast_top_block, line: 520, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_ast_module, line: 563, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {_ast_file, line: 613, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {generate_ast, line: 642, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {print_node_type, line: 659, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {print_node_head, line: 699, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {print_ast_rec, line: 707, col: 4, type: USRWD} + +Block being skipped. Parsing will pick up after the end: + Token {print_ast, line: 724, col: 4, type: USRWD} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {:, line: 3, col: 1, type: UNKNOWN} + +Importing compile/compile.tnsl +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {:, line: 2, col: 2, type: UNKNOWN} + +Importing compile/generate.tnsl +Block being skipped. Parsing will pick up after the end: + Token {generate, line: 1, col: 4, type: USRWD} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {"out.asm\0", line: 5, col: 23, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {" +TNSLC v0.6.0 (C) 2024 CircleShift (MPL 2.0) + +usage: + tnslc (file in) [file out] + +\0", line: 13, col: 16, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {"Error opening file\n\0", line: 15, col: 20, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {"\0", line: 17, col: 19, type: LITRL} + +Expected 'import', 'struct', 'asm', block, or declaration in top level: + Token {"\n\0", line: 18, col: 18, type: LITRL} + +Block being skipped. Parsing will pick up after the end: + Token {main, line: 20, col: 4, type: USRWD} + +{ NODE_TYPE: NTYPE_MODULE, DATA: + { NODE_TYPE: NTYPE_ASM, DATA: extern malloc, realloc, free, printf, open, close, read, write, lseek, perror + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_PRE_OP, DATA: { + } + { NODE_TYPE: NTYPE_ID, DATA: uint8 + } + } + { NODE_TYPE: NTYPE_ID, DATA: _alert + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_PRE_OP, DATA: { + } + { NODE_TYPE: NTYPE_ID, DATA: uint8 + } + } + { NODE_TYPE: NTYPE_ID, DATA: _dec + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_PRE_OP, DATA: { + } + { NODE_TYPE: NTYPE_ID, DATA: uint8 + } + } + { NODE_TYPE: NTYPE_ID, DATA: _ptr + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_PRE_OP, DATA: ~ + } + { NODE_TYPE: NTYPE_ID, DATA: void + } + } + { NODE_TYPE: NTYPE_ID, DATA: NULL + } + } + { NODE_TYPE: NTYPE_MODULE, DATA: utils + { NODE_TYPE: NTYPE_STRUCT, DATA: Vector + { NODE_TYPE: NTYPE_DLIST, DATA: { + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_PRE_OP, DATA: ~ + } + { NODE_TYPE: NTYPE_ID, DATA: void + } + } + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint + } + } + { NODE_TYPE: NTYPE_ID, DATA: count + } + { NODE_TYPE: NTYPE_ID, DATA: size + } + { NODE_TYPE: NTYPE_ID, DATA: _elsz + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint + } + } + { NODE_TYPE: NTYPE_ID, DATA: VECTOR_MIN_ELEMENTS + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint + } + } + { NODE_TYPE: NTYPE_ID, DATA: VECTOR_MAX_GROW + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_PRE_OP, DATA: ~ + } + { NODE_TYPE: NTYPE_ID, DATA: uint8 + } + } + { NODE_TYPE: NTYPE_ID, DATA: NUM_STR + } + } + { NODE_TYPE: NTYPE_STRUCT, DATA: Artifact + { NODE_TYPE: NTYPE_DLIST, DATA: { + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_PRE_OP, DATA: ~ + } + { NODE_TYPE: NTYPE_PRE_OP, DATA: ~ + } + { NODE_TYPE: NTYPE_ID, DATA: uint8 + } + } + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint + } + } + { NODE_TYPE: NTYPE_ID, DATA: size + } + { NODE_TYPE: NTYPE_ID, DATA: count + } + } + { NODE_TYPE: NTYPE_STRUCT, DATA: File + { NODE_TYPE: NTYPE_DLIST, DATA: { + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: path + } + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: int32 + } + } + { NODE_TYPE: NTYPE_ID, DATA: handle + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: pos + } + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: bool + } + } + { NODE_TYPE: NTYPE_ID, DATA: at_end + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_PRE_OP, DATA: ~ + } + { NODE_TYPE: NTYPE_ID, DATA: uint8 + } + } + { NODE_TYPE: NTYPE_ID, DATA: PT_HANDLE + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_PRE_OP, DATA: ~ + } + { NODE_TYPE: NTYPE_ID, DATA: uint8 + } + } + { NODE_TYPE: NTYPE_ID, DATA: PARENT_DIR + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_PRE_OP, DATA: ~ + } + { NODE_TYPE: NTYPE_ID, DATA: uint8 + } + } + { NODE_TYPE: NTYPE_ID, DATA: CURRENT_DIR + } + } + { NODE_TYPE: NTYPE_STRUCT, DATA: Iterator + { NODE_TYPE: NTYPE_DLIST, DATA: { + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_PRE_OP, DATA: ~ + } + { NODE_TYPE: NTYPE_ID, DATA: Vector + } + } + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: int + } + } + { NODE_TYPE: NTYPE_ID, DATA: pos + } + } + } + { NODE_TYPE: NTYPE_MODULE, DATA: parse + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint + } + } + { NODE_TYPE: NTYPE_ID, DATA: TTYPE_DELIM + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint + } + } + { NODE_TYPE: NTYPE_ID, DATA: TTYPE_SEP + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint + } + } + { NODE_TYPE: NTYPE_ID, DATA: TTYPE_KEYWD + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint + } + } + { NODE_TYPE: NTYPE_ID, DATA: TTYPE_KEYTP + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint + } + } + { NODE_TYPE: NTYPE_ID, DATA: TTYPE_LITRL + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint + } + } + { NODE_TYPE: NTYPE_ID, DATA: TTYPE_AUG + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint + } + } + { NODE_TYPE: NTYPE_ID, DATA: TTYPE_USRWD + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint + } + } + { NODE_TYPE: NTYPE_ID, DATA: TTYPE_COMNT + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint + } + } + { NODE_TYPE: NTYPE_ID, DATA: TTYPE_UNKNOWN + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint + } + } + { NODE_TYPE: NTYPE_ID, DATA: TTYPE_ERR + } + } + { NODE_TYPE: NTYPE_STRUCT, DATA: Token + { NODE_TYPE: NTYPE_DLIST, DATA: { + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint + } + } + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_PRE_OP, DATA: ~ + } + { NODE_TYPE: NTYPE_ID, DATA: uint8 + } + } + { NODE_TYPE: NTYPE_ID, DATA: data + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: line + } + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: col + } + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_PRE_OP, DATA: ~ + } + { NODE_TYPE: NTYPE_ID, DATA: uint8 + } + } + { NODE_TYPE: NTYPE_ID, DATA: KEYWORDS + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_PRE_OP, DATA: ~ + } + { NODE_TYPE: NTYPE_ID, DATA: uint8 + } + } + { NODE_TYPE: NTYPE_ID, DATA: KEYTYPES + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_PRE_OP, DATA: ~ + } + { NODE_TYPE: NTYPE_ID, DATA: uint8 + } + } + { NODE_TYPE: NTYPE_ID, DATA: LITERALS + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_PRE_OP, DATA: ~ + } + { NODE_TYPE: NTYPE_ID, DATA: uint8 + } + } + { NODE_TYPE: NTYPE_ID, DATA: RESERVED + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_PRE_OP, DATA: ~ + } + { NODE_TYPE: NTYPE_ID, DATA: uint8 + } + } + { NODE_TYPE: NTYPE_ID, DATA: OP + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_PRE_OP, DATA: ~ + } + { NODE_TYPE: NTYPE_ID, DATA: uint8 + } + } + { NODE_TYPE: NTYPE_ID, DATA: MULTI_OP + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint + } + } + { NODE_TYPE: NTYPE_ID, DATA: MAX_MULTI + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_PRE_OP, DATA: ~ + } + { NODE_TYPE: NTYPE_ID, DATA: uint8 + } + } + { NODE_TYPE: NTYPE_ID, DATA: MULTI_OP_W + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_PRE_OP, DATA: ~ + } + { NODE_TYPE: NTYPE_ID, DATA: uint8 + } + } + { NODE_TYPE: NTYPE_ID, DATA: DELIMS + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint16 + } + } + { NODE_TYPE: NTYPE_ID, DATA: NTYPE_MODULE + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint16 + } + } + { NODE_TYPE: NTYPE_ID, DATA: NTYPE_EXPORT + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint16 + } + } + { NODE_TYPE: NTYPE_ID, DATA: NTYPE_STRUCT + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint16 + } + } + { NODE_TYPE: NTYPE_ID, DATA: NTYPE_TYPE + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint16 + } + } + { NODE_TYPE: NTYPE_ID, DATA: NTYPE_ID + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint16 + } + } + { NODE_TYPE: NTYPE_ID, DATA: NTYPE_BIN_OP + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint16 + } + } + { NODE_TYPE: NTYPE_ID, DATA: NTYPE_PRE_OP + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint16 + } + } + { NODE_TYPE: NTYPE_ID, DATA: NTYPE_POST_OP + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint16 + } + } + { NODE_TYPE: NTYPE_ID, DATA: NTYPE_FUNCTION + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint16 + } + } + { NODE_TYPE: NTYPE_ID, DATA: NTYPE_METHOD + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint16 + } + } + { NODE_TYPE: NTYPE_ID, DATA: NTYPE_TLIST + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint16 + } + } + { NODE_TYPE: NTYPE_ID, DATA: NTYPE_DLIST + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint16 + } + } + { NODE_TYPE: NTYPE_ID, DATA: NTYPE_ELIST + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint16 + } + } + { NODE_TYPE: NTYPE_ID, DATA: NTYPE_LITERAL + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint16 + } + } + { NODE_TYPE: NTYPE_ID, DATA: NTYPE_KEY_TYPE + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint16 + } + } + { NODE_TYPE: NTYPE_ID, DATA: NTYPE_ENUM + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint16 + } + } + { NODE_TYPE: NTYPE_ID, DATA: NTYPE_DECL + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint16 + } + } + { NODE_TYPE: NTYPE_ID, DATA: NTYPE_ASM + } + } + { NODE_TYPE: NTYPE_STRUCT, DATA: Node + { NODE_TYPE: NTYPE_DLIST, DATA: { + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: uint16 + } + } + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_PRE_OP, DATA: ~ + } + { NODE_TYPE: NTYPE_ID, DATA: uint8 + } + } + { NODE_TYPE: NTYPE_ID, DATA: data + } + { NODE_TYPE: NTYPE_ID, DATA: utils + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_ID, DATA: Vector + } + } + { NODE_TYPE: NTYPE_ID, DATA: sub + } + } + } + { NODE_TYPE: NTYPE_MODULE, DATA: compile + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_PRE_OP, DATA: ~ + } + { NODE_TYPE: NTYPE_ID, DATA: uint8 + } + } + { NODE_TYPE: NTYPE_ID, DATA: DEFAULT_FOUT + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_PRE_OP, DATA: ~ + } + { NODE_TYPE: NTYPE_ID, DATA: uint8 + } + } + { NODE_TYPE: NTYPE_ID, DATA: USAGE + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_PRE_OP, DATA: ~ + } + { NODE_TYPE: NTYPE_ID, DATA: uint8 + } + } + { NODE_TYPE: NTYPE_ID, DATA: FOPEN_ERR + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_PRE_OP, DATA: ~ + } + { NODE_TYPE: NTYPE_ID, DATA: uint8 + } + } + { NODE_TYPE: NTYPE_ID, DATA: char_str + } + } + { NODE_TYPE: NTYPE_DECL, DATA: + { NODE_TYPE: NTYPE_TYPE, DATA: + { NODE_TYPE: NTYPE_PRE_OP, DATA: ~ + } + { NODE_TYPE: NTYPE_ID, DATA: uint8 + } + } + { NODE_TYPE: NTYPE_ID, DATA: newline + } + } +} diff --git a/tnslc/parse/ast.tnsl b/tnslc/parse/ast.tnsl index 3afce74..0102146 100644 --- a/tnslc/parse/ast.tnsl +++ b/tnslc/parse/ast.tnsl @@ -16,6 +16,7 @@ uint16 NTYPE_LITERAL = 13 uint16 NTYPE_KEY_TYPE = 14 uint16 NTYPE_ENUM = 15 uint16 NTYPE_DECL = 16 +uint16 NTYPE_VLIST = 17 uint16 NTYPE_ASM = 998 struct Node { @@ -58,7 +59,7 @@ struct Node { ;/ /; _advance_check(~utils.File fin, ~Token tok, ~uint8 eq) [bool] - /; if (tok`.eq(eq) == true) + /; if (tok`._type !== TTYPE_ERR && tok`.eq(eq) == true) Token tmp = produce_next_token(fin, tok`) tok`.end() tok` = tmp @@ -220,6 +221,38 @@ struct Node { # AST lists +/; _ast_list_value (~utils.File fin, ~Node mod, ~Token first) + Node list + list.init(NTYPE_VLIST, first`.data) + + uint8 end = _get_closing_delim(first`.data`) + + first` = produce_next_token(fin, first`) + + /; loop (first`._type !== TTYPE_ERR && first`.data` !== end) + + /; if (first`._type == TTYPE_USRWD || first`._type == TTYPE_KEYTP || first`.eq("~\0") == true || first`.eq("{\0") == true) + _ast_type(fin, ~list, first) + ;; else + _ast_print_err(first, "Expected type in type list\0") + mod`.sub.push(~list) + return + ;/ + + /; if (_advance_check(fin, first, ",\0") == false && first`._type !== TTYPE_DELIM) + _ast_print_err(first, "Expected ',' to continue the type list or a closing delimiter\0") + mod`.sub.push(~list) + return + ;/ + ;/ + + mod`.sub.push(~list) + + Token next = produce_next_token(fin, first`) + first`.end() + first` = next +;/ + /; _maybe_helper_decl (~utils.File fin, ~Node mod, ~Token first) ;/ @@ -334,7 +367,11 @@ struct Node { # Method and function blocks +/; _ast_method (~utils.File fin, ~Node mod, ~Token first) +;/ +/; _ast_function (~utils.File fin, ~Node mod, ~Token first) +;/ # Top level directives @@ -516,17 +553,96 @@ struct Node { ;/ /; _ast_top_block(~utils.File fin, ~Node mod, ~Token first) - Token tmp = produce_next_token(fin, first`) - first`.end() - first` = tmp + Token blf = first` + first` = produce_next_token(fin, first`) + + /; loop (bool run = true; run == true && first`._type !== TTYPE_ERR) + /; if (first`.eq("module\0") == true || first`.eq("export\0") == true) + _ast_module(fin, mod, first) + ;; else if (_advance_check(fin, first, "method\0") == true) + _ast_method(fin, mod, first) + ;; else if (first`._type == TTYPE_USRWD) + _ast_function(fin, mod, first) + ;; else + _ast_print_err(first, "Expected module, method, or function for top level block\0") + ;/ + + run = _advance_check(fin, first, ";;\0") + /; if (run == false && first`.eq(";/\0") == false) + _ast_print_err(first, "Block being skipped. Parsing will pick up after the end\0") + ;/ + ;/ + + /; loop (int deep = 1; deep > 0 && first`._type !== TTYPE_ERR) + /; if (first`.eq(";/\0")) + deep = deep - 1 + ;; else if (first`.eq("/;\0")) + deep = deep + 1 + ;/ + + /; if (deep > 0) + Token tmp = produce_next_token(fin, first`) + first`.end() + first` = tmp + ;/ + ;/ + + /; if (_advance_check(fin, first`, ";/\0") == false) + _ast_print_err(~blf, "Could not find closing ;/ for top block\0") + _ast_print_err(first, "^^^ Last token before previous error\0") + ;/ + blf.end() ;/ /; _ast_module(~utils.File fin, ~Node mod, ~Token first) - Token tmp = produce_next_token(fin, first`) - first`.end() - first` = tmp + uint16 nt = NTYPE_MODULE + + /; if (_advance_check(fin, first, "export\0") == true) + /; if (_advance_check(fin, first, "module\0") == false) + _ast_print_err(first, "Expected 'module' keyword after 'export'\0") + return + ;/ + nt = NTYPE_EXPORT + ;; else if (_advance_check(fin, first, "module\0") == false) + _printf("[FATAL] The following issue is with the compiler, not your program.\n\0") + _printf("[FATAL] Please report the following issue to tnslc upstream.\n\0") + _ast_print_err(first, "[FATAL] [CMPERR] Should only call _ast_module when 'module' or 'export' are seen\0") + ;/ + + /; if (first`._type !== TTYPE_USRWD) + _ast_print_err(first, "Expected module name (identifier) after 'module'\0") + ;/ + + Node nmod + nmod.init(nt, first`.data) + first` = produce_next_token(fin, first`) + + /; loop (bool run = true; run == true && first`._type !== TTYPE_ERR) + /; if (_advance_check(fin, first, "import\0") == true) + _ast_import(fin, ~nmod, first) + ;; else if (_advance_check(fin, first, "struct\0") == true) + _ast_struct(fin, ~nmod, first) + ;; else if (_advance_check(fin, first, "enum\0") == true) + _ast_enum(fin, ~nmod, first) + ;; else if (_advance_check(fin, first, "asm\0") == true) + _ast_asm(fin, ~nmod, first) + ;; else if (first`.eq("/;\0") == true) + _ast_top_block(fin, ~nmod, first) + ;; else if (first`._type == TTYPE_KEYTP || first`._type == TTYPE_USRWD || first`.eq("~\0") == true || first`.eq("{\0") == true) + _ast_decl(fin, ~nmod, first) + ;; else if (first`.eq(";/\0") == true) + run = false + ;; else + _ast_print_err(first, "Expected 'import', 'struct', 'asm', block, or declaration in top level\0") + + Token tmp = produce_next_token(fin, first`) + first`.end() + first` = tmp + ;/ + ;/ + mod`.sub.push(~nmod) ;/ /; _ast_file (~utils.File fin, ~Node mod) @@ -547,10 +663,7 @@ struct Node { ;; else if (first._type == TTYPE_KEYTP || first._type == TTYPE_USRWD || first.eq("~\0") == true || first.eq("{\0") == true) _ast_decl(fin, mod, ~first) ;; else - _printf("Expected 'import', 'struct', 'asm', block, or declaration in top level:\n\0") - _printf(" \0") - print_token(first) - _printf("\n\0") + _ast_print_err(~first, "Expected 'import', 'struct', 'asm', block, or declaration in top level\0") Token tmp = produce_next_token(fin, first) first.end() @@ -580,41 +693,43 @@ struct Node { /; print_node_type (~Node n) /; if (n`._type == NTYPE_MODULE) - _printf("NTYPE_MODULE\0") + _printf("MODULE\0") ;; else if (n`._type == NTYPE_EXPORT) - _printf("NTYPE_EXPORT\0") + _printf("EXPORT\0") ;; else if (n`._type == NTYPE_STRUCT) - _printf("NTYPE_STRUCT\0") + _printf("STRUCT\0") ;; else if (n`._type == NTYPE_TYPE) - _printf("NTYPE_TYPE\0") + _printf("TYPE\0") ;; else if (n`._type == NTYPE_ID) - _printf("NTYPE_ID\0") + _printf("ID\0") ;; else if (n`._type == NTYPE_BIN_OP) - _printf("NTYPE_BIN_OP\0") + _printf("BIN_OP\0") ;; else if (n`._type == NTYPE_PRE_OP) - _printf("NTYPE_PRE_OP\0") + _printf("PRE_OP\0") ;; else if (n`._type == NTYPE_POST_OP) - _printf("NTYPE_POST_OP\0") + _printf("POST_OP\0") ;; else if (n`._type == NTYPE_FUNCTION) - _printf("NTYPE_FUNCTION\0") + _printf("FUNCTION\0") ;; else if (n`._type == NTYPE_METHOD) - _printf("NTYPE_METHOD\0") + _printf("METHOD\0") ;; else if (n`._type == NTYPE_TLIST) - _printf("NTYPE_TLIST\0") + _printf("TLIST\0") ;; else if (n`._type == NTYPE_DLIST) - _printf("NTYPE_DLIST\0") + _printf("DLIST\0") ;; else if (n`._type == NTYPE_ELIST) - _printf("NTYPE_ELIST\0") + _printf("ELIST\0") ;; else if (n`._type == NTYPE_LITERAL) - _printf("NTYPE_LITERAL\0") + _printf("LITERAL\0") ;; else if (n`._type == NTYPE_KEY_TYPE) - _printf("NTYPE_KEY_TYPE\0") + _printf("KEY_TYPE\0") ;; else if (n`._type == NTYPE_ENUM) - _printf("NTYPE_ENUM\0") + _printf("ENUM\0") ;; else if (n`._type == NTYPE_DECL) - _printf("NTYPE_DECL\0") + _printf("DECL\0") + ;; else if (n`._type == NTYPE_VLIST) + _printf("VLIST\0") ;; else if (n`._type == NTYPE_ASM) - _printf("NTYPE_ASM\0") + _printf("ASM\0") ;/ ;/ -- cgit v1.2.3