Open ThierryGoubier opened 7 years ago
To explain: with either the %root or %hierarchy directive, SmaCC will generate three classes around Expression, Binary and Number.
With %prefix AST; and %suffix Node;, we will have:
SmaCCParseNode subclass: #ASTExpressionNode
instanceVariableNames: 'leftParenTokens rightParenTokens'
classVariableNames: ''
poolDictionaries: ''
category: 'SmaCC-Tutorial'
And:
ASTExpressionNode subclass: #ASTBinaryNode
instanceVariableNames: 'left operator right'
classVariableNames: ''
poolDictionaries: ''
category: 'SmaCC-Tutorial'.
ASTExpressionNode subclass: #ASTNumberNode
instanceVariableNames: 'numberToken'
classVariableNames: ''
poolDictionaries: ''
category: 'SmaCC-Tutorial'
Parsing the following: ((4)) will then create an ASTNumberNode with the parenthesis inside the node:
That is, even with the parenthesis, no ASTExpressionNode will be created. The same with (3+4), it will create an instance of ASTBinaryNode, with the parenthesis inside.
Evaluation:
SmaCC correctly infer types if the right superclass is created, fail inference if there is no common superclass, and never creates labelled node (i.e. a superclass instance).
This segment only resolve properly if the following is added:
Or
Otherwise SmaCC signal the following error: