Wednesday, September 1, 2010

The prototype of C++ syntax directed editor

C++ syntax directed editor was designed to work with C++ programs. Usually we work with a text on a letter's level using an ordinary text editors. C++ syntax directed editor offers another approach: you work with constructions of the language (statements, declarations, functions and so on). See the next picture (to enlarge a picture click on it).

As a consequence you'll make much less lexical and syntax errors, build a syntax tree automatically, resolve coloring problem and so on.
Let's consider the example. When you start a new program(File/New menu) you'll see the image on the next picture.
You can see the image of a second Constructions window on the next picture.

The editor "knows" a current context of C++ program and depicts allowed constructions of C++ language for that context in the Constructions window. Double click "type variables" in the Constructions window. The "declaration" nest will be changed by "type variables" as you can see on the next picture.

Click on "function_definition" nest(see the next picture). The nest is highlighted by blue color.

The content of Constructions window is changed (see the next picture). Double click "WinMain..." in the Constructions window.

The "function_definition" nest will be changed by the construction as you can see on the next picture.

Now it's clear how syntax directed editor works.
After development of incremental expression's parser lexical and syntax errors will be totally under control.
So C++ syntax directed editor is a powerful, convenient, reliable tool. Rich set of commands(more than 40 commands) makes a work with it easy and enjoyable.
The importance of syntax directed editors will be increased with a development of intentional programming (IP).
I give a citation from the article written by Charles Simonyi:
“Probably the least natural aspect of IP seems to be the requirement that the source tree be edited as a structure and not as text.
Users have historically accepted direct manipulation for graphics, for example.
However, when the source data is shown in terms of characters, the tradition has been to edit the source as it were a character stream.
The syntax directed editors have come the closest to approximating the IP editing problem.
In the syntax directed paradigm, the syntax rules are immediately applied to the user’s input, with two important results: first the input of illegal constructions is prevented at the outset; and second, as a result of parsing, the system has knowledge of what has been typed and this knowledge can be used in turn to help the user with prompts, automatic formatting, defaults and so on.
Despite these advantages, syntax directed editing has never been a commercial success.
One can only surmise the reasons for the user’s dislike of such systems, but one good guess is that a successful system should be modeless and intentional.
Modelesssness means that work on one section of the code can be always suspended and the focus transferred to some other portion.
Intentional here means that the editor commands should directly relate to the intentions rather than the representation of the intentions.
Modelessness is important because programs are seldom constructed in a strict order.
The programmer must be able to express code fragments whether or not they make sense in their intermediate forms.
There should be no interruptions, demanding prompts, or beeps.
IP does have two subtle forms of reminders: incomplete operands are typically highlighted in color, and there is also a “To Do” list with current references to all incomplete or otherwise incorrect code as discovered by a background type checker.
After finishing some coding the programmer can simply scan the screen for highlights and then scan the todo list for any remaining errors.
Of course, there will always be a few obscure errors which will be uncovered only during the reduction/compilation of the program.
The editing model is based on the standard cut/copy/paste operations, but with about seven different selection types as opposed to the single text selection used by text editors.
Just one of the selection types, for example, is necessary for selections within constants, names or comments which can all be edited as text.
The other types select subtrees, lists of subtrees, individual nodes, places in lists, and left or right operands for operations.
While this is quite a bit more complicated than basic word processing, the programmer users are well equipped and motivated to handle the conceptual load.
Having a reliable and multi-step undo facility also help create a comfortable environment where the consequences of mistakes are very much limited and where experimentation is encouraged.”

No comments:

Post a Comment