
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

Suppose we have the following context-free grammar which accepts nested lists such as (a (b d) (e (f ))).
List ::= single single ::= VAR | ( multi ) multi ::= single | multi single
Here each V AR can be matched to an arbitrary variable name (e.g., a, b, c).
List ::= single {List.count = single.count; } single ::= VAR {single.count = 1; } | ( multi ) { single.count = multi.count; } multi ::= single { multi.count = single.count; } | multi1 single { multi.count = multi1.count + single.count; }
List ::= {single.before=0; } single {List.count = single.count; } single ::= {VAR.before=single.before; } VAR {single.count = 1; } | ( {multi.before=single.before; } multi ) { single.count = multi.count; } multi ::= {single.before = multi.before; } single { multi.count = single.count; } | {multi1.before = multi.before; } multi {single.before = multi.before + multi1.count; } single { multi.count = multi1.count + single.count; }