Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!news.iecc.com!.POSTED!nerds-end From: Lee Newsgroups: comp.compilers Subject: parsing function name and arguments Date: Thu, 9 May 2013 04:05:30 -0700 (PDT) Organization: Compilers Central Lines: 70 Sender: johnl@iecc.com Approved: comp.compilers@iecc.com Message-ID: <13-05-005@comp.compilers> NNTP-Posting-Host: news.iecc.com Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: leila.iecc.com 1368195114 12019 64.57.183.58 (10 May 2013 14:11:54 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Fri, 10 May 2013 14:11:54 +0000 (UTC) Keywords: question, parse Posted-Date: 10 May 2013 10:11:54 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: csiph.com comp.compilers:891 Hi all, I am strugling with this simple thing, any help will be greatly appreciated. I would like to extract the name and the argument from the following line: FUNCTION Entry (args) I have the flex file defined as: %{ #include %} T_FUNCTION FUNCTION SYMBOL_ID [a-zA-Z]+[a-zA-Z0-9_]* OPEN_PARA [\(] CLOSE_PARA [\)] WHITE_SPACE [ \t\f\r\v]+ NEW_LINE [\n] %% {T_FUNCTION} { printf("1.yylval = %s\n", yytext); return (FUNCTION); } {SYMBOL_ID} { printf("2.yylval = %s\n", yytext); yylval.all_str = yytext; return (SYMBOLID); } {OPEN_PARA} { return ('('); } {CLOSE_PARA} { return (')'); } {WHITE_SPACE} { } <> { yyterminate(); } . { printf("3.error_msg = yytext : %s\n", yytext); return(0); } %% int main() { printf("Starting...\n\n"); return yyparse(); } and the grammar as: %{ void yyerror(char *s); %} %union { int intnum; char *all_str; } %token FUNCTION %token SYMBOLID %type program %start program %% program : FUNCTION SYMBOLID '(' SYMBOLID ')' { printf("FUNCTION SYMBOL = %s\n", $2); printf("func name and args: '%s' '%s'\n", $2, $4); } ; %% void yyerror(char *s) { printf("Errors\n"); exit(1); } The lexer is extracting corectly the tokens but not the grammar. I'am using flex and bison from GNUWin distribution (tested on ubuntu same result). Thanks, Lee