Thanks Joe.
I think the source of my confusion is the fact that parse.h does not
appear in any of the sqlite source tree. I found it now that I've run
lemon on parse.y. However, I still can't find definitions for COMMA,
SEMI, etc. They appear in the lemon rules, but there has to be
something somewhere that says COMMA = ',' or #define COMMA ',' or ',' {
return COMMA; } I can't find anything that looks like lexer source for
sqlite. What lexer does sqlite use? Where is the sqlite.l file?
The example of flex being used with lemon is (primal scream) a
calculator. I can't find a simple lemon example anywhere for parsing
strings rather than numbers. SQlite's parse.y is a tad bit daunting in
size alone, notwithstanding that it doesn't appear to use a lexer.
Ron Wilson, Senior Engineer, MPR Associates, 518.831.7546
-----Original Message-----
From: Joe Wilson [mailto:[EMAIL PROTECTED]
Sent: Tuesday, December 18, 2007 3:36 PM
To: [email protected]
Subject: Re: [sqlite] a few lemon questions
--- "Wilson, Ron" <[EMAIL PROTECTED]> wrote:
> %type multiselect_op {int}
> multiselect_op(A) ::= UNION(OP). {A = @OP;}
> multiselect_op(A) ::= UNION ALL. {A = TK_ALL;}
> multiselect_op(A) ::= EXCEPT|INTERSECT(OP). {A = @OP;}
>
> 1. What does the '@' symbol mean? At first glance I thought it meant,
> 'give me the literal string,' but 'A' is an integer, so that doesn't
> work. How is {A = @OP;} different from {A = OP;}?
This rule:
multiselect_op(A) ::= EXCEPT|INTERSECT(OP). {A = @OP;}
is shorthand for:
multiselect_op(A) ::= EXCEPT(OP). {A = TK_EXCEPT;}
multiselect_op(A) ::= INTERSECT(OP). {A = TK_INTERSECT;}
You can get away with putting EXCEPT|INTERSECT in the same rule if they
share the same precedence.
> 2. If TK_ALL is a token, what are the other all-caps literals?
They are also tokens. The TK_ prefixed ones appear in { C code },
whereas the non TK_-prefixed all caps tokens appear in the lemon rules.
> I assume
> they are literal text, i.e. 'UNION' is a keyword in sql. However, SQL
> is not case sensitive, so explain how case is handled with these
> literals. I don't think sqlite upcases all text sent to the parser,
so
> there must be some rule that controls the case sensitivity. Or maybe
> these are also tokens?
They're tokens.
You code the lexer to return UNION or ONION or whatever you want to
call the token. It need not match the real spelling. It's just an
implementation detail of your lexer.
> 3. Lemon prefixes all tokens with TK_ (or whatever you define
> %token_prefix). But there are some other literals that I can find no
> definition for, e.g. SEMI, COMMA, etc.
SEMI and COMMA are required by the grammar, but not by the rule action's
C code.
The command:
lemon parse.y
generates, among other things, the file "parse.h" which contains defines
for TK_SEMI and TK_COMMA which you #include in your code.
> 4. I don't see any documention on using a lexer (e.g. flex) with
lemon.
> There are some helps on the internet, but the obvous ommission leads
me
> to believe I don't need a lexer. Does lemon take on some of the
> functionality of a lexer? If I need to define tokens as regular
> expressions can I do that in lemon or do I need a lexer?
You have to supply your own lexer function.
There's an example of flex being used with lemon.
Search the web for "lemon tutorial".
________________________________________________________________________
____________
Looking for last minute shopping deals?
Find them fast with Yahoo! Search.
http://tools.search.yahoo.com/newsearch/category.php?category=shopping
------------------------------------------------------------------------
-----
To unsubscribe, send email to [EMAIL PROTECTED]
------------------------------------------------------------------------
-----
-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------