[plug] Writing a language?

Bernard Blackham bernard at blackham.com.au
Mon Jun 16 11:08:44 WST 2003


On Mon, Jun 16, 2003 at 01:36:49AM -0000, Simon Scott wrote:
> Just wondering if anyone here has any experience in writing languages?

Well not writing a language, but I have had the joy/pain of writing
a parser for a language.

> I need to construct a fairly minimal language for a project, but need a nudge
> to get started (it keeps falling into the 'too hard basket').
> 
> The main difficulty I would have I imagine would be parsing and checking
> syntax.... Are there any examples/libraries for parsing freeform text?

The work I did was based around using flex(1). It takes a bit of
getting your head around, but probably makes things easier in the
long run. 

The way I had it working, was...
  1) you have a lexer input file, which maps tokens of your language
     to some compilable language of your choice (C/C++ works well).
  2) you run this lexer file through flex/flex++, which generates a C/C++
     program that will parse your input.
  3) you link this program against your other helper libraries.
  4) you pass your source code for your theoretical language through
     your compiled parser, to generate compilable source code in the
     language you chose in (1).
  5) compile that :)

This was for a basic -> C++ converter, which never did get finished,
but will need to be soon. *sigh*

The info pages for flex should give you a better idea, or scare you
completely, if I haven't already :)

HTH,

Bernard.

-- 
 Bernard Blackham 
 bernard at blackham dot com dot au



More information about the plug mailing list