in reply to parens question
This is one reason why some languages use THEN with IF statements. As soon as the parser looks ahead one token and sees THEN, it knows that it's done parsing the IF condition. In Perl, the parenthesis serve the same function. When the parser looks ahead one token and sees ')' (having already accounted for nested parenthesis), it knows it has the condition parsed.
Consider a silly (and probably incorrect) example:
If the parser, having recognized that it's dealing with an IF statement and is parsing the condition, is looking ahead at the single token '$b', how can it tell whether it has finished parsing the condition and is now looking at the following statement? The answer is, it can't.if $a == undef $b = 1; ^
Parsers are fun. Playing with one for a while can give one a much deeper appreciation for language design.
(And now someone who really knows the Perl parser will tell my why I'm full of it. ;-)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(tye)Re: parens question
by tye (Sage) on Jan 28, 2001 at 04:58 UTC |