From b4b06a5275762a16e3f74fdc8626adff647a5129 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 21 Nov 2005 23:44:56 +0000 Subject: beef up lexer a little git-svn-id: file:///home/lennart/svn/public/sse/trunk@18 5fbabb74-0606-0410-a5e4-b5cc6a42724e --- feed/Makefile | 3 ++- feed/sse_lex_c.l | 78 +++++++++++++++++++++++++++++++------------------------ feed/test-lex-c.c | 17 ++++++++++++ 3 files changed, 63 insertions(+), 35 deletions(-) diff --git a/feed/Makefile b/feed/Makefile index aeb8883..94c2540 100644 --- a/feed/Makefile +++ b/feed/Makefile @@ -1,4 +1,5 @@ -CLAGS=-Wextra -g -O2 -pipe +CFLAGS=-Wextra -O3 -pipe +#CFLAGS=-Wextra -g -O0 -pipe LIBS=-lfl all: sse_lex_c diff --git a/feed/sse_lex_c.l b/feed/sse_lex_c.l index 52f46a7..4674b73 100644 --- a/feed/sse_lex_c.l +++ b/feed/sse_lex_c.l @@ -4,6 +4,48 @@ #include +static void print_with_subwords(const char *w) { + const char *e; + + printf("%s\n", w); + + if ((e = strchr(w, '_'))) { + + /* Split at dashes.*/ + + do { + for (; *e == '_'; e++); + + if (strlen(e) < 3) + break; + + printf("S:%s\n", e); + + e = strchr(e, '_'); + } while (e); + + } else { + + /* Split a place where an uppercase letter follows a lowercase + * letter */ + + e = w; + for (;;) { + for (; *e && !(islower(*e) && isupper(*(e+1))); e++); + + if (!*e) + break; + + e++; + + if (strlen(e) < 3) + break; + + printf("S:%s\n", e); + } + } + +} %} @@ -46,40 +88,7 @@ NIDCHAR [^_a-zA-Z0-9] . ; . { BEGIN CHAR; } -auto{NIDCHAR} | -break{NIDCHAR} | -case{NIDCHAR} | -char{NIDCHAR} | -const{NIDCHAR} | -continue{NIDCHAR} | -default{NIDCHAR} | -do{NIDCHAR} | -double{NIDCHAR} | -else{NIDCHAR} | -enum{NIDCHAR} | -extern{NIDCHAR} | -float{NIDCHAR} | -for{NIDCHAR} | -goto{NIDCHAR} | -if{NIDCHAR} | -int{NIDCHAR} | -long{NIDCHAR} | -register{NIDCHAR} | -return{NIDCHAR} | -short{NIDCHAR} | -signed{NIDCHAR} | -sizeof{NIDCHAR} | -static{NIDCHAR} | -struct{NIDCHAR} | -switch{NIDCHAR} | -typedef{NIDCHAR} | -union{NIDCHAR} | -unsigned{NIDCHAR} | -void{NIDCHAR} | -volatile{NIDCHAR} | -while{NIDCHAR} { yyless(yyleng-1); } - -[a-zA-Z_][a-zA-Z_0-9]{3,} { printf("%s\n", yytext); } +[a-zA-Z_][a-zA-Z_0-9]{3,} { print_with_subwords(yytext); } [0-9]+ ; 0x[0-9a-fA-F]+ ; @@ -89,6 +98,7 @@ NIDCHAR [^_a-zA-Z0-9] %% + int main(int argc, char *argv[]) { if (argc <= 1) diff --git a/feed/test-lex-c.c b/feed/test-lex-c.c index d43f10f..9b984bb 100644 --- a/feed/test-lex-c.c +++ b/feed/test-lex-c.c @@ -118,3 +118,20 @@ int main(int argc, char argv[]) { FOO_BAR(blafasel); } + + + + dies_ist_ein_test +___DIES___IST___EIN__TEST_______ + + alpha beta gamma + _________ + + + DiesIstEinTest + + Dies_Ist_Ein_Test___ + + ArschTritt + + deppVomLande -- cgit