help-bison
[Top][All Lists]
Advanced

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

Is it always possible to make a non-reentrant parser reentrant?


From: Peng Yu
Subject: Is it always possible to make a non-reentrant parser reentrant?
Date: Thu, 7 Feb 2019 19:01:49 -0600

Hi,

The bash parser uses global variables and it also uses lexical freeback.

For example, to deal with heredoc in bash, the grammar rule will change the
variable `need_here_doc` via `push_heredoc()`.

```
    |   LESS_LESS WORD
            {
              source.dest = 0;
              redir.filename = $2;
              $$ = make_redirection (source, r_reading_until, redir, 0);
              push_heredoc ($$);
            }
```
http://git.savannah.gnu.org/cgit/bash.git/tree/parse.y#n539

```
static void
push_heredoc (r)
     REDIRECT *r;
{
  if (need_here_doc >= HEREDOC_MAX)
    {
      last_command_exit_value = EX_BADUSAGE;
      need_here_doc = 0;
      report_syntax_error (_("maximum here-document count exceeded"));
      reset_parser ();
      exit_shell (last_command_exit_value);
    }
  redir_stack[need_here_doc++] = r;
}
```

http://git.savannah.gnu.org/cgit/bash.git/tree/parse.y#n2794

`need_here_doc` is used in `read_token()`, which is called by
`yylex()`. This makes the behavior of `yylex()` non-automomous.

It seems to me that the parsing code could be made simpler by making
the parser reentrant. So there can be a parser parses anything not
heredoc and another parser just parse heredoc. And there should
different lexers for non-heredoc and heredoc. Is it so?

Does anybody have any suggestions on how to make the parsing code more
manageable?

````
      if (need_here_doc)
    gather_here_documents ();
````
http://git.savannah.gnu.org/cgit/bash.git/tree/parse.y#n3285

````
  current_token = read_token (READ);
````

http://git.savannah.gnu.org/cgit/bash.git/tree/parse.y#n2761

-- 
Regards,
Peng



reply via email to

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