Is there a way make the lex program match multiple line?

From: Wen Yi <896634148(at)qq(dot)com>
To: pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Is there a way make the lex program match multiple line?
Date: 2023-06-18 01:17:53
Message-ID: tencent_BD0B710D6EAAD2162E0D754DABC9A60C9008@qq.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi community,
I am making a config program, use the lex program to analyse input.

/*
&nbsp;&nbsp; &nbsp;config.l
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; The lex rule file for toysql
&nbsp;&nbsp; &nbsp;Wen Yi
*/
%option noyywrap
%{
#include <string.h&gt;
#include <stdlib.h&gt;&nbsp;&nbsp;&nbsp;
%}
%%
-[0-9]+.[0-9]+|[0-9]+.[0-9]+|-[0-9]+|[0-9]+ { printf("Number = %lf\n", atof(yytext)); }
[a-zA-Z_0-9]+&nbsp; { printf("Token = %s\n", yytext); }
['].+['] {
&nbsp;&nbsp; &nbsp;yytext[yyleng - 1] = '\0';
&nbsp;&nbsp; &nbsp;memmove(yytext, yytext + 1, yyleng - 1);
&nbsp;&nbsp; &nbsp;printf("String = %s\n", yytext);
}

; {}
. { printf("Anything: '%s'\n", yytext);&nbsp; }
%%
int main()
{
&nbsp;&nbsp; &nbsp;yylex();
&nbsp;&nbsp; &nbsp;return 0;
}

But when I try to run it:

[beginnerc(at)bogon config]$ ./a.out
'This is a single line string'
String = This is a single line string

'This is a multiple line string
Anything: '''
Token = This
Anything: ' '
Token = is
Anything: ' '
Token = a
Anything: ' '
Token = multiple
Anything: ' '
Token = line
Anything: ' '
Token = string

Can someone give me some advice to make the ['].+['] match multiple string?
Thanks in advance!

Yours,
Wen Yi

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2023-06-18 01:50:08 Re: Is there a way make the lex program match multiple line?
Previous Message Brainmue 2023-06-16 20:18:46 Re: Question: Multiple pg clusters on one server can be reached with the standard port.