Automatic code refactoring

Calvin Spealman calvin at
Wed Mar 2 19:46:07 UTC 2005

Sylvain Joyeux wrote:
> Moreover, having a common parser won't help you to write new code while
> refactoring. The syntax is different, and I don't think you can write code
> using the BNF syntax, you can only *read* it.

I disagree. I believe BNF support could be a lot more useful than you
realize. For example, the source code could be parsed into an in-memory
tree structure (think DOM), which could be analyzed or manipulated. A
generic interface to this could allow langauge-independant manipulations,
such as 'assign that number this variable'. Now, of course, this doesn't
mean we can have a generic implementation that can assign a number to a
variable in any source code, it means that it would be easier to implement
for each language. All the manipulation code would need to know is:
  1) How to represent a variable to assign a value to.
  2) How to represent a number.
  3) How to assign a numerical value to a variable.
These three rules could all be defined in the BNF. Most of these rules'
generic versions could have a hierarchy to them, such as 'representation of
a variable' and then 'representation of a variable for assignment' and
'representation of a variable for its value', which would be good for such
languages as BASH scripting. This kind of setup would mean that for every
language, you would be able to describe only the most specific rules for
that language, even specifying completely new, language-specific rules. All
this would add up to a very nice framework for manipulating code in a very
generic way, or a specific way, depending on your needs and situations.


More information about the KDevelop-devel mailing list