question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Correct parsing of chains of < and <=

See original GitHub issue

Parsing a chain of comparison operators, such as 1 <= x < 10 is a quite natural thing for humans to do. However, how to best represent this doesn’t seem quite as clear cut to me. Which of the <= and < signs comes first? Or should we somehow encode that they’re at the same level? Or…?

For the record, this is what the compute-engine currently does. It’s a bit inconsistent.

image

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
arnogcommented, Feb 4, 2022

Yes, that could work as well.

BTW, ["Less"] is a valid MathJSON expression: it’s the partial application of the Less function to no arguments (["Less", 0] is the partial application of the Less function)

0reactions
stefnotchcommented, Feb 4, 2022

I realized that Mathematica has the same problem. So clearly, it would make sense to check what they’re doing.

The following piece of code

SetAttributes[fullFormString, HoldAll];
fullFormString[expr_] := ToString[Unevaluated @ FullForm[expr]]
fullFormString[1<x<=k]

(Source: https://mathematica.stackexchange.com/a/152438 )

returns

Inequality[1, Less, x, LessEqual, k]

Which seems like a rather reasonable way of doing it in the compute engine. I guess functions would have to be wrapped in brackets or something, so that they can be distinguished from variables. ["Inequality", 1, ["Less"], "x", ["LessEqual"], "k"]

And here is their relevant documentation https://reference.wolfram.com/language/ref/FullForm.html and https://reference.wolfram.com/language/ref/TreeForm.html

Read more comments on GitHub >

github_iconTop Results From Across the Web

Right way to parse chain of various binary functions with ...
there is no standard way to implement "importance" of an operation: for example a + b = b + a should be parsed...
Read more >
A Guide To Parsing: Algorithms And Terminology
A complete parser is usually composed of two parts: a lexer, also known as scanner or tokenizer, and the proper parser. The parser...
Read more >
Constituency Parsing - Stanford University
CKY with neural methods to choose a single correct parse by syntactic disambigua- ... B by a chain of one or more unit...
Read more >
Parsing: a timeline -- V3.1 - GitHub Pages
Recursive descent, without help, cannot parse RIGHT-OP. As of 1961, parsing theory has not developed well enough to state why in a precise...
Read more >
Parsing and PCFGs - Brown CS
Most importantly, there is no agreement on the correct grammar even for a well-studied language like English. For example, what's the structure ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found