help needed with yacc/bison

Started by Oleg Bartunovalmost 23 years ago5 messageshackers
Jump to latest
#1Oleg Bartunov
oleg@sai.msu.su

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: oleg@sai.msu.su, http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83

#2Oleg Bartunov
oleg@sai.msu.su
In reply to: Oleg Bartunov (#1)
Re: help needed with yacc/bison

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: oleg@sai.msu.su, 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: oleg@sai.msu.su, http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83

Attachments:

ex.tar.gzapplication/octet-stream; name=ex.tar.gzDownload
#3Hannu Krosing
hannu@tm.ee
In reply to: Oleg Bartunov (#1)
Re: help needed with yacc/bison

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

#4Oleg Bartunov
oleg@sai.msu.su
In reply to: Hannu Krosing (#3)
Re: help needed with yacc/bison

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 majordomo@postgresql.org)

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

#5Hannu Krosing
hannu@tm.ee
In reply to: Oleg Bartunov (#4)
Re: help needed with yacc/bison

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

Attachments:

gram.ytext/plain; charset=UTF-8; name=gram.yDownload
lex.ltext/plain; charset=UTF-8; name=lex.lDownload