Logo: C To Ast

C To Ast

Organisatioun
Narwhal-Lab
c-to-ast

Parse C source code into an Abstract Syntax Tree (AST). Use when analyzing C programs, understanding code structure, performing static analysis, or preparing code for further program analysis (e.g., CFG, DFG, vulnerability detection).

Iwwersiicht

EditeurNarwhal-Lab
RepositoryMagicSkills
Skill-Nummc-to-ast
Stären
317
Forks
24
Matgeliwwert Dateien
6
LizenzMIT
Linken
  • Instruktiounen am Markdown-Format

    Eng SKILL.md-Datei, déi de Modell bei Bedarf luet, soudatt nëmmen Token ufalen, wann eng Ufro tatsächlech dozou passt.

  • Funktionéiert mat all LLM

    KI-Skills si reng Markdown, keen ubidderspezifesche Code. Dofir funktionéiert dëse Skill mat GPT, Claude, Gemini, Grok oder engem lokale Modell.

  • 6 matgeliwwert Dateien

    Skripten, Virlagen a Referenzen, déi de Modell beim Schaffe liese kann. D'Dateie kënnen nëmme gelies ginn a ginn ni ausgeféiert.

  • Open Source

    Narwhal-Lab huet de Skill op GitHub verëffentlecht. Liest de Quelltext, ier Dir de Skill installéiert.

Installatioun

Installéiert de KI-Skill C To Ast an TypingMind, fir e mat all LLM ze benotzen, oder setzt en an en anere KI-Agent an, deen SKILL.md liest.

1

An TypingMind installéieren

TypingMind installéiert e Skill direkt aus sengem GitHub-Dossier — dobäi gëtt SKILL.md gelies, d'Ressourcedateie gi gebëndelt an d'Resultat gëtt lokal gespäichert.

  1. Maacht d'App op a gitt op Plugins → Skills.
  2. Wielt „Vu GitHub installéieren“.
  3. Pecht d'URL vum Skill-Dossier, déi hei drënner steet, an a bestätegt d'Installatioun.
    https://github.com/Narwhal-Lab/MagicSkills/tree/main/skill_template/c_2_ast
  4. Aktivéiert de Skill an all Chat, an deem Dir e benotze wëllt.
Plugins → Skills → Skill derbäisetzen → Iwwer eng GitHub-URL. Pecht dann d'URL vum Dossier an a klickt op Weider.
2

An engem anere KI-Agent installéieren

All KI-Agent, deen d'Format Agent Skills liest, kann dëse Skill benotzen — kopéiert den Dossier an d'Skill-Verzeechnes vun deem KI-Agent.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/Narwhal-Lab/MagicSkills.git /tmp/MagicSkills
mkdir -p .claude/skills
cp -r /tmp/MagicSkills/skill_template/c_2_ast .claude/skills/c-to-ast
Start Claude Code nom Kopéieren nei, fir datt den neie Skill erkannt gëtt.

An TypingMind benotzen

Aktivéiert C To Ast an engem Chat vun TypingMind, an de Modell iwwerhëlt de Rescht. Den Numm an d'Beschreiwung stinn am System-Prompt. Soubal eng Ufro dozou passt, luet de Modell déi komplett Instruktioune selwer — Dir musst de Skill ni manuell opruffen, an et fale keng Token un, bis en tatsächlech benotzt gëtt.

De Modell luet C To Ast automatesch, soubal eng Ufro dozou passt.

Funktionéiert mat all KI-Modell

KI-Skills si reng Markdown-Instruktiounen amplaz vun ubidderspezifeschem Code. Dofir ass C To Ast net un de Modell gebonnen, fir deen de Skill geschriwwe gouf. Installéiert en eemol an TypingMind a benotzt e mat GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama oder engem lokale Modell, deen Dir selwer bedreift — alles mat Ären eegenen API-Schlësselen.

  • Gëtt nëmme gelueden, wann et néideg ass

    De System-Prompt enthält nëmmen den Numm an d'Beschreiwung. D'Instruktioune gi bei der éischter passender Ufro gelueden, soudatt en onbenotzte Skill näischt kascht.

  • De Modell am lafende Chat wiesselen

    Well de Skill aus Instruktiounen amplaz vu Code besteet, funktionéiert en och no engem Modellwiessel — den nächste Modell liest déi selwecht SKILL.md-Datei.

Skill-Instruktiounen

