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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:11:58+00:00 2026-05-18T08:11:58+00:00

hi im confusing about how to get a char* when i read a specific

  • 0

hi im confusing about how to get a char* when i read a specific token…
I look in various sites and they provide suggestions but not complete, i mean, for example yylval and yytext declaration is missing or how to transform the types, etc

What is need in .l file?
What is need in .y file?

What I have

in the .l file:

{WORD}      { yylval = strdup(yytext);return T_ValidWord;}

in the .y file:

%union{
  char *str;
}

%token<str> T_ValidWord

%%

element:
T_OpenTag T_ValidWord ele1 {printf("%s", $2);}
; 

The error:

xml.lex: In function ‘yylex’:
xml.lex:34: error: incompatible types when assigning to type ‘YYSTYPE’ from type ‘char *’

Other thing more that confused me:
In some places i see

yylval->something = yytext
yylval.something = yytext
yylval = yytext

In the manual of bison tell that yylval is a macro, I understand that a macro is text replaced for other text, but in this situation i really don’t get it.

  • 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-18T08:11:58+00:00Added an answer on May 18, 2026 at 8:11 am

    yylval is a union type YYSTYPE. Change your assignment in the scanner to yylval.str = strdup(yytext).

    yylval is a union which you can either declare or the bison will declare automatically. Bison’s default yylval is essentially useless. You declare yylval using %union { ... } in your parser because you may need to return other values from the scanner to the parser. For example, when you match a number in your scanner, you’ll want to return a token like T_NUM. But you most probably also want the value of that number, which is where yylval comes handy. Using yylval, if you have an integer field, you could simply do yylval.num = atoi(yytext) inside your scanner, and then use that num field in the parser.

    yytext is an array of characters, which acts as a buffer for the input currently being parsed. You cannot declare yytext, and neither should you.

    When you use bison to compile the parser into a .tab.c file, use the flags bison -d -t for debugging symbols and the header file. The header file will be called *.tab.h. Include that in your scanner so you only need to declare token names once and have proper use of yylval.

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

Sidebar

Related Questions

I have read many about REST api in php articles. but I still get
I have read several posts about WSDL and SOAP but still I'm confusing the
I posted this is the thread which discussed about request_threaded_irq but I did not
I read few questions here on SO about this topic which seems yet confusing
Caution: I know nothing about C++. I'm comfortable using C#, but this is confusing
I'm currently writing JavaScript and confusing about callback . I've found it's not kind
Can someone explain the threading model in windows metro? I really get confusion about
I'm always confusing about this stuff. I have this query : string[] names =
i am really confusing about how to pass an enum type to a function
One thing I have continually found very confusing about using an object database like

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.