yeah, I think that's right. I'm having trouble with the main function even though I made my own main function flex is generating the default one also in #if YY_MAIN tag. I've tried setting #define YY_MAIN 0 and manually removing that extra main function from lex.yy.c, but it still says there are multiple main functions. I did a grep main * and the only places it comes up are in mylex.l and lex.yy.c. Here is mylex.l:
Code:
%{
#include <stdio.h>
#include "y.tab.h"
#define YY_MAIN 0
#undef YY_INPUT
#define YY_INPUT(b, r, ms) (r = my_yyinput(b, ms))
#define MAXIMO 60
unsigned verbose;
char *progName;
%}
%%
-h |
"-?" |
--help { printf("usage is: %s [--help | -h | -? ] [--verbose | -v] [(--file | -f) filename]\n", progName); }
-v |
--verbose { printf("verbose mode is on\n"); verbose = 1; }
%%
char myinput[80]; /* input buffer */
char *myinputptr; /* current position in buffer */
char *myinputlim; /* end of data */
main(int argc, char **argv)
{
char buff[BUFSIZ];
fgets( buff, BUFSIZ, stdin );
myinputptr = buff;
myinputlim = buff + strlen(buff);
yylex();
}
int yyerror (char *s) /* Called by yyparse on error */
{
printf ("%s\n", s);
}
int yywrap ()
{
}
int min(int x, int y)
{
if(x < y)
return x;
else
return y;
}
int my_yyinput(char *buf, int max_size)
{
/* compiler $$$$$es about subtracting int from ptr, so myinputlim is ptr now
*/
/* int n = min(max_size, myinputlim - myinputptr); */
int n = myinputlim - myinputptr;
if (n > 0) {
memcpy(buf, myinputptr, n);
myinputptr += n;
}
return n;
/*
strcpy(buf, "5+5\n");
return 5;
*/
}