mirror of
https://github.com/ziglang/zig.git
synced 2026-02-21 16:54:52 +00:00
move docs to website
This commit is contained in:
parent
d5271d1e49
commit
0a922d3bca
176
doc/langref.md
176
doc/langref.md
@ -1,176 +0,0 @@
|
||||
# Language Reference
|
||||
|
||||
## Grammar
|
||||
|
||||
```
|
||||
Root = many(TopLevelItem) "EOF"
|
||||
|
||||
TopLevelItem = ErrorValueDecl | CompTimeExpression(Block) | TopLevelDecl | TestDecl
|
||||
|
||||
TestDecl = "test" String Block
|
||||
|
||||
TopLevelDecl = option(VisibleMod) (FnDef | ExternDecl | GlobalVarDecl | UseDecl)
|
||||
|
||||
ErrorValueDecl = "error" Symbol ";"
|
||||
|
||||
GlobalVarDecl = VariableDeclaration ";"
|
||||
|
||||
VariableDeclaration = option("comptime") ("var" | "const") Symbol option(":" TypeExpr) "=" Expression
|
||||
|
||||
ContainerMember = (ContainerField | FnDef | GlobalVarDecl)
|
||||
|
||||
ContainerField = Symbol option(":" Expression) ","
|
||||
|
||||
UseDecl = "use" Expression ";"
|
||||
|
||||
ExternDecl = "extern" option(String) (FnProto | VariableDeclaration) ";"
|
||||
|
||||
FnProto = option("coldcc" | "nakedcc" | "stdcallcc") "fn" option(Symbol) ParamDeclList option("->" TypeExpr)
|
||||
|
||||
VisibleMod = "pub" | "export"
|
||||
|
||||
FnDef = option("inline" | "extern") FnProto Block
|
||||
|
||||
ParamDeclList = "(" list(ParamDecl, ",") ")"
|
||||
|
||||
ParamDecl = option("noalias" | "comptime") option(Symbol ":") (TypeExpr | "...")
|
||||
|
||||
Block = "{" many(Statement) option(Expression) "}"
|
||||
|
||||
Statement = Label | VariableDeclaration ";" | Defer(Block) | Defer(Expression) ";" | BlockExpression(Block) | Expression ";" | ";"
|
||||
|
||||
Label = Symbol ":"
|
||||
|
||||
TypeExpr = PrefixOpExpression | "var"
|
||||
|
||||
BlockOrExpression = Block | Expression
|
||||
|
||||
Expression = ReturnExpression | BreakExpression | AssignmentExpression
|
||||
|
||||
AsmExpression = "asm" option("volatile") "(" String option(AsmOutput) ")"
|
||||
|
||||
AsmOutput = ":" list(AsmOutputItem, ",") option(AsmInput)
|
||||
|
||||
AsmInput = ":" list(AsmInputItem, ",") option(AsmClobbers)
|
||||
|
||||
AsmOutputItem = "[" Symbol "]" String "(" (Symbol | "->" TypeExpr) ")"
|
||||
|
||||
AsmInputItem = "[" Symbol "]" String "(" Expression ")"
|
||||
|
||||
AsmClobbers= ":" list(String, ",")
|
||||
|
||||
UnwrapExpression = BoolOrExpression (UnwrapMaybe | UnwrapError) | BoolOrExpression
|
||||
|
||||
UnwrapMaybe = "??" Expression
|
||||
|
||||
UnwrapError = "%%" option("|" Symbol "|") Expression
|
||||
|
||||
AssignmentExpression = UnwrapExpression AssignmentOperator UnwrapExpression | UnwrapExpression
|
||||
|
||||
AssignmentOperator = "=" | "*=" | "/=" | "%=" | "+=" | "-=" | "<<=" | ">>=" | "&=" | "^=" | "|=" | "*%=" | "+%=" | "-%=" | "<<%="
|
||||
|
||||
BlockExpression(body) = Block | IfExpression(body) | TryExpression(body) | TestExpression(body) | WhileExpression(body) | ForExpression(body) | SwitchExpression | CompTimeExpression(body)
|
||||
|
||||
CompTimeExpression(body) = "comptime" body
|
||||
|
||||
SwitchExpression = "switch" "(" Expression ")" "{" many(SwitchProng) "}"
|
||||
|
||||
SwitchProng = (list(SwitchItem, ",") | "else") "=>" option("|" option("*") Symbol "|") Expression ","
|
||||
|
||||
SwitchItem = Expression | (Expression "..." Expression)
|
||||
|
||||
ForExpression(body) = option("inline") "for" "(" Expression ")" option("|" option("*") Symbol option("," Symbol) "|") body option("else" BlockExpression(body))
|
||||
|
||||
BoolOrExpression = BoolAndExpression "or" BoolOrExpression | BoolAndExpression
|
||||
|
||||
ReturnExpression = option("%") "return" option(Expression)
|
||||
|
||||
BreakExpression = "break" option(Expression)
|
||||
|
||||
Defer(body) = option("%") "defer" body
|
||||
|
||||
IfExpression(body) = "if" "(" Expression ")" body option("else" BlockExpression(body))
|
||||
|
||||
TryExpression(body) = "if" "(" Expression ")" option("|" option("*") Symbol "|") body "else" "|" Symbol "|" BlockExpression(body)
|
||||
|
||||
TestExpression(body) = "if" "(" Expression ")" option("|" option("*") Symbol "|") body option("else" BlockExpression(body))
|
||||
|
||||
WhileExpression(body) = option("inline") "while" "(" Expression ")" option("|" option("*") Symbol "|") option(":" "(" Expression ")") body option("else" option("|" Symbol "|") BlockExpression(body))
|
||||
|
||||
BoolAndExpression = ComparisonExpression "and" BoolAndExpression | ComparisonExpression
|
||||
|
||||
ComparisonExpression = BinaryOrExpression ComparisonOperator BinaryOrExpression | BinaryOrExpression
|
||||
|
||||
ComparisonOperator = "==" | "!=" | "<" | ">" | "<=" | ">="
|
||||
|
||||
BinaryOrExpression = BinaryXorExpression "|" BinaryOrExpression | BinaryXorExpression
|
||||
|
||||
BinaryXorExpression = BinaryAndExpression "^" BinaryXorExpression | BinaryAndExpression
|
||||
|
||||
BinaryAndExpression = BitShiftExpression "&" BinaryAndExpression | BitShiftExpression
|
||||
|
||||
BitShiftExpression = AdditionExpression BitShiftOperator BitShiftExpression | AdditionExpression
|
||||
|
||||
BitShiftOperator = "<<" | ">>" | "<<%"
|
||||
|
||||
AdditionExpression = MultiplyExpression AdditionOperator AdditionExpression | MultiplyExpression
|
||||
|
||||
AdditionOperator = "+" | "-" | "++" | "+%" | "-%"
|
||||
|
||||
MultiplyExpression = CurlySuffixExpression MultiplyOperator MultiplyExpression | CurlySuffixExpression
|
||||
|
||||
CurlySuffixExpression = TypeExpr option(ContainerInitExpression)
|
||||
|
||||
MultiplyOperator = "*" | "/" | "%" | "**" | "*%"
|
||||
|
||||
PrefixOpExpression = PrefixOp PrefixOpExpression | SuffixOpExpression
|
||||
|
||||
SuffixOpExpression = PrimaryExpression option(FnCallExpression | ArrayAccessExpression | FieldAccessExpression | SliceExpression)
|
||||
|
||||
FieldAccessExpression = "." Symbol
|
||||
|
||||
FnCallExpression = "(" list(Expression, ",") ")"
|
||||
|
||||
ArrayAccessExpression = "[" Expression "]"
|
||||
|
||||
SliceExpression = "[" Expression ".." option(Expression) "]"
|
||||
|
||||
ContainerInitExpression = "{" ContainerInitBody "}"
|
||||
|
||||
ContainerInitBody = list(StructLiteralField, ",") | list(Expression, ",")
|
||||
|
||||
StructLiteralField = "." Symbol "=" Expression
|
||||
|
||||
PrefixOp = "!" | "-" | "~" | "*" | ("&" option("const") option("volatile")) | "?" | "%" | "%%" | "??" | "-%"
|
||||
|
||||
PrimaryExpression = Integer | Float | String | CharLiteral | KeywordLiteral | GroupedExpression | GotoExpression | BlockExpression(BlockOrExpression) | Symbol | ("@" Symbol FnCallExpression) | ArrayType | (option("extern") FnProto) | AsmExpression | ("error" "." Symbol) | ContainerDecl
|
||||
|
||||
ArrayType = "[" option(Expression) "]" option("const") TypeExpr
|
||||
|
||||
GotoExpression = "goto" Symbol
|
||||
|
||||
GroupedExpression = "(" Expression ")"
|
||||
|
||||
KeywordLiteral = "true" | "false" | "null" | "continue" | "undefined" | "error" | "this" | "unreachable"
|
||||
|
||||
ContainerDecl = option("extern" | "packed") ("struct" | "enum" | "union") "{" many(ContainerMember) "}"
|
||||
```
|
||||
|
||||
## Operator Precedence
|
||||
|
||||
```
|
||||
x() x[] x.y
|
||||
!x -x -%x ~x *x &x ?x %x %%x ??x
|
||||
x{}
|
||||
* / % ** *%
|
||||
+ - ++ +% -%
|
||||
<< >>
|
||||
&
|
||||
^
|
||||
|
|
||||
== != < > <= >=
|
||||
and
|
||||
or
|
||||
?? %%
|
||||
= *= /= %= += -= <<= >>= &= ^= |=
|
||||
```
|
||||
@ -21,7 +21,6 @@ level declarations are:
|
||||
* Function Definition
|
||||
* Global Variable Declaration
|
||||
* Container Declaration (struct or enum)
|
||||
* Type Declaration
|
||||
* Error Value Declaration
|
||||
* Use Declaration
|
||||
|
||||
|
||||
@ -12,4 +12,4 @@ Write the target-specific code in the standard library.
|
||||
|
||||
Update the C integer types to be the correct size for the target.
|
||||
|
||||
Make sure that `c_long_double` codegens the correct floating point value.
|
||||
Make sure that `c_longdouble` codegens the correct floating point value.
|
||||
|
||||
@ -91,7 +91,7 @@ static const char *ZIG_ZEN = "\n"
|
||||
" * Avoid local maximums.\n"
|
||||
" * Reduce the amount one must remember.\n"
|
||||
" * Minimize energy spent on coding style.\n"
|
||||
" * Together we serve the end users.\n";
|
||||
" * Together we serve end users.\n";
|
||||
|
||||
static int print_target_list(FILE *f) {
|
||||
ZigTarget native;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user