[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Tutorial or Article
From: |
Chris verBurg |
Subject: |
Re: Tutorial or Article |
Date: |
Wed, 2 Mar 2016 23:29:16 -0800 |
Hey Stephen,
I don't know that we see enough of your code to say for sure what's going
on, but my limited guess is that if "if_group" is your top-level pattern,
then it'll never understand ELSE because else_group is not referenced
anywhere downstream of if_group. If so, what about having the elements of
if_group reference the optional ELIFs and ELSE that follow, e.g.:
if_group: NUMBER_SIGN KEYWORD_IF constant_expression NEW_LINE group
optional_elses | ... ;
optional_elses:
| else_group
| elif_groups optional_elses
;
(I'm presuming 'group' means non-preprocessor code so it has to be
preserved.)
-Chris
On Wed, Mar 2, 2016 at 9:39 AM, Tathams <address@hidden> wrote:
> Can anyone suggest something for me to read to learn and understand look
> ahead
> and fall back.
>
> I am have trouble writing a partial C pre-processor and wish to create a
> few
> non-terminals to handle the many different #xxxx things that can occur in
> header files.
>
> So if I have a non-terminal to handle #if or #ifdef then another to handle
> #elif and a final to handle #else like so
>
> /* ISO/IEC 9899:201x (6.10) */
> if_group
> : NUMBER_SIGN KEYWORD_IF constant_expression NEW_LINE group
> | NUMBER_SIGN KEYWORD_IF constant_expression NEW_LINE
> | NUMBER_SIGN KEYWORD_IFDEF IDENTIFIER NEW_LINE group
> | NUMBER_SIGN KEYWORD_IFDEF IDENTIFIER NEW_LINE
> | NUMBER_SIGN KEYWORD_IFNDEF IDENTIFIER NEW_LINE group
> | NUMBER_SIGN KEYWORD_IFNDEF IDENTIFIER NEW_LINE
> ;
>
> /* ISO/IEC 9899:201x (6.10) */
> elif_groups
> : elif_group
> | elif_groups elif_group
> ;
>
> /* ISO/IEC 9899:201x (6.10) */
> elif_group
> : NUMBER_SIGN KEYWORD_ELIF constant_expression NEW_LINE group
> | NUMBER_SIGN KEYWORD_ELIF constant_expression NEW_LINE
> ;
>
> /* ISO/IEC 9899:201x (6.10) */
> else_group
> : NUMBER_SIGN KEYWORD_ELSE NEW_LINE group
> | NUMBER_SIGN KEYWORD_ELSE NEW_LINE
> ;
>
> How do I not fail when the NUMBER_SIGN finds an ELSE rather than a IF.
>
> Regards
> Stephen
>
>
>
> ____________________________________________________________
> South Africas premier free email service - www.webmail.co.za
>
> _______________________________________________
> address@hidden https://lists.gnu.org/mailman/listinfo/help-bison
>