用大模型自动适配元模型演进后的语法,减少人工干预。
Leveraging LLMs for Grammar Adaptation: A Study on Metamodel-Grammar Co-Evolution

- 通过学习历史版本的语法变更,让大模型自动推导新语法调整方案。
- 在测试集上三款大模型均实现100%规则一致性与输出相似性。
- 适合需要频繁更新语法的领域特定语言开发者使用。
在模型驱动工程中,元模型演进导致需适配对应语法以保持一致性,传统手动工作繁琐。现有基于规则的方法虽可部分自动化,但在复杂场景下受限。本文提出一种基于大语言模型的方法,通过学习历史版本的语法变更,自动为演进后的语法应用适配。我们在六个真实世界的Xtext领域特定语言上评估该方法:用四个DSL作为训练集制定提示策略,两个作为测试集验证效果,并对QVTo开展纵向案例研究。评估使用Claude Sonnet 4.5、ChatGPT 5.1、Gemini 3三款大模型,从规则级一致性、输出相似性和元模型符合性三个维度衡量适应质量。结果表明,在测试集上,所有三款大模型均达到100%一致性与输出相似性;而基于规则的方法在DOT上仅达84.21%,Xcore上仅62.50%。在QVTo的纵向研究中,大模型方法在全部三个演进步骤中成功复用学习到的适配,无需人工修改;而规则方法在其中两次演进中仍需人工调整。然而,在大规模语法(EAST-ADL,297条规则)上,大模型的适应一致性远低于90%。本研究证明大模型在处理复杂语法场景中的优势,也揭示其在大规模语法适配上的局限。
原文摘要 · Abstract (English)
In model-driven engineering, metamodel evolution leads to the need to adapt corresponding grammars to maintain consistency, which typically requires tedious manual work. Existing rule-based methods can achieve partial automation but have limitations when handling complex grammar scenarios. This paper proposes a Large Language Model-based approach that automatically applies adaptations to new grammars after evolution by learning grammar adaptations from previous versions. We evaluated this approach on six real-world Xtext domain-specific languages, using four DSLs as a training set to develop prompting strategies, two DSLs as a test set for validation, and conducting a longitudinal case study on QVTo. The evaluation used three Large Language Models (Claude Sonnet 4.5, ChatGPT 5.1, Gemini 3) and measured grammar adaptation quality from three dimensions: grammar rule-level adaptation consistency, output similarity, and metamodel conformance. Results show that on the test set, all three LLMs achieved 100% adaptation consistency and output similarity, while the rule-based approach achieved only 84.21% on DOT and 62.50% on Xcore. In the QVTo longitudinal study, the LLM-based approach successfully reused learned adaptations across all three evolution steps without manual grammar editing, while the rule-based approach required manual adjustments in two of three transitions. However, on large-scale grammars (EAST-ADL, 297 rules), LLMs' adaptation consistency was far below 90%. This study demonstrates the advantages of LLM-based approaches in handling complex grammar scenarios, while revealing their limitations in large-scale grammar adaptation.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。