Sujet : Re: help with a logic algorithm
De : anton.txt (at) *nospam* gmail.moc (Anton Shepelev)
Groupes : comp.lang.cDate : 07. Apr 2024, 01:58:46
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240407035846.47c1134be4066f90106de1fc@gmail.moc>
References : 1 2 3
User-Agent : Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
Thiago Adams:
the algorithm is be used in flow analysis of C code. I
realized my previous approach will not work because I also
need intermediate result.
>
for instance
>
if (p && p->i) {}
>
I need to know p is not-null after && , I cannot wait
until the end of expression. The algorithm must propagate
the results. I am thinking on alternatives..
Then your original idea of analysing the expression tree is
good: the algorithm will be linear for conjunction and
negation, but will branch over disjunction. The short-
circuit evaluation may be accounted for by, eg., stroring
the known invariants with each node. For (a || b) you will
have:
OR
a
b [a is false]
yielding two branches: 1) a and 2) !a && b .
I do believe that waiting for the end of the expression
involves the chronology encoded in the expression tree.
-- () ascii ribbon campaign -- against html e-mail/\ www.asciiribbon.org -- against proprietary attachments