pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Wen Yi <chuxuec@outlook.com>
To: PostgreSQL General <pgsql-general@lists.postgresql.org>
Subject: [Beginner question]How to solve multiple definition of `yylval'?
Date: Thu, 11 May 2023 11:52:27 +0000
Message-ID: <TYAP286MB063665A17431CD4D243315D7A9749@TYAP286MB0636.JPNP286.PROD.OUTLOOK.COM> (raw)

Hi team,
I am studying on the yacc & lex to help me understand the parser of the postgres, but now I'm facing some trouble.

-------------------
/*
      1-3.y
*/

%{
#include <stdio.h>
int yylex();
int yyerror(char *s);
typedef char* string;
#define YYSTPYE string
%}
%token NUMBER
%token ADD SUB MUL DIV ABS
%token NEWLINE

%%

calclist: /* Empty rule */
| calclist expression NEWLINE { printf (" = %lf", $2); }
;

expression: factor { $$ = $1; }
| expression ADD factor { $$ = $1 + $3; }
| expression SUB factor { $$ = $1 - $3; }
;

factor: term { $$ = $1; }
| factor MUL term { $$ = $1 * $3; }
| factor DIV term { $$ = $1 / $3; }
;

term: NUMBER  { $$ = $1; }
| ABS term { $$ = $2 > 0 ? $2 : - $2; }

%%

int main(int argc, char *argv[])
{
      yyparse();
}
int yyerror(char *s)
{
      puts(s);
}

---------

/*
      1.3.l
            Calc Program
      Jing Zhang
*/
%option noyywrap
%option noinput

%{
      #include <stdlib.h>
      enum yyTokenType
      {
            NUMBER = 258,
            ADD,
            SUB,
            MUL,
            DIV,
            ABS,
            NEWLINE
      };
      double yylval;
%}

%%

"+" { return ADD; }
"-" { return SUB; }
"*" { return MUL; }
"/" { return DIV; }
"|" { return ABS; }
[0-9]+ { yylval = atof (yytext); return NUMBER;}
\n { return NEWLINE; }
[ \t] { ; }
. { ; }
%%

-------


When I use the yacc & lex to compile,

yacc -d 1-3.y
lex 1-3.l
gcc 1-3.tab.c lex.yy.c
/usr/bin/ld: /tmp/ccYqqE5N.o:(.bss+0x28): multiple definition of `yylval'; /tmp/ccdJ12gy.o:(.bss+0x4): first defined here

Can someone provide me a solution?
Thanks in advance!

Yours,
Jing Zhang.


view thread (2+ messages)  latest in thread

Message-ID: <TYAP286MB063665A17431CD4D243315D7A9749@TYAP286MB0636.JPNP286.PROD.OUTLOOK.COM>
Permalink:  ../TYAP286MB063665A17431CD4D243315D7A9749@TYAP286MB0636.JPNP286.PROD.OUTLOOK.COM/
Also on:    postgresql.org/message-id/TYAP286MB063665A17431CD4D243315D7A9749@TYAP286MB0636.JPNP286.PROD.OUTLOOK.COM

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: chuxuec@outlook.com
  Subject: Re: [Beginner question]How to solve multiple definition of `yylval'?
  In-Reply-To: <TYAP286MB063665A17431CD4D243315D7A9749@TYAP286MB0636.JPNP286.PROD.OUTLOOK.COM>
  References: <TYAP286MB063665A17431CD4D243315D7A9749@TYAP286MB0636.JPNP286.PROD.OUTLOOK.COM>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox