Chip code parsing method, device and medium based on context semantic perception

By using a context-based semantic awareness method, chip code is parsed character by character and the code state is recorded using a stack to determine the parent-child relationship of custom tags. This solves the problem of low efficiency in parsing custom code in existing technologies and enables fast and accurate parsing of chip code.

CN122387458APending Publication Date: 2026-07-14METAX INTEGRATED CIRCUITS (SHANGHAI) CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
METAX INTEGRATED CIRCUITS (SHANGHAI) CO LTD
Filing Date
2026-04-22
Publication Date
2026-07-14

AI Technical Summary

Technical Problem

Existing code parsers cannot effectively identify and parse custom code inserted into chip code, resulting in low parsing efficiency and insufficient accuracy.

Method used

A context-aware semantic approach is adopted. By parsing the chip code character by character, the code state is obtained and stored in the stack. Based on the code state stored in the stack, the context semantics are perceived, the parent-child relationship of custom tags in the custom code is determined, and the target code is generated based on this.

Benefits of technology

It improves the efficiency and accuracy of custom code parsing, ensuring fast and accurate parsing of chip code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122387458A_ABST
    Figure CN122387458A_ABST
Patent Text Reader

Abstract

The application relates to the chip technical field, in particular to a chip code analysis method, device and medium based on context semantic perception, which comprises the following steps: S1, obtaining chip code to be processed, wherein the chip code to be processed comprises code generated based on a preset standard syntax and self-defined code interpolated in the code generated based on the preset standard syntax; S2, analyzing the chip code to be processed according to characters, obtaining a code state, and storing the obtained code state in a stack; S3, perceiving context semantics based on the code state stored in the stack, and determining the parent-child relationship of a self-defined label in the self-defined code; and S4, generating target code based on the parent-child relationship of the self-defined label and self-defined parameters. The application improves the chip code analysis efficiency and accuracy of the chip code with the interpolated self-defined code.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of chip technology, and in particular to a chip code parsing method, device, and medium based on context semantic awareness. Background Technology

[0002] During chip development, debugging and other operations require setting corresponding attribute information for chip interfaces. As chips become increasingly large, the number of chip interfaces also grows exponentially. To improve the efficiency of processing chip interface attribute information, custom code can be inserted at different locations within the chip code to automate batch processing of this information. However, this inserted custom code typically uses non-standard syntax, which existing code parsers cannot directly recognize and parse. Furthermore, the meaning of the custom code may differ depending on its insertion location. Therefore, providing a method to accurately and quickly parse chip code with interpolated custom code is a pressing technical problem that needs to be solved. Summary of the Invention

[0003] The purpose of this invention is to provide a chip code parsing method, device, and medium based on context semantic awareness, which improves the efficiency and accuracy of chip code parsing with interpolated custom code.

[0004] According to a first aspect of the present invention, a chip code parsing method based on context semantic awareness is provided, comprising: Step S1: Obtain the chip code to be processed. The chip code to be processed includes code generated based on a preset standard syntax and custom code interpolated in the code generated based on the preset standard syntax. The custom code includes custom tags and custom parameters. Step S2: Parse the chip code to be processed by character, obtain the code status, and store the obtained code status in the stack; Step S3: Based on the semantic awareness of the code state stored in the stack, determine the parent-child relationship of custom tags in custom code; Step S4: Generate target code based on the parent-child relationship of custom tags and the parsing of custom parameters.

[0005] According to a second aspect of the present invention, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being configured to perform the method described in the first aspect of the present invention.

[0006] According to a third aspect of the present invention, a computer-readable storage medium is provided, storing computer-executable instructions for performing the method described in the first aspect of the present invention.

[0007] Compared with existing technologies, this invention has significant advantages and beneficial effects. Through the above technical solution, the chip code parsing method, device, and medium provided by this invention, based on context semantic awareness, achieve considerable technological advancement and practicality, and have broad industrial application value. It possesses at least the following beneficial effects: This invention interpolates custom code into a preset standard syntax, parses the chip code to be processed character by character, obtains the code state, records the code state using a stack, perceives the semantics of the following text based on the code state stored in the stack, determines the parent-child relationship of custom tags in the custom code, and then parses and generates the target code based on the parent-child relationship of custom tags and custom parameters. This invention can accurately and quickly parse chip code with interpolated custom code, improving the parsing efficiency and accuracy of chip code with interpolated custom code. Attached Figure Description

[0008] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0009] Figure 1 A flowchart of a chip code parsing method based on context semantic awareness provided in an embodiment of the present invention. Detailed Implementation

