Giter Site home page Giter Site logo

ape's Introduction

ape programming language

Humans (Homo Sapiens) are the most abundant and widespread species of primate. They are a type of Great Ape (Hominidae).

compile a program

  • run go run main.go ./tests/<source file>.ape
  • check the generated c code in ./out/<source file>.i
  • run the binary ./bin

layout

ape/lexer.go - tokenizes files into the tokens defined in ape/token
ape/parser.go - recursive descent parser that parses the grammar described in grammar.txt, and generates an ast described in ape/ast
ape/types - type checks ast and produces a 'type environment' used by code generator
ape/c - code generation that compiles an ast tree to c code

pipeline

The directories above are listed in the same order they are used in the compilation pipeline:
lex file into tokens -> parse tokens into ast -> type check ast -> generate code

ape/util.go implements func EndToEndC(path string) which provides an example of how each module is called in order to compile a file. EndToEndC compiles the ape source file path to the binary ./bin, and outputs the generated c code in ./out (this is an empty directory not checked in to git). EndToEndC invokes gcc directly to compile the generated c code, so this will not work unless gcc is installed (but other c compilers should be able to compile the generated c code).

testing

cmd/gen/main.go - Generates input for the parser based on the grammar described in grammar.txt, using dist.txt to control how grammar rules are expanded. These test programs are valid grammar derivations, but are not validly typed.
tests - Contains handwritten programs to test the language. All tests can be run and verified with go run ./tests/run.go.

scratch

parse statements as string chunk first

  • idea is that expressions that cannot be created within a single c expression are only needed before the statement they are used in
  • allows constructing temporary results ahead of statement
  • write supplementary code + 'actual' line to source

ape's People

Contributors

pcen avatar alex-bakker avatar mioyamanaka avatar aliqyan avatar zacjoffe avatar

Stargazers

 avatar

Watchers

 avatar  avatar

ape's Issues

Define Bytecode File Format

Define a file format for the code generator to write program bytecode to that the VM can read from disk. Based on the virtual machine implementation, it will probably look something like this:

HEADER:       specify length of constants section
CONSTANTS:    a list of <length of entry><type of entry><value of entry>
INSTRUCTIONS: program bytecode

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.