overdev / brah-0.1.0-impl1

A very basic and simplistic programming language (compiler + interpreter) made in pure Python 3.8.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BRAH Programming Language

EBNF Grammar Specification

Module       = Imports Declarations
Imports      = Import Imports
Import       = "importe" "{" Names "}" "de" SOURCEFILE ";"
Names        = NAME [ "," Names ]
Declarations = Declaration Declarations
Declaration  = Constant
             | Function
             | Structure
             | Interface
             | Class
Constant     = "constante" NAME "=" Expression ";"
Variable     = "var" NAME [ "=" Expression ] ";"
ProtOrDef    = ( ";" | Definition )
Definition   = ( FunDef | StrucDef | IntefDef | ClassDef )
Function     = "função" NAME "(" [ Parameters ] ")" ProtOrDef
Structure    = "estrutura" NAME ProtOrDef
Interface    = "interface" NAME ProtOrDef
Class        = "classe" NAME [ "extende" NAME ] [ "implementa" NAME ] ProtOrDef



Feature Tree

syntax: {
    brazilian portuguese
    identifiers with special caracters  
}

storage types {
    typedef
    constants
    exceptions: {
        index based exception tree
    }
    variables
    enumerations: {
        flagset counter
    }
    signatures
    functions: {
        default arguments
        variable length argument number
        templates
        plataform invoke
    }
    interfaces
    structures: {
        methods
        properties
        overloads
        operator overloads
    }
    classes: {
        single inheritance
        static fields, properties and methods
        overrides
        super calls
        access modifiers
    }
}

statements: {
    import: {
        source files: {
            all names
            specific names
        }
        pre-compiled libraries
    }
    if: {
        then
        then-else
    }
    while
    do: {
        with label
        while
        until
    }
    repeat:{
        with label
        finite
        infinite
    }
    switch-case
    for: {
        with label
        element in container
        index, element in container
        index of length
    }
    try: {
        finally
        catch-finally
    }
    raise
    break: {
        label
    }
    continue: {
        label
    }
    return
}

expressions: {
    ternary expressions
    increment: {
        pre
        pos
    }
    decrement: {
        pre
        pos
    }
}

Implementation Details

Function Definition

Keywords

  • KW_RETURN (retorne)
  • KW_FUNCTION (função)

Nodes

  • NK_FUNCTION_DECL
  • NK_PARAM_DECL
  • NK_RETURN_STMT
  • NK_PARAM_EXPR
  • NK_FCALL_EXPR
  • NK_FUNCTION_EXPR

Mnemonics

  • CALL codePtr numArgs
  • RET
  • JMP

Parser

  • parse_decl_function(self, scope: Scope, stream: TokenStream) -> ASTNode
  • parse_decl_fblock(self, scope: Scope, stream: TokenStream) -> ASTNode
  • parse_decl_params(self, scope: Scope, stream: TokenStream) -> ASTNode
  • parse_decl_param(self, scope: Scope, stream: TokenStream) -> ASTNode
  • parse_stmt_return(self, scope: Scope, stream: TokenStream) -> ASTNode

Compiler

  • compile_decl_function(self, decl_node: AstNode) -> None
  • compile_expr_fcall(self, decl_node: AstNode) -> None
  • compile_stmt_return(self, decl_node: AstNode) -> None

If Statement

Keywords

  • KW_IF (se)
  • KW_ELSE (senão)
  • KW_AND (e)
  • KW_OR (ou)
  • KW_OUX (oux)
  • KW_IS (é)
  • KW_NOT (não)

Nodes

  • NK_IF_THEN_STMT
  • NK_IF_ELSE_STMT
  • NK_TERNARY_EXPR
  • NK_LOGIC_EXPR
  • NK_COMPARISSON_EXPR

Mnemonics

  • CMP
  • JE
  • JNE
  • JA
  • JAE
  • JB
  • JBE
  • JZ
  • JNZ
  • AND
  • ANDL
  • OR
  • ORL
  • XOR
  • XORL
  • NOT
  • NOTL

Operators

  • Equal (==)
  • Not Equal (!=)
  • Greater Than (>)
  • Greater Than or Equal (>=)
  • Lesser Than (<)
  • Lesser Than or Equal (<=)
  • Binary And (&)
  • Binary Or (|)
  • Binary Xor (^)
  • Binary Not (~)
  • Ternary (?)

Parser

parse_stmt_if(self, scope: Scope, stream: TokenStream) -> AstNode parse_expr_ternary(self, scope: Scope, stream: TokenStream) -> AstNode

Compiler

compile_stmt_ifthen() -> None compile_stmt_ifelse() -> None compile_expr_ternary() -> None

About

A very basic and simplistic programming language (compiler + interpreter) made in pure Python 3.8.

License:MIT License


Languages

Language:Python 100.0%