|
Abstract syntax tree (AST) was an important intermediate expression form of code. Aiming at the deficiencies of existing lexical and syntax analysis tool JavaCC (Java Compiler Compiler) that it did not support the new C++ standard and did not have a good error handling mechanism, an abstract syntax tree construction analysis model based on JavaCC was proposed in this paper. First, C++ grammar rules through the EBNF (Extended Backus-Naur Form) are defined, and a rule expansion method is proposed to deal with future syntax updates. Secondly, a syntax tree is constructed based on the JavaCC by generating lexical and grammar parser, and the key information is extracted through traversing the syntax tree. Thirdly, some strategies are proposed such as embedding Java code, skipping mismatched grammatical fragments, and constructing the feature hash of syntax tree nodes for error handling. Finally, a prototype system based on this model is designed and developed in this paper, and the effectiveness of the model in both time and space dimensions is verified through open source engineering experiments adopting C++ new standard. |
|
Keywords:C++;syntax tree;JavaCC;syntax change;error handling;construction analysis model |
|