source: subversion/applications/rendering/gosmore/tagcmp.l @ 34655

Last change on this file since 34655 was 21969, checked in by nic, 9 years ago

Add a lot of incomplete (disabled) code: tagcmp() implemented in lex,

UI editor, style editor.

Fix compiling on systems lacking pkg-config.

File size: 3.4 KB
Line 
1%option noyywrap case-insensitive
2%option align
3/* 'align' will hopefully improve ARM performance, but does it affect x86 performance ? */
4        int cmpStart, cmpCnt, num;
5%{
6#define YY_USER_ACTION cmpCnt += yyleng;
7/* This action is described in the FAQ contained in the flex info page */
8%}
9
10%s middle
11
12WE      [\0 \n\t,]
13/* Word end */
14
15 /* The rules.
16    If we find a meaningless prefix, we set cmpStart.
17    If we find a meaningless suffix, we reduce cmpCnt, so that it's excluded and we return.
18 */
19 /* Rules for English. */
20%%
21<INITIAL>the" "                                                         cmpStart = cmpCnt; cmpCnt = 0;
22<middle>" "(ave|avenue|blvd|boulevard|byp|bypass){WE}                   cmpCnt -= yyleng; return num;
23<middle>" "(cir|circle|close|cres|crescent|ct|court|ctr|center){WE}     cmpCnt -= yyleng; return num;
24<middle>" "(dr|drive|hwy|highway|ln|lane|loop){WE}                      cmpCnt -= yyleng; return num;
25<middle>" "(pass|pky|parkway|pl|place|plz|plaza){WE}                    cmpCnt -= yyleng; return num;
26<middle>" "(rd|road|sq|square|st|street){WE}                            cmpCnt -= yyleng; return num;
27<middle>" "(ter|terrace|tpke|turnpike|walk|way){WE}                     cmpCnt -= yyleng; return num;
28twenty[ -]      num = 20;
29thirty[ -]      num = 30;
30fourty[ -]      num = 40;
31fifty[ -]       num = 50;
32sixty[ -]       num = 60;
33seventy[ -]     num = 70;
34eighty[ -]      num = 80;
35ninety[ -]      num = 90;
36first           return num + 1;
37second          return num + 2;
38third           return num + 3;
39fourth          return num + 4;
40fifth           return num + 5;
41sixth           return num + 6;
42seventh         return num + 7;
43eighth          return num + 8;
44nineth          return num + 9;
45tenth           return 10;
46eleventh        return 11;
47twelth          return 12;
48thirteenth      return 13;
49fourteenth      return 14;
50fifthteenth     return 15;
51sixteenth       return 16;
52seventeenth     return 17;
53eighteenth      return 18;
54nineteenth      return 19;
55twentieth       return 20;
56
57 /* Rules for French. */
58<INITIAL>(avenue|boulevard|rue)" "(de" "(la" ")?)?                      cmpStart = cmpCnt; cmpCnt = 0;
59
60 /* Rules for Italian. */
61<INITIAL>via" "                                                         cmpStart = cmpCnt; cmpCnt = 0;
62
63 /* Rules for German. Normally "strasse" will not be a separate word, but my guess is that it's
64    better to accomodate that variation. */
65<middle>" "?(strasse|platz|straße){WE}                                  cmpCnt -= yyleng; return num;
66
67 /* Rules for Dutch. Same guess regarding 2 words variations. */
68<middle>" "?(straat|weg|baan|kade|steeg|gracht|veer){WE}                cmpCnt -= yyleng; return num;
69
70 /* American/TIGER street names often start with an N, an E, a W or an S. Ignore it. */
71<INITIAL>[news]" "                                                      cmpStart = cmpCnt; cmpCnt = 0;
72
73[0-9]+          return atoi (yytext);
74[\0\n,]         return num;
75<INITIAL>.      BEGIN (middle);
76<middle>.       ;
77
78%%
79
80main()
81{
82        //yyscan_t scanner;
83        YY_BUFFER_STATE buf;
84        //yylex_init( &scanner );
85        char a[100], b[100];
86        int acmpStart, acmpCnt, anum, i;
87        while (gets (a)) {
88        // for (i = 0; i < 2; i++) { // for 'a' and 'b'
89          acmpStart = cmpStart;
90          acmpCnt = cmpCnt;
91          anum = num;
92          cmpStart = 0;
93          cmpCnt = 0;
94          num = 0;
95          buf = yy_scan_bytes (i ? b : a, 100);
96          /* yy_scan_string() does not process the trainling '\0', which makes it
97             impossible?? to match full words. */
98         
99          num = yylex();
100          printf ("%d '%.*s'\n", num, cmpCnt - cmpStart, a + cmpStart);
101          BEGIN (INITIAL);
102         
103          yy_delete_buffer(buf); //,scanner);
104        }
105        //yylex_destroy( scanner );
106        // return num != anum ? num - anum : strncasecmp (a + acmpStart, b + cmpStart,
107        //  acmpCnt > cmpCnt ? cmpCnt : acmpCnt) ? : cmpCnt - acmpCnt);
108}
Note: See TracBrowser for help on using the repository browser.