Gossip-lang Documentation

Welcome to the Gossip-lang documentation. Gossip-lang is a Python-compiled programming language that allows you to write neat and whimsical code for your little projects. This documentation provides information on how to install, set up, and use Gossip-lang, as well as details on its syntax, errors, and grammar.

Table of Contents

Installation Guide

Prerequisites

Before installing Gossip-lang, ensure that you have Python 3.10.0 or a higher version installed on your system.

Installation

  1. Clone the Gossip-lang GitHub repository using the following command in your terminal:

git clone https://github.com/plugyawn/gossip.git
  1. Navigate to the gossip directory using the following command:

cd gossip
  1. Install the required packages using the following command:

pip install -r requirements.txt

This will install all the required dependencies listed in the requirements.txt file.

  1. Optionnally, you can create a virtual environment using the following command:

pipenv install -r requirements.txt
pipenv shell

This will create a virtual environment and install all the required dependencies listed in the requirements.txt file.

  1. Congratulations, you have successfully installed Gossip-lang! Head on over to the usage guide to learn how to use Gossip-lang.

Usage Guide

  1. To run Gossip with an input file containing Gossip code, use the -f or –from-file option followed by the path to the input file:

    python main.py -f ./path/to/input.gos
    

    For example, to run the test.gos file, use the following command:

    python main.py -f ./examples/test.gos
    
  2. To update Gossip to the latest version, use the -u or –update option:

    python main.py -u
    
  3. To start an interactive prompt where you can enter Gossip code directly, use the -i or –interpret option:

    python main.py -i
    
  4. To show feedback whenever a command is entered, use the -s or –show-feedback option:

    python main.py -s
    
  5. To show a visualization of the Gossip code, line by line, use the -v or –visualize option:

    python main.py -v
    

Once you have finished using Gossip, you can exit the program by pressing CTRL-C or typing exit() at the prompt.

Head on over to the syntax page to learn more about the Gossip syntax.

Gossip Syntax

Gossip is a dynamically typed, interpreted programming language. This document specifies the syntax of the language.

Data Types

Gossip has two built-in data types: numbers and booleans.

Numbers

Numbers in Gossip can be integers or floating-point numbers. They can be written in decimal notation. Here are some examples:

10
3.14
Booleans

Booleans in Gossip are True and False.

Variables

Variables in Gossip are dynamically typed, which means that they can be assigned values of any type. A variable is declared using the let keyword. Here is an example:

let x = 10

Operators

Gossip has several built-in operators.

Arithmetic Operators

Gossip has the following arithmetic operators:

+ - * ** / rem quot  

Here is an example:

10 + 5 * 2
Comparison Operators

Gossip has the following comparison operators:

< > <= >= == !=

Here is an example:

10 < 20
Logical Operators

Gossip has the following logical operators:

and or not

Here is an example:

True and False
Assignment Operators

Gossip has two assignment operators:

let assign

Here is an example:

let x = 10
x assign 20

Control Flow

Gossip has the following control flow statements.

If Statements

An if statement in Gossip looks like this:

if a < b then
x = 10
else
x = 20
end
While Loops

A while loop in Gossip looks like this:

while x < 10 do
x = x + 1
end
For Loops

A for loop in Gossip looks like this:

for i in 1 to 10 do
print i
end
Repeat Loops

A repeat loop in Gossip looks like this:

repeat
x = x + 1
until x == 10

Grammar

The grammar page provides a detailed description of the Gossip-lang grammar, including information on the different types of expressions, statements, and literals used in the language.

program: statement*

statement:
    | "let" identifier "=" expression
    | "assign" identifier "=" expression
    | "print" expression
    | compound_statement
    | if_statement
    | while_statement
    | repeat_statement
    | "declare" variable_declaration+ "in" statement "end"

compound_statement:
    | "for" identifier "in" range "do" statement "end"
    | "for" identifier "," identifier "in" matrix_range "do" statement "end"
    | "with" expression "as" identifier "do" statement "end"

