I have a Flex Bison application. For some of my tokens, I copy ydtex from Flex using strdup I works great except for an error of the unexpected token.
Simple example
flex.l: ... [a-zA-Z0- 9] + {lval.string = strdup (yytext); Return identity}; [\ {\}] {Returns yytext [0]}; ... and
parse.y ...% killer {free ($$); } IDENT% DESTINATION {Free ($$ -> Name); Free ($$ -> type); Free ($$); } Tags ... Tags: IDNT '{' IDENT '}' {struct tag * mytag = malloc (sizeof (struct tag)); Mytag-> Name = $ 1; Mitig-> Type = $ 3; $ & Lt; Tag & gt; $ = Mytag; } ... Now assume I keep this input:
blah blah blah laser Send the first identity token, which is pushed onto the stack. After the first token it is expecting a bracket token, but instead gets another identification token. This is a syntax error, the destroyer will be called on the first IDENT token, but not on the second (unpredictable). I can not find a way to destroy the unexpected token. Does anyone know how I should do this?
I found that the proper use of 'error' token is to flex it properly to call the destructor function Inspires for Go to me
parse.y ...% Dosage {Free ($$); } IDENT% DESTINATION {Free ($$ -> Name); Free ($$ -> type); Free ($$); } Tags ... Tags Tags Tags Tags Error tag | ; Tags: identifier '{' IDENT '}' {struct tag * mytag = malloc (sizeof (struct tag)); Mytag-> Name = $ 1; Mitig-> Type = $ 3; $ & Lt; Tag & gt; $ = Mytag; } ...
Comments
Post a Comment