This disclosure relates to a dynamic compiler that translates formulas, scripts, and code of one programming language into another programming language, or vice versa, in real-time, and provides a user interface for a user.
The greater the complexity of a programming language, the more challenging and time-consuming it can be to learn and code in the programming languages. However, complex programming languages tend to provide broader functionality compared to simpler or more restrictive programming languages. Tools that enable use of the functionality of complex programming languages without requiring the ability to code in these languages are desirable.
The reverse compiler system provides an integrated development environment (IDE) that enables real-time translation to and from programs written in two programming languages. In some cases, the two languages vary in complexity or restrictiveness. A user may prefer to use a simpler programming language for various reasons, such as to save time in the coding process or not knowing how to code in a complex programming language. However, the user may nonetheless require the functionality of the complex programming language. For example, the coding task may be part of a broader project that can integrate modules programmed in the more complex programming language, but not the simpler programming language. Finding or hiring someone to complete the coding task in the complex programming language is cumbersome, costly, and time-consuming. In some embodiments, the reverse compiler system can also be used as an educational tool for learning various programming languages.
An exemplary reverse compiler system can translate between first code written in a first programming language (e.g., spreadsheet formulas written in a spreadsheet programming language) and second code written in a second programming language (e.g., Python code written in the Python programming language). For example, as the user inputs a spreadsheet formula with one or more arguments (input values into the formula) into a graphical user interface, the reverse compiler system may translate the entered spreadsheet formula and its arguments into functionally equivalent Python code. For example, the reverse compiler system may map the entered spreadsheet formula into a corresponding function(s) in Python code. The reverse compiler system may also determine the arguments entered with the spreadsheet formula, and may provide the arguments in the appropriate configuration to the corresponding Python function(s). The reverse compiler system may display the generated Python code and any output from running the Python code (e.g., a table of calculated values, a scientific chart or graph, data output, data visualization, images, media, etc.) in the graphical user interface. As the user edits code written in the first programming language, such as the spreadsheet formula or its arguments, in the user interface, the reverse compiler system may again translate the revised first code and its arguments into functionally equivalent second code (e.g., Python code). The reverse compiler system may display the generated second code corresponding to the edited first code or arguments and any output from running the updated second code in the graphical user interface.
The exemplary reverse compiler system is also able to translate from code written in the second programming language into code written in the first programming language. For example, the reverse compiler system may translate Python code into code describing spreadsheet formulas using a similar process as described above. For example, as the user inputs Python code into the graphical user interface, the reverse compiler system may translate the entered Python code into a functionally equivalent spreadsheet program. For example, the reverse compiler system maps the entered Python code into a corresponding spreadsheet formula(s). The reverse compiler may also determine the arguments entered with any functions in the Python code and may provide the arguments in the appropriate configuration to the corresponding spreadsheet formula(s) (or for other programming languages). The reverse compiler system may display the generated spreadsheet program and any output from running the spreadsheet program (e.g., a table of calculated values, a scientific chart or graph, data output, data visualization, images, media, etc.) in the graphical user interface. As the user edits code written in the second programming language (e.g., the Python code) in the user interface, the reverse compiler system again may translate the revised code (e.g., the revised Python code) into a functionally equivalent code in the first programming language (e.g., spreadsheet program). The reverse compiler system may display the generated spreadsheet program corresponding to the edited Python code or arguments and any output from running the updated spreadsheet program in the graphical user interface.
While the above example and other examples described herein discuss translations to and from spreadsheet programs and Python code, embodiments are not so limited. The reverse compiler system can translate between other programming languages as well.
In some embodiments, a user can edit (e.g., types or enters using preset menu) the source code editor for the spreadsheet program in user interface 100 while in “Input” mode. In an exemplary embodiment as shown by user interface 100, the user enters, into the first area 105, a spreadsheet program containing three lines of code for reading in a file, plotting a histogram based on a portion of data in the file, and transposing data from the file. In some embodiments, the user clicks the “Run Script” button 135, which can cause the reverse compiler system to generate the functionally equivalent Python code. User interface 100 may display the generated Python code in the second area 110 (i.e., the source code editor for the Python code). User interface 100 also may display the transposed data from the file (“olive.csv”) in the third area 115. The user can toggle between the “Input, “Output” or “Plot” modes to revise the code in the editable text boxes, view the transpose data, or view the histogram, respectively. As described above, the reverse compiler system may perform a similar process to translate Python code into a spreadsheet program when the user inputs or revises source code in the Python source code editor, or when translating between other programming languages.
It is understood that user interfaces 100 and 200 are exemplary and not limiting. The reverse compiler system can implement any suitable user interface including a different configuration of user interface elements compared to those shown in
Not all embodiments involve a plot, histogram, or similar to be output by the reverse compiler system. For example,
In addition to supplementary functionalities described herein, the reverse compiler system may provide functionalities provided by an integrated development environment (IDE). In some embodiments, the reverse compiler system provides an interactive graphical user interface with source code editors, debugging tools, build automation tools, and compiling capabilities. In some embodiments, the reverse compiler system performs operations typically performed by compilers, including but not limited to lexical analysis, parsing (e.g., syntax analysis), semantic analysis, and code generation. During lexical analysis, the reverse compiler system uses tokenization to convert source code input from its source code editors into a list of tokens. In some cases, the tokenization process splits the string of source code into smaller units with assigned meanings (e.g., separator, operator, keyword, literal, identifier, etc.). Following the tokenization process, the reverse compiler system can perform a parsing analysis during which the information produced during tokenization can be loaded into data structures for general use and compiling. In some embodiments, parsing involves transforming the list of tokens into an abstract syntax tree to represent the structure of the source code program.
When the reverse compiler system receives source code input in a first programming language from a user, the reverse compiler system may parse the input. Based on the tokens indicating the token value and assigned meanings, the reverse compiler system can determine which code segments correspond to a formula or function (e.g., operator or keyword) and which characters correspond to arguments (e.g., literal). For each of the code segments of the input source code written in a first programming language, the reverse compiler system determines functionally equivalent code segments written in a second programming language. In some embodiments, the reverse compiler system makes the determination based on its stored preconfigured mapping that indicates corresponding formulas, functions, operators, and/or arguments between the first and second programming languages (e.g., Python and spreadsheet formulas). Some corresponding formulas, functions, operators, arguments may be the same across the two programming languages. In some embodiments, the mapping includes information for any components regardless of whether they are the same or different across the two programming languages. The mapping may be stored using any suitable data structure (e.g., lookup table, etc.). In some cases, the reverse compiler system may store multiple mappings to enable translations between multiple combinations of languages.
Spreadsheet formula 510 has seven arguments (highlighted). The arguments “A:A” and “B:B” indicate columns A and B, respectively, in a spreadsheet. The arguments “0,” “1,” and “−1” indicate values to output depending on the result of comparison performed on columns A and B. Python code 520 is functionally equivalent to spreadsheet formula 510. In Python, columns are expressed as column number starting at 0, so columns A and B from formula 510 correspond to columns “0” and “1” in Python code 520. The output values “0,” “1,” and “−1” are expressed in the same way in Python, so the values of these arguments remain the same.
In some embodiments, the reverse compiler system may determine the corresponding arguments based on a stored mapping as described above. The reverse compiler system can look up the arguments provided in the source code input written in a first programming language and determines the corresponding argument in the second programming language. If, for example, translating from spreadsheet formulas to Python, the reverse compiler system can look up arguments provided in spreadsheet formula 510. In this case, the reverse compiler system may find that the stored mapping associates columns “A:A” and “B:B” in the spreadsheet formula to columns “0” and “1” in Python, respectively. The mapping can further associate that numerical values “0,” “1,” and “−1” correspond to numerical values “0,” “1,” and “−1” in Python, respectively. The reverse compiler system may perform a similar analysis based on the stored mapping to determine Python functions and operators corresponding to those in spreadsheet formula 510. The reverse compiler system may insert the corresponding Python arguments into the appropriate locations in Python code 520.
As seen in
In some embodiments, the reverse compiler system has already performed a previous translation between a spreadsheet program and Python code. Thus, the spreadsheet source code editor and the Python source code editor of the reverse compiler system's user interface may display functionally equivalent spreadsheet source code and Python source code, respectively. As a result of this previous translation, the reverse compiler system has stored mapping information indicating associations between corresponding spreadsheet code segments and Python code segments of the source code input by the user, as well as argument mapping information indicating arguments and positions (e.g., byte locations) in which arguments belong in the source code. Flowchart 900 depicts the steps that the reverse compiler system performs when a user seeks an updated translation by modifying the source code in the reverse compiler system's source code editor.
At step 910, the reverse compiler system may receive source code input by a user. For example, the user may edit first code written in a first programming language into a corresponding source code editor for the first programming language (e.g., Python code in the Python source code editor), such as that shown in the user interfaces of
At step 920, the reverse compiler system may determine which portion of the source code was modified. Whether the modified portion is within an argument affects the subsequent steps performed by the reverse compiler system. If the modification is within an argument, the reverse compiler system proceeds to step 940 to revise the translation with the updated argument. If the modification involves code other than an argument (e.g., as shown in exemplary modification 1000 of
At step 930, the reverse compiler system may retranslate the block of code affected by the user's source code modification. In some embodiments, retranslating involves performing the parsing and mapping steps described above (e.g., with respect to
At step 940, if the modification only involves an argument, the reverse compiler system may determine which block of the spreadsheet program is affected by the Python source code modification. In some embodiments, if the source code is a spreadsheet program, each block of the spreadsheet program corresponds to a line of code in the spreadsheet program. Other suitable ways of separating the source code into blocks can be implemented as long as the blocks are separately identifiable. In some embodiments, in other programming languages, such as Python code, the source code may be split into blocks corresponding to import attachments, from statements, function attachments, and lines of code corresponding to spreadsheet formulas.
In some embodiments, the reverse compiler system may store information to track what the source code corresponds to for each block and may use the stored information to determination the affected block. In some embodiments, the information identifies the start and end of each block (e.g., by line numbers, index, source code text, etc.). Taking the example of
At step 950, the reverse compiler system may determine which argument was modified in the first code (e.g., the Python code). The reverse compiler system can make this determination based on stored argument mapping information produced from parsing the first code (e.g., Python code). In some embodiments, the argument mapping information identifies each argument by an index (e.g., third code segment corresponding to an argument provided in the source code) and indicates a position (e.g., byte location) within the first code (e.g., Python code) to which the argument maps.
At step 960, the reverse compiler system also can determine the argument in the identified second code block (e.g., spreadsheet block) to which the first code (e.g., Python code) argument identified in step 950 corresponds. The reverse compiler system can make this determination based on stored mapping information indicating associations between code segments of the second code and the first code (e.g., spreadsheet program and Python code). Based on the stored information, the reverse compiler system may identify the code segment of the second code block (e.g., spreadsheet program block) that maps to the modified first code (e.g., Python) argument identified in step 950.
At step 970, the reverse compiler system may revise the identified argument in the second code (e.g., the spreadsheet formula) block to match the value of the modified first code (e.g., Python) argument and rebuilds the updated second code (e.g., spreadsheet program).
A depiction of the method described in flowchart 900 is described with respect to elements from
In some embodiments, the user subsequently wants to modify Python code 520 and obtain a translation of the modified code into a spreadsheet program. The user can replace the first argument from “0” to “2,” so that the updated Python code reads “np.where(dfiloc[:,2]==df.iloc . . . ” in the Python source code editor (step 910). The reverse compiler system can detect that the only modified portion was an argument (step 920), so the affected Python code does not need to be fully remapped and retranslated (step 930). Instead, the reverse compiler system can proceed to revise the current spreadsheet 510 with the updated argument.
First, the reverse compiler system determines which block of spreadsheet code corresponds to the modified Python code (step 940). As described above, the reverse compiler system stores information indicating corresponding blocks of code between the spreadsheet program and the Python code. Based on the mapping, the reverse compiler system determines that the block including Python code 520 corresponds to the block of the spreadsheet program including spreadsheet formula 510. In some embodiments, the identified spreadsheet block is identified by a block index (e.g., “Block 2” at index 2). Other indexing methods or schemes can be utilized as long as the blocks are separately identifiable.
The reverse compiler system then determines which argument in the Python code was modified (step 950). The reverse compiler system may determine that the modified argument was the first argument in Python code 520 (i.e., the argument to the first “iloc” function). The reverse compiler system may store information indication the location at which the argument is positioned in Python code 520 (e.g., at byte location “a”).
The reverse compiler system may determine to which argument in spreadsheet formula 510 the first argument in Python code 520 corresponds (step 960). The reverse compiler system may make this determination based on the mapping information stored between corresponding arguments in spreadsheet formula 510 and Python code 520. Here, the reverse compiler system can determine that the first argument in Python code 520 corresponds to the first argument in spreadsheet formula 510, which has value “A:A” and located at position 3 to 5 in spreadsheet formula 510.
The reverse compiler system may revise the identified first argument in the spreadsheet formula 510 and rebuilds the updated spreadsheet program (step 970). First, the reverse compiler system can determine the equivalent value of modified value “2” of the first argument in Python code 520 in the spreadsheet formula. The reverse compiler system can look up the equivalent value of calling a column index “2” in spreadsheet formula notation (e.g., spreadsheet formula A1 notation), which returns value “C:C.” Since the first argument in spreadsheet formula 510 is located at position 305, the reverse compiler system revises the first argument to have value “C:C.” The reverse compiler system can then rebuild the updated spreadsheet program including the revising formula “IF(C:C=B:B,0,IF(A:A>B:B,1,−1)).”
Additional mapping capabilities of the reverse compiler system are described below. In addition to mapping changes in source code, the reverse compiler system can also map changes caused by other keystrokes, such as the “enter” key and “delete” key. For example, mapping 1200 of
Embodiments described herein are performed by suitable computer systems. The user device (e.g., laptop, computer, tablet device, etc.) that a user uses to interact with the graphical user interface of the reverse compiler system stores mapping information by local and/or remote data storage means. In some embodiments, the user device establishes a network communication with a server to perform methodologies or modules discussed herein.
The computer system 1500 includes a processor 1510, memory and non-volatile memory 1520, a communications BUS 1530, a network adapter 1540, a disk interface 1550 and an interface device 1560. Various common components (e.g., cache memory) are omitted for illustrative simplicity. The computer system 1500 is intended to illustrate a hardware device on which any of the components described in the examples (and any other components described in this specification) can be implemented. The components of the computer system 1500 are coupled together via the bus 1530 or through some other known or convenient device.
This disclosure contemplates the computer system 1500 taking any suitable physical form. As an example, and not by way of limitation, a computer system 1500 may be an embedded computer system, a system-on-chip (SOC), a single-board computer system (SBC) (such as, for example, a computer-on-module (COM) or system-on-module (SOM)), a desktop computer system, a laptop or notebook computer system, an interactive kiosk, a mainframe, a mesh of computer systems, a mobile telephone, a personal digital assistant (PDA), a server, or a combination of two or more of these. Where appropriate, computer system 1500 may include one or more computer systems 1500; be unitary or distributed; span multiple locations; span multiple machines; or reside in a cloud, which may include one or more cloud components in one or more networks. Where appropriate, one or more computer systems 1500 may perform, without substantial spatial or temporal limitation, one or more steps of one or more methods described or illustrated herein. As an example, and not by way of limitation, one or more computer systems 1500 may perform in real time or in batch mode one or more steps of one or more methods described or illustrated herein. One or more computer systems 1500 may perform at different times or at different locations one or more steps of one or more methods, described or illustrated herein, where appropriate.
The processor may be, for example, a conventional microprocessor such as an Intel Pentium microprocessor or Motorola power PC microprocessor. One of skill in the relevant art will recognize that the terms “machine-readable (storage) medium” or “computer-readable (storage) medium” include any type of device that is accessible by the processor.
The memory is coupled to the processor by, for example, a bus. The memory can include, by way of example but not limitation, random access memory (RAM), such as dynamic RAM (DRAM), static RAM (SRAM), and video RAM (VRAM). The memory can be local, remote, or distributed.
The bus also couples the processor to the non-volatile memory and drive unit. The non-volatile memory is often a solid state drive (SSD), magnetic floppy or hard disk, a magnetic-optical disk, an optical disk, a read-only memory (ROM), such as a CD-ROM, EPROM, or EEPROM, a magnetic or optical card, or another form of storage for large amounts of data. Some of this data is often written, by a direct memory access process, into memory during execution of software in the computer 1500. The non-volatile storage can be local, remote, or distributed. The non-volatile memory is optional because systems can be created with all applicable data available in memory. A typical computer system will usually include, at least, a processor, memory, and a device (e.g., a bus) coupling the memory to the processor.
Software is typically stored in the non-volatile memory and/or the drive unit. Indeed, storing an entire large program in memory may not even be possible. Nevertheless, it should be understood that for software to run, if necessary, it is moved to a computer readable location appropriate for processing, and for illustrative purposes, that location is referred to as the memory. Even when software is moved to the memory for execution, the processor will typically make use of hardware registers to store values associated with the software, and local cache that, ideally, serves to speed up execution. As used herein, a software program is assumed to be stored at any known or convenient location (from non-volatile storage to hardware registers) when the software program is referred to as “implemented in a computer-readable medium.” A processor is considered to be “configured to execute a program” when at least one value associated with the program is stored in a register readable by the processor.
The bus also couples the processor to the network interface device. The interface can include one or more of a modem or network interface. It will be appreciated that a modem or network interface can be considered to be part of the computer system 1500. The interface can include an analog modem, ISDN modem, cable modem, token ring interface, satellite transmission interface (e.g., “direct PC”), or other interfaces for coupling a computer system to other computer systems. The interface can include one or more input and/or output devices. The I/O devices can include, by way of example but not limitation, a keyboard, a mouse or other pointing device, disk drives, printers, a scanner, and other input and/or output devices, including a display device. The display device can include, by way of example but not limitation, a cathode ray tube (CRT), liquid crystal display (LCD), or some other applicable known or convenient display device. For simplicity, it is assumed that controllers of any devices not depicted reside in the interface.
In operation, the computer system 1500 can be controlled by operating system software that includes a file management system, such as a disk operating system. One example of operating system software with associated file management system software is the family of operating systems known as Windows® from Microsoft Corporation of Redmond, Wash., and their associated file management systems. Another example of operating system software with its associated file management system software is the Linux™ operating system, and its associated file management system. The file management system is typically stored in the non-volatile memory and/or drive unit and causes the processor to execute the various acts required by the operating system to input and output data and to store data in the memory, including storing files on the non-volatile memory and/or drive unit.
The algorithms and displays presented herein are not inherently related to any particular computer or other apparatus. Various general purpose systems may be used with programs in accordance with the teachings herein, or it may prove convenient to construct more specialized apparatus to perform the methods of some embodiments. The required structure for a variety of these systems will appear from the description below. In addition, the techniques are not described with reference to any particular programming language, and various embodiments may thus be implemented using a variety of programming languages.
In alternative embodiments, the machine operates as a stand-alone device or may be connected (e.g., networked) to other machines. In a networked deployment, the machine may operate in the capacity of a server or a client machine in a client-server network environment, or as a peer machine in a peer-to-peer (or distributed) network environment.
The machine may be a server computer, a client computer, a personal computer (PC), a tablet PC, a laptop computer, a set-top box (STB), a personal digital assistant (PDA), a cellular telephone, an iPhone, a Blackberry, a processor, a telephone, a web appliance, a network router, switch or bridge, or any machine capable of executing a set of instructions (sequential or otherwise) that specify actions to be taken by that machine.
While the machine-readable medium or machine-readable storage medium is shown in an exemplary embodiment to be a single medium, the term “machine-readable medium” and “machine-readable storage medium” should be taken to include a single medium or multiple media (e.g., a centralized or distributed database, and/or associated caches and servers) that store the one or more sets of instructions. The term “machine-readable medium” and “machine-readable storage medium” shall also be taken to include any medium that is capable of storing, encoding or carrying a set of instructions for execution by the machine, and that cause the machine to perform any one or more of the methodologies or modules of the presently disclosed technique and innovation.
In general, the routines executed to implement the embodiments of the disclosure may be implemented as part of an operating system or a specific application, component, program, object, module or sequence of instructions, referred to as “computer programs.” The computer programs typically comprise one or more instructions set at various times in various memory and storage devices in a computer, and that, when read and executed by one or more processing units or processors in a computer, cause the computer to perform operations to execute elements involving the various aspects of the disclosure.
Further examples of machine-readable storage media, machine-readable media, or computer-readable (storage) media include, but are not limited to, recordable-type media such as volatile and non-volatile memory devices, floppy and other removable disks, hard disk drives, optical disks (e.g., Compact Disk Read-Only Memory (CD ROMS), Digital Versatile Disks, (DVDs), etc.), among others, and transmission-type media such as digital and analog communication links.
In some circumstances, operation of a memory device, such as a change in state from a binary one to a binary zero or vice-versa, for example, may comprise a transformation, such as a physical transformation. With particular types of memory devices, such a physical transformation may comprise a physical transformation of an article to a different state or thing. For example, but without limitation, for some types of memory devices, a change in state may involve an accumulation and storage of charge or a release of stored charge. Likewise, in other memory devices, a change of state may comprise a physical change or transformation in magnetic orientation or a physical change or transformation in molecular structure, such as from crystalline to amorphous or vice versa. The foregoing is not intended to be an exhaustive list in which a change in state for a binary one to a binary zero or vice-versa in a memory device may comprise a transformation, such as a physical transformation; rather, the foregoing is intended as illustrative examples.
A storage medium typically may be non-transitory or comprise a non-transitory device. In this context, a non-transitory storage medium may include a device that is tangible, meaning that the device has a concrete physical form, although the device may change its physical state. Thus, for example, non-transitory refers to a device remaining tangible despite this change in state.
Reference in this specification to “one embodiment” or “an embodiment” means that a particular feature, structure, or characteristic described in connection with the embodiment is included in at least one embodiment of the disclosure. The appearances of the phrase “in one embodiment” in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. Moreover, various features are described that may be exhibited by some embodiments and not by others. Similarly, various requirements are described that may be requirements for some embodiments but not others.
Unless the context clearly requires otherwise, throughout the description and the claims, the words “comprise,” “comprising,” and the like are to be construed in an inclusive sense, as opposed to an exclusive or exhaustive sense; that is to say, in the sense of “including, but not limited to.” As used herein, the terms “connected,” “coupled,” or any variant thereof, means any connection or coupling, either direct or indirect, between two or more elements. The coupling or connection between the elements can be physical, logical, or a combination thereof. For example, two devices may be coupled directly, or via one or more intermediary channels or devices. As another example, devices may be coupled in such a way that information can be passed there between, while not sharing any physical connection with one another. Additionally, the words “herein,” “above,” “below,” and words of similar import, when used in this application, shall refer to this application as a whole and not to any particular portions of this application. Where the context permits, words in the Detailed Description using the singular or plural number may also include the plural or singular number respectively. The word “or,” in reference to a list of two or more items, covers all of the following interpretations of the word: any of the items in the list, all of the items in the list, and any combination of the items in the list.
If the specification states a component or feature “may,” “can,” “could,” or “might” be included or have a characteristic, that particular component or feature is not required to be included or have the characteristic.
The term “module” refers broadly to software, hardware, or firmware components (or any combination thereof). Modules are typically functional components that can generate useful data or another output using specified input(s). A module may or may not be self-contained. An application program (also called an “application” or “app”) may include one or more modules, or a module may include one or more application programs.
The foregoing description of various embodiments of the claimed subject matter has been provided for the purposes of illustration and description. It is not intended to be exhaustive or to limit the claimed subject matter to the precise forms disclosed. Many modifications and variations will be apparent to one skilled in the art. Embodiments were chosen and described in order to best describe the principles of the invention and its practical applications, thereby enabling others skilled in the relevant art to understand the claimed subject matter, the various embodiments, and the various modifications that are suited to the particular uses contemplated.
While embodiments have been described in the context of fully-functioning computers and computer systems, those skilled in the art will appreciate that the various embodiments are capable of being distributed as a program product in a variety of forms, and that the disclosure applies equally regardless of the particular type of machine or computer-readable media used to actually effect the distribution.
Although the above Detailed Description describes certain embodiments and the best mode contemplated, no matter how detailed the above appears in text, the embodiments can be practiced in many ways. Details of the systems and methods may vary considerably in their implementation details, while still being encompassed by the specification. As noted above, particular terminology used when describing certain features or aspects of various embodiments should not be taken to imply that the terminology is being redefined herein to be restricted to any specific characteristics, features, or aspects of the invention with which that terminology is associated. In general, the terms used in the following claims should not be construed to limit the invention to the specific embodiments disclosed in the specification, unless those terms are explicitly defined herein. Accordingly, the actual scope of the invention encompasses not only the disclosed embodiments, but also all equivalent ways of practicing or implementing the embodiments under the claims.
The language used in the specification has been principally selected for readability and instructional purposes, and it may not have been selected to delineate or circumscribe the inventive subject matter. It is therefore intended that the scope of the invention be limited not by this Detailed Description, but rather by any claims that issue on an application based hereon. Accordingly, the disclosure of various embodiments is intended to be illustrative, but not limiting, of the scope of the embodiments, which is set forth in the following claims.
The present techniques will be better understood with reference to the following enumerated embodiments:
1. A method comprising: receiving first code written in a first programming language; generating second code written in a second programming language, the second code being functionally equivalent to the first code; detecting a modification to the second code; and updating the first code based on the detected modification.
2. The method of embodiment 1, wherein updating the first code comprises: updating the first code in real-time; and causing the updated first code to be displayed within a user interface.
3. The method of any one of embodiments 1-2, wherein detecting the modification comprises: detecting a user interaction with a user interface rendering the first code.
4. The method of any one of embodiments 1-3, wherein receiving the first code comprises: receiving at least one keyboard shortcut for entering at least one of a preset formula or a preset function, the at least one keyboard shortcut being a keyboard shortcut in the first programming language.
5. The method of any one of embodiments 1-4, wherein generating the second code comprises: performing a lexical analysis to the first code, including tokenizing the first code to produce a list of tokens.
6. The method of embodiment 5, wherein the first code is represented by a string of characters, tokenizing the first code comprises: splitting the string of first code into units having assigned meanings.
7. The method of embodiment 6, wherein the units having the assigned meanings include at least one of: a separator, an operator, a keyword, a literal, or an identifier.
8. The method of any one of embodiments 5-6 further comprising: upon determining that the lexical analysis has completed, performing a parsing analysis, including loading the list of tokens into one or more data structures for compiling.
9. The method of embodiment 8, wherein performing the parsing analysis comprises: transforming the list of tokens into an abstract syntax tree to represent a structure of the first code.
10. The method of any one of embodiments 5-9, further comprising: determining, from the list of tokens, a value and an assigned meaning of each token.
11. The method of embodiment 10, further comprising: determining, based on the value and the assigned meaning of each token, one or more segments of the first code that correspond to a formula or function, and one or more characters in the first code corresponding to an argument.
12. The method of embodiment 11, further comprising: determining, for each of the code segments of the first code, functionally equivalent code segments in the second code.
13. The method of embodiment 12, wherein determining the functionally equivalent code segments comprises: retrieving a preconfigured mapping of formulas, functions, operators, and arguments written in the first programming language to formulas, functions, operators, and arguments written in the second programming language.
14. The method of embodiment 13, wherein retrieving the preconfigured mapping comprises: determining the first programming language; determining the second programming language; and selecting the preconfigured mapping from a plurality of preconfigured mappings based the first code being written in the first programming language and the second code being written in the second programming language.
15. The method of any one of embodiments 13-14, wherein generating the second code comprises: generating a mapping indicating a position of each argument included in the first code and a position that each argument is to be inserted into the second code.
16. The method of embodiment 15, wherein the position that each argument is to be inserted into the second code comprises a byte location at which the argument is to be inserted into a corresponding segment of the second code.
17. The method of any one of embodiments 1-16, further comprising: determining a portion of the second code associated with the modification; and determining whether the portion of the second code is within an argument.
18. The method of embodiment 17, wherein the modification comprises at least one of: adding a line of code including a function to the second code, deleting a line of code from the second code, or modifying a function included in the second code.
19. The method of embodiment 18, wherein the modification modifies the function included in the second code, the method further comprises: determining one or more blocks of code from the first code affected by the modification to the function included in the second code.
20. The method of embodiment 19, wherein updating the first code comprises: identifying, based on the one or more blocks, one or more lines of code from the second code that were modified; determining one or more lines of code from the first code that are to be updated based on the one or more lines of code from the second code that were modified; and generating the updated first code comprising updates to at least some of the one or more lines of code from the first code based on the one or more modified lines of the second code.
21. The method of any one of embodiments 17-21, wherein the portion of the second code is within the argument, updating the first code comprises: determining a portion of the first code that is affected by the portion of the second code that is modified; determining an argument within the portion of the second code that was modified; determining an argument within the portion of the first code that corresponds to the argument within the portion of the second code that was modified; revising the argument within the portion of the first code to match a value of the modified argument within the portion of the second code; and rebuilding the first code based on the revised argument within the portion of the first code.
22. The method of any one of embodiments 1-21, further comprising: determining a portion of the second code associated with the modification; determining a portion of the first code related to the portion of the second code; and storing or updating information indicating a correspondence between the portion of the second code and the portion of the first code.
23. The method of any one of embodiments 1-22, further comprising: detecting an invocation to cause an existing line from the first code or the second code to be deleted; removing the existing line from the first code or the second code; and causing a mapping of the first code and the second code to be updated based on the removed existing line.
24. The method of any one of embodiments 1-24, wherein the first code is displayed within a first area of a user interface (UI) and the second code is displayed within a second area of the UI.
25. The method of embodiment 24, wherein the first area is a first code editor for editing code in the first programming language and the second area is a second code editor for editing code in the second programming language.
26. The method of any one of embodiments 1-25, wherein the first code comprises a spreadsheet formula.
27. The method of any one of embodiments 1-26, further comprising: generating a plot based on the spreadsheet formula by executing the first code or the second code.
28. The method of embodiment 27, wherein: the first code is displayed within a first area of a user interface (UI); the second code is displayed within a second area of the UI; and the plot is displayed in a third area of the UI.
29. The method of any one of embodiments 1-28, wherein the functionally equivalent code segments are determined based on a preconfigured mapping stored as a lookup table.
30. The method of embodiment 29, wherein the preconfigured mapping is generated based on prior translations performed by the code translation engine between code written in the first programming language and code written in the second programming language.
31. The method of any one of embodiments 29-30, wherein the functionally equivalent code segments are determined based on a preconfigured mapping stored as a lookup table.
32. The method of any one of embodiments 1-31, wherein generating the second code comprises: retrieving a preconfigured mapping of arguments written in the first programming language to arguments written in the second programming language; identifying, within the first code, based on the preconfigured mapping, one or more of the arguments written in the first programming language included in the first code; and determining, for each of the one or more the arguments written in the first programming language, based on the preconfigured mapping, a corresponding argument of the arguments written in the second programming language included in the second code.
33. The method of embodiment 32, wherein the preconfigured mapping includes a first rule for translating an argument written in the first programming language to an argument written in the second programming language, and a second rule for translating at least one of an operator or a function written in the first programming language into at least one of an operator or a function written in the second programming language.
34. The method of any one of embodiments 1-33, wherein the second code being functionally equivalent to the first code comprises an output produced by executing the first code being equivalent to an output produced by executing the second code.
35. The method of any one of embodiments 1-34, wherein the code translation engine performs lexical analysis and syntactic analysis of the first code.
36. The method of any one of embodiments 1-35, wherein the modification comprises an edit to the second code, detecting the modification comprises: detecting a notification to initiate a translation process to cause the first code to be updated based on the edit to the second code.
37. The method of embodiment 36, wherein the first code and the second code are displayed within a user interface (UI), the UI comprises at least one button that is invoked to cause the notification to be generated.
38. The method of any one of embodiments 1-37, further comprising: storing information indicating a correspondence between a portion of the second code associated with the modification and a portion of the first code related to the portion of the second code, wherein the information identifies a start and an end of the portion of the second code and a start and end of the portion of the first code.
39. The method of embodiment 38, wherein the information includes at least one of: a line number, an index, or source code text associated with at least one of the portion of the first code or the portion of the second code.
40. The method of any one of embodiments 1-39, further comprising: detecting changes to the first code or the second code caused by keystrokes; and updating a mapping of correspondences between the first code and the second code based on the detected changes.
41. The method of any one of embodiments 1-40, further comprising: detecting an invocation to cause a new line to be added to the first code or the second code; adding a blank line to the first code or the second code based on the detected invocation; and causing a mapping of the first code and the second code to be updated based on the added blank line.
42. The method of embodiment 41, wherein the mapping includes indications of a location of each block of code within the first code and each block of code within the second code, and the updated mapping stores an updated location of each block of code within the first code and each block of code within the second code based on the detected invocation.
43. The method of any one of embodiments 1-42, wherein the first code is received using a code translation engine, the second code is generated using the code translation engine, the modification to the second code is detected using the code translation engine, and the first code is updated using the code translation engine.
44. A system, comprising: one or more processors programmed to perform the method of any one of embodiments 1-43.
45. A non-transitory computer-readable medium storing computer program instructions that, when executed by one or more processors, effectuate operations comprising the method of any one of embodiments 1-43.
46. A code translation engine comprising one or more processors programmed to perform the method of any one of embodiments 1-43.
The present application claims priority to U.S. Provisional Application No. 63/247,123, filed Sep. 22, 2021, the disclosure of which is hereby incorporated by reference in its entirety.
Number | Date | Country | |
---|---|---|---|
63247123 | Sep 2021 | US |