> For the complete documentation index, see [llms.txt](https://0xlava.gitbook.io/ducky-morph/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://0xlava.gitbook.io/ducky-morph/workflow.md).

# Workflow

## Workflow Explain :&#x20;

DuckyMorph follows a simple but structured pipeline that transforms DuckyScript payloads into executable code for different target platforms.

The entire system is designed around a clear separation of concerns :&#x20;

```mermaid
graph TD
  Parsing--> AST--> Generation
```

### 1. Input Layer (DuckyScript) :&#x20;

The workflow starts with a raw DuckyScript input, either from:

* A `.ds` file
* A string passed programmatically
* CLI input

Example:

```
REM Example payload
STRING Hello World
DELAY 1000
STRINGLN Done
```

At this stage, the input is just plain text with no structure.

***

### 2. Parsing Stage :&#x20;

The parser (`DuckyParser`) is responsible for:

* Tokenizing the input
* Recognizing commands
* Validating syntax (basic level)
* Converting raw text into structured nodes

Each recognized command is converted into an **AST node**.

***

### 3. AST (Abstract Syntax Tree) :&#x20;

The AST is the **core intermediate representation** in DuckyMorph.

It represents the script in a structured, machine-readable format.

Example structure:

* `STRING    → <Duckymorph | ASTNode(ASTNodeTypes.STRING,"hello")>`
* `DELAY 500 → <Duckymorph | ASTNode(ASTNodeTypes.DELAY,"500")>`
* `KEY_COMBO → <Duckymorph | ASTNode(ASTNodeTypes.KEY_COMBO,"['GUI', 'r']")>`

At this stage:

* No platform logic exists
* No Arduino/Python assumptions are made
* Everything is abstract and language-agnostic

The AST acts as the **bridge between parsing and code generation**.

***

### 4. Code Generation Layer

Once the AST is built, it is passed to a **Code Generator**.

Each generator is responsible for converting AST nodes into target-specific output.

Examples:

* Arduino Generator → `.ino` code
* Python Generator → Python script
* Future targets → any custom backend

Each generator:

* Traverses the AST
* Maps nodes to target syntax
* Produces final output code


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://0xlava.gitbook.io/ducky-morph/workflow.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
