World: r3wp
[Parse] Discussion of PARSE dialect
older newer | first last |
Anton 8-Jan-2006 [817] | Ah, recursive rules. :) I pushed my variables onto a stack when recursing, then popped them off when returning. That tends to bloat the code a fair bit. ( push-vars [a b c] recursive-rule pop-vars [a b c] ) so then you get to thinking to generate this code automatically with a make-recursive-rule function, which takes a parse rule, looks for recursion in it, then surrounds it with push-vars and pop-vars for you (kind of macro expansion). Or I did something like that, anyway. |
Ammon 8-Jan-2006 [818] | I would be very interested in seeing this code of yours. I'm planning on going further down the rabit hole of parse than anyone has gone before over the next couple of months. ;-) |
Anton 8-Jan-2006 [819] | http://www.lexicon.net/antonr/rebol/library/make-recursive-rule.r (Mmm.. it says it has a big flaw, but I know I'm using it successfully in a program. Maybe my input never trips the flaw, or I fixed it and forgot to write that down... Anyway, it gives you an idea how the user interface can look.) |
Ammon 8-Jan-2006 [820] | Kewl, thanks! I'll dig right into it. ;-) (I'll be back, Wahahahaha!) |
Anton 8-Jan-2006 [821] | Mmm... I think only the old commented code has the problem. I would have to test that, though... |
Rebolek 12-Jan-2006 [822] | I'm forced to work with regular expressions now and I must say that PARSE is shining sun compared to that terrible black magic called regular expressions. They suck! |
Pekr 12-Jan-2006 [823x2] | :-) |
but they are said being powerfull tool, once you master them of course ... | |
Henrik 12-Jan-2006 [825] | I always hear that if you need to use a UNIX OS, you need to learn them. So far I've done fairly well without them, but have been configuring procmail once, which was a complete nightmare. :-) |
Ladislav 12-Jan-2006 [826] | regular expressions are *very* powerful, as long as you *don't* compare them with Parse :-) |
Henrik 12-Jan-2006 [827] | I've also been confronted with UNIX users who are disappointed that there is no regexp implementation in REBOL. :-) they find it hard to believe that there might be something superior to it |
Sunanda 12-Jan-2006 [828] | It'd be fun to compare parse and REs..... Maybe a shootout between experts in both. Both sides could learn a lot. |
Pekr 12-Jan-2006 [829] | do you think you can do everything allowed in regexp in rebol's parse? |
Sunanda 12-Jan-2006 [830] | No....I suspect they each have core abilities they excel and other things they can only do with ugly workarounds, if at all. It'd be interesting to see experts bringing out the best in both. |
Gregg 12-Jan-2006 [831] | There was some talk about that on the ML a few years back. Joel and Ladislav had some great exchanges IIRC. Parse and RegEx are different tools. I can see the power of RegExs, but they aren't for the faint of heart when you start doing complex things. A RegEx can be very concise, and can be very handy for simple pattern matching. |
Ladislav 13-Jan-2006 [832] | http://www.compkarori.com/vanilla/display/PARSE-Versus-Regexs |
Gregg 13-Jan-2006 [833] | Thanks Ladislav! |
Rebolek 1-Mar-2006 [834] | Is it possible to use "<" ">" and so on in parse rules? (not in string parse). |
Anton 1-Mar-2006 [835x2] | What are you trying to parse ? |
I think the answer is no, but I am not sure of the question yet. Please give an example input. | |
Rebolek 1-Mar-2006 [837x3] | I'm trying to parse something as simple as 1 < 2. |
hm it's possible with any-word! ... | |
but that does not help me very much | |
Anton 1-Mar-2006 [840] | Yes, I'm not having much luck here. |
Rebolek 1-Mar-2006 [841] | Probably it's something like Oldes' comma problem. :/ |
Gabriele 1-Mar-2006 [842] | >> lt: to lit-word! first [ < ] == '< >> parse [1 < 2] [number! lt number!] == true |
Rebolek 1-Mar-2006 [843x3] | great, thanks! |
actually not great, but working :) | |
Unfortunately, there's probably no similar trick that can be used with comma, poor Oldes | |
Volker 1-Mar-2006 [846] | replace/all str "," comma " ; :)) |
Oldes 1-Mar-2006 [847] | you cannot use this in a dialect! |
Volker 1-Mar-2006 [848] | before i load the string! But not too reliable, if you have "," in strings. |
Oldes 1-Mar-2006 [849] | and I'm not such a poor:-) I am using double parenthesis in my dialect instead of using commas (it's ugly, but it's working) |
Volker 1-Mar-2006 [850] | how does some sample code look? |
Oldes 1-Mar-2006 [851x2] | I still think it's a shame, that we cannot load strings with commas, so we cannot forexample parse javascript or actionscript |
my code looks like doSomeFunction(("a" add b) 1) | |
Volker 1-Mar-2006 [853] | i think that is hard to do perfectly. for example "\"", how to parse that? |
Oldes 1-Mar-2006 [854] | in actionscript it's doSomeFunction("a" add b, 1) |
Volker 1-Mar-2006 [855] | doSomeFunction("a" add b # 1) doSomeFunction("a" add b . 1) ? |
Oldes 1-Mar-2006 [856x2] | I know it woud be possible to improve my dialect, but I'm not going to do it in near future, I'm already used to write it this way:) |
I think it's quite logical to close it in parenthesis than using chars like # | |
Volker 1-Mar-2006 [858] | But chars like # are easier to search/replace. But i dont defend my solution, yours looks ok. Do you write your dialect-code in rebol-blocks or in a string? |
Oldes 1-Mar-2006 [859x4] | And for the Rebolek: I use in RSWF this: |
slash: to-lit-word first [/] dslash: to-lit-word "//" rShift: to-lit-word ">>" UrShift: to-lit-word ">>>" _bigger: to-lit-word ">" _less: to-lit-word "<" _noteql: to-lit-word "<>" _lesseql: to-lit-word "<=" _biggeql: to-lit-word ">=" | |
and then: | |
'* (term-op: [ins-act #{0C}]) | slash (term-op: [ins-act #{0D}]) ;Divide | dslash (term-op: [ins-act #{3F}]) ;Modulo | rShift (term-op: [ins-act #{64}]) ;RShift | UrShift (term-op: [ins-act #{65}]);UnsignedRShift | lShift (term-op: [ins-act #{63}]) ;lShift | '| (term-op: [ins-act #{61}]) ;bitwise OR | ['|| | 'or] (term-op: [ins-act #{11}]);OR | ['& | 'band] (term-op: [ins-act #{60}]) ;bitwise AND | 'and (term-op: [ins-act #{10}]) ;AND | |
Rebolek 1-Mar-2006 [863] | Thanks Oldes, that should help me |
Oldes 1-Mar-2006 [864x2] | Volker: blocks |
it's much more easier as you can use Rebol's datatypes | |
Volker 1-Mar-2006 [866] | i thought about something like "js-load string" which would do the comma-conversion. But if your dialect works, no need for extra work. |
older newer | first last |