How to use flex option -o (--output=FILE)
Asked Answered
C

1

6

I met a problem when trying to flex abcd.l. I wanted to redirect the output to a new file instead of the default one lex.yy.c I looked up it in manual finding an option -o(--output=FILE) so I changed my command to flex xx.l -o lex.yy.1.c but error occurs.

flex: can't open --outfile=lex.yy.1.c
/usr/bin/m4:stdin:2621: ERROR: end of file in string

My working environment is cygwin and windows 7

Crumpton answered 25/8, 2015 at 6:45 Comment(0)
N
12

You need to put command line options before positional arguments:

flex -o lex.yy.1.c xx.l

Once a positional (filename) argument is recognized, flex assumes that all following arguments are also filenames. This is the normal form of argument processing for command-line utilities, although some (gcc, for example) allow options to follow the filenames.

(Personally, I'd suggest using a filename like xx.lex.c, but the principle is the same.)

Noblewoman answered 25/8, 2015 at 14:53 Comment(3)
For me, even flex -o azure_lexer.lex.c azure_lexer.l is giving error C:\GnuWin32\bin\flex.exe: can't open azure_lexer.lex.cGull
@SouravKannanthaB i'm getting exactly same error. Did you find any fix?Josie
@Josie Instead of using command line args for specifying file name, I now use %option outfile="xx.lex.c" from within the .l file. here. Also, note that, command line arg is --outfile="xx.lex.c" and not -o xx.lex.c. (My bad, -oxx.lex.c is also allowed, with no spaces.)Gull

© 2022 - 2024 — McMap. All rights reserved.