jflex-de / jflex

The fast scanner generator for Java™ with full Unicode support
http://jflex.de
Other
586 stars 114 forks source link

[Bug] Macro error on regexp negation (!) [sf#55] #57

Closed lsf37 closed 9 years ago

lsf37 commented 9 years ago

Reported by deadsea on 2002-09-18 14:33 UTC I tried to create a lexer for SQL which is an interesting beast. SQL has a rule that says operators can be any combination of certain characters except for combinations that would start a comment.

I tried to implement this using the regexp negation feature of JFlex but I get a macro error. I'm trying to do the the expression that matches everything of a not matched by b as specified in the user manual: !(!a|b) I create a very loose definition of an operator (a) and then a definition for things that look they they are an operator, but aren't (b).

I am attaching a test case that demonstrates this.

If you modify it to compile, you can run: jflex Test.jflex javac Test.java java Test

(I'm using JFlex 1.3.5)

lsf37 commented 9 years ago

Commented by deadsea on 2002-09-18 14:33 UTC Compile error on regexp negation.

lsf37 commented 9 years ago

Commented by lsf37 on 2002-09-25 13:18 UTC Logged In: YES user_id=93534

I can't completely reproduce the error. If I run JFlex (1.3.5) on your example, I don't really get a macro error, but (wrong) warnings. I've found a bug in the macro expansion which I think is what you're experiencing (it doesn't descend into negated expressions, this should affect the warnings only, though).

If I run the example, I get:

kleing@kosh:> jflex Test.flex
Reading "Test.flex"

Warning : Macro "operatorChar" has been declared but never
used.

Warning : Macro "illegalOperator" has been declared but
never used.
Constructing NFA : 87 states in NFA
Converting NFA to DFA :
.............
15 states before minimization, 11 states in minimized DFA
Writing code to "Test.java"
kleing@kosh:> javac Test.java
kleing@kosh:> java Test
Operator: #
Operator: #
Operator: /
Operator: #
Comment: / comment /
Operator: #
Comment: -- comment

The result seems to be ok according to the spec (although I confess, I've not analyzed it thouroughly). If I remove the comments in the spec, I get another warning:

Rule can never be matched: <YYINITIAL> ({operator}) {

This warning is correct, though, because the rule above it ( {operatorChar}+) is a superset of {operator}.

As a quick fix for the warnings, I've attached a replacement for JFlex.jar that does the warnings properly (it should report 1.4_pre3 as version number).

Is this the error you meant, or is it something completely
different?

lsf37 commented 9 years ago

Updated by lsf37 on 2002-09-25 13:18 UTC

lsf37 commented 9 years ago

Commented by lsf37 on 2002-09-25 13:20 UTC

lsf37 commented 9 years ago

Updated by lsf37 on 2002-09-25 13:20 UTC

lsf37 commented 9 years ago

Updated by lsf37 on 2004-04-12 12:26 UTC