The project aims to create a simple and convenient tool for converting scripts written in Python, in a sequence of bash commands.
The program correctly converts the following language constructs of Python:
- for i in range() (or xrange()) with different number of parameters to be passed in a similar construction shell bash: for (i = BEGIN; i <= END; i ++) or for i in {BEGIN..END};
- implementation using the print output is converted to a similar design echo;
- also processed string literals and numeric values.
To analyze and convert Python script commands in the program used class NodeVisitor module ast (Abstract Syntax Trees). Module 'ast' helps Python applications to process trees of the Python abstract syntax grammar. This module helps to find out programmatically what the current grammar looks like. In Abstract Syntax Trees (AST) as internal vertices are the operators of the programming language, as well as the leaves - the operands they passed. Thus, in contrast to the parse tree in AST does not include items that do not affect the semantics of the program, such as braces, semicolons, and so on, because the information about the division of the organization itself carries nodes in the tree.
python main.py [-h] [-o {mem,spd}] [-v] pyscript pyscript - mandatory command-line argument specifies the file name * .py Optional arguments: -h, --help - displays the help message and exit the program; -o [mem,spd], --optimized [mem,spd] - optimizing code for efficient use of memory, or the maximum speed; -v, --verbose - enable verbose output.
Python 2.7.9