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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:31:22+00:00 2026-05-30T02:31:22+00:00

I’m trying to compile a simple calculator example that I found in the internet

  • 0

I’m trying to compile a simple calculator example that I found in the internet for my embedded environment, but I’m having a few difficulties regarding dependencies with flex/bison.

My test files are these:

lexer.l

%{
// lexer.l     From tcalc: a simple calculator program
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include "tcalc.tab.h"
extern YYSTYPE yylval;

%}
%option noyywrap
%option never-interactive
%option nounistd
delim         [ \t]
whitesp       {delim}+
digit         [0-9]
number        [-]?{digit}*[.]?{digit}+
%%
{number}  { sscanf(yytext, "%lf", &yylval); return NUMBER;}
"+"       { return PLUS; }
"-"       { return MINUS; }
"/"       { return SLASH; }
"*"       { return ASTERISK; }
"("       { return LPAREN; }
")"       { return RPAREN; }
"\n"      { return NEWLINE; }
{whitesp} { /* No action and no return */}

tcalc.y

/* tcalc.y - a four function calculator */
%{
#define YYSTYPE double      /* yyparse() stack type */
#include <stdlib.h>
%}
/* BISON Declarations */
%token NEWLINE NUMBER PLUS MINUS SLASH ASTERISK LPAREN RPAREN

/* Grammar follows */
%%
input:              /* empty string */
    | input line
    ;
line: NEWLINE
    | expr NEWLINE           { printf("\t%.10g\n",$1); }
    ;
expr: expr PLUS term         { $$ = $1 + $3; }
    | expr MINUS term        { $$ = $1 - $3; }
    | term
    ;
term: term ASTERISK factor   { $$ = $1 * $3; }
    | term SLASH factor      { $$ = $1 / $3; }
    | factor
    ;
factor:  LPAREN expr RPAREN  { $$ = $2; }
      | NUMBER
      ;
%%
/*--------------------------------------------------------*/
/* Additional C code */
/* Error processor for yyparse */
#include <stdio.h>
int yyerror(char *s)        /* called by yyparse on error */
{
    printf("%s\n",s);
    return(0);
}

/*--------------------------------------------------------*/
/* The controlling function */
#include "lex.h"
int parse(void)
{
    char exp[] = "2+3\n\0\0";
    yy_scan_buffer(exp, sizeof(exp));
    yyparse();
    exit(0);
}

When I try to compile it with my compiler, I get an error about EINTR not being found. There is no EINTR in my errno.h header (from my compiler’s toolchain).

Is there some options do make flex/bison more lightweight and depend less on POSIX stuff?

  • 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-30T02:31:24+00:00Added an answer on May 30, 2026 at 2:31 am

    In short: No. flex will reference EINTR in all C scanners. So you basically have three choices (in descending order):

    1. Fix your compiler. Which one doesn’t define EINTR?
    2. Define your own YY_INPUT in a %top block.
    3. Define a dummy EINTR; 0 or INT_MAX are probably good choices for this specific application but redefining standard macros can always have funny side-effects.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.