Skip to content

spartanproj/Rosemary

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rosemary

A blend of Python and C. Transpiled to C

  • Check out /examples for more use cases!
  • Lead dev werdl is away for a week so no pushing for a while!

Why use Rosemary?

Ease of use

  • You can write short, efficient code

    Download the Visual Studio Code extension which makes your code colourful and includes IntelliSense for you to code faster.

  • Easy for both Python, Ruby, C and Java programmers to approach

Speed

  • It is very fast (Takes <50 ms to compile to C)
  • The program below takes 13ms to compile.
ints a,b,c
while a<1 {
    print "Enter number of scores: "
    input a
}
if a<=2 {
    print "a is 2"
}
floats s
print "Enter one value at a time: "
while b<a {
    input c
    s+=c
    b++
}
print "Mean: "
print s/a

Code insertion

  • You can insert C directly into your program!

Syntax

Rosemary

C

Python

if x>=1 {
    print "hi"
}
if (x>=1) {
    printf("hi");
}
if x>=1:
    print("hi")
float a = 0
while x>2 {
    input a
    print a
}
float a = 0;
while (x>2) {
    scanf("%f",&a);
    printf("%d",a);
}
while x>2:
    a=float(input())
    print(a)
loop 10 {
    print "hi"
}
for (int x=0;x<10;x++) {
    printf("hi");
}
for x in range(10):
    print("hi")
int x=0
extern "x=3;" // c in rsmy
print x
int x=0;
x=3; // using c in c
printf("%d",x);
# Not possible
int x=0
x+=1
print x
int x=0;
x+=1;
print x;
x=0;
x+=1;
print(x);
strings x
input x
if "hi"==x { # note yoda notation
    print "Hello","There" //HelloThere
}
char * f=malloc(8192);
scanf("%s", f)
if(!strcmp(f,"gh")){
    printf("Hello\n");
}
x=str(input())
if x=="hi":
    print("Hello")
func x(int xz,int yz) -> int{
    int result=xz*yz
    print result
    ret result
}
int x(int xz, int yz) {
    int result=xz*yz;
    printf("%d",result);
    return result;
}
def x(xz: int,yz: int) -> int:
    result=xz*yz
    print(result)
    return result

Types: The list

Float

  • Floating point decimal number
  • Equivalent to C's float

Int

  • Integer
  • Equivalent to <stdint.h>'s int64_t

String

  • String
  • Equivalent to C's char *
  • No segfaults (you hope)

Website

  • Is autogenerated from markdown with md.py
  • No cmd line arguments needed
  • Will write to docs/index.html
  • Also uses python markdown extension

List of reserved keywords

  • Do not use any keywords in code in variables, functions etc.

Types

int
ints

string
strings

float
floats

bool
bools

Control flow

if
elif
else

label
goto

loop
while

Builtins

inc
extern

print
input

Functions

func (all type are valid return types)

ret

Libraries

std

Operators

Basic

=
+
-
*
/

Comparison

==
!=
<
>
<=
>=

Other::Functions

(
)
{
}
->
,

Other::Maths

+=
-=
*=
/=
++
--

Library functions

Maths

  • These are just calls to the math.h C API. An internal function handles the function definitions.
func sin(float x) -> float
func cos(float x) -> float
func tan(float x) -> float
func asin(float x) -> float
func acos(float x) -> float
func atan(float x) -> float
func atan2(float y, float x) -> float
func sinh(float x) -> float
func cosh(float x) -> float
func tanh(float x) -> float
func exp(float x) -> float
func log(float x) -> float
func log10(float x) -> float
func pow(float base, float exponent) -> float
func sqrt(float x) -> float
func ceil(float x) -> float
func floor(float x) -> float
func fabs(float x) -> float
func fmod(float numerator, float denominator) -> float
func exp2(float x) -> float
func expm1(float x) -> float
func log1p(float x) -> float
func log2(float x) -> float
func cbrt(float x) -> float
func erf(float x) -> float
func erfc(float x) -> float
func hypot(float x, float y) -> float
func lgamma(float x) -> float
func tgamma(float x) -> float
func nearbyint(float x) -> float
func rint(float x) -> float
func round(float x) -> float
func trunc(float x) -> float

File API

func fileread(string filename) -> string
func fileow(string filename,string text) -> int
func fileoa(string filename,string text) -> int
func filew(string filename,string text,string mode) -> int

Standard Library

bool true=1
bool false=0
func flip(bool bit) -> bool
func intflip(int bit) -> int
func printn(string x) -> int
func printnn(float x) -> int
func strlen(string t) -> int
func strint(string t) -> int

String (included by default)

func strcpy(string dest, string src) -> string
func strncpy(string dest, string src, int n) -> string
func strcat(string dest, string src) -> string
func strncat(string dest, string src, int n) -> string
func strcmp(string str1, string str2) -> int
func strncmp(string str1, string str2, int n) -> int
func strlen(string str) -> int
func strchr(string str, int c) -> string
func strrchr(string str, int c) -> string
func strstr(string haystack, string needle) -> string
func strtok(string str, string delim) -> string