How to build an AST using PackCC?

38 views Asked by At

Using PackCC to generate a parser from a PEG grammar you get a API like this

typedef struct pcc_context_tag pcc_context_t;

pcc_context_t *pcc_create(void *auxil);
int pcc_parse(pcc_context_t *ctx, int *ret);
void pcc_destroy(pcc_context_t *ctx);

Since the implementation of struct pcc_context_tag is only in the .c file, I imagine that it is intentionally "hidden" and I can work with these API. Therefore my question is:

  • I can build the Abstract Syntax Tree using the API? Or I need to investigate the .c file to understanding the actual implementation of the parser?

As context, I'm trying to store the the AST on a tree like the bellow, where for each PEG file data is a pointer for a distinct structure with the information of each node of the AST.

The example AST Builder for Tiny-C is not clear to me, no much comments in the code...

Another example is PegOF (also not clear to me), I can't find on it a subroutine to convert pcc_context_t to struct AstNode.

typedef struct tree_s {
   void *data;
   struct tree_s *first_children;
   struct tree_s *next_sibling;
} tree_t;
0

There are 0 answers