GithubHelp home page GithubHelp logo

lamm-mit / falcon-programming-language Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ericlbuehler/falcon-programming-language

3.0 0.0 0.0 153.37 MB

The Falcon Programming Language.

License: MIT License

C++ 65.06% Python 0.07% C 34.82% HTML 0.02% Batchfile 0.02%

falcon-programming-language's Introduction

Falcon Programming Language - Version 1.2.4

Eric Buehler 2022

Falcon is a multithreaded, multi-paradigm interpreted programming language, with a focus on readability and simplicity. It is dynamically typed, and has automatic garbage collection based on reference counting and a tri-generational garbage collector. In comparison to other languages, it a hybrid of Python and C, with the benefits of Python and the syntax of C.

Falcon is implemented in C++. However, although the compiler and virtual machines do not use object oriented features and could mostly be compiled in C, the lexer and parser make heavy use of such features.

Builtins

  • print
  • __build_class__
  • id
  • input
  • repr
  • iter
  • next
  • round
  • enumerate
  • range
  • zip
  • globals
  • locals
  • alllocals
  • len
  • copyright
  • exit
  • isinstance
  • eval
  • super
  • getattr
  • setattr
  • iscallable
  • reverse
  • isiter
  • min
  • max
  • map
  • abs
  • method
  • classmethod
  • staticmethod
  • property
  • getannotation
  • sum
  • hasattr
  • dir
  • bin
  • hex
  • ord
  • chr
  • unicode_name

Builtin libraries

  • time
  • math
  • random
  • threading
  • sys
  • os
  • sockets
  • simpleserver
  • builtins
  • json
Exceptions
  • Exception
  • TypeError
  • ValueError
  • AttributeError
  • KeyError
  • NameError
  • IndexError
  • MemoryError
  • RecursionError
  • StopIteration
  • FileNotFoundError
  • InvalidOperationError
  • ImportError
  • KeyboardInterrupt
  • AssertionError
  • ZeroDivisionError

Keywords

  • func
  • class
  • return
  • if
  • else
  • elif
  • raise
  • try
  • except
  • finally
  • for
  • break
  • while
  • import
  • from
  • del
  • assert
  • continue
  • lambda
  • yield
  • with

Other syntax

  • : - Global variable access
  • :: - Nonlocal variable access
  • <name> : <type> - Type annotations in function arguments or assignment
  • <function definition> : <type> { - Type annotation for function return value
  • f"Text {code}" - Format strings using code snippets
  • b"Text" - Creates a bytes object from string
  • \uXXX - Unicode escape, where XXXX represents a 4 digit hexadecimal string (mandatory)
  • \N... - Unicode name literal, where ... represents a valid name that represents a unicode code point

Documentation

Sample Program

Program
m="Placeholder value"

class Falcon{
    var=m
    func sound(self){
        print("Sound!")
    }
}


class Peregrine(Falcon){
    var=m
    func __new__(self){
        print("__new__ called")
        return super(self).__new__(self)
    }
    func __init__(self){
        print(self)
    }
    func f(self){
        print(self.var)
    }
}

x=Peregrine()

y=Peregrine()

a=Peregrine.var
x.var=5
y.var="Value"
b=x.var

x.f()
y.f()

x.sound()

print(x.__bases__)

func f(x,c="A"){
    print("Function f says: ","")
    print(c)
}

f(1)



dictionary={1:[1,2,3], 2:{1:"A"}, "Hello":"World", [123]:2}

l=list(1,2,3,4,5)

x=object()
y=object()


true = x == y
maybe = x is y
same = x is x
print(500==500)


print("Done")

print(l[3])
print(dictionary[[123]])


try{
    if 500 is 200{
        raise Exception("500 is not the same object as 200")
    }
    elif 500 is 500{
        raise TypeError("500 is not the same object as 200, but is the same as 500")
    }
    else{
        raise NameError("Else condition reached")
    }
}
except Exception e{
    print(e)
}

i=0

func x(){
    i=i+1

    print(i)
    if (i==3){
        raise ValueError("I is 50!")
    }
    x()
}

try{
    x()
}
except Exception e{
    print(e)
}

val=2
print(val.__mul__(5))

func fib(n){
    if (n<=1){
        return n
    }
    else{
        return fib(n-1)+fib(n-2)
    }
}

print(fib(10))

pi=238649.2131693410000000
x=pi*100
print(str(pi))
print(int("1234"))
print(float("10.222"))

for n in [10,20,30]{
    print(n)
}

i=0
while i<10{
    print(i)
    i+=1
}

print(True and False)
print(True or False)
print(not 1==1)

print(100^2)
print(100^2*3)
print(100^6)

When run with ./fpl.exe program.fpl

Output
__new__ called        
<Peregrine @ 0xba7a98>
__new__ called        
<Peregrine @ 0xba7b40>
5
Value
Sound!
[<class 'Falcon'>, <class 'object'>]
Function f says:  
A
True
Done
4
2
500 is not the same object as 200, but is the same as 500
1
2
3
I is 50!
10
55
238649.213169341
1234
10.222
10
20
30
False
True
False
102
98
98

Usage

Build Falcon in debug mode ./build.cmd

Build Falcon in release mode ./release.cmd

Run a script ./fpl program

Enter REPL ./fpl

Help ./fpl -h

Links

Licenses

falcon-programming-language's People

Contributors

ericlbuehler avatar

Stargazers

 avatar Yunhao Yang avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.