[Top][All Lists]

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

using a push parser to connect Octave to a GUI

From: John W. Eaton
Subject: using a push parser to connect Octave to a GUI
Date: Sat, 28 Jan 2012 22:28:30 -0500

I've been experimenting with generating a push parser with Bison
instead of the traditional "pull parser" that Bison normally
generates.  The concept of a push parser is described here:


but briefly, the idea is that instead of calling the parser
once and having it gather input, you call the lexer repeatedly to
extract tokens from the input stream and feed them to the parser one
at a time.

Using this style of interface with Octave would mean that a GUI or
other front-end could gather input one line at a time (instead of one
complete statement at a time) and feed tokens to Octave's parser as
they are available.  It would not be necessary to run Octave inside a
full terminal emulator widget.

Without a terminal widget, and using Octave this way, we
would not be able to use GNU readline.  OTOH, it might not be that
difficult to emulate enough readline keybindings to satisfy most GUI
users of Octave.

A tiny example calculator that demonstrates these ideas is attached
below.  It uses gtkmm 3.x.  The included Makefile is simplistic and
assumes you have all the necessary tools installed and that you have a
pkg-config script that can tell you what include flags and libraries
are needed for using gtkmm.  You won't need Bison unless you delete
the included parse.cc file.  The generated program is called "calc"
and it accepts a --tty option to run it without the GUI.

I see this approach as a possibility for solving the GUI problem
without requiring a terminal widget that can connect to Octave with a
pty interface, which seems to be a difficulty for Windows systems.  We
would need to have some kind of simplistic "terminal-like" widget derived
from a GUI text box style widget that would gather input and display
the output, but it would likely be simpler than creating a vt100
emulator.  My example code has a very simple version of this based on
the Gtk::TextView widget.

We would also have to solve the problem of reentrancy for the parser.
The parser is not currently reentrant, and using the Bison option to
generate a pure parser will not make reentrant.  So we need to either
avoid calling it to parse different input streams at the same time, or
we have to find a way to make it reentrant.  I think either solution
is possible, and making the parser reentrant would probably be a good
thing anyway.



PNG image

Attachment: gui-with-push-parser.tar.gz
Description: Binary data

reply via email to

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