Re: Precedence of exponentiation
From: David Frauzel (nemo_at_weathersong.net)
Date: 09/28/04
- Next message: Duke of Hazard: "Defining a string/array with perl characters"
- Previous message: Shawn Corey: "Re: Using "system" command - is it "bad practice" for perl?"
- In reply to: Abigail: "Re: Precedence of exponentiation"
- Next in thread: Anno Siegel: "Re: Precedence of exponentiation"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 28 Sep 2004 00:37:44 GMT
Abigail <abigail@abigail.nl> wrote in
news:slrnclh90j.hv.abigail@alexandra.abigail.nl:
> Which to me suggest that you think Perl should change on how it parses
> things. I haven't seen any poster in this thread agreeing with that.
> I agree that it would have been better if Perl parsed -a ** b as
> (-a) ** b, but I strongly disagree Perl should change on how it parses
> expressions.
I wrapped it up in <rant> to suggest I wasn't being entirely serious. If
anything I've written gives the appearance of advocating Perl5 reform, it
was not my intention. The parser I'm writing isn't even written in Perl
(nor does it use yacc), and that's my primary reason for this topic.
> Perl6 is a different language, which won't happen any time soon. This
> newsgroup discusses real things, not vaporware.
Yikes, sore spot I guess. Won't bring it up again. :p
> Oh, it has happened. Most of the time it was not intentional. People
> go to great lengths to make sure any program that was written for a
> previous version of Perl will still work with a new version.
> Incompatible changes would need a very good justification. And I do
> believe that a dramatic change the way you like to see hasn't happened
> before - at least not since 5.000.
And I recall programming Perl before 5.000. :D
> What preprocessor are you talking about? Perl doesn't have any. And
> don't get confused by the fact that the deparser doesn't emit
> identical code. It deparses 'q{foo}' as 'q[foo]'. Does that mean the
> '{}' is useless?
Oops, I didn't mean to use the word preprocessor. (I'm cross-referencing
my own parser and perly.y / perly.c, and I'm making quite a few
multitasker typos.) I mean the optimization made throughout each compile
pass. (I know, not the same thing as a preprocessor.)
What I meant by "useless" is that "foo" (double-quotes around 'foo') is
not as efficient as 'foo' (single quotes). The compiler's optimization
sequence converts the double-quotes into single-quotes, because there's
nothing to interpolate. I know you know this, and I already said I was
being nit-picky. ;p
> Grammar:
>
> Expression: Term | '-' Expression
> Term: Digits | Term '**' Expression
> Digits: Digit | Digit Digits
> Digit: '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' |
> '9'
And:
"termbinop : term POWOP term",
No, I don't see any special rules. So, I don't think it's Perl's parser I
misunderstand, it's yacc. My idea of a parser with both precedence and
associativity is not the same as what yacc is doing. In the interest of
building a better parser, I'll do some reading on yacc sometime.
> which to me indicates you are argueing that 'a ** -b' should be
> identical to '-(a ** b)' by extracting the unary minus from the middle
> of the expression to the front.
>
> So, once again I ask, do you know any language that does so? Your
> Smalltalk example doesn't do this.
Mine does. It builds a parse tree by starting at the root, and comparing
precedence, until it finds an available node, or detects that a token
somewhere down from the root has less precedence than the current token
in the parser. It's loosely based on a tree sort. The core of the parser
is about 75 lines of Pascal (Delphi). It works identically to Perl with
everything except the exponentiation operator (bug). So I wrote the
lexer, too (a couple hundred lines).
- Next message: Duke of Hazard: "Defining a string/array with perl characters"
- Previous message: Shawn Corey: "Re: Using "system" command - is it "bad practice" for perl?"
- In reply to: Abigail: "Re: Precedence of exponentiation"
- Next in thread: Anno Siegel: "Re: Precedence of exponentiation"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|