Compiling and optimizing a computer code by minimizing a number of states in a finite machine corresponding to the computer code
First Claim
1. A computer-implemented method for compiling and optimizing computer code and translating the computer source code from a first programming language into a second programming language, the method comprising:
- acquiring a first source code, the first source code being written in the first programming language;
parsing, via one or more parsing expression grammar (PEG) modules and based on a first grammar associated with the first programming language determined by an augmented Backus-Naur Form (ABNF), the first source code to convert the first source code into a first abstract syntax tree (AST);
converting the first AST into a first non-deterministic finite state machine (NFSM);
converting the first NFSM into a first deterministic finite state machine (DFSM);
optimizing the first DFSM by minimizing a number of states in a finite state machine and by twice reversing the edges of the first DFSM to produce a second NFSM using a standard powerset construction by constructing only the reachable states of the first DFSM to obtain an optimized DFSM; and
converting, via at least the one or more PEG modules, the optimized DFSM into a second source code, the second source code being written in a second programming language wherein the second source code is a translation of the first source code;
the converting the optimized DFSM including converting the optimized DFSM into a third NFSM, converting the third NFSM into a second AST, and recompiling the second AST into the second source code.
1 Assignment
0 Petitions
Accused Products
Abstract
Methods and systems for compiling codes from programming languages into programming languages are disclosed. An example method may include acquiring a first code written in a first language. The method allows generating, based on the first code, a first deterministic finite state machine (DFSM). The method includes optimizing the first DFSM to obtain a second DFSM. The method includes generating, based on the second DFSM, a second code. The second code can be written in a second language. Generating the first DFSM includes parsing the first code into a first abstract syntax tree (AST), translating the first AST into a first non-deterministic finite state machine (NFSM), and converting the first NFSM into the first DFSM. Generating the second code includes translating the second DFSM into a second NFSM, translating the second NFSM into a second AST, and recompiling the second AST into a second code.
-
Citations
9 Claims
-
1. A computer-implemented method for compiling and optimizing computer code and translating the computer source code from a first programming language into a second programming language, the method comprising:
-
acquiring a first source code, the first source code being written in the first programming language; parsing, via one or more parsing expression grammar (PEG) modules and based on a first grammar associated with the first programming language determined by an augmented Backus-Naur Form (ABNF), the first source code to convert the first source code into a first abstract syntax tree (AST); converting the first AST into a first non-deterministic finite state machine (NFSM); converting the first NFSM into a first deterministic finite state machine (DFSM); optimizing the first DFSM by minimizing a number of states in a finite state machine and by twice reversing the edges of the first DFSM to produce a second NFSM using a standard powerset construction by constructing only the reachable states of the first DFSM to obtain an optimized DFSM; and converting, via at least the one or more PEG modules, the optimized DFSM into a second source code, the second source code being written in a second programming language wherein the second source code is a translation of the first source code;
the converting the optimized DFSM including converting the optimized DFSM into a third NFSM, converting the third NFSM into a second AST, and recompiling the second AST into the second source code. - View Dependent Claims (2, 3, 4, 5)
-
-
6. A system for compiling source code and translating the source code from a first programming language into a second programming language, the system comprising:
-
at least one processor; and a memory communicatively coupled to the at least one processor, the memory storing instructions, which, when executed by the at least one processor, perform a method comprising; acquiring a first source code, the first source code being written in the first programming language; parsing, via one or more parsing expression grammar (PEG) modules and based on a first grammar associated with the first programming language determined by an augmented Backus-Naur Form (ABNF), the first source code to convert the first source code into a first abstract syntax tree (AST); converting the first AST into a first non-deterministic finite state machine (NFSM); converting the first NFSM into a first deterministic finite state machine (DFSM); optimizing the first DFSM by minimizing a number of states in a finite state machine and by twice reversing the edges of the first DFSM to produce a second NFSM using a standard powerset construction by constructing only the reachable states of the first DFSM to obtain an optimized DFSM; and converting, via at least the one or more PEG modules, the optimized DFSM into a second source code, the second source code being written in a second programming language wherein the second source code is a translation of the first source code, the converting the optimized DFSM including converting the optimized DFSM into a third NFSM, converting the third NFSM into a second AST, and recompiling the second AST into the second source code. - View Dependent Claims (7, 8)
-
-
9. A non-transitory computer-readable storage medium having embodied thereon instructions, which, when executed by one or more processors, perform a method for translating source code from a first programming language into a second programming language, the method comprising:
-
acquiring a first source code, the first source code being written in the first programming language; parsing, via one or more parsing expression grammar (PEG) modules and based on a first grammar associated with the first programming language, the first source code to convert the first source code into a first abstract syntax tree (AST), wherein the grammar is determined by an augmented Backus-Naur Form; converting the first AST into a first non-deterministic finite state machine (NFSM); converting the first NFSM into a first deterministic finite state machine (DFSM); optimizing the first DFSM by minimizing a number of states in a finite state machine and by twice reversing the edges of the first DFSM to produce a second NFSM using a standard powerset construction by constructing only the reachable states of the first DFSM to obtain an optimized DFSM; converting the optimized DFSM into a third NFSM; converting the third NFSM into a second AST; and recompiling, via the one or more PEG modules and based on a second grammar associated with a second programming language, the second AST into the second source code, the second source code being written in the second programming language wherein the second source code is a translation of the first source code.
-
Specification