Re: Flex: token value more than what regexp matches
On 7 Jul 2005, at 23:53, Frans Englich wrote: I have the problem that the value of a token appears to be more than what the regexp matches. When parsing the expression "fn:false()", I get a QNAME token with the value "fn:false" -- what I expect & want. However, when parsing the expression "false()", I get the token NCNAME with the value "false(". The token is right, but I don't want the parantese to be included. This is frequently asked question: The Flex lexer merely provides a pointer to the identified text in a buffer, temporarily '0'- terminated, and in order to preserve that in subsequent lexer calls, you need to copy it over. The Bison parser does indeed make several calls to the lexer before the rule action is invoked. Hans Aberg ___ Help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison
RE: Flex: token value more than what regexp matches
Frans Englich wrote: > The relevant parts in my Bison is: > > %union > { > int ival; > char *sval; > KDOM::XPath::ExpressionImpl *expr; > KDOM::XPath::ExpressionImpl::List *expressionList; > QPSingleType *singleType; KDOM::XPath::SharedQName *qName; > bool emptyAllowed; > } > However, when parsing the expression "false()", I get the > token NCNAME with > the value "false(". The token is right, but I don't want the > parantese to be included. > > Why is the parantese included in the value, and how do I fix > it? The regexp > "[a-zA-Z-]+" really shouldn't match it, right? This is really a FAQ. Flex overwrites the '(' with a null character when it passes the token to bison. Your bison rule stores only the pointer to the string. By the time the bison parser gets around to printing your token (one token later), flex has restored the '(' character (and overwritten the ')' character). To fix, save the contents of the string instead of only the pointer to it. Vincent Zweije Development -- WCC Services - Advanced Matching Technology NL +31 30 7503222 [EMAIL PROTECTED] www.wcc-group.com ___ Help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison
Re: Flex: token value more than what regexp matches
Hans, Vincent, Thanks for your suggestions -- it of course solved my problem. Cheers, Frans ___ Help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison