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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:42:35+00:00 2026-06-04T02:42:35+00:00

I want to change the define $$ as a struct in the following grammar

  • 0

I want to change the define $$ as a struct in the following grammar i have declared yylval as str, but i have errors when compile the .c file with gcc

gcc *.c -ly 
tp.l: In function ‘yylex’:
tp.l:12: error: request for member ‘sum’ in something not a structure or union
y.tab.c:1035: error: conflicting types for ‘yylval’
tp.y:11: note: previous declaration of ‘yylval’ was here

the yacc file:

 %{
        #include <ctype.h>
        #include <stdio.h>
        #include <stdlib.h>

        typedef struct {
            int val;
            int cpt;
        } str;

        str yylval;

%}
        %start  start 
        %token  number

%%
    start : number'+'number'\n'
    ;

%%

int main(void)
{
        yyparse();
        return 0;
}

the lex file :

%option noyywrap

%{
    #include<stdio.h>
    #include<stdlib.h>
    #include<ctype.h>
    #include"y.tab.h"
%}

%%
[0-9]+  {
            yylval = atoi(yytext); 
            return number;
        }

"+"     return '+';
\n      return '\n';
" " ;

%%
  • 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-06-04T02:42:37+00:00Added an answer on June 4, 2026 at 2:42 am

    You cannot define your own yylval. The generated code already defines this. Use the %union directive to define the type indirectly. If that is not suitable, then what you can do is redefine the macro YYSTYPE which expands to arbitrary type specifiers. For instance:

    struct my_semantic_attributes {
      int foo;
      /* ... */
    };
    
    #define YYSTYPE struct my_semantic_attributes
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array defined as; static double Temp_data[TABLE_SIZE]; I want to change the
I want change following javascript code to jquery code, How is it? With done
I have a RadioButtnList. I want change body background color based on radio button
i have many div's with the same background image and i want change this
So, I have some code, kind of like the following, to add a struct
So I have something like this #define HASHSIZE 1010081 static struct nlist *hashtab[HASHSIZE]; Now
I have a file in C++ containing constant definitions, I want to use the
I want to define the style of Div based on a CSS file. The
I've defined the following struct: typedef struct { double salary; } Employee; I want
I want to change device description in a FTDI-Chip. For that, I define first

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.