├── success ├── simple.cvc ├── empty_if.cvc ├── empty_function.cvc ├── nest_array_size.cvc ├── minus.cvc ├── types.cvc ├── new_global_order.cvc ├── types_monop.cvc ├── cast.cvc ├── types_expressions.cvc ├── types_more_monop.cvc ├── array_super_simple.cvc ├── preprocessor.cvc ├── basic.cvc ├── var_after_fun_global.cvc ├── array_nd.cvc ├── cast_expression.cvc ├── scope.cvc ├── types_parameters.cvc ├── early_return.cvc ├── boolean_monop.cvc ├── fun_after_var.cvc ├── array_simple.cvc ├── do-while.cvc ├── early_return_reversed.cvc ├── for_scope.cvc ├── very_basic.cvc ├── reverse_for.cvc ├── types_funcall.cvc ├── array_short_assignment.cvc ├── boolean_comparison.cvc ├── nested_funcall.cvc ├── cast_boolean.cvc ├── side_effects.cvc ├── short_circuit.cvc ├── array_def_side_effects.cvc ├── order_of_operations.cvc ├── short_circuit_or.cvc ├── monop.cvc ├── pop_funreturn.cvc ├── global.cvc ├── if_else.cvc ├── dynamic_array_size.cvc ├── useless_function.cvc ├── civic.h ├── array.cvc ├── short_circuit_long.cvc ├── useless_cast.cvc ├── cast_boolean_to_int.cvc ├── array_size.cvc ├── array_dimension_expansion.cvc ├── recursion.cvc ├── for_loop_evaluation.cvc ├── global_deep.cvc ├── indexing.cvc ├── local_array.cvc ├── factorial_simple.cvc ├── euclid_simple.cvc ├── localfuns.cvc ├── factorial_local.cvc ├── complex_comparisons.cvc ├── fibonacci_simple.cvc ├── loops.cvc ├── euclid_local.cvc ├── fibonacci_local.cvc ├── primes_simple.cvc ├── print_matrix.cvc ├── primes_local.cvc ├── queens.cvc └── quicksort.cvc ├── fail ├── garbage.cvc ├── empty.cvc ├── missing_sbrackets.cvc ├── index_none_array.cvc ├── reinit_array.cvc ├── floating_comma.cvc ├── local_export.cvc ├── types_negate.cvc ├── void_variable.cvc ├── floating_comma_funcall.cvc ├── bad_float.cvc ├── for_induction_var.cvc ├── non_array_init.cvc ├── bad_array.cvc ├── int_in_boolean.cvc ├── reinit_array_hardcode.cvc ├── return_in_if.cvc ├── bad_array_parameter_negative.cvc ├── not_bool_if.cvc ├── not_bool_loop.cvc ├── modulus.cvc ├── types_return.cvc ├── boolean_operator_abuse.cvc ├── lone_else.cvc ├── array_hardcode.cvc ├── arrayformat.cvc ├── bad_for_loop_small.cvc ├── bad_init.cvc ├── boolean_arithmetic.cvc ├── for_without_body.cvc ├── arrayformat_comma.cvc ├── bad_for_loop.cvc ├── order.cvc ├── array_parameter_length.cvc ├── arraytype.cvc ├── overflow.cvc ├── array_wrong_dimensions.cvc ├── types.cvc ├── short_circuit_bad.cvc ├── array_invalid_assignment_nd.cvc ├── if_else_return.cvc ├── types_monop.cvc ├── redefine.cvc ├── array_invalid_assignment_nd_more.cvc ├── types_more_monop.cvc ├── extra.cvc ├── no_return.cvc ├── types_expressions.cvc ├── double_param.cvc ├── types_parameters_length.cvc ├── types_parameters_list.cvc ├── types_parameters_length_reverse.cvc ├── types_binop.cvc ├── var_after_fun.cvc ├── types_funcall.cvc ├── types_parameters.cvc ├── types_parameters_mixed.cvc ├── civic.h ├── types_return_multiple.cvc ├── duplicate.cvc ├── bad_array_parameter_size_reverse.cvc ├── empty_array_parameter_size.cvc └── bad_array_parameter_size.cvc ├── runtime ├── extern.cvc ├── bad_array_parameter_dec.cvc ├── bad_array_parameter_dec_zero.cvc ├── embargo.cvc ├── array_invalid_index.cvc └── array_invalid_index_nd.cvc ├── user ├── civic.h ├── scan_matrix.cvc └── matrix_mult.cvc ├── LICENSE.md ├── test.sh ├── patches ├── fix_preprocessor.diff └── fix_unions.diff └── README.md /success/simple.cvc: -------------------------------------------------------------------------------- 1 | export int main() { 2 | return 0; 3 | } 4 | -------------------------------------------------------------------------------- /fail/garbage.cvc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stephenswat/cocosnoot/HEAD/fail/garbage.cvc -------------------------------------------------------------------------------- /success/empty_if.cvc: -------------------------------------------------------------------------------- 1 | export int main() { 2 | if (true) {} 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /fail/empty.cvc: -------------------------------------------------------------------------------- 1 | // Should produce an error because a program needs at least one declaration. 2 | -------------------------------------------------------------------------------- /success/empty_function.cvc: -------------------------------------------------------------------------------- 1 | void foo() {} 2 | 3 | export int main() { 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /fail/missing_sbrackets.cvc: -------------------------------------------------------------------------------- 1 | export int main() { 2 | int [3] = 1, 1, 1; 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /fail/index_none_array.cvc: -------------------------------------------------------------------------------- 1 | export int main() { 2 | int a = 5; 3 | int b = a[2]; 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /fail/reinit_array.cvc: -------------------------------------------------------------------------------- 1 | export int main() { 2 | int[5] a = 0; 3 | a = 1; 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /runtime/extern.cvc: -------------------------------------------------------------------------------- 1 | extern int a; 2 | extern int[a] b; 3 | 4 | export int main() { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /fail/floating_comma.cvc: -------------------------------------------------------------------------------- 1 | void (5, 6,) {} 2 | 3 | export int main() { 4 | foo(4, 6); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /fail/local_export.cvc: -------------------------------------------------------------------------------- 1 | export int main() { 2 | int a = 5; 3 | export int b = 0; 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /fail/types_negate.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | int a = !0; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /fail/void_variable.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | void a; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /success/nest_array_size.cvc: -------------------------------------------------------------------------------- 1 | int a = 5; 2 | 3 | export int main() { 4 | int[a] a = 5; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /fail/floating_comma_funcall.cvc: -------------------------------------------------------------------------------- 1 | void (5, 6) {} 2 | 3 | export int main() { 4 | foo(4, 6,); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /fail/bad_float.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | float a = 5.654.4667; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /fail/for_induction_var.cvc: -------------------------------------------------------------------------------- 1 | export int main() { 2 | for(int i = 0, 20) 3 | i = i + i; 4 | return 1; 5 | } 6 | -------------------------------------------------------------------------------- /fail/non_array_init.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | int a = [1, 2, 4]; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /success/minus.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | printInt(5--6----(5-6)); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /success/types.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | int a = 0; 5 | a = 7; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /fail/bad_array.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | float[5] a = 4, 5, 7, 8, 9; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /fail/int_in_boolean.cvc: -------------------------------------------------------------------------------- 1 | export int main() { 2 | bool[6] a = true; 3 | if (false && 5 && false) {} 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /fail/reinit_array_hardcode.cvc: -------------------------------------------------------------------------------- 1 | export int main() { 2 | int[5] a = 0; 3 | a = [1, 1, 1, 1, 1]; 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /runtime/bad_array_parameter_dec.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | int[5, -1] a; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /fail/return_in_if.cvc: -------------------------------------------------------------------------------- 1 | export int main() { 2 | if (true) { 3 | return 1; 4 | } else { 5 | return 0; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /success/new_global_order.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | printInt(a); 5 | return 0; 6 | } 7 | 8 | int a = 5; 9 | -------------------------------------------------------------------------------- /fail/bad_array_parameter_negative.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | void foo(int[n, -m] b) {} 4 | 5 | export int main() { 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /fail/not_bool_if.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | if (5) { 5 | printInt(1); 6 | } 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /fail/not_bool_loop.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | while (5) { 5 | printInt(1); 6 | } 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /fail/modulus.cvc: -------------------------------------------------------------------------------- 1 | // Modulus only works on integers. 2 | 3 | #include "civic.h" 4 | 5 | export int main() { 6 | 6.0 % 5.0; 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /runtime/bad_array_parameter_dec_zero.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | int[4, 0, 4] array_not_found; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /success/types_monop.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | int a = 0; 5 | a = -5; 6 | printInt(a); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /runtime/embargo.cvc: -------------------------------------------------------------------------------- 1 | // Should produce an error in the VM because no main is exported. 2 | 3 | #include "civic.h" 4 | 5 | int main() { 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /success/cast.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | int a = 10; 5 | float b = (float) a; 6 | printFloat(b); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /success/types_expressions.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | float a = 0.0; 5 | a = (5.0 + 7.0); 6 | printFloat(a); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /success/types_more_monop.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | float a = 0.0; 5 | a = -(5.0 * 6.0); 6 | printFloat(a); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /fail/types_return.cvc: -------------------------------------------------------------------------------- 1 | // Should give a type checking error because a int function cannot return float. 2 | 3 | int fun() { 4 | return 6.0; 5 | } 6 | 7 | export int main() {} 8 | -------------------------------------------------------------------------------- /success/array_super_simple.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | int[5] a; 5 | a[2] = 3; 6 | 7 | printInt(a[2]); 8 | 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /success/preprocessor.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | #define N 100 3 | 4 | export int main() { 5 | if (N == 100) { 6 | printInt(N); 7 | } 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /fail/boolean_operator_abuse.cvc: -------------------------------------------------------------------------------- 1 | // Comparisons don't work on booleans, except for ==. 2 | 3 | #include "civic.h" 4 | 5 | export int main() { 6 | if (4 && 7) {} 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /fail/lone_else.cvc: -------------------------------------------------------------------------------- 1 | // Should produce a type checking error because binop types should match. 2 | 3 | #include "civic.h" 4 | 5 | export int main() { 6 | else {} 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /success/basic.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | int a = 5; 5 | int b; 6 | b = a + 2; 7 | a = 7; 8 | printInt(b); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /success/var_after_fun_global.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | void kaas() { 4 | printInt(6); 5 | } 6 | 7 | int a = 0; 8 | 9 | export int main() { 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /fail/array_hardcode.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | void foo(int[n] a) { 4 | printInt(a[0]); 5 | } 6 | 7 | export int main() { 8 | foo([0, 1, 2]); 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /fail/arrayformat.cvc: -------------------------------------------------------------------------------- 1 | // Should produce a parser error because a comma is missing. 2 | 3 | #include "civic.h" 4 | 5 | export int main() { 6 | int[4] a = [1, 2 3, 4]; 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /fail/bad_for_loop_small.cvc: -------------------------------------------------------------------------------- 1 | // For-loop needs two or three arguments. 2 | 3 | #include "civic.h" 4 | 5 | export int main() { 6 | for (int i = 0) {} 7 | 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /fail/bad_init.cvc: -------------------------------------------------------------------------------- 1 | // Should produce a type checking error 0 is an int literal, not a float. 2 | 3 | #include "civic.h" 4 | 5 | export int main() { 6 | float a = 0; 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /fail/boolean_arithmetic.cvc: -------------------------------------------------------------------------------- 1 | // Comparisons don't work on booleans, except for ==. 2 | 3 | #include "civic.h" 4 | 5 | export int main() { 6 | if (true > false) {} 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /fail/for_without_body.cvc: -------------------------------------------------------------------------------- 1 | // For-loop needs two or three arguments. 2 | 3 | #include "civic.h" 4 | 5 | export int main() { 6 | for (int i = 0, 5); 7 | 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /fail/arrayformat_comma.cvc: -------------------------------------------------------------------------------- 1 | // Should produce a parser error due to the double comma. 2 | 3 | #include "civic.h" 4 | 5 | export int main() { 6 | int[4] a = [1, 2,, 3, 4]; 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /fail/bad_for_loop.cvc: -------------------------------------------------------------------------------- 1 | // For-loop needs two or three arguments. 2 | 3 | #include "civic.h" 4 | 5 | export int main() { 6 | for (int i = 0, 5, 9, 1) {} 7 | 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /fail/order.cvc: -------------------------------------------------------------------------------- 1 | // Should produce a tree validation error due to vardecs following statement. 2 | 3 | export int main() { 4 | int a = 5; 5 | a = 6; 6 | int b = 7; 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /runtime/array_invalid_index.cvc: -------------------------------------------------------------------------------- 1 | // Should produce a parser error because a comma is missing. 2 | 3 | #include "civic.h" 4 | 5 | export int main() { 6 | int[4] a = 0; 7 | return a[4]; 8 | } 9 | -------------------------------------------------------------------------------- /fail/array_parameter_length.cvc: -------------------------------------------------------------------------------- 1 | // Should give an error because array sizes don't match. 2 | 3 | void fun(int a, int[n] b) {} 4 | 5 | export int main() { 6 | int [2, 2] b = 5; 7 | fun(b); 8 | } 9 | -------------------------------------------------------------------------------- /fail/arraytype.cvc: -------------------------------------------------------------------------------- 1 | // Should produce a type checking error for mixing types in an array. 2 | 3 | #include "civic.h" 4 | 5 | export int main() { 6 | int[4] a = [1, 2, 3.0, 4]; 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /fail/overflow.cvc: -------------------------------------------------------------------------------- 1 | // Should produce a parser error because the integer is too big. 2 | 3 | #include "civic.h" 4 | 5 | export int main() { 6 | int a = 10000000000000000000; 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /success/array_nd.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | int[2, 2] a = 10; 5 | a[1, 1] = 5; 6 | printInt(a[1, 0]); 7 | printInt(a[0, 1]); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /success/cast_expression.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | int a = 10; 5 | int b = (int) ((float) a + 1.6); 6 | 7 | printInt(b); 8 | 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /fail/array_wrong_dimensions.cvc: -------------------------------------------------------------------------------- 1 | // Should produce a parser error because a comma is missing. 2 | 3 | #include "civic.h" 4 | 5 | export int main() { 6 | int[4, 5, 7] a = 0; 7 | return a[2, 2]; 8 | } 9 | -------------------------------------------------------------------------------- /fail/types.cvc: -------------------------------------------------------------------------------- 1 | // Should produce a type checking error because 7.0 is a float. 2 | 3 | #include "civic.h" 4 | 5 | export int main() { 6 | int a = 0; 7 | a = 7.0; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /success/scope.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | int rv = 0; 4 | 5 | void kaas() { 6 | int rv = 1; 7 | } 8 | 9 | export int main() { 10 | kaas(); 11 | printInt(rv); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /success/types_parameters.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | int kaas(float a) { 4 | return 0; 5 | } 6 | 7 | export int main() { 8 | int a = 0; 9 | kaas(5.0 * 6.0); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /fail/short_circuit_bad.cvc: -------------------------------------------------------------------------------- 1 | // Should produce a context analysis error due to a function being undefined. 2 | 3 | int rv = 0; 4 | 5 | export int main() { 6 | if (false && kaas()) {} 7 | return rv; 8 | } 9 | -------------------------------------------------------------------------------- /runtime/array_invalid_index_nd.cvc: -------------------------------------------------------------------------------- 1 | // Should produce a parser error because a comma is missing. 2 | 3 | #include "civic.h" 4 | 5 | export int main() { 6 | int[4, 5, 7] a = 0; 7 | return a[3, 7, 4]; 8 | } 9 | -------------------------------------------------------------------------------- /success/early_return.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | if (true) { 5 | printInt(5); 6 | return 0; 7 | } 8 | 9 | printInt(2); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /success/boolean_monop.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | if (false && !!!!true) { 5 | printInt(1); 6 | } else { 7 | printInt(5); 8 | } 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /success/fun_after_var.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | int a = 6; 5 | 6 | void kaas() { 7 | printInt(a); 8 | } 9 | 10 | kaas(); 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /fail/array_invalid_assignment_nd.cvc: -------------------------------------------------------------------------------- 1 | // Should produce a parser error because a comma is missing. 2 | 3 | #include "civic.h" 4 | 5 | export int main() { 6 | int[4, 5, 1] a = [[4, 6], [6, 1]]; 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /fail/if_else_return.cvc: -------------------------------------------------------------------------------- 1 | // Should give an error because main doesn't end in a return. 2 | 3 | export int main() { 4 | if (true) { 5 | return 1; 6 | } else { 7 | return 2; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /fail/types_monop.cvc: -------------------------------------------------------------------------------- 1 | // Should produce a type checking error because monops also have a type. 2 | 3 | #include "civic.h" 4 | 5 | export int main() { 6 | int a = 0; 7 | a = -5.0; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /success/array_simple.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | int[100] a = 7; 5 | a[2] = 3; 6 | 7 | for (int i = 0, 5) { 8 | printInt(a[i]); 9 | } 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /success/do-while.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | int a = 0; 5 | 6 | do { 7 | a = a + 7; 8 | } while (a < 100); 9 | 10 | printInt(a); 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /success/early_return_reversed.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | if (false) { 5 | printInt(1); 6 | return 1; 7 | } 8 | 9 | printInt(0); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /success/for_scope.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | 4 | export int main() { 5 | int a = 5; 6 | int b = 6; 7 | 8 | for (int a = 0, b) { 9 | printInt(a); 10 | } 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /fail/redefine.cvc: -------------------------------------------------------------------------------- 1 | // Should produce a context analysis error because of a redefined variable. 2 | 3 | #include "civic.h" 4 | 5 | export int main() { 6 | int a = 0; 7 | float a = 5.0; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /success/very_basic.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | int a = 5; 5 | int b; 6 | int c; 7 | b = a + 2; 8 | a = 7; 9 | c = a + b; 10 | printInt(c); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /fail/array_invalid_assignment_nd_more.cvc: -------------------------------------------------------------------------------- 1 | // Should produce a parser error because a comma is missing. 2 | 3 | #include "civic.h" 4 | 5 | export int main() { 6 | int[4, 2] a = [0, 1, 2, 3, 4, 5, 6, 7]; 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /fail/types_more_monop.cvc: -------------------------------------------------------------------------------- 1 | // Should produce a type checking error because monops also have a type. 2 | 3 | #include "civic.h" 4 | 5 | export int main() { 6 | int a = 0; 7 | a = -(5.0 * 6.0); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /success/reverse_for.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | int b = 0; 5 | 6 | for (int i = 0, -10, -7) { 7 | b = b + 1; 8 | } 9 | 10 | printInt(b); 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /success/types_funcall.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | float kaas() { 4 | return 6.0; 5 | } 6 | 7 | export int main() { 8 | float a = 0.0; 9 | a = a + kaas(); 10 | printFloat(a); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /fail/extra.cvc: -------------------------------------------------------------------------------- 1 | // Should produce a syntax error due to operators not in the language. 2 | 3 | export int main() { 4 | int a = 5; 5 | int b; 6 | a += 7 * (((b - b) * 56) + 5); 7 | a++; 8 | a--; 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /fail/no_return.cvc: -------------------------------------------------------------------------------- 1 | // Should produce an error because fun must return something. 2 | 3 | #include "civic.h" 4 | 5 | int fun() { 6 | int v = 5; 7 | } 8 | 9 | export int main() { 10 | fun(); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /fail/types_expressions.cvc: -------------------------------------------------------------------------------- 1 | // Should produce a type checking error because 5.0 + 7.0 is a float value. 2 | 3 | #include "civic.h" 4 | 5 | export int main() { 6 | int a = 0; 7 | a = (5.0 + 7.0); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /success/array_short_assignment.cvc: -------------------------------------------------------------------------------- 1 | // Should produce a parser error because a comma is missing. 2 | 3 | #include "civic.h" 4 | 5 | export int main() { 6 | int[4] a = [0, 0]; 7 | printInt(a[0]); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /success/boolean_comparison.cvc: -------------------------------------------------------------------------------- 1 | // Comparisons don't work on booleans, except for ==. 2 | 3 | #include "civic.h" 4 | 5 | export int main() { 6 | if (true == false) { 7 | printInt(1234); 8 | } 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /success/nested_funcall.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | int foo() { 4 | return 5; 5 | } 6 | 7 | int bar(int i) { 8 | return 10; 9 | } 10 | 11 | export int main() { 12 | printInt(bar(foo())); 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /fail/double_param.cvc: -------------------------------------------------------------------------------- 1 | // Should produce a context analysis error because parameter names are doubled. 2 | 3 | void kaas(int a, int a) { 4 | return 6.0; 5 | } 6 | 7 | export int main() { 8 | kaas(5, 7); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /fail/types_parameters_length.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | int kaas(int a, int b, bool c, float d, int e) { 4 | return 0; 5 | } 6 | 7 | export int main() { 8 | int a = 0; 9 | kaas(5, 1, false, 7.0); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /fail/types_parameters_list.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | int kaas(int a, int b, bool c, float d, int e) { 4 | return 0; 5 | } 6 | 7 | export int main() { 8 | int a = 0; 9 | kaas(5, 1, false, 7, 8); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /success/cast_boolean.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | float a = 10.0; 5 | bool b = (bool) a; 6 | bool c = (bool) true; 7 | bool d = (bool) 5; 8 | bool e = b && c && d; 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /success/side_effects.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | int rv = 0; 4 | 5 | int foo() { 6 | rv = rv + 1; 7 | return 1; 8 | } 9 | 10 | export int main() { 11 | int a = 0 * foo(); 12 | printInt(rv); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /fail/types_parameters_length_reverse.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | int kaas(int a, int b, bool c, float d) { 4 | return 0; 5 | } 6 | 7 | export int main() { 8 | int a = 0; 9 | kaas(5, 1, false, 7.0, 8); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /success/short_circuit.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | int rv = 0; 4 | 5 | bool kaas() { 6 | rv = 1; 7 | return true; 8 | } 9 | 10 | export int main() { 11 | if (false && kaas()) {} 12 | printInt(rv); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /fail/types_binop.cvc: -------------------------------------------------------------------------------- 1 | // Should produce a type checking error because binop types should match. 2 | 3 | #include "civic.h" 4 | 5 | export int main() { 6 | int a = 5; 7 | if (6.0 > a) { 8 | a = 6; 9 | } 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /success/array_def_side_effects.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | int rv = 0; 4 | 5 | int foo() { 6 | rv = rv + 1; 7 | return 5; 8 | } 9 | 10 | export int main() { 11 | int[5] a = foo(); 12 | printInt(rv); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /success/order_of_operations.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | bool[6] a = true; 5 | if (false && a[0] && false) { 6 | printInt(5); 7 | } else { 8 | printInt(1); 9 | } 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /success/short_circuit_or.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | int rv = 0; 4 | 5 | bool kaas() { 6 | rv = 1; 7 | return true; 8 | } 9 | 10 | export int main() { 11 | if (true || kaas()) {} 12 | printInt(rv); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /success/monop.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | bool a = false; 5 | int b; 6 | 7 | if (!a) { 8 | b = 0; 9 | } else { 10 | b = 5; 11 | } 12 | 13 | printInt(-b); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /success/pop_funreturn.cvc: -------------------------------------------------------------------------------- 1 | int foo() { 2 | return 5; 3 | } 4 | 5 | void bar(int i) { 6 | return; 7 | } 8 | 9 | export int main() { 10 | bar(5); 11 | bar(foo()); 12 | foo(); 13 | bar(foo()); 14 | bar(5); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /fail/var_after_fun.cvc: -------------------------------------------------------------------------------- 1 | // Should produce a syntax validity error because a vardec is after a fundef. 2 | 3 | #include "civic.h" 4 | 5 | export int main() { 6 | void kaas() { 7 | printInt(6); 8 | } 9 | 10 | int a = 0; 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /fail/types_funcall.cvc: -------------------------------------------------------------------------------- 1 | // Should produce a type checking error because funcalls also have a type. 2 | 3 | #include "civic.h" 4 | 5 | float kaas() { 6 | return 6.0; 7 | } 8 | 9 | export int main() { 10 | int a = 0; 11 | a = a + kaas(); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /success/global.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | int a = 5; 4 | int b = 10; 5 | 6 | export int main() { 7 | int[a] c = 7; 8 | int[b, a] d = [[5, 6, 8, 2], [6, 3, 7, 1]]; 9 | int[a, b, c[2]] k = d[0, 1]; 10 | 11 | printInt(k[0, 0, 0]); 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /success/if_else.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | int a = 560; 5 | int b = 320; 6 | int c; 7 | 8 | if (a + 5 > b) { 9 | c = 0; 10 | } else { 11 | c = 1; 12 | } 13 | 14 | printInt(c); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /fail/types_parameters.cvc: -------------------------------------------------------------------------------- 1 | // Should produce a type checking error because funcall has bad arguments. 2 | 3 | #include "civic.h" 4 | 5 | int kaas(int a) { 6 | return 0; 7 | } 8 | 9 | export int main() { 10 | int a = 0; 11 | kaas(5.0 * 6.0); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /fail/types_parameters_mixed.cvc: -------------------------------------------------------------------------------- 1 | // Should produce a type checking error because funcall has bad arguments. 2 | 3 | #include "civic.h" 4 | 5 | int kaas(int a) { 6 | return 0; 7 | } 8 | 9 | export int main() { 10 | int a = 0; 11 | kaas(5 * 6.0); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /success/dynamic_array_size.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | int z = 5; 4 | 5 | export int main() { 6 | int p = 5; 7 | int c = 3; 8 | int[p * c * z, (p + c) - 3] b = 5 + c; 9 | printInt(b[0, 0]); 10 | printInt(b[1, 1]); 11 | printInt(z); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /success/useless_function.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | void foo() { 4 | int a = 6; 5 | 6 | printInt(a); 7 | 8 | if (5 > 6) { 9 | a = a + 5; 10 | } 11 | } 12 | 13 | export int main() { 14 | int a = 0; 15 | printInt(a); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /fail/civic.h: -------------------------------------------------------------------------------- 1 | #ifndef __CIVIC_H 2 | #define __CIVIC_H 3 | 4 | extern void printInt(int val); 5 | extern void printFloat(float val); 6 | 7 | extern int scanInt(); 8 | extern float scanFloat(); 9 | 10 | extern void printSpaces(int num); 11 | extern void printNewlines(int num); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /success/civic.h: -------------------------------------------------------------------------------- 1 | #ifndef __CIVIC_H 2 | #define __CIVIC_H 3 | 4 | extern void printInt(int val); 5 | extern void printFloat(float val); 6 | 7 | extern int scanInt(); 8 | extern float scanFloat(); 9 | 10 | extern void printSpaces(int num); 11 | extern void printNewlines(int num); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /user/civic.h: -------------------------------------------------------------------------------- 1 | #ifndef __CIVIC_H 2 | #define __CIVIC_H 3 | 4 | extern void printInt(int val); 5 | extern void printFloat(float val); 6 | 7 | extern int scanInt(); 8 | extern float scanFloat(); 9 | 10 | extern void printSpaces(int num); 11 | extern void printNewlines(int num); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /success/array.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | int a = 5; 5 | int b = 10; 6 | int[a] c = 7; 7 | int[b, a] d = [[5, 6, 8, 2], [6, 3, 7, 1]]; 8 | int[a, b, c[2]] e = d[0, 1]; 9 | 10 | printInt(e[0, 0, 0]); 11 | printNewlines(1); 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /success/short_circuit_long.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | int rv = 0; 4 | 5 | bool kaas() { 6 | rv = 1; 7 | return true; 8 | } 9 | 10 | export int main() { 11 | int[5] a = 5; 12 | if (false && kaas() && 5 + a[0] > 3 * 2 && 1 < 10) {} 13 | printInt(rv); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /fail/types_return_multiple.cvc: -------------------------------------------------------------------------------- 1 | // Should give a type checking error because a int function cannot return float. 2 | 3 | int fun(int a) { 4 | 5 | if (a > 5) { 6 | return 5.0; 7 | } else { 8 | return 8.0; 9 | } 10 | 11 | return 5; 12 | } 13 | 14 | export int main() { 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /success/useless_cast.cvc: -------------------------------------------------------------------------------- 1 | 2 | export int main() { 3 | int a = 0; 4 | float b = 0.0; 5 | bool c = false; 6 | 7 | a = (int) 5; 8 | a = (int) a + 5; 9 | 10 | b = (float) 5.0; 11 | b = (float) (int) 5; 12 | b = (float) b; 13 | 14 | c = (bool) !c; 15 | c = (bool) true; 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /success/cast_boolean_to_int.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | int p = 5; 5 | int c = (int) (5.0); 6 | int a = c + (int) true; 7 | int d = (int) true; 8 | float e = (float) false; 9 | int f = (int) (c > p); 10 | printInt(p); 11 | printInt(a); 12 | printInt(f); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /success/array_size.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | void kaas(int[a, b, c, d, e, f, g] z) { 4 | printInt(a); 5 | printInt(b); 6 | printInt(c); 7 | printInt(d); 8 | printInt(e); 9 | printInt(f); 10 | printInt(g); 11 | } 12 | 13 | export int main() { 14 | int[1, 2, 3, 4, 5, 6, 7] a = 10; 15 | kaas(a); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /success/array_dimension_expansion.cvc: -------------------------------------------------------------------------------- 1 | // Comparisons don't work on booleans, except for ==. 2 | 3 | #include "civic.h" 4 | 5 | int foo(int[n, m] a, int b) { 6 | printInt(n); 7 | printInt(m); 8 | printInt(a[0, b]); 9 | return a[0, b]; 10 | } 11 | 12 | export int main() { 13 | int [5, 3] a = 5; 14 | foo(a, foo(a, foo(a, 1))); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /success/recursion.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | int a = 560; 5 | int b = 320; 6 | 7 | void gcd2() { 8 | gcd1(); 9 | } 10 | 11 | void gcd1() { 12 | if (a > b) a = a - b; 13 | else b = b - a; 14 | } 15 | 16 | while(a != b) gcd2(); 17 | 18 | printInt(a); 19 | printNewlines(1); 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /fail/duplicate.cvc: -------------------------------------------------------------------------------- 1 | // Should produce a context analysis due to duplicate function definition 2 | 3 | #include "civic.h" 4 | 5 | export int main() { 6 | int a = 560; 7 | int b = 320; 8 | 9 | void gcd() {} 10 | 11 | void gcd() { 12 | gcd(); 13 | } 14 | 15 | while(a != b) gcd(); 16 | 17 | printInt(a); 18 | printNewlines(1); 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /success/for_loop_evaluation.cvc: -------------------------------------------------------------------------------- 1 | // For-loop check should be evaluated once! 2 | 3 | #include "civic.h" 4 | 5 | int a = 0; 6 | 7 | int foo() { 8 | a = a + 1; 9 | return 5; 10 | } 11 | 12 | export int main() { 13 | for (int i = 0, foo()) { 14 | printInt(0); 15 | } 16 | 17 | printInt(a); 18 | 19 | if (a != 1) { 20 | printInt(a); 21 | return 1; 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /success/global_deep.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | int a = 5; 4 | 5 | export int main() { 6 | void kaas() { 7 | void kaas() { 8 | void kaas() { 9 | void kaas() { 10 | printInt(a); 11 | } 12 | kaas(); 13 | } 14 | kaas(); 15 | } 16 | 17 | kaas(); 18 | } 19 | 20 | kaas(); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /success/indexing.cvc: -------------------------------------------------------------------------------- 1 | /* 2 | * @file fibonacci.cvc 3 | * @author Martha Szygula (10537988) and Stephen Swatman (10559442) 4 | * 5 | * @brief This file finds a given number of Fibonacci numbers in Civilised C 6 | * using relatively free variables. 7 | */ 8 | 9 | #include "civic.h" 10 | 11 | export int main() { 12 | int[4] a = [1, 2, 3, 4]; 13 | int[5] b = [100, 60, 23, 20]; 14 | printInt(b[a[2]]); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /success/local_array.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | 4 | export int main() { 5 | int[1, 2, 3, 4, 5, 6, 7] a = 10; 6 | int e = 60000; 7 | int b = 60000; 8 | int c = 60000; 9 | int d = 60000; 10 | 11 | void kaas(int[a, b, c, d, e, f, g] z) { 12 | printInt(a); 13 | printInt(b); 14 | printInt(c); 15 | printInt(d); 16 | printInt(e); 17 | printInt(f); 18 | printInt(g); 19 | } 20 | 21 | kaas(a); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /success/factorial_simple.cvc: -------------------------------------------------------------------------------- 1 | /* 2 | * @file factorial.cvc 3 | * @author Martha Szygula (10537988) and Stephen Swatman (10559442) 4 | * 5 | * @brief This file finds the factorial of a number in Civilised C. 6 | */ 7 | 8 | #include "civic.h" 9 | 10 | int factorial(int a) { 11 | if(a > 1) a = a * factorial(a - 1); 12 | return a; 13 | } 14 | 15 | export int main() { 16 | int n = 10; 17 | 18 | if(n > 0) 19 | n = factorial(n); 20 | 21 | printInt(n); 22 | printNewlines(1); 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /success/euclid_simple.cvc: -------------------------------------------------------------------------------- 1 | /* 2 | * @file euclid.cvc 3 | * @author Martha Szygula (10537988) and Stephen Swatman (10559442) 4 | * 5 | * @brief This file implements Euclids algorithm in the Civilised C programming 6 | * language. 7 | */ 8 | 9 | #include "civic.h" 10 | 11 | int gcd(int a, int b) { 12 | if (b == 0) return a; 13 | return gcd(b, a % b); 14 | } 15 | 16 | export int main() { 17 | int a = 560; 18 | int b = 320; 19 | 20 | a = gcd(a, b); 21 | 22 | printInt(a); 23 | printNewlines(1); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /success/localfuns.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | int a = 560; 5 | int b = 320; 6 | 7 | void gcd() { 8 | void gcd() { 9 | void gcd() { 10 | void gcd() { 11 | if (a > b) a = a - b; 12 | else b = b - a; 13 | } 14 | gcd(); 15 | } 16 | gcd(); 17 | } 18 | gcd(); 19 | } 20 | 21 | while(a != b) gcd(); 22 | 23 | printInt(a); 24 | printNewlines(1); 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /success/factorial_local.cvc: -------------------------------------------------------------------------------- 1 | /* 2 | * @file factorial.cvc 3 | * @author Martha Szygula (10537988) and Stephen Swatman (10559442) 4 | * 5 | * @brief This file finds the factorial of a number in Civilised C using 6 | * relatively free variables. 7 | */ 8 | 9 | #include "civic.h" 10 | 11 | export int main() { 12 | int result = 1; 13 | int n = 10; 14 | 15 | void factorial() { 16 | result = result * n; 17 | n = n - 1; 18 | } 19 | 20 | while(n > 0) factorial(); 21 | 22 | printInt(result); 23 | printNewlines(1); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /success/complex_comparisons.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | int a = 1; 4 | int b = 2; 5 | int c; 6 | int e; 7 | float f = 1.0; 8 | bool x = true; 9 | 10 | export int main() { 11 | int test = 1; 12 | int test2 = 2; 13 | bool a = true; 14 | bool b = true; 15 | 16 | void testje() { 17 | int bla = 1; 18 | int yo = 2; 19 | printInt(yo); 20 | } 21 | 22 | if (test == 1 || test2 == 2) { 23 | printInt(5); 24 | return 0; 25 | } 26 | printInt(8); 27 | 28 | test = test2 + 1; 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /user/scan_matrix.cvc: -------------------------------------------------------------------------------- 1 | /* 2 | * @file scan_matrix.cvc 3 | * @author Martha Szygula (10537988) and Stephen Swatman (10559442) 4 | * 5 | * @brief Reads in a matrix from stdin. Gets the size first, then the values. 6 | */ 7 | 8 | #include "civic.h" 9 | 10 | void scan_float_matrix(float[n, m] matFloat) { 11 | for(int i = 0, n) 12 | for(int j = 0, m) 13 | matFloat[i, j] = scanFloat(); 14 | } 15 | 16 | /* Main to call the functions */ 17 | export int main() { 18 | float[scanInt(), scanInt()] matrix; 19 | 20 | scan_float_matrix(matrix); 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /success/fibonacci_simple.cvc: -------------------------------------------------------------------------------- 1 | /* 2 | * @file fibonacci.cvc 3 | * @author Martha Szygula (10537988) and Stephen Swatman (10559442) 4 | * 5 | * @brief This file finds a given number of Fibonacci numbers in Civilised C. 6 | */ 7 | 8 | #include "civic.h" 9 | 10 | export int main() { 11 | int a = 0; 12 | int b = 1; 13 | int n = 100; 14 | int c; 15 | 16 | while (n > 0) { 17 | printInt(a); 18 | printNewlines(1); 19 | c = a + b; 20 | a = b; 21 | b = c; 22 | n = n - 1; 23 | } 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /success/loops.cvc: -------------------------------------------------------------------------------- 1 | #include "civic.h" 2 | 3 | export int main() { 4 | int a = 0; 5 | int b = 0; 6 | 7 | for (int b = 0, 10, 2) { 8 | a = a + b; 9 | } 10 | 11 | do { 12 | a = a + 7; 13 | } while (a < 100); 14 | 15 | if (true) { 16 | do { 17 | a = a + 7; 18 | } while (a < 100); 19 | } 20 | 21 | while (a * a < 20000) { 22 | while (b < 5) { 23 | b = b + 1; 24 | } 25 | a = a * 2; 26 | } 27 | 28 | printInt(a); 29 | printNewlines(1); 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /success/euclid_local.cvc: -------------------------------------------------------------------------------- 1 | /* 2 | * @file euclid.cvc 3 | * @author Martha Szygula (10537988) and Stephen Swatman (10559442) 4 | * 5 | * @brief This file implements Euclids algorithm in the Civilised C programming 6 | * language using relatively free variables. 7 | */ 8 | 9 | #include "civic.h" 10 | 11 | export int main() { 12 | int a = 560; 13 | int b = 320; 14 | 15 | void gcd() { 16 | if (a > b) a = a - b; 17 | else b = b - a; 18 | } 19 | 20 | while(a != b) gcd(); 21 | 22 | printInt(a); 23 | printNewlines(1); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /fail/bad_array_parameter_size_reverse.cvc: -------------------------------------------------------------------------------- 1 | // Should produce a type checking error because array sizes don't match. 2 | 3 | #include "civic.h" 4 | 5 | void fill_matrix(float[n, m] matrix) { 6 | for(int i = 0, n) 7 | for(int j = 0, m) 8 | matrix[i, j] = (float) i + (float) j + 0.5; 9 | } 10 | 11 | void print_matrix(float[n, m] matrix) { 12 | for(int i = 0, n) { 13 | for(int j = 0, m) { 14 | printFloat(matrix[i, j]); 15 | printSpaces(1); 16 | } 17 | 18 | printNewlines(1); 19 | } 20 | } 21 | 22 | export int main() { 23 | float[5, 3, 7] matrix; 24 | 25 | fill_matrix(matrix); 26 | print_matrix(matrix); 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /success/fibonacci_local.cvc: -------------------------------------------------------------------------------- 1 | /* 2 | * @file fibonacci.cvc 3 | * @author Martha Szygula (10537988) and Stephen Swatman (10559442) 4 | * 5 | * @brief This file finds a given number of Fibonacci numbers in Civilised C 6 | * using relatively free variables. 7 | */ 8 | 9 | #include "civic.h" 10 | 11 | export int main() { 12 | int a = 0; 13 | int b = 1; 14 | int n = 100; 15 | int c; 16 | 17 | void fibonacci() { 18 | c = a + b; 19 | a = b; 20 | b = c; 21 | n = n - 1; 22 | } 23 | 24 | while (n > 0) { 25 | printInt(a); 26 | printNewlines(1); 27 | fibonacci(); 28 | } 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /fail/empty_array_parameter_size.cvc: -------------------------------------------------------------------------------- 1 | // Should produce an error because an array is dimensionless. 2 | 3 | #include "civic.h" 4 | 5 | void fill_matrix(float[] matrix) { 6 | for(int i = 0, n) 7 | for(int j = 0, m) 8 | matrix[i, j] = (float) i + (float) j + 0.5; 9 | } 10 | 11 | void print_matrix(float[] matrix) { 12 | for(int i = 0, n) { 13 | for(int j = 0, m) { 14 | printFloat(matrix[i, j]); 15 | printSpaces(1); 16 | } 17 | 18 | printNewlines(1); 19 | } 20 | } 21 | 22 | /* Main to call the functions */ 23 | export int main() { 24 | float[5, 3] matrix; 25 | 26 | fill_matrix(matrix); 27 | print_matrix(matrix); 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /fail/bad_array_parameter_size.cvc: -------------------------------------------------------------------------------- 1 | // Should produce a type checking error because array sizes don't match. 2 | 3 | #include "civic.h" 4 | 5 | void fill_matrix(float[n, m, o] matrix) { 6 | for(int i = 0, n) 7 | for(int j = 0, m) 8 | matrix[i, j] = (float) i + (float) j + 0.5; 9 | } 10 | 11 | void print_matrix(float[n, m] matrix) { 12 | for(int i = 0, n) { 13 | for(int j = 0, m) { 14 | printFloat(matrix[i, j]); 15 | printSpaces(1); 16 | } 17 | 18 | printNewlines(1); 19 | } 20 | } 21 | 22 | /* Main to call the functions */ 23 | export int main() { 24 | float[5, 3] matrix; 25 | 26 | fill_matrix(matrix); 27 | print_matrix(matrix); 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /success/primes_simple.cvc: -------------------------------------------------------------------------------- 1 | /* 2 | * @file primes.cvc 3 | * @author Martha Szygula (10537988) and Stephen Swatman (10559442) 4 | * 5 | * @brief This file finds a given number of prime numbers in Civilised C. 6 | */ 7 | 8 | #include "civic.h" 9 | 10 | bool is_prime(int y) { 11 | int z = 2; 12 | 13 | while (z * z <= y) { 14 | if (y % z == 0) return false; 15 | z = z + 1; 16 | } 17 | 18 | return true; 19 | } 20 | 21 | export int main() { 22 | int n = 100; 23 | int t = 2; 24 | 25 | while (n > 0) { 26 | if (is_prime(t)) { 27 | n = n - 1; 28 | printInt(t); 29 | printNewlines(1); 30 | } 31 | 32 | t = t + 1; 33 | } 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /success/print_matrix.cvc: -------------------------------------------------------------------------------- 1 | /* 2 | * @file print_matrix.cvc 3 | * @author Martha Szygula (10537988) and Stephen Swatman (10559442) 4 | * 5 | * @brief This file prints a matrix. The matrix is predefined. 6 | */ 7 | 8 | #include "civic.h" 9 | 10 | void fill_matrix(float[n, m] matrix) { 11 | for(int i = 0, n) 12 | for(int j = 0, m) 13 | matrix[i, j] = (float) i + (float) j + 0.5; 14 | } 15 | 16 | void print_matrix(float[n, m] matrix) { 17 | for(int i = 0, n) { 18 | for(int j = 0, m) { 19 | printFloat(matrix[i, j]); 20 | printSpaces(1); 21 | } 22 | 23 | printNewlines(1); 24 | } 25 | } 26 | 27 | /* Main to call the functions */ 28 | export int main() { 29 | float[5, 3] matrix; 30 | 31 | fill_matrix(matrix); 32 | print_matrix(matrix); 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /success/primes_local.cvc: -------------------------------------------------------------------------------- 1 | /* 2 | * @file primes.cvc 3 | * @author Martha Szygula (10537988) and Stephen Swatman (10559442) 4 | * 5 | * @brief This file finds a given number of prime numbers in Civilised C using 6 | * relatively free variables. 7 | */ 8 | 9 | #include "civic.h" 10 | 11 | export int main() { 12 | int n = 100; 13 | int t = 2; 14 | 15 | bool is_prime() { 16 | int z = 2; 17 | 18 | while (z * z <= t) { 19 | if (t % z == 0) return false; 20 | z = z + 1; 21 | } 22 | 23 | return true; 24 | } 25 | 26 | while (n > 0) { 27 | if (is_prime()) { 28 | n = n - 1; 29 | printInt(t); 30 | printNewlines(1); 31 | } 32 | 33 | t = t + 1; 34 | } 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /success/queens.cvc: -------------------------------------------------------------------------------- 1 | /* 2 | * @file queens.cvc 3 | * @author Martha Szygula (10537988) and Stephen Swatman (10559442) 4 | * 5 | * @brief This file finds all solutions to the N-queens problem. N is set to 6 | * 8 by default. 7 | */ 8 | 9 | #include "civic.h" 10 | 11 | bool is_safe(int[n] rows, int x, int y) { 12 | if (y == 0) return true; 13 | 14 | for (int i=0, y) 15 | if (rows[i] == x || rows[i] == x + y - i || rows[i] == x - y + i) 16 | return false; 17 | 18 | return true; 19 | } 20 | 21 | bool unused(int t, float s, int[n, m] rows, int x, int y, float [b, c] a) { 22 | return false; 23 | } 24 | 25 | void putboard(int[n] rows) { 26 | for (int y=0, n) { 27 | for (int x=0, n) { 28 | if (x == rows[y]) printInt(1); 29 | else printInt(0); 30 | printSpaces(1); 31 | } 32 | 33 | printNewlines(1); 34 | } 35 | 36 | printNewlines(1); 37 | } 38 | 39 | void eight_queens_helper(int[n] rows, int y) { 40 | for (int x = 0, n) { 41 | if (is_safe(rows, x, y)) { 42 | rows[y] = x; 43 | if (y == n - 1) 44 | putboard(rows); 45 | else 46 | eight_queens_helper(rows, y+1); 47 | } 48 | } 49 | } 50 | 51 | /* Main to call the functions */ 52 | export int main() { 53 | int n = 8; 54 | int[n] rows; 55 | 56 | eight_queens_helper(rows, 0); 57 | 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /success/quicksort.cvc: -------------------------------------------------------------------------------- 1 | /* 2 | * @file quicksort.cvc 3 | * @author Martha Szygula (10537988) and Stephen Swatman (10559442) 4 | * 5 | * @brief This file implements quicksort on some predefined vectors in 6 | * Civilised C. 7 | */ 8 | 9 | #include "civic.h" 10 | 11 | 12 | void create_vector(int[n] vector) { 13 | for(int i = 0, n) vector[i] = (5349 * (n + i)) % (n * n); 14 | } 15 | 16 | void print_vector(int[n] vector) { 17 | for(int i = 0, n) { 18 | printInt(vector[i]); 19 | printSpaces(1); 20 | } 21 | 22 | printNewlines(1); 23 | } 24 | 25 | int partition(int[n] vector, int lo, int hi) { 26 | int pivot = vector[hi]; 27 | int temp = vector[lo]; 28 | int i = lo; 29 | 30 | for(int j = lo, hi) { 31 | if(vector[j] <= pivot) { 32 | temp = vector[i]; 33 | vector[i] = vector[j]; 34 | vector[j] = temp; 35 | i = i + 1; 36 | } 37 | } 38 | 39 | temp = vector[i]; 40 | vector[i] = vector[hi]; 41 | vector[hi] = temp; 42 | 43 | return i; 44 | } 45 | 46 | void quicksort_helper(int[n] vector, int lo, int hi) { 47 | int part; 48 | 49 | if(lo < hi) { 50 | part = partition(vector, lo, hi); 51 | quicksort_helper(vector, lo, part - 1); 52 | quicksort_helper(vector, part + 1, hi); 53 | } 54 | } 55 | 56 | void quicksort(int[n] vector) { 57 | quicksort_helper(vector, 0, n - 1); 58 | } 59 | 60 | /* Main to call the functions */ 61 | export int main() { 62 | int[20] vector; 63 | 64 | create_vector(vector); 65 | print_vector(vector); 66 | quicksort(vector); 67 | print_vector(vector); 68 | 69 | return 0; 70 | } 71 | -------------------------------------------------------------------------------- /user/matrix_mult.cvc: -------------------------------------------------------------------------------- 1 | /* 2 | * @file matrix_mult.cvc 3 | * @author Martha Szygula (10537988) and Stephen Swatman (10559442) 4 | * 5 | * @brief This file implements matrix multiplication in Civilised C. Reads the 6 | * size of the matrix from stdin. 7 | */ 8 | 9 | #include "civic.h" 10 | 11 | /* Scan the matrices */ 12 | void scanFloatMatrix(float[n, m] matFloat) { 13 | for(int i = 0, n, 1) { 14 | for(int j = 0, m, 1) { 15 | matFloat[i, j] = scanFloat(); 16 | } 17 | } 18 | printNewlines(1); 19 | } 20 | 21 | /* Print those matrices */ 22 | void printFloatMatrix(float[n, m] matFloat) { 23 | for(int i = 0, n, 1) { 24 | for(int j = 0, m, 1) { 25 | printFloat(matFloat[i, j]); 26 | printSpaces(1); 27 | } 28 | printNewlines(1); 29 | } 30 | printNewlines(1); 31 | } 32 | 33 | /* Calculate new matrix */ 34 | void newFloatMatrix(float[n, m] matFloat1, float[k, l] matFloat2) { 35 | float[n, l] matFloat3; 36 | float sum = 0.0; 37 | 38 | for(int i = 0, n, 1) { 39 | for(int j = 0, l, 1) { 40 | for(int y = 0, k, 1) { 41 | sum = sum + matFloat1[i, y] * matFloat2[y, j]; 42 | } 43 | matFloat3[i, j] = sum; 44 | sum = 0.0; 45 | } 46 | } 47 | 48 | printFloatMatrix(matFloat3); 49 | } 50 | 51 | /* Main to call the functions */ 52 | export int main() { 53 | int matrixFloatN1 = scanInt(); 54 | int matrixFloatM1 = scanInt(); 55 | int matrixFloatN2 = scanInt(); 56 | int matrixFloatM2 = scanInt(); 57 | 58 | float[matrixFloatN1, matrixFloatM1] matFloat1; 59 | float[matrixFloatN2, matrixFloatM2] matFloat2; 60 | 61 | scanFloatMatrix(matFloat1); 62 | scanFloatMatrix(matFloat2); 63 | 64 | printFloatMatrix(matFloat1); 65 | printFloatMatrix(matFloat2); 66 | 67 | newFloatMatrix(matFloat1, matFloat2); 68 | 69 | return 0; 70 | } 71 | -------------------------------------------------------------------------------- /test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # If this is set to true, compare the output of the user compiler to that of the 4 | # reference compiler. 5 | CHECK_OUTPUT=true 6 | 7 | # Fill in your compiler command here. 8 | COMPILER=civcc 9 | 10 | # Fill in the reference compiler here. 11 | REFERENCE_COMPILER=civcc 12 | 13 | # Fill in the assembler and virtual machine here. 14 | ASSEMBLER=civas 15 | VM=civvm 16 | 17 | # Do not touch anything below. Actually, I don't really care what you do because 18 | # it's a local copy so go ahead. 19 | FAIL=0 20 | TOTAL=0 21 | 22 | execute() { 23 | $1 -o _tmp_$2.s $3 >/dev/null 2>&1 24 | $ASSEMBLER -o _tmp_$2.out _tmp_$2.s 2>&1 25 | $VM _tmp_$2.out 2>&1 26 | RV=$? 27 | rm -f _tmp_$2.s _tmp_$2.out 28 | return $RV 29 | } 30 | 31 | cd "$(dirname "${BASH_SOURCE[0]}")" 32 | shopt -s nullglob 33 | command -v $COMPILER >/dev/null 2>&1 || { echo "$COMPILER is not an executable file."; exit 1; } 34 | 35 | echo "Running failure tests..." 36 | for x in fail/*.cvc; do 37 | TOTAL=$((TOTAL+1)) 38 | $COMPILER $x 1>/dev/null 2>/dev/null && { 39 | echo "Test $x should not succeed!"; 40 | FAIL=$((FAIL+1)); 41 | } 42 | done 43 | 44 | echo "Running runtime failure tests..." 45 | for x in runtime/*.cvc; do 46 | TOTAL=$((TOTAL+1)) 47 | $COMPILER $x 1>/dev/null 2>/dev/null && execute $COMPILER usr $x >/dev/null && { 48 | echo "Test $x should not run!"; 49 | FAIL=$((FAIL+1)); 50 | } 51 | done 52 | 53 | echo "Running success tests..." 54 | for x in success/*.cvc; do 55 | TOTAL=$((TOTAL+1)) 56 | $COMPILER $x 1>/dev/null 2>/dev/null || { 57 | echo "Test $x should not fail!"; 58 | FAIL=$((FAIL+1)); 59 | continue; 60 | } 61 | 62 | if [ $CHECK_OUTPUT = true ]; then 63 | diff <(execute $REFERENCE_COMPILER ref $x) \ 64 | <(execute $COMPILER usr $x) > /dev/null \ 65 | || { echo "Test $x did not match reference output!"; FAIL=$((FAIL+1)); } 66 | fi 67 | done 68 | 69 | if [ $TOTAL -eq 0 ]; then echo "No tests were run. Make sure you are in the right directory."; exit 1; fi 70 | echo "Passed $((TOTAL-FAIL)) out of $((TOTAL)) tests. Your grade: $(bc -l <<< "scale=1; ($TOTAL-$FAIL) * 10 / $TOTAL")." 71 | if [ $FAIL -eq 0 ]; then echo "Well done! :)"; fi 72 | -------------------------------------------------------------------------------- /patches/fix_preprocessor.diff: -------------------------------------------------------------------------------- 1 | Nur en fixed/demo: .count_operators.d 2 | Nur en fixed/demo: count_operators.o 3 | Nur en fixed/demo: .opt_sub.d 4 | Nur en fixed/demo: opt_sub.o 5 | Nur en fixed/demo: .rename_identifiers.d 6 | Nur en fixed/demo: rename_identifiers.o 7 | diff -rc src/framework/scanparse.c fixed/framework/scanparse.c 8 | *** src/framework/scanparse.c 2016-03-08 16:00:35.115049313 +0100 9 | --- fixed/framework/scanparse.c 2016-03-08 16:24:48.055651281 +0100 10 | *************** 11 | *** 48,54 **** 12 | 13 | 14 | #include 15 | ! 16 | #include "scanparse.h" 17 | #include "dbug.h" 18 | #include "globals.h" 19 | --- 48,54 ---- 20 | 21 | 22 | #include 23 | ! #include 24 | #include "scanparse.h" 25 | #include "dbug.h" 26 | #include "globals.h" 27 | *************** 28 | *** 78,90 **** 29 | "SPdoScanParse() called with existing syntax tree."); 30 | 31 | if (global.cpp) { 32 | ! filename = STRcatn( 3, 33 | ! ".", 34 | ! global.infile, 35 | ! ".cpp"); 36 | } 37 | else { 38 | ! filename = STRcpy( global.infile); 39 | } 40 | 41 | yyin = fopen( filename, "r"); 42 | --- 78,87 ---- 43 | "SPdoScanParse() called with existing syntax tree."); 44 | 45 | if (global.cpp) { 46 | ! asprintf(&filename, "%s.cpp", global.infile); 47 | } 48 | else { 49 | ! filename = strdup(global.infile); 50 | } 51 | 52 | yyin = fopen( filename, "r"); 53 | *************** 54 | *** 108,119 **** 55 | 56 | DBUG_ENTER("SPdoRunPreProcessor"); 57 | 58 | ! cppcallstr = STRcatn( 5, 59 | ! "gcc -E ", 60 | ! global.infile, 61 | ! " > .", 62 | ! global.infile, 63 | ! ".cpp"); 64 | 65 | err = system( cppcallstr); 66 | 67 | --- 105,111 ---- 68 | 69 | DBUG_ENTER("SPdoRunPreProcessor"); 70 | 71 | ! asprintf(&cppcallstr, "gcc -x c -E %s > %s.cpp", global.infile, global.infile); 72 | 73 | err = system( cppcallstr); 74 | 75 | diff -rc src/global/phase.mac fixed/global/phase.mac 76 | *** src/global/phase.mac 2016-03-08 16:00:35.111049339 +0100 77 | --- fixed/global/phase.mac 2016-03-08 16:14:24.402123127 +0100 78 | *************** 79 | *** 15,21 **** 80 | SUBPHASE( cpp, 81 | "Running C preprocessor", 82 | SPdoRunPreProcessor, 83 | ! NEVER, 84 | ld) 85 | 86 | SUBPHASE( scp, 87 | --- 15,21 ---- 88 | SUBPHASE( cpp, 89 | "Running C preprocessor", 90 | SPdoRunPreProcessor, 91 | ! ALWAYS, 92 | ld) 93 | 94 | SUBPHASE( scp, 95 | -------------------------------------------------------------------------------- /patches/fix_unions.diff: -------------------------------------------------------------------------------- 1 | diff -rc src/framework/attribs.h.xsl fixed/framework/attribs.h.xsl 2 | *** src/framework/attribs.h.xsl 2011-02-01 16:15:50.000000000 +0100 3 | --- fixed/framework/attribs.h.xsl 2016-03-08 16:03:49.405810078 +0100 4 | *************** 5 | *** 161,167 **** 6 | * called N_nodename. 7 | ****************************************************************************/ 8 | 9 | ! 10 | 11 | 12 | 13 | --- 161,167 ---- 14 | * called N_nodename. 15 | ****************************************************************************/ 16 | 17 | ! 18 | 19 | 20 | 21 | diff -rc src/framework/sons.h.xsl fixed/framework/sons.h.xsl 22 | *** src/framework/sons.h.xsl 2011-02-01 16:15:50.000000000 +0100 23 | --- fixed/framework/sons.h.xsl 2016-03-08 16:04:01.241735010 +0100 24 | *************** 25 | *** 128,134 **** 26 | * called N_nodename. 27 | ****************************************************************************/ 28 | 29 | ! 30 | 31 | 32 | 33 | --- 128,134 ---- 34 | * called N_nodename. 35 | ****************************************************************************/ 36 | 37 | ! 38 | 39 | 40 | 41 | diff -rc src/framework/tree_basic.h fixed/framework/tree_basic.h 42 | *** src/framework/tree_basic.h 2016-01-28 11:19:22.000000000 +0100 43 | --- fixed/framework/tree_basic.h 2016-03-08 16:04:33.633529801 +0100 44 | *************** 45 | *** 70,77 **** 46 | int lineno; /* line of definition */ 47 | int colno; /* line of definition */ 48 | node* error; /* error node */ 49 | ! struct SONUNION sons; /* the sons */ 50 | ! struct ATTRIBUNION attribs; /* the nodes attributes */ 51 | }; 52 | 53 | #include "node_basic.h" 54 | --- 70,77 ---- 55 | int lineno; /* line of definition */ 56 | int colno; /* line of definition */ 57 | node* error; /* error node */ 58 | ! union SONUNION sons; /* the sons */ 59 | ! union ATTRIBUNION attribs; /* the nodes attributes */ 60 | }; 61 | 62 | #include "node_basic.h" 63 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Compiler Construction starter kit 2 | 3 | A set of tests and miscellaneous useful files for the Compiler Construction 4 | course at the University of Amsterdam. 5 | 6 | ## Test suite 7 | 8 | We provide a test suite consisting of dozens of edge cases that you might not 9 | be aware of. 10 | 11 | ### Installation 12 | 13 | The easiest way to install the test suite, would be to add it as a subdirectory 14 | to your own repository. To do this, use the following code from the root of 15 | your own project repository: 16 | 17 | git submodule add git@github.com:StephenSwat/Compiler-Construction-Starter-Kit.git test 18 | git commit -m 'Add the compiler construction starter kit' 19 | 20 | #### Integrating with `make` 21 | 22 | You can add a rule to your Makefile to easily run the test files for you. The 23 | rule should look something like the following: 24 | 25 | test: civicc 26 | @test/test.sh 27 | 28 | Then, run `make test` to execute the full suite of tests. 29 | 30 | #### Adding the compiler et al. to your path 31 | 32 | To make developing your compiler easier, you might want to be able to just call 33 | the name of your compiler in stead of having to give its path. One way of doing 34 | this is as follows: 35 | 36 | mkdir ~/.bin 37 | echo 'PATH=$PATH:~/.bin' >> ~/.bashrc 38 | ln -s [path to your compiler executabe] ~/.bin/my_compiler 39 | 40 | You should then extract the compiler toolchain (`civcc`, `civas`, `civrun` and 41 | `civvm`) to the `~/.bin` directory, which should allow you to simply run the 42 | commands `civcc`, `my_compiler` (giving your compiler a creative name is 43 | encouraged), etc. 44 | 45 | ### Configuration 46 | 47 | After installing, fill in the file `test/test.sh` with the details of your 48 | compiler. Enter the name of your compiler, the reference compiler, the assembler 49 | and the virtual machine. 50 | 51 | If you enable the `CHECK_OUTPUT` flag, the test suite will also compare the 52 | output of your code after insertion into the virtual machine to the output of 53 | the reference compiler. This only makes sense if you are already generating 54 | byte code! 55 | 56 | ### Running 57 | 58 | To run the suite, navigate to the test directory and execute the test script 59 | using a command such as `./test.sh`. If you have set everything up correctly, 60 | you should get output similar to the following: 61 | 62 | Running failure tests... 63 | Test fail/embargo.cvc should not succeed! 64 | Running success tests... 65 | Test success/array_size.cvc should not fail! 66 | Test success/local_array.cvc should not fail! 67 | Test success/print_matrix.cvc should not fail! 68 | Test success/queens.cvc should not fail! 69 | Test success/quicksort.cvc should not fail! 70 | Test success/short_circuit.cvc should not fail! 71 | Test success/short_circuit_or.cvc should not fail! 72 | Passed 53 out of 61 tests. Your grade: 8.6. 73 | 74 | ## Patches 75 | 76 | There are some blatant issues with the framework provided. Mainly, the C 77 | preprocessor is broken and secondly, the framework wastes a lot of memory by 78 | using strucs where is should use unions. Provided with this starter kit are 79 | patches that fix these issues. To fix the problems, run the following from your 80 | project root: 81 | 82 | (cd src/; patch -p1 -i ../test/patches/fix_unions.diff) 83 | (cd src/; patch -p1 -i ../test/patches/fix_preprocessor.diff) 84 | 85 | ## Updating 86 | 87 | To update the test suite submodule, run the following command: 88 | 89 | git submodule foreach git pull origin master 90 | 91 | ## Contributing 92 | 93 | You are encouraged to add your own tests to the suite. Granted that you insert 94 | them into the right directory, the suite should adapt to any number of tests. 95 | For reference, the reference compiler should score a perfect score. Please make 96 | a pull request to share your tests with others so we can all profit from your 97 | work! 98 | 99 | ## License 100 | 101 | This code is licensed under the Unlicense, so you are completely free to do 102 | anything you want with this code. Just don't come up to me crying if something 103 | goes wrong. 104 | --------------------------------------------------------------------------------