Path: utzoo!attcan!uunet!samsung!aplcen!haven!wam!dkim From: dkim@wam.umd.edu (Daeshik Kim) Newsgroups: comp.lang.c Subject: Re: yacc sorrows Message-ID: <1990Feb8.035311.6506@wam.umd.edu> Date: 8 Feb 90 03:53:11 GMT References: <7179@arcturus> Sender: usenet@wam.umd.edu (USENET Posting) Reply-To: dkim@wam.umd.edu (Daeshik Kim) Organization: Univ. of Md, College Park Lines: 42 In article <7179@arcturus> evil@arcturus.UUCP (Wade Guthrie) writes: > > %{ > #include "y.tab.h" > [...] > %} > [...] > %% > auto { return(AUTO); } > register { return(REGISTER); } > [...] > "->" { return(ARROW); } > ";" { return(SEMICOLON); } > . { return(yytext[0]); } > If you need to pass a value to 'yacc', then do the following: somestring { yylval.sval=(char*)malloc(yyleng); strcpy(yylval.sval, yytext); return(TOKENNAME); } someinteger { yylval.ival=atoi(yytext); return(TOKENNAME); } ... Note that "yyval" is the type defined by "%union ....". In the above example, in 'yacc' def, %union { int ival; char *sval; } scan over c code from lex. -- Daeshik Kim H: (301) 445-0475/2147 O: (703) 689-5878 SCHOOL: dkim@wam.umd.edu, dskim@eng.umd.edu, mz518@umd5.umd.edu WORK: dkim@daffy.uu.net (uunet!daffy!dkim)