Re: [HACKERS] help needed with yacc/bison

2003-07-02 Thread Oleg Bartunov
On Wed, 1 Jul 2003, Hannu Krosing wrote:

 Oleg Bartunov kirjutas T, 01.07.2003 kell 15:49:
  Hi there,
 
  attached archive contains simple parser demonstrating our
  problem. untar it, make, make test
 
  Good test:
  echo -n 12 34.1234 ... | ./parser
  INTEGER:'12'
  CHAR:   ' '
  VERSION:'34.1234'
  CHAR:   ' '
  DOT:'.'
  DOT:'.'
  DOT:'.'
  Wrong:
  echo -n 12 34.1234. ... | ./parser
  INTEGER:'12'
  CHAR:   ' '
  yyerror: syntax error, unexpected CHAR, expecting INTEGER
 
  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 :)


  ;
 
  For last query '34.1234.' we want to print VERSION '34.1234' and
  return DOT.

 you can't return DOT as version is str and DOT is opr

  This is just an test example, actually we know workaround
  for this case, but we need something simple and universal :)

 please describe the problem with some more samples, as it will make it
 easier which kind of universal you are searching for ;)


We're thinking about rewriting tsearch's parser and got this problem.
Similar situation could arise form hyphenated words, etc.

 
 Hannu


 ---(end of broadcast)---
 TIP 2: you can get off all lists at once with the unregister command
 (send unregister YourEmailAddressHere to [EMAIL PROTECTED])


Regards,
Oleg
_
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: [EMAIL PROTECTED], http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [HACKERS] help needed with yacc/bison

2003-07-02 Thread Hannu Krosing
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


[HACKERS] help needed with yacc/bison

2003-07-01 Thread Oleg Bartunov
Hi there,

attached archive contains simple parser demonstrating our
problem. untar it, make, make test

Good test:
echo -n 12 34.1234 ... | ./parser
INTEGER:'12'
CHAR:   ' '
VERSION:'34.1234'
CHAR:   ' '
DOT:'.'
DOT:'.'
DOT:'.'
Wrong:
echo -n 12 34.1234. ... | ./parser
INTEGER:'12'
CHAR:   ' '
yyerror: syntax error, unexpected CHAR, expecting INTEGER

The problem is recognizing VERSION
(from gram.y)

version:
INTEGER DOT INTEGER{ $$ = strconcat($1, $3, $2); }
| version DOT INTEGER  { $$ = strconcat($1, $3, $2); }
;

For last query '34.1234.' we want to print VERSION '34.1234' and
return DOT.
This is just an test example, actually we know workaround
for this case, but we need something simple and universal :)


Regards,
Oleg
_
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: [EMAIL PROTECTED], http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83

---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [HACKERS] help needed with yacc/bison

2003-07-01 Thread Oleg Bartunov
Sorry,

forgot to attach archive :)

Oleg
On Tue, 1 Jul 2003, Oleg Bartunov wrote:

 Hi there,

 attached archive contains simple parser demonstrating our
 problem. untar it, make, make test

 Good test:
 echo -n 12 34.1234 ... | ./parser
 INTEGER:'12'
 CHAR:   ' '
 VERSION:'34.1234'
 CHAR:   ' '
 DOT:'.'
 DOT:'.'
 DOT:'.'
 Wrong:
 echo -n 12 34.1234. ... | ./parser
 INTEGER:'12'
 CHAR:   ' '
 yyerror: syntax error, unexpected CHAR, expecting INTEGER

 The problem is recognizing VERSION
 (from gram.y)

 version:
 INTEGER DOT INTEGER{ $$ = strconcat($1, $3, $2); }
 | version DOT INTEGER  { $$ = strconcat($1, $3, $2); }
 ;

 For last query '34.1234.' we want to print VERSION '34.1234' and
 return DOT.
 This is just an test example, actually we know workaround
 for this case, but we need something simple and universal :)


   Regards,
   Oleg
 _
 Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
 Sternberg Astronomical Institute, Moscow University (Russia)
 Internet: [EMAIL PROTECTED], http://www.sai.msu.su/~megera/
 phone: +007(095)939-16-83, +007(095)939-23-83

 ---(end of broadcast)---
 TIP 4: Don't 'kill -9' the postmaster


Regards,
Oleg
_
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: [EMAIL PROTECTED], http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83

ex.tar.gz
Description: Binary data

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [HACKERS] help needed with yacc/bison

2003-07-01 Thread Hannu Krosing
Oleg Bartunov kirjutas T, 01.07.2003 kell 15:49:
 Hi there,
 
 attached archive contains simple parser demonstrating our
 problem. untar it, make, make test
 
 Good test:
 echo -n 12 34.1234 ... | ./parser
 INTEGER:'12'
 CHAR:   ' '
 VERSION:'34.1234'
 CHAR:   ' '
 DOT:'.'
 DOT:'.'
 DOT:'.'
 Wrong:
 echo -n 12 34.1234. ... | ./parser
 INTEGER:'12'
 CHAR:   ' '
 yyerror: syntax error, unexpected CHAR, expecting INTEGER
 
 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 ;)

 ;
 
 For last query '34.1234.' we want to print VERSION '34.1234' and
 return DOT.

you can't return DOT as version is str and DOT is opr

 This is just an test example, actually we know workaround
 for this case, but we need something simple and universal :)

please describe the problem with some more samples, as it will make it
easier which kind of universal you are searching for ;)


Hannu


---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send unregister YourEmailAddressHere to [EMAIL PROTECTED])