cppsp -a transpiled script-like language base on c++
Download the cppsp_compiler.exe or compiler the sourcecode by yourself
- Requirement:prepare your own c++ compiler and set it’s folder to environment path(environment variable)
- Requirement:a 64bits c++ compiler to make sure exe can be open
- Optional: put the folder path of exe/elf/mach-o to environment
- remember delete _mac/_linux to make cppsp_compiler works
- (Optional) rename cppsp_compiler.exe(or cppsp_compiler) to any name you like to change compile command like:cppsp、abcdef….
- Install from cmd/console:
curl -L -o cppsp_compiler.exe https://github.com/user19870/cppsp/raw/refs/heads/First/cppsp_compiler.exe
curl -L -o cppsp_compiler https://github.com/user19870/cppsp/raw/refs/heads/First/cppsp_compiler_linux.delete_linux
curl -L -o cppsp_compiler https://github.com/user19870/cppsp/raw/refs/heads/First/cppsp_compiler_mac.delete_mac
- Use cmd or other console to compiler .cppsp file:
cppsp_compiler(if not in environment path:.\cppsp_compiler.exe or c:\...\cppsp_compiler.exe) script.cppsp - Setting c++ include/lib folder by .ini file
include.ini:C:…\include1,c:…\include2
lib.ini:C:…\lib1,c:…\lib2
- can compile when there is only print(“hello world”) in .cppsp
- can use almost c++ header by import
- custom pattern-driven, nested, namespace-scoped templates
- can use c++ code by @inject and @function
- enable indentation and multi-line after v1.3
- declare multi variables with
var…..type - control variables inside keyword or globle
#useclangor#usegcc: use clang++ or g++ compile command@command("..."): add command when compile like:-Os、-m64#overwrite:make@command()overwrite g++ …. or clang++ compile command like@command("g++ -Os -m64 -nostdlib -shared -o dll.dll dll.cpp")and add “*/” after int main(){..} also add “/*” in front of int main(){..}#skipcompile: skip g++/clang++ compile and directly run outputimport:import header in c++ and accept import iostream,cstdio,x,y,…..@function>: inject everything(void()、int()、bool()、even #define and using namespace) in > to the space under #include above int main().Better not put any word, symbol or blanks but enalbe “enter” or nothing after “>>” to make difference between operation likea>>band >@inject(...):inject everything in (…) to int main(){…} —-@inject(....)and@inject("....")are both legal. @inject(….) belonging to line ast and @inject(“….”) belonging to token ast but @inject(….) will be transpiled before @inject(“….”) and any keyword belonging to token ast.)print(): print content to console like print(“12\n”,” “,1,” “,2.1,true,false,” “)input(): input data to variablesvar…..type: declare variables with/without values. Support multi variables and type can be written asint/float/char/string/bool. is a value but 1+1 not(it’s expression)if/else/else if(...){...}:similar to “if/else/else if” in c++ but enable syntax:if(input(x)>1). Can write cppsp keywords and operation( =,+,-,*,/,++….) in {…}for(...){...}:similae to “for” in c++ like for( type i=0,i0;i++,j++) or for(type i:x) . Can write cppsp keywords and operation( =,+,-,*,/,++….) in {…}function f()...:function f() type {...return...}will define a function with type,function f(){...}will define a void function,function f()will declare a void function,function f(){...return...}will define a function with auto in c++. Usages
function [std::pow,std::sort,abs,sqrt] // will regist functions from c++
// but template function still need like std::sort(x,x+5,()}>)
struct S{...}: define a structure and the name of structure will become a type ,so can use something like var….S. If writestruct a b cwithout{}a ,b, and c will become type but won’t generate any c++ code@custom xxx("...",,...): @custom can let users write own syntaxs. *”…” can generate code, is similar to it but will become a placeholder and replaced by parameter when the custom syntax is called.Code will generate in global and the inner of some cppsp keywords. namespace only accept one level like:namespace n{ @custom.... }
@custom subs(," sub(",,",",,")"," {return a-b;}")
subs(int ,int a,int b)
- control variables in cppsp once a line or separate by
;
: c++ code or everything in will become an element of cppsp keyowds like :
import math.h,iostream
print( )
import string,iostream
var a,c,d = 1,
,4 int
var b = "hello world" string
var f1,f2,f3 float
var c1 char
var b1 = bool
input(f1)
print(a," ",c," ",d," ",b," ",b1," ",f1)
import iostream
var x={1,2,3} int
@inject("x[0]=3;x[1]=2; x[2]=1;")
if(true) {
x[0]=4
}
for(int i=0,i
- Cannot accept any space/blank before keyword before v1.2!
- No multi-line before v1.3!
@command()will never be multi-line but you can use following as an alternative
@command("-f1 -f2 ..... -f5")
@command("-f6 -f7 ....-f10")
with #overwrite command
@command("g++ -Os -m64 -nostdlib -shared ")
@command(" -o dll.dll dll.cpp")
@command("-mtune=native -fomit-frame-pointer -static-libgcc -ffunction-sections -fdata-sections -Wl,--gc-sections -Wl,--as-needed -s -Wl,--strip-all -Os -m64")
import iostream,vector
@functionusing namespace std;>>
print("12\n"," ",1," ",2.1,true,false," ")
print( "abc")
print(1,"\n") //abv
//print(1.1)
@inject(int x=1;int y=2;int z=3; auto is_bool = [](const std::string& s){ return s == "true" || s == "false";};)
input(x,y,z)
@function cars = {"Volvo", "BMW", "Ford", "Mazda"};};>>
print(x+y+z)
#overwrite
@command("g++ -Os -m64 -nostdlib -shared -o dll.dll dll.cpp")
@functionextern "C" __declspec(dllexport) int add(int a, int b) { return a * b;}>>