[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: parser : which library ?
- From: Gaspard Bucher <gaspard@...>
- Date: Wed, 1 Jun 2011 00:03:05 +0200
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* '}';
}%%
It is not very readable like this, but once you have some colors, it is manageable and easy to maintain/adapt.
Gaspard
On Tue, May 31, 2011 at 1:35 AM, Valerio Schiavoni
<valerio.schiavoni@gmail.com> wrote:
Hello,
I have to realize a parser for a simple language to describe network
topologies.
The language is made by nodes and links between nodes, and it is
described by this document:
http://www.scribd.com/doc/54853179/59/Description (page 34 and 39,
respectively).
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
libraries
to facilitate this task ?
Thanks for your suggestions,
Valerio