help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

interesting push parser use case


From: Bob Rossi
Subject: interesting push parser use case
Date: Sat, 8 Sep 2007 18:05:42 -0400
User-agent: Mutt/1.5.13 (2006-08-11)

Hi,

I found an interesting issue when converting my program from the pull
parser to the push parser. I used to generate a parser, and then write a
thin "main" around the parser. Then I would feed the program a
particular file and let it parse it.

The file contained a list of gdb/mi output commands. The grammar is
capable of parsing one or more gdb/mi output commands.

The grammar would look like,

  %start opt_output_list
  %%

  opt_output_list: {
    tree = NULL;
  };

  opt_output_list: output_list {
    tree = $1;
  };

  output_list: output {
    $$ = $1;
  };

  output_list: output_list output {
    $$ = append_gdbmi_output ($1, $2);
  };

which would allow me to parse a list of commands. The "output" rule is
the rule that parses a single gdb/mi output command. So, as you can see,
the "output_list" rule would allow you to parse 1 or more gdb/mi
commands.

Here is the issue, when I convert this to a push parser, the parser
_always_ thinks that it can parse more data. It never thinks it is
finished. Since it never realizes it's finished, it never gets from 
the top "output_list" rule to the "opt_output_list" rule. This causes my
global variable "tree" to never get the result of the parse tree.

The first issue is that I probably need a way to tell the parser that
I'm done giving it tokens. That way, it will finish all of it's rules.
Is there already a way to do this?

The second issue is slightly more fuzzy. Essentially, after each token I
give to the parser, it would probably be useful to know if it just
finished a particular rule, and if so, which rule. That way, the
application would know when it would want to tell the push parser that
it is all done giving it tokens. Basically, I'd want to tell the parser
that it's done after I've finished an "output_list" rule.

It is possible that I can workaround these issues by changing the
grammar or moving where I do the assignment to the 'tree' pointer.
However, these issues will probably come up again from someone else.

Any ideas?

Thanks,
Bob Rossi




reply via email to

[Prev in Thread] Current Thread [Next in Thread]