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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:42:03+00:00 2026-05-24T07:42:03+00:00

I’m using Bison and I’ve generated a quite complex grammar. The trouble is that

  • 0

I’m using Bison and I’ve generated a quite complex grammar. The trouble is that my first test case is failing- but Bison will only say “syntax error”. Is there any way to ask Bison to output the rule that failed to match and the token that is a problem? I used

%define parse.trace true

but still only get syntax error as the output.

  • 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-24T07:42:04+00:00Added an answer on May 24, 2026 at 7:42 am

    None of the Yacc-based parsers does anything much better than ‘syntax error’ when there is a problem; it is largely up to you to improve on that.

    There are a couple of things you can do fairly readily.

    One is to instrument your lexical analyzer so it prints out the tokens it finds as it returns them to the parser proper. This tells you which token the grammar is failing on, and what tokens were supplied beforehand.

    The other is to compile with Yacc debug enabled, and then turn it on. This requires -DYYDEBUG=1 and setting the variable yydebug to a non-zero value (conventionally 1). The first step compiles the extra information into the grammar; the second step enables the output.

    From the Bison 2.4.3 manual:

    §8.2 Tracing Your Parser

    If a Bison grammar compiles properly but doesn’t do what you want when it runs, the
    yydebug parser-trace feature can help you figure out why.

    There are several means to enable compilation of trace facilities:

    • the macro YYDEBUG

      Define the macro YYDEBUG to a nonzero value when you compile the parser.
      This is compliant with POSIX Yacc. You could use -DYYDEBUG=1 as a compiler
      option or you could put #define YYDEBUG 1 in the prologue of the grammar
      file (see Section 3.1.1 [The Prologue], page 47).

    • the option -t, --debug

      Use the -t option when you run Bison (see Chapter 9 [Invoking Bison],
      page 117). This is POSIX compliant too.

    • the directive %debug

      Add the %debug directive (see Section 3.7.12 [Bison Declaration Summary],
      page 72). This is a Bison extension, which will prove useful when Bison will
      output parsers for languages that don’t use a preprocessor. Unless POSIX and
      Yacc portability matter to you, this is the preferred solution.

    We suggest that you always enable the debug option so that debugging is always possible.

    The trace facility outputs messages with macro calls of the form YYFPRINTF (stderr,
    format, args)
    where format and args are the usual printf format and variadic arguments.
    If you define YYDEBUG to a nonzero value but do not define YYFPRINTF, <stdio.h>
    is automatically included and YYFPRINTF is defined to fprintf.

    Once you have compiled the program with trace facilities, the way to request a trace is
    to store a nonzero value in the variable yydebug. You can do this by making the C code do
    it (in main, perhaps), or you can alter the value with a C debugger.

    Each step taken by the parser when yydebug is nonzero produces a line or two of trace
    information, written on stderr. The trace messages tell you these things:

    • Each time the parser calls yylex, what kind of token was read.
    • Each time a token is shifted, the depth and complete contents of the state stack (see
      Section 5.5 [Parser States], page 95).
    • Each time a rule is reduced, which rule it is, and the complete contents of the state
      stack afterward.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace

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.