作者alpho (Whyyyyy)
看板RegExp
标题[问题] lex 编译出问题
时间Thu May 7 12:55:00 2015
/*
听说注明使用的语言、环境
*
问题有可能较容易被解决...
*/
我是用flex去写lex,然後转成lex.yy.c再编译成a.exe
%option noyywrap
%{
#include<stdio.h>
%}
%%
([(1)?[0-9]{1,2}|2[0-4][0-9]|2[5][0-5]]\.){3,3}
[1?[0-9]{1,2}|2([0-4])[0-9]|25[0-5]] { printf( yytext) ;}
. { }
%%
int main(void)
{
yylex();
return 0;
}
题目要求给一串字串,从里面挑出符合IP格式的输出 "0~255.0~255.0~255.0~255" ←这样
然後结果:
C:\Users\USER>flex pd2.l
C:\Users\USER>g++ lex.yy.c
pd2.l: In function 'int yylex()':
pd2.l:8:2: error: expected identifier before numeric constant
pd2.l:8:57: warning: lambda expressions only available with -std=c++11 or
-std=gnu++11 [enabled by d
efault]
pd2.l:9:2: error: expected ';' before 'break'
不过只要把最後判定的 [1?[0-9]{1,2}|2([0-4])[0-9]|25[0-5]] delete掉,编译就
能通过。
所以有点搞不懂问题出在哪,求解。
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 61.219.133.73
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/RegExp/M.1430974503.A.E51.html
1F:→ pccts: 用 debian-6 的 flex 2.5.35 + gcc 4.5.5 试, 没问题. 05/25 21:34