Le 01/03/2015 09:13, kilon alios a écrit :


I have this grammar definition in the python parser

file_input: {{}}
     | file_input <NEWLINE> {{}}
     | file_input stmt 'statement' {{}}
     ;

So I would expect
a) the class to be name Pyfile_inputNode , instead is named
PyFileInputNode, why ?

The naming scheme inside SmaCC removes the _ and capitalize the words :)

b) I would expect a "statement" instance variable in that class and
instead I get "statements" instance variable, why ?

Because this two productions define a list of stmt (possibly empty) and the AST generation code notices that, so it adds an s to statement and prepare that instance variable to be an OrderedCollection.

When I see the code doing that in SmaCC, I'm allways impressed. Ok, the theory behind is well known and not that complex, but the inference done (cascading through the grammar rules to fetch everything needed) is impressive (and basically fairly hard to master when you write a parser :().

Thierry

Reply via email to