bmx-ng / bcc

A next-generation bcc parser for BlitzMax
zlib License
33 stars 12 forks source link

Translator error on some expressions without assigment #613

Open Kerntrick opened 1 year ago

Kerntrick commented 1 year ago

Example:

Local a%, b%
a Shl b

Gives the error:

Parsing...
Semanting...
Compile Error: Internal Error in TTranslator.ExprPri.
Please report the issue, with an example if possible, to https://github.com/bmx-ng/bcc/issues/new

Occurs with Mod, Shl, Shr,

GWRon commented 1 year ago

Parser.bmx (2539ff)

a simple replacement:

Case "=",":*",":/",":+",":-",":&",":|",":~~","mod","shl","shr", ":shl", ":shr", "sar", ":sar", ":mod"
'replaced with
Case "=",":*",":/",":+",":-",":&",":|",":~~", ":shl", ":shr", ":sar", ":mod"

leads then to:

Compile Error: Expecting expression but encountered 'shl'

which looks OK to me.

A potential error message could be the one of this example:

SuperStrict 
1 + 2

Which results in:

Compile Error: Expression cannot be used as a statement.
GWRon commented 1 year ago

While I played with replacing it:

                    '"=","*=","/=","+=","-=","&=","|=","~~=","<<=",">>=","Sar=","%="
                    Case "=",":*",":/",":+",":-",":&",":|",":~~", ":shl", ":shr", ":sar", ":mod"

I saw this one (line 2569ff):

                    If TIdentExpr( expr )

                        expr=New TFuncCallExpr.Create( expr,ParseArgs( True ) )

                    Else If TFuncCallExpr( expr) Or TInvokeSuperExpr( expr ) Or TNewObjectExpr( expr ) Or TNewExpr(expr)

                    Else If TIndexExpr(expr)
                        expr = New TFuncCallExpr.Create( expr, ParseArgs( True ) )
                    Else
                        Err "Expression cannot be used as a statement."
                    EndIf

Isn't that second

                    Else If TIndexExpr(expr)
                        expr = New TFuncCallExpr.Create( expr, ParseArgs( True ) )

never used? Aka ... can be removed.

OR! was the original intentation to check it again (once "expr" got the TFuncCallExpr assigned)?

                    If TIdentExpr( expr )

                        expr=New TFuncCallExpr.Create( expr,ParseArgs( True ) )

                    Else If TFuncCallExpr( expr) Or TInvokeSuperExpr( expr ) Or TNewObjectExpr( expr ) Or TNewExpr(expr)
                    End If

                    If Not TIndexExpr(expr)
                        Err "Expression cannot be used as a statement."
                    EndIf