Fixed error with failure messages. Null terminated lists to mpca_lang and fixed crash.

This commit is contained in:
Daniel Holden
2014-04-23 12:20:20 +01:00
parent 60b1496bb5
commit a5ed2097ea
6 changed files with 13 additions and 12 deletions

View File

@@ -641,7 +641,6 @@ Fold Functions
<tr><td><code>mpc_val_t *mpcf_snd_free(int n, mpc_val_t** xs);</code></td><td>Returns second element of <code>xs</code> and calls <code>free</code> on others</td></tr>
<tr><td><code>mpc_val_t *mpcf_trd_free(int n, mpc_val_t** xs);</code></td><td>Returns third element of <code>xs</code> and calls <code>free</code> on others</td></tr>
<tr><td><code>mpc_val_t *mpcf_strfold(int n, mpc_val_t** xs);</code></td><td>Concatenates all <code>xs</code> together as strings and returns result </td></tr>
<tr><td><code>mpc_val_t *mpcf_maths(int n, mpc_val_t** xs);</code></td><td>Examines second argument as string to see which operator it is, then operators on first and third argument as if they are <code>int*</code>.</td></tr>
</table>

View File

@@ -12,7 +12,7 @@ int main(int argc, char **argv) {
" noun : \"lisp\" | \"language\" | \"c\" | \"book\" | \"build\"; "
" phrase : <adjective> <noun>; "
" doge : /^/ <phrase>* /$/; ",
Adjective, Noun, Phrase, Doge);
Adjective, Noun, Phrase, Doge, NULL);
if (argc > 1) {

View File

@@ -21,7 +21,7 @@ int main(int argc, char **argv) {
" expr : <number> | <symbol> | <string> "
" | <comment> | <sexpr> | <qexpr> ; "
" lispy : /^/ <expr>* /$/ ; ",
Number, Symbol, String, Comment, Sexpr, Qexpr, Expr, Lispy);
Number, Symbol, String, Comment, Sexpr, Qexpr, Expr, Lispy, NULL);
if (argc > 1) {

View File

@@ -12,7 +12,12 @@ int main(int argc, char **argv) {
" product : <value> (('*' | '/') <value>)*; "
" value : /[0-9]+/ | '(' <expression> ')'; "
" maths : /^/ <expression> /$/; ",
Expr, Prod, Value, Maths);
Expr, Prod, Value, Maths, NULL);
mpc_print(Expr);
mpc_print(Prod);
mpc_print(Value);
mpc_print(Maths);
if (argc > 1) {

View File

@@ -60,7 +60,7 @@ int main(int argc, char **argv) {
" includes : (\"#include\" <string>)* ; \n"
" smallc : /^/ <includes> <decls> <procedure>* <main> /$/ ; \n",
Ident, Number, Character, String, Factor, Term, Lexp, Stmt, Exp,
Typeident, Decls, Args, Body, Procedure, Main, Includes, Smallc);
Typeident, Decls, Args, Body, Procedure, Main, Includes, Smallc, NULL);
if (err != NULL) {
mpc_err_print(err);

11
mpc.c
View File

@@ -157,9 +157,8 @@ char *mpc_err_string(mpc_err_t *x) {
if (x->failure) {
mpc_err_string_cat(buffer, &pos, &max,
"error: %s\n",
x->filename, x->state.row+1,
x->state.col+1, x->failure);
"%s: error: %s\n",
x->filename, x->failure);
return buffer;
}
@@ -2867,6 +2866,7 @@ static mpc_parser_t *mpca_grammar_find_parser(char *x, mpca_grammar_st_t *st) {
/* Search Existing Parsers */
for (i = 0; i < st->parsers_num; i++) {
mpc_parser_t *p = st->parsers[i];
if (p == NULL) { return mpc_failf("Unknown Parser '%s'!", x); }
if (p->name && strcmp(p->name, x) == 0) { return p; }
}
@@ -2879,10 +2879,7 @@ static mpc_parser_t *mpca_grammar_find_parser(char *x, mpca_grammar_st_t *st) {
st->parsers = realloc(st->parsers, sizeof(mpc_parser_t*) * st->parsers_num);
st->parsers[st->parsers_num-1] = p;
if (p == NULL) {
return mpc_failf("Unknown Parser '%s'!", x);
}
if (p == NULL) { return mpc_failf("Unknown Parser '%s'!", x); }
if (p->name && strcmp(p->name, x) == 0) { return p; }
}