pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Wen Yi <chuxuec@outlook.com>
To: pgsql-general <pgsql-general@postgresql.org>
Subject: [Beginner Question]How can I use the yacc & lex in right way?
Date: Sat, 10 Dec 2022 00:23:22 +0000
Message-ID: <TYAP286MB06361995DDAC70EA27A29C7FA91F9@TYAP286MB0636.JPNP286.PROD.OUTLOOK.COM> (raw)

Hello the team:
I'm now learning the yacc & lex and want to write a simple SQL parser,
Here's part of my code


%option noyywrap
%option bison-bridge
%option reentrant
...
enum {
    UNDEFINED = 1,
    CREATE,
    TABLE,
    UPDATE,
    SET,
    INSERT,
    INTO,
    VALUES,
    DELETE,
    FROM,
    SELECT,
    GET,
    PUT,
    EXIST,
    USER,
    BEGIN,
    COMMIT,
    ROLLBACK
};
...
[Cc][Rr][Ee][Aa][Tt][Ee] RETURN_TOKEN(CREATE)
[Tt][Aa][Bb][Ll][Ee] RETURN_TOKEN(TABLE)
[Uu][Pp][Dd][Aa][Tt][Ee] RETURN_TOKEN(UPDATE)
[Ss][Ee][Tt] RETURN_TOKEN(SET)
[Ii][Nn][Ss][Ee][Rr][Tt] RETURN_TOKEN(INSERT)
[Ii][Nn][Tt]Oo RETURN_TOKEN(INTO)

As you can see,I want to let the lex recognized the token,but when I compile the c code generated by the lex,
some error showed:


[beginnerc@fedora SimpleSQL]$ lex try.l
[beginnerc@fedora SimpleSQL]$ gcc lex.yy.c
lex.yy.c:145:18: error: expected ',' or '}' before '->' token
  145 |  */
      |                  ^
try.l:32:5: note: in expansion of macro 'BEGIN'
   32 |     BEGIN,
      |     ^~~~~
lex.yy.c:559:5: error: unknown type name 'YYSTYPE'
  559 |
      |     ^
lex.yy.c:606:1: error: unknown type name 'YYSTYPE'; did you mean 'YYSTATE'?
  606 |
      | ^
      | YYSTATE
lex.yy.c:608:19: error: unknown type name 'YYSTYPE'; did you mean 'YYSTATE'?
  608 |
      |                   ^
      |                   YYSTATE
lex.yy.c:726:17: error: unknown type name 'YYSTYPE'; did you mean 'YYSTATE'?
  726 | extern int yylex \
      |                 ^~
      |                 YYSTATE

Can someone give me some advice to fix the error?
Thanks in advance!
Yours,
WenYi.


Message-ID: <TYAP286MB06361995DDAC70EA27A29C7FA91F9@TYAP286MB0636.JPNP286.PROD.OUTLOOK.COM>
Permalink:  ../TYAP286MB06361995DDAC70EA27A29C7FA91F9@TYAP286MB0636.JPNP286.PROD.OUTLOOK.COM/
Also on:    postgresql.org/message-id/TYAP286MB06361995DDAC70EA27A29C7FA91F9@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 can I use the yacc & lex in right way?
  In-Reply-To: <TYAP286MB06361995DDAC70EA27A29C7FA91F9@TYAP286MB0636.JPNP286.PROD.OUTLOOK.COM>
  References: <TYAP286MB06361995DDAC70EA27A29C7FA91F9@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