Hi community,
I am making a config program, use the lex program to analyse input.
/*
config.l
The lex rule file for toysql
Wen Yi
*/
%option noyywrap
%{
#include <string.h>
#include <stdlib.h>
%}
%%
-[0-9]+.[0-9]+|[0-9]+.[0-9]+|-[0-9]+|[0-9]+ { printf("Number = %lf\n", atof(yytext)); }
[a-zA-Z_0-9]+ { printf("Token = %s\n", yytext); }
['].+['] {
yytext[yyleng - 1] = '\0';
memmove(yytext, yytext + 1, yyleng - 1);
printf("String = %s\n", yytext);
}
; {}
. { printf("Anything: '%s'\n", yytext); }
%%
int main()
{
yylex();
return 0;
}
config.l
The lex rule file for toysql
Wen Yi
*/
%option noyywrap
%{
#include <string.h>
#include <stdlib.h>
%}
%%
-[0-9]+.[0-9]+|[0-9]+.[0-9]+|-[0-9]+|[0-9]+ { printf("Number = %lf\n", atof(yytext)); }
[a-zA-Z_0-9]+ { printf("Token = %s\n", yytext); }
['].+['] {
yytext[yyleng - 1] = '\0';
memmove(yytext, yytext + 1, yyleng - 1);
printf("String = %s\n", yytext);
}
; {}
. { printf("Anything: '%s'\n", yytext); }
%%
int main()
{
yylex();
return 0;
}
But when I try to run it:
[beginnerc@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?
'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