[svlug] Lex question about variable length fields

Ivan Sergio Borgonovo mail at webthatworks.it
Wed May 21 16:43:27 PDT 2014


On Wed, 21 May 2014 12:12:01 -0700
Bob Smith <bsmith at linuxtoys.org> wrote:

> Anyone here remember Lex?
> 
> I'm writing a parser in which the end of line can
> have a random ASCII string with spaces, tabs, and
> commas.  What I want is a grammar something like:

> command:
>    WORD WORD WORD WORDS_TO_EOL
>    ;

It's not clear if you want a fixed numbers of words, if [\t, ]
aren't meaningful for the whole grammar or just in a "command".
Furthermore it is confusing why you're referring to lex for the
grammar.

It'd be clearer if you could make an actual example and the expected
result (parser tree)

Should something like

word,word\tword word , word\t, \tword\n

be valid?

Do you need to digest each "word" as a separate token? Are [\t, ]
significative?

A starting point for your grammar could be:

command
    : sentence EOL
    ;
sentence
    : sentence word
    | word
    ;

-- 
Ivan Sergio Borgonovo
http://www.webthatworks.it





More information about the svlug mailing list