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 can't differentiate between ReplaceAll and Division (Times [ , Power]) #989

Closed
weakit opened this issue Oct 22, 2020 · 3 comments · Fixed by #991
Closed

Parser can't differentiate between ReplaceAll and Division (Times [ , Power]) #989

weakit opened this issue Oct 22, 2020 · 3 comments · Fixed by #991
Labels

Comments

@weakit
Copy link
Contributor

weakit commented Oct 22, 2020

Take a look at this example.

Mathics:

In[1]:= 1/.2
ReplaceAll::reps: 2 is not a valid replacement rule.
Out[1]= 1 /. 2

Wolfram:

image
image

Not really a big problem, but is something that needs to be fixed eventually.

@mmatera
Copy link
Contributor

mmatera commented Oct 25, 2020

I have tracked this issue to the tokenizer (mathics/mathics/core/parser/tokenizer.py):

in line 125:
('ReplaceAll', r' \/\. '),
defines the rule for ReplaceAll, that is tested before
('Divide', r' \/|\u00f7 '),
in the method next of the Tokenizer class:
if indices: for index in indices: tag, pattern = self.tokens[index] match = pattern.match(self.code, self.pos) if match is not None: break
I tryed to fix this changing ('ReplaceAll', r' /. '),
by ('ReplaceAll', r' /.![0-9] '),

but for some reason, this produces a failure on the "contribute" routine in the mathics.builtin module. If someone can help me in defining a more sensible regular expression, I am trying to fix this in the branch https://github.com/mathics/Mathics/tree/fix-tokenized

@rocky
Copy link
Member

rocky commented Oct 25, 2020

It might just be a simple lexing issue, and adjusting your regexp to lookahead and then backup, but...

Robert Jacobson's FoxySheep parser has the same problem. And although in spirit it is the same, it works very differently.

Is it really just ReplaceAll or are there other functions?

From what I understand about the scanner and parser, I would not attempt to fix this without understanding more about how this all works and the subtleties.

Getting more pure parsing tests in place and a framework for adding test case bugs like this would be useful first too.

To get some idea as to the subtleties involved and how this works see this or the the readme in the FoxySheep repostiory.

@mmatera
Copy link
Contributor

mmatera commented Oct 25, 2020

Thanks Rocky, I was aware of that. This was a headake for implementing the Information operator ??. My problem this time was more basic: I was writting wrong the regular expression. I think now it will work...

This was referenced Oct 26, 2020
@GarkGarcia GarkGarcia added the bug label Oct 26, 2020
mmatera added a commit that referenced this issue Oct 26, 2020
@rocky rocky changed the title Parser can't differentiate between ReplaceAll and Division Parser can't differentiate between ReplaceAll and Division (Times [ , Power]) Oct 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants