Closed mgood7123 closed 5 years ago
if i do
Line : <Hyphen> | <Equals> | <Digit>
then i get
test:1:1: error: expected '-', '=' or one or more of one of '0123456789' at 'a'
and if i do
Line : <Hyphen> | <Equals> | <Digit> | <Alpha>
then i get
test:1:2: error: expected one of 'abcdefghijklmnopqrstuvwxyz', one or more of one of 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', ';', newline or end of input at '='
with
Command : <Line> <Command_End>
aswell as matching against
mpc_parser_t * n = mpc_newline(); mpcnew(nl); mpc_define(nl,n);
" Command : <Expression> <Command_End> ; "
" Expression : <Assignment> | <Variable> | <Array> | <Index>; "
" Assignment : <Alpha> <Equals> ( <Alnum> | <Variable> | <Array>)?; "
" Variable : <Dollar> ( <At> | <Alnum> ) ;"
" Array : <Alpha> <Index> ;"
" Index : '[' ( <Digit> | <Array> ) ']' ;"
" Alpha : /[a-z]+[A-Z]+/ | /[A-Z]+[a-z]+/ | /[a-z]+/ | /[A-Z]+/;"
" Alnum : <Alpha> | <Digit>;"
" Digit : /[0-9]+/;"
" Dollar : '$' ;"
" At : '@' ;"
" Equals : '=' ;",
" Command_End: ';' | <nl> | /$/; "
with
a=3\nb=9;
i get
test:2:1: error: expected ';', newline or end of input at 'b'
It is hard for me to say exactly what is wrong and how to fix it without knowing what your intent is but in your original grammar I don't think the Hyphen
clause can ever be parsed as part of a Line
because the Line
will always succeed by matching zero or more Alpha
first. I.E. Line
can be easily matched by the empty string so it will never attempt to parse Hyphen
. (See more here.)
Basically you need to work out how to re-structure your grammar probably be factorizing the terms somehow so that your Line
rule matches zero or more Things
of some kind where the things themselves can either be identifiers, hypens, or spaces.
basically i want Line to match from Alpha
to Command_End
, accepting all input characters
You can try (<Alpha> | <Hyphen> | <Space>)*
ok
it just loads forever lol
wish there was a mpc_ascii or mpc_printable lol
as mpc_any doesnt work
Okay well I am going to close this issue and leave you to debug the grammar yourself since I don't think it is a bug or error in the library.
mpc_parser_t * n = mpc_any(); mpcnew(Any); mpc_define(Any,n);
mpca_lang(MPCA_LANG_DEFAULT,
" Any : <Any>*;",
Any, NULL);
mpc_result_t r;
eval("a=3; b=9; a=$b; a[b[0]]; azG[6] ;ls def kj hgj yih;bash -", Any, &r);
mpc_cleanup(1, Any, NULL);
mobile_c@Mobile-C:~/git/mpc/examples$ gcc shell.c ../mpc.c && ./a.out
Segmentation fault (core dumped)
mobile_c@Mobile-C:~/git/mpc/examples$
https://paste.pound-python.org/show/vy90zrfxIKiBVyxAXusz/
it is however possible to capture it alone (with just the hyphen rule), im not sure why yet https://paste.pound-python.org/show/PUHVGTccAcC6Xw53UAjb/