看板 RegExp 關於我們 聯絡資訊
/* 聽說註明使用的語言、環境 * 問題有可能較容易被解決... */ 我是用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://www.ptt.cc/bbs/RegExp/M.1430974503.A.E51.html
pccts: 用 debian-6 的 flex 2.5.35 + gcc 4.5.5 試, 沒問題. 05/25 21:34