[svlug] Lex question about variable length fields

Ivan Sergio Borgonovo mail at webthatworks.it
Thu May 22 17:01:24 PDT 2014

On Thu, 22 May 2014 15:33:25 -0700
Bob Smith <bsmith at linuxtoys.org> wrote:

> Ivan Sergio Borgonovo wrote:
> > It'd be clearer if you could make an actual example and the expected
> > result (parser tree)
> Jesse, Ivan, thanks for your replies.  Yeah, my original post
> was pretty vague.  Let me try again.
> I would like to get three single word tokens followed by a fourth
> token that is whatever is left on the input line.  So, the input
> line "My name is Jabba the Hutt" would return tokens
> "My",
> "name",
> "is", and
> "Jabba the Hutt".
> The last token looks like several words and when I write the lex
> rules to pick up more than one word, it picks up the whole line.

We're getting nearer.
It's not clear if what precede the name (Jabba the Hutt) has a
particular structure or it has a fixed number of tokens or if the name
itself (Jabba the Hutt) has a particular structure.

Otherwise understanding when the "before the name" end and where the
"name" start is impossible.

BTW lex/bison/yacc and Co. don't ignore \s (or punctuation) by default,
you've to explicitly tell them so.

BTW are you sure you need a full fledged parser and not just a regexp?

Ivan Sergio Borgonovo

More information about the svlug mailing list