java - Why won't javac accept `x = x+++++y`? -


from perspective of compiler theory, why javac compiler not accept statement of form x = x+++++y accept x = x+++ ++y ?

because ++ valid token java lexer, statement x+++ ++y parsed tokens :

(x)(++)(+)( )(++)(y) 

whereas x+++++y tokenized invalid:

(x)(++)(++)(+)(y) 

the above invalid java because ++ operator can applied things numeric variables, result of (x++) not. type of tokenizing great example of concept known maximal munch.

from jls section 3.2

the longest possible translation used @ each step, if result not make correct program while lexical translation would.

thus, input characters a--b tokenized (§3.5) a, --, b, not part of grammatically correct program, though tokenization a, -, -, b part of grammatically correct program.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -