Hi "Z",

you replied to me in private (unintentionally, I presume), so I'm CCing the
list on my reply (I hope it's OK).
On Monday 25 Apr 2011 12:07:54 z sway wrote:
Hi,sorry I hadn't said it clearly,what I want to do is to generate a LOL
from an expression and try* *not to use any extra modules.
OK, one thing you should realise is that, to quote my late grandfather, Perl
without CPAN is like a cat without whiskers[whiskers]. While it sometimes
makes sense to reduce dependencies[Deps], often many modules on CPAN are self-
contained, or have very few dependencies and you can stick them in one place
and forget about them or pack them in PAR. See:


(Matt S. Trout has an offensive and insulting style, so you have been warned,
but he still says wise things of substance.).

Anyway, you can put one of the parser generators on your system, and I think
byacc-perl generates self-contained Perl code.
So far i've only got an idea that spilt the expression into a list_A,in
which each element is a number or"+*()",use list_B as a stack,pop from
list_A,push to list_B under some rules,finally got the tree in list_B.

I think my method is a bit complicated,there should be a easier one even if
can't detect some mistakes like (5+)2)*5 or 6++7*8
Implementing your own Parse-Recdescent (or worse LALR/GLR/etc.) parser is
prone to errors and inadvisable, especially if you don't have a lot of
theoretical background. Unless this is homework in compilation theory or a
similar course (which most universities don't really do in Perl, for better or
for worse), then please use a parser generator, in case you're interested in
writing your code quickly and correctly, rather than re-inventing your own
square wheel (and trust me - it will be square).

If you *are* interested in learning more about compiler theory and parsing,
then I liked the Dragon book (read the green one I think, but there's already
a newer Purple dragon one which should be better), and while it has some
issues, is pretty good:


There are many other online and offline books, tutorials and resources (on
http://www.wikibooks.org/ / etc.), and you should be good to go. But doing it
without learning it first is not a good idea. To quote
http://en.wikiquote.org/wiki/Euclid , "There is no royal road to geometry",
because sometimes various issues in computer science require learning some
theory to do properly. Note though that parsing theory is not *that* hard.

Sorry for the long post.


Shlomi Fish

[whiskers] - I have only understood this sentence later on when I realised
that cats with damaged whiskers lose their balance, and are very non-


It didn't help that my grandfather said it in Hebrew, using the same word for
"whiskers" as the Hebrew word for "moustache", which is completely inessential
for humans to survive. There is an English idiom called "the Cat's whiskers",
but I think it means more like "the top of the top" or "la creme de la creme".

[Deps] - It is discussed here:


It kinda reminds me of "Can you build a package in one command?" from the
"McConnell test"/"Joel test":


Shlomi Fish http://www.shlomifish.org/
Understand what Open Source is - http://shlom.in/oss-fs

There is no IGLU Cabal! None of them could pass the Turing test. But strangely
enough a computer program they coded, could.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

Search Discussions

Discussion Posts


Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 3 of 12 | next ›
Discussion Overview
groupbeginners @
postedApr 24, '11 at 12:08p
activeMay 1, '11 at 4:32p



site design / logo © 2021 Grokbase