Lexical Text Comparison

Code Compare provides different depths of source comparison:

1. Symbol by Symbol comparison. In case this option is used, Code Compare highlights each of the different symbols with specific color that can be set in the Options dialog box;
2.Word by Word comparison. In case this comparison approach is selected, whole words are compared with each other;
3.Line by Line comparison. If you select this option, lines will be considered different even if they have only one different symbol.

You can select the required approach in the Code Compare options.

To select comparison approach, go to the Comparison menu, select the Compare Text submenu, and then select the required menu item.

To customize the default comparison mode, in the Tools menu select Options, then in the displayed Options dialog box expand the Code Compare node, navigate to the File page and set the required value in the Compare content drop-down list.

ExpandedToggleIcon(9x12)        Lexical Comparison Implementation for Programming Languages

Lexical comparison is supported for the following languages:

C#
C++
Visual Basic
JavaScript
Java

Lexical comparison is activated when the Symbol by Symbol mode is chosen. As this option is supported only for some of the languages, it is disabled by default.

You can see the advantages of such comparison from the following example.

ExpandedToggleIcon(9x12)        Example: Regular Comparison vs Lexical Comparison

The example below demonstrates advantages of lexical comparison as opposed to regular 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.

lexical_comparison_1

Regular text comparison algorithm

With lexical comparison enabled, different lexeme types are never compared with each other.

lexical_comparison_2

Lexical comparison - different lexeme types

Code Compare tool with lexical comparison enabled always compares numbers wholly. This is illustrated by the next screenshot.

lexical_comparison_3

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.

lexical_comparison_4

Comparing numbers with text comparison mode

Additional Options

Ignoring comments can be enabled in the Comparison menu.

lexical_comparison_5

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

lexical_comparison_6

ExpandedToggleIcon(9x12)        See Also