I've moved on to step 1 of the MAL process, which involves creating the lexer and parser. I feel like I'm this close to a breakthrough in the code, but I keep running into various errors where somewhere my code is producing undefined values...
I think there is something tricky going on with my read_list and read_atom functions. If the first thing I do when I run the program is submit a list, then the program parses (not quite for some reason) without crashing. However, when I try to submit a list as the next command, the code craps out and gives an undefined error. It looks like the iterator is skipping around, not catching every token (otherwise all the tokens would print at "token =
output
hypatia@Yours-MacBook-Air:\https://cs.marlboro.college/cours/spring2019/jims_tutorials/mal/javascript$ node step1_read_print.js
user> (this is a list)
Debug: Tokens = (,this, is, a, list,),
token = is
token = list
read_form returns
undefined
user> (1 2 3)
Debug: Tokens = (,1, 2, 3,),
token = 2
token = )
token = undefined
/Users/hypatia/mal/javascript/reader.js:50
if (token.match(numbers)){
^
TypeError: Cannot read property 'match' of undefined
at read_atom (/Users/hypatia/mal/javascript/reader.js:50:15)
at read_form (/Users/hypatia/mal/javascript/reader.js:30:21)
at read_list (/Users/hypatia/mal/javascript/reader.js:39:21)
at read_form (/Users/hypatia/mal/javascript/reader.js:28:21)
at Object.read_str (/Users/hypatia/mal/javascript/reader.js:12:44)
at READ (/Users/hypatia/mal/javascript/step1_read_print.js:30:19)
at rep (/Users/hypatia/mal/javascript/step1_read_print.js:47:12)
at main (/Users/hypatia/mal/javascript/step1_read_print.js:64:25)
at Object.<anonymous> (/Users/hypatia/mal/javascript/step1_read_print.js:71:1)
at Module._compile (internal/modules/cjs/loader.js:816:30)
last modified | size | ||
printer.js | Mon Nov 25 2024 12:40 pm | 696B | |
reader.js | Mon Nov 25 2024 12:40 pm | 1.4K | |
step1_read_print.js | Mon Nov 25 2024 12:40 pm | 1.4K |