4.2 Editing at Code Level

4.2.1 Code editor

The code editor provides structure editing on each fragment form. In the following a separate code editor is chosen by shift-double-clicking on the program fragment form in the group editor (or using the pop-up menu in the code editor) of Fig. 13.

4.2.2 Structure Editing

The basic idea of structure editing is that the program is manipulated in terms of its logical structure rather than the textual elements such as characters, words and lines. The advantage of this approach is that only logically coherent parts can be inserted or deleted and thereby preserving the syntactical rules of the language at any time.

Figure 19

[4kb 508x246 GIF]

The window above shows an example where a template for a BETA program has been derived. The template includes placeholders (nonterminals) and keywords (terminals). If a nonterminal is selected the mouse pointer is changed to an icon that indicates that the rightmost button of the mouse must be pushed to pop-up a menu (only Unix version, in general the Pop-up Menu Button;.;; is used, see Basic User interface principles). In the example, the <<AttributeDeclOpt>> placeholder has been selected and the legal declarations (according to the BETA grammar) is shown in the pop-up menu.

Figure 20

[6kb 508x246 GIF]

The PatternDecl entry is selected and the result is:

Figure 21

[5kb 508x246 GIF]

4.2.3 Text Editing and Parsing

Structure editing has its greatest force at the higher levels of editing, i.e. for creating the overall structure of the program or for moving around large chunks of code. At the detailed level the textediting technique is more useful.

Text editing can at any time be used as an alternative to structure editing. Text editing is activated either by just starting to type or by selecting the Textedit command in the Edit menu. If you start typing at the keyboard, the typed characters will replace the current selection in the code editor window. Text editing mode may alternatively be entered without deleting the current selection, by means of the Textedit command. In that case the text cursor will be positioned in the start of the current selection.

Text editing mode can be terminated by selecting the Parse Text command in the Edit menu. The possibly modified text will immediately be parsed and any parse errors will be reported (but only one at a time). Note that semantic checking is not done by the editor. In this example a parse error is detected.

In Fig. 17 the placeholder <<NameDecl>> is selected and the name hello is typed. After that the <<DoPartOpt>> is selected and the text

'hello world -> putline

is typed. When textediting is exited the syntax error is immediately reported:

Figure 22

[16kb 731x566 GIF]

4.2.4 Checking

After correcting the syntax error the program looks like below:

Figure 23

[15kb 731x566 GIF]

Now we want to call the checker. This is done by means of the Check Current command in the Tools menu. But the compiler does not accept unexpanded nonterminals. Therefore the following dialog is popped up:

Figure 24

[3kb 278x119 GIF]

Notice that in this example all nonterminals are optionals (is indicated by the Opt suffix). An easy way to remove unexpanded optionals is to select the whole program and use the Remove Optionals in the Edit menu. The result is:

Figure 25

[14kb 731x566 GIF]

Now the checker is called again and the semantic error is detected and shown by means of the semantic error viewer:

Figure 26

[5kb 418x346 GIF]

In this case there is only one semantic error, but in general the Fragment Forms pane will contain a list of fragment forms with semantic errors and the Semantic Errors pane will for each fragment form in the upper pane show a list of semantic errors. By selecting in the two panes the different semantic errors can be inspected. By clicking in the Semantic Errors pane the code editor will select the corresponding structure. The first semantic error will always be selected automatically. In the example the following selection is made:

Figure 27

[15kb 731x566 GIF]


Mjolner Integrated Development Tool - Tutorial
© 1991-2004 Mjølner Informatics
[Modified: Monday March 11th 2002 at 16:16]