On 17 Sep 2009, at 19:52, Kyle Brandt wrote:
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.
You might inquiry in the Usenet newsgroup comp.compilers, which can
give better advice on general parsing problems. There are probably
examples out there.
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%
I think the normal thing, though, would be to be letting the lexer
just parse the tokens, and hand that over to the parser, which in turn
builds the actions. So a grammar perhaps like:
%token TILDE
%token SLASH
%%
command_line:
command args
;
args:
/* empty */
| args arg
;
arg:
TILDE other_stuff
SLASH other_stuff
| other_stuff
;
other_stuff: ... ;
Also, the man page of say bash, section invocation, describes in
detail how commands are interpreted, which can be useful if you do not
have an example grammar.
Hans
_______________________________________________
help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison