POV-Ray : Newsgroups : povray.programming : Parsing a POV-Ray file Server Time
22 Dec 2024 07:37:22 EST (-0500)
  Parsing a POV-Ray file (Message 1 to 9 of 9)  
From: Oodini
Subject: Parsing a POV-Ray file
Date: 18 Sep 2005 13:21:42
Message: <432da226$1@news.povray.org>
Hello,

I programmed a simple 3D renderer in C, and I would like to include a 
parsing functionnality.

I don't know anything about parsing, BNF, flex and other bisons.
I supposed I am not the first one to do this kind of project. Could 
anyone provide me some links to or advices to get some success with this 
project ?

Ideally: I'd like to have:

1 - some theory on BNF
2 - some examples of grammar, possibly with a scene description language
3 - some tutorials with flex or bison

If you have any other material to provide, you're welcome. :-)


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: Parsing a POV-Ray file
Date: 18 Sep 2005 13:43:00
Message: <432da724$1@news.povray.org>
Oodini wrote:
> I programmed a simple 3D renderer in C, and I would like to include a 
> parsing functionnality.

You may want to read 
<http://tag.povray.org/povQandT/filesQandT.html#povtootherformatsdifficulty> 
before you try parsing POV-Ray scene files.

For many other 3d file formats a "real" parser is overkill and something as 
simple as scanf will do.

	Thorsten


Post a reply to this message

From: Darren New
Subject: Re: Parsing a POV-Ray file
Date: 18 Sep 2005 14:31:28
Message: <432db280$1@news.povray.org>
Oodini wrote:
> 1 - some theory on BNF
> 2 - some examples of grammar, possibly with a scene description language
> 3 - some tutorials with flex or bison

http://www.google.com/search?hl=en&q=bnf+tutorial

I've found that the word "tutorial" is a particularly effective way of 
getting high-quality introductory texts on such subjects.

