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 7762871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:31:12+00:00 2026-06-01T14:31:12+00:00

I have the following parser grammar (this is a small sample): expr: ident assignop

  • 0

I have the following parser grammar (this is a small sample):

expr:
        ident assignop expr
        {
            $$ = new NAssignment(new NAssignmentIdentifier(*$1), $2, *$3);
        } |
        STAR expr %prec IDEREF
        {
            $$ = new NDereferenceOperator(*$2);
        } |
        STAR expr assignop expr %prec IDEREF
        {
            $$ = new NAssignment(new NAssignmentDereference(*$2), $3, *$4);
        } |
        ... ;

...

assignop:
        ASSIGN_EQUAL |
        ASSIGN_ADD |
        ASSIGN_SUBTRACT |
        ASSIGN_MULTIPLY |
        ASSIGN_DIVIDE ;

Now I’m trying to parse any of the following lines:

*0x8000 = 0x7000;
*mem = 0x7000;

However, Bison keeps seeing “*mem” and reducing on the ‘STAR expr’ rule and not performing look-ahead to see whether ‘STAR expr assignop…’ matches. As far as I understand Bison, it should be doing this look-ahead. My closest guess is that %prec is turning off look-ahead or something strange like that, but I can’t see why it would do so (since the prec values are equivalent).

How do I make it perform look-ahead in this case?

EDIT:

The state that it enters when encountering ‘STAR expr’ is:

state 45

   28 expr: STAR expr .
   29     | STAR expr . assignop expr
   35     | expr . binaryop expr

    $default  reduce using rule 28 (expr)

    assignop  go to state 81
    binaryop  go to state 79

So I don’t understand why it’s picking $default when it could pick assignop (note that the order of the rules in the parser.y file don’t affect which one it picks in this case; I’ve tried reordering the assignop one above the standard ‘STAR expr’).

  • 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-01T14:31:14+00:00Added an answer on June 1, 2026 at 2:31 pm

    I ended up solving this problem by creating another rule ‘deref’ like so:

    deref:
            STAR ident
            {
                $$ = new NDereferenceOperator(*$<ident>2);
            } |
            STAR numeric
            {
                $$ = new NDereferenceOperator(*$2);
            } |
            STAR CURVED_OPEN expr CURVED_CLOSE
            {
                $$ = new NDereferenceOperator(*$3);
            } |
            deref assignop expr
            {
                if ($1->cType == "expression-dereference") // We can't accept NAssignments as the deref in this case.
                    $$ = new NAssignment(new NAssignmentDereference(((NDereferenceOperator*)$1)->expr), $2, *$3);
                else
                    throw new CompilerException("Unable to apply dereferencing assignment operation to non-dereference operator based LHS.");
            } ;
    

    replacing both rules in ‘expr’ with a single ‘deref’.

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

Sidebar

Related Questions

So I have this grammar: expr(op(T,B,E)) => [term(T), binop(B), expr(E)]. expr(T) => [term(T)]. term(N)
Problem Description In my yacc parser grammar, I have the following rules and corresponding
I have the following methods in my simple Custom Parser Class, when I execute
I have a UITableView with the following code: - (void)viewDidLoad { [super viewDidLoad]; parser
I'm trying to learn about shift-reduce parsing. Suppose we have the following grammar, using
I have the following grammar (i'm showing only the important sectons) packageDeclaration : PACKAGE
I have the following spirit grammar. I am trying to create a vector of
I have the following ANTLR grammar which is given as an example by Terrence
I have the following grammar: rule: q=QualifiedName {System.out.println($q.text);}; QualifiedName : i=Identifier { $i.setText($i.text +
I have the following grammar in ANTLRWorks 1.4. I'm playing around with ideas for

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.