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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:02:20+00:00 2026-05-12T20:02:20+00:00

I was making this very simple lex program (just an introductory program). But on

  • 0

I was making this very simple lex program (just an introductory program). But on compiling lex.yy.c, I am getting this error as:

inToPostfix.l:26: error: ‘struct stackoperand’ has no member named ‘top’
inToPostfix.l:32: error: ‘struct stackoperator’ has no member named ‘top’....

I could not make any reason for this error as I already have defined top in the specified structure.
Can you see any reason for it?

Code is posted at http://pastebin.com/d5f059c1d

  • 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-12T20:02:20+00:00Added an answer on May 12, 2026 at 8:02 pm

    Move line 3 to line 16.

    You also need to remove the initializers from the structure declarations – at least for C (but the C++ compiler didn’t think much of it either).

    struct stackoperator
    {
    char stack[10];
    int top =-1;
    };
    

    To:

    struct stackoperator
    {
    char stack[10];
    int top;
    };
    

    In the actions, you also need to declare ‘ch’.

    You also need to declare your functions – I made them static. This compiles (assuming you have a C99 compiler – the designated initializers won’t work with C89 compilers):

    %{
    #include<stdio.h>
    
    struct stackoperator
    {
    char stack[10];
    int top;
    };
    
    struct stackoperand
    {
    int stack[10][2];
    int top;
    };
    struct stackoperator operator = { .top = -1 };
    struct stackoperand operand = { .top = -1 };
    int num=0;
    static void push(int num,int flag);
    static int pop(void);
    static int precedence(char a,char b);
    %}
    
    %%
    
    [0-9]   {num=num*10+(*yytext-'0');push(num,1);}
    [-+*/]  {
            if(precedence(operator.top,*yytext)) {
                char ch=pop();
                push(ch,0);
                operand.stack[operand.top][1]=1;
            }
            push(*yytext,0);
        }
    [ \t]    ;
    [\n]      {
            char ch;
            while(operator.top!=-1)
            {
                ch=pop();
                push(ch,0);
            }
            int i=0;
            while(i<=operand.top)
            {
                if(operand.stack[operand.top][1]==1)
                    printf(" %c ",operand.stack[operand.top][0]);
                else
                    printf(" %d ",operand.stack[operand.top][0]);
            }
        }
    %%
    
    static void push(int num,int flag)
    {
        if(flag)
        {       operand.top++;
            operand.stack[operand.top][0]=num;
            operand.stack[operand.top][1]=0;
        }
        else
            operator.stack[++operator.top]=num;
    }
    
    static int pop(void)
    {
        return operator.stack[operator.top--];
    }
    
    static int precedence(char a,char b)
    {
        if(operator.top==-1)
            return 0;
    
        if((a=='*'||a=='/') && (b=='+'||b=='-'))
            return 1;
        else
            return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 490k
  • Answers 490k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Since you're probably storing the same instance of NSMutableString over… May 16, 2026 at 9:09 am
  • Editorial Team
    Editorial Team added an answer Configuring and tuning mysql for performance is a tedious task.… May 16, 2026 at 9:09 am
  • Editorial Team
    Editorial Team added an answer I would move the Logger higher in the food chain.… May 16, 2026 at 9:09 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have just started making web pages and I'm having lots of trouble with
Beginner here, I have a simple question. In Android what would be the best
I'm not generally a GUI programmer but as luck has it, I'm stuck building
Sorry for long winded post. I am trying to understand UIScrollView and running into
I've been using SVN to track my projects, and I've run into a problem
I'm developing an Android game that has to download some assets to the SD
As I am working with the new database projects in VS2010, and as I
I need to write a function that takes 4 bytes as input, performs a
I'm developing an application that detects Source-based games running on the LAN. Following up

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.