Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7811695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:15:48+00:00 2026-06-02T04:15:48+00:00

Is there a way to specify that a Bison rule should NOT match if

  • 0

Is there a way to specify that a Bison rule should NOT match if the lookahead token is a given value?

I currently have the following Bison grammar (simplified):

var_decl:
        type ident
        {
            $$ = new NVariableDeclaration(*$1, *$2);
        } |
        type ident ASSIGN_EQUAL expr
        {
            $$ = new NVariableDeclaration(*$1, *$2, $4);
        } |
        type CURVED_OPEN STAR ident CURVED_CLOSE CURVED_OPEN func_decl_args CURVED_CLOSE
        {
            $$ = new NVariableDeclaration(*(new NFunctionPointerType(*$1, *$7)) /* TODO: free this memory */, *$4);
        } |
        type CURVED_OPEN STAR ident CURVED_CLOSE CURVED_OPEN func_decl_args CURVED_CLOSE ASSIGN_EQUAL expr
        {
            $$ = new NVariableDeclaration(*(new NFunctionPointerType(*$1, *$7)) /* TODO: free this memory */, *$4, $10);
        } ;

...

deref:
        STAR ident
        {
            $$ = new NDereferenceOperator(*$<ident>2);
        } |

...

type:
        ident
        {
            $$ = new NType($<type>1->name, 0, false);
            delete $1;
        } |
        ... ;

...

expr:
        deref
        {
            $$ = $1;
        } |
        ...
        ident
        {
            $<ident>$ = $1;
        } |
        ...
        ident CURVED_OPEN call_args CURVED_CLOSE
        {
            $$ = new NMethodCall(*$1, *$3);
            delete $3;
        } |
        ...
        CURVED_OPEN expr CURVED_CLOSE
        {
            $$ = $2;
        } ;

...

call_args:
        /* empty */
        {
            $$ = new ExpressionList();
        } |
        expr
        {
            $$ = new ExpressionList();
            $$->push_back($1);
        } |
        call_args COMMA expr
        {
            $1->push_back($3);
        } ;

The problem is that when parsing:

void (*ident)(char* some_arg);

It’s seeing void (*ident) and deducing that it must be a function call instead of a function declaration. Is there a way I can tell Bison that it should favour looking ahead to match var_decl instead of reducing *ident and void into derefs and exprs?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T04:15:52+00:00Added an answer on June 2, 2026 at 4:15 am

    any identifier can be a type

    That’s exactly the problem. LALR(1) grammars for C-like languages (or languages with C-like syntax for types) need to differentiate types and other identifiers at the token level. That is, you need IDENT and TYPEIDENT be two different tokens. (You will have to feed data about identifiers from the compiler back to the tokenizer). It’s the most standard way to disambiguate the otherwise ambiguous grammar.

    Update See, for instance, this ANSI C grammar for Yacc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to specify that a symbol should not be defined, in
Is there any way to specify that a function should be called when a
Is there some way when sending this message to specify that I rather have
Is there a way to specify a value to the text_area method that will
Is there any way to specify that a given Controller or Action uses Session
Is there a 'standard' way to specify that a task continuation should run on
I'm looking for a way to specify that a subset of files should not
Is there a way to specify that a model (or app, even) should only
Is there a way to specify that the app runs on the iphone, the
Is there a way in an XML schema to specify that an element may

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.