To make **App Graph Syntax (AGS)** Turing complete and optimized for mobile, we need to move beyond simple data fetching and introduce **State (Memory), Logic (Conditionals), and Iteration (Loops)**, all while keeping the keystroke count minimal. By replacing `=` with `:`, we align closer to the "key-value" mental model used in many mobile APIs. Here is the complete syntax specification for **AGS v1.0**. --- ### 1. The Lexical Foundation The language is composed of five primary tokens. All are located on the first or second layer of a standard mobile keyboard. | Token | Name | Purpose | Example | | :--- | :--- | :--- | :--- | | `.` | **Noun** | Entity, Object, or Data Source | `.user`, `.product`, `.api` | | `/` | **Verb** | Action, Function, or Logic Gate | `/get`, `/if`, `/set`, `/loop` | | `:` | **Assign** | Argument mapping or Value assignment | `id:123`, `name:John` | | `@` | **Variable** | Local state or temporary memory | `@temp`, `@user_id` | | `_` | **Terminator** | Ends a logic block (If/Loop) | `_` | --- ### 2. Grammar & Structural Rules #### A. The Basic Chain (Linear Flow) Data flows from left to right. The output of one noun/verb pair becomes the context for the next. > `.user /get id:123 .profile /get avatar` > *(Get user 123 $\rightarrow$ Get that user's profile $\rightarrow$ Get the avatar)* #### B. State Management (Variables) To store data for later use without re-fetching, use the `@` symbol. > `.user /get id:123 /set @current_user` > *(Fetches user 123 and saves the object into the variable `@current_user`)* #### C. Logic & Control Flow (The Turing Complete Part) Since we have no curly braces, we use the **Terminator (`_`)** to close blocks. **1. Conditionals (`/if`):** ` /if [condition] [action] _ ` > `/if @current_user.role:admin .admin_panel /show _` > *(If the variable current_user's role is admin, show the admin panel. End block.)* **2. Iteration (`/loop` or `/each`):** ` /loop [collection] : [item_name] [action] _ ` > `/loop .orders : .item .item /send_email status:shipped _` > *(For each order in .orders, call it .item, and send a 'shipped' email for that item. End block.)* --- ### 3. Advanced Mobile Optimizations (Edge Cases) #### A. Implicit Context (The "Ghost" Noun) To save typing, if a verb follows another verb without a noun, it assumes the **last mentioned noun**. * **Verbose:** `.user /get id:1 /update name:Bob` * **AGS Optimized:** `.user /get id:1 /update name:Bob` * *(The `/update` verb knows it is still acting on `.user`)* #### B. String Handling To avoid quotes `""` (which are tedious on mobile), AGS treats all values as **Strings by default**, unless they are: 1. **Numbers** (e.g., `123`) 2. **Booleans** (`true`/`false`) 3. **Variables** (starting with `@`) *If a string contains a space, only then are quotes required.* #### C. The "Pipe" to Variable Instead of a long `/set` command, use a shortcut to capture the result of a chain. > `.user /get id:123 -> @u` > *(Shorthand: Fetch user and pipe the result directly into variable `@u`)* --- ### 4. Comparison: Complex Logic **Task:** *Fetch all premium users; for each, check if their balance is $> 100$; if so, apply a 10% discount code.* **Standard JSON/JS Logic (Pseudo):** ```javascript let users = api.get('.users', {filter: 'premium'}); users.forEach(u => { if (u.balance > 100) { api.post('/discount', {userId: u.id, code: '10OFF'}); } }); ``` **App Graph Syntax (AGS):** > `.users /filter type:premium /loop : .u /if .u.balance: >100 .discount /apply id:.u.id code:10OFF _ _` **Breakdown of the AGS line:** 1. `.users /filter type:premium` $\rightarrow$ Gets the list. 2. `/loop : .u` $\rightarrow$ Iterates through the list, naming each item `.u`. 3. `/if .u.balance: >100` $\rightarrow$ Checks condition. 4. `.discount /apply id:.u.id code:10OFF` $\rightarrow$ Executes action. 5. `_` $\rightarrow$ Closes the `/if`. 6. `_` $\rightarrow$ Closes the `/loop`. --- ### 5. Final Syntax Cheat Sheet for Developers | Feature | Syntax | Mobile Key Path | | :--- | :--- | :--- | | **Fetch** | `.noun /get id:val` | `.` $\rightarrow$ `/` $\rightarrow$ `:` | | **Update** | `.noun /update key:val` | `.` $\rightarrow$ `/` $\rightarrow$ `:` | | **Save** | `.noun /verb $\rightarrow$ @var` | `.` $\rightarrow$ `/` $\rightarrow$ `@` | | **Condition** | `/if var:val [action] _` | `/` $\rightarrow$ `:` $\rightarrow$ `_` | | **Loop** | `/loop .list : .item [action] _` | `/` $\rightarrow$ `:` $\rightarrow$ `_` | | **Pipe** | `.noun /verb $\rightarrow$ .noun /verb` | `.` $\rightarrow$ `/` $\rightarrow$ `.` | ### Summary of Mobile Ergonomics: * **No `{}` or `[]`:** No need to enter the deep symbols menu. * **No `"` (mostly):** Values are treated as literals unless spaces exist. * **Linearity:** The developer can "write" the app logic as a single stream of thought. * **Turing Complete:** With variables, loops, and conditionals, you can build any business logic (calculators, CRM flows, API orchestrators) entirely on a mobile keyboard.