Xref: utzoo comp.unix.questions:25115 comp.misc:9964 Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!know!zaphod.mps.ohio-state.edu!usc!snorkelwacker!bloom-beacon!eru!hagbard!sunic!sics.se!uplog.se!uplog.uplog.se!thomas From: thomas@uplog.se (Thomas Tornblom) Newsgroups: comp.unix.questions,comp.misc Subject: Re: File I/O with lex/yacc Message-ID: Date: 30 Aug 90 08:38:01 GMT References: <2320@cirrusl.UUCP> <1990Aug29.122152.1600@virtech.uucp> <1990Aug29.172830.14348@cunixf.cc.columbia.edu> Sender: thomas@uplog.se (Thomas Tornblom) Organization: TeleLOGIC Uppsala AB Lines: 46 In-Reply-To: gld@cunixd.cc.columbia.edu's message of 29 Aug 90 17:28:30 GMT In article <1990Aug29.172830.14348@cunixf.cc.columbia.edu> gld@cunixd.cc.columbia.edu (Gary L Dare) writes: Is there any way to get around the use of standard input/output in a lex file??? The C file generated by lex (from the lexical analyzer spec you feed in) has the following line hard-coded: FILE *yyin = {stdin}, *yyout = {stdout}; however, there doesn't seem to be a way to sneak in a redefinition of yyin or yyout as a pointer to a file (a single, in-line statement) except by hand, 'cos a switch{} is generated in C from the lexical analysis rules. If you want to have yyin and yyout set to something else, just fopen() them to whatever file you want before calling yylex(). Is there any way to force a single, inline statement into the C file generated by lex, other than by hand? I'm not sure I know what you mean by this. You can put inline code almost wherever you want. In the definitions part you can: %{ #include ... [whatever] %} In the rules part you can have C code that executes whenever the rule is matched. ^foo {printf("matched foo at beginning of line\n"); } and in the subroutine part you can stick in c code. -- Real life: Thomas Tornblom Email: thomas@uplog.se Snail mail: TeleLOGIC Uppsala AB Phone: +46 18 189406 Box 1218 Fax: +46 18 132039 S - 751 42 Uppsala, Sweden