Code Monkey home page Code Monkey logo

antlr4-calculator's People

Contributors

arothuis avatar arothuis-hu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

antlr4-calculator's Issues

Feature: improve on number token

It might be interesting to support floating-point numbers, rather than only integers (1.23).
We could also allow _ as a separator for more legible numbers (i.e. 1_000_000).

This requires adding and changing token names for better disambiguation.

calculator returns incorrect results

I tested your calculator with the inputs below:

Calculate: 1-2
-1.0
Calculate: 1-2*3
-5.0
Calculate: 1-2*3+4
-9.0

This is wrong, 1-2*3+4 = -1.0

Sub operator not work

Start program with 'nl.arothuis.antlr4calculator.ListenerMain' or 'nl.arothuis.antlr4calculator.ListenerMain'
Calculate: 4-2
4.0
Calculate: 4+-2
2.0

This may due to "-" is treated as number, but how to fix it?

Chore: naming to benefit education

Things that would benefit education:

  • the parser package is perhaps a misnomer: it contains behaviors rather than merely parsing (evaluator or translator might be more accurate names)
  • tokens are too specific (and needlessly abbreviated): we're naming our tokens by the actions they belong to (which is semantically too specific), rather than how they look (which is more on the level of tokenization/lexing): CARET, PLUS, MINUS, STAR, SLASH, LEFT_PARENTHESIS, RIGHT_PARENTHESIS
  • remove typos from comments

Questions about how to build locally in Intellij IDEA

Hi,

Sorry to interrupt. Could you help me how to build this project in Intellij IDEA locally?

import nl.arothuis.antlr4calculator.core.parser.CalculatorLexer;
import nl.arothuis.antlr4calculator.core.parser.CalculatorParser;

It suggests that these two classes cannot be imported.

Feature: error handling

Right now, the parser is quite tolerant -- a bit too tolerant, perhaps.

For educational purposes, it might be a better idea to explicitly fail on a parse error and give the user some feedback on what went wrong.

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.