POV-Ray : Newsgroups : povray.pov4.discussion.general : Parse Strings Server Time
27 Apr 2024 09:08:20 EDT (-0400)
  Parse Strings (Message 1 to 10 of 18)  
Goto Latest 10 Messages Next 8 Messages >>>
From: Chambers
Subject: Parse Strings
Date: 21 Oct 2007 18:30:01
Message: <web.471bd1d97f0ae97fbb646420@news.povray.org>
Can we please parse strings?

As in, without having to write it to a temporary file and then include that
file?

The syntax would be straightforward:

#parse( <text string or string id> )


Post a reply to this message

From: Warp
Subject: Re: Parse Strings
Date: 21 Oct 2007 20:04:15
Message: <471be8ff@news.povray.org>
Chambers <bdc### [at] yahoocom> wrote:
> Can we please parse strings?

  With the current parser the answer is basically no. Too difficult to
implement.

  With a redesigned-from-scratch SDL and parser it should be rather trivial
(although byte-compiling and JIT-compiling could present their own quirks,
but other languages such as PHP manage to do it, so it's definitely possible).

> The syntax would be straightforward:

> #parse( <text string or string id> )

  Functions in the current SDL don't start with a #.

-- 
                                                          - Warp


Post a reply to this message

From: Tim Attwood
Subject: Re: Parse Strings
Date: 23 Oct 2007 19:09:20
Message: <471e7f20$1@news.povray.org>
>> Can we please parse strings?
>
>  With the current parser the answer is basically no. Too difficult to
> implement.
>
>  With a redesigned-from-scratch SDL and parser it should be rather trivial
> (although byte-compiling and JIT-compiling could present their own quirks,
> but other languages such as PHP manage to do it, so it's definitely 
> possible).
>
>> The syntax would be straightforward:
>
>> #parse( <text string or string id> )
>
>  Functions in the current SDL don't start with a #.

Yeah, IMO it'd be OK to continue suporting the "#command parameter"
syntax for 4.0 scripting control structures. A #parse command probably
wouldn't have parens, just quote delimited strings, string identifiers, or
functions returning a string (like concat).


Post a reply to this message

From: Warp
Subject: Re: Parse Strings
Date: 23 Oct 2007 19:44:03
Message: <471e8743@news.povray.org>
Tim Attwood <tim### [at] comcastnet> wrote:
> Yeah, IMO it'd be OK to continue suporting the "#command parameter"
> syntax for 4.0 scripting control structures. A #parse command probably
> wouldn't have parens, just quote delimited strings, string identifiers, or
> functions returning a string (like concat).

  The main problem with parsing a string as SDL is not a syntactical one,
but related to implementation, especially if and when the new SDL will be
byte/JIT-compiled.

  There's a reason why eg. C++ and Java don't support parsing strings and
interpreting them as C++ or Java. Even many interpreted scripting languages
don't have any parse function because it may not be quite trivial to
implement in them. The current SDL is a good example of this.

  I don't know too much about scripting language interpreters and compilers,
but I can easily imagine a string parsing function being a nightmare to
implement properly. For example, a string could define a new function which
must then be callable from outside the string. This means that you are
creating new functions on the fly, during execution and can't create the
interpreter/compiler so that it just creates a static set of functions.
The string might define new types which should then be usable from the
outside, so the interpreter/compiler must somehow dynamically create
information about new types during runtime, as they are created. This
can easily make the interpreter/compiler much more complex than it would
otherwise be.

  Of course it also means that the byte-compiler and the bytecode interpreter
cannot be independent and separated, but must be married together, as the
bytecode interpreter may need to call the byte-compiler. This effecively
makes it impossible to make a virtual machine which only interprets bytecode,
without a compiler.

  Of course I'm not saying this is impossible. As far as I know, for example
PHP byte-compiles the program before interpreting it, *and* it also has an
eval() function, which effectively parses a given string as PHP code. So it's
definitely possible. Just not trivial.

-- 
                                                          - Warp


Post a reply to this message

From: Chambers
Subject: Re: Parse Strings
Date: 24 Oct 2007 11:55:01
Message: <web.471f69c87a948168261d9700@news.povray.org>
Warp <war### [at] tagpovrayorg> wrote:
> Chambers <bdc### [at] yahoocom> wrote:
> > Can we please parse strings?
>
>   With the current parser the answer is basically no. Too difficult to
> implement.

It's a good thing that we're not discussing the current parser, then :)

