Git Product home page Git Product logo

tiny-language's Introduction

Design Point

  • a tiny, mostly-static, very easy-to-compile imperative language intended for high-performance integer computations

  • safe: any unsafe action such as out-of-bounds array access leads to program termination with a diagnostic

  • newlines are significant, but indentation is not; a logical line of code can be broken across physical lines using a backslash, which must immediately precede a newline, and which is treated as whitespace by the lexer

  • there are no libraries, separate compilation, linking, etc.

Syntax

program :=
     function+

function :=
     type ident(type ident <, type ident>*) {
       stmt*
     }

type :=
  bool
  int
  array
  void

stmt :=
     { \n <stmt \n>* }\n (NOTE: angular braces are used for grouping)
     type ident <, ident>*
     array ident\[expr\] <, ident\[expr\]>*
     print(<string|expr> <, <string|expr> >*
     if (expr) stmt [else stmt]
     while (expr) stmt
     for (ident : expr) stmt
     ident := expr
     ident\[expr\] := expr
     expr
     ;.*
     return [expr]

expr :=
     true
     false
     -?[0-9]+
     ident
     (expr ? expr : expr)
     sizeof(ident)
     input()
     ident\[expr\]
     ident(expr <, expr>*)
     (expr binop expr)
     (unaryop expr)

binop :=
     + - * ^ / % & | == != > >= < <=
    (caret is exponentiation, we have no xor operator)

unaryop :=
    - !
    (bang is Boolean not)

ident :=
     [a-zA-Z_][a-zA-Z0-9_]*

More

  • there are no implicit conversions among types
  • the int type is a 64-bit, two's complement integer
  • an array is always a 1-D array of int
  • arrays are sized (and bounds checked) but the size is not part of the type
  • the void type is not allowed in variable definitions or function parameter lists
  • identifiers cannot be keywords
  • every program must contain exactly one function called "main"
  • recursion is allowed
  • arrays cannot be assigned
  • arrays are passed to functions by reference
  • when the program first passes an array definition, an array of the specified size is allocated and initialized to all zero
  • arrays are deallocated at the end of their block
  • arrays must not escape their block
  • variables are visible using block scope
  • there are no global variables
  • variable shadowing is a compile-time error

THE FUTURE

version 2 of this language will have bignum as the default (and only!) integer type

tiny-language's People

Contributors

regehr avatar manasij7479 avatar pranavk avatar

Watchers

James Cloos 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.