help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Useless nonterminals - what and why?


From: Matthew Palmer
Subject: Useless nonterminals - what and why?
Date: Sun, 19 Nov 2000 01:11:48 +1100 (EST)

OK, hacking on somebody else's bison file, and I have gotten this message. 
Not real sure exactly what it means, beyond a definition somebody gave that
"A useless nonterminal is one which doesn't produce any strings" or similar.

I will admit that I am an absolute newbie on matters of Bison and parsers
and grammars and all the rest of this stuff.  I'm hacking on this to add new
functionality (HTTP proxy support to a program which uses HTTP to transfer
stuff) by copying the nearly identical functionality involved in parsing a
HTTP URL.  That stuff, incidentally, compiles and works fine... Argh...

The appropriate parts of the code:

%union {
  sa_list_t *sa_list;
  /* others */
}

%token <longval> PORTNUM_TOK
%token COLON_TOK

%type <sa_list> http_proxy_list http_proxy

%start start

start:  /* other rules */
        | http_proxy_list
          {
            /* Do stuff like other rules */
          }
        | /* other rules */

http_proxy_list: http_proxy_list http_proxy
                 {
                   sa_list_t *addrs;

                   addrs = sa_union($1, $2);
                   sa_list_free($1);
                   sa_list_free($2);
                   $$ = addrs;
                 }

http_proxy:     host opt_port
                {
                  long port;
                  sa_list_t *addrs = NULL;

                  port = ($2 != 0 ? $2 : DEFAULT_HTTP_PROXY_PORT);
                  dns_add_host(&addrs, $1, port);
                  mem_free($1, strlen($1)+1);
                  $$ = addrs;
                }

opt_port:       COLON_TOK PORTNUM_TOK
                {
                  $$ = $2;
                }
                |       /* empty */
                {
                  $$ = 0;
                }                                                               
                 








reply via email to

[Prev in Thread] Current Thread [Next in Thread]