Hi Arjen,

Thanks for the mail...I found it very helpful and i started to execute
it......I succeeded in doing it...

However i started writing a sample program for converting "Infix to
Prefix"...I am struck at this point ...so can u help me in
writing this program...

Thanks in advance....

Regards,
Arjun

On Sat, Jun 28, 2008 at 12:54 AM, Arjen Markus <[EMAIL PROTECTED]>
wrote:

> > Hi,
> > Can u send me any documentation on LEMON that u have worked out.
> > I have some queries also.....
> > 1.Does LEMON work on Windows environment?
> > 2.I tried but it is not.I heard that it works on Linux environment.I am
> > trying to know why not on windows...can u give me some info about it
> >
> > I am reading the material u have suggested me but it did not have any
> > information regarding to my queries.
> >
> > Can u mail me if u have made any documentation on LEMON.
> >
>
> Well, basically lemon works as follows:
> 1. It reads the definition of the parser from the input file
>   you give it as the first argument. From that it produces
>   a set of tables that implement the parser. This information
>   gets filled in in a template.
> 2. The result is a C file that you can use to parse (interpret)
>   your input.
> 3. What it does not do is split up the input into tokens. You
>   have to do that yourself.
>
> I attach a small - not very efficient - example that shows a
> few features of lemon.
>
> As for your questions:
> There is no reason it would not work on Windows: it is a
> perfectly straghtforward C program, you get the source code
> and compile it. One thing though: the template file must be
> in the directory where you run the program, where the
> executable lives or in the PATH.
>
> (I am using it myself on Windows :). I am adapting it so that
> it will produce Fortran code instead of C code. But that is
> off topic.)
>
> Here is my sample parser definition:
>
> // expr.y
> // Simple parser:
> // expr = vaue + value + value + ...
>
> %extra_argument {State *state}
> %token_type {Token*}
> %type term {int}
>
> expr ::= firstterm plusterms . {
>    printf( "Result: %d\n", state->sum );
> }
>
> firstterm ::= term(T) . {
>    state->sum = T;
>    printf("First term: %d\n", T );
> }
>
> term(V) ::= NUMBER(N) . {
>    sscanf( N->token, "%d", &V );
>    printf("Term: %d -- %s\n", V, N->token );
> }
>
> plusterms ::= .
> plusterms ::= plusterms plusterm .
>
> plusterm ::= PLUS term(T) . {
>    state->sum = state->sum + T;
>    printf( "Result so far: %d\n", state->sum );
> }
>
> ------
> And here is the main program that includes the
> resulting C code:
>
> #include <stdlib.h>
> #include <stdio.h>
> #include <assert.h>
>
> typedef struct {
>    char *token;
> } Token;
> typedef struct {
>    int sum;
> } State;
>
> #include "expr.h"
> #include "expr.c"
>
> int main( int argc, char *argv[] ) {
>    Token token[10];
>    State state;
>
>    void *pParser = (void *) ParseAlloc( malloc );
>
>    ParseTrace( stdout, ">>" );
>
>    token[0].token = "1"; Parse( pParser, NUMBER, &token[0], &state );
>    token[1].token = "+"; Parse( pParser, PLUS,   &token[1], &state );
>    token[2].token = "2"; Parse( pParser, NUMBER, &token[2], &state );
>    token[3].token = "+"; Parse( pParser, PLUS,   &token[3], &state );
>    token[4].token = "3"; Parse( pParser, NUMBER, &token[4], &state );
>
>    Parse( pParser, 0, &token[0], &state );
>
>    ParseFree( pParser, free );
>
>    return 0;
> }
>
> -----
> One thing to note:
> As the tokens are not always treated the moment they are passed
> to the parser - this depends on the grammar and the moment in the
> parsing process, you need to make sure that the tokens remain
> available. I have done that in this silly program by using an
> array of them. But a smarter program would use lemon's
> abilities to destroy the tokens when ready.
>
> Regards,
>
> Arjen
>
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to