I am new to compiler techniques and started to translate the code below to Matlab.
https://github.com/jol-jol/pymatlabparser/blob/master/pymatlabparser/matlab_parser.py
The tokenizer is done, I have started a simple shift/reduce parser. But no rule seems to yield 'expr' without requiring it in its pattern.
Where does this magic happen, by built-in Python functions and types? An idea how to implement it in Matlab?
Thanks sepp2k.
In
@_('NAME', 'NUMBER', 'STRING') # e.g. x, 56, 3e-2, "example"
def expr(self, p):
return (p[0],) # creates a tuple for the token to avoid strings getting concatenated later on
I was missing the def expr part. So expr is not created as a token type, but as a function.