r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Parse] Discussion of PARSE dialect

shadwolf
14-Jan-2011
[5442x2]
either error? :value [
                        value: disarm :value
how do I adapt that ?
BrianH
14-Jan-2011
[5444]
value: disarm :value 
Just get rid of the line.
shadwolf
14-Jan-2011
[5445x2]
ok ...
and this how i use transcode in it ? instead of load/next here ? 
>> error? set/any [value end] try [load/next start]
Steeve
14-Jan-2011
[5447]
Shad, I will do it if you wait a little
shadwolf
14-Jan-2011
[5448x2]
I can do it now either way i need to understand the way R3 handle 
things
since the disarm is gone this like don't work anymore either value/arg2/1
BrianH
14-Jan-2011
[5450]
It depends on the circumstances. Once an error is triggered it can't 
be referred to again until it is caught by TRY, which disarms it.
Oldes
15-Jan-2011
[5451x2]
You don't need disarm in R3:

>> if error? set/any 'err try [1 / 0][ probe err true]
make error! [
    code: 400
    type: 'Math
    id: 'zero-divide
    arg1: none
    arg2: none
    arg3: none
    near: [/ 0]
    where: [/ try]
]
== true
Do we need the set/any or is enough just:
	if error? err: try [1 / 0][ probe err true]
TomBon
15-Feb-2011
[5453x3]
how to copy a parsed stream into a object instead a string var?
this fails
parse page [thru <tag1>  copy obj-buffer/result   to <tag2>]
** Script Error: Invalid argument: obj-buffer/result
ok, looks like this is working.


parse page [thru <tag1>  copy a  to <tag2> (obj-buffer/result : copy 
a)]
Pekr
22-Feb-2011
[5456]
Common parse patterns request - http://www.rebol.com/article/0508.html
james_nak
22-Feb-2011
[5457]
Thanks Pekr for drawing that to my attention.
Gregg
26-Feb-2011
[5458]
If it's a patterns page, it shouldn't be R3 specific. If patterns 
require different implementations in R2 and R3, those can be filled 
in, or stubbed out with a note as to why it is either not needed 
or not worth the effort in one version or the other.
BrianH
26-Feb-2011
[5459x3]
Every pattern should have an R2 and R3 version, with explanations.
Also, every new R3 operation should have an R2 equivalent in the 
pattern list. The parse proposals page can be mined for examples.
IIRC there's only one new R3 op that doesn't have an R2 equivalent, 
but it might not be implemented yet. Let me check.
Gregg
26-Feb-2011
[5462]
I just didn't want to remove the R3-only comments without some discussion, 
in case there was a reason for them being there.
BrianH
26-Feb-2011
[5463]
Yup, agreed. Just checked, LIMIT, the one proposal with no R2 equivalent 
hasn't been implemented yet.
Geocaching
11-Mar-2011
[5464x2]
Hello
Hello, I am struggling to build a parser of equation. The idea is 
a function who would take sth like "SQRT(1-x^2)/(1-x)^3" and return 
a block of rebol code: [divide square-root subtract 1 power x 2 power 
subtract 1 x 3].
Anyone has done it already?
Gregg
11-Mar-2011
[5466]
I know Gabriele has done something along those lines, and I'm sure 
others have as well. I don't know of any that return REBOL code. 
Can you be more specific about what problems you're having?
Ladislav
11-Mar-2011
[5467x2]
Geocachi, see

http://www.fm.tul.cz/~ladislav/rebol/evaluate.r
(can return Rebol code)
Geocaching
13-Mar-2011
[5469]
Thanks ladislav... but I end up with my own implementation...  http://www.rebol.org/view-script.r?script=parse-equation.r
But I will check the your implementation to see how it differs :)
Geocaching
14-Mar-2011
[5470]
Hello, I put a new version of my parse-equation.r script on rebol.org: 
the parser engine is now completed and finalized. I improved the 
recursive implementation to make the code much more readable, understandable 
and elegant. Future improvements should be now limited to adding 
new math functions and a syntax error handling to return usefull 
error messages to the user when she/he makes a syntax error in the 
equation.  http://www.rebol.org/view-script.r?script=parse-equation.r
jocko
14-Mar-2011
[5471]
very nice work !
Geocaching
14-Mar-2011
[5472]
Thanks... just uploaded a new file on rebol.org... I mistakenly put 
a old one :)
sqlab
14-Mar-2011
[5473]
this does not work with signed numbers as in "1 + -2"
Geocaching
14-Mar-2011
[5474x4]
indeed, not yet implemented... in the meantime use "1 - 2" instead
And i am not sure how to implement signed numbers... Usinfg the minus 
sign introduces a level of complexiy I want to avaoid in the code. 
I might decide to force the use of a function like neg()... I am 
still thinking about it...
actually, i found a quite straightforward way to handle signed numbers 
:) i will post later today (for now, I am going to ski... shusss!!!!)
Hello sqlab... Signed numbers and signed sub-expression are now properly 
handled :)
>> parse-equation "+(1+-x)**-sqrt(-1--x)"

== [power add 1.0 negate x negate square-root subtract -1.0 negate 
x]

Thanks for pointing my attention to this issue.

http://www.rebol.org/view-script.r?script=parse-equation.r
Endo
15-Mar-2011
[5478x2]
Very nice script. ^ character can also be added as power operator 
just like **. As in some languages ^ is power operator.
Oh and English comments in the source code please, if possible :)
Ladislav
15-Mar-2011
[5480]
Just a terminological note: the strings you convert to REBOL expressions 
are not "mathematical equations". They are just mathematical expressions.
GrahamC
15-Mar-2011
[5481]
an equation has an = sign in the expression
Ladislav
15-Mar-2011
[5482x3]
BTW, there is an error in associativity:

>> parse-equation "3-3-3"
== [subtract 3.0 subtract 3.0 3.0]
(you need to take into account, that some operations are left-associative, 
while other operations may be right-associative)
The same error here:

>> parse-equation "3-3+3"
== [subtract 3.0 add 3.0 3.0]
MaxV
15-Mar-2011
[5485]
Did you see http://www.rebol.org/view-script.r?script=supercalculator.r&sid=f4jz
(script start in the just last 20 lines)
instead of parse you can use "replace/all" and work evene better
Geocaching
15-Mar-2011
[5486x4]
Ladislav, thanks for your comments... I will have a closer look  
on this associativity issue.
MaxV. Yes, I have seen supercalculator but it crashes on simple expression 
like sqrt(1-3)/(1+4)...
MaxV sorry, my mistake... normal it crashes :)

But when i tried it, it fails on an expression... I do not remember 
which one...
MaxV: supercaclulator fails on 1/-(3+2)
Ladislav
15-Mar-2011
[5490]
regarding the supercalculator - it has wrong associativity as well
Geocaching
15-Mar-2011
[5491]
like parse-equation.r did yesterday btw :)