parsing expressions (Flash again)
[1/6] from: oliva::david::seznam::cz at: 22-Nov-2001 21:16
parsing expressions (Flash again)
+++++++++++++++++++++++++++++++++
Hi there...
When I was sending my Flash email (sorry that there was no subject:) I didn't wanted
to know, if Flash is better then Rebol. Of course Rebol is better, because you cannot
make Rebol in Flash but you can make Flash from Rebol.... and maybe it will sound strange,
I don'l like the scalable graphic so much, because I prefer pixel accuracy and Flash
is not so much accurate.... and if we are talking about MM, I think that VRML is better
then Flash (unfortunately much more difficult to write and almost nobody has (good) VRML
player), btw. anybody knows how it looks with Mpeg4? LivingWorlds mailing list seems
to be dead. One of the last messages was this more than one year old doc.: http://oldes.multimedia.cz/rur/specifikace/m6353-MU-MPEG-4-Requirements.htm
but never mind...
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
The "flash" question was, how to parse the expressions like:
a: x + random 10
in any dialect... unfortunately there was no reply...
Now I have found that I have problems with 2x3 transformation matrix in Matrix record
so I'm not sure if I'll continue now. I already have what I wanted to...
a) place movies on the main screen at specified positions
c) to be able surf inside the SWF structure (for example to find links to other files)
so if you want to see the code, I will upload it to:
http://sweb.cz/r-mud/swf-lab/
cheers Oldes
[2/6] from: brett:codeconscious at: 23-Nov-2001 13:30
> The "flash" question was, how to parse the expressions like:
>
> a: x + random 10
>
> in any dialect... unfortunately there was no reply...
Oh bother, I'd even thought up a response, but neglected to send it :(
The response is, Gabriele Santilli some time ago posted a script called
expression-evaluator.r.
This fairly small script evaluates expressions and I feel it is similar to
what you want to achieve. Might be worth studying for ideas. I include it
below (I'm guessing it is ok with Gabriele - i hope anyway :) ).
Brett
...
REBOL [
Title: "Expression evaluator"
Author: "Gabriele Santilli <[giesse--writeme--com]>"
Comment: {
Evaluates expressions taking usual operator precedence
into account.
1. (...)
2. - [negation], ! [factorial]
3. ^ [power]
4. *, /
5. +, - [subtraction]
}
]
; A simple iterative implementation; returns 1 for negative
; numbers. FEEL FREE TO IMPROVE THIS!
factorial: func [n [integer!] /local res] [
if n < 2 [return 1]
res: 1
; should avoid doing the loop for i = 1...
repeat i n [res: res * i]
]
expression-parser: make object! [
slash: to-lit-word first [/]
expr-val:
expr-op: none
expression: [
term (expr-val: term-val)
any [
['+ (expr-op: 'add) | '- (expr-op: 'subtract)]
term (expr-val: compose [(expr-op) (expr-val) (term-val)])
]
]
term-val:
term-op: none
term: [
pow (term-val: power-val)
any [
['* (term-op: 'multiply) | slash (term-op: 'divide)]
pow (term-val: compose [(term-op) (term-val) (power-val)])
]
]
power-val: none
pow: [
unary (power-val: unary-val)
opt ['^ unary (power-val: compose [power (power-val) (unary-val)])]
]
unary-val:
pre-uop:
post-uop: none
unary: [
(post-uop: pre-uop: [])
opt ['- (pre-uop: 'negate)]
primary
opt ['! (post-uop: 'factorial)]
(unary-val: compose [(post-uop) (pre-uop) (prim-val)])
]
prim-val: none
; WARNING: uses recursion for parens.
primary: [
set prim-val [number! | word!]
| set prim-val paren! (prim-val: translate to-block :prim-val)
]
translate: func [expr [block!] /local res recursion] [
; to allow recursive calling, we need to preserve our state
recursion: reduce [
:expr-val :expr-op :term-val :term-op :power-val :unary-val
:pre-uop :post-uop :prim-val
]
res: if parse expr expression [expr-val]
set [
expr-val expr-op term-val term-op power-val unary-val
pre-uop post-uop prim-val
] recursion
res
]
set 'eval func [expr [block!] /translate] [
expr: self/translate expr
either translate [expr] [do expr]
]
]
[3/6] from: jasonic:panix at: 22-Nov-2001 21:57
> so if you want to see the code, I will upload it to:
> http://sweb.cz/r-mud/swf-lab/
>
> cheers Oldes
YesWow... Oldes Thank you very much!
I am really looking forwards to exploring this. Please keep us posted of any
developments [including swf examples you make with your toolkit, also any
README/Documentation].
+ happy thanksgiving to you [it's family holiday today in USA]
./Jason
[4/6] from: ljurado:bariloche:ar at: 23-Nov-2001 0:23
>so if you want to see the code, I will upload it to:
>http://sweb.cz/r-mud/swf-lab/
>cheers Oldes
do %swf-kruh.r
** Script Error: action-bin has no value
** Where: compile
** Near: clear action-bin
parse val actions-rules
But replacing:
do %make-swf.r
with:
do %make-swf.r
action-bin: make binary! 1000
FLASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!
Luis
[5/6] from: brett:codeconscious at: 23-Nov-2001 21:32
> Now I have found that I have problems with 2x3 transformation matrix in
Matrix record so I'm not sure if I'll continue now. I already have what I
wanted to...
> a) place movies on the main screen at specified positions
> c) to be able surf inside the SWF structure (for example to find links to
other files)
> so if you want to see the code, I will upload it to:
> http://sweb.cz/r-mud/swf-lab/
>
> cheers Oldes
Great work! Thank you for sharing it.
Btw, roughly how much time did it take to make the swf compiler?
Brett.
[6/6] from: oliva:david:seznam:cz at: 25-Nov-2001 22:54
Re: [REBOL] Re: parsing expressions (Flash again)
>Btw, roughly how much time did it take to make the swf compiler?
>
>Brett.
hmmm... about week for what's already done, but I was playing with decompiling the Flash
files year ago so it's difficult to say how much time it tooks me:-)
I've downloaded the MING (the C opensource) and I'm really lucky, that I can do it in
Flash. It's so difficult to read it in C... and the compiled (win) library for Apache
has >700kB. My script hasn't all tags implemented yet but has 7kB now :-)
It's a shame, that we cannot do:
compress/method "something" 'zlib
It would be really usefull and the code has to be in the Rebol already.
PS: the Flash spec. you can find here:
http://download.macromedia.com/pub/flash/Flash_File_Format_(SWF)_SDK.zip
I've just downloaded it and really hate files generated from M$ office:-(((( I really
don't understand, why must small HTML file have more then 300kB !!!
Oldes