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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:37:16+00:00 2026-05-23T08:37:16+00:00

So, copying the code from Introduction to Compiler Construction in Unix I wind up

  • 0

So, copying the code from Introduction to Compiler Construction in Unix I wind up with the snippet:

/* samplec.l snipped */
static struct rwtable {               /* reserved word table */
    char *rw_name;                    /* representation */
    int rw_yylex;                     /* yylex() value */
    } rwtable[] = {                   /* sorted */
        "break",                          token(BREAK),
        "continue",                       token(CONTINUE),
        "else",                           token(ELSE),
        "if",                             token(IF),
        "int",                            token(INT),
        "return",                         token(RETURN),
        "while",                          token(WHILE)
    };
/* samplec.l snipped */

When I lex the code everything seems fine

$ lex -v samplec.l 
scanner options: -XvI8 -Cem
94/2000 NFA states
38/1000 DFA states (125 words)
16 rules
Compressed tables always back-up
Beginning-of-line patterns used
1/40 start conditions
60 epsilon states, 27 double epsilon states
10/100 character classes needed 144/500 words of storage, 0 reused
105 state/nextstate pairs created
62/43 unique/duplicate transitions
40/1000 base-def entries created
69/2000 (peak 60) nxt-chk entries created
2/2500 (peak 30) template nxt-chk entries created
0 empty table entries
3 protos created
2 templates created, 3 uses
15/256 equivalence classes created
1/256 meta-equivalence classes created
2 (1 saved) hash collisions, 27 DFAs equal
0 sets of reallocations needed
489 total table entries needed

But, when I try to compile it, it fails:

$ gcc -c lex.yy.c -o lex.yy.o
samplec.l:75: error: initializer element is not constant
samplec.l:75: error: (near initialization for ‘rwtable[0].rw_yylex’)
# etc for each token(T)

What’s up? Is token() a macro that should be evaluated (but isn’t for some reason)? Or, should token() have been evaluated by lex?

Sorry, these sort of naive introductions are bad specifically in this situation – where bugs occur that you weren’t taught to understand 🙁 I guess there’s no skimping in learning tools.

  • 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-23T08:37:16+00:00Added an answer on May 23, 2026 at 8:37 am

    token(x) was in fact a macro defined in the file I was working on viz. samplec.l

    #define token(x) x
    

    but of course I had a typo which omitted the x

    #define token(x)
    

    Furthermore, I was missing 3 functions (undefined symbols): s_lookup, yyerror and yymark. The following chapter defines a small stub for yyerror and so I simply defined s_lookup and yymark as empty functions.

    I don’t know if I should have to stub out s_lookup or yymark but the resulting parser worked.

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

Sidebar

Related Questions

I am copying an VBA code snippet from MSDN that shows me how to
I am copying code from website matplotlib and pasting into the Vim editor in
When copying and pasting a bit of sample code from MSDN, I came up
I am trying to reuse code from another project, but while copying the classes
When copying code from the web (usually using Chrome in Ubuntu) I am frustrated
I tried copying the exact same code from the FullCalendar Homepage . So I
I'm copying code from one part of our application (an applet) to inside the
Without copying all the code from one project to another, is it possible to
I'm trying to follow the TableView programming guide, and I'm copying the code directly
When I run the following code to test copying a directory, I get a

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.