[0010] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0011] This invention provides a chip code parsing method based on context semantic awareness, such as... Figure 1 As shown, it includes: Step S1: Obtain the chip code to be processed. The chip code to be processed includes code generated based on a preset standard syntax and custom code interpolated in the code generated based on the preset standard syntax. The custom code includes custom tags and custom parameters.

[0012] As an example, the preset standard syntax is JSON syntax. The chip code to be processed is generated based on a JSON schema, which includes multiple key-value pairs. These key-value pairs can be nested; for example, a key's value may contain a key-value pair. Custom code can be generated based on XML syntax rules. For example, inserting "..." into the chip code to be processed... <contract> clk="my_clock", resetn="reset_signal"< / contract> ",in, <contract>< / contract> This is a custom label; clk="my_clock" and resetn="reset_signal" are custom parameters. <contract> To customize the start label,< / contract> For custom closing tags.

[0013] Step S2: Parse the chip code to be processed by character, obtain the code status, and store the obtained code status in the stack.

[0014] It should be noted that existing code parsing is line-by-line parsing, while the chip code parsing process in this application is character-by-character parsing. The code state is obtained based on the text composed of the parsed continuous characters, and the obtained code state is stored in the stack, thereby obtaining the context code state.

[0015] Step S3: Based on the semantic awareness of the code state stored in the stack, determine the parent-child relationship of custom tags in custom code.

[0016] It should be noted that while custom tags can be obtained through character parsing, it is impossible to determine whether they are parent or child tags. However, by using the code state stored in the stack, the semantic context of the code can be perceived, thereby clarifying the parent-child relationship of custom tags in the custom code.

[0017] Step S4: Generate target code based on the parent-child relationship of custom tags and the parsing of custom parameters.

[0018] It should be noted that the target code can be accurately generated based on the parent-child relationship of custom tags.

[0019] As one embodiment, in step S2, the step of parsing the chip code to be processed by character includes: If the parsed content is a single-line comment or a multi-line comment, such as a single-line / / or multiple-line / * * / , then the current code state is determined to be the comments state.

