aa-ahmed-aa/Dorm


This is a package for running and compiling your c /c++/java/python code 💥

https://aa-ahmed-aa.github.io/Dorm/

License: Other

Language: PHP

Keywords: c, composer, cpp, java, package, python, python2, python3


Dorm

This is a package for running and compiling your c and c++ files add the compiler to the configurations file and you are ready to go 💥 .

🍯 Install

You can install the package using composer require aa-ahmed-aa/dorm

OR

to your composer.json file add this to your require list

{
    "require": {
        "aa-ahmed-aa/dorm": "~1.1"
    }
}

then run composer update

🔨 Configuration

First you need to install compilers and configure their paths in src/Config.php

C++

  • you can find the MinGW compiler Here
  • after you download the compiler files copy the MinGW folder to your C:// drive

Java

  • install jdk and configure the path in your environment variables you can find the judk Here

Python

  • install python from Here
  • if you want this package to handle both versions of python2.x and python3.x the package already do this and you can look at This Question to cnfigure both of them on the command line

🔦 Usage

First you need to setCompilationPath in this path the package will create files of the code and compile and run your code
so let's compile and run your first cpp code

require ('vendor/autoload.php');
use Ahmedkhd\Dorm\Dorm;

$obj = new Dorm();

//set compilation path
$obj->setCompilationPath( __DIR__ );
echo $obj->getCompilationPath();

Now lets compile and run some real code

C++

here we compile and run c++ code and print the result

$cpp_code = <<<'EOT'
	#include<iostream>
	using namespace std;

	int main()
	{
	    cout<<"hello, c plus plus";
	    return 0;
				}
EOT;
	
	$comp = $obj->compile( $cpp_code, "cpp" );
	echo "Compilation : " . ( ! is_array($comp) ? "Success" : "Fail" )  . "\n";
	echo "Running is : " . ( ! is_array($comp) ? $obj->run() : "Fail" ) . "\n";

Java

//java
$java_code = <<<'EOT'
	public class Main {
	public static void main(String[] args) {
        // Prints "Hello, World" to the terminal window.
        System.out.println("Hello, Java");
    }

}
EOT;


$comp = $obj->compile( $java_code, "java" );
echo "Compilation : " . ( ! is_array($comp) ? "Success" : "Fail" )  . "\n";
echo "Running is : " . ( ! is_array($comp) ? $obj->run() : "Fail" ) . "\n";

Python

$python_code = <<<'EOT'
print "Hello, Python3.4"
EOT;

$comp = $obj->compile( $python_code, "python2" );
echo "Running : " . implode( $comp )  . "\n";

🔌 Add your compiler

You can check this blog post for more information.

This package is designed to handle compile/run of any other compilers in your project

	$compilers = [
		"__COMPILER_NAME__"=>[
			"path" => "__COMPILER_PATH__",
			"file_extension" =>'__CODE_FILE_EXTENSION_',
			"compile_func" => __NAME_FOR_YOUR_COMPILER_FUNCTION__,
			"run_func" => __NAME_FOR_YOUR_RUN_FUNCTION__
		]
	];
Steps
  • Add your customized key for your configuration to use it later in your compile and run function see src/Config.php.
  • Add run and compile functions for your compiler as you named in the configuration array.
  • Test and Bom your compiler is there.

License

The MIT License (MIT). Please see License File for more information.

Project Statistics

Sourcerank 3
Repository Size 57.6 KB
Stars 3
Forks 1
Watchers 1
Open issues 1
Dependencies 2
Contributors 1
Tags 4
Created
Last updated
Last pushed

Top Contributors See all

Ahmed Khaled MOhamed

Packages Referencing this Repo

aa-ahmed-aa/dorm
This is a compiler package for compiling and running c and cpp files this package is designed to ...
Latest release v1.3 - Updated - 3 stars

Recent Tags See all

v1.3 May 05, 2018
v1.3 May 05, 2018
v1.1.0 April 29, 2018
v1.0.0 April 29, 2018

Something wrong with this page? Make a suggestion

Last synced: 2018-09-06 06:17:20 UTC

Login to resync this repository