Xref: utzoo comp.lang.c:38723 comp.unix.questions:30765 comp.unix.wizards:25152 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!apple!motcsd!mcdcup!mcdchg!marcal!odgate!mike From: mike@odgate.odesta.com (Mike J. Kelly) Newsgroups: comp.lang.c,comp.unix.questions,comp.unix.wizards Subject: Re: lex and yacc help desired Message-ID: <1991Apr25.204908.21654@odgate.odesta.com> Date: 25 Apr 91 20:49:08 GMT References: <1991Apr23.164744.25927@mnemosyne.cs.du.edu> Organization: Odesta Corporation, Northbrook IL. Lines: 27 In article <1991Apr23.164744.25927@mnemosyne.cs.du.edu> allen wade writes: >I am fairly new to Lex and Yacc and I am tring to develop a >language definition for a small report processer. > My input lines will generally look like this: > >|MEDINA|ANTOINIO|01/14/62|M|(312)778-2540|60629|GARFIELD|LAREN|GP|DC101A| > You could use Yacc to parse this, but it's really overkill. scanf(3) would work as well, or at worst, just read the line into a string and use the string package to separate out the components; look at strtok(3) and strchr(3). If you really want to use Yacc, what I'd do is write a simple lex which returns four types of tokens: TOK_DATE, TOK_PHONE, TOK_NUM and TOK_STRING. Then your yacc grammar is: statement: TOK_STRING '|' TOK_STRING '|' TOK_DATE '|' TOK_STRING '|' ... { last_name = $1; /* first field */ first_name = $3; /* second field */ bday = $5; /* third field */ . . . }