delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/06/28/15:54:53

From: "Christopher Nelson" <paradox AT gye DOT satnet DOT net>
To: <djgpp AT delorie DOT com>
Subject: Re: Bison and particular expressions.
Date: Sun, 27 Jun 1999 15:05:08 -0600
Message-ID: <01bec0e0$bcf60680$LocalHost@thendren>
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 4.71.1712.3
X-MimeOLE: Produced By Microsoft MimeOLE V4.71.1712.3
Reply-To: djgpp AT delorie DOT com

>
>    The problem with this, is "item" is different in different contexts.
This
>would work fine for parameter lists, but I need to compensate for variable
>declarations in the form "int a,b,c,*d, **&e;" as well.  I've been able to
>solve my problem with some excelent help provided by Doug Eleveld.  It had
to
>do with combining the "item" and the "," into one item to allow bison to
use a
>look-ahead token to resolve some conflicts.

item can be resolved to be any number of smaller tokens.  for example, item
could be a nonterminal that can match 'a', '*a', '**a', or '**&a'.  i find
that using the most general definition possible, until you get to a terminal
is usually the most efficient and easiest method to use.

it's good that you fixed the problem. :-)

>> in addition, it is partially a lexical problem.  c is a very complex
>> language to parse specifically because of typedef's and some special-case
>> problems.  one part of what you should do is have the lexical-analyzer
>> understand id contexts.  that way you can write the recursive list like
>> this:
>
>[snip]
>
>I've think I got typedef's working, as well as structs and simple classes
>(without methods) without lexical tie-ins.  Besides, scope stuff can be
done to
>make lexical tie-ins tricky [like]:
>struct a {int a;};
>
>int j()
>{int m,a;
>}


    This is precisely what i refered to.  That's why C also has the
most-closely nested rule.  Your parser should maintain context information
about what block is the current one, and the symbol table should maintain
scope information about where the variable was declared.  If your symbol
table knows where you are, and also knows where a variable was declared, it
can then easily resolve the above example.  For example, compile the above
example in gcc, and use the shadow parameter warning and you'll see what I
mean.

    -={C}=-

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019