Hello there,
Can anyone point to me some resources about how to parse/traverse the gnu-smalltalk code? There are many Parsers in the STInST package. I see two syntax forms in the the source directory. Code in the kernel/ can be used in gst, but some in tests/, like Compiler.st, have parsing errors. What's going wrong here? Shouldn't gst support both syntax? Thanks. Junsong Li _______________________________________________ help-smalltalk mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-smalltalk |
Hi, > Can anyone point to me some resources about how to parse/traverse the > gnu-smalltalk code? There are many Parsers in the STInST package. I assume you mean programatically? The Parser package of STInST is the way to go. And the content in packages/sttools has an example on how to use it. > I see two syntax forms in the the source directory. Code in the kernel/ can > be used in gst, but some in tests/, like Compiler.st, have parsing errors. > What's going wrong here? Shouldn't gst support both syntax? There is the standard “fileout” syntax of Smalltalk and the new GST format to make it more pleasant to edit with standard unix tools. What parse error do you get? There is a known issue in STInST that it fails to parse compile time constants ##(2/3) (which will be evaluated at compile time). holger _______________________________________________ help-smalltalk mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-smalltalk |
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: 1. STParsingDriver <- STEvaluationDriver 2. RBParser <- STFileParser <- STFileInParser <- GSTFileInParser A simple executable expression to get a GSTFileInParser is (STInST.STParsingDriver new parseSmalltalkStream: 'Object subclass: Test [ method [ ^1 ] ]' readStream with: STInST.GSTFileInParser) parser Then I am stuck on getting AST out. It appears to having no methods to return the AST node. Anything wrong with it? I also noticed there were a class named RBProgramNodeVisitor, Is there a way I can get the RBProgramNodeVisitor from a given source file? To answer your second question, yes, that's the error. Thanks for pointing out. On Sun, Apr 12, 2015 at 4:03 AM, Holger Freyther <[hidden email]> wrote: > > Hi, > > > Can anyone point to me some resources about how to parse/traverse the > > gnu-smalltalk code? There are many Parsers in the STInST package. > > I assume you mean programatically? The Parser package of STInST is > the way to go. And the content in packages/sttools has an example on how > to use it. > > > > > I see two syntax forms in the the source directory. Code in the kernel/ > can > > be used in gst, but some in tests/, like Compiler.st, have parsing > errors. > > What's going wrong here? Shouldn't gst support both syntax? > > > There is the standard “fileout” syntax of Smalltalk and the new GST > format to make it more pleasant to edit with standard unix tools. What > parse error do you get? > > There is a known issue in STInST that it fails to parse compile time > constants ##(2/3) (which will be evaluated at compile time). > > holger help-smalltalk mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-smalltalk |
Sorry. A typo: I also noticed there was a class named RBProgramNodeVisitor,
Is there a way I can get the RBProgramNode from a given source file? On Sun, Apr 12, 2015 at 10:56 AM, Junsong Li <[hidden email]> 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: > > 1. STParsingDriver <- STEvaluationDriver > 2. RBParser <- STFileParser <- STFileInParser <- GSTFileInParser > > A simple executable expression to get a GSTFileInParser is > > (STInST.STParsingDriver new parseSmalltalkStream: 'Object subclass: Test [ > method [ ^1 ] ]' readStream > with: STInST.GSTFileInParser) parser > > Then I am stuck on getting AST out. It appears to having no methods to > return the AST node. Anything wrong with it? > > I also noticed there were a class named RBProgramNodeVisitor, Is there a > way I can get the RBProgramNodeVisitor from a given source file? > > To answer your second question, yes, that's the error. Thanks for pointing > out. > > > On Sun, Apr 12, 2015 at 4:03 AM, Holger Freyther <[hidden email]> > wrote: > >> >> Hi, >> >> > Can anyone point to me some resources about how to parse/traverse the >> > gnu-smalltalk code? There are many Parsers in the STInST package. >> >> I assume you mean programatically? The Parser package of STInST is >> the way to go. And the content in packages/sttools has an example on how >> to use it. >> >> >> >> > I see two syntax forms in the the source directory. Code in the kernel/ >> can >> > be used in gst, but some in tests/, like Compiler.st, have parsing >> errors. >> > What's going wrong here? Shouldn't gst support both syntax? >> >> >> There is the standard “fileout” syntax of Smalltalk and the new GST >> format to make it more pleasant to edit with standard unix tools. What >> parse error do you get? >> >> There is a known issue in STInST that it fails to parse compile time >> constants ##(2/3) (which will be evaluated at compile time). >> >> holger > > > help-smalltalk mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-smalltalk |
In reply to this post by Junsong Li
> On 12 Apr 2015, at 16:56, Junsong Li <[hidden email]> 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 [hidden email] https://lists.gnu.org/mailman/listinfo/help-smalltalk |
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 <[hidden email]> wrote: > > > On 12 Apr 2015, at 16:56, Junsong Li <[hidden email]> 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 [hidden email] https://lists.gnu.org/mailman/listinfo/help-smalltalk |
> On 15 Apr 2015, at 14:21, Junsong Li <[hidden email]> wrote: > > Thanks. Using STClassLoader to load the class and then walking the AST of the class is the way to go! Done! > What are you implementing? holger _______________________________________________ help-smalltalk mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-smalltalk |
Basically, I want to desugar/translate SmallTalk programs to a
meta-language, using the meta-language to model the semantics of smalltalk to understand OOP language designs(in this case, the design of smalltalk). On Wed, Apr 15, 2015 at 4:42 PM, Holger Freyther <[hidden email]> wrote: > > > On 15 Apr 2015, at 14:21, Junsong Li <[hidden email]> wrote: > > > > Thanks. Using STClassLoader to load the class and then walking the AST > of the class is the way to go! Done! > > > > What are you implementing? > > holger > > help-smalltalk mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-smalltalk |
Free forum by Nabble | Edit this page |