c - What is the scope of yacc/bison actions? -


i'm attempting write (relatively) simple config file parser in flex/bison. basic idea bison grammar uses c functions organize parsed data series of c structs. i'd happy post code if thinks necessary answer question, comment.

the issue i'm running involves scope of procedures within bison actions. example, if have like:

set           : ntok name    {                           section *sec                           init_s(sec, $2);                           add_s(cf, sec);                          } 

shouldn't sec available in later rule of grammar use? i'm getting error: 'sec' undeclared when try call argument again later on. can enlighten me?

all code generated actions in bison in own scope (iirc, generated code wraps in curly-braces enforce this). if want make data globally available other actions, you'll need explicitly declare global variable somewhere (perhaps @ top of flex or bison script?), write variable. rationale behind if every variable in action implicitly global, or @ least readable other actions, easy accidentally recycle garbage data when meant creating new data.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -