help-bison
[Top][All Lists]
Advanced

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

help-bison Digest, Vol 67, Issue 1 (Answer to Message 1)


From: Naushad Ahmed
Subject: help-bison Digest, Vol 67, Issue 1 (Answer to Message 1)
Date: Fri, 1 May 2009 10:17:36 -0700

To override the default signature of yyparse() so that it can accept an
argument then inside %{......
.....
#define YYPARSE_PARAM arg
%}

main()
{
  char buffer[xxx];
 yyparse(&buffer);
}

now in grammar actions use
(char *) arg


On Fri, May 1, 2009 at 9:00 AM, <address@hidden> wrote:

> Send help-bison mailing list submissions to
>        address@hidden
>
> To subscribe or unsubscribe via the World Wide Web, visit
>        http://lists.gnu.org/mailman/listinfo/help-bison
> or, via email, send a message with subject or body 'help' to
>        address@hidden
>
> You can reach the person managing the list at
>        address@hidden
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of help-bison digest..."
>
>
> Today's Topics:
>
>   1. Without standard input (Mark Redd)
>   2. Can't compile bison/flex output files without cc? (Mark Redd)
>   3. Re: Can't compile bison/flex output files without cc?
>      (Philip Herron)
>   4. Re: Can't compile bison/flex output files without cc? (Mark Redd)
>   5. Re: Can't compile bison/flex output files without cc?
>      (Philip Herron)
>   6. Re: Can't compile bison/flex output files without cc?
>      (Philip Herron)
>   7. Re: Without standard input (Luca)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Thu, 30 Apr 2009 19:18:22 +0200
> From: Mark Redd <address@hidden>
> Subject: Without standard input
> To: address@hidden
> Message-ID:
>        <address@hidden>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Hi everybody.
> I've made my parser using Flex/Bison and it works.
>
> My main function is
>
> main()
> {
>        yyparse();
> }
>
> Now my task is to develop a GUI in order to use it.
> Suppose I've a char buffer[xxx] with the text i need to parse (and it is
> true, because I'm using a textview), how can I pass it to yyparse()?
>
> Thanks!
>
>
> ------------------------------
>
> Message: 2
> Date: Fri, 1 May 2009 10:17:02 +0200
> From: Mark Redd <address@hidden>
> Subject: Can't compile bison/flex output files without cc?
> To: address@hidden
> Message-ID:
>        <address@hidden>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Hello everybody.
> I'm developing a didactic project using Anjuta IDE. I must use it, so I
> can't use cc.
>
> I've made my scanner/parser with flex/bison and if I type in console these
> tree commands
> flex foo.l
> bison -d foo.y
> cc lex.yy.c foo.tab.c -o foo
> it works.
>
> So I said "ok, now I could just create an Anjuta project with foo.tab.c,
> foo.tab.h, lex.yy.c and compile". I followed this way, and it compiles with
> several warnings.
> When I run the executable programm, it works fine but when input is not
> recognized and the recovery procedure is impossible, it crashes with a
> "segmentation fault" error message.
>
> I'm a desperate programmer! There is a way to fix this situation?
>
>
> ------------------------------
>
> Message: 3
> Date: Fri, 01 May 2009 10:46:05 +0100
> From: Philip Herron <address@hidden>
> Subject: Re: Can't compile bison/flex output files without cc?
> To: Mark Redd <address@hidden>
> Cc: address@hidden
> Message-ID: <address@hidden>
> Content-Type: text/plain; charset=ISO-8859-1
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hey
>
> One quick question what do you mean that you cant use CC in anjuta? as
> in c-compiler or what?
>
> This is the way your don't want to be working with your parser and
> lexer. I mean you want your makefile to be re-generating your parser
> and compiling if any changes. This sounds like a problem with your
> parser. If input isn't recognized, do you mean your lexer won't pickup
> any tokens if it cannot be matched, and then once the lexer has the
> tokens it will be passed to your parser generated by bison.
>
> "So I said "ok, now I could just create an Anjuta project with foo.tab.c,
> foo.tab.h, lex.yy.c and compile". I followed this way, and it compiles
> with
> several warnings.
> When I run the executable programm, it works fine but when input is not
> recognized and the recovery procedure is impossible, it crashes with a
> "segmentation fault" error message."
>
>
> So i would doubt  bison is giving you a seg-fault it could be you have
> some code that has a pointer to something that doesn't exist. Try to
> run though the program your self a few times.
>
> Only thing i could think of if you parser needs to do actual work on
> some of the tokens make sure your lexer does yylval= strdup(yytext)
>
> If you haven't union'ed yylval it could be a good idea. so you could
> do yylval.string= strdup(yytext); return B
>
> So as you can do stuff with your tokens in bison like:
>
> #define yystype char * or to the union
>
> fooRule: A B C
>             {
>                 printf("%s", $2)
>             }
>             ;
>
> Personally i don't like IDE's like anjuta. You would be much better
> off using automake and autoconf to do this, because its more portable
> and easier to work with. You should track down your code, and if your
> sure its your parser try to dump some code here so as we can help.
>
> One thing try to make sure you don't have any shift/reduce problems in
> your parser that could be a potential problem. Anyways there isn't
> much i can do unless you track down your problem more specifically.
>
> - -Phil
> http://redbrain.co.uk
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iEYEARECAAYFAkn6xNEACgkQAhcOgIaQQ2HB+gCbBn7AjZuZ81gUpD7AiBr+D8ld
> om0An13ftc4VpzqlL1wQDQZsMfpmTyww
> =K/kx
> -----END PGP SIGNATURE-----
>
>
>
>
>
> ------------------------------
>
> Message: 4
> Date: Fri, 1 May 2009 12:01:38 +0200
> From: Mark Redd <address@hidden>
> Subject: Re: Can't compile bison/flex output files without cc?
> To: Philip Herron <address@hidden>
> Cc: address@hidden
> Message-ID:
>        <address@hidden>
> Content-Type: text/plain; charset=ISO-8859-1
>
> >
> > One quick question what do you mean that you cant use CC in anjuta? as
> > in c-compiler or what?
>
>
>
> I meant that I don't use directly "cc" command typing it in console, but
> Anjuta does it for me.
>
> I wasn't much clear and so now I'll explain better my situation.
> I've done my scanner/parser and it works fine. Now I have to realize a GUI
> in order to use it, so I taught to use Anjuta+Glade.
>
> I've not yet develop the graphical interface (it will be the next step),
> but
> I created a simple console project composed by foo.tab.c, foo.tab.h,
> lex.yy.c files.
> They were the same files that worked fine when I campiled/liked them typing
> "cc <>" in console.
> If I compile them in Anjuta and run executable file, when the input is
> syntactical correct works good, but if it isn't correct and it can't handle
> error recovery it has a segmentation fault end.
> How is it possible that the same source files give a different software
> behaviour?
>
>
> >
> >
> > This is the way your don't want to be working with your parser and
> > lexer. I mean you want your makefile to be re-generating your parser
> > and compiling if any changes.
>
>
> I know this way, but I prefer to use Anjuta+Glade for GUI: it's easier.
>
>
> > This sounds like a problem with your
> > parser. If input isn't recognized, do you mean your lexer won't pickup
> > any tokens if it cannot be matched, and then once the lexer has the
> > tokens it will be passed to your parser generated by bison.
>
>
> I don't think it's a problem with my parser. When I compile writing "cc .."
> in console, it works fine with the same input code!
>
>
> > One thing try to make sure you don't have any shift/reduce problems in
> > your parser that could be a potential problem.
>
>
> I haven't shift/reduce problem.
> Any hints?
>
> Mark Redd
>
>
> ------------------------------
>
> Message: 5
> Date: Fri, 01 May 2009 13:53:54 +0100
> From: Philip Herron <address@hidden>
> Subject: Re: Can't compile bison/flex output files without cc?
> To: Mark Redd <address@hidden>
> Cc: address@hidden
> Message-ID: <address@hidden>
> Content-Type: text/plain; charset=ISO-8859-1
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
>
> Hey
>
> I found this thread: (is it the same problem?)
> http://ubuntuforums.org/showthread.php?t=834944
>
> I am downloading anjuta to try it out for doing bison/flex so i'll let
> you know how i get on. But i think there must be a way to do this. If
> you have to use anjuta.
>
> - -Phil
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iEYEARECAAYFAkn68OAACgkQAhcOgIaQQ2E3yQCcCOMkAfm4cGuTlKAbyhOJT0AX
> jW8AoIVP8J0EklhsPk8lcUSTuEB4mscZ
> =3lOS
> -----END PGP SIGNATURE-----
>
>
>
>
>
> ------------------------------
>
> Message: 6
> Date: Fri, 01 May 2009 14:10:41 +0100
> From: Philip Herron <address@hidden>
> Subject: Re: Can't compile bison/flex output files without cc?
> To: Mark Redd <address@hidden>
> Cc: address@hidden
> Message-ID: <address@hidden>
> Content-Type: text/plain; charset=ISO-8859-1
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hey
>
> I got this all working it seems. I didn't finish it but i can see how
> anjuta makes it work.
>
> So basicly you want to be just adding in your foo.l and fooparser.y as
> your sources. Because when you add a new source you should notice
> anjuta manages your Makefile.am! This means your using the full
> autoconf and automake.
>
> One problem i am not sure how your meant to add to your configure.ac
> for automake to have the macros to LEX and YACC
>
> But what you could do is look at this configure.ac that anjuta
> generated for me:
>
> dnl Process this file with autoconf to produce a configure script.
> dnl Created by Anjuta application wizard.
>
> AC_INIT(foobar_sample, 0.1)
>
> AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
> AC_CONFIG_HEADERS([config.h])
> AM_MAINTAINER_MODE
>
> AC_ISC_POSIX
> AC_PROG_CC
> AM_PROG_CC_STDC
> AC_HEADER_STDC
>
>
>
>
> dnl
> ***************************************************************************
> dnl Internatinalization
> dnl
> ***************************************************************************
> GETTEXT_PACKAGE=foobar_sample
> AC_SUBST(GETTEXT_PACKAGE)
> AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [GETTEXT
> package name])
> AM_GLIB_GNU_GETTEXT
> IT_PROG_INTLTOOL([0.35.0])
>
> AM_PROG_LIBTOOL
>
>
> AC_OUTPUT([
> Makefile
> src/Makefile
> po/Makefile.in
> ])
>
>
> What you should do is add in here:
>
> AC_PROG_YACC
> AC_PROG_LEX
>
> before the check for libtool. You should probably do checks to throw
> an error like something:
> after each: if test "$LEX" == ""  then AC_MSG_ERROR or somthing.
>
> But once thats done now automake knows of lex and yacc but you also
> need in your Makefile.am that contains the sources to be compiled add in:
>
> AM_YFLAGS = -d
>
>
> This should do the job.
>
> - -Phil
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iEYEARECAAYFAkn69M4ACgkQAhcOgIaQQ2GmIwCfS+FjNY2TVDTRuFzWKieD3tWz
> LfgAn0fK06P+ImutbyjxOz7SweOfS+Yt
> =wV5g
> -----END PGP SIGNATURE-----
>
>
>
>
>
> ------------------------------
>
> Message: 7
> Date: Fri, 01 May 2009 16:32:12 +0200
> From: Luca <address@hidden>
> Subject: Re: Without standard input
> To: Mark Redd <address@hidden>
> Cc: address@hidden
> Message-ID: <address@hidden>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Mark Redd ha scritto:
> > Hi everybody.
> > I've made my parser using Flex/Bison and it works.
> >
> > My main function is
> >
> > main()
> > {
> >         yyparse();
> > }
> >
> > Now my task is to develop a GUI in order to use it.
> > Suppose I've a char buffer[xxx] with the text i need to parse (and it is
> > true, because I'm using a textview), how can I pass it to yyparse()?
> >
> > Thanks!
> > _______________________________________________
> > address@hidden http://lists.gnu.org/mailman/listinfo/help-bison
> >
> >
> See "Multiple Input Buffer" in flex help:
>
> http://flex.sourceforge.net/manual/Multiple-Input-Buffers.html#Multiple-Input-Buffers
> in this way you can parse a string:
>
>        #include "y.tab.h"
>        //declaration
>        typedef struct yy_buffer_state *YY_BUFFER_STATE;
>        YY_BUFFER_STATE yy_scan_string(const char*str);
>        void yy_switch_to_buffer(YY_BUFFER_STATE new_buffer);
>
>        //code
>        YY_BUFFER_STATE b=yy_scan_string(stringToParse);
>        yy_switch_to_buffer(b);
>        yyparse();
>
> Luca
>
>
>
>
>
> ------------------------------
>
> _______________________________________________
> help-bison mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/help-bison
>
> End of help-bison Digest, Vol 67, Issue 1
> *****************************************
>


reply via email to

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