victorlei / smop

Small Matlab to Python compiler
MIT License
1.08k stars 409 forks source link

Lexer crash on `...>=(...)...` #170

Open fenollp opened 3 years ago

fenollp commented 3 years ago
% fcn.m
function [B] = fcn(A)
  B = A>=(A)
end

smop fcn.m

Traceback (most recent call last):
  File "/home/pete/.local/lib/python3.5/site-packages/smop/main.py", line 65, in main
    stmt_list = parse.parse(buf if buf[-1] == '\n' else buf + '\n')
  File "/home/pete/.local/lib/python3.5/site-packages/smop/parse.py", line 850, in parse
    buf, tracking=1, debug=options.debug_parser, lexer=new_lexer)
  File "/home/pete/.local/lib/python3.5/site-packages/ply/yacc.py", line 331, in parse
    return self.parseopt(input, lexer, debug, tracking, tokenfunc)
  File "/home/pete/.local/lib/python3.5/site-packages/ply/yacc.py", line 909, in parseopt
    tok = call_errorfunc(self.errorfunc, errtoken, self)
  File "/home/pete/.local/lib/python3.5/site-packages/ply/yacc.py", line 192, in call_errorfunc
    r = errorfunc(token)
  File "/home/pete/.local/lib/python3.5/site-packages/smop/parse.py", line 838, in p_error
    new_lexer)
  File "/home/pete/.local/lib/python3.5/site-packages/smop/lexer.py", line 338, in raise_exception
    my_lexer.lexdata[startpos:endpos]))
  File "fcn.m", line 2
    B = A>=(A)
           ^
SyntaxError: Unexpected "=" (parser)

Note: crash is flaky. Sometimes compilation passes and generates:

# Generated with SMOP  0.41-beta
from libsmop import *
# fcn.m

@function
def fcn(A=None,*args,**kwargs):
    varargin = fcn.varargin
    nargin = fcn.nargin

    B=A >= (A)
# fcn.m:2
    return B

if __name__ == '__main__':
    pass

Workaround: try compilation multiple times. Looks like it works 1 in 10 times 100% of the times :)

amole-arup commented 3 years ago

Having similar problem. Will try your work-around:

File "dloslab.m", line 179

[r b]= deal(var(1,:)'>=delta*varmax & YL(:,5)~=2, var(1,:)'<=-delta*varmax & YL(:,5)~=2);
SyntaxError: Unexpected "=" (parser)
Errors: 1