views:

47

answers:

1

I'd like to use lex/yacc to read in a delimited text file. This would be pretty trivial stuff for a parser, but different text files have different delimiters, so I'd like to let the user specify whether the text is separated by tabs, spaces, commas, pipes, unicode snowmen, et cetera.

The normal means of using these tools is to write a spec for lex and yacc, compile, and then use the static code for parsing. But is there a way to let the user specify the delimiter (and thus redefine the tokens) at run time?

I'm currently using flex/bison, but am open to suggestions of small and portable alternatives.

A: 

No, there isn't any way to do this. Lex and Yacc create the lexer or parser tables as part of a C program, so you can't alter it after it has been created.

It's not exactly clear what format you need to parse, so without examples I won't make any suggestions.

Kinopiko