2015-01-28 14:53 GMT+01:00 kilon alios <kilon.al...@gmail.com>:

> Ok I have read a few times of the tutorial of Smacc in here
> http://www.refactoryworkers.com/SmaCC/ASTs.html
>
> and I am also following the help tool documentation inside pharo for SmaCC
> and I have to say I am very confused. Please bare with me because I am
> extremely noob when it comes to parsing, this is my first effort.
>

Ok. I made sure the help was up to date with the current SmaCC; the online
tutorial may differ a bit (GUI, some of the class creation commands).


>
> Now the way I understand it so far, is that SmaCC uses a syntax similar to
> regex expressions to define parsers and scanners. Scanners evaluate a
> string to see that it contains a valid form and parser divide to parts
> named as "tokens" and help in the creating of ASTs which are basically
> hierarchy tree containing the syntax elements of a language.
>

Scanners divide the input stream in tokens with regular expressions.

Parsers builds (sort of: at least they follow the steps) a tree (a parse
tree) out of the tokens, parse tree which is reduced and simplified as an
AST. And the AST represent the structure of the source code (as per the
language definition in the grammar)


>
> Now in order to make SmaCC work I need to use the SmaCC tool that comes
> with pharo . The smacc tool takes two inputs a scanner and a parser class.
> Does that mean I need to create that parser and scanner class ? I thought
> since I define the syntax that those things would be generated by the tool.
>

If you give new classes, it will create them. If you give existing classes,
it will reuse them.


> What I need to define exactly ?
>
> Why when I select the PythonScanner2 and PythonParser2 and click then
> Compile LR it gives a MNU receiver of method is nil ?
>

This is the issue I told you about in Pharo 4. The fix is waiting for
review before integration (https://pharo.fogbugz.com/default.asp?14730).


>
> I am using latest Pharo 4 image.
>
> My goal is to parse python types to similar pharo objects. I get those
> python types as strings and my main focus in lists, dictionaries and tuples
> . The tricky part is that one can contain the other inside in every
> imagined way.
>
> The way I understand it I will need something called "transformations" to
> convert those python types to OrderedCollections, Arrays etc and anything
> would make more sense for a pharo coder.
>

With the PythonParser, you get a visitor generated, so you can subclass it
and visit the ast produced by the parser and generate the relevant
OrderedCollections.


>
> Additionally what is the meaning of the vertibal bar ?   --> |
> eg.
> | Number
>

It means or. For example,

Atom:
    | Number
    ;

Would mean that Atom is either empty or a number.


>
> Are there any other tutorials that can help a beginner like me to
> understand these concepts ?
>

I don't have any at hand: I teach that at the moment, so I'm not delegating
to a tutorial for my students ;)


>
> I am not looking for someone to give me the solution to the plate, I would
> love to learn and understand parsing because I am very interested into
> making Pharo easy to mix with Python code and allow Pharo to use Python
> libraries without the user having to learn or code Python :)
>
> As you may imagine this is a crucial ingredient for my project Ephestos
> which tries to use Pharo to script Blender by either replacing or
> cooperating with blender python. So learning a good way to parse pharo code
> to python code and vice versa is extremely important for me.
>

The way it is set should support you well for doing what you want, so keep
doing it :)

Thierry

Reply via email to