Skip to content

General purpose interpreted programming language

License

Notifications You must be signed in to change notification settings

JoaoCardoso00/Cog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cog

image

Cog is a general purpose, interpreted programming language

Cog has support for the following:

  • numeric literals
  • arithmetic operations
  • variable declaration
  • native function calls
  • objects and object member calls
  • string literals
  • user defined functions
  • conditionals
  • loops

Since this is a college project i dont think i will add anything outside the list mentioned above, this is a side project, feel free to use the contents in this repo as you wish.

Runing the project:

1 - Clone the repo:

git clone https://github.com/JoaoCardoso00/Cog.git

2 - Run the program:

cargo run -- example.cog

you can write in the example.cog or create a new one and pass the path to the file as the argument for the program

the program also supports an optional -ast flag that prints the generated AST to the standard output

cargo run -- example.cog -ast

Example:

let x = 5;

Output:

  AST {
    kind: "Program",
    statements: [
        ASTStatement {
            kind: VariableDeclaration(
                VariableDeclaration {
                    constant: false,
                    identifier: String(
                        "x",
                    ),
                    value: Some(
                        ASTExpression {
                            kind: NumericLiteral,
                            body: Value(
                                Number(
                                    5.0,
                                ),
                            ),
                        },
                    ),
                },
            ),
        },
    ],
}

Native functions supported:

print(args)

prints to the standard output all the arguments it was provided

examples:

let x = 10;

print(5 + 5)
print(x / 2)

it also supports object fields as arguments

let obj = {
  field: {
    value: 20
  }
}

print(obj.field.value)

About

General purpose interpreted programming language

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages