[squeak-dev] Precedence in SmaCC

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Precedence in SmaCC

Andrew Wakeling

Hi,

 

I’ve recently attempted to get SmaCC working in Squeak.

 

I’m having trouble getting precedence working in my image.

 

My base image is Squeak 3.9 final 7067.

 

I have confirmed that I have all the pre-requisite packages loaded:

 

AST-lr.157

RefactoringEngine-lr.46 (Just updated)

SmaCC-lr.13

SmaCCDev-lr.18

 

I’m trying the examples listed in the tutorial and this is the code that I’m putting in the scanner and the parser.

 

Scanner:
<number>        :       [0-9]+ (\. [0-9]*) ? ;

Parser:
%left "+" "-";
%left "*" "/"; Expression :
          Expression 'exp1' "+" Expression 'exp2' {exp1 + exp2} | Expression 'exp1' "-" Expression 'exp2' {exp1 - exp2} | Expression 'exp1' "*" Expression 'exp2' {exp1 * exp2} | Expression 'exp1' "/" Expression 'exp2' {exp1 / exp2} | Number 'number' {number};
Number : <number> 'numberToken' {numberToken value asNumber};

 

When I type in, “2+3*4” and hit “Parse and Inspect”, I’m getting 20 instead of 14.

 

Is anybody else getting this behaviour?

 

It would be great too if anybody who tries this can send me their generated classes so I can compare the results.

 

I’m running my Squeak in Windows XP too.

 

Regards,

Zak



Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Re: Precedence in SmaCC

Andrew Tween
Hi,
I get the same problem.
But if I change the parser def slightly (simply insert a cr after %left "*"
"/"; ) to give...

%left "+" "-";
%left "*" "/";
Expression :
          Expression 'exp1' "+" Expression 'exp2' {exp1 + exp2} | Expression
'exp1' "-" Expression 'exp2' {exp1 - exp2} | Expression 'exp1' "*"
Expression 'exp2' {exp1 * exp2} | Expression 'exp1' "/" Expression 'exp2'
{exp1 / exp2} | Number 'number' {number};
Number : <number> 'numberToken' {numberToken value asNumber};

and recompile, then it works as expected, giving 2+3*4 = 14.
Comparing the generated classes for the two parser defs  shows that the only
difference  in the generated code is in TestParser>>#transitionTable

Cheers,
Andy