diff --git a/Sources/rxcc/rxcc.swift b/Sources/rxcc/rxcc.swift index cc8c866..6a9a458 100644 --- a/Sources/rxcc/rxcc.swift +++ b/Sources/rxcc/rxcc.swift @@ -451,27 +451,37 @@ enum Validity { } func validateConstruct(_ construct: Construct, tokens: inout [Token], node: SyntaxTreeNode) -> Validity { + var indent: String { + var count: Int = 0 + var child: SyntaxTreeNode = node + while child.parent != nil { + count += 1 + child = child.parent! + } + return String(repeating: " ", count: count) + } + var loop: Bool = false repeat { for element in construct { switch element { case .Construct(let type): - print("Begin validate subconstruct (type \"\(type)\")") + print("\(indent)Begin validate subconstruct (type \"\(type)\")") var valid: Validity = .Invalid var validVariant: ConstructVariant = .Error let tokenBackup: [Token] = tokens for key in constructDefinitions[type]!.keys { let childNode = node.addChild(value: key) - print("Testing variant \(key) (Loop = \(loop))") + print("\(indent)Testing variant \(key) (Loop = \(loop))") valid = validateConstruct(constructDefinitions[type]![key]!, tokens: &tokens, node: childNode) if valid == .Invalid { - print("Fail") + print("\(indent)Fail") tokens = tokenBackup _ = node.popLastChild() continue } - print("Success") + print("\(indent)Success") validVariant = key break @@ -484,10 +494,10 @@ func validateConstruct(_ construct: Construct, tokens: inout [Token], node: Synt if type == .Factor { let nextToken: Token = tokens[tokens.count - 1] if nextToken.type == .MULTIPLICATION || nextToken.type == .DIVISION { - print("Looping due to factor") + print("\(indent)Looping due to factor") loop = true } else { - print("Breaking out of factor loop") + print("\(indent)Breaking out of factor loop") loop = false return .Break } @@ -497,10 +507,10 @@ func validateConstruct(_ construct: Construct, tokens: inout [Token], node: Synt else if type == .Term { let nextToken: Token = tokens[tokens.count - 1] if nextToken.type == .ADDITION || nextToken.type == .NEGATION { - print("Looping due to term") + print("\(indent)Looping due to term") loop = true } else { - print("Breaking out of term loop") + print("\(indent)Breaking out of term loop") loop = false return .Break } @@ -510,26 +520,24 @@ func validateConstruct(_ construct: Construct, tokens: inout [Token], node: Synt if valid == .Invalid { - print("Subconstruct validation failed") + print("\(indent)Subconstruct validation failed") return .Invalid } else if valid == .Break { - print("End validate subconstruct (variant \"\(validVariant) by breaking\")") + print("\(indent)End validate subconstruct (variant \"\(validVariant) by breaking\")") print(type) break } - print("End validate subconstruct (variant \"\(validVariant)\")") - print(type) - + print("\(indent)End validate subconstruct (variant \"\(validVariant)\")") continue case .Token(let type): if let token: Token = tokens.popLast() { if type != token.type { - print("VALIDATION FAILED FOR TOKEN \"\(token.content)\"") + print("\(indent)VALIDATION FAILED FOR TOKEN \"\(token.content)\"") return .Invalid } - print("Validated token \"\(token.content)\"") + print("\(indent)Validated token \"\(token.content)\"") if token.type == .LITERAL_INTEGER { node.value = String(token.content) @@ -541,7 +549,7 @@ func validateConstruct(_ construct: Construct, tokens: inout [Token], node: Synt continue } else { - print("RAN OUT OF TOKENS") + print("\(indent)RAN OUT OF TOKENS") return .Invalid } } diff --git a/a.out b/a.out index cda0f91..ffc6a38 100755 Binary files a/a.out and b/a.out differ diff --git a/bitwise.s b/bitwise.s deleted file mode 100644 index e04fa70..0000000 --- a/bitwise.s +++ /dev/null @@ -1,21 +0,0 @@ - .file "bitwise.c" - .text - .globl main - .type main, @function -main: -.LFB0: - .cfi_startproc - pushq %rbp - .cfi_def_cfa_offset 16 - .cfi_offset 6, -16 - movq %rsp, %rbp - .cfi_def_cfa_register 6 - movl $-13, %eax - popq %rbp - .cfi_def_cfa 7, 8 - ret - .cfi_endproc -.LFE0: - .size main, .-main - .ident "GCC: (GNU) 15.2.1 20260103" - .section .note.GNU-stack,"",@progbits diff --git a/my.out b/my.out deleted file mode 100755 index f8d436e..0000000 Binary files a/my.out and /dev/null differ diff --git a/test.c b/test.c new file mode 100644 index 0000000..554c254 --- /dev/null +++ b/test.c @@ -0,0 +1,3 @@ +int main() { + return !1 * 1; +} diff --git a/test.s b/test.s new file mode 100644 index 0000000..e69de29 diff --git a/test2.c b/test2.c new file mode 100644 index 0000000..08e20b8 --- /dev/null +++ b/test2.c @@ -0,0 +1,3 @@ +int main() { + return (~2 + !(4 - 2) / 9 - -9) + 90 * 8 - 2 - 33 * (400 - 1) - !~-9; +} diff --git a/test2.s b/test2.s new file mode 100644 index 0000000..e69de29