>>> I don't want to call "rs_init(&yylval->str)" in any action.
> You don't have to do that in every action, just the ones returning strings.
I don't get the point.
Is there a problem to not call "rs_init(&yylval->str)" in any action
(this include the actions that return strings)?
--
Regards,
>
> C++ is too verbose, generate bloated binary and takes long time to compile.
Any reason that you don't want to use C++ and e.g. std::string instead of
> your
> pure C and garbage collector solution?
>
--
Regards,
Peng
___
help-bison@gnu.org https://l
Hi,
I have the following toy flex code to generate a lexer.
I use rapidstring to make the string operations use and use the Boehm
garbage collector so that I don't have to always remember to release
the memory.
https://github.com/boyerjohn/rapidstring
Because I want to use the previously alloca
This lexical tie-in creates feedback from the parser to the lexer. So
the lexer cannot be tested standalone.
But the principle of separating lexer and parser is to make parser
builtin on top of the parser. Is there something that can avoid the
feedback yet still allow context-dependent parsing? Al
still spit the ASSIGNMENT_WORD but do more internal work
to deal with the actions of the assignment and nested parameter
expansions.
What do you think the best implement should be in this case?
On Sun, Feb 17, 2019 at 8:44 AM Akim Demaille wrote:
>
> Hi!
>
> > Le 17 févr. 2019 à 14:08,
Hi,
The more I study flex/bison, the more confused I got about when to use
what actions and what to put in lexer and what to put in grammar.
For example, for an assignment,
x=10
it can be processed by the lexer,
[[:alpha:]_][[:alnum:]_]=[[:digit:]+] { /* parse yytext to get the
name and value
> We should probably offer an example of a pull parser in examples/c.
> Have a look at the documentation to have an idea of what I mean.
OK. I will take a look at it.
Bash uses one parser to deal with both interactive run and
non-interactive run and uses a global variable to test whether the run
> I have no idea. You'd have to study the grammar to see if there
> are doing fancy things around yacc_EOF.
declare -p BASH_SOURCE
Here is what I got with the above one line bash code (with the newline
at the end).
The lines with -> are the parsing rules activated. The rest lines are
yylex() re
Hi,
Since flex does lexical analysis which is before parsing, logically,
it should be that bison includes output from flex.
But the reality is flex using y.tab.h generated by bison which
reverses the dependency relation. This looks weird.
Why is it so?
--
Regards,
Peng
___
Hi,
yacc_EOF instead of 0 is used in `yylex()`.
http://git.savannah.gnu.org/cgit/bash.git/tree/parse.y#n3257
The grammar explicitly relies on yacc_EOF.
http://git.savannah.gnu.org/cgit/bash.git/tree/parse.y#n376
But this seems to be different from the normal usage in flex/bison.
For example, f
Hi Simon,
> Normally, you'd use lexer states to activate/deactivate rules. The
> primitive approach would be
>
> %x INITIAL HEREDOC
I see %x is from flex. Bash can support nested heredoc. How can it be
implemented in flex?
> and then prefixing all matches with or .
>
> The main problem there is
On Thu, Feb 7, 2019 at 11:49 PM Akim Demaille wrote:
> Hi Peng,
>
> > Le 8 févr. 2019 à 02:01, Peng Yu a écrit :
> >
> > [...]
> > For example, to deal with heredoc in bash, the grammar rule will change
> the
> > variable `need_here_doc` via `push_hered
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.file
> 256 is the error token, and 257 is the undef token (when we receive unknown
> tokens from yylex).
>
> 256 is mandated by POSIX :
>
> https://pubs.opengroup.org/onlinepubs/007904875/utilities/yacc.html
>
> > The token error shall be reserved for error handling. The name error can be
> > used in
> It's been a while, but as far as I can remember those extra 2 are always
> automatically used for the special built-in terminals YYEOF and YYEMPTY.
No. They are not.
y.tab.c
1249:#define YYEMPTY (-2)
y.tab.c
1250:#define YYEOF 0
--
Regards,
Peng
Hi,
I don't quite understand why tokens are numbered starting from 258.
What are 256 and 257 for? Thanks.
#define IF 258
--
Regards,
Peng
___
help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison
Hi,
I see both yytokentype and the corresponding macro definitions in
y.tab.h. It sounds like just one of them will be sufficient. Why are
there both of them?
/* Token type. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
enum yytokentype
{
IF = 258,
/* Tokens. */
#define IF 258
--
Regar
>
>
> So far, there's no way to get a modular description of the grammar.
> There is definitely interest for it, but a clean solution remains
> to be designed.
Why is it so? Is because the grammar spec usually is not a DAG?
But there should be ways to introduce more nodes to make a non DAG to DA
On Sun, Jan 6, 2019 at 8:45 AM John P. Hartmann
wrote:
> Your concern is with managing such a large grammar, right?
Yes. Mainly for testing.
There is no law against splitting the larger productions into separate
> files and use the C preprocessor before passing the file to Bison. You
> would
Hi,
I only see bison examples in which all the grammar rules are in the
same file. And all the rules must be tested as a whole.
For example, the following one is of over 6000 lines.
http://git.savannah.gnu.org/cgit/bash.git/tree/parse.y
Having a very large parser file makes it hard to understan
In Levine' flex & bison book, it mentioned "As should be apparent by
now, the C++ support in bison is nowhere near as mature as the C
support,..." on page 241 (Chapter 9).
I'm still learning bison and haven't finish reading all the previous
chapters. Could somebody point to me explicitly in what a
On Sat, Jan 9, 2010 at 11:00 AM, John R. Levine wrote:
>> I have never used soelim before. I have been looking for some
>> introductory material on it, but I don't find anything useful. (The
>> man page is too terse and hard for me to figure out how to use it if I
>> know nothing about it).
>
> Th
On Tue, Dec 29, 2009 at 11:17 PM, John Levine wrote:
>>I just start reading the book "flex & bison Text Processing Tools" by
>>John Levine. Please excuse me if I ask some question that are
>>available somewhere in the book. When the grammar become huge, it
>>would be inconvenient put all BNFs in a
I see bison++ lex++ tutorial in the following webpage. I contact the
author of the tutorial. But he doesn't know where the official
websites are.
http://www.mario-konrad.ch/index.php?page=20024
The tutorial pointed the following wiki page for flex++.
http://en.wikipedia.org/wiki/Flex%2B%2B
Is th
I want to learn to generate parser in C++. However, the book by Levine
only mentioned C++ in the last chapter, Chapter 9. All the examples in
Chapter 1-8 are in C. Instead of reading the book in order, could
somebody let me know if there is a faster way to learn bison to
generate parser in C++?
ht
I want to get words from a file and print them out. But I'm not sure
how to make yylval a pointer to the string yytext. Could somebody let
me know how to modify the following code so that the string can be
retrieved the symbol WORD.
>yylval_string.l
%option nodefault
%{
# include "yylval_string.ta
mbers:
NUMBER { printf("NUMBER = %d\n", $1); }
| numbers NUMBER { printf("NUMBER = %d\n", $2); }
;
%%
main()
{
yyparse();
}
yyerror(char *s)
{
fprintf(stderr, "error: %s\n", s);
}
> On Wed, 30 Dec 2009 09:39:30 -0600, Peng Yu wrote:
>> On
what I should use to replace the line '.{ yyerror("mystery character
%c\n", *yytext); }' in order to catch errors.
%option nodefault
%{
# include "yylval_string.tab.h"
%}
%%
[0-9]+ { yylval=atoi(yytext); return NUMBER; }
[[:space:]] { /*SPACE*/ }
. { yyerror("myst
I have the source files listed at the end of the message. I basically
want to parse a file with only numbers (separated by spaces) and print
the numbers out. It is an overkill to use bison/flex. But I just want
to try how to use bison/flex.
I need to understand how to debug the program. Could some
On Tue, Dec 29, 2009 at 2:49 AM, Hans Aberg wrote:
> On 29 Dec 2009, at 03:54, Peng Yu wrote:
>
>> It seems to me that to use bison I have to have a BNF first. I'm
>> reading Programming Language Pragmatics 3rd Ed (PLP3). What is not
>> clear to me is that how to con
On Tue, Dec 29, 2009 at 2:49 AM, Hans Aberg wrote:
> On 29 Dec 2009, at 03:54, Peng Yu wrote:
>
>> It seems to me that to use bison I have to have a BNF first. I'm
>> reading Programming Language Pragmatics 3rd Ed (PLP3). What is not
>> clear to me is that how to con
It seems to me that to use bison I have to have a BNF first. I'm
reading Programming Language Pragmatics 3rd Ed (PLP3). What is not
clear to me is that how to construct the BNF for a language? Based on
my reading of PLP3, I haven't found a formal way to construct BNF.
What I understand is that, to
I have the following example6.y and example6.l files. The compilation
gives me warnings. I'm not sure where to put '#define YYSTYPE char *'
(it is currently in example6.y). Could somebody let me know? The
example is from http://tldp.org/HOWTO/Lex-YACC-HOWTO-4.html
$./compile.sh
here
example6.l: In
I try to run the example on
http://tldp.org/HOWTO/Lex-YACC-HOWTO-4.html. But I get the following
error. Could somebody let me know what I am wrong?
$ bison -d example4.y
example4.y:24.1-8: syntax error, unexpected identifier:
$ cat example4.y
%{
#include
#include
void yyerror(const char *str)
{
34 matches
Mail list logo