Open alphastigma101 opened 1 month ago
Thanks for the feedback!
The reason ParserBase
class that was made abstract was because it has an abstract method parse()
which all deriving class must implement.
I have also made structural changes to the codebase (see 26ff596bd0069183a18e5e137ff9eba5e975d969) which hopefully will better organize stuffs to where they need to be.
Currently,
astNode.ts
stores the base implementation of the AstNode
class, the base class to all AST nodes;astNodes.ts
stores all classes that extends from AstNode
with its own data.I'm looking at the vistor, i hope to implement it soon.
A simple printer has been implemented (see 7db058720fc09e28ed9b851f050caa493a6edcf2), which hopefully will resolve this inquiry. The issue will be closed in 24 hours if there are no further comments. Once again, thanks for the feedback.
retreat
. It shouldn't be there. It is an abstract class which the methods should only be declared and not defined. The derived class should overwrite each method inside the abstract class. Which is why polymorphism can be so useful. You should start from scratch. Take a look at this example: https://craftinginterpreters.com/representing-code.html and understand what an abstraction syntax tree is. This should be your road map. Due note the code is written in Java, so you're going to need to translate the java code into typescript or whichever language you're using.-------------------------------------------------------------------------------------------------------------------------------------------------------------------
astNode.ts
This file should not be here. What makes the nodes, which you can store in a container is your parser. This is the parser I implemented in c++ after translating it from java: https://craftinginterpreters.com/parsing-expressions.html#wiring-up-the-parser---------------------------------------------------------------------------------------------------------------------------------------------------------------------
astRepr.ts
is basically your visitor method. It is supposed to be a design pattern that visits the nodes that were created by your parser. So, Yourinterpreter
, andgrammar
should implementaccept
andvisit
method followed bythis
to achieve that polymorphism and assuming the proper classes are abstracted.