Code Monkey home page Code Monkey logo

procalparsing's People

Contributors

bryanchun avatar danvim avatar mcreng avatar

Watchers

 avatar  avatar  avatar

procalparsing's Issues

Hidden Multiplication

Codes

$a$b$c

Error Returned

org.bychan.core.basic.ParsingFailedException: Parsing failed: 'Current token does not support led parsing' @ position 1:6 (index 5), current lexeme is variable($c), previous was variable($b), and remaining are [colon(:), END] at org.bychan.core.basic.ParseResult.checkSuccess(ParseResult.java:83) at org.bychan.core.basic.ParseResult.getRootNode(ParseResult.java:36) at fx50.Main$Run.run(Main.java:120) at fx50.Main.main(Main.java:29) Error: Parsing failed: 'Current token does not support led parsing' @ position 1:6 (index 5), current lexeme is variable($c), previous was variable($b), and remaining are [colon(:), END]

Nested parsing unwanted behavior

What happened

> showParseResult off
Parse result will not be shown.
> ?->$A
A?:?->$B
B?:?->$C
C?:5
C?:4
B?:3
=5

> $A
=5

> $B
=3

> $C
=4

What should have happened

> showParseResult off
Parse result will not be shown.
> ?->$A
A?:?->$B
B?:?->$C
C?:5
=5

> $A
=5

> $B
=5

> $C
=5

What might be the problem

I have absolutely no idea why!

Revamp the whole system by replacing BigDecimal with BigNumber which has a fraction implementation

Possible implementation

public class BigNumber{
    private int numerator;
    private int denominator;
    private BigDecimal decimal = new BigDecimal(numerator/denominator);
    private boolean state; //to be set when being constructed
    //... and whole bunch of other methods
}                        

Possible implementation

class BigNumber extends BigDecimal {
    //all your fraction stuff
    public BigNumber add(BigNumber bigNumber) {/*...*/}
}

Variable Set Display

The following codes work in an actual calculator but no in ours.
$A->$B display
May want to include it for better calc programming.

floor and ceiling

Input

  1. Floor(2)
  2. Ceiling(2)
  3. Ceiling(3.8)
  4. Rnd_Up(3.8)
  5. Rnd_Down(3.8)

Errors

  1. Error: Lexing failed: 'No matching rule' @ position 1:7 (index 6): last lexeme was 'lparen(()', remaining text is '2):'
  2. Error: Lexing failed: 'No matching rule' @ position 1:9 (index 8): last lexeme was 'lparen(()', remaining text is '2):'
  3. Error: Parsing failed: 'Current lexeme does not support nud parsing' @ position 1:1 (index 0), current lexeme is combination(C), previous was null, and remaining are [function(eiling), lparen((), number(3.8), rparen()), colon(:), END]
  4. Error: Lexing failed: 'No matching rule' @ position 1:4 (index 3): last lexeme was 'suffixFunction(Rnd)', remaining text is '_Up(3.8):'
  5. Similar error to above

Add base conversion tokens

Syntax

BIN: <Statement>

Explanation

The output will be printed in that base when a token is detected anywhere.

PowerNode unwanted behavior

What happened

&exp^0 returns 0^0 is undefined.


What should have happened

This should return 1


What might be the problem

Logic error

nCr & nPr

Expressions

  1. 10C2
  2. 10P2

Results

  1. 7.3156608E+10, should be 45
  2. 1.46313216E+11, should be 90

acos() miscalculation

Input

  1. acos(0)
  2. acos(1)
  3. acos(-1)

Output

  1. 1.5, should be more precise, i.e. 1.570796327
  2. Error: Math Error, should be 0
  3. Error: Math Error, should be 3.141592654

I believe other values are fine in acos().

Hidden Multiplication on functions

Codes

  1. 2sin(&pi/2)
  2. 2->$A: &pi/2->$B: $A sin($B) display

