regex - Explanation and solution for JavaCC's warning "Regular expression choice : FOO can never be matched as : BAR"? -


I'm reading myself to use Java CCE in a hobby project, and a simple to write a parser Grammar is Parts of the parser include:

  token: {& lt; Digitally: (["0" - "9"] gt; } Token: {& lt; INTEGER: (& lt; DIGIT & gt;) + & gt; } Token: {& lt; INTEGER_PAIR: (& lt; integer & gt;) {2} & gt; } Token: {& lt; Flat: (& lt; NEGATE & gt;)? & Lt; Integer & gt; | (& Lt; negation & gt;)? & Lt; Integer & gt; "." & Lt; Integer & gt; | (& Lt; negation & gt;)? & Lt; Integer & gt; "." | (& Lt; negation & gt;)? "." & Lt; Integer & gt; & Gt; } Token: {& lt; FLOAT_PAIR: (& lt; float & gt;) {2} & gt; } Token: {& lt; NUMBER_PAIR: & lt; FLOAT_PAIR & gt; | & Lt; INTEGER_PAIR & gt; & Gt; } Token: {& lt; Negative: "-" & gt; }  

When compiled with a resident resident, I get the output:

  WARNING: Regular expression option: FLOAT_PAIR can never be matched : NUMBER_PAIR WARNING: Regular Expression Options: INTEGER_PAIR can never be matched as: NUMBER_PAIR  

I'm sure this is a simple concept, but I do not understand the warning Has been, novice in both parsing generation and regular expression / P>

What does this warning mean (like the newbie-like-the-conditions)?

I do not know a resident, but I am a compiler engineer.

FLOAT_PAIR rule is unclear Consider the following text:

  0.0  

This Flow 0 after float .0 can be>; Or it could be flow 0. After flow 0 ; As a result of both FLOAT_PAIR or this can be a single float 0.0 .

More importantly, though, you are experimenting creatively in a way that is unlikely to work. Consider this number: 12345

It can be parsed as INTEGER 12, INTEGER 345 , which results in INTEGER_PAIR . Or it can be parsed as INTEGER 123, INTEGER 45 , another INTEGER_PAIR . Or it may be INTEGER 12345 , another token may exist because the white space between the lexical elements of you INTEGER_PAIR (or FLOAT_PAIR ) is not needed.

You should never try to handle almost any such lexer in pairs instead, you can use plain number ( INTEGER and float ) should handle and handle things like denial and coupling in the parser, where the whitespace has been dealt with and stripped. / P>

(For example, how are you going to process "---- 42" ? This is a valid expression in most programming languages, which have many rejections in the right way

Also, keep in mind that the integer with a single digit in your Lexus will not be matched as INTEGER They DIGIT . I do not know the correct syntax for the Javasiasi to fix this for you, though. What you do not want to define as DIGIT token, but you can use some other tokens in definitions; Alternatively, the definition of DIGIT ( [0-9] ) is directly using the DIGIT in your code.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -