Reference: Crafting Interpreters. Print statement is not able to evaluate expression. Help me fix this (details below)

28 views Asked by At

I have implemented till Statements and State in Tree Walk Interpreter.


> print (4+4);
[line ] Error at 'print': Expect expression.
Exception in thread "main" com.piscan.Zealot.Parser$ParseError
    at com.piscan.Zealot.Parser.error(Parser.java:201)
    at com.piscan.Zealot.Parser.primary(Parser.java:130)
    at com.piscan.Zealot.Parser.unary(Parser.java:105)
    at com.piscan.Zealot.Parser.factor(Parser.java:88)
    at com.piscan.Zealot.Parser.term(Parser.java:76)
    at com.piscan.Zealot.Parser.comparison(Parser.java:63)
    at com.piscan.Zealot.Parser.equality(Parser.java:50)
    at com.piscan.Zealot.Parser.expression(Parser.java:45)
    at com.piscan.Zealot.Parser.expressionStatement(Parser.java:149)
    at com.piscan.Zealot.Parser.statement(Parser.java:139)
    at com.piscan.Zealot.Parser.parse(Parser.java:37)
    at com.piscan.Zealot.Zealot.run(Zealot.java:85)
    at com.piscan.Zealot.Zealot.runPrompt(Zealot.java:66)
    at com.piscan.Zealot.Zealot.main(Zealot.java:25)

you can look for my Parser file here: Parser and Interpreter file here: Interpreter

here is the main lox file: Zealot

I have been stucked here since 2 days. Tried many different ways to solve this but i didnt worked out.

update: i debugged it and found that Parser is recognizing the print keyword, but it is not recognizing it as a valid expression. The expression method in the Parser class is responsible for parsing expressions, and it calls the equality method, which in turn calls the comparison method, and so on. how to fix this? Now, can you help me with that

0

There are 0 answers