Ludvig Strigeus wrote:

With Bison, you can do something like this (not quite bison syntax):

myrule: TYPE IDENT {DoSomethingRightAfterIdent($1,$2); } LP more_rules
RP; {DoSomethingAfterEverything($1,$2,$5); }

I.e. you have a chunk of C code that's called in the middle of the
processing of the production. (In the above case right after TYPE
IDENT)

Can you do this with lemon?

I don't know if you can do it bison-style, but you can do this:

1) have a struct that wraps a TYPE(T) and IDENT(I).

2) myrule : prefix(P) LP more_rules(R) RP . { /* process rule */ }

3) prefix(P) : TYPE(T) IDENT(I) . { /* process ident; wrap T and I in the struct from (1); */ }

4) remember to set the default destructor of the prefix rule to destroy the struct from (1).

I know you can do something like this for other cases,

myrule ::= TYPE(T) IDENT(I) temp LP more_rules(R) RP. {
DoSomethingAfterEverything(T,I,R); }
temp ::= DoSomethingRightAfterIdent(...how would I access TYPE/INDENT
from here..);

but it doesn't quite work for this case...

Any ideas?
/Ludvig
HTH

Ulrik Petersen

--
Ulrik Petersen, PhD student, MA, B.Sc.
Aalborg University, Denmark


Reply via email to