POV-Ray : Newsgroups : povray.off-topic : Mini-languages Server Time
4 Sep 2024 09:18:14 EDT (-0400)
  Mini-languages (Message 29 to 38 of 108)  
<<< Previous 10 Messages Goto Latest 10 Messages Next 10 Messages >>>
From: scott
Subject: Re: Mini-languages
Date: 10 Nov 2010 12:55:46
Message: <4cdadca2@news.povray.org>
>> (\+|-)[0-9]+(\.[0-9]+)?(E(\+|-)?[0-9]{1,3})?
>
>   do
>     option (char '+' <|> char '-')
>     many1 digit
>     option (char '.')
>     many1 digit
>     option (do char 'E'; option (char '+' <|> char '-'); many1 digit)

Hmm, now which one is more readable?


Post a reply to this message

From: Darren New
Subject: Re: Mini-languages
Date: 10 Nov 2010 14:25:47
Message: <4cdaf1bb$1@news.povray.org>
Warp wrote:
> Basically you need to write the above twice

I would think at the worst you'd need to write the part before the "E" twice.

-- 
Darren New, San Diego CA, USA (PST)
   Serving Suggestion:
     "Don't serve this any more. It's awful."


Post a reply to this message

From: Darren New
Subject: Re: Mini-languages
Date: 10 Nov 2010 14:28:32
Message: <4cdaf260$1@news.povray.org>
Invisible wrote:
>> OK, so how do you do
>>
>> (\+|-)[0-9]+(\.[0-9]+)?(E(\+|-)?[0-9]{1,3})?
>>
>> in your parser language?
> 
> OK, that's one big ol' complex regex, right there.

That's a pretty simple regex, actually.

>> (That is, optional sign, one or more digits, optional decimal point
>> followed by one or more digits, optional E followed by optional sign
>> followed by one to three digits.)
> 
> If I've understood the spec correctly, it's
> 
>   do
>     option (char '+' <|> char '-')
>     many1 digit
>     option (char '.')
>     many1 digit
>     option (do char 'E'; option (char '+' <|> char '-'); many1 digit)

Bzzzt. Sorry. That requires at least a 2-digit number.

> Enforcing that the exponent is less than or equal to 3 digits would be 
> slightly more wordy. The obvious way is
> 
>   xs <- many1 digit
>   if length xs > 3 then fail else return ()
> 
> Notice that since this is written in a /real/ programming language and 
> not a text string, we can do
> 
>   sign = char '+' <|> char '-'
> 
>   number = do
>     option sign
>     many1 digit
>     option (char '.')
>     many1 digit
>     option (do char 'E'; option sign; many1 digit)
> 
> and save a little typing.

You can do that with many regexp engines too. That's what I meant by 
"trivial macros".

> You can also factor the task into smaller pieces:

Yeah, that's just a text substitution in the regexp expression.

> With a regex, on the other hand, you cannot even statically guarantee 
> that a given string is even a syntactically valid regex. 

Nonsense. How'd you get that?

If you mean you can't use a regexp to parse a regexp, well, yeah, so?

-- 
Darren New, San Diego CA, USA (PST)
   Serving Suggestion:
     "Don't serve this any more. It's awful."


Post a reply to this message

From: nemesis
Subject: Re: Mini-languages
Date: 10 Nov 2010 15:53:32
Message: <4cdb064c$1@news.povray.org>
Invisible escreveu:
>>    Nice straw man.
> 
> Wasn't his problem that he didn't have a brain?
> 
>> (And "foo*bar" still doesn't mean what you think it means
>> as a regex.)
> 
> So, what, it means
> 
>   string "fo"
>   many (char 'o')
>   string "bar"
> 
> Or am I reading this wrong?

* means 0 or more of the previous pattern, in this case, letter 'o'.
+ means 1 or more.

"fobar" is accepted.  The correct pattern should be foo+bar or foo.*bar.

-- 
a game sig: http://tinyurl.com/d3rxz9


Post a reply to this message

From: nemesis
Subject: Re: Mini-languages
Date: 10 Nov 2010 16:04:03
Message: <4cdb08c3@news.povray.org>
Invisible escreveu:
>> OK, so how do you do
>>
>> (\+|-)[0-9]+(\.[0-9]+)?(E(\+|-)?[0-9]{1,3})?
>>
>> in your parser language?
> 
> OK, that's one big ol' complex regex, right there.

I see you never looked at perl code.

>> (That is, optional sign, one or more digits, optional decimal point
>> followed by one or more digits, optional E followed by optional sign
>> followed by one to three digits.)
> 
> If I've understood the spec correctly, it's
> 
>   do
>     option (char '+' <|> char '-')
>     many1 digit
>     option (char '.')
>     many1 digit
>     option (do char 'E'; option (char '+' <|> char '-'); many1 digit)