Anyway, my request isn't based on how easy or hard it would be to implement,
but rather on how useful it would be to me.  In the past year, I've run
across more and more situations where I would want this.


Post a reply to this message

From: Warp
Subject: Re: Parse Strings
Date: 24 Oct 2007 13:23:20
Message: <471f7f88@news.povray.org>
Chambers <bdc### [at] yahoocom> wrote:
> Anyway, my request isn't based on how easy or hard it would be to implement,
> but rather on how useful it would be to me.  In the past year, I've run
> across more and more situations where I would want this.

  It would certainly be a handy feature, but will most probably make the
interpreter/compiler more complicated than without it...

-- 
                                                          - Warp


Post a reply to this message

From: Nicolas Alvarez
Subject: Re: Parse Strings
Date: 24 Oct 2007 17:14:29
Message: <471fb5b5$1@news.povray.org>

> Warp <war### [at] tagpovrayorg> wrote:
>> Chambers <bdc### [at] yahoocom> wrote:
>>> Can we please parse strings?
>>   With the current parser the answer is basically no. Too difficult to
>> implement.
> 
> It's a good thing that we're not discussing the current parser, then :)
> 
> Anyway, my request isn't based on how easy or hard it would be to implement,
> but rather on how useful it would be to me.  In the past year, I've run
> across more and more situations where I would want this.
> 
> 

Name some. Maybe we don't need an eval()-like function, what we need is 
other features so that we never ever need to use eval.


Post a reply to this message

From: Fa3ien
Subject: Re: Parse Strings
Date: 25 Oct 2007 06:45:11
Message: <472073b7$1@news.povray.org>


>   There's a reason why eg. C++ and Java don't support parsing strings and
> interpreting them as C++ or Java. Even many interpreted scripting languages
> don't have any parse function because it may not be quite trivial to
> implement in them. The current SDL is a good example of this.

The main problem with the current method of using an include file is speed.
If it could be done using a virtual file stored in RAM, there could be
a huge gain in speed without fundamentally changing the method.

(Is my memory weakening, or do I correctly remember that, at some point,
  there was a patch, MegaPOV or another, which actually allowed to parse
  a string ?)

Fabien.


Post a reply to this message

From: Charles C
Subject: Re: Parse Strings
Date: 25 Oct 2007 14:25:59
Message: <4720dfb7@news.povray.org>
Nicolas Alvarez wrote:

>> Anyway, my request isn't based on how easy or hard it would be to 
>> implement,
>> but rather on how useful it would be to me.  In the past year, I've run
>> across more and more situations where I would want this.
>>
>>
> 
> Name some. Maybe we don't need an eval()-like function, what we need is 
> other features so that we never ever need to use eval.

In my case I was using POV-Ray as a graphing calculator and wanted the 
resultant image to show both the text and graphic form of the function. 
   I wanted to only have to enter a function in SDL once, so I used a 
string, and figured out the include-file-method as a workaround to 
convert that string to something plot-able.  I asked on the newsgroups 
if there was a better way... wishing.
Charles


Post a reply to this message

From: Nicolas Alvarez
Subject: Re: Parse Strings
Date: 25 Oct 2007 14:53:46
Message: <4720e63a@news.povray.org>

> Nicolas Alvarez wrote:
>>
>> Name some. Maybe we don't need an eval()-like function, what we need 
>> is other features so that we never ever need to use eval.
> 
> In my case I was using POV-Ray as a graphing calculator and wanted the 
> resultant image to show both the text and graphic form of the function. 
>   I wanted to only have to enter a function in SDL once, so I used a 
> string, and figured out the include-file-method as a workaround to 
> convert that string to something plot-able.  I asked on the newsgroups 
> if there was a better way... wishing.
> Charles


#declare F = function { x*2 };
#declare Ftext = f.toString(); // <-- that's probably the feature you need

Or a way to convert a string to a function; note that's still not an 
eval(), as it would be limited to only mathematical expressions.


Post a reply to this message

Goto Latest 10 Messages Next 8 Messages >>>

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.