Source Code Comparison via Statement Structure Parsing
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Current tools for comparing source code files are inefficient as they focus on line-by-line changes, failing to effectively identify differences in the underlying structure of source code files, which is crucial for debugging and copyright analysis.
Innovation Solution
A method and system that parse source code files to determine their code statement structures and compare these structures, using language-specific drivers to generate a common internal representation, allowing for the identification and reporting of differences in the file structures rather than line-by-line changes.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Measurement precision
If current text file comparison tools are used to compare source code files line by line, then the comparison process is simple and fast, but the comparison accuracy is insufficient because it fails to identify structural changes in the source code
Solution Approach 1:
The source code files are segmented into code statements with hierarchical structures (functions, variables, control structures) rather than treating them as plain text lines. The parser divides the code into meaningful units and builds a structured representation that captures the semantic relationships between different code elements, enabling accurate structural comparison.
Solution Approach 2:
An intermediate code statement structure representation is introduced between the raw source code files and the comparison process. This intermediate representation (IR) serves as a mediator that transforms unstructured text into a structured format that preserves code semantics, allowing the comparison tool to accurately identify structural differences without directly comparing raw text lines.
2Productivity
If line-by-line comparison is performed on source code files, then the comparison speed is fast, but the comparison effectiveness is reduced because it cannot identify whether underlying code structure has changed
Solution Approach 1:
The source code files are pre-processed by a parser that generates code statement structures before the comparison operation. This preliminary action of parsing and structuring the code enables the subsequent comparison to efficiently operate on meaningful code units rather than raw text lines, preserving structural information while maintaining comparison efficiency.
Solution Approach 2:
The comparison approach changes from operating on text-based parameters (lines, characters) to operating on structure-based parameters (code statements, functions, variables). By changing the fundamental parameters of comparison from textual to structural, the system can identify meaningful code differences while maintaining efficiency through systematic traversal of the code statement structures.
Data Source
AI summary
A computer system identifies a plurality of source code files to be compared, parses each source code file to identify a code statement structure present in the file, and compares the plurality of source code files using corresponding code statement structures.


