I’m stuck on Stage #TZ7.
I’ve tried testing my solution, but I always get stuck in the test that uses “//Comment” and it times out the testing when others run normally fast.
Here are my logs:
[tester::#TZ7] Running tests for Stage #TZ7 (Scanning: Multi-line errors)
[tester::#TZ7] [test-1] Running test case: 1
[tester::#TZ7] [test-1] Writing contents to ./test.lox:
[tester::#TZ7] [test-1] [test.lox] ()<|SPACE|><|TAB|>@
[tester::#TZ7] [test-1] $ ./your_program.sh tokenize test.lox
[your_program] LEFT_PAREN ( null
[your_program] RIGHT_PAREN ) null
[your_program] [line 2] Error: Unexpected character: @
[your_program] EOF null
[tester::#TZ7] [test-1] ✓ 1 line(s) match on stderr
[tester::#TZ7] [test-1] ✓ 3 line(s) match on stdout
[tester::#TZ7] [test-1] ✓ Received exit code 65.
[tester::#TZ7] [test-2] Running test case: 2
[tester::#TZ7] [test-2] Writing contents to ./test.lox:
[tester::#TZ7] [test-2] [test.lox] #
[tester::#TZ7] [test-2] [test.lox] %<|TAB|>
[tester::#TZ7] [test-2] $ ./your_program.sh tokenize test.lox
[your_program] EOF null
[your_program] [line 1] Error: Unexpected character: #
[your_program] [line 2] Error: Unexpected character: %
[tester::#TZ7] [test-2] ✓ 2 line(s) match on stderr
[tester::#TZ7] [test-2] ✓ 1 line(s) match on stdout
[tester::#TZ7] [test-2] ✓ Received exit code 65.
[tester::#TZ7] [test-3] Running test case: 3
[tester::#TZ7] [test-3] Writing contents to ./test.lox:
[tester::#TZ7] [test-3] [test.lox] () #<|TAB|>{}
[tester::#TZ7] [test-3] [test.lox] @
[tester::#TZ7] [test-3] [test.lox] $
[tester::#TZ7] [test-3] [test.lox] +++
[tester::#TZ7] [test-3] [test.lox] // Let's Go!
[tester::#TZ7] [test-3] [test.lox] +++
[tester::#TZ7] [test-3] [test.lox] #
[tester::#TZ7] [test-3] $ ./your_program.sh tokenize test.lox
[your_program] [line 1] Error: Unexpected character: #
[your_program] [line 2] Error: Unexpected character: @
[your_program] [line 3] Error: Unexpected character: $
[your_program] [line 7] Error: Unexpected character: #
[your_program] LEFT_PAREN ( null
[your_program] RIGHT_PAREN ) null
[your_program] LEFT_BRACE { null
[your_program] RIGHT_BRACE } null
[your_program] PLUS + null
[your_program] PLUS + null
[your_program] PLUS + null
[your_program] PLUS + null
[your_program] PLUS + null
[your_program] PLUS + null
[your_program] EOF null
[tester::#TZ7] [test-3] ✓ 4 line(s) match on stderr
[tester::#TZ7] [test-3] ✓ 11 line(s) match on stdout
[tester::#TZ7] [test-3] ✓ Received exit code 65.
[tester::#TZ7] [test-4] Running test case: 4
[tester::#TZ7] [test-4] Writing contents to ./test.lox:
[tester::#TZ7] [test-4] [test.lox] ({;
[tester::#TZ7] [test-4] [test.lox] @})
[tester::#TZ7] [test-4] $ ./your_program.sh tokenize test.lox
[your_program] LEFT_PAREN ( null
[your_program] [line 2] Error: Unexpected character: @
[your_program] LEFT_BRACE { null
[your_program] SEMICOLON ; null
[your_program] RIGHT_BRACE } null
[your_program] RIGHT_PAREN ) null
[your_program] EOF null
[tester::#TZ7] [test-4] ✓ 1 line(s) match on stderr
[tester::#TZ7] [test-4] ✓ 6 line(s) match on stdout
[tester::#TZ7] [test-4] ✓ Received exit code 65.
[tester::#TZ7] Test passed.
[tester::#ER2] Running tests for Stage #ER2 (Scanning: Whitespace)
[tester::#ER2] [test-1] Running test case: 1
[tester::#ER2] [test-1] Writing contents to ./test.lox:
[tester::#ER2] [test-1] [test.lox] <|SPACE|>
[tester::#ER2] [test-1] $ ./your_program.sh tokenize test.lox
[your_program] EOF null
[tester::#ER2] [test-1] ✓ 1 line(s) match on stdout
[tester::#ER2] [test-1] ✓ Received exit code 0.
[tester::#ER2] [test-2] Running test case: 2
[tester::#ER2] [test-2] Writing contents to ./test.lox:
[tester::#ER2] [test-2] [test.lox] <|TAB|>
[tester::#ER2] [test-2] [test.lox] <|SPACE|>
[tester::#ER2] [test-2] $ ./your_program.sh tokenize test.lox
[your_program] EOF null
[tester::#ER2] [test-2] ✓ 1 line(s) match on stdout
[tester::#ER2] [test-2] ✓ Received exit code 0.
[tester::#ER2] [test-3] Running test case: 3
[tester::#ER2] [test-3] Writing contents to ./test.lox:
[tester::#ER2] [test-3] [test.lox] {
[tester::#ER2] [test-3] [test.lox] }
[tester::#ER2] [test-3] [test.lox] ((<|SPACE|>.,;))
[tester::#ER2] [test-3] $ ./your_program.sh tokenize test.lox
[your_program] LEFT_BRACE { null
[your_program] RIGHT_BRACE } null
[your_program] LEFT_PAREN ( null
[your_program] LEFT_PAREN ( null
[your_program] DOT . null
[your_program] COMMA , null
[your_program] SEMICOLON ; null
[your_program] RIGHT_PAREN ) null
[your_program] RIGHT_PAREN ) null
[your_program] EOF null
[tester::#ER2] [test-3] ✓ 10 line(s) match on stdout
[tester::#ER2] [test-3] ✓ Received exit code 0.
[tester::#ER2] [test-4] Running test case: 4
[tester::#ER2] [test-4] Writing contents to ./test.lox:
[tester::#ER2] [test-4] [test.lox] {<|TAB|><|TAB|>
[tester::#ER2] [test-4] [test.lox]
[tester::#ER2] [test-4] [test.lox] }
[tester::#ER2] [test-4] [test.lox] ((>-,
[tester::#ER2] [test-4] [test.lox] ;))
[tester::#ER2] [test-4] $ ./your_program.sh tokenize test.lox
[your_program] LEFT_BRACE { null
[your_program] RIGHT_BRACE } null
[your_program] LEFT_PAREN ( null
[your_program] LEFT_PAREN ( null
[your_program] GREATER > null
[your_program] MINUS - null
[your_program] COMMA , null
[your_program] SEMICOLON ; null
[your_program] RIGHT_PAREN ) null
[your_program] RIGHT_PAREN ) null
[your_program] EOF null
[tester::#ER2] [test-4] ✓ 11 line(s) match on stdout
[tester::#ER2] [test-4] ✓ Received exit code 0.
[tester::#ER2] Test passed.
[tester::#ML2] Running tests for Stage #ML2 (Scanning: Division operator & comments)
[tester::#ML2] [test-1] Running test case: 1
[tester::#ML2] [test-1] Writing contents to ./test.lox:
[tester::#ML2] [test-1] [test.lox] //Comment
[tester::#ML2] [test-1] $ ./your_program.sh tokenize test.lox
[tester::#ML2] [test-1] timed out, test exceeded 10 seconds
[tester::#ML2] [test-1] Test failed
And here’s a snippet of my code that I added for this stage to work:
elif char == "/":
if idx + 1 < len(file_contents) and file_contents[idx + 1] == "/":
if file_contents.find("\n", idx + 2) == 0:
idx = len(file_contents) - 1
else:
idx = file_contents.find("\n", idx + 1) - 1
else:
print("SLASH / null")
elif char in "$#@%":
print(f"[line {line_number}] Error: Unexpected character: {char}", file=sys.stderr)
error_code = 65
elif char in " \t":
pass
elif char == "\n":
line_number += 1
idx += 1
print("EOF null")
exit(error_code)