Re: Which parser to use to parse the gnu-smalltalk code

Junsong Li <[email protected]>
Newsgroups gmane.comp.lang.smalltalk.gnu.general
Message-ID <CA+kGxtPFUo1cq3Crd8cr_woR1PU4NQp+m6S4LUcjfksqYkR3NQ@mail.gmail.com>
Thanks. Using STClassLoader to load the class and then walking the AST of
the class is the way to go! Done!

On Sun, Apr 12, 2015 at 1:34 PM, Holger Freyther <[email protected]> wrote:

>
> > On 12 Apr 2015, at 16:56, Junsong Li <[email protected]> wrote:
> >
> > Thanks. Basically what I want is just a method that compile the .st
> file, give me the root node of the AST, then I can traverse the AST and
> print out each kind of expression. I have tried _various_ classes in
> STInST, none of them works. Here is what I got. There are basically Drivers
> and Parsers for parsing:
>
> The general approach is to look at the testcases. E.g. to parse a class the
> first thing I found is:
>
> > (STInST.STParsingDriver new parseSmalltalkStream: 'Object subclass: Test
> [ method [ ^1 ] ]' readStream
> >   with: STInST.GSTFileInParser) parser
>
> Did you have a look at the test cases? E.g. the STClassLoader? And did you
> look
> at scripts/Convert.st which is using STInST to parse and re-format? At the
> same
> also at the STCompiler which inherits from the RBProgramNodeVisitor?
>
> The STInST.STParsingDriver hierarchy will load the code and call
> >>#evaluate:
> on each node. So you don’t get an AST of ASTs with this.
>
> But if you start the other way around. E.g. with the RBParser you can
> parse simple
> expressions like STInST.RBParser parseExpression: '3+3’ or even entire
> methods
> using STInST.RBBracketedMethodParser parseMethod: 'abc [ ^ 3]’ which will
> give
> you RBMethodNode.
>
> But starting from the STFileInparser subclass you need to provide a driver
> that
> will be called whenever something has been parsed. It is then up to you to
> decide
> what to do with the RB nodes.
>
>
>
> >
> > Then I am stuck on getting AST out. It appears to having no methods to
> return the AST node.  Anything wrong with it?
>
> You looked at the driver. IIRC they go through the classes but don’t store
> them. E.g. the
> STClassLoader loads a class and you can access a representation of the
> class then.
>
>
>
_______________________________________________
help-smalltalk mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/help-smalltalk
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.