8
examples/tests/address_test.c
Archivo normal
8
examples/tests/address_test.c
Archivo normal
@@ -0,0 +1,8 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int x = 42;
|
||||
int *ptr = &x;
|
||||
printf("x = %d\n", x);
|
||||
return 0;
|
||||
}
|
||||
22
examples/tests/advanced_pointers_test.c
Archivo normal
22
examples/tests/advanced_pointers_test.c
Archivo normal
@@ -0,0 +1,22 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int x = 42;
|
||||
int *ptr = &x;
|
||||
int **ptr_to_ptr = &ptr;
|
||||
|
||||
printf("x = %d\n", x);
|
||||
printf("&x = %p\n", &x);
|
||||
printf("ptr = %p\n", ptr);
|
||||
printf("*ptr = %d\n", *ptr);
|
||||
printf("**ptr_to_ptr = %d\n", **ptr_to_ptr);
|
||||
|
||||
// Test pointer arithmetic
|
||||
int arr[3] = {10, 20, 30};
|
||||
int *p = arr;
|
||||
printf("arr[0] = %d, *p = %d\n", arr[0], *p);
|
||||
p++;
|
||||
printf("arr[1] = %d, *p = %d\n", arr[1], *p);
|
||||
|
||||
return 0;
|
||||
}
|
||||
25
examples/tests/array_advanced_test.c
Archivo normal
25
examples/tests/array_advanced_test.c
Archivo normal
@@ -0,0 +1,25 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
// Test simple array initialization
|
||||
int arr[5];
|
||||
arr[0] = 10;
|
||||
arr[1] = 20;
|
||||
arr[2] = 30;
|
||||
arr[3] = 40;
|
||||
arr[4] = 50;
|
||||
|
||||
printf("Array contents:\n");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
printf("arr[%d] = %d\n", i, arr[i]);
|
||||
}
|
||||
|
||||
// Test array arithmetic
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
sum = sum + arr[i];
|
||||
}
|
||||
printf("Sum = %d\n", sum);
|
||||
|
||||
return 0;
|
||||
}
|
||||
9
examples/tests/array_as_ptr_test.c
Archivo normal
9
examples/tests/array_as_ptr_test.c
Archivo normal
@@ -0,0 +1,9 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int arr[3];
|
||||
arr[0] = 10;
|
||||
int *ptr = arr;
|
||||
printf("Value: %d\n", *ptr);
|
||||
return 0;
|
||||
}
|
||||
23
examples/tests/array_debug.c
Archivo normal
23
examples/tests/array_debug.c
Archivo normal
@@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("=== Array Assignment Debug ===\n");
|
||||
int arr[3];
|
||||
|
||||
printf("Before assignments:\n");
|
||||
printf("arr[0] = %d, arr[1] = %d, arr[2] = %d\n", arr[0], arr[1], arr[2]);
|
||||
|
||||
printf("Assigning arr[0] = 10\n");
|
||||
arr[0] = 10;
|
||||
printf("arr[0] = %d, arr[1] = %d, arr[2] = %d\n", arr[0], arr[1], arr[2]);
|
||||
|
||||
printf("Assigning arr[1] = 20\n");
|
||||
arr[1] = 20;
|
||||
printf("arr[0] = %d, arr[1] = %d, arr[2] = %d\n", arr[0], arr[1], arr[2]);
|
||||
|
||||
printf("Assigning arr[2] = 30\n");
|
||||
arr[2] = 30;
|
||||
printf("arr[0] = %d, arr[1] = %d, arr[2] = %d\n", arr[0], arr[1], arr[2]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
8
examples/tests/array_ptr_test.c
Archivo normal
8
examples/tests/array_ptr_test.c
Archivo normal
@@ -0,0 +1,8 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int arr[3] = {10, 20, 30};
|
||||
int *ptr = arr;
|
||||
printf("First element: %d\n", *ptr);
|
||||
return 0;
|
||||
}
|
||||
16
examples/tests/array_test.c
Archivo normal
16
examples/tests/array_test.c
Archivo normal
@@ -0,0 +1,16 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int arr[5];
|
||||
arr[0] = 10;
|
||||
arr[1] = 20;
|
||||
arr[2] = 30;
|
||||
arr[3] = 40;
|
||||
arr[4] = 50;
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
printf("arr[%d] = %d\n", i, arr[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
19
examples/tests/basic_function_test.c
Archivo normal
19
examples/tests/basic_function_test.c
Archivo normal
@@ -0,0 +1,19 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int test_param(int x) {
|
||||
printf(" In test_param: x = %d\n", x);
|
||||
return x + 1;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Testing basic function calls...\n");
|
||||
|
||||
int result1 = test_param(5);
|
||||
printf("Result 1: %d\n", result1);
|
||||
|
||||
int result2 = test_param(10);
|
||||
printf("Result 2: %d\n", result2);
|
||||
|
||||
printf("Test completed.\n");
|
||||
return 0;
|
||||
}
|
||||
16
examples/tests/bitwise_test.c
Archivo normal
16
examples/tests/bitwise_test.c
Archivo normal
@@ -0,0 +1,16 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int a = 12; // 1100 in binary
|
||||
int b = 10; // 1010 in binary
|
||||
|
||||
printf("a = %d, b = %d\n", a, b);
|
||||
printf("a & b = %d\n", a & b); // bitwise AND
|
||||
printf("a | b = %d\n", a | b); // bitwise OR
|
||||
printf("a ^ b = %d\n", a ^ b); // bitwise XOR
|
||||
printf("~a = %d\n", ~a); // bitwise NOT
|
||||
printf("a << 2 = %d\n", a << 2); // left shift
|
||||
printf("a >> 1 = %d\n", a >> 1); // right shift
|
||||
|
||||
return 0;
|
||||
}
|
||||
29
examples/tests/bubble_sort_test.c
Archivo normal
29
examples/tests/bubble_sort_test.c
Archivo normal
@@ -0,0 +1,29 @@
|
||||
#include <stdio.h>
|
||||
void bubble_sort(int arr[], int n) {
|
||||
for (int i = 0; i < n - 1; i++) {
|
||||
for (int j = 0; j < n - i - 1; j++) {
|
||||
if (arr[j] > arr[j + 1]) {
|
||||
int temp = arr[j];
|
||||
arr[j] = arr[j + 1];
|
||||
arr[j + 1] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
int main() {
|
||||
int numbers[5] = {64, 34, 25, 12, 22};
|
||||
printf("Original array: ");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
printf("%d ", numbers[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
bubble_sort(numbers, 5);
|
||||
|
||||
printf("Sorted array: ");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
printf("%d ", numbers[i]);
|
||||
}
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
16
examples/tests/complex_ptr_test.c
Archivo normal
16
examples/tests/complex_ptr_test.c
Archivo normal
@@ -0,0 +1,16 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int a = 10;
|
||||
int b = 20;
|
||||
int *ptr1 = &a;
|
||||
int *ptr2 = &b;
|
||||
|
||||
// Swap the pointer targets
|
||||
*ptr1 = *ptr1 + *ptr2;
|
||||
*ptr2 = *ptr1 - *ptr2;
|
||||
*ptr1 = *ptr1 - *ptr2;
|
||||
|
||||
printf("Swapped values: a=%d, b=%d\n", a, b);
|
||||
return 0;
|
||||
}
|
||||
20
examples/tests/compound_operators_test.c
Archivo normal
20
examples/tests/compound_operators_test.c
Archivo normal
@@ -0,0 +1,20 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int x = 10;
|
||||
printf("Initial x = %d\n", x);
|
||||
|
||||
x += 5;
|
||||
printf("After x += 5: %d\n", x);
|
||||
|
||||
x -= 3;
|
||||
printf("After x -= 3: %d\n", x);
|
||||
|
||||
x *= 2;
|
||||
printf("After x *= 2: %d\n", x);
|
||||
|
||||
x /= 4;
|
||||
printf("After x /= 4: %d\n", x);
|
||||
|
||||
return 0;
|
||||
}
|
||||
52
examples/tests/comprehensive_test.c
Archivo normal
52
examples/tests/comprehensive_test.c
Archivo normal
@@ -0,0 +1,52 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("=== ALECC Compiler Test Suite ===\n");
|
||||
|
||||
// Test 1: Basic arithmetic and variables
|
||||
printf("Test 1: Basic operations\n");
|
||||
int a = 10;
|
||||
int b = 20;
|
||||
printf(" a = %d, b = %d\n", a, b);
|
||||
printf(" a + b = %d\n", a + b);
|
||||
printf(" a * b = %d\n", a * b);
|
||||
printf(" a %% 3 = %d\n", a % 3);
|
||||
|
||||
// Test 2: Pointer operations
|
||||
printf("Test 2: Pointer operations\n");
|
||||
int x = 42;
|
||||
int *ptr = &x;
|
||||
printf(" x = %d\n", x);
|
||||
printf(" *ptr = %d\n", *ptr);
|
||||
*ptr = 100;
|
||||
printf(" After *ptr = 100: x = %d\n", x);
|
||||
|
||||
// Test 3: Arrays
|
||||
printf("Test 3: Array operations\n");
|
||||
int arr[3];
|
||||
arr[0] = 1;
|
||||
arr[1] = 2;
|
||||
arr[2] = 3;
|
||||
printf(" arr[0] = %d, arr[1] = %d, arr[2] = %d\n", arr[0], arr[1], arr[2]);
|
||||
|
||||
// Test 4: Control flow
|
||||
printf("Test 4: Control flow\n");
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (i % 2 == 0) {
|
||||
printf(" %d is even\n", i);
|
||||
} else {
|
||||
printf(" %d is odd\n", i);
|
||||
}
|
||||
}
|
||||
|
||||
// Test 5: While loops
|
||||
printf("Test 5: While loop\n");
|
||||
int count = 0;
|
||||
while (count < 3) {
|
||||
printf(" count = %d\n", count);
|
||||
count++;
|
||||
}
|
||||
|
||||
printf("=== All tests completed successfully! ===\n");
|
||||
return 0;
|
||||
}
|
||||
17
examples/tests/debug_else_only.c
Archivo normal
17
examples/tests/debug_else_only.c
Archivo normal
@@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int debug_else_only(int n) {
|
||||
printf("Called with n = %d\n", n);
|
||||
if (n <= 1) {
|
||||
return 1;
|
||||
} else {
|
||||
return n * 2;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Testing else-only...\n");
|
||||
int result = debug_else_only(5);
|
||||
printf("Result = %d\n", result);
|
||||
return 0;
|
||||
}
|
||||
25
examples/tests/debug_expr_test.c
Archivo normal
25
examples/tests/debug_expr_test.c
Archivo normal
@@ -0,0 +1,25 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int x = 5;
|
||||
int y = 3;
|
||||
|
||||
printf("x = %d, y = %d\n", x, y);
|
||||
|
||||
int sum = x + y;
|
||||
printf("x + y = %d\n", sum);
|
||||
|
||||
int diff = x - y;
|
||||
printf("x - y = %d\n", diff);
|
||||
|
||||
int prod = sum * diff;
|
||||
printf("(x + y) * (x - y) = %d\n", prod);
|
||||
|
||||
int mod = x % y;
|
||||
printf("x %% y = %d\n", mod);
|
||||
|
||||
int result = prod + mod;
|
||||
printf("result = %d\n", result);
|
||||
|
||||
return 0;
|
||||
}
|
||||
16
examples/tests/debug_if_only.c
Archivo normal
16
examples/tests/debug_if_only.c
Archivo normal
@@ -0,0 +1,16 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int debug_if_only(int n) {
|
||||
if (n > 0) {
|
||||
printf("In if branch\n");
|
||||
return n + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Testing if-only...\n");
|
||||
int result = debug_if_only(5);
|
||||
printf("Result = %d\n", result);
|
||||
return 0;
|
||||
}
|
||||
8
examples/tests/debug_printf.c
Archivo normal
8
examples/tests/debug_printf.c
Archivo normal
@@ -0,0 +1,8 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("First call\n");
|
||||
printf("Second call\n");
|
||||
printf("Third call\n");
|
||||
return 0;
|
||||
}
|
||||
20
examples/tests/debug_recursion_test.c
Archivo normal
20
examples/tests/debug_recursion_test.c
Archivo normal
@@ -0,0 +1,20 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int test_recursion(int n) {
|
||||
printf("Entering test_recursion with n = %d\n", n);
|
||||
if (n <= 0) {
|
||||
printf("Base case reached, returning 0\n");
|
||||
return 0;
|
||||
}
|
||||
printf("Calling recursion with n-1 = %d\n", n-1);
|
||||
int result = test_recursion(n - 1);
|
||||
printf("Recursion returned %d for n = %d\n", result, n);
|
||||
return result + 1;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Starting recursion test\n");
|
||||
int result = test_recursion(2);
|
||||
printf("Final result: %d\n", result);
|
||||
return 0;
|
||||
}
|
||||
9
examples/tests/deref_test.c
Archivo normal
9
examples/tests/deref_test.c
Archivo normal
@@ -0,0 +1,9 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int x = 42;
|
||||
int *ptr = &x;
|
||||
int y = *ptr;
|
||||
printf("y = %d\n", y);
|
||||
return 0;
|
||||
}
|
||||
8
examples/tests/double_printf.c
Archivo normal
8
examples/tests/double_printf.c
Archivo normal
@@ -0,0 +1,8 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int x = 42;
|
||||
printf("first\n");
|
||||
printf("second\n");
|
||||
return 0;
|
||||
}
|
||||
56
examples/tests/edge_case_test.c
Archivo normal
56
examples/tests/edge_case_test.c
Archivo normal
@@ -0,0 +1,56 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("=== Array Assignment Edge Cases ===\n");
|
||||
|
||||
// Test 1: Multiple arrays
|
||||
int arr1[3];
|
||||
int arr2[3];
|
||||
arr1[0] = 1;
|
||||
arr1[1] = 2;
|
||||
arr1[2] = 3;
|
||||
arr2[0] = 10;
|
||||
arr2[1] = 20;
|
||||
arr2[2] = 30;
|
||||
printf("arr1: [%d, %d, %d]\n", arr1[0], arr1[1], arr1[2]);
|
||||
printf("arr2: [%d, %d, %d]\n", arr2[0], arr2[1], arr2[2]);
|
||||
|
||||
// Test 2: Sequential assignments
|
||||
int seq[5];
|
||||
int k = 0;
|
||||
while (k < 5) {
|
||||
seq[k] = k * k;
|
||||
k = k + 1;
|
||||
}
|
||||
printf("Sequence: ");
|
||||
k = 0;
|
||||
while (k < 5) {
|
||||
printf("%d ", seq[k]);
|
||||
k = k + 1;
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
// Test 3: Array with function calls
|
||||
int result[3];
|
||||
printf("Setting result[0] = 5\n");
|
||||
result[0] = 5;
|
||||
printf("result[0] = %d\n", result[0]);
|
||||
printf("Setting result[1] = result[0] * 2\n");
|
||||
result[1] = result[0] * 2;
|
||||
printf("result[1] = %d\n", result[1]);
|
||||
printf("Setting result[2] = result[1] + result[0]\n");
|
||||
result[2] = result[1] + result[0];
|
||||
printf("result[2] = %d\n", result[2]);
|
||||
|
||||
// Test 4: Large indices to test multiplication
|
||||
int big_arr[100];
|
||||
big_arr[99] = 42;
|
||||
big_arr[50] = 25;
|
||||
big_arr[1] = 99;
|
||||
printf("big_arr[99] = %d\n", big_arr[99]);
|
||||
printf("big_arr[50] = %d\n", big_arr[50]);
|
||||
printf("big_arr[1] = %d\n", big_arr[1]);
|
||||
|
||||
printf("All edge cases passed!\n");
|
||||
return 0;
|
||||
}
|
||||
11
examples/tests/even_test.c
Archivo normal
11
examples/tests/even_test.c
Archivo normal
@@ -0,0 +1,11 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int i = 4;
|
||||
if (i % 2 == 0) {
|
||||
printf("even\n");
|
||||
} else {
|
||||
printf("odd\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
15
examples/tests/exact_repro_test.c
Archivo normal
15
examples/tests/exact_repro_test.c
Archivo normal
@@ -0,0 +1,15 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int arr[3];
|
||||
arr[0] = 1;
|
||||
printf("After arr[0] = 1: arr[0] = %d, arr[1] = %d, arr[2] = %d\n", arr[0], arr[1], arr[2]);
|
||||
|
||||
arr[1] = 2;
|
||||
printf("After arr[1] = 2: arr[0] = %d, arr[1] = %d, arr[2] = %d\n", arr[0], arr[1], arr[2]);
|
||||
|
||||
arr[2] = 3;
|
||||
printf("After arr[2] = 3: arr[0] = %d, arr[1] = %d, arr[2] = %d\n", arr[0], arr[1], arr[2]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
7
examples/tests/explicit_return_test.c
Archivo normal
7
examples/tests/explicit_return_test.c
Archivo normal
@@ -0,0 +1,7 @@
|
||||
int simple_explicit_return(int n) {
|
||||
return 42;
|
||||
}
|
||||
|
||||
int main() {
|
||||
return simple_explicit_return(5);
|
||||
}
|
||||
14
examples/tests/factorial_test.c
Archivo normal
14
examples/tests/factorial_test.c
Archivo normal
@@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
int factorial(int n) {
|
||||
if (n <= 1) {
|
||||
return 1;
|
||||
}
|
||||
return n * factorial(n - 1);
|
||||
}
|
||||
int main() {
|
||||
printf("Testing factorial...\n");
|
||||
for (int i = 0; i <= 5; i++) {
|
||||
printf("factorial(%d) = %d\n", i, factorial(i));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
10
examples/tests/fibonacci_no_printf.c
Archivo normal
10
examples/tests/fibonacci_no_printf.c
Archivo normal
@@ -0,0 +1,10 @@
|
||||
int fibonacci(int n) {
|
||||
if (n <= 1) {
|
||||
return n;
|
||||
}
|
||||
return fibonacci(n - 1) + fibonacci(n - 2);
|
||||
}
|
||||
|
||||
int main() {
|
||||
return fibonacci(5);
|
||||
}
|
||||
13
examples/tests/fibonacci_simple.c
Archivo normal
13
examples/tests/fibonacci_simple.c
Archivo normal
@@ -0,0 +1,13 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int fibonacci(int n) {
|
||||
if (n <= 1) {
|
||||
return n;
|
||||
}
|
||||
return fibonacci(n - 1) + fibonacci(n - 2);
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("fib(5) = %d\n", fibonacci(5));
|
||||
return 0;
|
||||
}
|
||||
14
examples/tests/fibonacci_test.c
Archivo normal
14
examples/tests/fibonacci_test.c
Archivo normal
@@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
int fibonacci(int n) {
|
||||
if (n <= 1) {
|
||||
return n;
|
||||
}
|
||||
return fibonacci(n - 1) + fibonacci(n - 2);
|
||||
}
|
||||
int main() {
|
||||
printf("Testing fibonacci...\n");
|
||||
for (int i = 0; i <= 10; i++) {
|
||||
printf("fibonacci(%d) = %d\n", i, fibonacci(i));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
19
examples/tests/final_success_test.c
Archivo normal
19
examples/tests/final_success_test.c
Archivo normal
@@ -0,0 +1,19 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("ALECC Test Summary\n");
|
||||
|
||||
int arr[3];
|
||||
arr[0] = 10;
|
||||
arr[1] = 20;
|
||||
arr[2] = 30;
|
||||
printf("Arrays: arr[1] = %d (FIXED!)\n", arr[1]);
|
||||
|
||||
int val = 42;
|
||||
int* ptr = &val;
|
||||
*ptr = 99;
|
||||
printf("Pointers: value is now %d\n", val);
|
||||
|
||||
printf("ALECC compiler SUCCESS!\n");
|
||||
return 0;
|
||||
}
|
||||
54
examples/tests/final_summary_test.c
Archivo normal
54
examples/tests/final_summary_test.c
Archivo normal
@@ -0,0 +1,54 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int fibonacci(int n) {
|
||||
if (n <= 1) {
|
||||
return n;
|
||||
}
|
||||
return fibonacci(n - 1) + fibonacci(n - 2);
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("=== ALECC Final Test Summary ===\n");
|
||||
|
||||
// Test 1: Basic math
|
||||
int a = 15;
|
||||
int b = 4;
|
||||
printf("Math: %d + %d = %d\n", a, b, a + b);
|
||||
printf("Modulo: %d %% %d = %d\n", a, b, a % b);
|
||||
|
||||
// Test 2: Arrays (our fixed feature!)
|
||||
int arr[5];
|
||||
arr[0] = 10;
|
||||
arr[1] = 20; // This was the bug we fixed!
|
||||
arr[2] = 30;
|
||||
arr[3] = 40;
|
||||
arr[4] = 50;
|
||||
printf("Array: arr[1] = %d (FIXED!)\n", arr[1]);
|
||||
|
||||
// Test 3: Pointers
|
||||
int val = 42;
|
||||
int* ptr = &val;
|
||||
*ptr = 99;
|
||||
printf("Pointers: value is now %d\n", val);
|
||||
|
||||
// Test 4: Control flow
|
||||
int i = 0;
|
||||
printf("Loop: ");
|
||||
while (i < 5) {
|
||||
printf("%d ", i);
|
||||
i = i + 1;
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
// Test 5: Recursion
|
||||
printf("Fibonacci(6) = %d\n", fibonacci(6));
|
||||
|
||||
// Test 6: Multiple printf calls (stack alignment fixed!)
|
||||
printf("Stack alignment test:\n");
|
||||
printf("Line 1\n");
|
||||
printf("Line 2\n");
|
||||
printf("Line 3\n");
|
||||
|
||||
printf("SUCCESS: All major features working!\n");
|
||||
return 0;
|
||||
}
|
||||
76
examples/tests/final_test.c
Archivo normal
76
examples/tests/final_test.c
Archivo normal
@@ -0,0 +1,76 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int fibonacci(int n) {
|
||||
if (n <= 1) {
|
||||
return n;
|
||||
}
|
||||
return fibonacci(n - 1) + fibonacci(n - 2);
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("=== ALECC Final Comprehensive Test ===\n");
|
||||
|
||||
// Test 1: All basic operations
|
||||
int a = 15;
|
||||
int b = 4;
|
||||
printf("Basic operations:\n");
|
||||
printf(" %d + %d = %d\n", a, b, a + b);
|
||||
printf(" %d - %d = %d\n", a, b, a - b);
|
||||
printf(" %d * %d = %d\n", a, b, a * b);
|
||||
printf(" %d / %d = %d\n", a, b, a / b);
|
||||
printf(" %d %% %d = %d\n", a, b, a % b);
|
||||
|
||||
// Test 2: Arrays with all indices working
|
||||
printf("\nArray test:\n");
|
||||
int numbers[7];
|
||||
int i = 0;
|
||||
while (i < 7) {
|
||||
numbers[i] = i * i + 1;
|
||||
printf(" numbers[%d] = %d\n", i, numbers[i]);
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
// Test 3: Pointers
|
||||
printf("\nPointer test:\n");
|
||||
int value = 42;
|
||||
int* ptr = &value;
|
||||
printf(" value = %d\n", value);
|
||||
printf(" *ptr = %d\n", *ptr);
|
||||
*ptr = 100;
|
||||
printf(" After *ptr = 100: value = %d\n", value);
|
||||
|
||||
// Test 4: Complex expressions
|
||||
printf("\nComplex expressions:\n");
|
||||
int x = 5;
|
||||
int y = 3;
|
||||
int result = (x + y) * (x - y) + x % y;
|
||||
printf(" (%d + %d) * (%d - %d) + %d %% %d = %d\n", x, y, x, y, x, y, result);
|
||||
|
||||
// Test 5: Control flow
|
||||
printf("\nControl flow test:\n");
|
||||
int j = 0;
|
||||
while (j < 5) {
|
||||
if (j % 2 == 0) {
|
||||
printf(" %d is even\n", j);
|
||||
} else {
|
||||
printf(" %d is odd\n", j);
|
||||
}
|
||||
j = j + 1;
|
||||
}
|
||||
|
||||
// Test 6: Function calls and recursion
|
||||
printf("\nRecursion test:\n");
|
||||
int n = 6;
|
||||
printf(" fibonacci(%d) = %d\n", n, fibonacci(n));
|
||||
|
||||
// Test 7: Multiple printf calls (stack alignment test)
|
||||
printf("\nMultiple printf test:\n");
|
||||
printf(" Line 1\n");
|
||||
printf(" Line 2\n");
|
||||
printf(" Line 3\n");
|
||||
printf(" Line 4\n");
|
||||
printf(" Line 5\n");
|
||||
|
||||
printf("\nAll tests passed! ALECC compiler is working perfectly!\n");
|
||||
return 0;
|
||||
}
|
||||
8
examples/tests/for_loop_final_test.c
Archivo normal
8
examples/tests/for_loop_final_test.c
Archivo normal
@@ -0,0 +1,8 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
printf("i = %d\n", i);
|
||||
}
|
||||
return 42;
|
||||
}
|
||||
13
examples/tests/for_loop_test.c
Archivo normal
13
examples/tests/for_loop_test.c
Archivo normal
@@ -0,0 +1,13 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("Testing for loop...\n");
|
||||
|
||||
int i;
|
||||
for (i = 0; i < 5; i = i + 1) {
|
||||
printf("for loop: i = %d\n", i);
|
||||
}
|
||||
|
||||
printf("For loop completed!\n");
|
||||
return 0;
|
||||
}
|
||||
16
examples/tests/format_test.c
Archivo normal
16
examples/tests/format_test.c
Archivo normal
@@ -0,0 +1,16 @@
|
||||
// Simple test without stdio.h to verify formatting didn't break functionality
|
||||
int main() {
|
||||
// Arrays (our main fix!)
|
||||
int arr[3];
|
||||
arr[0] = 10;
|
||||
arr[1] = 20; // The bug we fixed
|
||||
arr[2] = 30;
|
||||
|
||||
// Pointers
|
||||
int val = 42;
|
||||
int* ptr = &val;
|
||||
*ptr = 99;
|
||||
|
||||
// Return the sum to verify functionality
|
||||
return arr[1] + val; // Should be 20 + 99 = 119
|
||||
}
|
||||
13
examples/tests/function_no_params_test.c
Archivo normal
13
examples/tests/function_no_params_test.c
Archivo normal
@@ -0,0 +1,13 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int say_hello() {
|
||||
printf("Hello from function!\n");
|
||||
return 42;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Before function call\n");
|
||||
int result = say_hello();
|
||||
printf("After function call, result = %d\n", result);
|
||||
return 0;
|
||||
}
|
||||
10
examples/tests/function_test.c
Archivo normal
10
examples/tests/function_test.c
Archivo normal
@@ -0,0 +1,10 @@
|
||||
int printf(const char* format, ...);
|
||||
|
||||
int add(int a, int b) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Result: %d\n", add(5, 3));
|
||||
return 0;
|
||||
}
|
||||
6
examples/tests/hello_simple.c
Archivo normal
6
examples/tests/hello_simple.c
Archivo normal
@@ -0,0 +1,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("Hello world!\n");
|
||||
return 0;
|
||||
}
|
||||
20
examples/tests/if_else_return_test.c
Archivo normal
20
examples/tests/if_else_return_test.c
Archivo normal
@@ -0,0 +1,20 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int if_else_return_test(int n) {
|
||||
printf("Called with n = %d\n", n);
|
||||
if (n <= 1) {
|
||||
printf("Returning from if branch\n");
|
||||
return 1;
|
||||
}
|
||||
printf("In else branch\n");
|
||||
return n * 2;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Testing if-else return...\n");
|
||||
int result1 = if_else_return_test(0);
|
||||
printf("Result1 = %d\n", result1);
|
||||
int result2 = if_else_return_test(3);
|
||||
printf("Result2 = %d\n", result2);
|
||||
return 0;
|
||||
}
|
||||
21
examples/tests/if_else_return_test_fixed.c
Archivo normal
21
examples/tests/if_else_return_test_fixed.c
Archivo normal
@@ -0,0 +1,21 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int if_else_return_test_fixed(int n) {
|
||||
printf("Called with n = %d\n", n);
|
||||
if (n <= 1) {
|
||||
printf("Returning from if branch\n");
|
||||
return 1;
|
||||
} else {
|
||||
printf("In else branch\n");
|
||||
return n * 2;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Testing if-else return with explicit braces...\n");
|
||||
int result1 = if_else_return_test_fixed(0);
|
||||
printf("Result1 = %d\n", result1);
|
||||
int result2 = if_else_return_test_fixed(3);
|
||||
printf("Result2 = %d\n", result2);
|
||||
return 0;
|
||||
}
|
||||
12
examples/tests/if_else_test.c
Archivo normal
12
examples/tests/if_else_test.c
Archivo normal
@@ -0,0 +1,12 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
if (i % 2 == 0) {
|
||||
printf("%d is even\n", i);
|
||||
} else {
|
||||
printf("%d is odd\n", i);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
10
examples/tests/if_only.c
Archivo normal
10
examples/tests/if_only.c
Archivo normal
@@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int i = 4;
|
||||
int result = i % 2;
|
||||
if (result == 0) {
|
||||
printf("zero\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
22
examples/tests/index1_test.c
Archivo normal
22
examples/tests/index1_test.c
Archivo normal
@@ -0,0 +1,22 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int arr[3];
|
||||
|
||||
// Test with index 1 specifically
|
||||
printf("Testing arr[1] assignment:\n");
|
||||
|
||||
arr[1] = 42;
|
||||
printf("After arr[1] = 42: arr[1] = %d\n", arr[1]);
|
||||
|
||||
arr[1] = 7;
|
||||
printf("After arr[1] = 7: arr[1] = %d\n", arr[1]);
|
||||
|
||||
arr[1] = 0;
|
||||
printf("After arr[1] = 0: arr[1] = %d\n", arr[1]);
|
||||
|
||||
arr[1] = 1;
|
||||
printf("After arr[1] = 1: arr[1] = %d\n", arr[1]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
10
examples/tests/minimal_function_test.c
Archivo normal
10
examples/tests/minimal_function_test.c
Archivo normal
@@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int test_func() {
|
||||
return 99;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int result = test_func();
|
||||
return result;
|
||||
}
|
||||
14
examples/tests/minimal_return_test.c
Archivo normal
14
examples/tests/minimal_return_test.c
Archivo normal
@@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int minimal_return_test(int n) {
|
||||
printf("Called with n = %d\n", n);
|
||||
printf("About to return\n");
|
||||
return n * 2;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Testing minimal return...\n");
|
||||
int result = minimal_return_test(3);
|
||||
printf("Result = %d\n", result);
|
||||
return 0;
|
||||
}
|
||||
10
examples/tests/modulo_comprehensive.c
Archivo normal
10
examples/tests/modulo_comprehensive.c
Archivo normal
@@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("Testing modulo operator:\n");
|
||||
printf("10 %% 3 = %d\n", 10 % 3);
|
||||
printf("15 %% 4 = %d\n", 15 % 4);
|
||||
printf("8 %% 2 = %d\n", 8 % 2);
|
||||
printf("9 %% 2 = %d\n", 9 % 2);
|
||||
return 0;
|
||||
}
|
||||
8
examples/tests/modulo_only.c
Archivo normal
8
examples/tests/modulo_only.c
Archivo normal
@@ -0,0 +1,8 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int i = 4;
|
||||
int result = i % 2;
|
||||
printf("result: %d\n", result);
|
||||
return 0;
|
||||
}
|
||||
9
examples/tests/modulo_test.c
Archivo normal
9
examples/tests/modulo_test.c
Archivo normal
@@ -0,0 +1,9 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int a = 7;
|
||||
int b = 3;
|
||||
int result = a % b;
|
||||
printf("%d %% %d = %d\n", a, b, result);
|
||||
return 0;
|
||||
}
|
||||
6
examples/tests/multiple_vars.c
Archivo normal
6
examples/tests/multiple_vars.c
Archivo normal
@@ -0,0 +1,6 @@
|
||||
int main() {
|
||||
int x = 10;
|
||||
int y = 32;
|
||||
int z = x + y;
|
||||
return z;
|
||||
}
|
||||
8
examples/tests/no_printf_test.c
Archivo normal
8
examples/tests/no_printf_test.c
Archivo normal
@@ -0,0 +1,8 @@
|
||||
int simple_function(int x) {
|
||||
return x + 1;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int result = simple_function(5);
|
||||
return result;
|
||||
}
|
||||
7
examples/tests/null_ptr_test.c
Archivo normal
7
examples/tests/null_ptr_test.c
Archivo normal
@@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int *ptr = 0;
|
||||
printf("Null pointer test done\n");
|
||||
return 0;
|
||||
}
|
||||
34
examples/tests/pointer_comprehensive_test.c
Archivo normal
34
examples/tests/pointer_comprehensive_test.c
Archivo normal
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* ALECC Pointer Support Test Suite
|
||||
* This file demonstrates all implemented pointer features
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
// Test 1: Basic pointer declaration and assignment
|
||||
int x = 42;
|
||||
int *ptr = &x; // Address-of operator
|
||||
|
||||
// Test 2: Reading through pointer dereference
|
||||
int value = *ptr; // Dereference for reading
|
||||
|
||||
// Test 3: Writing through pointer dereference
|
||||
*ptr = 100; // Dereference for assignment
|
||||
|
||||
// Test 4: Multiple pointers
|
||||
int y = 200;
|
||||
int *ptr2 = &y;
|
||||
|
||||
// Test 5: Pointer reassignment
|
||||
ptr = ptr2; // Point to different variable
|
||||
|
||||
// Test 6: Complex expressions with dereferences
|
||||
int result = *ptr + *ptr2; // Both pointers pointing to same location
|
||||
|
||||
// Test 7: Null pointer
|
||||
int *null_ptr = 0;
|
||||
|
||||
printf("All pointer tests compiled successfully!\n");
|
||||
return 0;
|
||||
}
|
||||
11
examples/tests/pointer_test.c
Archivo normal
11
examples/tests/pointer_test.c
Archivo normal
@@ -0,0 +1,11 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int x = 42;
|
||||
int *ptr = &x;
|
||||
printf("x = %d\n", x);
|
||||
printf("*ptr = %d\n", *ptr);
|
||||
*ptr = 100;
|
||||
printf("x after *ptr = 100: %d\n", x);
|
||||
return 0;
|
||||
}
|
||||
9
examples/tests/ptr_assign_test.c
Archivo normal
9
examples/tests/ptr_assign_test.c
Archivo normal
@@ -0,0 +1,9 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int x = 42;
|
||||
int *ptr = &x;
|
||||
*ptr = 100;
|
||||
printf("x = %d\n", x);
|
||||
return 0;
|
||||
}
|
||||
19
examples/tests/sequence_test.c
Archivo normal
19
examples/tests/sequence_test.c
Archivo normal
@@ -0,0 +1,19 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int arr[3];
|
||||
|
||||
printf("Step 1: arr[0] = 1\n");
|
||||
arr[0] = 1;
|
||||
printf("arr[0] = %d, arr[1] = %d, arr[2] = %d\n", arr[0], arr[1], arr[2]);
|
||||
|
||||
printf("Step 2: arr[2] = 3\n");
|
||||
arr[2] = 3;
|
||||
printf("arr[0] = %d, arr[1] = %d, arr[2] = %d\n", arr[0], arr[1], arr[2]);
|
||||
|
||||
printf("Step 3: arr[1] = 2\n");
|
||||
arr[1] = 2;
|
||||
printf("arr[0] = %d, arr[1] = %d, arr[2] = %d\n", arr[0], arr[1], arr[2]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
17
examples/tests/simple_array_test.c
Archivo normal
17
examples/tests/simple_array_test.c
Archivo normal
@@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int arr[3];
|
||||
|
||||
// Set values directly
|
||||
arr[0] = 100;
|
||||
arr[1] = 200;
|
||||
arr[2] = 300;
|
||||
|
||||
// Test reading
|
||||
printf("Reading: arr[0] = %d\n", arr[0]);
|
||||
printf("Reading: arr[1] = %d\n", arr[1]);
|
||||
printf("Reading: arr[2] = %d\n", arr[2]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
11
examples/tests/simple_complex_test.c
Archivo normal
11
examples/tests/simple_complex_test.c
Archivo normal
@@ -0,0 +1,11 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int x = 5;
|
||||
int y = 3;
|
||||
int result = (x + y) * (x - y) + x % y;
|
||||
|
||||
printf("Complex expression result: %d\n", result);
|
||||
|
||||
return 0;
|
||||
}
|
||||
10
examples/tests/simple_for_debug.c
Archivo normal
10
examples/tests/simple_for_debug.c
Archivo normal
@@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int i;
|
||||
for (i = 0; i < 3; i++) {
|
||||
printf("i = %d\n", i);
|
||||
}
|
||||
printf("Final i = %d\n", i);
|
||||
return 0;
|
||||
}
|
||||
9
examples/tests/simple_for_debug2.c
Archivo normal
9
examples/tests/simple_for_debug2.c
Archivo normal
@@ -0,0 +1,9 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int i;
|
||||
for (i = 0; i < 3; i++) {
|
||||
printf("i = %d\n", i);
|
||||
}
|
||||
return 42;
|
||||
}
|
||||
5
examples/tests/simple_format_test.c
Archivo normal
5
examples/tests/simple_format_test.c
Archivo normal
@@ -0,0 +1,5 @@
|
||||
int main() {
|
||||
int x = 10;
|
||||
int y = 20;
|
||||
return x + y; // Should be 30
|
||||
}
|
||||
10
examples/tests/simple_function_test.c
Archivo normal
10
examples/tests/simple_function_test.c
Archivo normal
@@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int simple_function(int x) {
|
||||
return x + 1;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("result = %d\n", simple_function(5));
|
||||
return 0;
|
||||
}
|
||||
11
examples/tests/simple_if_else.c
Archivo normal
11
examples/tests/simple_if_else.c
Archivo normal
@@ -0,0 +1,11 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int i = 5;
|
||||
if (i % 2 == 0) {
|
||||
printf("even\n");
|
||||
} else {
|
||||
printf("odd\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
14
examples/tests/simple_loop_test.c
Archivo normal
14
examples/tests/simple_loop_test.c
Archivo normal
@@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("Testing simple loop...\n");
|
||||
|
||||
int i = 0;
|
||||
while (i < 3) {
|
||||
printf("i = %d\n", i);
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
printf("Loop completed!\n");
|
||||
return 0;
|
||||
}
|
||||
14
examples/tests/simple_pointers_test.c
Archivo normal
14
examples/tests/simple_pointers_test.c
Archivo normal
@@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int x = 42;
|
||||
int *ptr = &x;
|
||||
|
||||
printf("x = %d\n", x);
|
||||
printf("*ptr = %d\n", *ptr);
|
||||
|
||||
*ptr = 100;
|
||||
printf("After *ptr = 100, x = %d\n", x);
|
||||
|
||||
return 0;
|
||||
}
|
||||
6
examples/tests/simple_printf_test.c
Archivo normal
6
examples/tests/simple_printf_test.c
Archivo normal
@@ -0,0 +1,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("Simple test\n");
|
||||
return 0;
|
||||
}
|
||||
20
examples/tests/simple_recursion_debug.c
Archivo normal
20
examples/tests/simple_recursion_debug.c
Archivo normal
@@ -0,0 +1,20 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int factorial_simple(int n) {
|
||||
printf("factorial_simple called with n = %d\n", n);
|
||||
if (n <= 1) {
|
||||
printf("Base case reached, returning 1\n");
|
||||
return 1;
|
||||
}
|
||||
printf("Calling factorial_simple(%d)\n", n - 1);
|
||||
int result = factorial_simple(n - 1);
|
||||
printf("Got result %d, returning %d * %d = %d\n", result, n, result, n * result);
|
||||
return n * result;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Testing simple recursion...\n");
|
||||
int result = factorial_simple(3);
|
||||
printf("factorial_simple(3) = %d\n", result);
|
||||
return 0;
|
||||
}
|
||||
14
examples/tests/simple_recursion_test.c
Archivo normal
14
examples/tests/simple_recursion_test.c
Archivo normal
@@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int countdown(int n) {
|
||||
if (n <= 0) {
|
||||
return 0;
|
||||
}
|
||||
printf("n = %d\n", n);
|
||||
return countdown(n - 1);
|
||||
}
|
||||
|
||||
int main() {
|
||||
countdown(3);
|
||||
return 0;
|
||||
}
|
||||
13
examples/tests/simple_return_test.c
Archivo normal
13
examples/tests/simple_return_test.c
Archivo normal
@@ -0,0 +1,13 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int simple_return_test(int n) {
|
||||
printf("Called with n = %d\n", n);
|
||||
return n * 2;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Testing simple return...\n");
|
||||
int result = simple_return_test(5);
|
||||
printf("Result = %d\n", result);
|
||||
return 0;
|
||||
}
|
||||
7
examples/tests/simple_test.c
Archivo normal
7
examples/tests/simple_test.c
Archivo normal
@@ -0,0 +1,7 @@
|
||||
int printf(const char* format, ...);
|
||||
|
||||
int main() {
|
||||
int i = 5;
|
||||
printf("i = %d\n", i);
|
||||
return 0;
|
||||
}
|
||||
4
examples/tests/simple_var.c
Archivo normal
4
examples/tests/simple_var.c
Archivo normal
@@ -0,0 +1,4 @@
|
||||
int main() {
|
||||
int x = 42;
|
||||
return x;
|
||||
}
|
||||
7
examples/tests/simple_var_test.c
Archivo normal
7
examples/tests/simple_var_test.c
Archivo normal
@@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int x = 42;
|
||||
printf("x = %d\n", x);
|
||||
return 0;
|
||||
}
|
||||
8
examples/tests/single_printf_test.c
Archivo normal
8
examples/tests/single_printf_test.c
Archivo normal
@@ -0,0 +1,8 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int x = 42;
|
||||
int *ptr = &x;
|
||||
printf("*ptr = %d\n", *ptr);
|
||||
return 0;
|
||||
}
|
||||
14
examples/tests/step_by_step_test.c
Archivo normal
14
examples/tests/step_by_step_test.c
Archivo normal
@@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int x = 42;
|
||||
printf("x = %d\n", x);
|
||||
|
||||
int *ptr = &x;
|
||||
printf("*ptr = %d\n", *ptr);
|
||||
|
||||
*ptr = 100;
|
||||
printf("x after assignment = %d\n", x);
|
||||
|
||||
return 0;
|
||||
}
|
||||
15
examples/tests/string_test.c
Archivo normal
15
examples/tests/string_test.c
Archivo normal
@@ -0,0 +1,15 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
char message[] = "Hello, World!";
|
||||
char greeting[] = "Hi there";
|
||||
|
||||
printf("Message: %s\n", message);
|
||||
printf("Greeting: %s\n", greeting);
|
||||
|
||||
// Test character access
|
||||
printf("First char of message: %c\n", message[0]);
|
||||
printf("Last char of greeting: %c\n", greeting[7]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
24
examples/tests/success_summary_test.c
Archivo normal
24
examples/tests/success_summary_test.c
Archivo normal
@@ -0,0 +1,24 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("=== Test Resumen ALECC ===\n");
|
||||
|
||||
// Arrays (nuestro fix principal!)
|
||||
int arr[3];
|
||||
arr[0] = 10;
|
||||
arr[1] = 20; // El bug que arreglamos
|
||||
arr[2] = 30;
|
||||
printf("Arrays: arr[1] = %d (FIXED!)\n", arr[1]);
|
||||
|
||||
// Punteros
|
||||
int val = 42;
|
||||
int* ptr = &val;
|
||||
*ptr = 99;
|
||||
printf("Punteros: valor ahora es %d\n", val);
|
||||
|
||||
// Funciones básicas (sin recursión)
|
||||
printf("Basic functions work!\n");
|
||||
|
||||
printf("ALECC compiler SUCCESS!\n");
|
||||
return 0;
|
||||
}
|
||||
14
examples/tests/sum_recursive_test.c
Archivo normal
14
examples/tests/sum_recursive_test.c
Archivo normal
@@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
int sum_recursive(int n) {
|
||||
if (n <= 0) {
|
||||
return 0;
|
||||
}
|
||||
return n + sum_recursive(n - 1);
|
||||
}
|
||||
int main() {
|
||||
printf("Testing recursive sum...\n");
|
||||
for (int i = 0; i <= 10; i++) {
|
||||
printf("sum(1 to %d) = %d\n", i, sum_recursive(i));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
11
examples/tests/test_final_functionality.c
Archivo normal
11
examples/tests/test_final_functionality.c
Archivo normal
@@ -0,0 +1,11 @@
|
||||
int factorial(int n) {
|
||||
if (n <= 1) {
|
||||
return 1;
|
||||
}
|
||||
return n * factorial(n - 1);
|
||||
}
|
||||
|
||||
int main() {
|
||||
int result = factorial(5);
|
||||
return result;
|
||||
}
|
||||
1
examples/tests/test_for.c
Archivo normal
1
examples/tests/test_for.c
Archivo normal
@@ -0,0 +1 @@
|
||||
int main() { int i; for (i = 0; i < 5; i++) { } return 0; }
|
||||
1
examples/tests/test_for_empty.c
Archivo normal
1
examples/tests/test_for_empty.c
Archivo normal
@@ -0,0 +1 @@
|
||||
int main() { for (;;) { return 0; } }
|
||||
1
examples/tests/test_for_init.c
Archivo normal
1
examples/tests/test_for_init.c
Archivo normal
@@ -0,0 +1 @@
|
||||
int main() { int i; for (i = 0;;) { return 0; } }
|
||||
1
examples/tests/test_for_without_inc.c
Archivo normal
1
examples/tests/test_for_without_inc.c
Archivo normal
@@ -0,0 +1 @@
|
||||
int main() { int i; for (i = 0; i < 5;) { i++; } return 0; }
|
||||
1
examples/tests/test_gcc.c
Archivo normal
1
examples/tests/test_gcc.c
Archivo normal
@@ -0,0 +1 @@
|
||||
int main() { return 0; }
|
||||
1
examples/tests/test_increment.c
Archivo normal
1
examples/tests/test_increment.c
Archivo normal
@@ -0,0 +1 @@
|
||||
int main() { int i; i++; return 0; }
|
||||
6
examples/tests/test_no_include.c
Archivo normal
6
examples/tests/test_no_include.c
Archivo normal
@@ -0,0 +1,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("Testing after include directory removal\n");
|
||||
return 0;
|
||||
}
|
||||
1
examples/tests/test_simple_decl.c
Archivo normal
1
examples/tests/test_simple_decl.c
Archivo normal
@@ -0,0 +1 @@
|
||||
int main() { int i; return 0; }
|
||||
8
examples/tests/two_printf_test.c
Archivo normal
8
examples/tests/two_printf_test.c
Archivo normal
@@ -0,0 +1,8 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int x = 42;
|
||||
int *ptr = &x;
|
||||
printf("Before: x = %d, *ptr = %d\n", x, *ptr);
|
||||
return 0;
|
||||
}
|
||||
11
examples/tests/two_returns_test.c
Archivo normal
11
examples/tests/two_returns_test.c
Archivo normal
@@ -0,0 +1,11 @@
|
||||
int test_two_returns(int n) {
|
||||
if (n <= 1) {
|
||||
return n;
|
||||
}
|
||||
// Explicit return statement
|
||||
return 42;
|
||||
}
|
||||
|
||||
int main() {
|
||||
return test_two_returns(3);
|
||||
}
|
||||
7
examples/tests/var_test.c
Archivo normal
7
examples/tests/var_test.c
Archivo normal
@@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int x = 42;
|
||||
printf("x = %d\n", x);
|
||||
return 0;
|
||||
}
|
||||
28
examples/tests/version_test.c
Archivo normal
28
examples/tests/version_test.c
Archivo normal
@@ -0,0 +1,28 @@
|
||||
// Test the new version with advanced features
|
||||
int test_compound_operators() {
|
||||
int x = 10;
|
||||
x += 5; // 15
|
||||
x *= 2; // 30
|
||||
x /= 3; // 10
|
||||
return x;
|
||||
}
|
||||
|
||||
int test_bitwise_operators() {
|
||||
int a = 12; // 1100 in binary
|
||||
int b = 10; // 1010 in binary
|
||||
|
||||
int result = 0;
|
||||
result += (a & b); // 8 (1000)
|
||||
result += (a | b); // 14 (1110)
|
||||
result += (a ^ b); // 6 (0110)
|
||||
result += (a << 1); // 24 (11000)
|
||||
result += (a >> 1); // 6 (110)
|
||||
|
||||
return result; // 8 + 14 + 6 + 24 + 6 = 58
|
||||
}
|
||||
|
||||
int main() {
|
||||
int comp_result = test_compound_operators(); // 10
|
||||
int bit_result = test_bitwise_operators(); // 58
|
||||
return comp_result + bit_result; // 68
|
||||
}
|
||||
10
examples/tests/while_test.c
Archivo normal
10
examples/tests/while_test.c
Archivo normal
@@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int i = 0;
|
||||
while (i < 5) {
|
||||
printf("i = %d\n", i);
|
||||
i++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Referencia en una nueva incidencia
Block a user