# Lexical Error Detection

**URL:** <https://forum.codecrafters.io/t/lexical-error-detection/1387>\
**Category:** Challenges\
**Tags:** challenge:interpreter\
**Created:** [August 12, 2024, 7:22pm UTC](https://forum.codecrafters.io/t/lexical-error-detection/1387 "2024-08-12T19:22:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![apmsabee](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/apmsabee/32/1270_2.png) [@apmsabee](https://forum.codecrafters.io/u/apmsabee)\
**Post date:** [August 12, 2024, 7:22pm UTC](https://forum.codecrafters.io/t/lexical-error-detection/1387/1 "2024-08-12T19:22:09Z")

</div>

I’m stuck on Stage #TZ7

I already have the default case in my switch statement designed to print out what they’re asking for in this stage, I’m really not clear on why I’m not detecting these characters at all.

Here are my logs:

```auto
remote: [tester::#TZ7] Running tests for Stage #TZ7 (Scanning: Multi-line errors)
remote: [tester::#TZ7] [test-1] Running test case: 1
remote: [tester::#TZ7] [test-1] Writing contents to ./test.lox:
remote: [tester::#TZ7] [test-1] [test.lox] ()<|SPACE|><|TAB|>@
remote: [tester::#TZ7] [test-1] $ ./your_program.sh tokenize test.lox
remote: [your_program] Logs from your program will appear here!
remote: [your_program] LEFT_PAREN ( null
remote: [your_program] RIGHT_PAREN ) null
remote: [your_program] EOF null

```

And here’s a snippet of my code in my scanner.go class:

```go
case '\n':
		s.currentLine++
		return nil, ""
	case ' ', '\r', '\t':
		s.current++
		return nil, ""
	default:
		err := fmt.Sprintf("[line %d] Error: Unexpected character: %c\n", s.currentLine, currToken)
		return nil, err
	}

```

---

<div class="post-metadata">

**Author:** ![rohitpaulk](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/rohitpaulk/32/6_2.png) [@rohitpaulk](https://forum.codecrafters.io/u/rohitpaulk)\
**Post date:** [August 13, 2024, 11:20am UTC](https://forum.codecrafters.io/t/lexical-error-detection/1387/2 "2024-08-13T11:20:25Z")

</div>

@apmsabee hmm, if you run this against a file locally, do you see the errors printed?

Also, could you publish your code to GitHub please? Here’s how you can do this: [Publish to GitHub - CodeCrafters](https://docs.codecrafters.io/features/publish-to-github#publish-to-github). Without seeing the rest of your code it’s difficult to figure out what’s going on.

---

<div class="post-metadata">

**Author:** ![vb-ee](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/vb-ee/32/1283_2.png) [@vb-ee](https://forum.codecrafters.io/u/vb-ee)\
**Post date:** [August 14, 2024, 9:39am UTC](https://forum.codecrafters.io/t/lexical-error-detection/1387/3 "2024-08-14T09:39:52Z")

</div>

I also have similar issue, I am not sure but it seems like the remote test case is not correct. I created an identical test case on my local machine and it passed successfully, but running remote test cases give following error. Note that according to test case the file does not contain `@` character

 ![Screenshot 2024-08-14 at 11.21.41 AM](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/8/829433b06cbf6da56a56d67b04ce91e6bf818deb.png)

---

<div class="post-metadata">

**Author:** ![rohitpaulk](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/rohitpaulk/32/6_2.png) [@rohitpaulk](https://forum.codecrafters.io/u/rohitpaulk)\
**Post date:** [August 14, 2024, 11:39am UTC](https://forum.codecrafters.io/t/lexical-error-detection/1387/4 "2024-08-14T11:39:58Z")

</div>

> [@vb-ee](#):
>
> Note that according to test case the file does not contain `@` character

@vb-ee looking at the logs, `@` **is** present in the file, no? Your program seems to print out the error correctly, it just isn’t exiting with code 65.

---

<div class="post-metadata">

**Author:** ![vb-ee](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/vb-ee/32/1283_2.png) [@vb-ee](https://forum.codecrafters.io/u/vb-ee)\
**Post date:** [August 14, 2024, 1:13pm UTC](https://forum.codecrafters.io/t/lexical-error-detection/1387/5 "2024-08-14T13:13:43Z")

</div>

I apologize for the confusion, yes you are right, my implementation of exit with code 65 was wrong. Sorry for misunderstanding

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [October 4, 2024, 2:13am UTC](https://forum.codecrafters.io/t/lexical-error-detection/1387/6 "2024-10-04T02:13:53Z")

</div>

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
