Giter VIP home page Giter VIP logo

yulang's Introduction

Yu Language - yulang

PyPI version GitHub issues GitHub forks GitHub stars GitHub license

A toy project for creating a simple programming language using Bison and Flex in C++.

interface

$ ./yulang
Yu Language 0.0.1 (unstable, Oct 23 2021, 21:31:19)
use:    yulang -c               = interactive console
        yulang <filename>       = running the script file
        yulang -v               = version
        yulang -h               = this menu
        (...) -d [end line]     = developer/debug monitor

interactive console

$ ./yulang -c
Yu Language 0.0.1 (unstable, Oct 23 2021, 21:31:19)
interactive:
y> var a = 3;
y> print(a);
print: 3
y> square a: {return a ^ 2;}
y> print(square(a : 10));
print: 100
y> 

examples

arithmetic

source codes:

print(10 + 30);
print(10 - 30);
print(10. / 30.);
print(10 * 30);
print(30 % 9);
print((5. + 5.) / 3.);

output:

$ ./yulang tests/stable/arithmetics.yu 
print: 40
print: -20
print: 0.333333
print: 300
print: 3
print: 3.33333

string

source codes:

var a = "hello world";
print(a);

output:

$ ./yulang tests/stable/strings.yu  
print: hello world

functions

source codes: (// is used for comments)

// create a square function
square p, l:
{
    var L = p * l;
    return L;
}

// using the square function in a volume function
volume t:
{
    var V = square(p : 5, l : 6) * t;
    return V;
}

// assigning volume return in myVol variable
var myVol = volume(4);
print(myVol);

output:

$ ./yulang tests/stable/functions.yu  
print: 120

variables

source codes: (var is used for generating variables)

// defining variables
var a, b, c, d;
a = 10; // integer
b = .5; // float
c = 3.; // float
d = 3.14; // float

print(a);
print(b);
print(c);
print(d);

output:

$ ./yulang tests/stable/variables.yu 
print: 10
print: 0.5
print: 3
print: 3.14

import files

source codes in includes.yu

multiply a, b:
{
    return a * b;
}

source codes in multi_files.yu

// relative to current directory of terminal (or shell)
// you can import multiple relative paths and they do not create errors

import: "tests/stable/multi_files/includes.yu"
import: "stable/multi_files/includes.yu"
import: "multi_files/includes.yu"

var c = multiply(a : 10, b : 20);
print(c);

output:

$ ./yulang tests/stable/multi_files.yu
print: 200

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.