[Beginner Question]How can I use the yacc & lex in right way?

From: Wen Yi <chuxuec(at)outlook(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: [Beginner Question]How can I use the yacc & lex in right way?
Date: 2022-12-10 00:23:22
Message-ID: TYAP286MB06361995DDAC70EA27A29C7FA91F9@TYAP286MB0636.JPNP286.PROD.OUTLOOK.COM
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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(at)fedora SimpleSQL]$ lex try.l
[beginnerc(at)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.

Browse pgsql-general by date

  From Date Subject
Next Message Eagna 2022-12-10 09:40:22 Regular expression for lower case to upper case.
Previous Message Amit Kapila 2022-12-09 10:36:05 Re: Support logical replication of DDLs