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

Поиск
Список
Период
Сортировка
От Wen Yi
Тема [Beginner Question]How can I use the yacc & lex in right way?
Дата
Msg-id TYAP286MB06361995DDAC70EA27A29C7FA91F9@TYAP286MB0636.JPNP286.PROD.OUTLOOK.COM
обсуждение исходный текст
Список 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@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.

В списке pgsql-general по дате отправления:

Предыдущее
От: Mateusz Henicz
Дата:
Сообщение: Re: configure a patroni cluster with a follower who never can become leader
Следующее
От: Eagna
Дата:
Сообщение: Regular expression for lower case to upper case.