43
loading...
This website collects cookies to deliver better user experience
#type declaration
type dec_type = def(int)->int
type first_type = def(int)
def decorator(dec_type func)->first_type:
def value(int c):
printf("Answer is %d\n",func(c))
return value
@decorator
def dec_test(int x)->int:
return x*x
def main():
dec_test(4)
#type declaration
type dec_type = def(int)->int
type first_type = def(int)
def decorator(dec_type func)->first_type:
def value(int c):
printf("Answer is %d\n",func(c))
return value
def temp_dec_test(int x)->int:
return x*x
first_type dec_test=decorator(temp_dec_test)
def main():
dec_test(4)
def main():
int a=0
int b=7
int c=7
match a,b,c:
case 5,7,8:
printf("a is 5,b is 7 and c is 8")
case 4,7,_:#c can be anything
printf("a is 4 but b is 7")
break #we dont want default to execute
case 4,_,7:#b can be anything
printf("a is 4 but c is 7")
break #we dont want default to execute
case 8,_:#b and c can be anything
printf("a is 8")
case _:
printf("idk")
#optional
default:#will be executed at the end if no break
printf("\nHello\n")
git clone -b rewrite https://github.com/peregrine-lang/Peregrine.git
cd Peregrine
meson builddir
cd builddir
ninja
./peregrine.elf
in the builddir folder./peregrine.elf compile path_to_file.pe
.It will create the executable named ./a.out
. Run it to see the result. Check the can_comp.pe file in the root directory to know what you can do with the c++ backend at this point ./peregrine.elf compile path_to_file.js.pe -js
.index.js
. Run the generated javascript using node index.js
. Check the can_comp.js.pe file in the root directory to know what you can do with the js backend at this point./peregrine.elf
then it will parse ../Peregrine/test.pe
and print the tokens and parse tree in the form of s expression.