[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
How to implement Variable Substitution / Interpolation
From: |
Kyle Brandt |
Subject: |
How to implement Variable Substitution / Interpolation |
Date: |
Thu, 17 Sep 2009 13:52:01 -0400 |
I am just learning flex / bison and I am writing my own shell with it. I am
trying to figure out a good way to do variable interpolation. My initial
approach to this was to have flex scan for something like ~ for my home
directory, or $myVar , and then set what the yyval.string to what is
returned using a look up function. My problem is that this doesn't help me
when text appears as one token:
kbsh:/home/kbrandt% echo ~
/home/kbrandt
kbsh:/home/kbrandt% echo ~/foo
/home/kbrandt /foo
kbsh:/home/kbrandt%
The lex definition I have for variables:
\$[a-zA-Z/0-9_]+ {
yylval.string=return_value(&variables, (yytext + sizeof(char)));;
return(WORD);
}
Then in my Grammar, I have things like:
chdir_command:
CD WORD { change_dir($2); }
;
Anyone know of a good way to handle this sort of thing? Am I going about
this wrong?
Thank you,
Kyle
- How to implement Variable Substitution / Interpolation,
Kyle Brandt <=