A Simulated C++ Interpreter
Project description
Scierra
Scierra [see-eh-rah] is a Simulated C++ Interpreter with Recurrent Adaptation.
In human words, it's a interactive interpreter for C++, which allows you to run and debug your program immediately as you type. Well, basically. But the implementation is slightly trickier.
To get a quick start, simply launch Scierra on the terminal and type cout << "Hello, World!";
. Yes, that's a complete C++ program in Scierra!
WARNING: Scierra is still under development. Even though many vital aspects of C++ (e.g. function definition, templates, classes) are already supported, Scierra does not handle input statements very well. This is unfortunately keeping Scierra in Beta...
Navigation
Example
An sample program running on the Scierra interpreter:
++> cout << "Hello, World!";
Hello, World!
++> int factorial(int n){
--> if (n==1 || n==0)
--> return 1;
--> else return n * factorial(n-1);
--> }
++> cout << "10 factorial is: " << factorial(10);
10 factorial is: 3628800
Installation
Prerequisites:
-
Python must be installed and added to PATH.
The key ideas of Scierra and it's CLI have been implemented in Python.
-
GCC (GNU Compiler Collection) must be installed and added to PATH.
This allows Python to access G++ through the command line. If you're a Linux user, there's a good chance that GCC tools are already included in your distro. Users of other operating systems like Windows or MacOS may need to make additional installations. MinGW has been tested to work with Scierra on Windows.
Install with PIP
Install Scierra with PIP using:
$ pip install scierra
After installation, run Scierra on your terminal using:
$ scierra
Usage
Quick Start
Launch scierra
in your terminal, and try pasting in the full sample program below.
Note Scierra's ability to automatically categorise whether the block of code you've just typed belongs to the main
function section, global declarations section, or preprocessors section (refer to the anatomy of a C++ program in Scierra). The <esc>
command closes the interpreter.
cout << "Hello, World!\n";
#define CYAN "\033[36m"
#define GREEN "\033[32m"
#define DEFAULT "\033[0m"
cout << GREEN << "I am SCIERRA" << DEFAULT << endl;
int factorial(int n){
if (n==1 || n==0)
return 1;
else return n * factorial(n-1);
}
cout << CYAN << "10 factorial is: " << factorial(10) << DEFAULT << endl;
<esc>
Below is a demo of the above program running in a terminal with Scierra:
Keywords
Type these special keywords at any stage when writing your code to perform special functions.
-
<print>
: Prints out the code you've written so far. -
<restart>
: Restarts another interpreter session and forgets all local variables. -
<esc>
: Terminates Scierra.
Code keywords
Put the following keywords at the start of each block of your code for special operations.
-
<
: Using this keyword before a single-lined statement without any semicolons (e.g.<10+23
or<"Hey!"
) makes Scierra automatically output the evaluated value of the statement. It works with all data types, variables and classes that supportscout
statements. You can even join multiple outputs together! E.g.++> int x = 132; ++> < x*7 924 ++> < x%127 << x%12 << "COOL!" 50COOL! ++>
-
<prep>
: Forcefully specifies that the block of code that you type belongs to the 'preprocessor' section of the program. E.g.++> <prep> --> const int Answer_to_Ultimate_Question_of_Life = 42; ++>
This puts
const int Answer_to_Ultimate_Question_of_Life = 42;
in the 'preprocessors' section. Without the<prep>
keyword, this statement would be automatically placed in themain
function by Scierra.Refer to: Anatomy of a C++ Program in Scierra.
-
<glob>
: Forcefully specifies that the block of code that you type belongs to the 'globals' section of the program.Refer to: Anatomy of a C++ Program in Scierra.
-
<main>
: Forcefully specifies that the block of code that you type belongs to themain
function in the program.Refer to: Anatomy of a C++ Program in Scierra.
Docs
Anatomy of a C++ Program in Scierra
Scierra divides a C++ program into three distinct sections: the 'preprocessor' section, the 'globals' section, and the 'main' section. Please refer to the keywords and expressions table for the full list of keywords and expressions that Scierra uses to categorise a block of code. However, here is a quick overview:
The 'preprocessor' section comes at the top of the program. This is where libraries are imported and namespaces are defined. By default in Scierra, the libraries iostream
, sstream
, fstream
, vector
and string
are already imported, and the namespace std
is under use. The 'globals' section is reserved for global class and function declarations, while the 'main' section goes into the main
function of your C++ program.
When you enter a block of code in Scierra, it automatically categorises it into one of these three sections based on syntactical keywords and expressions. You can override this automatic behaviour by using one of the code keywords.
Keywords and Expressions Table
Here is a table showing the different keywords and expressions that Scierra uses to categorise your block of code.
Preprocessor Section | Globals Section | Main Section |
---|---|---|
#include statement |
class keyword |
Anything that doesn't fit into the former two sections |
#define statement |
struct keyword |
|
typedef keyword |
return keyword |
|
using keyword |
void keyword |
|
template keyword |
||
typename keyword |
Unsupported features
Scierra supports most features that come with your installed version of GCC.
However, unfortunately the following features are not yet supported by Scierra:
-
any expression involving inputs
-
lambda expressions
-
range-based for loops
LICENSE
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file scierra-0.6.1.tar.gz
.
File metadata
- Download URL: scierra-0.6.1.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1e58124a6ea51cac18ced40c28d913c72c30198713120faaadfcaa340352d7c |
|
MD5 | 3575b77a053f424e547a169aacd5c7cf |
|
BLAKE2b-256 | 2f2ea0a5ff9c6c25c76f1b1cc09d8163670fa5ff6afed2a020926cf1bd2aa56f |
File details
Details for the file scierra-0.6.1-py3-none-any.whl
.
File metadata
- Download URL: scierra-0.6.1-py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d584ade06cfa47af71910f6888bd23f1af931f13958b2f1330e296334b3c0bb2 |
|
MD5 | 95e6429411d3ff4505a86ed707d84912 |
|
BLAKE2b-256 | 884ff0c1c338e115aefbb53a8a6159c835a3d739f25d65b563ef1655a0dc7f4e |