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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:22:45+00:00 2026-05-27T06:22:45+00:00

I’m trying to build a parser with bison and have narrowed all my errors

  • 0

I’m trying to build a parser with bison and have narrowed all my errors down to one difficult one.

Here’s the debug output of bison with the state where the error lies:

state 120

   12 statement_list: statement_list . SEMICOLON statement
   24 if_statement: IF conditional THEN statement_lists ELSE statement_list .

    SEMICOLON  shift, and go to state 50

    SEMICOLON  [reduce using rule 24 (if_statement)]
    $default   reduce using rule 24 (if_statement)

Here are the translation rules in the parser.y source

%%

program              : ID COLON block ENDP ID POINT
                     ;
block                : CODE statement_list
                     | DECLARATIONS declaration_block CODE statement_list
                     ;
declaration_block    : id_list OF TYPE type SEMICOLON
                     | declaration_block id_list OF TYPE type SEMICOLON
                     ;
id_list              : ID
                     | ID COMMA id_list
                     ;
type                 : CHARACTER
                     | INTEGER
                     | REAL
                     ;
statement_list       : statement
                     | statement_list SEMICOLON statement
                     ;
statement_lists      : statement
                     | statement_list SEMICOLON statement
                     ;
statement            : assignment_statement
                     | if_statement
                     | do_statement
                     | while_statement
                     | for_statement
                     | write_statement
                     | read_statement
                     ;
assignment_statement : expression OUTPUTTO ID
                     ;
if_statement         : IF conditional THEN statement_lists ENDIF
                     | IF conditional THEN statement_lists ELSE statement_list
                     ;
do_statement         : DO statement_list WHILE conditional ENDDO
                     ;
while_statement      : WHILE conditional DO statement_list ENDWHILE
                     ;
for_statement        : FOR ID IS expression BY expressions TO expression DO statement_list ENDFOR
                     ;
write_statement      : WRITE BRA output_list KET
                     | NEWLINE
                     ;
read_statement       : READ BRA ID KET
                     ;
output_list          : value
                     | value COMMA output_list
                     ;
condition            : expression comparator expression
                     ;
conditional          : condition
                     | NOT conditional
                     | condition AND conditional
                     | condition OR conditional
                     ;
comparator           : ASSIGNMENT
                     | BETWEEN
                     | LT
                     | GT
                     | LESSEQUAL
                     | GREATEREQUAL
                     ;
expression           : term
                     | term PLUS expression
                     | term MINUS expression
                     ;
expressions          : term
                     | term PLUS expressions
                     | term MINUS expressions
                     ;
term                 : value
                     | value MULTIPLY term
                     | value DIVIDE term
                     ;
value                : ID
                     | constant
                     | BRA expression KET
                     ;
constant             : number_constant
                     | CHARCONST
                     ;
number_constant      : NUMBER
                     | MINUS NUMBER
                     | NUMBER POINT NUMBER
                     | MINUS NUMBER POINT NUMBER
                     ;              
%%

When I remove the if_statement rule there are no errors, so I’ve narrowed it down considerably, but still can’t solve the error.

Thanks for any help.

  • 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-05-27T06:22:46+00:00Added an answer on May 27, 2026 at 6:22 am

    Consider this statement: if condition then s2 else s3; s4

    There are two interpretations:

    if condition then
       s1;
    else 
       s2;
    s3;
    

    The other one is:

    if condition then
       s1;
    else
       s2;
       s3;
    

    In the first one, the statment list is composed of an if statement and s3. While the other statement is composed of only one if statement. That’s where the ambiguity comes from. Bison will prefer shift to reduce when a shift-reduce conflict exist, so in the above case, the parser will choose to shift s3.

    Since you have an ENDIF in your if-then statement, consider to introduce an ENDIF in your if-then-else statement, then the problem is solved.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,

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.