diff options
| author | Cliff Click <cliffc@acm.org> | 2026-10-03 14:03:48 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-10-04 13:30:41 -0700 |
| commit | 3476d99690805b3ebe69219b326e5e1b64ebd0a4 (patch) | |
| tree | cb05c136d87603d292c44ac4e5df38d8136f1872 /docs/chapter17b/17-grammar.md | |
| parent | 9a5ca20d2537179f3a8e01762c8db6b52a4db2d9 (diff) | |
| download | Simple-3476d99690805b3ebe69219b326e5e1b64ebd0a4.tar.gz Simple-3476d99690805b3ebe69219b326e5e1b64ebd0a4.zip | |
Chapter 17b: Syntax Sugarlinear-chapter17b
Diffstat (limited to 'docs/chapter17b/17-grammar.md')
| -rw-r--r-- | docs/chapter17b/17-grammar.md | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/docs/chapter17b/17-grammar.md b/docs/chapter17b/17-grammar.md new file mode 100644 index 00000000..9a70f323 --- /dev/null +++ b/docs/chapter17b/17-grammar.md @@ -0,0 +1,22 @@ +# Chapter 17b grammar additions + +Start with [Chapter 17a's declaration syntax](../../chapter17a/docs/17-grammar.md). +This chapter adds inference, assignment shortcuts, conditional expressions, and +`for` loops. Access and binding permissions keep the same meaning. + +```text +inferredDeclaration = ("var" | "val") ("!" | "~")? identifier "=" assignment +assignment = expression (assignmentOperator assignment)? +assignmentOperator = "=" | "+=" | "-=" | "*=" | "/=" | "&=" | "|=" | "^=" + | "<<=" | ">>=" | ">>>=" +expression = bitwise ("?" assignment (":" assignment)?)? +prefixUpdate = ("++" | "--") identifier +postfixUpdate = lvalue ("++" | "--") +forStatement = "for" "(" declarationOrExpression? ";" assignment? ";" + assignment? ")" statement +``` + +Declarations can contain several comma-separated names. `var` permits +reassignment and `val` fixes the binding; both retain the initializer's reference +permissions. Postfix updates also support fields and array elements. Prefix +updates currently support local names. See the README for evaluation order. |
