This code calls the mpc_parse
function with our parser Lispy
, and the input string input
. It copies the result of the parse into r
and returns 1
on success and 0
on failure. We use the address of operator &
on r
when we pass it to the function. This operator will be explained in more detail in later chapters.
Otherwise there has been an error, which is copied into r
in the field error
. We can print it out using mpc_err_print
and delete it using mpc_err_delete
.
Lispy Version 0.0.0.0.2
Press Ctrl+c to Exit
lispy> + 5 (* 2 2)
>
regex
expr|>
char:1:5 '('
operator|char:1:6 '*'
expr|number|regex:1:8 '2'
expr|number|regex:1:10 '2'
regex
lispy> hello
<stdin>:1:1: error: expected whitespace, '+', '-', '*' or '/' at 'h'
lispy> / 1dog
<stdin>:1:4: error: expected one of '0123456789', whitespace, '-', one or more of one of '0123456789', '(' or end of input at 'd'
lispy>
I’m getting an error <stdin>:1:1: error: Parser Undefined!
.