[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [help-bison]How to stock information?
From: |
soledady |
Subject: |
Re: [help-bison]How to stock information? |
Date: |
Wed, 20 Jul 2005 07:49:31 +0200 |
Le mercredi 20 juillet 2005 à 01:42 +0200, Hans Aberg a écrit :
thanks you very much for the quick answer!
> > when I execute bison It builds a syntaxical tree (doesn't it?)
>
> Not really. Bison supplies the constructs so that you can build a
> syntax trees in the parser, bottom up, if you so want. One can't
> immediately build them top-down.
>
can i construct a top-down grammar?
> For example, if you have a rule
> term:
> term "+" term {...}
> then $1, $2, and $3 will be used to assign values to the RHS
> occurrences of "term", which can be forwarded to the LHS by the use
> of $$. If you let $$ be the root of a tree, and $1, $2 and $3 be
> branches attached to $$, you get a syntax tree:
> $$
> / | \
> $1 $2 $3
the $$ could be use again in other rule couldn't it?
if yes then How?(not really in rule i mean in code next tne rule
between brackets)
just a precision what the meaning of RHS and LHS(Right...? and Left
something?)
> > so for this part of an example (without all the rest of the example)
> > U{N}=U{N-1}+3*U{N-2}; U{0}=1; U{1}=2;
> > it's give me:
> > *3+ ; 1 2 =U{1}=U{0} U{n-2} U{n-1} =U{N}
> >
> >
> > how can i do to recover correctly which number for which part of
> > code ?
>
> My guess is that you ask for the semantic value. It will be held in
> the variables $$ and $k.
>
ok but how can i do to know that *3+ means +3*
and to know which kind of term (u(n) or u(n+1) and so on...) are in use
> Also, there is a program <http://codeworker.free.fr/> dedicated to
> this kind of task, you may want to have a look at.
>
> >
> You just assign the suitable text values to the tokens, and start to
> build suitable strings or macros. Assume you have
>
> statement:
> "{" statement_body "}"
>
> statement_body: /* Builds "u(n)=u(n-1)+3*u(n-2);u{0}=1;u{1}=2;" */
>
yes but how can i built this expression
> Then you need an action for "statement" like
> statement: "{" statement_body "}" {
> $$ = "begin Name=Suite; begin DEFINITION=RECURRENTE;" + $1 + ...
> }
> where "+" is string concatenation. I hope you see the idea.
>
ok can we use $$ for other rule and recover its value,
the idea is in the built of the grammar
> You can simplify token handling by using Flex, and let every token
> return the text that is lexed.
>
> Hans Aberg
>
I thank you again.
>
>
>
> _______________________________________________
> address@hidden http://lists.gnu.org/mailman/listinfo/help-bison
>