The test case -
{
// This is a complex test case
str1 = "Test"
str2 = "Case"
num1 = 100
num2 = 200.00
result = (str1 == str2) != ((num1 + num2) >= 300)
}
$ ./your_program.sh tokenize test.lox
Logs from your program will appear here!
LEFT_BRACE { null
IDENTIFIER str1 null
EQUAL = null
STRING "Test" Test
IDENTIFIER str2 null
EQUAL = null
STRING "Case" Case
IDENTIFIER num1 null
EQUAL = null
NUMBER 100 100.0
IDENTIFIER num2 null
EQUAL = null
NUMBER 200 200.0
IDENTIFIER result null
EQUAL = null
LEFT_PAREN ( null
IDENTIFIER str1 null
EQUAL_EQUAL == null
IDENTIFIER str2 null
RIGHT_PAREN ) null
BANG_EQUAL != null
LEFT_PAREN ( null
LEFT_PAREN ( null
IDENTIFIER num1 null
PLUS + null
IDENTIFIER num2 null
RIGHT_PAREN ) null
GREATER_EQUAL >= null
NUMBER 300 300.0
RIGHT_PAREN ) null
RIGHT_BRACE } null
EOF null
remote: [tester::#EY7] [test-4] ✓ LEFT_BRACE { null
remote: [tester::#EY7] [test-4] ✓ IDENTIFIER str1 null
remote: [tester::#EY7] [test-4] ✓ EQUAL = null
remote: [tester::#EY7] [test-4] ✓ STRING "Test" Test
remote: [tester::#EY7] [test-4] ✓ IDENTIFIER str2 null
remote: [tester::#EY7] [test-4] ✓ EQUAL = null
remote: [tester::#EY7] [test-4] ✓ STRING "Case" Case
remote: [tester::#EY7] [test-4] ✓ IDENTIFIER num1 null
remote: [tester::#EY7] [test-4] ✓ EQUAL = null
remote: [tester::#EY7] [test-4] ✓ NUMBER 100 100.0
remote: [tester::#EY7] [test-4] ✓ IDENTIFIER num2 null
remote: [tester::#EY7] [test-4] ✓ EQUAL = null
remote: [tester::#EY7] [test-4] 𐄂 NUMBER 200 200.0
remote: [tester::#EY7] [test-4] Expected line #13 on stdout to be "NUMBER 200.00 200.0", got "NUMBER 200 200.0"
remote: [tester::#EY7] [test-4] Test failed
Should the line not be “NUMBER 200 200.0” and not “NUMBER 200.00 200.0” since the lexeme part of the token stores the number without the decimal point in the case of an integer. What is the purpose of it being “200.00” if not?
For the input “42”, this should be the output according to “Scanning: Number literals” -
$ ./your_program.sh tokenize test.lox
NUMBER 42 42.0
EOF null