help please?

"Mark Hahn" <[email protected]> Fri, 30 Apr 2004 12:40:40 -0700
Newsgroups gmane.comp.lang.prothon.devel
Message-ID <000c01c42eeb$05623150$0d01a8c0@MarkVaio>
I'm trying to add some features to the parser, and I'm having problems just
as I've always had.  I thought maybe you could answer a question or two.

I want to be able to distinguish between these two cases:

    x = obj$func

and

    x = obj$func()

Here is how I am trying to do it (note last two lines):

obj:
        '$'                                                         { $$ =
ds_to_obj(yylex_param); }
    |   target_param                                                { $$ =
tgtparm_to_obj(yylex_param, $1); }
    |   INT_                                                        { $$ =
int_to_obj(yylex_param, $1); }
    |   LONG_                                                       { $$ =
string_to_obj(yylex_param, $1, NEW_LONG); }
    |   FLOAT_                                                      { $$ =
float_to_obj(yylex_param, $1, NEW_REAL); }
    |   INT_IMAG                                      { $$ =
float_to_obj(yylex_param, (double) $1, NEW_IMAG); }
    |   FLOAT_IMAG                                                  { $$ =
float_to_obj(yylex_param, $1, NEW_IMAG); }
    |   STRING                                                      { $$ =
string_to_obj(yylex_param, $1, NEW_STRN); }
    |   '{' brace_params '}'                                        { $$ =
new_dict(yylex_param, $2); }
    |   '[' list_params ']'                                  { $$ =
new_tuple_list(yylex_param, $2, NEW_LIST_); }
    |   '(' expr ')'                                            { $$ = $2; }
    |   '(' tuple_params ')'                             { $$ =
new_tuple_list(yylex_param, $2, NEW_TUPLE_); }
    |   obj '(' function_params ')'                     { $$ =
obj_func_params(yylex_param, $1, $3); }
    |   attr_ref '(' function_params ')'               { $$ =
self_func_params(yylex_param, $1, $3); }
    |   unbound_ref '(' function_params ')'       { $$ =
unbound_func_params(yylex_param, $1, $3); }
    |   obj '$' LABEL '(' function_params ')'    { $$ =
obj_ds_label_func_params(yylex_param, $1, $3, $5); }
    |   obj '$' LABEL                                     { $$ =
obj_ds_label(yylex_param, $1, $3); }
    ;

The problem is that the last case is always selected.  So obj$func() is
parsed as
    obj -> obj '$' LABEL
    obj -> obj '(' function_params ')'
When this happens I try rearraning line order, adding %prec commands, but
nothing works.  It is as if the parser does not like to "look ahead".  I
must admit that I have not taken the trouble to understand BISON and what it
does or what type of grammer it parses.  So excuse my ignorance (or don't).