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, 0x hex, 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)

  • func declarations

  • var / let at top level may be accepted by parser depending on grammar; prefer func + 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

expr ;

Var

var name [= expr] ;, let … optional init

Assign

name = expr ;

Func

func name ( [param [: type]] [, …] ) [ -> type ] { body }

If

if expr { stmts } [ else { stmts }]

While

while expr { stmts }

Loop

loop { stmts }

For

for [init]; [cond]; [step] { stmts } (parsed; prefer fixtures for subtle cases)

Return

return [expr] ;

Break / Continue

break;, continue;

Import

import "path" ; (path rules: P1SCode — Modules, imports, and the std story)

Block

{ stmts }

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); member obj.field

  • Grouped (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

int

i32

float

f32

string

&str (type positions)

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)

sys (use import "os/sys")

print, read_file, write_file, sleep, execute

math

random

str

concat

fs

read_file, read_text, write_file

crypto

get_random, hash_sha256, hmac_sha256, to_hex

ui

create_window, poll, event_type, mouse_x, mouse_y

io

print, print_err, read_line, read_file, read_text, write_file, read_bytes, write_bytes, sleep, execute (after import "std/io"; see P1SCode — Modules, imports, and the std story §3)


7. Diagnostics codes (subset)

Code

Meaning

P1SC-EIMP001

Unresolved file import

P1SC-EIMP002

Import file unreadable

P1SC-EIMP003

Malformed import syntax

P1SC-ELEX001

Lexer error (incl. native)

P1SC-ESYNTAX001

Parser error

Full table: P1SCode Toolchain Workflow.


See also