orangeduck / BuildYourOwnLisp

Learn C and build your own programming language in under 1000 lines of code!
http://www.buildyourownlisp.com/
Other
2.84k stars 392 forks source link

Errors with MPC #140

Open CaptainZidgel opened 4 years ago

CaptainZidgel commented 4 years ago

Has their been a change in mpc syntax since the last website update? Trying to follow tutorial and running into an issue at chapter 6, trying to run the following code:

#include <stdio.h>
#include <stdlib.h>
#include <editline/readline.h>
#include <editline/history.h>
#include "mpc.h"

static char input[2048];

int main() {
    mpc_parser_t* Number = mpc_new("number");
    mpc_parser_t* Operator = mpc_new("operator");
    mpc_parser_t* Expr = mpc_new("expr");
    mpc_parser_t* Lispy = mpc_new("lispy");

    mpca_lang(MPCA_LANG_DEFAULT,
    "                       \
    number : /-?[0-9]+/;                \
    operator : '+' | '-' | '*' | '/' ;      \
    expr : <number> | '(' <operator> <expr>+ ')' :  \
    lispy : /^/ <operator> <expr>+ /$/ ;        \
    ",
    Number, Operator, Expr, Lispy);

    puts("v 0.0");
    puts("Press Ctrl+c to Exit\n");

    while (1) {
        char* input = readline("* ");
        add_history(input);
        printf("You've just inp't %s", input);
        free(input);
        /* Poopy */
        mpc_result_t r;
        if (mpc_parse("<stdin>", input, Lispy, &r)) {
            mpc_ast_print(r.output);
            mpc_ast_delete(r.output);
        } else {
            mpc_ast_print(r.error);
            mpc_ast_delete(r.error);
        }

    }

    mpc_cleanup(4, Number, Operator, Expr, Lispy);
    return 0;
}

Running this command... cc -std=c99 -Wall thing.c mpc.c -ledit -lm -o thing.out (Using the file name 'thing' instead of 'parsing' as is used in the tutorial)

                 from mpc.h:1,
                 from thing.c:5:
mpc.h:927:29: error: conflicting types for ‘mpc_pdata_string_t’
 typedef struct { char *x; } mpc_pdata_string_t;
                             ^~~~~~~~~~~~~~~~~~
In file included from mpc.h:1:0,
                 from mpc.h:1,
                 from mpc.h:1,
                 from mpc.h:1,
                 from thing.c:5:
mpc.h:927:29: note: previous declaration of ‘mpc_pdata_string_t’ was here
 typedef struct { char *x; } mpc_pdata_string_t;
                             ^~~~~~~~~~~~~~~~~~
In file included from mpc.h:1:0,
                 from mpc.h:1,
                 from mpc.h:1,
                 from thing.c:5:
mpc.h:928:18: error: unknown type name ‘mpc_parser_t’
 typedef struct { mpc_parser_t *x; mpc_apply_t f; } mpc_pdata_apply_t;
                  ^~~~~~~~~~~~
mpc.h:928:35: error: unknown type name ‘mpc_apply_t’
 typedef struct { mpc_parser_t *x; mpc_apply_t f; } mpc_pdata_apply_t;
                                   ^~~~~~~~~~~
mpc.h:928:52: error: conflicting types for ‘mpc_pdata_apply_t’
 typedef struct { mpc_parser_t *x; mpc_apply_t f; } mpc_pdata_apply_t;
                                                    ^~~~~~~~~~~~~~~~~
In file included from mpc.h:1:0,
                 from mpc.h:1,
                 from mpc.h:1,
                 from thing.c:5:
mpc.h:928:52: note: previous declaration of ‘mpc_pdata_apply_t’ was here
 typedef struct { mpc_parser_t *x; mpc_apply_t f; } mpc_pdata_apply_t;
                                                    ^~~~~~~~~~~~~~~~~
In file included from mpc.h:1:0,
                 from mpc.h:1,
                 from mpc.h:1,
                 from mpc.h:1,
                 from mpc.h:1,
                 from mpc.h:1,
                 from mpc.h:1,
                 from mpc.h:1,
                 from mpc.h:1,
                 from thing.c:5:
mpc.h:929:18: error: unknown type name ‘mpc_parser_t’
 typedef struct { mpc_parser_t *x; mpc_apply_to_t f; void *d; } mpc_pdata_apply_to_t;
                  ^~~~~~~~~~~~
mpc.h:929:35: error: unknown type name ‘mpc_apply_to_t’
 typedef struct { mpc_parser_t *x; mpc_apply_to_t f; void *d; } mpc_pdata_apply_to_t;
                                   ^~~~~~~~~~~~~~
mpc.h:929:64: error: conflicting types for ‘mpc_pdata_apply_to_t’
 typedef struct { mpc_parser_t *x; mpc_apply_to_t f; void *d; } mpc_pdata_apply_to_t;
                                                                ^~~~~~~~~~~~~~~~~~~~
In file included from mpc.h:1:0,
                 from mpc.h:1,
                 from mpc.h:1,
                 from mpc.h:1,
                 from mpc.h:1,
                 from thing.c:5:
mpc.h:929:64: note: previous declaration of ‘mpc_pdata_apply_to_t’ was here
 typedef struct { mpc_parser_t *x; mpc_apply_to_t f; void *d; } mpc_pdata_apply_to_t;
                                                                ^~~~~~~~~~~~~~~~~~~~
In file included from mpc.h:1:0,
                 from mpc.h:1,
                 from mpc.h:1,
                 from mpc.h:1,
                 from mpc.h:1,
                 from mpc.h:1, //had to subtract about a couple dozen of these from every error "block"
                 from thing.c:5:
mpc.h:930:18: error: unknown type name ‘mpc_parser_t’
 typedef struct { mpc_parser_t *x; mpc_dtor_t dx; mpc_check_t f; char *e; } mpc_pdata_check_t;
                  ^~~~~~~~~~~~
mpc.h:930:35: error: unknown type name ‘mpc_dtor_t’
 typedef struct { mpc_parser_t *x; mpc_dtor_t dx; mpc_check_t f; char *e; } mpc_pdata_check_t;
                                   ^~~~~~~~~~
mpc.h:930:50: error: unknown type name ‘mpc_check_t’
 typedef struct { mpc_parser_t *x; mpc_dtor_t dx; mpc_check_t f; char *e; } mpc_pdata_check_t;
                                                  ^~~~~~~~~~~
mpc.h:930:76: error: conflicting types for ‘mpc_pdata_check_t’
 struct { mpc_parser_t *x; mpc_dtor_t dx; mpc_check_t f; char *e; } mpc_pdata_check_t;
                                                                    ^~~~~~~~~~~~~~~~~

This is just a small sample, as I suspect the actual console output would be a mile long...

orangeduck commented 4 years ago

Hi @Coolster4000,

I'm not sure what could be wrong and I can't seem to reproduce it but you could try getting the newest version of mpc from the github repo.

Dan