The Development Environment
Introduction
Depot4 is a translator generator. It behaves quite similar to an ordinary programming environment, just
terminology differs somewhat. What is usually called a programming language is now the meta language (Ml4).
And what you know as compiling is said to be implementation (or even translation ).
If all needed rules have been translated successfully, you can apply
(or use) your newly generated translator - quite similar to running a compiled program.
It's essential to distinguish both phases clearly to avoid misunderstanding.
Depot4/Java IDE Interface
The Depot4/Java IDE is an integrated development environment (IDE) for developing
and applying (domain specific language) translators.
The main frame consists of the following primary components:
- The Work cards area. Each work card contains at least one or two editing areas.
- The Menu bar appears at the top of the main frame and contains menu titles, which describe the
content of each menu. Most menu actions apply to the currently active editing area.
- The system's logging text area.
Menu bar
The menu bar contains the following menus:
top
Work Cards
Each work card consists of one or two text editor areas. The currently active area is marked by
highlighting its border.
These are the standard work cards:
There are some more work cards available:
- Dp4.ide.Counts
- Counts the occurrences of the nonterminals (nodes of the syntax tree); gives also the maximal height
of this tree and displays these numbers in the log area.
- Dp4.ide.Tree
- Displays the syntax tree of the parsed input (by means of indentation) in the log area.
- Dp4.ide.AST
- Displays the abstract syntax tree of the parsed input (very similar to Tree) in the log area.
- Dp4.ide.ASTXML
- Displays the abstract syntax tree of the parsed input as a XML structure in the log area.
top
The menus
- File
- Standard menu group, consisting of
- New
- Clears the active editor pane and its (eventually) associated file name.
- Open
- Displays a file selection dialog and loads the selected file's content into the editor pane.
- Save
- Opens a file selection dialog and save the active editor pane's content in the selected file.
- Print
- Prints the active editor pane's content.
- Quit
- Quits the application. (There is no warning regarding unsaved editor panes.)
All but the Quit action are not enabled if there is no current active editing area.
The New and Open actions are enabled only if the editing area is a source text area.
- Edit
- The Edit menu is enabled only if there is a current active editing area.
This standard menu group consists of
- Clear
- Clears the active editor pane but does not change any (eventually) associated file name.
- Undo Clear
- Undoes one preceding clear operation.
- Cut
- Copies the selected text stretch into the system clipboard and clears the selection.
- Copy
- Copies the selected text stretch into the system clipboard.
- Paste
- Pastes the clipboard contents.
- Goto
- Moves the cursor to the required position. This is useful as the translator emits error positions.
If there is a text selection that is long enough the position is computed from the begin of the selection.
(This is useful as with Translate Selected the error position will be relative to the start of
the selection.)
- Find...
- Simple search for a certain string.
- Find again
- Redo the last search.
- Font
- Opens submenus for selecting font face, font size, and font style.
- Translate
-
- All
- Starts the translation taking the source text pane of the current work card as input. Actual
execution depends from this card.
- Selected
- As before, but only the selected text stretch is processed. (Hint: Any error positions are locally to
this selection then.)
- List all nonterminals
- Logs the list of all currently known nonterminals and their implementing classes into the log area.
(There is an own list for every work card.)
- Options
- The Options menu contains a number of check boxes to enable/disable options:
Case sensitive: If not checked, upper and lower case characters in identifiers are considered equal.
Check enabled: If checked, an additional check against unbounded recursion will be done.
Trace: If checked, every invocation of a nonterminal will be logged on entry and exit.
Warnings (only for Ml4 translation): Logs some warnings that may be useful for fixing problems.
Verbose Compiling (only for Ml4 translation): Sets the -verbose
switch for the Java compiler.
Logging: Offers a sub-menu for more individual logging.
- Window
- Contains actions to add and delete different work cards. It is possible to add customized cards with the
Add ... card action. (Examples:
Dp4.ide.Counts
, Dp4.ide.Tree
,
Dp4.ide.AST
, Dp4.ide.ASTXML
)
Save card settings: Save the current card settings (including fonts) to a local configuration file.
- Debug
- The Debug menu is only enabled if a Debug work card is selected.
- Breakpoints
- Opens the Breakpoint dialog. Breakpoints may be set on entry and exit of a nonterminal
implementation only.
- Info
-
- Help IDE
- Shows this text.
- Help Ml4
- Shows the Ml4 syntax definition.
- Getting started...
- Explains first steps using a simple translation example.
- About...
- See the about box, which includes current settings and heap usage.
top
The Work Cards
Mostly, you look for a translator generator because you want to do some translation. So one usually
starts with defining the translator. This is by no means an easy job but a tool like this may be helpful.
Depot4 is a nonterminal based system, i.e. all rules for a single nonterminal are collected in one
production. Such productions constitute the basic entities, which the generator handles.
See Ml4 Syntax for a short description of the Ml4 language.
Converting the Ml4 description of a translation rule into an executable form takes two steps. First a
Java class definition is generated. Then the Java compiler is called. Usually, this should be of
little interest for the user. (As nobody wants to be bothered with object formats when using a compiler.)
The only difference is that there may occur error messages from the Java compiler. As most of the
possible faults are caught by the Ml4->Java translator this happens seldom. The most likely reasons
are the use of Java keywords (such as do
) as identifier (this will be caught in a future
version) and parameter mismatch with imported objects.
If the translated rule was already loaded it will be reloaded before it is applied again in a Use action.
top
This allows the joint implementation of a list of Ml4 descriptions. Thus, the text area does not contain
any Ml4 text but the respective file names.
There is an additional button Add File which allows you to select files individually by use of
the standard file dialog. Their names are appended to the content of the text area. You can save
and reload this list as an ordinary text file.
Hint: With some earlier Java version multiple file selection does not work. Add the files one by one then.
top
This is the mode of applying a generated translator. A translator is defined by the name of its root production.
You can prefix the root production with its package name (if it was generated this way). This package name
is added to the module search paths automatically then.
Input is taken from the Source text area, which therefore must own the focus border. Any output, i.e., the first
target of the root production, will be displayed in the Target area.
Remark: The interface as it is, doesn't fully exploit Depot4's
capabilities. Only one target will be displayed (up to eight are possible) and you have to save it explicitly.
Let us mention again that this interface is just one way of using translators. One can also use the translators
from within any
other Java program by calling the translation method of Depot4's runtime. There is just the need to apply
the constructor of the source object before. (For more detail, have a look into the code of Dp4Run.java,
which is contained in the archive of the at top level sources.)
One can set Ml4jT as the root and write some Ml4 code in the Source area to see how it is translated into Java.
top
Debug
This is an
additional frame that allows you to set breakpoints at entrance and/or exit of every called production. (
It is possible to stop at every second, third, ... call only, too.) Type the name in the text field, check/uncheck
the on entry/on exit boxes and press the "add" button. Doing this again for the same name will change
previous settings. Unchecking both boxes is similar to removing a breakpoint.
The function of the "Go" buttons is the same as that of the "Do" one on the Debug card. They are there just for
your convenience.
At breakpoints one more frame appears. Pressing its buttons causes the display of information in the Log.
One can inspect the current position, the nonterminal's implementation target name (...where the code
comes from), the JVM stack trace, the call stack of the parser, and - but only on exit, of course -
the accepted source text and the generated target.
You can change breakpoint settings by pressing the "add" button with the new settings again.
top
©J. Lampe 2002-2010
(31.05.2010)