Math-Parser
Tim Holzschuh via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun May 4 07:56:12 PDT 2014
Am 03.05.2014 21:47, schrieb Timon Gehr via Digitalmars-d-learn:
> On 05/03/2014 08:20 PM, Tim Holzschuh via Digitalmars-d-learn wrote:
>>
>>> Let me know if you also want hints on how to get the logic right.
>> Would be very nice!
>> While 2*2 works, 2+2 throws an Error because the number-method gets an
>> END-Token instead of a Number-Token (although I'm not sure why).
>>
>> Thank you,
>> Tim
>
> Get rid of 'revert' and implement the parser in terms of range
> primitives. (The first thing you do in the while loops should be a
> popFront().)
Thank you very much, everything is working now!
I have just a few questions left:
The operator-precedence of the mathematical expressions is implemented
through calling different functions that will parse in the 'mathematical
way'.
I think for more complex 'interpreters' this would be very inconvenient.
So.. how is precedence of operators/keywords and so on handled for more
complex parser? (Or better: What is a way to do it, I think there are
many ways..)
Does anybody have some improvement-suggestions about the code?
For example:
I'm not sure whether the Token-struct is very elegant implemented..
Would in this case a Token-class with a NumberToken subclass be more
appropriate?
Or maybe a union or something other..
Code: https://github.com/tholzschuh/math-parser/
So thanks again!
(and sorry for the bad english)
Tim
More information about the Digitalmars-d-learn
mailing list