[0020] If the parsed content is to read the root node of the preset standard syntax, then the current code state is determined to be the parsing start state. At this time, the parser is in the initial state and has not yet recognized any valid syntax units, such as {, [, key, value.

[0021] If the parsed content is a complete and closed standard syntax structure, then the current code state is determined to be the parsing end state. This is the parser's end state, such as when parsing is completed normally or when a terminator is encountered.

[0022] If the parsing content involves entering the curly braces {} and preparing to read key-value pairs, then the current code state is determined to be the object parsing state. At this time, the parser is currently in the object context, that is, inside the curly braces { ...}, and is parsing the key-value pairs within the object.

[0023] If the parsed content is a separator for reading keys and values, then the current code state is determined to be the state after reading the keys. At this time, the parser has just finished parsing a key and is waiting to parse the separator, such as:

[0024] If the parsed content is a value to be read, then the current code state is determined to be the state after reading the colon. At this time, the parser has just finished parsing the colon after the key and is waiting to parse the value.

[0025] If the parsed content indicates that the next key or value is waiting to be read, then the current code state is determined to be after_comma, where the parser has just finished parsing a key-value pair or array element and is waiting to parse the next element.

[0026] If the parsing content is to enter the [] and prepare to read array elements, then the current code state is determined to be array parsing state array. At this time, the parser is currently in the array context, that is, inside [...], and is parsing array elements.

[0027] If the parsed content is a key, then the current code state is determined to be Key. Specifically, if the parsed content is a key enclosed in single quotes, then the current code state is determined to be single_quoted_key; if the parsed content is a key enclosed in double quotes, then the current code state is determined to be double_quoted_key; if the parsed content is a key without quotes, then the current code state is determined to be unquoted_key.

[0028] If the parsed content is a value, the current code state is determined to be Value. Specifically, if the parsed content is a value enclosed in single quotes, the current code state is determined to be single_quoted_val; if the parsed content is a value enclosed in double quotes, the current code state is determined to be double_quoted_val; if the parsed content is an unquoted value, the current code state is determined to be unquoted_val; and if the parsed content is a primitive value, the current code state is determined to be primitive_value.

[0029] If the parsed content is a custom tag, then the current code state is determined to be Contracts.

[0030] If the parsed content is a custom parameter, then the current code state is determined to be Params.

[0031] As one embodiment, step S3 includes: Step S31: If the previous state of the state corresponding to the custom tag in the stack is Key, then the custom tag is determined to be the parent tag.

[0032] It should be noted that the custom parameters corresponding to the parent tag can be applied to all child tags.

[0033] Step S32: If the previous state of the state corresponding to the custom tag in the stack is value, then the custom tag is determined to be a child tag, and the custom tag in the stack whose state is Contracts and is the parent tag is determined to be the parent tag of the custom tag.

[0034] Steps S31-S32 can determine the parent-child relationships between all custom tags.

[0035] As one embodiment, the custom parameters corresponding to the parent tag include chip interface attribute information, which includes one or more of clock information, reset information, input information, and output information. The custom parameters corresponding to the child tag include chip interface attribute information and inheritance type information, where inheritance type includes inheritance, overriding, and ignoring. Step S4 includes: Step S41: Obtain the chip interface attribute information of the parent tag corresponding to the sub-tag of the chip interface.

[0036] Step S42: Based on the chip interface attribute information and inheritance type information corresponding to the sub-tags of the chip interface, modify the chip interface attribute information of the parent tag to generate the chip interface attribute information corresponding to each chip interface; Step S43: Bind the chip interface attribute information corresponding to the chip interface to the corresponding chip interface.

[0037] As one embodiment, step S42 includes: Step S421: If the sub-label corresponding to the chip interface is inherited, then proceed to step S422; if the sub-label corresponding to the chip interface is overridden, then proceed to step S423; if the sub-label corresponding to the chip interface is ignored, then proceed to step S424.

[0038] Step S422: Determine the chip interface attribute information corresponding to the parent tag as the chip interface attribute information corresponding to the child tag, and then execute step S425.

[0039] It is understandable that if the inheritance type of the child tag is inheritance, then the chip interface corresponding to the child tag directly inherits the chip interface attribute information of the parent tag.

[0040] Step S423: Obtain the chip interface attribute information corresponding to the sub-tag as the attribute information to be replaced, replace the information corresponding to the attribute to be replaced in the chip interface attribute information corresponding to the parent tag with the attribute information to be replaced, determine the replaced attribute information as the chip interface attribute information of the chip interface corresponding to the sub-tag, and execute step S425.

[0041] It is understandable that the attribute to be replaced is the attribute corresponding to the attribute information to be replaced.

[0042] Step S424: If the chip interface attribute information corresponding to the sub-tag is empty, skip the attribute information binding operation of the chip interface corresponding to the sub-tag. If the chip interface attribute information corresponding to the sub-tag is not empty, obtain the chip interface attribute information corresponding to the sub-tag as the attribute information to be deleted, delete the attribute information to be deleted in the chip interface attribute information corresponding to the parent tag, and determine the chip interface attribute information corresponding to the parent tag after deleting the attribute information to be deleted as the chip interface attribute information of the chip interface corresponding to the sub-tag. Then execute step S425.

[0043] Step S425: If the attribute information of all chip interfaces has been analyzed, proceed to step S43; otherwise, return to step S421.

[0044] It should be noted that, through steps S421-S425, the chip interface attribute information corresponding to the parent tag is first obtained. Then, based on the inheritance type parameter and the chip interface attribute information corresponding to the child tag, the chip interface attribute information corresponding to the parent tag is inherited, partially overridden, or ignored. It can be understood that for chip interfaces with identical interface attribute information, the chip interface attribute information corresponding to the parent tag can be directly inherited. For interfaces that only require modification of partial attribute information, the attribute information can be partially modified based on the chip interface attribute information corresponding to the parent tag to obtain the chip interface attribute information. For chip interfaces that do not require checking, the inheritance type parameter can be directly set to ignore, and the interface attribute information of the ignored chip interfaces is not bound. For chip interfaces that require partial attribute information to be ignored, the chip interface attribute information to be ignored can be specified in the chip interface attribute information corresponding to the child tag. The processing of steps S421-S425 improves the accuracy and efficiency of generating chip interface attribute information.

[0045] This invention inserts custom code into a preset standard syntax, parses the chip code to be processed character by character, obtains the code state, records the code state using a stack, perceives the semantics of the following text based on the code state stored in the stack, determines the parent-child relationship of custom tags in the custom code, and then parses and generates the target code based on the parent-child relationship of custom tags and custom parameters. This invention can accurately and quickly parse chip code with interpolated custom code, improving the parsing efficiency and accuracy of chip code with interpolated custom code.

[0046] It should be noted that some exemplary embodiments are described as processes or methods depicted as flowcharts. Although the flowcharts describe the steps as sequential processes, many of these steps can be performed in parallel, concurrently, or simultaneously. Furthermore, the order of the steps can be rearranged. A process can be terminated when its operation is complete, but it may also have additional steps not included in the figures. A process can correspond to a method, function, procedure, subroutine, subroutine, etc.

[0047] This invention also provides an electronic device, including: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being configured to perform the method described in this invention.

[0048] This invention also provides a computer-readable storage medium storing computer-executable instructions for performing the methods described in this invention.

[0049] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention in any way. Although the present invention has been disclosed above with reference to preferred embodiments, it is not intended to limit the present invention. Any person skilled in the art can make some modifications or alterations to the above-disclosed technical content to create equivalent embodiments without departing from the scope of the present invention. Any simple modifications, equivalent changes, and alterations made to the above embodiments based on the technical essence of the present invention without departing from the scope of the present invention shall still fall within the scope of the present invention.

Claims

1. A chip code parsing method based on context semantic awareness, comprising: Step S1: Obtain the chip code to be processed. The chip code to be processed includes code generated based on a preset standard syntax and custom code interpolated in the code generated based on the preset standard syntax. The custom code includes custom tags and custom parameters. Step S2: Parse the chip code to be processed by character, obtain the code status, and store the obtained code status in the stack; Step S3: Based on the semantic awareness of the code state stored in the stack, determine the parent-child relationship of custom tags in custom code; Step S4: Generate target code based on the parent-child relationship of custom tags and the parsing of custom parameters.

2. The method according to claim 1, characterized in that, In step S2, the step of parsing the chip code to be processed by character includes: If the parsed content is a comment on the current line or a comment on multiple lines, then the current code state is determined to be the comments state. If the parsed content is to read the root node of the preset standard syntax, then the current code state is determined to be the parsing start state; If the parsed content is a complete and closed standard syntax structure, then the current code state is determined to be the parsing end state. If the parsed content is to enter the {} and prepare to read key-value pairs, then the current code state is determined to be the object parsing state. If the parsed content is a separator for waiting to read keys and values, then the current code state is determined to be the state after reading the key; If the parsed content is a value waiting to be read, then the current code state is determined to be the state after reading the value after the colon; If the parsed content indicates that the next key or value is waiting to be read, then the current code state is determined to be the state after reading the comma. If the parsed content is to enter the [] and prepare to read array elements, then the current code state is determined to be array parsing state. If the parsed content is a key, then the current code state is determined to be Key; If the parsed content is a value, then the current code state is determined to be Value; If the parsed content is a custom tag, then the current code state is determined to be Contracts; If the parsed content is a custom parameter, then the current code state is determined to be Params.

3. The method according to claim 2, characterized in that, If the parsed content is a key, then determining the current code state as Key includes: If the parsed content is a key enclosed in single quotes, then the current code state is determined to be single_quoted_key; If the parsed content is a key enclosed in double quotes, then the current code state is determined to be double_quoted_key; If the parsed content is an unquoted key, then the current code state is determined to be unquoted_key.

4. The method according to claim 2, characterized in that, If the parsed content is a value, then determining the current code state as Value includes: If the parsed content is a value enclosed in single quotes, then the current code state is determined to be single_quoted_val; If the parsed content is a value enclosed in double quotes, then the current code state is determined to be double_quoted_val; If the parsed content is an unquoted value, then the current code state is determined to be unquoted_val; If the parsed content is a primitive value, then the current code state is determined to be primitive_value.

5. The method according to claim 1, characterized in that, Step S3 includes: Step S31: If the previous state of the state corresponding to the custom tag in the stack is Key, then determine that the custom tag is the parent tag; Step S32: If the previous state of the state corresponding to the custom tag in the stack is value, then the custom tag is determined to be a child tag, and the custom tag in the stack whose state is Contracts and is the parent tag is determined to be the parent tag of the custom tag.

6. The method according to claim 1, characterized in that, The custom parameters corresponding to the parent tag include chip interface attribute information, and the custom parameters corresponding to the child tag include chip interface attribute information and inheritance type information. The inheritance type includes inheritance, overriding, and ignoring. Step S4 includes: Step S41: Obtain the chip interface attribute information of the parent tag corresponding to the sub-tag of the chip interface; Step S42: Based on the chip interface attribute information and inheritance type information corresponding to the sub-tags of the chip interface, modify the chip interface attribute information of the parent tag to generate the chip interface attribute information corresponding to each chip interface; Step S43: Bind the chip interface attribute information corresponding to the chip interface to the corresponding chip interface.

7. The method according to claim 1, characterized in that, Chip interface attribute information includes one or more of the following: clock information, reset information, input information, and output information.

8. The method according to claim 1, characterized in that, The preset standard syntax is JSON syntax.

9. An electronic device, characterized in that, include: At least one processor; And, a memory communicatively connected to the at least one processor; The memory stores instructions that are executed by the at least one processor, the instructions being configured to perform the method of any one of claims 1-8.

10. A computer-readable storage medium, characterized in that, The device stores computer-executable instructions for performing the method of any one of claims 1-8.