Re: Decision Tables




"Ben Bacarisse" <ben.usenet@xxxxxxxxx> wrote in message

<snip>

Another way to go about this (when you don't have closures) is to
encode the actions that match into a stack machine. One simple
encoding is as function pointers (invented language):

void match_first_name(rM, cM) { push(rM.FirstName == cM.FirstName); }
void match_last_name(rM, cM) { push(rM.LastName == cM.LastName); }
void match_country(rM, cM) { push(rM.Country == cM.Country); }

void match_and(rM, cM) { push(pop() & pop()); }
void match_or(rM, cM) { push(pop() | pop()); }
void match_not(rM, cM) { push(!pop()); }

Your complex matches then become short NULL terminated arrays for
these:

complex_match[] = { match_contry, match_not, match_first_name,
match_or, NULL };

Very cool. I hadn't thought of using a stack. I'll have to add this to my
bag of tricks. Thanks.


.



Relevant Pages

  • Re: Basic programming Question?
    ... Indeed I am not aware of any programming language that would ... The unnecessary evaluation in all these cases derives, I think, from ... the structure of a simple stack machine, such as is used to interpret ... Henceforth, then, the Party directs that all computers shall ...
    (comp.programming)
  • Re: Script Assembler in C++: What operations should I implement?
    ... >>Many great tips, plus good explanations. ... >>thinking of creating a stack machine. ... > language 'Forth'. ... It is a very simple programming language, ...
    (comp.lang.cpp)
  • Re: Script Assembler in C++: What operations should I implement?
    ... > Many great tips, plus good explanations. ... > thinking of creating a stack machine. ... language 'Forth'. ... It is a very simple programming language, ...
    (comp.lang.cpp)