lex/yacc/cc/unix question

lex/yacc/cc/unix question

Post by Paul Sherm » Mon, 12 Sep 1994 20:26:21



I hope that this is the correct forum to ask this question. I am trying
to learn lex and yacc and have run into a small snag.

In my application, I am trying to have lex parse input for yacc and do
the type conversions for insertion onto the stack. I realize as I am
writing this that that approach may be part of my problem, and instead
I should leave conversions to yacc, but...

Anyway, in the process of doing this conversion, I use the atof, malloc
and free functions. Here is an extract of part of my code from lex:

        fpnumber  -?(([0-9]+)|([0-9]*\.[0-9]+))

        %%

        {fpnumber} {
                yylval.val = atof(yytext);
                return NUMBER;
                }

Anyway, so what I need is the stdlib included in order for atof to work
correctly. So when I try to do this right, and put the #include just
before my main like so:

        %%

        #include <stdlib.h>
        main() {
                yylex;
        }

and then run lex on it, the #include ends up in the lower part of the code.
This is correct so far. However, when I compile I get the following messages:

% cc lex.yy.c -ll -o trythis
cc: "/usr/include/stdlib.h", line 79: error 1584:
        Inconsistent type declaration: "atof".
cc: "/usr/include/stdlib.h", line 85: warning 533:
        Inconsistent type declaration for function "free".
cc: "/usr/include/stdlib.h", line 122: error 1584:
        Inconsistent type declaration: "malloc".

This is a trifle annoying...

On the other hand, when I lex my source, then manually edit lex.yy.c and put
the #include<stdlib.h> just below the #include"stdio.h" that lex
automatically includes, then everything works just fine.

So, while I have a work around, it sucks. Any suggestions on how to do this
a bit more elegantly. Part of my problem is that I am not all that sure where
my error lies. Is due to the degree of my ignorance in lex and yacc (very
substantial) or the degree of my ignorance of the mysteries of cc and unix
(only slightly less substantial)? Anyway, a post or an e-mail with some
clue would help. I would appreciate it.

--
+-------------------------------^-------------------------------------+

+-------------------------------^-------------------------------------+
| "Despite all the computations y'know you could just dance to a      |
|  Rock-n-Roll station station and it was alright. It was alright."   |
|                        -The Velvet Underground                      |
+---------------------------------------------------------------------+

--
+-------------------------------^-------------------------------------+

+-------------------------------^-------------------------------------+
| "Despite all the computations y'know you could just dance to a      |
|  Rock-n-Roll station station and it was alright. It was alright."   |
|                        -The Velvet Underground                      |
+---------------------------------------------------------------------+

 
 
 

lex/yacc/cc/unix question

Post by Jonathan Ch » Tue, 13 Sep 1994 08:50:24



[snip]

Quote:>Anyway, so what I need is the stdlib included in order for atof to work
>correctly. So when I try to do this right, and put the #include just
>before my main like so:
>    %%

>    #include <stdlib.h>
>    main() {
>            yylex;
>    }
>and then run lex on it, the #include ends up in the lower part of the code.
>This is correct so far. However, when I compile I get the following messages:

[snip]

Change your lex code format to this :

------------<tof>-------
%{
#include        <stdlib.h>
%}

%%
lex-match stuff

%%
main ()
{
        yylex ();

Quote:}

---------------<eof>------

and the <stdlib.h> will be #include'd at the top
--

#include <std/disclaimer>        | Voice  : +64.9.489.7020