Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compilers > #891

parsing function name and arguments

From Lee <lchaplin13@gmail.com>
Newsgroups comp.compilers
Subject parsing function name and arguments
Date 2013-05-09 04:05 -0700
Organization Compilers Central
Message-ID <13-05-005@comp.compilers> (permalink)

Show all headers | View raw


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 <fct.tab.h>
%}
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}   { }
<<EOF>>         { 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 <all_str> SYMBOLID
    %type <program> 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

Back to comp.compilers | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

parsing function name and arguments Lee <lchaplin13@gmail.com> - 2013-05-09 04:05 -0700
  Re: parsing function name and arguments Hans Aberg <haberg-news@telia.com> - 2013-05-10 22:24 +0200

csiph-web