commit e5e75b344f572b660eb1d7b23d34d7242c5cd56a Author: Trevor Maze Date: Sun Jan 25 20:58:36 2026 -0500 SOMEHOW IT WORKS diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0023a53 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +.DS_Store +/.build +/Packages +xcuserdata/ +DerivedData/ +.swiftpm/configuration/registries.json +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata +.netrc diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5d58067 --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ +.PHONY: build run clean release test + +build: + swift build + +release: + swift build -c release + +run: + swift run + +test: + swift test + +clean: + swift package clean diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..5b4139f --- /dev/null +++ b/Package.swift @@ -0,0 +1,15 @@ +// swift-tools-version: 6.2 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "rxcc", + targets: [ + // Targets are the basic building blocks of a package, defining a module or a test suite. + // Targets can depend on other targets in this package and products from dependencies. + .executableTarget( + name: "rxcc" + ), + ] +) diff --git a/Sources/rxcc/rxcc.swift b/Sources/rxcc/rxcc.swift new file mode 100644 index 0000000..da87785 --- /dev/null +++ b/Sources/rxcc/rxcc.swift @@ -0,0 +1,153 @@ +enum Constant { + case Integer(value: Int) +} + +struct Return { + let value: Constant +} + +struct Function { + let name: String + let statement: Return +} + +struct Program { + let contents: Function +} + +enum TokenType { + case BRACE_OPEN + case BRACE_CLOSE + case PARENTHESIS_OPEN + case PARENTHESIS_CLOSE + case SEMICOLON + case INT + case RETURN + case IDENTIFIER + case LITERAL_INTEGER + + case UNDEFINED +} + +struct Token { + let content: Substring + let type: TokenType +} + +typealias Construct = [Element] + +enum Element { + case Construct(type: Construct) + case Token(type: TokenType) +} + + + +let expression: Construct = [ + .Token(type: .LITERAL_INTEGER) +] +let statement: Construct = [ + .Token(type: .RETURN), + .Construct(type: expression), + .Token(type: .SEMICOLON) +] +let function: Construct = [ + .Token(type: .INT), + .Token(type: .IDENTIFIER), + .Token(type: .PARENTHESIS_OPEN), + .Token(type: .PARENTHESIS_CLOSE), + .Token(type: .BRACE_OPEN), + .Construct(type: statement), + .Token(type: .BRACE_CLOSE) +] +let program: Construct = [ + .Construct(type: function) +] + + + +@main +struct rxcc { + static func main() { + let lexed: [Substring] = lex(string: """ + int main() { + return 100; + } + """) + parse(lexed: lexed) + } +} + +func lex(string: String) -> [Substring] { + var line = string.replacing("\n", with: " ") + line = line.replacing("\t", with: " ") + line = line.replacing("{", with: " { ") + line = line.replacing("}", with: " } ") + line = line.replacing("(", with: " ( ") + line = line.replacing(")", with: " ) ") + line = line.replacing(";", with: " ; ") + + do { + let tokens: [Substring] = line.split(separator: try Regex(" +")) + return tokens + } catch { + print("Regex did something wrong") + } + return [] +} + +func parse(lexed: [Substring]) { + var tokens: [Token] = [Token]() + for token: Substring in lexed { + let tokenType: TokenType = categorizeToken(token: token) + tokens.append(Token(content: token, type: tokenType)) + } + tokens = tokens.reversed() + + if validateConstruct(program, tokens: &tokens) { + print("Success") + return + } + + print("Distinct lack of success") +} + +func validateConstruct(_ construct: Construct, tokens: inout [Token]) -> Bool { + for element in construct { + switch element { + case .Construct(let type): + print("Begin validate subconstruct") + if !validateConstruct(type, tokens: &tokens) { + print("Subconstruct validation failed") + return false + } + print("End validate subconstruct") + break + + case .Token(let type): + if let token: Token = tokens.popLast() { + if type != token.type { + print("VALIDATION FAILED FOR TOKEN \"\(token.content)\"") + return false + } + } + } + } + + return true +} + +func categorizeToken(token: Substring) -> TokenType { + if token.firstMatch(of: /{/) != nil { return .BRACE_OPEN } + else if token.firstMatch(of: /}/) != nil { return .BRACE_CLOSE } + else if token.firstMatch(of: /\(/) != nil { return .PARENTHESIS_OPEN } + else if token.firstMatch(of: /\)/) != nil { return .PARENTHESIS_CLOSE } + else if token.firstMatch(of: /;/) != nil { return .SEMICOLON } + else if token.firstMatch(of: /int/) != nil { return .INT } + else if token.firstMatch(of: /return/) != nil { return .RETURN } + else if token.firstMatch(of: /[a-zA-Z]\w*/) != nil { return .IDENTIFIER } + else if token.firstMatch(of: /[0-9]+/) != nil { return .LITERAL_INTEGER } + + return .UNDEFINED +} + diff --git a/c/a.out b/c/a.out new file mode 100755 index 0000000..90f76cf Binary files /dev/null and b/c/a.out differ diff --git a/c/return_2 b/c/return_2 new file mode 100755 index 0000000..096aa21 Binary files /dev/null and b/c/return_2 differ diff --git a/c/return_2.c b/c/return_2.c new file mode 100644 index 0000000..76598f0 --- /dev/null +++ b/c/return_2.c @@ -0,0 +1,4 @@ +int main() { + return 2; +} + diff --git a/c/return_2.s b/c/return_2.s new file mode 100644 index 0000000..b949824 --- /dev/null +++ b/c/return_2.s @@ -0,0 +1,35 @@ + .file "return_2.c" + .text + .globl main + .type main, @function +main: +.LFB0: + .cfi_startproc + pushl %ebp + .cfi_def_cfa_offset 8 + .cfi_offset 5, -8 + movl %esp, %ebp + .cfi_def_cfa_register 5 + call __x86.get_pc_thunk.ax + addl $_GLOBAL_OFFSET_TABLE_, %eax + movl $2, %eax + popl %ebp + .cfi_restore 5 + .cfi_def_cfa 4, 4 + ret + .cfi_endproc +.LFE0: + .size main, .-main + .section .text.__x86.get_pc_thunk.ax,"axG",@progbits,__x86.get_pc_thunk.ax,comdat + .globl __x86.get_pc_thunk.ax + .hidden __x86.get_pc_thunk.ax + .type __x86.get_pc_thunk.ax, @function +__x86.get_pc_thunk.ax: +.LFB1: + .cfi_startproc + movl (%esp), %eax + ret + .cfi_endproc +.LFE1: + .ident "GCC: (GNU) 15.2.1 20260103" + .section .note.GNU-stack,"",@progbits diff --git a/c/test_compiler.sh b/c/test_compiler.sh new file mode 100755 index 0000000..ccc485a --- /dev/null +++ b/c/test_compiler.sh @@ -0,0 +1,158 @@ +#!/bin/bash + +padding_dots=$(printf '%0.1s' "."{1..60}) +padlength=50 +cmp=$1 +success_total=0 +failure_total=0 + +print_test_name () { + test_name=$1 + printf '%s' "$test_name" + printf '%*.*s' 0 $((padlength - ${#test_name})) "$padding_dots" +} + +test_success () { + echo "OK" + ((success++)) +} + +test_failure () { + echo "FAIL" + ((fail++)) +} + +test_not_implemented () { + echo "NOT IMPLEMENTED" +} + +run_our_program () { + actual_out=`./$1 2>/dev/null` + actual_exit_code=$? + rm $1 2>/dev/null +} + +run_correct_program () { + expected_out=`./a.out` + expected_exit_code=$? + rm a.out +} + +compare_program_results () { + # make sure exit code is correct + if [ "$expected_exit_code" -ne "$actual_exit_code" ] || [ "$expected_out" != "$actual_out" ] + then + test_failure + else + test_success + fi +} + +test_stage () { + success=0 + fail=0 + echo "====================================================" + echo "STAGE $1" + echo "===================Valid Programs===================" + for prog in `find . -type f -name "*.c" -path "./stage_$1/valid/*" -not -path "*/valid_multifile/*" 2>/dev/null`; do + + gcc -w $prog + run_correct_program + + base="${prog%.*}" #name of executable (filename w/out extension) + test_name="${base##*valid/}" + + print_test_name $test_name + $cmp $prog 2>/dev/null + status=$? + + if [[ $test_name == "skip_on_failure"* ]]; then + # this may depend on features we haven't implemented yet + # if compilation succeeds, make sure it gives the right result + # otherwise don't count it as success or failure + if [[ -f $base ]] && [[ $status -eq 0 ]]; then + # it succeeded, so run it and make sure it gives the right result + run_our_program $base + compare_program_results + else + test_not_implemented + fi + else + run_our_program $base + compare_program_results + fi + done + # programs with multiple source files + for dir in `ls -d stage_$1/valid_multifile/* 2>/dev/null` ; do + gcc -w $dir/* + + run_correct_program + + base="${dir%.*}" #name of executable (directory w/out extension) + test_name="${base##*valid_multifile/}" + + # need to explicitly specify output name + $cmp -o "$test_name" $dir/* >/dev/null + + print_test_name $test_name + + # check output/exit codes + run_our_program $test_name + compare_program_results + + done + echo "===================Invalid Programs=================" + for prog in `ls stage_$1/invalid/{,**/}*.c 2>/dev/null`; do + + base="${prog%.*}" #name of executable (filename w/out extension) + test_name="${base##*invalid/}" + + $cmp $prog >/dev/null 2>&1 + status=$? #failed, as we expect, if exit code != 0 + print_test_name $test_name + + # make sure neither executable nor assembly was produced + # and exit code is non-zero + if [[ -f $base || -f $base".s" ]] + then + test_failure + rm $base 2>/dev/null + rm $base".s" 2>/dev/null + else + test_success + fi + done + echo "===================Stage $1 Summary=================" + printf "%d successes, %d failures\n" $success $fail + ((success_total=success_total+success)) + ((failure_total=failure_total + fail)) +} + +total_summary () { + echo "===================TOTAL SUMMARY====================" + printf "%d successes, %d failures\n" $success_total $failure_total +} + +if [ "$1" == "" ]; then + echo "USAGE: ./test_compiler.sh /path/to/compiler [stages(optional)]" + echo "EXAMPLE(test specific stages): ./test_compiler.sh ./mycompiler 1 2 4" + echo "EXAMPLE(test all): ./test_compiler.sh ./mycompiler" + exit 1 +fi + +if test 1 -lt $#; then + testcases=("$@") # [1..-1] is testcases + for i in `seq 2 $#`; do + test_stage ${testcases[$i-1]} + done + total_summary + exit 0 +fi + +num_stages=10 + +for i in `seq 1 $num_stages`; do + test_stage $i +done + +total_summary diff --git a/c/tests/stage_1/invalid/missing_paren.c b/c/tests/stage_1/invalid/missing_paren.c new file mode 100644 index 0000000..8e72a5c --- /dev/null +++ b/c/tests/stage_1/invalid/missing_paren.c @@ -0,0 +1,3 @@ +int main( { + return 0; +} \ No newline at end of file diff --git a/c/tests/stage_1/invalid/missing_retval.c b/c/tests/stage_1/invalid/missing_retval.c new file mode 100644 index 0000000..2f8d9bf --- /dev/null +++ b/c/tests/stage_1/invalid/missing_retval.c @@ -0,0 +1,3 @@ +int main() { + return; +} \ No newline at end of file diff --git a/c/tests/stage_1/invalid/no_brace.c b/c/tests/stage_1/invalid/no_brace.c new file mode 100644 index 0000000..96aac66 --- /dev/null +++ b/c/tests/stage_1/invalid/no_brace.c @@ -0,0 +1,2 @@ +int main() { + return 0; diff --git a/c/tests/stage_1/invalid/no_semicolon.c b/c/tests/stage_1/invalid/no_semicolon.c new file mode 100644 index 0000000..584f789 --- /dev/null +++ b/c/tests/stage_1/invalid/no_semicolon.c @@ -0,0 +1,3 @@ +int main() { + return 0 +} diff --git a/c/tests/stage_1/invalid/no_space.c b/c/tests/stage_1/invalid/no_space.c new file mode 100644 index 0000000..14a289b --- /dev/null +++ b/c/tests/stage_1/invalid/no_space.c @@ -0,0 +1,3 @@ +int main() { + return0; +} \ No newline at end of file diff --git a/c/tests/stage_1/invalid/wrong_case.c b/c/tests/stage_1/invalid/wrong_case.c new file mode 100644 index 0000000..bbae350 --- /dev/null +++ b/c/tests/stage_1/invalid/wrong_case.c @@ -0,0 +1,3 @@ +int main() { + RETURN 0; +} \ No newline at end of file diff --git a/c/tests/stage_1/valid/multi_digit.c b/c/tests/stage_1/valid/multi_digit.c new file mode 100644 index 0000000..13f3123 --- /dev/null +++ b/c/tests/stage_1/valid/multi_digit.c @@ -0,0 +1,3 @@ +int main() { + return 100; +} \ No newline at end of file diff --git a/c/tests/stage_1/valid/newlines.c b/c/tests/stage_1/valid/newlines.c new file mode 100644 index 0000000..7d8ba2e --- /dev/null +++ b/c/tests/stage_1/valid/newlines.c @@ -0,0 +1,10 @@ + +int +main +( +) +{ +return +0 +; +} \ No newline at end of file diff --git a/c/tests/stage_1/valid/no_newlines.c b/c/tests/stage_1/valid/no_newlines.c new file mode 100644 index 0000000..6a86477 --- /dev/null +++ b/c/tests/stage_1/valid/no_newlines.c @@ -0,0 +1 @@ +int main(){return 0;} \ No newline at end of file diff --git a/c/tests/stage_1/valid/return_0.c b/c/tests/stage_1/valid/return_0.c new file mode 100644 index 0000000..e9cdae1 --- /dev/null +++ b/c/tests/stage_1/valid/return_0.c @@ -0,0 +1,3 @@ +int main() { + return 0; +} \ No newline at end of file diff --git a/c/tests/stage_1/valid/return_2.c b/c/tests/stage_1/valid/return_2.c new file mode 100644 index 0000000..5c52fee --- /dev/null +++ b/c/tests/stage_1/valid/return_2.c @@ -0,0 +1,3 @@ +int main() { + return 2; +} \ No newline at end of file diff --git a/c/tests/stage_1/valid/spaces.c b/c/tests/stage_1/valid/spaces.c new file mode 100644 index 0000000..e77bfef --- /dev/null +++ b/c/tests/stage_1/valid/spaces.c @@ -0,0 +1 @@ + int main ( ) { return 0 ; } \ No newline at end of file diff --git a/c/tests/stage_10/invalid/fun_redefined_as_var.c b/c/tests/stage_10/invalid/fun_redefined_as_var.c new file mode 100644 index 0000000..8efff10 --- /dev/null +++ b/c/tests/stage_10/invalid/fun_redefined_as_var.c @@ -0,0 +1,9 @@ +int foo() { + return 3; +} + +int foo = 4; + +int main() { + return foo; +} \ No newline at end of file diff --git a/c/tests/stage_10/invalid/multiple_global_defs.c b/c/tests/stage_10/invalid/multiple_global_defs.c new file mode 100644 index 0000000..d46a90e --- /dev/null +++ b/c/tests/stage_10/invalid/multiple_global_defs.c @@ -0,0 +1,7 @@ +int foo = 3; + +int main() { + return foo; +} + +int foo = 0; \ No newline at end of file diff --git a/c/tests/stage_10/invalid/non_constant_init.c b/c/tests/stage_10/invalid/non_constant_init.c new file mode 100644 index 0000000..aa5f3f8 --- /dev/null +++ b/c/tests/stage_10/invalid/non_constant_init.c @@ -0,0 +1,6 @@ +int foo = 3; +int bar = foo + 1; + +int main() { + return bar; +} \ No newline at end of file diff --git a/c/tests/stage_10/invalid/use_before_declaration.c b/c/tests/stage_10/invalid/use_before_declaration.c new file mode 100644 index 0000000..32504c6 --- /dev/null +++ b/c/tests/stage_10/invalid/use_before_declaration.c @@ -0,0 +1,5 @@ +int main() { + return foo; +} + +int foo = 3; \ No newline at end of file diff --git a/c/tests/stage_10/invalid/var_redefined_as_fun.c b/c/tests/stage_10/invalid/var_redefined_as_fun.c new file mode 100644 index 0000000..cf39438 --- /dev/null +++ b/c/tests/stage_10/invalid/var_redefined_as_fun.c @@ -0,0 +1,9 @@ +int foo = 4; + +int foo() { + return 3; +} + +int main() { + return foo; +} \ No newline at end of file diff --git a/c/tests/stage_10/invalid/variable_used_as_fun.c b/c/tests/stage_10/invalid/variable_used_as_fun.c new file mode 100644 index 0000000..3d4884b --- /dev/null +++ b/c/tests/stage_10/invalid/variable_used_as_fun.c @@ -0,0 +1,5 @@ +int foo = 3; + +int main() { + return foo(); +} \ No newline at end of file diff --git a/c/tests/stage_10/valid/forward_declaration.c b/c/tests/stage_10/valid/forward_declaration.c new file mode 100644 index 0000000..ce6e560 --- /dev/null +++ b/c/tests/stage_10/valid/forward_declaration.c @@ -0,0 +1,7 @@ +int foo; + +int main() { + return foo; +} + +int foo = 3; \ No newline at end of file diff --git a/c/tests/stage_10/valid/fun_shadowed_by_variable.c b/c/tests/stage_10/valid/fun_shadowed_by_variable.c new file mode 100644 index 0000000..8f400c8 --- /dev/null +++ b/c/tests/stage_10/valid/fun_shadowed_by_variable.c @@ -0,0 +1,8 @@ +int foo() { + return 3; +} + +int main() { + int foo = 5; + return foo; +} \ No newline at end of file diff --git a/c/tests/stage_10/valid/global.c b/c/tests/stage_10/valid/global.c new file mode 100644 index 0000000..59095a6 --- /dev/null +++ b/c/tests/stage_10/valid/global.c @@ -0,0 +1,5 @@ +int foo = 4; + +int main() { + return foo + 3; +} \ No newline at end of file diff --git a/c/tests/stage_10/valid/global_not_initialized.c b/c/tests/stage_10/valid/global_not_initialized.c new file mode 100644 index 0000000..d8b75ec --- /dev/null +++ b/c/tests/stage_10/valid/global_not_initialized.c @@ -0,0 +1,7 @@ +int foo; + +int main() { + for (int i = 0; i < 3; i = i + 1) + foo = foo + 1; + return foo; +} \ No newline at end of file diff --git a/c/tests/stage_10/valid/global_shadowed.c b/c/tests/stage_10/valid/global_shadowed.c new file mode 100644 index 0000000..762c326 --- /dev/null +++ b/c/tests/stage_10/valid/global_shadowed.c @@ -0,0 +1,10 @@ +int a = 3; + +int main() { + int ret = 0; + if (a) { + int a = 0; + ret = 4; + } + return ret; +} \ No newline at end of file diff --git a/c/tests/stage_10/valid/multiple_global.c b/c/tests/stage_10/valid/multiple_global.c new file mode 100644 index 0000000..909e246 --- /dev/null +++ b/c/tests/stage_10/valid/multiple_global.c @@ -0,0 +1,6 @@ +int a = 3; +int b = 4; + +int main() { + return a * b; +} \ No newline at end of file diff --git a/c/tests/stage_2/invalid/missing_const.c b/c/tests/stage_2/invalid/missing_const.c new file mode 100644 index 0000000..6dd069e --- /dev/null +++ b/c/tests/stage_2/invalid/missing_const.c @@ -0,0 +1,3 @@ +int main() { + return !; +} \ No newline at end of file diff --git a/c/tests/stage_2/invalid/missing_semicolon.c b/c/tests/stage_2/invalid/missing_semicolon.c new file mode 100644 index 0000000..5570d64 --- /dev/null +++ b/c/tests/stage_2/invalid/missing_semicolon.c @@ -0,0 +1,3 @@ +int main() { + return !5 +} \ No newline at end of file diff --git a/c/tests/stage_2/invalid/nested_missing_const.c b/c/tests/stage_2/invalid/nested_missing_const.c new file mode 100644 index 0000000..43b7097 --- /dev/null +++ b/c/tests/stage_2/invalid/nested_missing_const.c @@ -0,0 +1,3 @@ +int main() { + return !~; +} \ No newline at end of file diff --git a/c/tests/stage_2/invalid/wrong_order.c b/c/tests/stage_2/invalid/wrong_order.c new file mode 100644 index 0000000..27a9f02 --- /dev/null +++ b/c/tests/stage_2/invalid/wrong_order.c @@ -0,0 +1,3 @@ +int main() { + return 4-; +} \ No newline at end of file diff --git a/c/tests/stage_2/valid/bitwise.c b/c/tests/stage_2/valid/bitwise.c new file mode 100644 index 0000000..a0070d3 --- /dev/null +++ b/c/tests/stage_2/valid/bitwise.c @@ -0,0 +1,3 @@ +int main() { + return ~12; +} diff --git a/c/tests/stage_2/valid/bitwise_zero.c b/c/tests/stage_2/valid/bitwise_zero.c new file mode 100644 index 0000000..2c2ed2e --- /dev/null +++ b/c/tests/stage_2/valid/bitwise_zero.c @@ -0,0 +1,3 @@ +int main() { + return ~0; +} \ No newline at end of file diff --git a/c/tests/stage_2/valid/neg.c b/c/tests/stage_2/valid/neg.c new file mode 100644 index 0000000..b7ac431 --- /dev/null +++ b/c/tests/stage_2/valid/neg.c @@ -0,0 +1,3 @@ +int main() { + return -5; +} \ No newline at end of file diff --git a/c/tests/stage_2/valid/nested_ops.c b/c/tests/stage_2/valid/nested_ops.c new file mode 100644 index 0000000..9fb3f87 --- /dev/null +++ b/c/tests/stage_2/valid/nested_ops.c @@ -0,0 +1,3 @@ +int main() { + return !-3; +} \ No newline at end of file diff --git a/c/tests/stage_2/valid/nested_ops_2.c b/c/tests/stage_2/valid/nested_ops_2.c new file mode 100644 index 0000000..416d4d1 --- /dev/null +++ b/c/tests/stage_2/valid/nested_ops_2.c @@ -0,0 +1,3 @@ +int main() { + return -~0; +} \ No newline at end of file diff --git a/c/tests/stage_2/valid/not_five.c b/c/tests/stage_2/valid/not_five.c new file mode 100644 index 0000000..df792bb --- /dev/null +++ b/c/tests/stage_2/valid/not_five.c @@ -0,0 +1,3 @@ +int main() { + return !5; +} \ No newline at end of file diff --git a/c/tests/stage_2/valid/not_zero.c b/c/tests/stage_2/valid/not_zero.c new file mode 100644 index 0000000..b6b7cb5 --- /dev/null +++ b/c/tests/stage_2/valid/not_zero.c @@ -0,0 +1,3 @@ +int main() { + return !0; +} \ No newline at end of file diff --git a/c/tests/stage_3/invalid/malformed_paren.c b/c/tests/stage_3/invalid/malformed_paren.c new file mode 100644 index 0000000..3c444bc --- /dev/null +++ b/c/tests/stage_3/invalid/malformed_paren.c @@ -0,0 +1,3 @@ +int main() { + return 2 (- 3); +} \ No newline at end of file diff --git a/c/tests/stage_3/invalid/missing_first_op.c b/c/tests/stage_3/invalid/missing_first_op.c new file mode 100644 index 0000000..84a3c34 --- /dev/null +++ b/c/tests/stage_3/invalid/missing_first_op.c @@ -0,0 +1,3 @@ +int main() { + return /3; +} \ No newline at end of file diff --git a/c/tests/stage_3/invalid/missing_second_op.c b/c/tests/stage_3/invalid/missing_second_op.c new file mode 100644 index 0000000..a0a313b --- /dev/null +++ b/c/tests/stage_3/invalid/missing_second_op.c @@ -0,0 +1,3 @@ +int main() { + return 1 + ; +} \ No newline at end of file diff --git a/c/tests/stage_3/invalid/no_semicolon.c b/c/tests/stage_3/invalid/no_semicolon.c new file mode 100644 index 0000000..0704f18 --- /dev/null +++ b/c/tests/stage_3/invalid/no_semicolon.c @@ -0,0 +1,3 @@ +int main() { + return 2*2 +} \ No newline at end of file diff --git a/c/tests/stage_3/valid/add.c b/c/tests/stage_3/valid/add.c new file mode 100644 index 0000000..464d543 --- /dev/null +++ b/c/tests/stage_3/valid/add.c @@ -0,0 +1,3 @@ +int main() { + return 1 + 2; +} \ No newline at end of file diff --git a/c/tests/stage_3/valid/associativity.c b/c/tests/stage_3/valid/associativity.c new file mode 100644 index 0000000..d099bdf --- /dev/null +++ b/c/tests/stage_3/valid/associativity.c @@ -0,0 +1,3 @@ +int main() { + return 1 - 2 - 3; +} \ No newline at end of file diff --git a/c/tests/stage_3/valid/associativity_2.c b/c/tests/stage_3/valid/associativity_2.c new file mode 100644 index 0000000..511ba51 --- /dev/null +++ b/c/tests/stage_3/valid/associativity_2.c @@ -0,0 +1,3 @@ +int main() { + return 6 / 3 / 2; +} \ No newline at end of file diff --git a/c/tests/stage_3/valid/div.c b/c/tests/stage_3/valid/div.c new file mode 100644 index 0000000..ebe1577 --- /dev/null +++ b/c/tests/stage_3/valid/div.c @@ -0,0 +1,3 @@ +int main() { + return 4 / 2; +} \ No newline at end of file diff --git a/c/tests/stage_3/valid/div_neg.c b/c/tests/stage_3/valid/div_neg.c new file mode 100644 index 0000000..a8feb93 --- /dev/null +++ b/c/tests/stage_3/valid/div_neg.c @@ -0,0 +1,3 @@ +int main() { + return (-12) / 5; +} \ No newline at end of file diff --git a/c/tests/stage_3/valid/mult.c b/c/tests/stage_3/valid/mult.c new file mode 100644 index 0000000..fb22f95 --- /dev/null +++ b/c/tests/stage_3/valid/mult.c @@ -0,0 +1,3 @@ +int main() { + return 2 * 3; +} \ No newline at end of file diff --git a/c/tests/stage_3/valid/parens.c b/c/tests/stage_3/valid/parens.c new file mode 100644 index 0000000..f7d427b --- /dev/null +++ b/c/tests/stage_3/valid/parens.c @@ -0,0 +1,3 @@ +int main() { + return 2 * (3 + 4); +} \ No newline at end of file diff --git a/c/tests/stage_3/valid/precedence.c b/c/tests/stage_3/valid/precedence.c new file mode 100644 index 0000000..b6d3c3d --- /dev/null +++ b/c/tests/stage_3/valid/precedence.c @@ -0,0 +1,3 @@ +int main() { + return 2 + 3 * 4; +} \ No newline at end of file diff --git a/c/tests/stage_3/valid/sub.c b/c/tests/stage_3/valid/sub.c new file mode 100644 index 0000000..39cdcfa --- /dev/null +++ b/c/tests/stage_3/valid/sub.c @@ -0,0 +1,3 @@ +int main() { + return 1 - 2; +} \ No newline at end of file diff --git a/c/tests/stage_3/valid/sub_neg.c b/c/tests/stage_3/valid/sub_neg.c new file mode 100644 index 0000000..67b0dac --- /dev/null +++ b/c/tests/stage_3/valid/sub_neg.c @@ -0,0 +1,3 @@ +int main() { + return 2- -1; +} \ No newline at end of file diff --git a/c/tests/stage_3/valid/unop_add.c b/c/tests/stage_3/valid/unop_add.c new file mode 100644 index 0000000..3049b00 --- /dev/null +++ b/c/tests/stage_3/valid/unop_add.c @@ -0,0 +1,3 @@ +int main() { + return ~2 + 3; +} \ No newline at end of file diff --git a/c/tests/stage_3/valid/unop_parens.c b/c/tests/stage_3/valid/unop_parens.c new file mode 100644 index 0000000..d3f6e24 --- /dev/null +++ b/c/tests/stage_3/valid/unop_parens.c @@ -0,0 +1,3 @@ +int main() { + return ~(1 + 1); +} \ No newline at end of file diff --git a/c/tests/stage_4/invalid/missing_first_op.c b/c/tests/stage_4/invalid/missing_first_op.c new file mode 100644 index 0000000..5af3bb3 --- /dev/null +++ b/c/tests/stage_4/invalid/missing_first_op.c @@ -0,0 +1,3 @@ +int main() { + return <= 2; +} \ No newline at end of file diff --git a/c/tests/stage_4/invalid/missing_mid_op.c b/c/tests/stage_4/invalid/missing_mid_op.c new file mode 100644 index 0000000..4b36056 --- /dev/null +++ b/c/tests/stage_4/invalid/missing_mid_op.c @@ -0,0 +1,3 @@ +int main() { + return 1 < > 3; +} \ No newline at end of file diff --git a/c/tests/stage_4/invalid/missing_second_op.c b/c/tests/stage_4/invalid/missing_second_op.c new file mode 100644 index 0000000..8f1513a --- /dev/null +++ b/c/tests/stage_4/invalid/missing_second_op.c @@ -0,0 +1,3 @@ +int main() { + return 2 && +} \ No newline at end of file diff --git a/c/tests/stage_4/invalid/missing_semicolon.c b/c/tests/stage_4/invalid/missing_semicolon.c new file mode 100644 index 0000000..deafd68 --- /dev/null +++ b/c/tests/stage_4/invalid/missing_semicolon.c @@ -0,0 +1,3 @@ +int main() { + return 1 || 2 +} \ No newline at end of file diff --git a/c/tests/stage_4/valid/and_false.c b/c/tests/stage_4/valid/and_false.c new file mode 100644 index 0000000..f1ad90b --- /dev/null +++ b/c/tests/stage_4/valid/and_false.c @@ -0,0 +1,3 @@ +int main() { + return 1 && 0; +} \ No newline at end of file diff --git a/c/tests/stage_4/valid/and_true.c b/c/tests/stage_4/valid/and_true.c new file mode 100644 index 0000000..87d3131 --- /dev/null +++ b/c/tests/stage_4/valid/and_true.c @@ -0,0 +1,3 @@ +int main() { + return 1 && -1; +} \ No newline at end of file diff --git a/c/tests/stage_4/valid/eq_false.c b/c/tests/stage_4/valid/eq_false.c new file mode 100644 index 0000000..39895e9 --- /dev/null +++ b/c/tests/stage_4/valid/eq_false.c @@ -0,0 +1,3 @@ +int main() { + return 1 == 2; +} \ No newline at end of file diff --git a/c/tests/stage_4/valid/eq_true.c b/c/tests/stage_4/valid/eq_true.c new file mode 100644 index 0000000..1a6f8eb --- /dev/null +++ b/c/tests/stage_4/valid/eq_true.c @@ -0,0 +1,3 @@ +int main() { + return 1 == 1; +} \ No newline at end of file diff --git a/c/tests/stage_4/valid/ge_false.c b/c/tests/stage_4/valid/ge_false.c new file mode 100644 index 0000000..abeaf9a --- /dev/null +++ b/c/tests/stage_4/valid/ge_false.c @@ -0,0 +1,3 @@ +int main() { + return 1 >= 2; +} \ No newline at end of file diff --git a/c/tests/stage_4/valid/ge_true.c b/c/tests/stage_4/valid/ge_true.c new file mode 100644 index 0000000..e3729d0 --- /dev/null +++ b/c/tests/stage_4/valid/ge_true.c @@ -0,0 +1,3 @@ +int main() { + return 1 >= 1; +} \ No newline at end of file diff --git a/c/tests/stage_4/valid/gt_false.c b/c/tests/stage_4/valid/gt_false.c new file mode 100644 index 0000000..3bf766b --- /dev/null +++ b/c/tests/stage_4/valid/gt_false.c @@ -0,0 +1,3 @@ +int main() { + return 1 > 2; +} \ No newline at end of file diff --git a/c/tests/stage_4/valid/gt_true.c b/c/tests/stage_4/valid/gt_true.c new file mode 100644 index 0000000..ad051a4 --- /dev/null +++ b/c/tests/stage_4/valid/gt_true.c @@ -0,0 +1,3 @@ +int main() { + return 1 > 0; +} \ No newline at end of file diff --git a/c/tests/stage_4/valid/le_false.c b/c/tests/stage_4/valid/le_false.c new file mode 100644 index 0000000..e29deeb --- /dev/null +++ b/c/tests/stage_4/valid/le_false.c @@ -0,0 +1,3 @@ +int main() { + return 1 <= -1; +} \ No newline at end of file diff --git a/c/tests/stage_4/valid/le_true.c b/c/tests/stage_4/valid/le_true.c new file mode 100644 index 0000000..d45dbeb --- /dev/null +++ b/c/tests/stage_4/valid/le_true.c @@ -0,0 +1,3 @@ +int main() { + return 0 <= 2; +} \ No newline at end of file diff --git a/c/tests/stage_4/valid/lt_false.c b/c/tests/stage_4/valid/lt_false.c new file mode 100644 index 0000000..5e33fae --- /dev/null +++ b/c/tests/stage_4/valid/lt_false.c @@ -0,0 +1,3 @@ +int main() { + return 2 < 1; +} \ No newline at end of file diff --git a/c/tests/stage_4/valid/lt_true.c b/c/tests/stage_4/valid/lt_true.c new file mode 100644 index 0000000..a82436b --- /dev/null +++ b/c/tests/stage_4/valid/lt_true.c @@ -0,0 +1,3 @@ +int main() { + return 1 < 2; +} \ No newline at end of file diff --git a/c/tests/stage_4/valid/ne_false.c b/c/tests/stage_4/valid/ne_false.c new file mode 100644 index 0000000..b13c3a8 --- /dev/null +++ b/c/tests/stage_4/valid/ne_false.c @@ -0,0 +1,3 @@ +int main() { + return 0 != 0; +} \ No newline at end of file diff --git a/c/tests/stage_4/valid/ne_true.c b/c/tests/stage_4/valid/ne_true.c new file mode 100644 index 0000000..de775a4 --- /dev/null +++ b/c/tests/stage_4/valid/ne_true.c @@ -0,0 +1,3 @@ +int main() { + return -1 != -2; +} \ No newline at end of file diff --git a/c/tests/stage_4/valid/or_false.c b/c/tests/stage_4/valid/or_false.c new file mode 100644 index 0000000..693c1f5 --- /dev/null +++ b/c/tests/stage_4/valid/or_false.c @@ -0,0 +1,3 @@ +int main() { + return 0 || 0; +} \ No newline at end of file diff --git a/c/tests/stage_4/valid/or_true.c b/c/tests/stage_4/valid/or_true.c new file mode 100644 index 0000000..fb40e98 --- /dev/null +++ b/c/tests/stage_4/valid/or_true.c @@ -0,0 +1,3 @@ +int main() { + return 1 || 0; +} \ No newline at end of file diff --git a/c/tests/stage_4/valid/precedence.c b/c/tests/stage_4/valid/precedence.c new file mode 100644 index 0000000..711bde1 --- /dev/null +++ b/c/tests/stage_4/valid/precedence.c @@ -0,0 +1,3 @@ +int main() { + return 1 || 0 && 2; +} \ No newline at end of file diff --git a/c/tests/stage_4/valid/precedence_2.c b/c/tests/stage_4/valid/precedence_2.c new file mode 100644 index 0000000..7d3fc81 --- /dev/null +++ b/c/tests/stage_4/valid/precedence_2.c @@ -0,0 +1,3 @@ +int main() { + return (1 || 0) && 0; +} \ No newline at end of file diff --git a/c/tests/stage_4/valid/precedence_3.c b/c/tests/stage_4/valid/precedence_3.c new file mode 100644 index 0000000..8bf357a --- /dev/null +++ b/c/tests/stage_4/valid/precedence_3.c @@ -0,0 +1,3 @@ +int main() { + return 2 == 2 > 0; +} \ No newline at end of file diff --git a/c/tests/stage_4/valid/precedence_4.c b/c/tests/stage_4/valid/precedence_4.c new file mode 100644 index 0000000..87d4a39 --- /dev/null +++ b/c/tests/stage_4/valid/precedence_4.c @@ -0,0 +1,3 @@ +int main() { + return 2 == 2 || 0; +} \ No newline at end of file diff --git a/c/tests/stage_4/valid/skip_on_failure_multi_short_circuit.c b/c/tests/stage_4/valid/skip_on_failure_multi_short_circuit.c new file mode 100644 index 0000000..8d6912f --- /dev/null +++ b/c/tests/stage_4/valid/skip_on_failure_multi_short_circuit.c @@ -0,0 +1,5 @@ +int main() { + int a = 0; + a || (a = 3) || (a = 4); + return a; +} \ No newline at end of file diff --git a/c/tests/stage_4/valid/skip_on_failure_short_circuit_and.c b/c/tests/stage_4/valid/skip_on_failure_short_circuit_and.c new file mode 100644 index 0000000..a48b05c --- /dev/null +++ b/c/tests/stage_4/valid/skip_on_failure_short_circuit_and.c @@ -0,0 +1,6 @@ +int main() { + int a = 0; + int b = 0; + a && (b = 5); + return b; +} \ No newline at end of file diff --git a/c/tests/stage_4/valid/skip_on_failure_short_circuit_or.c b/c/tests/stage_4/valid/skip_on_failure_short_circuit_or.c new file mode 100644 index 0000000..934f771 --- /dev/null +++ b/c/tests/stage_4/valid/skip_on_failure_short_circuit_or.c @@ -0,0 +1,6 @@ +int main() { + int a = 1; + int b = 0; + a || (b = 5); + return b; +} \ No newline at end of file diff --git a/c/tests/stage_5/invalid/redefine.c b/c/tests/stage_5/invalid/redefine.c new file mode 100644 index 0000000..3b2f9c4 --- /dev/null +++ b/c/tests/stage_5/invalid/redefine.c @@ -0,0 +1,5 @@ +int main() { + int a = 1; + int a = 2; + return a; +} \ No newline at end of file diff --git a/c/tests/stage_5/invalid/syntax_err_bad_decl.c b/c/tests/stage_5/invalid/syntax_err_bad_decl.c new file mode 100644 index 0000000..1ed774d --- /dev/null +++ b/c/tests/stage_5/invalid/syntax_err_bad_decl.c @@ -0,0 +1,4 @@ +int main() { + ints a = 1; + return a; +} \ No newline at end of file diff --git a/c/tests/stage_5/invalid/syntax_err_bad_decl_2.c b/c/tests/stage_5/invalid/syntax_err_bad_decl_2.c new file mode 100644 index 0000000..5d6b4d0 --- /dev/null +++ b/c/tests/stage_5/invalid/syntax_err_bad_decl_2.c @@ -0,0 +1,4 @@ +int main() { + int foo bar = 3; + return bar; +} \ No newline at end of file diff --git a/c/tests/stage_5/invalid/syntax_err_bad_lvalue.c b/c/tests/stage_5/invalid/syntax_err_bad_lvalue.c new file mode 100644 index 0000000..7f8a5f8 --- /dev/null +++ b/c/tests/stage_5/invalid/syntax_err_bad_lvalue.c @@ -0,0 +1,5 @@ +int main() { + int a = 2; + a + 3 = 4; + return a; +} \ No newline at end of file diff --git a/c/tests/stage_5/invalid/syntax_err_bad_lvalue_2.c b/c/tests/stage_5/invalid/syntax_err_bad_lvalue_2.c new file mode 100644 index 0000000..2954621 --- /dev/null +++ b/c/tests/stage_5/invalid/syntax_err_bad_lvalue_2.c @@ -0,0 +1,5 @@ +int main() { + int a = 2; + !a = 3; + return a; +} \ No newline at end of file diff --git a/c/tests/stage_5/invalid/syntax_err_no_semicolon.c b/c/tests/stage_5/invalid/syntax_err_no_semicolon.c new file mode 100644 index 0000000..29f6738 --- /dev/null +++ b/c/tests/stage_5/invalid/syntax_err_no_semicolon.c @@ -0,0 +1,5 @@ +int main() { + int a = 2 + a = a + 4; + return a; +} \ No newline at end of file diff --git a/c/tests/stage_5/invalid/undeclared_var.c b/c/tests/stage_5/invalid/undeclared_var.c new file mode 100644 index 0000000..a49ad45 --- /dev/null +++ b/c/tests/stage_5/invalid/undeclared_var.c @@ -0,0 +1,3 @@ +int main() { + return a; +} \ No newline at end of file diff --git a/c/tests/stage_5/invalid/var_declared_late.c b/c/tests/stage_5/invalid/var_declared_late.c new file mode 100644 index 0000000..a283aab --- /dev/null +++ b/c/tests/stage_5/invalid/var_declared_late.c @@ -0,0 +1,5 @@ +int main() { + a = 1 + 2; + int a; + return a; +} \ No newline at end of file diff --git a/c/tests/stage_5/valid/assign.c b/c/tests/stage_5/valid/assign.c new file mode 100644 index 0000000..10f91a0 --- /dev/null +++ b/c/tests/stage_5/valid/assign.c @@ -0,0 +1,5 @@ +int main() { + int a; + a = 2; + return a; +} \ No newline at end of file diff --git a/c/tests/stage_5/valid/assign_val.c b/c/tests/stage_5/valid/assign_val.c new file mode 100644 index 0000000..3a8d163 --- /dev/null +++ b/c/tests/stage_5/valid/assign_val.c @@ -0,0 +1,5 @@ +int main() { + int a; + int b = a = 0; + return b; +} \ No newline at end of file diff --git a/c/tests/stage_5/valid/exp_return_val.c b/c/tests/stage_5/valid/exp_return_val.c new file mode 100644 index 0000000..76c2f6c --- /dev/null +++ b/c/tests/stage_5/valid/exp_return_val.c @@ -0,0 +1,6 @@ +int main() { + int a; + int b; + a = b = 4; + return a - b; +} \ No newline at end of file diff --git a/c/tests/stage_5/valid/initialize.c b/c/tests/stage_5/valid/initialize.c new file mode 100644 index 0000000..6f0f5dd --- /dev/null +++ b/c/tests/stage_5/valid/initialize.c @@ -0,0 +1,4 @@ +int main() { + int a = 2; + return 0; +} \ No newline at end of file diff --git a/c/tests/stage_5/valid/missing_return.c b/c/tests/stage_5/valid/missing_return.c new file mode 100644 index 0000000..704dacc --- /dev/null +++ b/c/tests/stage_5/valid/missing_return.c @@ -0,0 +1,3 @@ +int main() { + +} \ No newline at end of file diff --git a/c/tests/stage_5/valid/multiple_vars.c b/c/tests/stage_5/valid/multiple_vars.c new file mode 100644 index 0000000..0d4caef --- /dev/null +++ b/c/tests/stage_5/valid/multiple_vars.c @@ -0,0 +1,5 @@ +int main() { + int a = 1; + int b = 2; + return a + b; +} \ No newline at end of file diff --git a/c/tests/stage_5/valid/no_initialize.c b/c/tests/stage_5/valid/no_initialize.c new file mode 100644 index 0000000..b6543fb --- /dev/null +++ b/c/tests/stage_5/valid/no_initialize.c @@ -0,0 +1,4 @@ +int main() { + int a; + return 0; +} \ No newline at end of file diff --git a/c/tests/stage_5/valid/refer.c b/c/tests/stage_5/valid/refer.c new file mode 100644 index 0000000..89e9b3f --- /dev/null +++ b/c/tests/stage_5/valid/refer.c @@ -0,0 +1,4 @@ +int main() { + int a = 2; + return a; +} \ No newline at end of file diff --git a/c/tests/stage_5/valid/unused_exp.c b/c/tests/stage_5/valid/unused_exp.c new file mode 100644 index 0000000..82e2181 --- /dev/null +++ b/c/tests/stage_5/valid/unused_exp.c @@ -0,0 +1,4 @@ +int main() { + 2 + 2; + return 0; +} \ No newline at end of file diff --git a/c/tests/stage_6/invalid/expression/incomplete_ternary.c b/c/tests/stage_6/invalid/expression/incomplete_ternary.c new file mode 100644 index 0000000..d0e69e9 --- /dev/null +++ b/c/tests/stage_6/invalid/expression/incomplete_ternary.c @@ -0,0 +1,3 @@ +int main() { + return 1 ? 2; +} \ No newline at end of file diff --git a/c/tests/stage_6/invalid/expression/malformed_ternary.c b/c/tests/stage_6/invalid/expression/malformed_ternary.c new file mode 100644 index 0000000..020d41a --- /dev/null +++ b/c/tests/stage_6/invalid/expression/malformed_ternary.c @@ -0,0 +1,3 @@ +int main() { + return 1 ? 2 : 3 : 4; +} \ No newline at end of file diff --git a/c/tests/stage_6/invalid/expression/malformed_ternary_2.c b/c/tests/stage_6/invalid/expression/malformed_ternary_2.c new file mode 100644 index 0000000..e902288 --- /dev/null +++ b/c/tests/stage_6/invalid/expression/malformed_ternary_2.c @@ -0,0 +1,3 @@ +int main() { + return 1 ? 2 ? 3 : 4; +} \ No newline at end of file diff --git a/c/tests/stage_6/invalid/expression/ternary_assign.c b/c/tests/stage_6/invalid/expression/ternary_assign.c new file mode 100644 index 0000000..b2ff76b --- /dev/null +++ b/c/tests/stage_6/invalid/expression/ternary_assign.c @@ -0,0 +1,6 @@ +int main() { + int a = 2; + int b = 1; + a > b ? a = 1 : a = 0; + return a; +} \ No newline at end of file diff --git a/c/tests/stage_6/invalid/statement/declare_statement.c b/c/tests/stage_6/invalid/statement/declare_statement.c new file mode 100644 index 0000000..dca9d0c --- /dev/null +++ b/c/tests/stage_6/invalid/statement/declare_statement.c @@ -0,0 +1,4 @@ +int main() { + if (5) + int i = 0; +} \ No newline at end of file diff --git a/c/tests/stage_6/invalid/statement/if_assignment.c b/c/tests/stage_6/invalid/statement/if_assignment.c new file mode 100644 index 0000000..ad3036d --- /dev/null +++ b/c/tests/stage_6/invalid/statement/if_assignment.c @@ -0,0 +1,8 @@ +int main() { + int flag = 0; + int a = if (flag) + 2; + else + 3; + return a; +} \ No newline at end of file diff --git a/c/tests/stage_6/invalid/statement/mismatched_nesting.c b/c/tests/stage_6/invalid/statement/mismatched_nesting.c new file mode 100644 index 0000000..a3322bc --- /dev/null +++ b/c/tests/stage_6/invalid/statement/mismatched_nesting.c @@ -0,0 +1,9 @@ +int main() { + int a = 0; + if (1) + return 1; + else + return 2; + else + return 3; +} \ No newline at end of file diff --git a/c/tests/stage_6/valid/expression/assign_ternary.c b/c/tests/stage_6/valid/expression/assign_ternary.c new file mode 100644 index 0000000..519ce72 --- /dev/null +++ b/c/tests/stage_6/valid/expression/assign_ternary.c @@ -0,0 +1,5 @@ +int main() { + int a = 0; + a = 1 ? 2 : 3; + return a; +} \ No newline at end of file diff --git a/c/tests/stage_6/valid/expression/multiple_ternary.c b/c/tests/stage_6/valid/expression/multiple_ternary.c new file mode 100644 index 0000000..d2e7cc2 --- /dev/null +++ b/c/tests/stage_6/valid/expression/multiple_ternary.c @@ -0,0 +1,5 @@ +int main() { + int a = 1 > 2 ? 3 : 4; + int b = 1 > 2 ? 5 : 6; + return a + b; +} \ No newline at end of file diff --git a/c/tests/stage_6/valid/expression/nested_ternary.c b/c/tests/stage_6/valid/expression/nested_ternary.c new file mode 100644 index 0000000..b18a4d1 --- /dev/null +++ b/c/tests/stage_6/valid/expression/nested_ternary.c @@ -0,0 +1,7 @@ +int main() { + int a = 1; + int b = 2; + int flag = 0; + + return a > b ? 5 : flag ? 6 : 7; +} \ No newline at end of file diff --git a/c/tests/stage_6/valid/expression/nested_ternary_2.c b/c/tests/stage_6/valid/expression/nested_ternary_2.c new file mode 100644 index 0000000..8da4bd7 --- /dev/null +++ b/c/tests/stage_6/valid/expression/nested_ternary_2.c @@ -0,0 +1,5 @@ +int main() { + int a = 1 ? 2 ? 3 : 4 : 5; + int b = 0 ? 2 ? 3 : 4 : 5; + return a * b; +} \ No newline at end of file diff --git a/c/tests/stage_6/valid/expression/rh_assignment.c b/c/tests/stage_6/valid/expression/rh_assignment.c new file mode 100644 index 0000000..d08f6b6 --- /dev/null +++ b/c/tests/stage_6/valid/expression/rh_assignment.c @@ -0,0 +1,6 @@ +int main() { + int flag = 1; + int a = 0; + flag ? a = 1 : (a = 0); + return a; +} \ No newline at end of file diff --git a/c/tests/stage_6/valid/expression/ternary.c b/c/tests/stage_6/valid/expression/ternary.c new file mode 100644 index 0000000..4013c4f --- /dev/null +++ b/c/tests/stage_6/valid/expression/ternary.c @@ -0,0 +1,4 @@ +int main() { + int a = 0; + return a > -1 ? 4 : 5; +} \ No newline at end of file diff --git a/c/tests/stage_6/valid/expression/ternary_short_circuit.c b/c/tests/stage_6/valid/expression/ternary_short_circuit.c new file mode 100644 index 0000000..70203ef --- /dev/null +++ b/c/tests/stage_6/valid/expression/ternary_short_circuit.c @@ -0,0 +1,6 @@ +int main() { + int a = 1; + int b = 0; + a ? (b = 1) : (b = 2); + return b; +} \ No newline at end of file diff --git a/c/tests/stage_6/valid/expression/ternary_short_circuit_2.c b/c/tests/stage_6/valid/expression/ternary_short_circuit_2.c new file mode 100644 index 0000000..78d225e --- /dev/null +++ b/c/tests/stage_6/valid/expression/ternary_short_circuit_2.c @@ -0,0 +1,6 @@ +int main() { + int a = 0; + int b = 0; + a ? (b = 1) : (b = 2); + return b; +} \ No newline at end of file diff --git a/c/tests/stage_6/valid/statement/else.c b/c/tests/stage_6/valid/statement/else.c new file mode 100644 index 0000000..1314bbe --- /dev/null +++ b/c/tests/stage_6/valid/statement/else.c @@ -0,0 +1,7 @@ +int main() { + int a = 0; + if (a) + return 1; + else + return 2; +} \ No newline at end of file diff --git a/c/tests/stage_6/valid/statement/if_nested.c b/c/tests/stage_6/valid/statement/if_nested.c new file mode 100644 index 0000000..9b0afa8 --- /dev/null +++ b/c/tests/stage_6/valid/statement/if_nested.c @@ -0,0 +1,9 @@ +int main() { + int a = 1; + int b = 0; + if (a) + b = 1; + else if (b) + b = 2; + return b; +} \ No newline at end of file diff --git a/c/tests/stage_6/valid/statement/if_nested_2.c b/c/tests/stage_6/valid/statement/if_nested_2.c new file mode 100644 index 0000000..2826706 --- /dev/null +++ b/c/tests/stage_6/valid/statement/if_nested_2.c @@ -0,0 +1,9 @@ +int main() { + int a = 0; + int b = 1; + if (a) + b = 1; + else if (b) + b = 2; + return b; +} \ No newline at end of file diff --git a/c/tests/stage_6/valid/statement/if_nested_3.c b/c/tests/stage_6/valid/statement/if_nested_3.c new file mode 100644 index 0000000..e387f00 --- /dev/null +++ b/c/tests/stage_6/valid/statement/if_nested_3.c @@ -0,0 +1,10 @@ +int main() { + int a = 0; + if (1) + if (2) + a = 3; + else + a = 4; + + return a; +} \ No newline at end of file diff --git a/c/tests/stage_6/valid/statement/if_nested_4.c b/c/tests/stage_6/valid/statement/if_nested_4.c new file mode 100644 index 0000000..e2a321c --- /dev/null +++ b/c/tests/stage_6/valid/statement/if_nested_4.c @@ -0,0 +1,10 @@ +int main() { + int a = 0; + if (1) + if (0) + a = 3; + else + a = 4; + + return a; +} \ No newline at end of file diff --git a/c/tests/stage_6/valid/statement/if_nested_5.c b/c/tests/stage_6/valid/statement/if_nested_5.c new file mode 100644 index 0000000..a83f7c8 --- /dev/null +++ b/c/tests/stage_6/valid/statement/if_nested_5.c @@ -0,0 +1,12 @@ +int main() { + int a = 0; + if (0) + if (0) + a = 3; + else + a = 4; + else + a = 1; + + return a; +} \ No newline at end of file diff --git a/c/tests/stage_6/valid/statement/if_not_taken.c b/c/tests/stage_6/valid/statement/if_not_taken.c new file mode 100644 index 0000000..41b22c0 --- /dev/null +++ b/c/tests/stage_6/valid/statement/if_not_taken.c @@ -0,0 +1,7 @@ +int main() { + int a = 0; + int b = 0; + if (a) + b = 1; + return b; +} \ No newline at end of file diff --git a/c/tests/stage_6/valid/statement/if_taken.c b/c/tests/stage_6/valid/statement/if_taken.c new file mode 100644 index 0000000..d136154 --- /dev/null +++ b/c/tests/stage_6/valid/statement/if_taken.c @@ -0,0 +1,7 @@ +int main() { + int a = 1; + int b = 0; + if (a) + b = 1; + return b; +} \ No newline at end of file diff --git a/c/tests/stage_6/valid/statement/multiple_if.c b/c/tests/stage_6/valid/statement/multiple_if.c new file mode 100644 index 0000000..b651130 --- /dev/null +++ b/c/tests/stage_6/valid/statement/multiple_if.c @@ -0,0 +1,16 @@ +int main() { + int a = 0; + int b = 0; + + if (a) + a = 2; + else + a = 3; + + if (b) + b = 4; + else + b = 5; + + return a + b; +} \ No newline at end of file diff --git a/c/tests/stage_7/invalid/double_define.c b/c/tests/stage_7/invalid/double_define.c new file mode 100644 index 0000000..ae3ed74 --- /dev/null +++ b/c/tests/stage_7/invalid/double_define.c @@ -0,0 +1,6 @@ +int main() { + { + int a; + int a; + } +} \ No newline at end of file diff --git a/c/tests/stage_7/invalid/out_of_scope.c b/c/tests/stage_7/invalid/out_of_scope.c new file mode 100644 index 0000000..7a12aba --- /dev/null +++ b/c/tests/stage_7/invalid/out_of_scope.c @@ -0,0 +1,6 @@ +int main() { + { + int a = 2; + } + return a; +} \ No newline at end of file diff --git a/c/tests/stage_7/invalid/syntax_err_extra_brace.c b/c/tests/stage_7/invalid/syntax_err_extra_brace.c new file mode 100644 index 0000000..782c2d6 --- /dev/null +++ b/c/tests/stage_7/invalid/syntax_err_extra_brace.c @@ -0,0 +1,6 @@ +int main() { + if(0){ + return 1; + }} + return 2; +} \ No newline at end of file diff --git a/c/tests/stage_7/invalid/syntax_err_missing_brace.c b/c/tests/stage_7/invalid/syntax_err_missing_brace.c new file mode 100644 index 0000000..0b1cfc6 --- /dev/null +++ b/c/tests/stage_7/invalid/syntax_err_missing_brace.c @@ -0,0 +1,5 @@ +int main() { + if(0){ + return 1; + return 2; +} \ No newline at end of file diff --git a/c/tests/stage_7/valid/consecutive_blocks.c b/c/tests/stage_7/valid/consecutive_blocks.c new file mode 100644 index 0000000..1839fb5 --- /dev/null +++ b/c/tests/stage_7/valid/consecutive_blocks.c @@ -0,0 +1,9 @@ +int main() { + int a = 1; + { + int a = 2; + } + { + return a; + } +} \ No newline at end of file diff --git a/c/tests/stage_7/valid/consecutive_declarations.c b/c/tests/stage_7/valid/consecutive_declarations.c new file mode 100644 index 0000000..34fad83 --- /dev/null +++ b/c/tests/stage_7/valid/consecutive_declarations.c @@ -0,0 +1,12 @@ +int main() { + int a = 0; + { + int b = 1; + a = b; + } + { + int b = 2; + a = a + b; + } + return a; +} \ No newline at end of file diff --git a/c/tests/stage_7/valid/declare_after_block.c b/c/tests/stage_7/valid/declare_after_block.c new file mode 100644 index 0000000..25ad580 --- /dev/null +++ b/c/tests/stage_7/valid/declare_after_block.c @@ -0,0 +1,8 @@ +int main() { + int i = 0; + { + int a = 2; + } + int b = 3; + return b; +} \ No newline at end of file diff --git a/c/tests/stage_7/valid/declare_block.c b/c/tests/stage_7/valid/declare_block.c new file mode 100644 index 0000000..3c4469c --- /dev/null +++ b/c/tests/stage_7/valid/declare_block.c @@ -0,0 +1,6 @@ +int main() { + if (5) { + int i = 0; + return i; + } +} \ No newline at end of file diff --git a/c/tests/stage_7/valid/declare_late.c b/c/tests/stage_7/valid/declare_late.c new file mode 100644 index 0000000..948977d --- /dev/null +++ b/c/tests/stage_7/valid/declare_late.c @@ -0,0 +1,8 @@ +int main() { + int a = 2; + { + a = 3; + int a = 0; + } + return a; +} \ No newline at end of file diff --git a/c/tests/stage_7/valid/multi_nesting.c b/c/tests/stage_7/valid/multi_nesting.c new file mode 100644 index 0000000..3e4acd6 --- /dev/null +++ b/c/tests/stage_7/valid/multi_nesting.c @@ -0,0 +1,10 @@ +int main(){ + int a = 2; + if (a < 3) { + { + int a = 3; + return a; + } + return a; + } +} \ No newline at end of file diff --git a/c/tests/stage_7/valid/nested_if.c b/c/tests/stage_7/valid/nested_if.c new file mode 100644 index 0000000..f20a7bf --- /dev/null +++ b/c/tests/stage_7/valid/nested_if.c @@ -0,0 +1,15 @@ +int main() { + int a = 0; + if (a) { + int b = 2; + return b; + } else { + int c = 3; + if (a < c) { + return 4; + } else { + return 5; + } + } + return a; +} \ No newline at end of file diff --git a/c/tests/stage_7/valid/nested_scope.c b/c/tests/stage_7/valid/nested_scope.c new file mode 100644 index 0000000..a7268f4 --- /dev/null +++ b/c/tests/stage_7/valid/nested_scope.c @@ -0,0 +1,9 @@ +int main() { + int a = 2; + int b = 3; + { + int a = 1; + b = b + a; + } + return b; +} \ No newline at end of file diff --git a/c/tests/stage_8/invalid/break_not_in_loop.c b/c/tests/stage_8/invalid/break_not_in_loop.c new file mode 100644 index 0000000..f2b16d6 --- /dev/null +++ b/c/tests/stage_8/invalid/break_not_in_loop.c @@ -0,0 +1,3 @@ +int main() { + break; +} \ No newline at end of file diff --git a/c/tests/stage_8/invalid/continue_not_in_loop.c b/c/tests/stage_8/invalid/continue_not_in_loop.c new file mode 100644 index 0000000..4f268a6 --- /dev/null +++ b/c/tests/stage_8/invalid/continue_not_in_loop.c @@ -0,0 +1,3 @@ +int main() { + continue; +} \ No newline at end of file diff --git a/c/tests/stage_8/invalid/out_of_scope.c b/c/tests/stage_8/invalid/out_of_scope.c new file mode 100644 index 0000000..1246d92 --- /dev/null +++ b/c/tests/stage_8/invalid/out_of_scope.c @@ -0,0 +1,8 @@ +int main() { + + while (1) { + int a = 2; + } + + return a; +} \ No newline at end of file diff --git a/c/tests/stage_8/invalid/out_of_scope_do_while.c b/c/tests/stage_8/invalid/out_of_scope_do_while.c new file mode 100644 index 0000000..7a2815c --- /dev/null +++ b/c/tests/stage_8/invalid/out_of_scope_do_while.c @@ -0,0 +1,6 @@ +int main() { + do { + int a = 2; + } while (a); + return 0; +} \ No newline at end of file diff --git a/c/tests/stage_8/invalid/syntax_err_do_no_semicolon.c b/c/tests/stage_8/invalid/syntax_err_do_no_semicolon.c new file mode 100644 index 0000000..a6552fe --- /dev/null +++ b/c/tests/stage_8/invalid/syntax_err_do_no_semicolon.c @@ -0,0 +1,5 @@ +int main() { + do + 3; + while (4) +} \ No newline at end of file diff --git a/c/tests/stage_8/invalid/syntax_err_empty_clause.c b/c/tests/stage_8/invalid/syntax_err_empty_clause.c new file mode 100644 index 0000000..43ad620 --- /dev/null +++ b/c/tests/stage_8/invalid/syntax_err_empty_clause.c @@ -0,0 +1,4 @@ +int main() { + for (int i = 2; )) + int a = 0; +} \ No newline at end of file diff --git a/c/tests/stage_8/invalid/syntax_err_paren_mismatch.c b/c/tests/stage_8/invalid/syntax_err_paren_mismatch.c new file mode 100644 index 0000000..43ad620 --- /dev/null +++ b/c/tests/stage_8/invalid/syntax_err_paren_mismatch.c @@ -0,0 +1,4 @@ +int main() { + for (int i = 2; )) + int a = 0; +} \ No newline at end of file diff --git a/c/tests/stage_8/invalid/syntax_err_statement_in_condition.c b/c/tests/stage_8/invalid/syntax_err_statement_in_condition.c new file mode 100644 index 0000000..12457b4 --- /dev/null +++ b/c/tests/stage_8/invalid/syntax_err_statement_in_condition.c @@ -0,0 +1,5 @@ +int main() { + while(int a) { + 2; + } +} \ No newline at end of file diff --git a/c/tests/stage_8/invalid/syntax_err_too_few_for_clauses.c b/c/tests/stage_8/invalid/syntax_err_too_few_for_clauses.c new file mode 100644 index 0000000..9e4205d --- /dev/null +++ b/c/tests/stage_8/invalid/syntax_err_too_few_for_clauses.c @@ -0,0 +1,5 @@ +int main() { + for (int i = 2; i < 3) + 3; + return 0; +} \ No newline at end of file diff --git a/c/tests/stage_8/invalid/syntax_err_too_many_for_clauses.c b/c/tests/stage_8/invalid/syntax_err_too_many_for_clauses.c new file mode 100644 index 0000000..fdb2f1c --- /dev/null +++ b/c/tests/stage_8/invalid/syntax_err_too_many_for_clauses.c @@ -0,0 +1,5 @@ +int main() { + for (;;;) + 3; + return 0; +} \ No newline at end of file diff --git a/c/tests/stage_8/valid/break.c b/c/tests/stage_8/valid/break.c new file mode 100644 index 0000000..bd3d237 --- /dev/null +++ b/c/tests/stage_8/valid/break.c @@ -0,0 +1,9 @@ +int main() { + int sum = 0; + for (int i = 0; i < 10; i = i + 1) { + sum = sum + i; + if (sum > 10) + break; + } + return sum; +} \ No newline at end of file diff --git a/c/tests/stage_8/valid/continue.c b/c/tests/stage_8/valid/continue.c new file mode 100644 index 0000000..3e70d3f --- /dev/null +++ b/c/tests/stage_8/valid/continue.c @@ -0,0 +1,9 @@ +int main() { + int sum = 0; + for (int i = 0; i < 10; i = i + 1) { + if ((sum / 2) * 2 != sum) + continue; + sum = sum + i; + } + return sum; +} \ No newline at end of file diff --git a/c/tests/stage_8/valid/continue_empty_post.c b/c/tests/stage_8/valid/continue_empty_post.c new file mode 100644 index 0000000..9e2674f --- /dev/null +++ b/c/tests/stage_8/valid/continue_empty_post.c @@ -0,0 +1,10 @@ +int main() { + int sum = 0; + for (int i = 0; i < 10;) { + i = i + 1; + if (i % 2) + continue; + sum = sum + i; + } + return sum; +} \ No newline at end of file diff --git a/c/tests/stage_8/valid/do_while.c b/c/tests/stage_8/valid/do_while.c new file mode 100644 index 0000000..d6b038a --- /dev/null +++ b/c/tests/stage_8/valid/do_while.c @@ -0,0 +1,8 @@ +int main() { + int a = 1; + do { + a = a * 2; + } while(a < 11); + + return a; +} \ No newline at end of file diff --git a/c/tests/stage_8/valid/empty_expression.c b/c/tests/stage_8/valid/empty_expression.c new file mode 100644 index 0000000..da04c1a --- /dev/null +++ b/c/tests/stage_8/valid/empty_expression.c @@ -0,0 +1,7 @@ +int main() { + int i = 3; + ; + for (int i = 0; i < 10; i = i + 1) + ; + return i; +} \ No newline at end of file diff --git a/c/tests/stage_8/valid/for.c b/c/tests/stage_8/valid/for.c new file mode 100644 index 0000000..02f4453 --- /dev/null +++ b/c/tests/stage_8/valid/for.c @@ -0,0 +1,7 @@ +int main() { + int a = 0; + + for (a = 0; a < 3; a = a + 1) + a = a * 2; + return a; +} \ No newline at end of file diff --git a/c/tests/stage_8/valid/for_decl.c b/c/tests/stage_8/valid/for_decl.c new file mode 100644 index 0000000..9505855 --- /dev/null +++ b/c/tests/stage_8/valid/for_decl.c @@ -0,0 +1,7 @@ +int main() { + int a = 0; + + for (int i = 0; i < 3; i = i + 1) + a = a + 1; + return a; +} \ No newline at end of file diff --git a/c/tests/stage_8/valid/for_empty.c b/c/tests/stage_8/valid/for_empty.c new file mode 100644 index 0000000..b55ae31 --- /dev/null +++ b/c/tests/stage_8/valid/for_empty.c @@ -0,0 +1,10 @@ +int main() { + int a = 0; + for (; ; ) { + a = a + 1; + if (a > 3) + break; + } + + return a; +} \ No newline at end of file diff --git a/c/tests/stage_8/valid/for_nested_scope.c b/c/tests/stage_8/valid/for_nested_scope.c new file mode 100644 index 0000000..2b961da --- /dev/null +++ b/c/tests/stage_8/valid/for_nested_scope.c @@ -0,0 +1,14 @@ +int main() { + int i = 0; + int j = 0; + + for (int i = 100; i > 0; i = i - 1) { + int i = 0; + int k = j; + int j = k * 2 + i; + } + + int k = 3; + + return j + k; +} \ No newline at end of file diff --git a/c/tests/stage_8/valid/for_variable_shadow.c b/c/tests/stage_8/valid/for_variable_shadow.c new file mode 100644 index 0000000..89adf1d --- /dev/null +++ b/c/tests/stage_8/valid/for_variable_shadow.c @@ -0,0 +1,10 @@ +int main() { + int i = 0; + int j = 0; + for (i = 0; i < 10; i = i + 1) { + int k = i; + for (int i = k; i < 10; i = i + 1) + j = j + 1; + } + return j + i; +} \ No newline at end of file diff --git a/c/tests/stage_8/valid/nested_break.c b/c/tests/stage_8/valid/nested_break.c new file mode 100644 index 0000000..da6704c --- /dev/null +++ b/c/tests/stage_8/valid/nested_break.c @@ -0,0 +1,10 @@ +int main() { + int ans = 0; + for (int i = 0; i < 10; i = i + 1) + for (int j = 0; j < 10; j = j + 1) + if ((i / 2)*2 == i) + break; + else + ans = ans + i; + return ans; +} \ No newline at end of file diff --git a/c/tests/stage_8/valid/nested_while.c b/c/tests/stage_8/valid/nested_while.c new file mode 100644 index 0000000..0ec1105 --- /dev/null +++ b/c/tests/stage_8/valid/nested_while.c @@ -0,0 +1,12 @@ +int main() { + int a = 1; + + while (a / 3 < 20) { + int b = 1; + while (b < 10) + b = b*2; + a = a + b; + } + + return a; +} \ No newline at end of file diff --git a/c/tests/stage_8/valid/return_in_while.c b/c/tests/stage_8/valid/return_in_while.c new file mode 100644 index 0000000..6ead13d --- /dev/null +++ b/c/tests/stage_8/valid/return_in_while.c @@ -0,0 +1,5 @@ +int main() { + while (1) { + return 2; + } +} \ No newline at end of file diff --git a/c/tests/stage_8/valid/while_multi_statement.c b/c/tests/stage_8/valid/while_multi_statement.c new file mode 100644 index 0000000..62d4a5d --- /dev/null +++ b/c/tests/stage_8/valid/while_multi_statement.c @@ -0,0 +1,11 @@ +int main() { + int a = 0; + int b = 1; + + while (a < 5) { + a = a + 2; + b = b * a; + } + + return a; +} \ No newline at end of file diff --git a/c/tests/stage_8/valid/while_single_statement.c b/c/tests/stage_8/valid/while_single_statement.c new file mode 100644 index 0000000..b9c382f --- /dev/null +++ b/c/tests/stage_8/valid/while_single_statement.c @@ -0,0 +1,8 @@ +int main() { + int a = 0; + + while (a < 5) + a = a + 2; + + return a; +} \ No newline at end of file diff --git a/c/tests/stage_9/invalid/bad_arg.c b/c/tests/stage_9/invalid/bad_arg.c new file mode 100644 index 0000000..651ade1 --- /dev/null +++ b/c/tests/stage_9/invalid/bad_arg.c @@ -0,0 +1,7 @@ +int foo(int a){ + return 3 + a; +} + +int main(){ + return foo(); +} \ No newline at end of file diff --git a/c/tests/stage_9/invalid/declaration_mismatch.c b/c/tests/stage_9/invalid/declaration_mismatch.c new file mode 100644 index 0000000..4f10f78 --- /dev/null +++ b/c/tests/stage_9/invalid/declaration_mismatch.c @@ -0,0 +1,9 @@ +int foo(int a); + +int main() { + return 5; +} + +int foo(int a, int b) { + return 4; +} \ No newline at end of file diff --git a/c/tests/stage_9/invalid/declaration_mismatch_2.c b/c/tests/stage_9/invalid/declaration_mismatch_2.c new file mode 100644 index 0000000..944655c --- /dev/null +++ b/c/tests/stage_9/invalid/declaration_mismatch_2.c @@ -0,0 +1,9 @@ +int foo(int a, int b); + +int main() { + return 5; +} + +int foo(int a) { + return 4; +} \ No newline at end of file diff --git a/c/tests/stage_9/invalid/redefine_function.c b/c/tests/stage_9/invalid/redefine_function.c new file mode 100644 index 0000000..8250e6c --- /dev/null +++ b/c/tests/stage_9/invalid/redefine_function.c @@ -0,0 +1,11 @@ +int foo(){ + return 3; +} + +int main() { + return foo(); +} + +int foo(){ + return 4; +} \ No newline at end of file diff --git a/c/tests/stage_9/invalid/redefine_variable.c b/c/tests/stage_9/invalid/redefine_variable.c new file mode 100644 index 0000000..b42c1d9 --- /dev/null +++ b/c/tests/stage_9/invalid/redefine_variable.c @@ -0,0 +1,7 @@ +int foo(int x) { + int x = 3; +} + +int main() { + foo(1); +} \ No newline at end of file diff --git a/c/tests/stage_9/invalid/too_many_args.c b/c/tests/stage_9/invalid/too_many_args.c new file mode 100644 index 0000000..9b074d4 --- /dev/null +++ b/c/tests/stage_9/invalid/too_many_args.c @@ -0,0 +1,7 @@ +int foo(int a) { + return a + 1; +} + +int main() { + return foo(1, 2); +} \ No newline at end of file diff --git a/c/tests/stage_9/valid/expression_args.c b/c/tests/stage_9/valid/expression_args.c new file mode 100644 index 0000000..be4f694 --- /dev/null +++ b/c/tests/stage_9/valid/expression_args.c @@ -0,0 +1,8 @@ +int add(int a, int b) { + return a + b; +} + +int main() { + int sum = add(1 + 2, 4); + return sum + sum; +} diff --git a/c/tests/stage_9/valid/fib.c b/c/tests/stage_9/valid/fib.c new file mode 100644 index 0000000..6b5e982 --- /dev/null +++ b/c/tests/stage_9/valid/fib.c @@ -0,0 +1,12 @@ +int fib(int n) { + if (n == 0 || n == 1) { + return n; + } else { + return fib(n - 1) + fib(n - 2); + } +} + +int main() { + int n = 5; + return fib(n); +} \ No newline at end of file diff --git a/c/tests/stage_9/valid/forward_decl.c b/c/tests/stage_9/valid/forward_decl.c new file mode 100644 index 0000000..795ebe8 --- /dev/null +++ b/c/tests/stage_9/valid/forward_decl.c @@ -0,0 +1,9 @@ +int foo(); + +int main() { + return foo(); +} + +int foo() { + return 3; +} \ No newline at end of file diff --git a/c/tests/stage_9/valid/forward_decl_args.c b/c/tests/stage_9/valid/forward_decl_args.c new file mode 100644 index 0000000..aea4e2b --- /dev/null +++ b/c/tests/stage_9/valid/forward_decl_args.c @@ -0,0 +1,9 @@ +int foo(int a); + +int main(){ + return foo(3); +} + +int foo(int a){ + return a + 1; +} \ No newline at end of file diff --git a/c/tests/stage_9/valid/forward_decl_multi_arg.c b/c/tests/stage_9/valid/forward_decl_multi_arg.c new file mode 100644 index 0000000..4694fba --- /dev/null +++ b/c/tests/stage_9/valid/forward_decl_multi_arg.c @@ -0,0 +1,9 @@ +int foo(int a, int b); + +int main() { + return foo(1, 2); +} + +int foo(int x, int y){ + return x - y; +} \ No newline at end of file diff --git a/c/tests/stage_9/valid/fun_in_expr.c b/c/tests/stage_9/valid/fun_in_expr.c new file mode 100644 index 0000000..35e71e8 --- /dev/null +++ b/c/tests/stage_9/valid/fun_in_expr.c @@ -0,0 +1,9 @@ +int sum(int a, int b) { + return a + b; +} + +int main() { + int a = sum(1, 2) - (sum(1, 2) / 2) * 2; + int b = 2*sum(3, 4) + sum(1, 2); + return b - a; +} \ No newline at end of file diff --git a/c/tests/stage_9/valid/hello_world.c b/c/tests/stage_9/valid/hello_world.c new file mode 100644 index 0000000..d829028 --- /dev/null +++ b/c/tests/stage_9/valid/hello_world.c @@ -0,0 +1,18 @@ +int putchar(int c); + +int main() { + putchar(72); + putchar(101); + putchar(108); + putchar(108); + putchar(111); + putchar(44); + putchar(32); + putchar(87); + putchar(111); + putchar(114); + putchar(108); + putchar(100); + putchar(33); + putchar(10); +} \ No newline at end of file diff --git a/c/tests/stage_9/valid/later_decl.c b/c/tests/stage_9/valid/later_decl.c new file mode 100644 index 0000000..10d463b --- /dev/null +++ b/c/tests/stage_9/valid/later_decl.c @@ -0,0 +1,9 @@ +int foo(int a) { + return a + 1; +} + +int main() { + return foo(4); +} + +int foo(int a); \ No newline at end of file diff --git a/c/tests/stage_9/valid/multi_arg.c b/c/tests/stage_9/valid/multi_arg.c new file mode 100644 index 0000000..db04cc2 --- /dev/null +++ b/c/tests/stage_9/valid/multi_arg.c @@ -0,0 +1,7 @@ +int sub_3(int x, int y, int z) { + return x - y - z; +} + +int main() { + return sub_3(10, 4, 2); +} \ No newline at end of file diff --git a/c/tests/stage_9/valid/mutual_recursion.c b/c/tests/stage_9/valid/mutual_recursion.c new file mode 100644 index 0000000..71de6bd --- /dev/null +++ b/c/tests/stage_9/valid/mutual_recursion.c @@ -0,0 +1,22 @@ +int foo(int a); +int bar(int b); + +int main() { + return foo(5); +} + +int foo(int a) { + if (a <= 0) { + return a; + } + + return a + bar(a - 1); +} + +int bar(int b) { + if (b <= 0) { + return b; + } + + return b + bar(b / 2); +} \ No newline at end of file diff --git a/c/tests/stage_9/valid/no_arg.c b/c/tests/stage_9/valid/no_arg.c new file mode 100644 index 0000000..e5dd720 --- /dev/null +++ b/c/tests/stage_9/valid/no_arg.c @@ -0,0 +1,7 @@ +int three(){ + return 3; +} + +int main() { + return three(); +} \ No newline at end of file diff --git a/c/tests/stage_9/valid/precedence.c b/c/tests/stage_9/valid/precedence.c new file mode 100644 index 0000000..3f9b432 --- /dev/null +++ b/c/tests/stage_9/valid/precedence.c @@ -0,0 +1,7 @@ +int three() { + return 3; +} + +int main() { + return !three(); +} \ No newline at end of file diff --git a/c/tests/stage_9/valid/rename_function_param.c b/c/tests/stage_9/valid/rename_function_param.c new file mode 100644 index 0000000..2115d9e --- /dev/null +++ b/c/tests/stage_9/valid/rename_function_param.c @@ -0,0 +1,9 @@ +int foo(int b); + +int main(){ + return foo(3); +} + +int foo(int a){ + return a + 1; +} \ No newline at end of file diff --git a/c/tests/stage_9/valid/single_arg.c b/c/tests/stage_9/valid/single_arg.c new file mode 100644 index 0000000..3fdfcfb --- /dev/null +++ b/c/tests/stage_9/valid/single_arg.c @@ -0,0 +1,7 @@ +int twice(int x){ + return 2 * x; +} + +int main() { + return twice(3); +} \ No newline at end of file diff --git a/c/tests/stage_9/valid/variable_as_arg.c b/c/tests/stage_9/valid/variable_as_arg.c new file mode 100644 index 0000000..f4bc83e --- /dev/null +++ b/c/tests/stage_9/valid/variable_as_arg.c @@ -0,0 +1,8 @@ +int foo(int x) { + return x + 1; +} + +int main() { + int a = 1; + return foo(a); +} diff --git a/run b/run new file mode 100755 index 0000000..280106f --- /dev/null +++ b/run @@ -0,0 +1,3 @@ +#!/bin/bash +make run +