[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Where to put '#define YYSTYPE char *'?
From: |
Peng Yu |
Subject: |
Where to put '#define YYSTYPE char *'? |
Date: |
Sun, 27 Dec 2009 20:55:09 -0600 |
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 function ‘yylex’:
example6.l:10: warning: assignment makes integer from pointer without a cast
example6.l:11: warning: assignment makes integer from pointer without a cast
$cat ./compile.sh
flex example6.l
bison -d example6.y
echo 'here'
gcc lex.yy.c example6.tab.c -o example6
$cat example6.y
%{
#include <stdio.h>
#include <string.h>
#define YYSTYPE char *
void yyerror(const char *str)
{
fprintf(stderr,"error: %s\n",str);
}
int yywrap()
{
return 1;
}
main()
{
yyparse();
}
%}
%token FILETOK SEMICOLON OBRACE EBRACE ZONETOK QUOTE WORD FILENAME
%%
commands:
|
commands command SEMICOLON
;
command:
zone_set
;
zone_set:
ZONETOK quotedname zonecontent
{
printf("Complete zone for '%s' found\n",$2);
}
;
zonecontent:
OBRACE zonestatements EBRACE
zonestatements:
|
zonestatements zonestatement SEMICOLON
;
zonestatement:
statements
|
FILETOK quotedname
{
printf("A zonefile name '%s' was encountered\n", $2);
}
;
quotedname:
QUOTE FILENAME QUOTE
{
$$=$2;
}
block:
OBRACE zonestatements EBRACE SEMICOLON
;
statements:
| statements statement
;
statement: WORD | block | quotedname
;
$cat example6.l
%{
#include <stdio.h>
#include "example6.tab.h"
%}
%%
zone return ZONETOK;
file return FILETOK;
[a-zA-Z][a-zA-Z0-9]* yylval=strdup(yytext); return WORD;
[a-zA-Z0-9\/.-]+ yylval=strdup(yytext); return FILENAME;
\" return QUOTE;
\{ return OBRACE;
\} return EBRACE;
; return SEMICOLON;
\n /* ignore EOL */;
[ \t]+ /* ignore whitespace */;
%%
address@hidden:~/morgan/test/flex/example6$
- Where to put '#define YYSTYPE char *'?,
Peng Yu <=