P1SCode — Language reference (concise)¶
Compact reference for the current surface: keywords, statements, expressions, and builtins. Narrative and examples live in P1SCode Language Guide; module policy in P1SCode — Modules, imports, and the std story.
Note
Authority order: 1) SDK/p1sdk/fixtures/ and run_fixtures.py 2) SDK/p1sdk/p1sc.py (transpile) 3) SDK/p1sdk/p1sc_syntax (parse). This page can lag; open a PR when you change behavior.
1. Lexical summary¶
Whitespace: space, tab, newline; line comments
//; block comments/* … */.Identifiers: ASCII letter or
_start; continue with ASCII alphanumeric or_(Rust lexer aligned).Keywords: see
SDK/p1sdk/p1scode_profile.json/lexer::KEYWORDS—func,var,let,const,if,else,while,for,loop,return,break,continue,struct,enum,import,true,false,null,and,or,not.Number literals: decimal integers,
0xhex, decimal floats with.fraction.String literals:
"…"with escapes\n\t\\\"\0(details in lexer; transpiler may adjust for Rust).Operators / delimiters:
+ - * / %, compound+= -= …, compare== != < > <= >=, logic&& || !, unary-, arrow->, punctuation() {} [] , ; : ..
2. Compilation unit (after import merge)¶
Conceptually: ordered top-level items:
import(only virtual imports may appear if merge failed to strip—normally file imports are gone)funcdeclarationsvar/letat top level may be accepted by parser depending on grammar; preferfunc+ block locals in portable code unless a fixture relies otherwise
Entry: func main() -> int { … } for hosted apps using the default transpiler template.
3. Statements (parser / AST)¶
Form |
Syntax sketch |
|---|---|
Expression stmt |
|
Var |
|
Assign |
|
Func |
|
If |
|
While |
|
Loop |
|
For |
|
Return |
|
Break / Continue |
|
Import |
|
Block |
|
struct / enum: keyword reserved; transpiler may partially emit—treat as advanced / fixture-driven.
4. Expressions (AST)¶
Literals: int, float, string, bool, null
Variable
Binary:
+ - * / %,== != < > <= >=Unary:
-,!Logical:
&&||Assign / compound assign (where grammar allows)
Call
f(args); memberobj.fieldGrouped
(expr)
Precedence: follow C-like intuitions; when in doubt, parenthesize or mirror a working fixture.
5. Type annotations (surface)¶
In signatures and optional locals:
Annotation |
Typical emission |
|---|---|
|
|
|
|
|
|
No separate spec for inference, generics, or ** lifetimes**—this is not Rust’s type system.
6. Builtins (transpiler-recognized)¶
Requires correct import / spelling as in P1SCode Language Guide §9. Summary:
Surface |
Members (non-exhaustive) |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7. Diagnostics codes (subset)¶
Code |
Meaning |
|---|---|
|
Unresolved file import |
|
Import file unreadable |
|
Malformed import syntax |
|
Lexer error (incl. native) |
|
Parser error |
Full table: P1SCode Toolchain Workflow.