if_statement:
    | "if" expression "then" statement "else" statement "end"
    | "if" expression "then" statement "end"

while_statement:
    | "while" expression "do" statement "end"

repeat_statement:
    | "repeat" statement "until" expression

variable_declaration:
    | identifier ("," identifier)*

range:
    | expression "to" expression

matrix_range:
    | range "by" expression "," expression "to" expression

expression:
    | comparison (("and" | "or") comparison)*

comparison:
    | term ((">" | "<" | ">=" | "<=" | "==" | "!=") term)*

term:
    | factor (("+" | "-") factor)*

factor:
    | power (("*" | "/" | "quot" | "rem") power)*

power:
    | call ("**" power)?

call:
    | atom ("(" call_arguments ")")?

call_arguments:
    | expression ("," expression)*

atom:
    | "True" | "False"
    | identifier
    | number
    | string
    | "(" expression ")"

identifier:
    | /[a-zA-Z_][a-zA-Z0-9_]*/

number:
    | /[0-9]+(\.[0-9]+)?/

string:
    | /"(\\.|[^"])*"/

Errors And Exceptions

Gossip-lang comes with custom errors to help you debug your code. This page provides details on each of the custom errors that can be raised when using Gossip-lang.

DeclarationError

Raised when a variable is called but has not been defined before.

class DeclarationError(Exception):
    def __init__(self, name):
        self.name = name
        print(f"DeclarationError: {name} is not declared.")

InvalidProgramError

Raised when a program is invalid.

class InvalidProgramError(Exception):
    def __init__(self, message, verbose=True):
        self.message = message
        print(f"InvalidProgramError: {message}")

EndOfStream

Raised when the end of a stream is reached.

class EndOfStream(Exception):
    pass

EndOfTokens

Raised when the end of a stream of tokens is reached.

class EndOfTokens(Exception):
    pass

TokenError

Raised when an invalid token is encountered.

class TokenError(Exception):
    pass

TypeCheckError

Raised when the type of the operands in the operation are not of valid type.

class TypeCheckError(Exception):
    def __init__(self, oprtype=None, message=None):
        self.oprtype = str(oprtype)
        if not message:
            print(f"TypeError: Operand(s) should have the type: {oprtype}.")
        else:
            print(f"TypeError: {message}")

InvalidCondition

Raised when an invalid condition is passed to a while loop.

class InvalidCondition(Exception):
    def __init__(self, cond):
        self.error = cond
        print(f"Invalid Condition: {cond} is not a valid condition.")

VariableRedeclaration

Raised when a variable is re-declared in the same scope.

class VariableRedeclaration(Exception):
    def __init__(self, var):
        self.var = var
        print(f"Redeclaration Error: {var} has already been declared in the current scope.")

AssignmentUsingNone

Raised when trying to assign using a variable that has no assigned value itself.

class AssignmentUsingNone(Exception):
    def __init__(self, var):
        self.var = var
        print(f"Trying to assign using {var} which has no assigned value itself.")

Refer to the syntax for more information on how to avoid these errors.

Installation Guide

The installation guide provides step-by-step instructions on how to install Gossip-lang on your system. It also includes information on the requirements and recommended package management systems.

Please refer to the installation guide for more details.

Usage Guide

The usage guide provides an overview of how to use Gossip-lang, including details on using the built-in command-line interface.

Please refer to the usage guide for more details.

Syntax

The syntax page provides a detailed description of the Gossip-lang syntax, including examples of how to write code using Gossip-lang. It covers topics such as comments, variables, functions, and more.

Please refer to the syntax page for more details.

Errors

The errors page provides information on the custom errors that can be generated when using Gossip-lang. It includes a list of error messages, as well as explanations of what causes each error.

Please refer to the errors page for more details.

Grammar

The grammar page provides a detailed description of the Gossip-lang grammar, including information on the different types of expressions, statements, and literals used in the language.

Please refer to the grammar page for more details.