Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

introjs

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

introjs

IntroJS is a JavaScript implementation of the simplified programming language Intro.

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
918
decreased by-16.39%
Maintainers
1
Weekly downloads
 
Created
Source

IntroJS

IntroJS is a JavaScript implementation of the simplified programming language Intro.

Example

def main()
  var n = read_int()
  if n <= 0
    return
  end
  while 1
    var values = read_ints(n)
    if !$values
      break
    end
    write_int(sum(values))
  end
end

def sum(values: Int[]): Int
  var ret = 0
  for v in values
    ret += v
  end
  return ret
end

Features

Data types are only integer type (Int) and its array types (Int[], Int[][], ...).

All codes must be written in a file.

Top level elements are only function declarations.

A program needs a main function.

Function parameters need a data type.

Variable declaration needs initialization.

I/O format is plain text which line is integer values separated by white spaces.

To read from stdin, you can use read* builtin functions.

To write to stdout, you can use write* builtin functions.

To print variables to stderr, you can use trace statement.

To branch by conditions, you can use if-elseif-else statement.

To get a length of array, you can use $ operator.

For-in statements

def main()
  var values = [3, 1, 4, 1, 5]
  trace values, $values

  # Ascending index
  for i in 0 :< $values
    write_ints([i, values[i]])
  end

  # Ascending index (Omitted "0 :<")
  for i in $values
    write_ints([i, values[i]])
  end

  # Each element
  for v in values
    write_int(v)
  end

  # Descending index
  for i in $values - 1 :>= 0
    write_ints([i, values[i]])
  end

  # Skip
  for i in 1 :< $values :% 2
    write_ints([i, values[i]])
  end
end

Install

npm install -g introjs

Usage

Usage: introjs [options] <source_file>
Options:
  -c, --convert:
    print converted AST
  -g, --generate:
    print generated JavaScript
  -h, --help:
    print help
  -p, --parse:
    print parsed AST
  -t, --test:
    execute test
  -v, --version:
    print version

Built-in functions

def read(values: Int[], offset: Int, length: Int): Int
def read_int(): Int
def read_ints(max_length: Int): Int[]
def write(values: Int[], offset: Int, length: Int)
def write_int(value: Int)
def write_ints(values: Int[])

Not supported features

  • Variable-length array
  • Associative array
  • Miscellaneous data types
  • Multiline comment
  • Switch statement
  • Do-while statement
  • Labeled break
  • Exception handling
  • Module
  • Class
  • Closure
  • Coroutine
  • Multithread
  • Asynchronous
  • Source map
  • Debugger
  • REPL

License

MIT

Keywords

FAQs

Package last updated on 13 Jun 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc