Monday, April 23, 2007

Dealing with Flex generated scanner memory (part 2)

In a previous post, I discussed about my problems with flex scanner's memory. The procedure I was using for manually releasing memory did not seem to be enough since there were still 4 bytes leaking.

Basically, the solution was simpler than I thought: you just need to call

after the lexer finished (for instance, after the call to yyparse()). You can also remove the <> rule (unless you need it to do specific tasks, but not for destroying the scanner!).

This solved all my problems :-)

Saturday, April 07, 2007

SourceHighlightIDE: an IDE for Source-Highlight

I've just released a new software: SourceHighlightIDE, an IDE for GNU Source-highlight (given a source file, produces a document with syntax highlighting).

Sourcehighlightide home page is

You can download sourcehighlightide from

You can find installation and usage instructions in the on-line manual.

Source-highlight reads source language specifications dynamically, thus it can be easily extended (without recompiling the sources) for handling new languages. It also reads output format specifications dynamically, and thus it can be easily extended (without recompiling the sources) for handling new output formats. The syntax for these specifications is quite easy (take a look at the manual).

Sourcehighlightide is useful when you have to develop a new language definition file for source-highlight. A language definition file makes use of regular expressions, and if they become complex it might be hard to understand how they are matched. Source-highlight already provides some mechanisms for debugging a language definition file; Sourcehighlightide provides a graphical interface to debug a language definition file: it will show which regular expression is matched during the formatting of the input file, and you can process the input file step by step (i.e., an expression at time), and you can also see the output while it is produced.

As you can see from the following screenshot, Sourcehighlightide is a MDI (Multi Document Interface) application, so you can have many files open at one time. Moreover, it provides the basic commands that are common to every GUI application, so we will assume their knowledge throughout this manual.
In the screenshow we see two opened editor windows.

The files that you open with the standard Open commands (or that you create with the New command) are intended to be language definition files for Source-highlight (we refer to Source-highlight manual for further details about such files). This file is shown in the left text area of the editor window.

You start debugging by using the button "Debug" (instead of "Update"), and then press "Step" for formatting element by element the parts of the input file that is to be formatted. You can interrupt the debugging by toggling the button "Debug" again. The debugging steps at each matched regular expression and the one that was matched is shown highlighted in the text area of the language definition file. The "Formatted" tab shows the parts of the input file that are already formatted. In the screenshot above we have just matched a quoted string inside an #include environment.

Notice that if the language definition file includes another one, the editor window will open the included file containing the current matched regular expression.

I developed SourceHighlightIDE for developing new language definition files for Source-highlight, and in particular to debug these language definitions. Some users of Source-highlight often send me new (or modified) language definitions, and I hope SourceHighlightIDE is useful for them too.