On Wed 2008-08-27 at 08:37h, Javier Abdul Cordoba Gandara wrote on 
sablecc-discussion:
> 
>       I think you're referring to the backend :) 
> I'm overriding the Lexer, it's just I didn't explain it well. 
> In your implementation, the structure you had to map was
> static or dynamic (tree-like)? I'm considering Sablecc 
> because we have a family of formats, but they are 
> lexically the same.
> 
>       Any other suggestion?

Suggestion 1: If the set of possible "length" values is not too large,
you could write (or have auto-generated) a grammar with a rule for
each length value. Something like:

   len01 = '01';
   len02 = '02';
   len03 = '03';
   :

   segment = len01 byte
           | len02 byte byte
           | len03 byte byte byte
           :

And then use CST->AST conversion to turn it into a simple list of
bytes.

Suggestion 2: If the formats are sufficiently generic, write a
dumb preprocessor which replaces the length values with a suitable
end-of-segment marker (or some sort of segment quoting syntax),
then use SableCC to parse the result.

Otherwise it's probably really simpler to just write a parser by hand.

-- Niklas Matthies

_______________________________________________
SableCC-Discussion mailing list
[email protected]
http://lists.sablecc.org/listinfo/sablecc-discussion

Reply via email to