[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
A Query in Tokenizing input
From: |
praveen thakur |
Subject: |
A Query in Tokenizing input |
Date: |
Sat, 21 Jun 2003 08:38:46 +0100 (BST) |
Hi,
I am writing a Lexer/Parser (using flex++/bison++) in
which I want
to differentiate some keywords from STRING at the
parser level.
My lexer file is like this...
NUMBER ([0-9]+)(\.[0-9]+)?
STRING [_A-Za-z][_A-Za-z0-9\.\\\/]*
%%
{NUMBER} {(parser.yylval).Int=(int)atoi(yytext);return
Parser::NUMBER;}
{STRING} {strcpy((parser.yylval).Str,yytext);return
Parser::STRING;}
. { return *yytext;}
%%
Now my Parser looks like...
%token STRING
%%
statement : statement expr
|
;
expr : operator1
| operator2
;
operator1 : 't''a' '=' NUMBER
;
operator2 : STRING '=' NUMBER
;
<only operator1 or operator2 at one time is written>
%%
I am using STRING at several places and I want some
keywords
(like "ta" above ) differentiated from the STRING
based on the
production rule. Can this be achieved ?? The above
representation in
terms of "operator1" is not working as the parser is
not getting "ta"
as chars rather it gets as STRING. One option I have,
is to implement
in terms of operator2 and use switch-case like
statements to
recognize the keywords. I can't send the keywords as
separate TOKENS
(because same string "ta" can be a string also in some
other rule).
Is there any alternative ways of getting the above.
(using states
or ...).
Thanking all,
praveen
__________________________________________________
Yahoo! Plus
For a better Internet experience
http://www.yahoo.co.uk/btoffer
- A Query in Tokenizing input,
praveen thakur <=