How to obtain parsing result in ANTLR 3 with C target language?

22 Views Asked by At

I have to use ANTLR 3 with C target and I have some problems to understand how to output different messages if the parsing is successfull or not.

What I have to add to my main.c file to obtain this behaviour?

int main(int argc, char *argv[]) {

    pANTLR3_UINT8 fName = (pANTLR3_UINT8)"./example";
    pANTLR3_INPUT_STREAM input = antlr3FileStreamNew(fName, ANTLR3_ENC_8BIT);

    pX509Lexer lxr = X509LexerNew(input);
    pANTLR3_COMMON_TOKEN_STREAM tokens = antlr3CommonTokenStreamSourceNew(ANTLR3_SIZE_HINT, TOKENSOURCE(lxr));
    //print_lexer_result(tokens);
    
    pX509Parser psr = X509ParserNew(tokens);
    psr -> prog(psr);

    lxr    -> free(lxr);
    tokens -> free(tokens);
    psr    -> free(psr);
    input  -> close(input);

    printf("[  OK  ] Successfully parsed!\n");

    return 0;
}

I think I have to add something after psr->prog(psr) to print the parsing result or the resulting parse tree.

0

There are 0 best solutions below