Install
$ agentstack add skill-narwhal-lab-magicskills-c-2-ast ✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.
Security review
✓ PassedNo issues found. Passed automated security review. · v0.1.0 How review works →
- ✓ Prompt-injection patterns
- ✓ Secret / credential exfiltration
- ✓ Dangerous shell & filesystem operations
- ✓ Untrusted network calls
- ✓ Known-malicious package signatures
What it can access
- ✓ Network access No
- ✓ Filesystem access No
- ✓ Shell / process execution No
- ✓ Environment & secrets No
- ✓ Dynamic code execution No
From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.
Verified badge
Passed review? Show it. Paste this badge into your README, it links to the public security report.
Reliability & compatibility
Declared compatibility
Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.
We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.
How agent discovery & health will work →About
C to AST Skill
Purpose
This Skill converts C source code into its Abstract Syntax Tree (AST) representation.
Use this Skill when you need to:
- Understand the structure of a C program
- Analyze functions, statements, and expressions
- Prepare C code for static analysis or security analysis
- Transform C code into an intermediate representation (AST)
- Feed structured code information into downstream tools or agents
The AST is generated using a Python-based C parser and printed directly to standard output.
When to Use
Apply this Skill when the user asks to:
- “Parse this C code”
- “Convert this C file to an AST”
- “Show me the AST of this C program”
- “Analyze the structure of this C code”
- “Extract syntax tree / abstract syntax tree from C”
This Skill is especially useful in compiler frontends, program analysis, and security research workflows.
Instructions
Follow these steps strictly and in order:
- Navigate to the Skill scripts directory
- Change working directory to the
scripts/directory under this skill:
`` scripts/ ``
- Handle the input C source
- If the user provides a path to a
.cfile, use it directly. - If the user provides inline C code as a string, you must first save it to a C source file using the provided script:
``bash python3 save_c.py --input "" --output --filename .c ``
- Ensure the generated file has a
.cextension and is successfully written to disk.
- Run the AST extraction script
- Convert the C source file to its Abstract Syntax Tree by executing:
``bash python3 c_2_ast.py --input ``
- Do not modify the source code
- This Skill is strictly read-only.
- Do not rewrite, reformat, optimize, or otherwise alter the C code.
- Return the AST output verbatim
- The script prints the AST directly to standard output.
- Return the output exactly as produced.
- Do not summarize, paraphrase, or restructure the AST.
- Preserve indentation, hierarchy, and node ordering.
- If parsing fails
- Report the exact error message produced by the script.
- Suggest likely causes, such as:
- Missing or unsupported header files
- Unsupported C extensions (e.g., compiler-specific syntax)
- Invalid or incomplete C syntax
Output Format
The output is a tree-structured textual AST, for example:
````
FileAST: FuncDef: Decl: main FuncDecl: TypeDecl: IdentifierType: ['int'] Compound: FuncCall: ID: puts ExprList: Constant: string, "Hello" Return: Constant: int, 0
````
This output represents the syntactic structure of the C program and can be consumed by downstream tools.
Additional Resources
For deeper understanding of:
- AST node types
pycparserinternal representation- Meaning of specific syntax tree nodes
- Limitations of the C grammar supported
see the accompanying reference document:
➡️ [reference.md](reference.md)
Only read this file when more detailed or theoretical information is required. For standard AST extraction tasks, this Skill file alone is sufficient.
Notes and Limitations
- The AST follows standard C syntax (C89/C99 subset).
- Some compiler-specific extensions (e.g., GCC attributes) may not be supported.
- Header files are handled using a minimal fake libc environment.
- Macro-heavy or highly platform-specific code may require preprocessing.
Examples
Example 1: Simple AST extraction
User request: > Convert this C file to an AST.
Action:
python3 c_2_AST.py --input example.c
````
Result:
* The AST is printed directly.
---
### Example 2: Security analysis preparation
User request:
> I want to analyze this C program for vulnerabilities.
Action:
* First, extract the AST using this Skill.
* Then, pass the AST to a vulnerability analysis or pattern-matching process.
---
## Best Practices
* Use this Skill **before** any deep code analysis.
* Treat the AST as an intermediate representation.
* Combine with CFG/DFG or semantic analysis for advanced tasks.
---
End of Skill.
## Source & license
This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.
- **Author:** [Narwhal-Lab](https://github.com/Narwhal-Lab)
- **Source:** [Narwhal-Lab/MagicSkills](https://github.com/Narwhal-Lab/MagicSkills)
- **License:** MIT
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet, be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.