Oleg Bartunov kirjutas K, 02.07.2003 kell 11:39:
> > > The problem is recognizing VERSION
> > > (from gram.y)
> > >
> > > version:
> > > INTEGER DOT INTEGER { $$ = strconcat($1, $3, $2); }
> > > | version DOT INTEGER { $$ = strconcat($1, $3, $2); }
> >
> > removing the line above seems to fix your problem ;)
>
> No, it's there by intention. VERSION could be not just 7.3 but 7.3.3 :)
Try attached gram.y and lex.l
-----------
Hannu
%{
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "scan.h"
char * strconcat( char *s1, char *s2, char c ) {
char *s;
int l1 = strlen(s1), l2=strlen(s2);
s = (char*)malloc( l1+l2+2 );
memcpy(s, s1, l1);
if ( c )
*(s+l1) = c;
memcpy( (s+ (l1+((c)?1:0)) ) , s2, l2);
*( s+(l1+l2+((c)?1:0)) ) = '\0';
return s;
}
int yyerror(char*);
int yylex(void);
int yyparse(void);
%}
%error-verbose
%union {
char *str;
u_int32_t opr;
}
%type <str> version
%type <str> integer
%type <opr> symbol
%type <opr> dot
%token <str> VERSION_MINOR
%token <str> INTEGER
%token <opr> DOT
%token <opr> CHAR
%token <str> ENDOF
%%
input:
| input data
;
data: ENDOF { return 0; }
| symbol
| dot
| version { printf("VERSION:\t'%s'\n", $1); }
| integer
;
version:
INTEGER VERSION_MINOR { $$ = strconcat($1, $2, '-'); }
| version VERSION_MINOR { $$ = strconcat($1, $2, '+'); }
;
integer:
INTEGER { printf("INTEGER:\t'%s'\n", $1); }
;
symbol:
CHAR { printf("CHAR:\t'%c'\n", $1); }
;
dot:
DOT { printf("DOT:\t'%c'\n", $1); }
;
%%
int yyerror(char *s) {
printf("yyerror: %s\n",s);
return 0;
}
int main(void) {
yyparse();
return 0;
}
%{
#include <sys/types.h>
#include <string.h>
#include "scan.h"
%}
%option 8bit
%option never-interactive
%option nounput
%option noyywrap
%%
\.[0-9]+ { yylval.str=strdup(yytext+1); return VERSION_MINOR; }
[0-9]+ { yylval.str=strdup(yytext); return INTEGER; }
\. { yylval.opr=(u_int32_t)*yytext; return DOT; }
. { yylval.opr=(u_int32_t)*yytext; return CHAR; }
<<EOF>> { return ENDOF; }
%%
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings