This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: New C parser [patch]


On Tue, 26 Oct 2004, Kyuupi wrote:

> > Distinguishing whether '(' in an expression starts a parenthesised
> > subexpression, a statement expression or is followed by a type name.
> > (Also after sizeof and alignof.)
> 
> This wasn't necessary in the parser I have written.

It's not strictly necessary if you consume the parenthesis and then have 
functions c_parser_{cast,unary}_expression_after_open_paren or similar.  
But I don't think there's anything intrinsically bad about using 2nd token 
lookahead (given it is needed elsewhere) and my parser doesn't recurse 
everywhere it could simply so as to be more "pure" recursive descent: it 
recurses where pragmatically convenient to make the code clearer or where 
a particular syntax production can occur in more than one place in the 
grammar.  Where more than 2nd token lookahead would be involved in "pure" 
recursive descent, the grammar is simply rearranged locally to avoid the 
problem (as with long sequences of __extension__, all but one discarded 
before deciding whether it is an unary operator or starts a declaration, 
or with sizeof compound-literal, only separable from sizeof ( type ) after 
the ( type ) has been parsed).

> > Distinguishing whether an identifier in an expression is followed by '('
> > and so could be an implicit function declaration.
> 
> I don't believe this is either.

This is rather an incident of the implementation: it could save the 
identifier in a temporary, consume the token and then look at the next 
token to determine the second argument to build_external_ref, but at 
present it uses slightly briefer source without the temporary.  This may 
change in a followup patch to fix bug 8927 by passing the location of the 
identifier to build_external_ref as well as its value.

-- 
Joseph S. Myers               http://www.srcf.ucam.org/~jsm28/gcc/
    jsm@polyomino.org.uk (personal mail)
    joseph@codesourcery.com (CodeSourcery mail)
    jsm28@gcc.gnu.org (Bugzilla assignments and CCs)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]