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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:06:06+00:00 2026-05-13T14:06:06+00:00

I am trying to build a parser with Bison/Yacc to be able to parse

  • 0

I am trying to build a parser with Bison/Yacc to be able to parse a flow of token done by another module. The tokens are already listed in a enumeration type as follow:

// C++ header file
enum token_id {
  TokenType1         = 0x10000000,
  TokenType2         = 0x11000000,
  TokenType3         = 0x11100000,
  //... and the list go on with about 200/300 line
};

I have gone through the documentation of bison many times but I couldn’t find a better solution than copying each token in the Bison file like this:

/* Bison/Yacc file */
%token TokenType1 0x10000000
%token TokenType2 0x11000000
%token TokenType3 0x11100000
//...

If I have to do it like that, It will become pretty hard to maintain the file if the other module specification change (which happen quite oftenly).

Could you please tell me how to do it, or point me in the good direction (any idea/comment is welcome). It would greatly help me! Thanks in advance.

  • 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-13T14:06:06+00:00Added an answer on May 13, 2026 at 2:06 pm

    Instead of doing :

    /* Bison/Yacc file */
    %token TokenType1 0x10000000
    %token TokenType2 0x11000000
    %token TokenType3 0x11100000
    //...
    

    You just need to include the file with the token type in the declaration part

    #include "mytoken_enum.h"
    // ...
    %token TokenType1
    %token TokenType2
    %token TokenType3 
    //...
    

    EDIT: This can not be done:

    As you see from the numbers above,
    Bison just numbers the tokens
    sequentially, and it is used shifted
    in parser lookup tables as indices,
    for speed simply. So Bison does not
    support that, I feel sure, and it
    would not be easy to fit with the
    implementation model.

    Just need to wrapper to convert the real token to yacc/bison token (eg: via yylex())

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

Sidebar

Related Questions

I'm trying to build a parser that would be able to extract the data
I'm trying to build a parser with bison and have narrowed all my errors
Please help! I am trying to build a parser to parse SSDP messages as
I'm using SCons to build a project at work, and I'm trying to parse
I am trying to build a parser and save the results as an xml
Im trying to build a simple XML to Controls parser in my CF application.
I'm trying to build a simple lexer/parser with Alex/Happy in Haskell, and I would
I'm trying to build a simple grammar to parse a .Net type name string,
I'm trying to build a simple parser, and since InputStream doesn't have some peek-like
I'm trying to parse Project Gutenberg's large RDF file. Another member of my team

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.