Front page | perl.recdescent |
Postings from September 2009
Deferred interpretation?
Thread Next
From:
Mike Diehl
Date:
September 3, 2009 14:24
Subject:
Deferred interpretation?
Message ID:
200909031525.29566.mdiehl@diehlnet.com
Hi all,
I've got another problem and I'm hoping someone can point me in the right
direction.
My grammar is for a "language" that includes an "if" type command. The "if"
command takes an expression, and two other commands. Depending on the values
of the expression, ONE of the commands is supposed to be executed. However,
what I'm seeing is that BOTH commands are being evaluated, but the results of
only one of the commands is being used.
Here is a snippet of the grammar:
===================================================================
if: "[#if(" boolean_expression "," command "," command ")]"
{
if ($item[2] eq "true") {
$return = $item[4];
} else {
$return = $item[6];
}
}
command: variable | include | word | quoted_string
{
$return = $item[1];
}
include: "[#include(" file_path ")]"
{
$return = main::parse_page($item[2]);
}
...
===================================================================
So, in the case where we have a true expression, both commands are being
evaluated, but only the results of one of the commands is returned. The
problem is that, as in the case of an "include" command, the commands might
have side-affects.
I'm sure this is a common design pattern. Perhaps there is an "easy" way to
deal with this?
--
Take care and have fun,
Mike Diehl.
Thread Next
-
Deferred interpretation?
by Mike Diehl