help-bison
[Top][All Lists]
Advanced

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

Re: Interactive continuation prompting


From: Chris verBurg
Subject: Re: Interactive continuation prompting
Date: Wed, 18 Jun 2014 22:26:04 -0700

Hey Grant,

I don't know the internals of how python and shells do it, but a project I
worked on a long time ago did it a completely different way.  They
implemented two grammars: one was the real language grammar (used for
reading in scripts from files), and the second would parse just an isolated
"line" (used for whatever the user would provide on an interactive
prompt).  It had to be two grammars because an isolated line was not valid
as a full script.

Command history and line continuation were handled directly, not by flex or
bison.  I think figuring out if a line needed continuation was a hack -- it
counted opening and closing parentheses and braces, or something, instead
of handing the string to bison and asking if it's complete.

Hope that was at least somewhat helpful,
-Chris




On Wed, Jun 18, 2014 at 7:53 PM, Grant McKenzie <address@hidden>
wrote:

> Hello,
>
> I have been going through the very nice "A Complete C++ Example" in the
> bison manual and extending it to implement a trivial language. I have a
> question about the parsing driver design on this page:
>
> http://www.gnu.org/software/bison/manual/html_node/Calc_
> 002b_002b-Parsing-Driver.html#Calc_002b_002b-Parsing-Driver
>
> I would eventually like to implement a simple command line interface to my
> little language. I understand that I can set yyin to some stream that I
> control from as-yet-to-be-implemented command line interface. That
> interface would also manage command line history etc.  I'm struggling to
> understand however how bash / python style continuation prompting would
> work ( e.g. python sets it's prompt in an interactive session to '...' when
> syntax is incomplete ). In order to be able to manage these prompts, I
> somehow need to send an indication from bison to flex to my interface that
> syntax is incomplete.
>
> The driver provided in the example does not include any parsing state that
> I could use as this indication.
>
> I can think of a few approaches to get what I want:
>
> 1. use the push-parser design described here http://www.gnu.org/software/
> bison/manual/html_node/Push-Decl.html
>
> 2. change my YY_DECL to pass parsing state to yylex - the interesting
> things that I'd like to pass such as yystack_ are private though ( my
> thinking here was that I could examine the stack depth each time yylex was
> called ).
>
> 3. Dive much deeper into Bison than I intended to and spend some time
> learning how to customize behaviour using the C or C++ API.
>
> I have been through the list archives and other Internet resources and
> although I can find similar questions posted, I have not been able to find
> answers ( or perhaps I do not understand enough yet to parse the answers. )
> Thanks for putting up with my newbiness.
>
> Thanks.
>
>
>
>
>
> _______________________________________________
> address@hidden https://lists.gnu.org/mailman/listinfo/help-bison
>


reply via email to

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