List Info

Thread: Using yyparse with command line parameters.




Using yyparse with command line parameters.
user name
2008-01-11 18:55:00
Hi

How I can run bison from C source code passing a string to
parse?

For example I have abcbdc sequence to parse. I can call
yyparse function
passing this string like parameters or directly like
executable parameters
(./parser abcbdc) ?

Many thanks for any suggestion.

Bye
_______________________________________________
help-bisongnu.org http
://lists.gnu.org/mailman/listinfo/help-bison

Re: Using yyparse with command line parameters.
country flaguser name
Germany
2008-01-12 04:39:55
> How I can run bison from C source code passing a string
to parse?

`yyparse' works by calling `yylex' which, in effect, passes
token-value
pairs to `yyparse'.  There is a difference depending on
whether your
parser is reentrant or not.  If it is, `yyparse' doesn't use
global
variables.  Passing a string as an argument to `yyparse' is
not the way
it's meant to be used.  Nor are the token-value pairs passed
back to
`yyparse' as the return value of `yylex'.

> For example I have abcbdc sequence to parse. I can call
yyparse function
passing this string like parameters or directly like
executable
parameters
> (./parser abcbdc) ?

The input source is a matter for `yylex'.  You can write
`yylex' by hand
or use Lex, Flex, or some other package to generate it.  The
Flex
documentation specifically explains how to get `yylex' to
read from a
string.  In fact, you can read from any input source you
want:  a file, a
pipe, a device,  whatever.

It is also possible to pass a parameter to `yyparse' which
can also be
passed to `yylex'.  A `void*' which points to the actual
object is the
argument.  You can, of course, use this object to refer,
directly or
indirectly, to the string you want to read.  This probably
isn't the
easiest solution, though.

It is certainly possible to pass a string or the name of a
file to your
`main' function and arrange for it to be parsed.  In this
case, you should
certainly ensure that only a certain number of characters is
read in order
to prevent buffer overflows.  You will, of course, also need
to use
appropriate quoting, to make sure that the shell doesn't
expand characters
that have a special meaning to the shell.

Laurence Finston





_______________________________________________
help-bisongnu.org http
://lists.gnu.org/mailman/listinfo/help-bison

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )