lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Hi !

Why put PDF documents on scribd ? It's full of annoying ads, impossible to download and it is hard to copy paste... Anyway, in your position, I would use a Ragel: it takes a single regular _expression_ with C callbacks and generates C code. Here is an example of for your task:

  ws       = ' ' | '\t' | '\n';
  var      = ws* ([a-zA-Z_][a-zA-Z0-9_:]*) $str_a;
  value    = [0-9]+;
  node_identifier = var %node_identifier;
  type = ws* ('host'|'router'|'PC'|'lanswitch'|'rj45');
  cpu  = ws+ '[' ws* ('min' value %min_value ws+)? ('max' value %max_value ws+)? ('weight' value %weight_value)? ws* ']';
  nodes := 'node' ws node_identifier ws* '{' type cpu? ws* '}';

And here is another example for the full syntax for the SQLiss pseudo SQL language used in Zena (not a toy language!):

It is not very readable like this, but once you have some colors, it is manageable and easy to maintain/adapt.


On Tue, May 31, 2011 at 1:35 AM, Valerio Schiavoni <> wrote:
I have to realize a parser for a simple language to describe network
The language is made by nodes and links between nodes, and it is
described by this document: (page 34 and 39,

The grammar is quite compact, and a simple pattern matching using the classical
regular _expression_ support in Lua might suffice to build an in-memory
representation of a topology.

I was wondering if better alternatives exist nowadays: how about the
lpeg library ? Is it appropriate ?  Are there other well-known
to facilitate this task ?

Thanks for your suggestions,