BASIC Parser
started by: Edward HEdward H
on: 1213826802|%e %b %Y, %H:%M %Z|agohover
number of posts: 13
rss icon RSS: new posts
summary:
Write a program that parses a mathematical expression, like expr(, without using expr(.
Math Parser
Edward HEdward H 1213826802|%e %b %Y, %H:%M %Z|agohover

Edit: okay, I've since decided that the original challenge was perhaps too ambitious a goal for BASIC. I've modified it, slightly.

Using pure TI-BASIC, write the smallest program that parses a mathematical expression stored in Str0, without using expr( or storing strings to functions or tricky things like that. The program needs to handle addition, subtraction, multiplication, division, exponentiation, unary negation, factorials, and parentheses with proper operator precedence and the proper direction for associativity.

Hint.

last edited on 1213903976|%e %b %Y, %H:%M %Z|agohover by Edward H + show more
unfold Math Parser by Edward HEdward H, 1213826802|%e %b %Y, %H:%M %Z|agohover
Re: Math Parser
builderboybuilderboy 1213828579|%e %b %Y, %H:%M %Z|agohover

hmmm, thats going to be tricky…

i'l get back to you on that…

unfold Re: Math Parser by builderboybuilderboy, 1213828579|%e %b %Y, %H:%M %Z|agohover
Re: Math Parser
builderboybuilderboy 1213890907|%e %b %Y, %H:%M %Z|agohover

Alright, i got it!

Input A
Disp A

Just type you equation directly into the prompt!

unfold Re: Math Parser by builderboybuilderboy, 1213890907|%e %b %Y, %H:%M %Z|agohover
Re: Math Parser
Edward HEdward H 1213903707|%e %b %Y, %H:%M %Z|agohover

See, that would qualify under "tricky things like that." Try again ;).

unfold Re: Math Parser by Edward HEdward H, 1213903707|%e %b %Y, %H:%M %Z|agohover
Re: Math Parser
Zaphod BeeblebroxZaphod Beeblebrox 1213928093|%e %b %Y, %H:%M %Z|agohover

Something like this would require expr( to just interpret individual numbers. Otherwise you'd have to write a separate engine just to parse a single number and account for negatives and decimals which would be very possible, but time consuming and useless.

unfold Re: Math Parser by Zaphod BeeblebroxZaphod Beeblebrox, 1213928093|%e %b %Y, %H:%M %Z|agohover
Re: Math Parser
Edward HEdward H 1213929764|%e %b %Y, %H:%M %Z|agohover

I'm not sure how many bytes this is, but it was definitely not time consuming, and is definitely not useless, because I use code like this in my chemical equation balancer to interpret the coefficients efficiently.

Delvar X
inString(Str1+".",".→A
For(I,1,length(Str1
inString("0123456789",sub(Str1,X,1
If Ans
X+(Ans-1)10^(A-I-(A>I→X
End
X(1-2(sub(Str1,1,1)="-
last edited on 1213929821|%e %b %Y, %H:%M %Z|agohover by Edward H + show more
unfold Re: Math Parser by Edward HEdward H, 1213929764|%e %b %Y, %H:%M %Z|agohover
Re: Math Parser
RandomProductionsRandomProductions 1214845604|%e %b %Y, %H:%M %Z|agohover

I call it the Do It Yourself Parser!

:Input "EQUATION?", Str0
:Disp "NOW YOU HAVE TO", "PARSE IT (TYPE", "IT AGAIN)"
:Input "EQUATION?", A
:Disp A

Well, you do put the equation in Str0, and then the equation gets "parsed"…by the user! :P
unfold Re: Math Parser by RandomProductionsRandomProductions, 1214845604|%e %b %Y, %H:%M %Z|agohover
Re: BASIC Parser
builderboybuilderboy 1214843094|%e %b %Y, %H:%M %Z|agohover
Input Str1
Str1→u
Disp u

:D

unfold Re: BASIC Parser by builderboybuilderboy, 1214843094|%e %b %Y, %H:%M %Z|agohover
Re: BASIC Parser
burrburr 1214853221|%e %b %Y, %H:%M %Z|agohover

What's the reason for using a graphing equation variable?

unfold Re: BASIC Parser by burrburr, 1214853221|%e %b %Y, %H:%M %Z|agohover
Re: BASIC Parser
builderboybuilderboy 1214854330|%e %b %Y, %H:%M %Z|agohover

u has the unique property to store strings in number format and are automatically parsed when accessed. Just a way around using exp(

(although, u is different in that if you store "Ans+2" to u, and then access u, it will calculate Ans+2)

unfold Re: BASIC Parser by builderboybuilderboy, 1214854330|%e %b %Y, %H:%M %Z|agohover
Re: BASIC Parser
burrburr 1214857916|%e %b %Y, %H:%M %Z|agohover

That's creative thinking :D

unfold Re: BASIC Parser by burrburr, 1214857916|%e %b %Y, %H:%M %Z|agohover
Re: BASIC Parser
Edward HEdward H 1214887918|%e %b %Y, %H:%M %Z|agohover

Oh, quit that, builderboy!

without using expr( or storing strings to functions or tricky things like that.

Note: you could also store to Y1, or any other function, I believe. If you just type "Y1" without the "(X" part, the calc just parses the function without changing X.

last edited on 1214888104|%e %b %Y, %H:%M %Z|agohover by Edward H + show more
unfold Re: BASIC Parser by Edward HEdward H, 1214887918|%e %b %Y, %H:%M %Z|agohover
Re: BASIC Parser
builderboybuilderboy 1214888567|%e %b %Y, %H:%M %Z|agohover

I'm just pointing out that there are numerous ways to do this already built into the calculator, so its rather pointless to write a program that does it, because the program will almost never be as good or as complete as the pre-built one.

unfold Re: BASIC Parser by builderboybuilderboy, 1214888567|%e %b %Y, %H:%M %Z|agohover
new post
Unless stated otherwise Content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License