Javadoc for SableCC grammar file

31 views
Skip to first unread message

Bui Hong Phuc

unread,
Nov 19, 2012, 4:25:16 PM11/19/12
to sab...@googlegroups.com
Hi,

How can I extend the SableCC Parser generator to generate Java files with
"Javadoc", which I write in Tokens and Productions. For example I have

Tokens
    /** the plus sign in expression */
    plus = '+';

then I will get something like:

/**
 * the plus sign in expression
 */
public TPlus extends Token{
    /** ... */
}

For productions it may be:

Abstract Syntax Tree
    /** represents the arithmetical expression */
    expression =
        /** represents the addition */
        {add} expresion plus expresion
        /** represents the multiplication */
        |{mul} expression mul expresion;

I will get something like

/** represents the arithmetical expression */
public abstract class Expression extends Node{
// ...
}

/**
represents the addition */
public class AAddExpression extends PExpression{
// ...
}

My first Idea is, I parse the grammar twice. At the first time I let SableCC generate the java files as normal.
At the second I recognize the javadoc in the grammar files (with some modi in the SableCC grammar file for
SableCC selft), then I parse the generated java file, combine the recognized javadoc with the AST and re-serialize
the AST to new Java file with Javadoc. But this way take to many time to implement. So has someone other idea?

Thank,

Hong Phuc

Etienne Gagnon

unread,
Nov 19, 2012, 11:24:18 PM11/19/12
to sab...@googlegroups.com
Hi Hong Phuc,

I really like this idea.

I don't recommend undertaking big projects in the SableCC 3 code base. But, your project seems an interesting one for SableCC 4.

Once SableCC 4 becomes self generating (for its parser), you could probably implement your idea without the need to parse twice. I'm working on it (SableCC 4).

Etienne
Etienne Gagnon, Ph.D.
http://sablecc.org
--
-- You received this message because you are subscribed to the SableCC group. To post to this group, send email to sab...@googlegroups.com. To unsubscribe from this group, send email to sablecc+u...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/sablecc?hl=en
 
 

Bui Hong Phuc

unread,
Nov 21, 2012, 5:02:43 PM11/21/12
to sab...@googlegroups.com
Hi Etienne,

so I'll try to parse the generated files and wait for the new SableCC 4. :)
Because nowadays IDEs support the on-the-fly javadoc browser, I think this idea
could be helpful for programmer to use the generated parser within a IDE.

Hong Phuc
Reply all
Reply to author
Forward
0 new messages