Giter Club home page Giter Club logo

Comments (3)

jashkenas avatar jashkenas commented on July 3, 2024

Hang on a sec, that is a syntax error, right? Two numbers next to each other, three and negative four. I think it would be strange if it parsed as a subtraction, and it would still be a syntax error if it was caught by the parser, which does understand unary minuses:

(-3 - -x)

Compiles, with negative x as a unary operator caught by the parser. Is there a reason that numbers shouldn't be allowed to be negative while lexing? It's just one less node to compile.

from coffeescript.

liamoc avatar liamoc commented on July 3, 2024

No, it isn't a syntax error. It's valid in JS and C and any other language with a unary minus. The problem is more exacerbated if you write it like this:

(3-4)

The unary minus case should only be exercised if the binary minus has been tried.

So, in formal logic with only numbers, unary minus and binary minus:
Num is all numbers.

x Num
------
x Atom

x Atom
------
-x Atom

x Atom
------
x Expr

x Expr y Expr
-------------
x - y Expr

from coffeescript.

jashkenas avatar jashkenas commented on July 3, 2024

Alright, I'm persuaded. I've removed the optional minus from the lexer, and added a test for your first example. Your cases now compile as expected. Closing the ticket...

from coffeescript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.