POV-Ray : Newsgroups : povray.programming : Parsing optional float parameter? Server Time
28 Jul 2024 16:16:08 EDT (-0400)
  Parsing optional float parameter? (Message 1 to 8 of 8)  
From: Warp
Subject: Parsing optional float parameter?
Date: 8 Dec 2000 08:18:46
Message: <3a30dfb5@news.povray.org>
Suppose that I want to make a new function in povray which takes two
integer parameters, the second one being optional, ie you could call it with
either one or two parameters (eg. "thefunction(1)" or "thefunction(1,2)").
  How do I parse this? I just don't get it.

  I have tried something like this to parse the second parameter:

    Parse_Comma();
    EXPECT
      CASE (FLOAT_FUNCT_TOKEN)
        SecondParam = (int)Token.Token_Float;
        EXIT
      END_CASE

      OTHERWISE
        UNGET
        EXIT
      END_CASE
    END_EXPECT

which works if I call it with a number as the second parameter (eg.
"thefunction(1,2)"), but if I call it, for example, with
"thefunction(1,false)", the SecondParam above gets the value '2'.


-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Chris Huff
Subject: Re: Parsing optional float parameter?
Date: 8 Dec 2000 09:16:58
Message: <chrishuff-486751.09174808122000@news.povray.org>
In article <3a30dfb5@news.povray.org>, Warp <war### [at] tagpovrayorg> 
wrote:

Try something like this:

Get_Token();
if(Token.Token_Id == COMMA_TOKEN)
{
    SecondParam = (int)Parse_Float();
}
else
{
    Unget_Token();
}

In other words, peek at the next token to see if it is a comma, in which 
case another parameter has been specified. A more generalized version of 
this could make a nice macro...

-- 
Christopher James Huff
Personal: chr### [at] maccom, http://homepage.mac.com/chrishuff/
TAG: chr### [at] tagpovrayorg, http://tag.povray.org/

<><


Post a reply to this message

From: Ron Parker
Subject: Re: Parsing optional float parameter?
Date: 8 Dec 2000 10:29:02
Message: <slrn931vhv.shn.ron.parker@fwi.com>
On Fri, 08 Dec 2000 09:17:48 -0500, Chris Huff wrote:
>In article <3a30dfb5@news.povray.org>, Warp <war### [at] tagpovrayorg> 
>wrote:
>
>Try something like this:
>
>Get_Token();
>if(Token.Token_Id == COMMA_TOKEN)
>{
>    SecondParam = (int)Parse_Float();
>}
>else
>{
>    Unget_Token();
>}
>
>In other words, peek at the next token to see if it is a comma, in which 
>case another parameter has been specified. A more generalized version of 
>this could make a nice macro...

But that would violate the principle that most commas are optional.

-- 
Ron Parker   http://www2.fwi.com/~parkerr/traces.html
My opinions.  Mine.  Not anyone else's.


Post a reply to this message

From: Warp
Subject: Re: Parsing optional float parameter?
Date: 8 Dec 2000 10:53:51
Message: <3a31040e@news.povray.org>
Chris Huff <chr### [at] maccom> wrote:
:     SecondParam = (int)Parse_Float();

  I'm right now just reading both parameters to get on with my code, but
I have a bad problem with the Parse_Float() function.
  For some reason it always returns 1026048. For both parameters. Always.
No matter what I put in the .pov file.
  Aargh!

  Any idea?

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Chris Huff
Subject: Re: Parsing optional float parameter?
Date: 8 Dec 2000 11:03:50
Message: <chrishuff-8B3694.11043908122000@news.povray.org>
In article <slr### [at] fwicom>, ron### [at] povrayorg 
wrote:

> But that would violate the principle that most commas are optional.

I've never seen anyone write multiple-parameter functions without 
commas...and if I did, I would tell them they forgot a comma. I don't 
think that is a serious problem...but if you really want to do that, you 
can just allow a comma and use the same technique to check the Token_Id 
of the next token to see if it was a float, unget it, and use 
Parse_Float() if it was a float token.

-- 
Christopher James Huff
Personal: chr### [at] maccom, http://homepage.mac.com/chrishuff/
TAG: chr### [at] tagpovrayorg, http://tag.povray.org/

<><


Post a reply to this message

From: Chris Huff
Subject: Re: Parsing optional float parameter?
Date: 8 Dec 2000 11:50:08
Message: <chrishuff-958FB6.11505708122000@news.povray.org>
In article <3a31040e@news.povray.org>, Warp <war### [at] tagpovrayorg> 
wrote:

> I have a bad problem with the Parse_Float() function.
>   For some reason it always returns 1026048. For both parameters. Always.

Always? Just in this patch, or other places as well?
This sounds really odd...maybe you have a stray pointer somewhere, or 
are accidentally modifying the values. Could you post the code?

-- 
Christopher James Huff
Personal: chr### [at] maccom, http://homepage.mac.com/chrishuff/
TAG: chr### [at] tagpovrayorg, http://tag.povray.org/

<><


Post a reply to this message

From: Peter J  Holzer
Subject: Re: Parsing optional float parameter?
Date: 8 Dec 2000 14:02:32
Message: <slrn932a6e.gcq.hjp-usenet@teal.h.hjp.at>
On 8 Dec 2000 10:53:51 -0500, Warp wrote:
>Chris Huff <chr### [at] maccom> wrote:
>:     SecondParam = (int)Parse_Float();
>
>  I'm right now just reading both parameters to get on with my code, but
>I have a bad problem with the Parse_Float() function.
>  For some reason it always returns 1026048. For both parameters. Always.

Did you #include "express.h" in your source file? A Failure to properly
declare a function returning a non-integer often leads to strange
results like this.

The default CFLAGS setting for povray is also a bit conservative on
enabling warnings. If you are using gcc, I recommend adding 

-Wall -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs

at least for your own source files.

	hp

-- 
   _  | Peter J. Holzer    | Es war nicht Gegenstand der Abstimmung zu

| |   | hjp### [at] wsracat      | Zahlen neu festzulegen.
__/   | http://www.hjp.at/ |	-- Johannes Schwenke <jby### [at] ginkode>


Post a reply to this message

From: Warp
Subject: Re: Parsing optional float parameter?
Date: 10 Dec 2000 05:35:02
Message: <3a335c56@news.povray.org>
Peter J. Holzer <hjp### [at] sikituwsracat> wrote:
: Did you #include "express.h" in your source file? A Failure to properly
: declare a function returning a non-integer often leads to strange
: results like this.

  That was exactly the problem (discovered it before reading your post,
though).

: The default CFLAGS setting for povray is also a bit conservative on
: enabling warnings.

  Forgot that gcc doesn't require by default function prototypes...

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

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