The Rule
%lex
%%
"foo" return 'FOO';
[a-zA-Z] return 'TEXT';
<<EOF>> return 'EOF';
" " /* do nothing */
/lex
%%
exp
: group EOF { return $1; }
;
group
: group e { $$ = $1 + $2; }
| e
;
e
: TEXT { $$ = yytext; }
| FOO { $$ = 'BAR'; }
;
So I try out:
foofoo
returns:
fooBAR
but i expected
BARBAR
Then I observe it by changing little rule:
And try this:
fooafoo
return the wrong output:
fooaBAR. (expected BARaBAR)
While:
foo&foo
return the right output:
BAR&BAR.
Is there any way to tokenize text without relying on punctuation?
The Rule
So I try out:
foofooreturns:
fooBARbut i expected
BARBARThen I observe it by changing little rule:
And try this:
fooafooreturn the wrong output:
fooaBAR. (expectedBARaBAR)While:
foo&fooreturn the right output:
BAR&BAR.Is there any way to tokenize text without relying on punctuation?