librdesc
Loading...
Searching...
No Matches
Typedefs | Functions
util.h File Reference

Development and Debugging Utilities. More...

#include <stdio.h>

Go to the source code of this file.

Typedefs

typedef void(* rdesc_tk_printer_func) (const struct rdesc_token *, FILE *out)
 Function pointer type for printing tokens.
 

Functions

void rdesc_dump_dot (const struct rdesc_node *n, rdesc_tk_printer_func tk_printer, const char *const nt_names[], FILE *out)
 Dumps the Concrete Syntax Tree (CST) as a Graphviz DOT graph.
 
void rdesc_dump_bnf (const struct rdesc_cfg *cfg, const char *const tk_names[], const char *const nt_names[], FILE *out)
 Dumps the Context-Free Grammar in BNF format.
 

Detailed Description

Development and Debugging Utilities.

This header provides tools for visualizing data structures in librdesc.

Function Documentation

◆ rdesc_dump_bnf()

void rdesc_dump_bnf ( const struct rdesc_cfg cfg,
const char *const  tk_names[],
const char *const  nt_names[],
FILE *  out 
)

Dumps the Context-Free Grammar in BNF format.

Iterates over the production rules defined in the configuration and prints them in a human-readable BNF format. (e.g.A ::= B | C)

Parameters
cfgUnderlying CFG
tk_namesThe token name or literal representation (e.g., IDENT or +). If you do not want to put double quotes around token name, put @ to beginning of the name.
nt_namesThe raw name of the non-terminal (e.g., expr). The dumper handles the surrounding < and > characters automatically.
outOutput file stream

◆ rdesc_dump_dot()

void rdesc_dump_dot ( const struct rdesc_node n,
rdesc_tk_printer_func  tk_printer,
const char *const  nt_names[],
FILE *  out 
)

Dumps the Concrete Syntax Tree (CST) as a Graphviz DOT graph.

Traverses the CST and generates a .dot representation.

Parameters
nCST node
nt_namesThe raw name of the non-terminal (e.g., expr). The dumper handles the surrounding < and > characters automatically.
tk_printerCallback to print token names.
  • DOT Context: This function handle seminfo fields and constructs a table accordingly.
outOutput file stream