2015-08-05 15:23:15 -07:00
|
|
|
# zig lang
|
2015-08-05 17:44:05 -07:00
|
|
|
|
2015-11-01 21:21:33 -08:00
|
|
|
An experiment in writing a low-level programming language with the intent to
|
|
|
|
replace C. Zig intends to be a small language, yet powerful enough to write
|
|
|
|
readable, safe, optimal, and concise code to solve any computing problem.
|
2015-08-05 17:44:05 -07:00
|
|
|
|
2015-11-01 21:21:33 -08:00
|
|
|
## Goals
|
|
|
|
|
|
|
|
* Ability to run arbitrary code at compile time and generate code.
|
|
|
|
* Completely compatible with C libraries with no wrapper necessary.
|
|
|
|
* Creating a C library should be a primary use case. Should be easy to export
|
|
|
|
an auto-generated .h file.
|
|
|
|
* Generics such as containers.
|
2015-11-03 21:31:27 -08:00
|
|
|
* Do not depend on libc unless explicitly imported.
|
2015-11-01 21:21:33 -08:00
|
|
|
* First class error code support.
|
|
|
|
* Include documentation generator.
|
|
|
|
* Eliminate the need for make, cmake, etc.
|
|
|
|
* Friendly toward package maintainers.
|
|
|
|
* Eliminate the need for C headers (when using zig internally).
|
|
|
|
* Ability to declare dependencies as Git URLS with commit locking (can
|
|
|
|
provide a tag or sha1).
|
|
|
|
* Rust-style enums.
|
|
|
|
* Opinionated when it makes life easier.
|
|
|
|
- Tab character in source code is a compile error.
|
|
|
|
- Whitespace at the end of line is a compile error.
|
|
|
|
* Resilient to parsing errors to make IDE integration work well.
|
|
|
|
* Source code is UTF-8.
|
2015-11-03 21:31:27 -08:00
|
|
|
* Shebang line OK so language can be used for "scripting" as well.
|
2015-11-01 21:21:33 -08:00
|
|
|
|
|
|
|
## Roadmap
|
|
|
|
|
|
|
|
* Hello, world.
|
2015-11-02 02:39:36 -08:00
|
|
|
- Build AST
|
|
|
|
- Code Gen
|
|
|
|
* C style comments.
|
|
|
|
* Unit tests.
|
|
|
|
* Simple .so library
|
2015-11-01 21:21:33 -08:00
|
|
|
* How should the Widget use case be solved? In Genesis I'm using C++ and inheritance.
|
2015-11-03 21:31:27 -08:00
|
|
|
|
|
|
|
## Grammar
|
|
|
|
|
|
|
|
```
|
|
|
|
Root : FnDecl*
|
|
|
|
FnDecl : TokenFn TokenSymbol TokenLParen list(ParamDecl, TokenComma, 0) TokenRParen (TokenArrow Type)? Block
|
|
|
|
ParamDecl : TokenSymbol TokenColon Type
|
|
|
|
Type : TokenSymbol | PointerType
|
|
|
|
PointerType : TokenStar (TokenConst | TokenMut) Type
|
|
|
|
Block : TokenLBrace Statement* Expression? TokenRBrace
|
|
|
|
Statement : ExpressionStatement | ReturnStatement
|
|
|
|
ExpressionStatement : Expression TokenSemicolon
|
|
|
|
ReturnStatement : TokenReturn Expression TokenSemicolon
|
|
|
|
Expression : TokenNumber | TokenString | FnCall
|
|
|
|
FnCall : TokenSymbol TokenLParen list(Expression, TokenComma, 0) TokenRParen
|
|
|
|
```
|