You are here: Home JastAdd Forums General board Short Tutorial / Parsers
Document Actions

Short Tutorial / Parsers

Up to General board

Short Tutorial / Parsers

Posted by MerlinK at April 25. 2008

Hello,


1)
I am experimenting with different language extension technologies, JastAdd included. Although plenty of examples are given in the form of programs, and some explanation (which is generally one or two sentences describing functionality rather than how to go about it), I would like to see a very simple extension to Java described in a step by step manner, starting from the grammar, ast to attributes etc. in a tutorial format. Once such a small tutorial (perhaps compiled from various documentation) is available, other examples that are already there will be clearer to me.


2)
I am unaware of whether JastAdd tackles left recursive grammars.


3)
The third point is related to second. Since any parser may be used, how exactly does Jastadd establishes connection between the parser generated and the ast described in Jastadd?? The question comes to mind, because ANTLR takes LL*, Javacc takes LL(k), SableCC takes LR(K) grammars. How is the relation between ast and parse tree is setup in such cases thus abstracting the details of parsers? (again ANTLR and Javacc create methods based on productions whereas Sablecc generates class heirarchy of production )


4)
What if I wanted to use some other parser, what is the procedure then?


Hope you answer these, and include a nice short 'tutorial' in the documentation. Thanks


-Merlin


Re: Short Tutorial / Parsers

Posted by Torbjörn Ekman at April 25. 2008

Hi Merlin,


1) A tutorial of the kind you describe is in the works. I can unfortunately not give you an estimated release date.


2-4) JastAdd mainly deals with abstract syntax trees (ASTs) and computations on top of them using attributes and rewrites. The problems you describe is specific to the kind of parser technology you use. For instance, in JastAddJ (the extensible Java compiler) we use a small preprocessor and generate a parsing spec for Beaver (http://beaver.sourceforge.net/). The parser is separated from the AST by using separate specifications: the parser will have to build an AST compliant with abstract grammar (defined in .ast files). That way the AST specification does not have to be restricted by parsing limitations such as how to handle left recursion. The AST is usually created by adding semantic actions to the parser which create instances of the node types generated from the abstract grammar. We can thus only interact with parser generators where you can tailor the semantic actions yourself.


Don't hesitate to ask if you have further questions.


Regards


/Torbjorn


Powered by Ploneboard