jed-users mailing list

[2009 Date Index] [2009 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: bug(?) in black3 and Guido Gonzato's updates


Hello John,

"John E. Davis" <davis@xxxxxxxxxxxxx> wrote:
> Jörg Sommer <joerg@xxxxxxxxxxxx> wrote:
>> Yes, me too. I thought it was the effect of a change anywhere else,
>> because black3.sl doesn't define keyword and keyword1. From which
>> color table these settings are inherited?
>
> These keywords are in the defined in the file:
>
>   # grep keyw black3.sl
>   set_color("keyword", "brightred", $2); % if, while, unsigned, ...
>   set_color("keyword1", "green", $2);    % malloc, exit, etc...

It's a bug (?) in the DFA cache file parser/generator or the DFA cache
misses an upgrade mechanism. The old version wrote this table to the DFA
cache file:

accept 9
130 0 0 0 0 0
120 0 0 0 0 0
113 0 0 0 0 0
105 0 0 0 0 0
101 0 1 22 0 0
98 0 0 8 0 0
91 0 0 8 0 0
60 0 0 9 0 0
44 0 0 29 0 0

while the new version outputs this tables:

accept 9
130 0 0 0 0 0
120 0 0 0 0 0
113 0 0 0 0 0
105 0 0 0 0 0
101 0 1 22 0 0
98 0 0 8 0 0
91 0 0 8 0 0
60 0 0 9 0 0
44 0 0 30 0 0

Both tables (and the whole cache files) differ only in the last line of
the table:

old: 44 0 0 29 0 0
new: 44 0 0 30 0 0

This seams to be related to the new color JHTML_KEY_COLOR. After
rebuilding the cache the color looks fine.

I think you should put a version number in the cache file to reject to
load and then rebuild the cache file, if the syntax or values have
changed.

>> Oh, I've thought the equivalent code is insert_spaces (--goal, goal), but
>> you are the developer of S‐Lang and you are right. Thanks for reviewing
>> these patches.
>
> I think the confusion arises because slang and C differ here.  In C,
> all statements, including assignment statements, produce a value.  For
> example, in C
>
>    x = (foo = bar);
>
> is equivalent to 
>
>    foo = bar;
>    x = bar;
>
> because foo=bar will evaluate to bar. In contrast, in S-Lang 
> x=(foo=bar) will generate a StackUnderflow exception, since foo=bar
> does not produce a value that can be assigned to x.  
>
> This also means that C distingushes between X++ and ++X:
>    
>    X = 1;
>    Y = X++;  ==> Y=1, X=2;
>    
>    X = 1;
>    Y = ++X;  ==> Y = 2, X=2;
>
> However, since X++ does not produce a value in S-Lang, there is no
> difference between X++ and ++X.

But this does not really solve my confusion. The main difference in C
between ++X and X++ is the point of execution of the increment.

Y = X++;

is a shorthand for

Y = X;
X = X + 1;

while

Y = ++X;

is a shorthand for

X = X + 1;
Y = X;

That gives a different value for Y. My confusion was the point of
execution of the increment. If it would happend after the assignment, the
result would be different. But as you explained, the increment always
happens before the assignment, so it's clear that both lines (with
insert_spaces) are equivalent.

But C is a little bit different:

% cat foo.c
#include <stdio.h>

int main(void)
{
    int x = 4, y = 2;

    y = x++, x;
    printf("x=%d, y=%d\n", x, y);
    y = ++x, x;
    printf("x=%d, y=%d\n", x, y);

    return 0;
}
% ./foo
x=5, y=4
x=6, y=6

But I saw putting braces around the expression, like in S‐Lang needed, a
sequence point is inserted and the increment gets executed before the
assignment, i.e.

    y = (x++, x);
    printf("x=%d, y=%d\n", x, y);
    y = (++x, x);
    printf("x=%d, y=%d\n", x, y);

yields to the same result in C and S‐Lang:

% ./foo
x=5, y=5
x=6, y=6

Regrads, Jörg.
-- 
“Programming today is a race between software engineers striving to
build bigger and better idiot—proof programs, and the Universe trying
to produce bigger and better idiots. So far, the Universe is winning.”
(Rich Cook)

--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.


[2009 date index] [2009 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]