so, besides the errors, are you satisfied to go the Lisp route and spell 
out all functions rather than rely on specialized, more convenient 
predefined syntax?

do you really believe spelling out "option (char '+' <|> char '-')" is 
any worth as opposed to "(\+|-)"?

> Enforcing that the exponent is less than or equal to 3 digits would be 
> slightly more wordy. The obvious way is
> 
>   xs <- many1 digit
>   if length xs > 3 then fail else return ()

no, sorry.  Truly overkill against "\d{3}".

-- 
a game sig: http://tinyurl.com/d3rxz9


Post a reply to this message

From: Darren New
Subject: Re: Mini-languages
Date: 10 Nov 2010 16:39:07
Message: <4cdb10fb$1@news.povray.org>
Invisible wrote:
>   xs <- many1 digit
>   if length xs > 3 then fail else return ()

By the way, this also means you have backtracking, which means you have 
exponential time and space requirements for your match rather than provably 
linear time and constant space.

-- 
Darren New, San Diego CA, USA (PST)
   Serving Suggestion:
     "Don't serve this any more. It's awful."


Post a reply to this message

From: nemesis
Subject: Re: Mini-languages
Date: 10 Nov 2010 16:49:58
Message: <4cdb1386@news.povray.org>
Orchid XP v8 escreveu:
> killer application for Unix", you don't expect some ugly archaic looking 
> text-only interface...
> 
> Yes, I've used SSH myself. It's quite neat that I can have an old 386 
> laptop sitting in a cupboard somewhere and operate it basically as if I 
> was sitting in front of it. On the other hand, would it be so hard to do 
> so with a less primitive interface?

it's strange that I guy used to programming languages feels awkward 
about a text interface.  Plus, were you ever taught that one shouldn't 
judge a book by its cover?  Notepad in all its glorious graphical user 
interface is much more featureless and rudimentar than vi on an old Unix 
terminal.

There is power in words, they make spells and those magical enchantments 
make things happen in the real world, like dispensing cash at your local 
ATM.

-- 
a game sig: http://tinyurl.com/d3rxz9


Post a reply to this message

From: Darren New
Subject: Re: Mini-languages
Date: 10 Nov 2010 17:07:12
Message: <4cdb1790$1@news.povray.org>
Invisible wrote:
> I've always thought that manpages and the ugliest, lamest, most archaic 
> thing ever, so I don't see that that's much of an advantage.

Oh, wait. Aren't you the one that goes on about LaTeX and Postscript? :-) 
I'm not sure what you have against a text-based program for generating 
typeset output.

> (On the other hand, today's reading suggests that troff is really 
> designed to control phototypesetters - whatever those are - and not 
> produce stuff on screen...)

Plus, they didn't produce stuff on screen. This is hardcopy land. Screens 
were advanced stuff. :-)

-- 
Darren New, San Diego CA, USA (PST)
   Serving Suggestion:
     "Don't serve this any more. It's awful."


Post a reply to this message

From: nemesis
Subject: Re: Mini-languages
Date: 10 Nov 2010 20:35:00
Message: <web.4cdb481595607d658c9d68c40@news.povray.org>
nemesis <nam### [at] gmailcom> wrote:
> Orchid XP v8 escreveu:
> > killer application for Unix", you don't expect some ugly archaic looking
> > text-only interface...
> >
> > Yes, I've used SSH myself. It's quite neat that I can have an old 386
> > laptop sitting in a cupboard somewhere and operate it basically as if I
> > was sitting in front of it. On the other hand, would it be so hard to do
> > so with a less primitive interface?
>
> it's strange that *a* guy used to programming languages feels awkward
> about a text interface.  Plus, were you ever taught that one shouldn't
> judge a book by its cover?  Notepad in all its glorious graphical user
> interface is much more featureless and *rudimentary* than vi on an old Unix
> terminal.
>
> There is power in words, they make spells and those magical enchantments
> make things happen in the real world, like dispensing cash at your local
> ATM.


Post a reply to this message

From: Invisible
Subject: Re: Mini-languages
Date: 11 Nov 2010 04:19:04
Message: <4cdbb508$1@news.povray.org>
>> xs <- many1 digit
>> if length xs > 3 then fail else return ()
>
> By the way, this also means you have backtracking

No it doesn't.

Parsec doesn't backtrack by default; you have to explicitly request it 
(which I haven't).

If there are more than three digits, the above parser fails, and no 
other alternatives are tried (i.e., no backtracking).

(As an aside, there are other Haskell libraries that work similarly to 
Parsec, but where backtracking is the default and turning it off is 
explicit. Apparently this is more intuitive to work with...)


Post a reply to this message

<<< Previous 10 Messages Goto Latest 10 Messages Next 10 Messages >>>

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