("download" being the other key word that's particular effective.)

-- 
   Darren New / San Diego, CA, USA (PST)
    "Rabbit beer, now with organic hops!"


Post a reply to this message

From: Paul Senzee
Subject: Re: Parsing a POV-Ray file
Date: 17 Jan 2006 21:13:55
Message: <43cda463$1@news.povray.org>
Hi Oodini,

If you're looking to use flex or bison I'd recommend the o'reilly book
'lex/yacc' by John Levine (I think).  However, given pov's grammar it's
actually quite doable (and probably more maintainable) as a top-down hand
written parser.  Given the pov syntax in BNF it's a mostly straightforward
(although laborious) task to translate that into a C top-down parser.

Either way, for moderate to complex parsing tasks, it's best to divide
parsing into two activities:  lexing and parsing.  Lexing is separating your
input stream of characters into 'tokens'.  A 'token' would be one meaningful
symbol from the input stream, such as any keyword, non-character symbol
(such as '{' or '<'), a string literal, a number, etc.  Parsing is combining
those tokens into some other meaningful form, typically a syntax tree.

Paul Senzee

"Oodini" <svd### [at] freefr> wrote in message
news:432da226$1@news.povray.org...
> Hello,
>
> I programmed a simple 3D renderer in C, and I would like to include a
> parsing functionnality.
>
> I don't know anything about parsing, BNF, flex and other bisons.
> I supposed I am not the first one to do this kind of project. Could
> anyone provide me some links to or advices to get some success with this
> project ?
>
> Ideally: I'd like to have:
>
> 1 - some theory on BNF
> 2 - some examples of grammar, possibly with a scene description language
> 3 - some tutorials with flex or bison
>
> If you have any other material to provide, you're welcome. :-)


Post a reply to this message

From: slinky
Subject: Re: Parsing a POV-Ray file
Date: 22 Jan 2007 13:25:01
Message: <web.45b500314ff92f74cb4b8a470@news.povray.org>
I need a parser for *.pov files, which will extract the relevant information
from the script so that it could be displayed/processed/modified by a
project that I am working on. Although it would be quite possible to write
such a thing myself, it would be better to not reinvent the wheel. Does
anyone
know where I could find already existing code to do this? ... or tell me how
povray itself does this? It occurred to me that povray MUST have code to do
this and that I could perhaps reuse their code. However, I been through the
source code several times and I cannot find the code which really parses
the file into useful information. I DID find a file which seemed to be able
to tokenize the script, but after that ... no luck. Thanks for your help.
"Paul Senzee" <pse### [at] yahoocom> wrote:
> Hi Oodini,
>
> If you're looking to use flex or bison I'd recommend the o'reilly book
> 'lex/yacc' by John Levine (I think).  However, given pov's grammar it's
> actually quite doable (and probably more maintainable) as a top-down hand
> written parser.  Given the pov syntax in BNF it's a mostly straightforward
> (although laborious) task to translate that into a C top-down parser.
>
> Either way, for moderate to complex parsing tasks, it's best to divide
> parsing into two activities:  lexing and parsing.  Lexing is separating your
> input stream of characters into 'tokens'.  A 'token' would be one meaningful
> symbol from the input stream, such as any keyword, non-character symbol
> (such as '{' or '<'), a string literal, a number, etc.  Parsing is combining
> those tokens into some other meaningful form, typically a syntax tree.
>
> Paul Senzee
>
> "Oodini" <svd### [at] freefr> wrote in message
> news:432da226$1@news.povray.org...
> > Hello,
> >
> > I programmed a simple 3D renderer in C, and I would like to include a
> > parsing functionnality.
> >
> > I don't know anything about parsing, BNF, flex and other bisons.
> > I supposed I am not the first one to do this kind of project. Could
> > anyone provide me some links to or advices to get some success with this
> > project ?
> >
> > Ideally: I'd like to have:
> >
> > 1 - some theory on BNF
> > 2 - some examples of grammar, possibly with a scene description language
> > 3 - some tutorials with flex or bison
> >
> > If you have any other material to provide, you're welcome. :-)


Post a reply to this message

From: Warp
Subject: Re: Parsing a POV-Ray file
Date: 22 Jan 2007 14:03:42
Message: <45b50a8e@news.povray.org>
slinky <gwj### [at] uiucedu> wrote:
> I could perhaps reuse their code.

  Note that the usage license allows this only if you do it for a personal
project which you will not be distributing to anyone. If you are going to
distribute that program of yours, then you can not directly take code from
the POV-Ray source code to your program.

  If what you want is to simply have any means to convert a .pov file
to another format, one idea which has been floating around for many
years is to make a patch for povray which, after the parsing has finished,
writes the created objects to that other format. (Of course this assumes
that you don't need to *tesselate* the objects, which in itself would be
a next-to-impossible task in the general case.) One more specific idea
which has been floating around is to make a pov-to-moray converter like
this (because moray supports most of the primitives without any need for
tesselation).

  Several attempts have been made to create independent, third-party
parsing libraries for the .pov format. AFAIK none of them have ever
reached a perfect state (ie. can parse and interpret *any* .pov file)
although there exist some good attempts.

-- 
                                                          - Warp


Post a reply to this message

From: slinky
Subject: Re: Parsing a POV-Ray file
Date: 22 Jan 2007 14:30:00
Message: <web.45b50fd34ff92f74cb4b8a470@news.povray.org>
Are there any tools/libraries to use if we don't want to write our own
parser? There seems to be a LOT of interest in having a parser which will
read *.pov
files into C or C++ objects so that the objects can be rendered by something
other than povray. The scene description language just forms a convenient
format. For instance, the source code for POV-ray MUST have code which
parses
*.pov files into 3D data, and materials definitions/etc. I've been looking
through this code with the intent of re-using it to do exactly what you are
talking about. I've found the code that tokenizes the pov file, but not the
code that takes these tokens and assigns spatial information/materials/etc.
Is
there some documentation for povrary which describes how file IO is handled?
"Paul Senzee" <pse### [at] yahoocom> wrote:
> Hi Oodini,
>
> If you're looking to use flex or bison I'd recommend the o'reilly book
> 'lex/yacc' by John Levine (I think).  However, given pov's grammar it's
> actually quite doable (and probably more maintainable) as a top-down hand
> written parser.  Given the pov syntax in BNF it's a mostly straightforward
> (although laborious) task to translate that into a C top-down parser.
>
> Either way, for moderate to complex parsing tasks, it's best to divide
> parsing into two activities:  lexing and parsing.  Lexing is separating your
> input stream of characters into 'tokens'.  A 'token' would be one meaningful
> symbol from the input stream, such as any keyword, non-character symbol
> (such as '{' or '<'), a string literal, a number, etc.  Parsing is combining
> those tokens into some other meaningful form, typically a syntax tree.
>
> Paul Senzee
>
> "Oodini" <svd### [at] freefr> wrote in message
> news:432da226$1@news.povray.org...
> > Hello,
> >
> > I programmed a simple 3D renderer in C, and I would like to include a
> > parsing functionnality.
> >
> > I don't know anything about parsing, BNF, flex and other bisons.
> > I supposed I am not the first one to do this kind of project. Could
> > anyone provide me some links to or advices to get some success with this
> > project ?
> >
> > Ideally: I'd like to have:
> >
> > 1 - some theory on BNF
> > 2 - some examples of grammar, possibly with a scene description language
> > 3 - some tutorials with flex or bison
> >
> > If you have any other material to provide, you're welcome. :-)


Post a reply to this message

From: nomail
Subject: Re: Parsing a POV-Ray file
Date: 22 Jan 2007 15:20:00
Message: <web.45b51b644ff92f74d7330c3b0@news.povray.org>
"slinky" <gwj### [at] uiucedu> wrote:
> Are there any tools/libraries to use if we don't want to write our own
> parser? There seems to be a LOT of interest in having a parser which will
> read *.pov
> files into C or C++ objects so that the objects can be rendered by something
> other than povray. The scene description language just forms a convenient
> format. For instance, the source code for POV-ray MUST have code which
> parses
> *.pov files into 3D data, and materials definitions/etc. I've been looking
> through this code with the intent of re-using it to do exactly what you are
> talking about. I've found the code that tokenizes the pov file, but not the
> code that takes these tokens and assigns spatial information/materials/etc.

If you have not found it, given it is in a file named "parse.cpp", you
should seriously ask yourself if you are up to the task at all...


Post a reply to this message

From: slinky
Subject: Re: Parsing a POV-Ray file
Date: 24 Jan 2007 11:00:01
Message: <web.45b782204ff92f74ceb5817b0@news.povray.org>
"nomail" <nomail@nomail> wrote:
> "slinky" <gwj### [at] uiucedu> wrote:
> > Are there any tools/libraries to use if we don't want to write our own
> > parser? There seems to be a LOT of interest in having a parser which will
> > read *.pov
> > files into C or C++ objects so that the objects can be rendered by something
> > other than povray. The scene description language just forms a convenient
> > format. For instance, the source code for POV-ray MUST have code which
> > parses
> > *.pov files into 3D data, and materials definitions/etc. I've been looking
> > through this code with the intent of re-using it to do exactly what you are
> > talking about. I've found the code that tokenizes the pov file, but not the
> > code that takes these tokens and assigns spatial information/materials/etc.
>
> If you have not found it, given it is in a file named "parse.cpp", you
> should seriously ask yourself if you are up to the task at all...
You are assuming that parse.cpp does what I call "useful". I should have
been more clear about what I wanted.


Post a reply to this message

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