Parsing

  1. Error: Parsing failed: 'Current token does not support led parsing' @ position 1:2 (index 1), current lexeme is function(sin), previous was number(2), and remaining are [lparen((), constant(&pi), divide(/), number(2), rparen()), colon(:), END]
  2. 2->$A: &pi/2->$B: ($Asin) * ($B) display

Result

  1. 0, which should have been 2

Add support for input prompt placeholder

This feature is wanted because one might want concise code but descriptive input prompt.

Syntax

?-> $A "descriptive text"
?-> $B

Console output

descriptive text?
B?

Statements

Codes

  1. If 1 Then 1 display IfEnd:
  2. While 1: 1 display WhileEnd:
  3. For 1->$A To 1: 1 display Next:

Returns

  1. Expected : but got IfEnd
  2. Expected : but got WhileEnd
  3. Expected : but got Next

Hidden Multiplication on PowerNode

The program 2^(3) is parsed with error Current lexeme does not support nud parsing' @ position 1:3 (index 2), current lexeme is power(^), previous was multiply(*), and remaining are [lparen((), number(3), rparen()), colon(:), END].

Cannot power negative

What happened

(-1)^(-1) returns an error

java.lang.ArithmeticException: Cannot power negative -1.000000000000000
        at org.nevec.rjm.BigDecimalMath.pow(BigDecimalMath.java:767)
        at fx50.nodes.PowerNode.evaluate(PowerNode.java:20)
        at fx50.nodes.StatementNode.evaluate(StatementNode.java:29)
        at fx50.Main$Run.run(Main.java:118)
        at fx50.Main$Run.run(Main.java:127)
        at fx50.Main$Run.run(Main.java:127)
        at fx50.Main.main(Main.java:29)
Error: Cannot power negative -1.000000000000000

What should have happened

(-1)^(-1) should return -1


What might be the problem

The rjm library.

Revamp Hidden Multiplication: an attempt with nud/led instead of hardcode regex

Illustration of thought:

Each Node can specify whether it supports hidden multiplication or not in an attribute of the class.
Hence checking can be done by finding out whether there is some consecutive nodes both with this attribute.

For example, let say we have a boolean property hiddenMultiplicative

NumberNode.hiddenMultiplicative = true;
VariableNode.hiddenMultiplicative = true;
ConstantNode.hiddenMultiplicative = true;
AdditionNode.hiddenMultiplicative = false;
<NumberNode><VariableNode> // invokes Hidden multiplication
<VariableNode><VariableNode> // self-chain: invokes Hidden multiplication
<NumberNode><NumberNode> // commutative: invokes Hidden multiplication but shall this be banned?
<VariableNode><ConstantNode> // invokes Hidden multiplication
<NumberNode><AdditionNode> // Not invoked

Hidden multiplication does not have a fixed binding power

What happened

Precedence of hidden multiplication is unexpected and not consistent.

1/1$A is parsed as (1/(1*$A))


What should have happened

Hidden multiplication should have the same left binding power

1/1$A should be parsed as ((1/1)*$A)


What might be the problem

Hidden multiplication is implemented as .led()s in some tokens with different binding powers, e.g. constant, variable, function, lparen.

Add support for calling stored programs

Syntax

QuadEquation($A, $B)->$C, $D

Explanation

The system looks for a files called QuadEquation.procal in the same directory and attempt to run it by supplying the input prompts with values of $A and $B then returns the displayed value and final result value, which is set the variables $C and $D.

Single '.'

This is a minor issue but . in calculators should return 0.
Our program returns Error: Lexing failed: 'No matching rule' @ position 1:1 (index 0): last lexeme was <none>, remaining text is '.:'.

Order of Operation

Codes

  1. 5: 2->$A: $A Ans^5

Parsing

  1. 5: 2->$A: ($A*Ans)^5

Results

  1. 1024 //The problem seems to only affect Ans but not other var

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.