This invention relates to the fields of
artificial intelligence and
natural language processing, and particularly to a method and
system for compiling and generating prompt words for large language models. The method includes responding to a compilation call request and receiving a PDL specification as the compilation input text; performing lexical and syntactic analysis on the compilation input text, and constructing a corresponding
Abstract Syntax Tree (AST) as an intermediate representation using a context-free method; performing semantic
verification and structural correction on the AST, and performing structural optimization when the
semantics are valid to generate an optimized AST; traversing the optimized AST, matching prompt word templates in the prompt
word generation rule base, mapping semantic nodes to
structured text fragments, concatenating the
structured text fragments to form the final prompt word text, and outputting a compilation result consistent with the
semantics of the PDL specification. By introducing a PDL-oriented compilation mechanism, the method achieves automated
parsing of the input specification, structural optimization, and high-quality prompt
word generation before prompt
word generation for large language models, improving the efficiency of prompt word development and output quality.