Lexical Comparison - recognizing tokens during comparison of source code


To improve source code comparison, Code Compare incorporates Lexical Comparison — one of the key principles of Code Orientation. This algorithm allows for a better file comparison, sync and merge through detecting lexemes from major programming languages — namely C#, C++, JavaScript, Java, and Visual Basic — and comparing them as single-pieces.

Language Combo Box

Lexical Comparison algorithm chooses the programming language automatically, based on the file extension. However, you can change this setting using the Language Combo Box on the toolbar. The chosen language wil be applied immediately, while the Text option turns off the Lexical Comparison algorithm.

Language Combo Box

Below you can find descriptions of the most popular cases when Lexical Comparison proved exceptionally useful.

Lexical Comparison vs. Text Comparison

  • Text comparison mode within Code Compare can be inconvenient for source code comparison as it does not recognize language elements and looks for similar symbols in totally different lexemes.

    Text comparison algorithm

    With Lexical Comparison enabled, different lexeme types are never compared with each other.

    Lexical comparison - different lexeme types
  • Code Compare tool with Lexical comparison enabled always compares numbers wholly. This is illustrated by the next screenshot.

    Comparing numbers with Lexical Comparison Mode

    If you choose text comparison mode, the numbers will be compared digit-by-digit, which is irrational in the context of source code comparison.

    Comparing numbers with text Comparison Mode

Additional Options

  • Ignoring comments can be enabled in Comparison options menu.

    Code Compare - Ignoring comments

    With respective checkbox checked, comparison tool will disregard any source code comments and highlight the blocks different by this sign only as unchanged.

    Comments ignored

For details on the major feature set of our file diff and merge tool, refer to the overview page of Code Compare.