Dëst ass den Inhalt vu SKILL.md, deen de Modell luet. Liest e virun der Installatioun — e Skill besteet aus Instruktiounen, déi Äre Modell befollegt.

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:

  1. Navigate to the Skill scripts directory

    • Change working directory to the scripts/ directory under this skill:
      scripts/
  2. Handle the input C source

    • If the user provides a path to a .c file, 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 "<C code string>" --output <output_dir> --filename <filename>.c
    • Ensure the generated file has a .c extension and is successfully written to disk.
  3. Run the AST extraction script

    • Convert the C source file to its Abstract Syntax Tree by executing:
      bash
      python3 c_2_ast.py --input <path_to_c_file>
  4. Do not modify the source code

    • This Skill is strictly read-only.
    • Do not rewrite, reformat, optimize, or otherwise alter the C code.
  5. 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.
  6. 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
  • pycparser internal representation
  • Meaning of specific syntax tree nodes
  • Limitations of the C grammar supported

see the accompanying reference document:

➡️ 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:

bash
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.

Matgeliwwert Dateien

De Modell liest dës Dateie bei Bedarf, wärend de Skill gelueden ass. Si ginn als liesbar Dateie bereetgestallt a ginn ni ausgeféiert.

Heefeg gestallte Froen

Wat mécht de KI-Skill C To Ast?

Parse C source code into an Abstract Syntax Tree (AST). Use when analyzing C programs, understanding code structure, performing static analysis, or preparing code for further program analysis (e.g., CFG, DFG, vulnerability detection).

Firwat C To Ast op TypingMind benotzen?

Well Dir en eemol installéiert a mat all Modell benotze kënnt. C To Ast besteet aus einfachem Markdown amplaz vun ubidderspezifeschem Code. Dee selwechte Skill funktionéiert also mat GPT-5, Claude, Gemini, Grok oder engem lokale Modell – an Dir kënnt de Modell matzen am Chat wiesselen, ouni datt de Skill ophält ze funktionéieren. TypingMind benotzt Är eegen API-Schlësselen, sou datt Dir d'Ubidder direkt bezuelt, amplaz en Abonnement pro Benotzerplaz ze bezuelen. Är Skills a Chats bleiwen an Ärem eegene Späicher.

Wéi installéieren ech C To Ast an TypingMind?

Maacht an TypingMind Plugins → Skills → Vu GitHub installéieren op a setzt https://github.com/Narwhal-Lab/MagicSkills/tree/main/skill_template/c_2_ast an. TypingMind liest d'Datei SKILL.md, bëndelt déi zougehéiereg Dateien an installéiert dat Ganzt als Skill, deen Dir pro Chat aktivéiere kënnt.

Wéi eng KI-Modeller kënnen C To Ast benotzen?

All Modell, deen Dir an TypingMind verbënnt. KI-Skills sinn einfach Markdown-Instruktiounen an net ubidderspezifesche Code. Dofir kënne GPT, Claude, Gemini, Grok a lokal Modeller dëse Skill lueden, wann eng Ufro dozou passt.

Wéi vill KI-Modeller kann ech mat C To Ast benotzen?

Esou vill wéi Dir wëllt. Soulaang e Modell Skills ënnerstëtzt, kënnt Dir C To Ast domat benotzen – zum Beispill mat GPT, Claude, Gemini, Grok, DeepSeek, Mistral oder Llama – alles op TypingMind mat Ären eegenen API-Schlësselen.

Ass de KI-Skill C To Ast gratis?

Jo. Narwhal-Lab huet de Skill ënner der Lizenz MIT op GitHub publizéiert. Dir bezuelt nëmmen Ären eegene KI-Ubidder fir d'Token, déi Dir benotzt.

Wat si KI-Skills?

E KI-Skill ass e weiderverwendbare Pak vun Instruktiounen, deen engem KI-Modell bäibréngt, wéi en eng bestëmmt Aufgab erfëllt. E follegt dem oppenen Agent Skills-Format: eng Datei SKILL.md mat engem Numm an enger Beschreiwung, plus all Scripten, Virlagen oder Referenzdateien, déi de Modell eventuell brauch. De Modell liest d'Instruktiounen eréischt, wann Är Ufro zum Skill passt. En installéierte Skill kascht also näischt, bis e benotzt gëtt.

Wéi ënnerscheede sech KI-Skills vu Plugins oder MCP-Serveren?

E Plugin oder MCP-Server gëtt engem Modell nei Tools, déi en opruffe kann – Code, deen iergendwou leeft an e Resultat zeréckgëtt. E KI-Skill gëtt dem Modell dogéint Wëssen an eng Virgoensweis: wéi en eng Aufgab ugeet, wéi eng Schrëtt e maache soll a wéi eng gutt Ausgab ausgesäit. Skills bestinn aus einfachem Markdown, brauche kee Server, keen API-Schlëssel a kee Lafzäitëmfeld a funktionéiere mat all Modell.

Alleguer weisen

Elo Ären eegene KI-Aarbechtsberäich ariichten

Abonnéiert Iech op eisen Newsletter, fir iwwer nei Funktiounen an zukünfteg Gewënnspiller informéiert ze ginn 👇