Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser error with statement like x ==123 #254

Closed
chaoqing opened this issue May 24, 2022 · 4 comments
Closed

Parser error with statement like x ==123 #254

chaoqing opened this issue May 24, 2022 · 4 comments
Labels
invalid This doesn't seem right

Comments

@chaoqing
Copy link

MISS_HIT Component affected
Please choose one from:

  • Style checker

Your operating system and Python version

  • Linux
  • Python 3.6.9

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
Copy link
Owner

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 florianschanda added the invalid This doesn't seem right label Jun 4, 2022
@florianschanda
Copy link
Owner

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

@chaoqing
Copy link
Author

chaoqing commented Jun 4, 2022

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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants