From ebce81ad510a9a58255e8d411635d6f3dae4fb68 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Fri, 9 Aug 2019 22:30:04 +0200 Subject: [PATCH] Parses most of C3. --- CMakeLists.txt | 13 +- README.md | 4 +- resources/c3.l | 179 ++ resources/grammar.y | 697 ++++++ resources/testfragments/compiletest.c3 | 11 + resources/testfragments/parsertest.c3 | 209 ++ src/build/build_options.c | 3 + src/build/build_options.h | 1 + src/compiler/ast.c | 856 +++++++ src/compiler/ast.h | 812 +++++++ src/compiler/bigint.c | 2096 ++++++++++++++++ src/compiler/bigint.h | 65 + src/compiler/compiler.c | 24 +- src/compiler/compiler_common.h | 46 +- src/compiler/context.c | 182 ++ src/compiler/context.h | 32 + src/compiler/diagnostics.c | 87 +- src/compiler/diagnostics.h | 13 +- src/compiler/lexer.c | 146 +- src/compiler/lexer.h | 28 +- src/compiler/module.c | 8 + src/compiler/parser.c | 3063 +++++++++++++++++++++--- src/compiler/parser.h | 15 + src/compiler/semantic_analyser.c | 420 +++- src/compiler/semantic_analyser.h | 25 +- src/compiler/source_file.c | 4 +- src/compiler/symtab.c | 8 +- src/compiler/tokens.c | 126 +- src/compiler/tokens.h | 75 +- src/compiler/value.c | 902 +++++++ src/compiler/value.h | 87 + src/compiler_tests/tests.c | 7 +- src/main.c | 2 + src/utils/errors.c | 7 +- src/utils/errors.h | 5 +- src/utils/file_utils.c | 4 +- src/utils/lib.h | 28 +- src/utils/malloc.c | 8 +- 38 files changed, 9753 insertions(+), 545 deletions(-) create mode 100644 resources/c3.l create mode 100644 resources/grammar.y create mode 100644 resources/testfragments/compiletest.c3 create mode 100644 resources/testfragments/parsertest.c3 create mode 100644 src/compiler/ast.c create mode 100644 src/compiler/ast.h create mode 100644 src/compiler/bigint.c create mode 100644 src/compiler/bigint.h create mode 100644 src/compiler/context.c create mode 100644 src/compiler/context.h create mode 100644 src/compiler/module.c create mode 100644 src/compiler/value.c create mode 100644 src/compiler/value.h diff --git a/CMakeLists.txt b/CMakeLists.txt index a621b431c..fdf909d82 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,6 @@ cmake_minimum_required(VERSION 3.13) project(c3c C) set(CMAKE_CXX_FLAGS_RELEASE "-O3") - set(CMAKE_C_STANDARD 11) include_directories( @@ -19,4 +18,14 @@ add_executable(c3c src/compiler/symtab.c src/compiler/parser.c src/compiler_tests/tests.c - src/compiler_tests/benchmark.c src/utils/malloc.c src/utils/malloc.h src/compiler/compiler.c src/compiler/compiler.h src/compiler/semantic_analyser.c src/compiler/semantic_analyser.h src/utils/common.h src/compiler/source_file.c src/compiler/source_file.h src/compiler/diagnostics.c src/compiler/diagnostics.h) \ No newline at end of file + src/compiler_tests/benchmark.c + src/utils/malloc.c + src/compiler/compiler.c + src/compiler/semantic_analyser.c + src/compiler/source_file.c + src/compiler/diagnostics.c + src/compiler/ast.c + src/compiler/module.c + src/compiler/value.c src/compiler/value.h src/compiler/bigint.c src/compiler/bigint.h src/compiler/context.c) + +target_compile_options(c3c PRIVATE -Werror -Wall -Wextra -Wno-unused-function -Wno-unused-variable -Wno-unused-parameter) diff --git a/README.md b/README.md index 72e972049..2ff3e773f 100644 --- a/README.md +++ b/README.md @@ -18,4 +18,6 @@ C3 tries to be an alternative in the the C/C++ niche: fast and close to the meta Most work is still being done in the design draft here: https://c3lang.github.io/c3docs/. If you have suggestions, send a mail to [christoffer@aegik.com](mailto:christoffer@aegik.com), [file an issue](https://github.com/c3lang/c3c/issues) or discuss C3 on the r/ProgrammingLanguages Discord server: https://discord.gg/cfu4wdk -There are some small work being done, in particular lifting some code from an earlier "work-in-progress" C2 compiler called [Titanos](https://github.com/lerno/titanos). +There are some small work being done on the parser here, but most of the structure is still missing. + +If you wish to contribute with ideas, please file issues on the c3docs: https://github.com/c3lang/c3docs instead of the compiler. diff --git a/resources/c3.l b/resources/c3.l new file mode 100644 index 000000000..3927a0bac --- /dev/null +++ b/resources/c3.l @@ -0,0 +1,179 @@ + +D [0-9] +UN [_] +L [a-zA-Z_] +AN [a-zA-Z_0-9] +H [a-fA-F0-9] +UA [A-Z_0-9] +DC [a-z] +UC [A-Z] +E [Ee][+-]?{D}+ +FS (f|F|l|L) +IS (u|U|l|L)* + +%{ +#include +#include "y.tab.h" +void count(void); +void comment(void); + +%} + +%% +"/*" { comment(); } + +"break" { count(); return(BREAK); } +"case" { count(); return(CASE); } +"char" { count(); return(CHAR); } +"const" { count(); return(CONST); } +"continue" { count(); return(CONTINUE); } +"default" { count(); return(DEFAULT); } +"do" { count(); return(DO); } +"double" { count(); return(DOUBLE); } +"else" { count(); return(ELSE); } +"enum" { count(); return(ENUM); } +"float" { count(); return(FLOAT); } +"for" { count(); return(FOR); } +"goto" { count(); return(GOTO); } +"if" { count(); return(IF); } +"int" { count(); return(INT); } +"uint" { count(); return(UINT); } +"long" { count(); return(LONG); } +"ulong" { count(); return(ULONG); } +"return" { count(); return(RETURN); } +"short" { count(); return(SHORT); } +"ushort" { count(); return(USHORT); } +"sizeof" { count(); return(SIZEOF); } +"local" { count(); return(LOCAL); } +"type" { count(); return(TYPE); } +"error" { count(); return(ERROR); } +"module" { count(); return(MODULE); } +"as" { count(); return(AS); } +"import" { count(); return(IMPORT); } +"generic" { count(); return(GENERIC); } +"struct" { count(); return(STRUCT); } +"switch" { count(); return(SWITCH); } +"typedef" { count(); return(TYPEDEF); } +"union" { count(); return(UNION); } +"void" { count(); return(VOID); } +"volatile" { count(); return(VOLATILE); } +"while" { count(); return(WHILE); } +"throw" { count(); return(THROW); } +"throws" { count(); return(THROWS); } +"func" { count(); return(FUNC); } +"nil" { count(); return(NIL); } +"next" { count(); return(NEXT); + +[_]*[A-Z]{UA}* { count(); return(CONST_IDENT); } +[_]*[A-Z]{UA}*[a-z]{AN}* { count(); return(TYPE_IDENT); } +[_]*[a-z]{AN}* { count(); return(IDENT); } +@{L}+[!]? { count(); return(AT_IDENT); } +${L}+ { count(); return(CT_IDENT); } +#{L}+ { count(); return(HASH_IDENT); } +0[xX]{H}+{IS}? { count(); return(CONSTANT); } +0{D}+{IS}? { count(); return(CONSTANT); } +{D}+{IS}? { count(); return(CONSTANT); } +L?'(\\.|[^\\'])+' { count(); return(CONSTANT); } + +{D}+{E}{FS}? { count(); return(CONSTANT); } +{D}*"."{D}+({E})?{FS}? { count(); return(CONSTANT); } +{D}+"."{D}*({E})?{FS}? { count(); return(CONSTANT); } + +L?\"(\\.|[^\\"])*\" { count(); return(STRING_LITERAL); } + +"..." { count(); return(ELLIPSIS); } +">>=" { count(); return(RIGHT_ASSIGN); } +"<<=" { count(); return(LEFT_ASSIGN); } +"+=" { count(); return(ADD_ASSIGN); } +"-=" { count(); return(SUB_ASSIGN); } +"*=" { count(); return(MUL_ASSIGN); } +"/=" { count(); return(DIV_ASSIGN); } +"%=" { count(); return(MOD_ASSIGN); } +"&=" { count(); return(AND_ASSIGN); } +"^=" { count(); return(XOR_ASSIGN); } +"|=" { count(); return(OR_ASSIGN); } +">>" { count(); return(RIGHT_OP); } +"<<" { count(); return(LEFT_OP); } +"++" { count(); return(INC_OP); } +"--" { count(); return(DEC_OP); } +"&&" { count(); return(AND_OP); } +"||" { count(); return(OR_OP); } +"<=" { count(); return(LE_OP); } +">=" { count(); return(GE_OP); } +"==" { count(); return(EQ_OP); } +"!=" { count(); return(NE_OP); } +"::" { count(); return(SCOPE); } +"?:" { count(); return(ELVIS); } +";" { count(); return(';'); } +("{") { count(); return('{'); } +("}") { count(); return('}'); } +"," { count(); return(','); } +":" { count(); return(':'); } +"=" { count(); return('='); } +"(" { count(); return('('); } +")" { count(); return(')'); } +("[") { count(); return('['); } +("]") { count(); return(']'); } +"." { count(); return('.'); } +"&" { count(); return('&'); } +"!" { count(); return('!'); } +"~" { count(); return('~'); } +"-" { count(); return('-'); } +"+" { count(); return('+'); } +"*" { count(); return('*'); } +"/" { count(); return('/'); } +"%" { count(); return('%'); } +"<" { count(); return('<'); } +">" { count(); return('>'); } +"^" { count(); return('^'); } +"|" { count(); return('|'); } +"?" { count(); return('?'); } + +[ \t\v\n\f] { count(); } +. { /* ignore bad characters */ } + +%% + +int yywrap(void) +{ + return 1; +} + + +void comment(void) +{ + char c, c1; + +loop: + while ((c = input()) != '*' && c != 0) + putchar(c); + + if ((c1 = input()) != '/' && c != 0) + { + unput(c1); + goto loop; + } + + if (c != 0) + putchar(c1); +} + + +int column = 0; + +void count(void) +{ + int i; + + for (i = 0; yytext[i] != '\0'; i++) + if (yytext[i] == '\n') + column = 0; + else if (yytext[i] == '\t') + column += 8 - (column % 8); + else + column++; + + ECHO; +} + + diff --git a/resources/grammar.y b/resources/grammar.y new file mode 100644 index 000000000..99e26b27e --- /dev/null +++ b/resources/grammar.y @@ -0,0 +1,697 @@ +%{ + +#include +#define YYERROR_VERBOSE + +extern char yytext[]; +extern int column; +int yylex(void); +void yyerror(char *s); +%} + +%token IDENT AT_IDENT CT_IDENT CONSTANT CONST_IDENT TYPE_IDENT STRING_LITERAL SIZEOF +%token INC_OP DEC_OP LEFT_OP RIGHT_OP LE_OP GE_OP EQ_OP NE_OP +%token AND_OP OR_OP MUL_ASSIGN DIV_ASSIGN MOD_ASSIGN ADD_ASSIGN +%token SUB_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN +%token XOR_ASSIGN OR_ASSIGN VAR NIL ELVIS HASH_IDENT NEXT + +%token TYPEDEF MODULE IMPORT +%token CHAR SHORT INT LONG FLOAT DOUBLE CONST VOLATILE VOID +%token BYTE USHORT UINT ULONG BOOL +%token STRUCT UNION ENUM ELLIPSIS AS LOCAL + +%token CASE DEFAULT IF ELSE SWITCH WHILE DO FOR GOTO CONTINUE BREAK RETURN +%token TYPE FUNC ERROR MACRO GENERIC CTIF CTELIF CTENDIF CTELSE CTSWITCH CTCASE CTDEFAULT CTEACH +%token THROWS THROW TRY CATCH SCOPE PUBLIC DEFER ATTRIBUTE + +%start translation_unit +%% + +ident_scope + : IDENT SCOPE + ; + +ident_expression + : CONST_IDENT + | IDENT + | CT_IDENT + | AT_IDENT + ; + +primary_expression + : STRING_LITERAL + | CONSTANT + | NIL + | ident_scope ident_expression + | ident_expression + | base_type initializer_list + | base_type '.' IDENT + | TYPE '(' type_expression ')' + | '(' expression ')' + ; + +postfix_expression + : primary_expression + | postfix_expression '[' expression ']' + | postfix_expression '(' ')' + | postfix_expression '(' argument_expression_list ')' + | postfix_expression '.' IDENT + | postfix_expression INC_OP + | postfix_expression DEC_OP + ; + +argument_expression_list + : expression + | argument_expression_list ',' expression + ; + +unary_expression + : postfix_expression + | INC_OP unary_expression + | DEC_OP unary_expression + | unary_operator unary_expression + | SIZEOF '(' type_expression ')' + ; + +unary_operator + : '&' + | '*' + | '+' + | '-' + | '~' + | '!' + ; + + +multiplicative_expression + : unary_expression + | multiplicative_expression '*' unary_expression + | multiplicative_expression '/' unary_expression + | multiplicative_expression '%' unary_expression + ; + +shift_expression + : multiplicative_expression + | shift_expression LEFT_OP multiplicative_expression + | shift_expression RIGHT_OP multiplicative_expression + ; + +bit_expression + : shift_expression + | bit_expression '&' shift_expression + | bit_expression '^' shift_expression + | bit_expression '|' shift_expression + ; + +additive_expression + : bit_expression + | additive_expression '+' bit_expression + | additive_expression '-' bit_expression + ; + +relational_expression + : additive_expression + | relational_expression '<' additive_expression + | relational_expression '>' additive_expression + | relational_expression LE_OP additive_expression + | relational_expression GE_OP additive_expression + | relational_expression EQ_OP additive_expression + | relational_expression NE_OP additive_expression + ; + +logical_expression + : relational_expression + | logical_expression AND_OP relational_expression + | logical_expression OR_OP relational_expression + ; + +conditional_expression + : logical_expression + | logical_expression '?' expression ':' conditional_expression + | logical_expression ELVIS conditional_expression + ; + +assignment_expression + : conditional_expression + | unary_expression assignment_operator assignment_expression + | unary_expression '=' initializer_list + ; + +expression + : assignment_expression + | TRY assignment_expression + | TRY assignment_expression ELSE assignment_expression + ; + + +assignment_operator + : '=' + | MUL_ASSIGN + | DIV_ASSIGN + | MOD_ASSIGN + | ADD_ASSIGN + | SUB_ASSIGN + | LEFT_ASSIGN + | RIGHT_ASSIGN + | AND_ASSIGN + | XOR_ASSIGN + | OR_ASSIGN + ; + +constant_expression + : conditional_expression + ; + + +enumerators + : enumerator + | enumerators ',' enumerator + ; +enumerator_list + : enumerators + | enumerators ',' + ; + +enumerator + : CONST_IDENT + | CONST_IDENT '=' constant_expression + ; + +identifier_list + : IDENT + | identifier_list ',' IDENT + ; + +macro_argument + : CT_IDENT + | IDENT + ; + +macro_argument_list + : macro_argument + | macro_argument_list ',' macro_argument + ; + +implicit_decl + : IDENT + | IDENT '=' initializer + ; + +explicit_decl + : type_expression IDENT '=' initializer + | type_expression IDENT + ; + +declaration + : explicit_decl + | explicit_decl ',' implicit_decl + | explicit_decl ',' explicit_decl + ; + +declaration_list + : declaration + ; + +param_declaration + : type_expression + | type_expression IDENT + | type_expression IDENT '=' initializer + ; + +parameter_type_list + : parameter_list + | parameter_list ',' ELLIPSIS + | parameter_list ',' type_expression ELLIPSIS + ; + +opt_parameter_type_list + : '(' ')' + | '(' parameter_type_list ')' + ; + +parameter_list + : param_declaration + | parameter_list ',' param_declaration + ; + +base_type + : VOID + | BOOL + | CHAR + | BYTE + | SHORT + | USHORT + | INT + | UINT + | LONG + | ULONG + | FLOAT + | DOUBLE + | TYPE_IDENT + | ident_scope TYPE_IDENT + | TYPE '(' constant_expression ')' + ; + +type_expression + : base_type + | type_expression '*' + | type_expression '&' + | type_expression '[' constant_expression ']' + | type_expression '[' ']' + | type_expression '[' '+' ']' + ; + +initializer + : expression + | initializer_list + ; + +initializer_values + : initializer + | initializer_values ',' initializer + ; + +initializer_list + : '{' initializer_values '}' + | '{' initializer_values ',' '}' + ; + +ct_case_statement + : CTCASE type_list ':' statement + | CTDEFAULT ':' statement + ; + +ct_elif_body + : ct_elif compound_statement + | ct_elif_body ct_elif compound_statement + ; + +ct_else_body + : ct_elif_body + | CTELSE compound_statement + | ct_elif_body CTELSE compound_statement + ; + +ct_switch_body + : ct_case_statement + | ct_switch_body ct_case_statement + ; + +ct_statement + : ct_if compound_statement + | ct_if compound_statement ct_else_body + | ct_switch '{' ct_switch_body '}' + | CTEACH '(' expression AS CT_IDENT ')' statement + ; + +throw_statement + : THROW expression ';' + +statement + : compound_statement + | labeled_statement + | expression_statement + | selection_statement + | iteration_statement + | jump_statement + | declaration_statement + | volatile_statement + | catch_statement + | try_statement + | defer_statement + | ct_statement + | throw_statement + ; + +defer_catch_body + : compound_statement + | expression_statement + | jump_statement + | iteration_statement + | selection_statement + ; + +defer_statement + : DEFER defer_catch_body + | DEFER catch_statement + ; + +catch_statement + : CATCH '(' type_expression IDENT ')' defer_catch_body + | CATCH '(' ERROR IDENT ')' defer_catch_body + ; + +try_statement + : TRY selection_statement + | TRY iteration_statement + | TRY jump_statement + ; + +volatile_statement + : VOLATILE compound_statement + ; + +label_statement + : IDENT ':' statement + + +labeled_statement + : label_statement + | CASE constant_expression ':' + | DEFAULT ':' + ; + +compound_statement + : '{' '}' + | '{' statement_list '}' + ; + +statement_list + : statement + | statement_list statement + ; + +declaration_statement + : declaration ';' + ; + +expression_statement + : ';' + | expression ';' + ; + + +control_expression + : decl_or_expr_list + | declaration_list ';' decl_or_expr_list + ; + +selection_statement + : IF '(' control_expression ')' statement + | IF '(' control_expression ')' compound_statement ELSE statement + | SWITCH '(' control_expression ')' compound_statement + ; + +expression_list + : expression + | expression_list ',' expression + ; + +decl_or_expr_list + : expression_list + | declaration_list + ; + +for_statement + : FOR '(' decl_or_expr_list ';' expression_statement ')' statement + | FOR '(' decl_or_expr_list ';' expression_statement expression_list ')' statement + ; + +iteration_statement + : WHILE '(' control_expression ')' statement + | DO statement WHILE '(' expression ')' ';' + | for_statement + ; + +jump_statement + : GOTO CONSTANT ';' + | CONTINUE ';' + | BREAK ';' + | RETURN ';' + | RETURN expression ';' + ; + +attribute + : AT_IDENT + | IDENT SCOPE AT_IDENT + | AT_IDENT '(' constant_expression ')' + | IDENT SCOPE AT_IDENT '(' constant_expression ')' + ; + +attribute_list + : attribute + | attribute_list attribute + ; + +opt_attributes + : attribute_list + | + ; + +error_type + : IDENT SCOPE TYPE_IDENT + | TYPE_IDENT + | ERROR '(' expression ')' + ; + +error_list + : error_type + | error_list error_type + ; + +throw_declaration + : THROWS + | THROWS error_list + ; + +opt_throw_declaration + : throw_declaration + | + ; + +func_name + : IDENT SCOPE TYPE_IDENT '.' IDENT + | TYPE_IDENT '.' IDENT + | IDENT + ; + +func_declaration + : FUNC type_expression func_name opt_parameter_type_list opt_attributes opt_throw_declaration + ; + +func_definition + : func_declaration compound_statement + | func_declaration ';' + ; + +macro_declaration + : MACRO AT_IDENT '(' macro_argument_list ')' compound_statement + ; + + +struct_or_union + : STRUCT + | UNION + ; + +struct_declaration + : struct_or_union TYPE_IDENT opt_attributes struct_body + ; + +struct_body + : '{' struct_declaration_list '}' + ; + +struct_declaration_list + : struct_member_declaration + | struct_declaration_list struct_member_declaration + ; + +struct_member_declaration + : type_expression identifier_list opt_attributes ';' + | struct_or_union IDENT opt_attributes struct_body + | struct_or_union opt_attributes struct_body + ; + +enum_declaration + : ENUM TYPE_IDENT ':' type_expression opt_attributes '{' enumerator_list '}' + | ENUM TYPE_IDENT opt_attributes '{' enumerator_list '}' + ; + +errors + : CONST_IDENT + | errors ',' CONST_IDENT + ; + +error_list + : errors + | errors ',' + ; + +error_declaration + : ERROR TYPE_IDENT '{' error_list '}' + ; + +type_list + : type_expression + | type_list ',' type_expression + ; + +generics_case + : CASE type_list ':' statement + +generics_body + : generics_case + | generics_body generics_case + ; + +generics_declaration + : GENERIC IDENT '(' macro_argument_list ')' '{' generics_body '}' + | GENERIC type_expression IDENT '(' macro_argument_list ')' '{' generics_body '}' + ; + +const_declaration + : CONST CT_IDENT '=' initializer ';' + | CONST type_expression IDENT '=' initializer ';' + ; + +func_typedef + : FUNC type_expression opt_parameter_type_list opt_throw_declaration + ; + +typedef_declaration + : TYPEDEF type_expression AS TYPE_IDENT ';' + | TYPEDEF func_typedef AS TYPE_IDENT ';' + ; + +attribute_domain + : FUNC + | VAR + | ENUM + | STRUCT + | UNION + | TYPEDEF + | CONST + ; + +attribute_domains + : attribute_domain + | attribute_domains ',' attribute_domain + ; + +attribute_declaration + : ATTRIBUTE AT_IDENT attribute_domains + | ATTRIBUTE AT_IDENT attribute_domains '(' parameter_type_list ')' + ; + +global_declaration + : type_expression IDENT ';' + | type_expression IDENT '=' initializer ';' + ; + +ct_if + : CTIF '(' expression ')' + ; + +ct_elif + : CTELIF '(' expression ')' + ; + +ct_switch + : CTSWITCH '(' expression ')' + ; + +top_level_block + : '{' top_level_statements '}' + ; + +tl_ct_elif_body + : ct_elif top_level_block + | tl_ct_elif_body ct_elif top_level_block + ; + +tl_ct_else_body + : tl_ct_elif_body + | tl_ct_else_body CTELSE top_level_block + ; + +tl_ct_case + : CTCASE type_list ':' top_level_statements + | CTDEFAULT ':' top_level_statements + ; + +tl_ct_switch_body + : tl_ct_case + | tl_ct_switch_body tl_ct_case + ; + +conditional_compilation + : ct_if top_level_block + | ct_if top_level_block tl_ct_else_body + | ct_switch '{' tl_ct_switch_body '}' + ; + +module_param + : CT_IDENT + | HASH_IDENT + | TYPE_IDENT + | AT_IDENT + ; + +module_params + : module_param + | module_params ',' module_param + ; + +module + : MODULE IDENT ';' + | MODULE IDENT '(' module_params ')' ';' + ; + +import_decl + : IMPORT IDENT ';' + | IMPORT IDENT AS IDENT ';' + | IMPORT IDENT AS IDENT LOCAL ';' + | IMPORT IDENT LOCAL ';' + ; + +imports + : import_decl + | imports import_decl + ; + +translation_unit + : module imports top_level_statements + ; + +top_level_statements + : visibility top_level + | top_level_statements visibility top_level + ; + +visibility + : LOCAL + | PUBLIC + | LOCAL PUBLIC + | PUBLIC LOCAL + | + ; + +top_level + : func_definition + | conditional_compilation + | struct_declaration + | attribute_declaration + | enum_declaration + | error_declaration + | const_declaration + | global_declaration + | macro_declaration + | generics_declaration + | typedef_declaration + ; + + +%% + +void yyerror(char *s) +{ + fflush(stdout); + printf("\n%*s\n%*s\n", column, "^", column, s); +} + +int main(int argc, char *argv[]) +{ + yyparse(); + return(0); +} \ No newline at end of file diff --git a/resources/testfragments/compiletest.c3 b/resources/testfragments/compiletest.c3 new file mode 100644 index 000000000..8f67c0fd7 --- /dev/null +++ b/resources/testfragments/compiletest.c3 @@ -0,0 +1,11 @@ +module foo; + +func void test() +{ + return; +} + +func int test2() +{ + return; +} \ No newline at end of file diff --git a/resources/testfragments/parsertest.c3 b/resources/testfragments/parsertest.c3 new file mode 100644 index 000000000..738ca6d24 --- /dev/null +++ b/resources/testfragments/parsertest.c3 @@ -0,0 +1,209 @@ +module foo ($foo, #bar, Integer); +import bar as eok local; +import bar2 as eok2; +import bar3 local; + +macro void @foo(int i, $e) +{ + $e = 1; + printf("Helo"); +} + +macro @goo(i, $e) +{ + +} + +macro @soom!(i, $e) +{} + +local struct Foom +{ + int i; + Foom *test; + int*** j; + int*[][]* k; +} + +struct Hej +{ + int x; +} + +enum FEok : int { + IFEJ +} + +enum Test +{ + FOO = 1 + 2, + BAR, +} + +enum Test2 : int +{ + FOO = 1, + BAR, +} + +union Foomt +{ + int i; + double d; +} + +error Errors +{ + BADERROR, + OTHER_ERROR +} + +func Foom test(int a) +{ + return 1 + 2; +} + +func boo::Bar zab::Baz.sd(die::Eij i) throws Zab // , sij:Zig +{ + float a = 0, b = 3, double c = 1, d; + int i = 0; +} + +generic int boor(i) +{ + case int: + return 1; + case double: + return 100; + default: + return 1000; +} + +generic boor2(i) +{ + case int: + return "Helo"; + default: + return 1000; +} + +$if ($e > 0) +{ + func void foo() {} +} +$elif ($e < 0) +{ + func void foo() { printf("HELO"); } +} +$else +{ + func void foo() { printf("OLEH"); } +} + +$if ($e > 0) +{ + func void foo() {} +} + +$if ($b > 0) +{ +} +$else +{ + generic test(i) { } +} + +generic boofer2(i, g, eok) +{ + case int, char[], type($eoo): + return "Helo"; + default: + return 1000; +} + +func void hello() throws Errors +{ + int i, j; + throw FOO; + throw awesome::FOO; + defer close(b); + foo::Bar x = 3; + try foo(); + try foo() else 1; + foo(try 1); + type($error) fk; + type(int).size + fk; + Errors {}; + Ferrors{a = 1, b = 20, b = { token }}; + Ferrors{1, 3, 1+4}; + $erro = 1; + FOO: + goto FOO; + type($error) fk; + foo::@macrof(); + int i = foo ? 2 : 4; + @macros(); + type(foo::y) z; + type(int) * 2; + $error = type(int); + int[4] a; + foo[1 + 2] * b; + type((i > 0) ? type(int) : type(double)) doek; + $e = type(type(type(Bar))); + $e = foo ? type(int) : type(Bar); + $e = type(type(foo::$eofk)); + if (a == 0 && 1 == b) + { + i = 0; + } + while (bpb >= 3) + { + a(); + } + do + { + } while (0); + for (i = 0;;) + {} + for (i = 0, j = 3; i < 0; i++, j++) {} + for (int i = 0; i < 100; i++) + { + i++; + } + int i = 1; + i + 1 * 100; + &i; + int j = i; + 2; + i++; + switch (int foo = 1; bar) + { + case 1: + next; + continue; + default: + break; + } + do { + i++; + } while (a < 0); + while (a > 0) + { + a--; + } + while (int a = 4; int b = 20) + { + a + 1; + } + return; +} + +typedef Foo* as Bar; +typedef func void(int, Foo*) as Zoo; + + + +func void test2() +{ + return; +} \ No newline at end of file diff --git a/src/build/build_options.c b/src/build/build_options.c index b50239b2f..84c36c936 100644 --- a/src/build/build_options.c +++ b/src/build/build_options.c @@ -50,6 +50,8 @@ static void usage(void) OUTPUT(" --template