florianschanda / miss_hit

MATLAB Independent, Small & Safe, High Integrity Tools - code formatter and more
GNU General Public License v3.0
158 stars 21 forks source link

Parser error with statement like `x ==123` #254

Closed chaoqing closed 2 years ago

chaoqing commented 2 years ago

MISS_HIT Component affected Please choose one from:

Your operating system and Python version

Describe the bug Run ./mh_debug_parser --tree bug.m with following Matlab script

x == 123;  % blank before 123
x ==123;   % no blank before 123

It is clear the parser give incorrect tree for second statement:

Root: Script_File
  Statements: Sequence_Of_Statements
    Statements: Naked_Expression_Statement
      Expression: Binary_Operation ==
        LHS: Identifier <x>
        RHS: Number_Literal <123>
    Statements: Naked_Expression_Statement
      Expression: Command form Function_Call
        Name: Identifier <x>
        Arguments: Char_Array_Literal '==123'
florianschanda commented 2 years ago

Welcome to the club of finding fun things with MATLAB.

It is actually correct as is. Please also see https://www.mathworks.com/help/matlab/matlab_prog/command-vs-function-syntax.html

I consider this to be a bug in the MATLAB language :D

florianschanda commented 2 years ago

Other hilarious features can be found here: https://github.com/florianschanda/miss_hit/blob/master/LEXING_ISSUES.md

chaoqing commented 2 years ago

Thanks for the explanation, according to the document you mentioned. It seems the lexing result of x ==123 depends on the semantical analysis result of x. When x is variable but not function, Matlab should not tigger command syntax.

It seems this is again related to #246 which seems very hard to fix for now, or nearly impossible when just do static analysis without Matlab Runtime.

florianschanda commented 2 years ago

Right, without semantic analysis there is no error here. Otherwise you'd get one because first you assign to x, then you try to call it.

It's still on the roadmap for me to do semantic analysis, I just am crazy busy with other real life things so things have been a bit slow on MISS_HIT lately.