Added flags to language specifiction. Added optional expect string to language specification. Added some exaple grammars for testing and demos

This commit is contained in:
Daniel Holden
2014-01-26 11:25:50 +00:00
parent 8931782986
commit d5e2bdf977
17 changed files with 942 additions and 269 deletions

View File

@@ -11,9 +11,9 @@ void test_grammar(void) {
Value = mpc_new("value");
Maths = mpc_new("maths");
mpc_define(Expr, mpca_grammar(" <product> (('+' | '-') <product>)* ", Prod));
mpc_define(Prod, mpca_grammar(" <value> (('*' | '/') <value>)* ", Value));
mpc_define(Value, mpca_grammar(" /[0-9]+/ | '(' <expression> ')' ", Expr));
mpc_define(Expr, mpca_grammar(MPC_LANG_DEFAULT, " <product> (('+' | '-') <product>)* ", Prod));
mpc_define(Prod, mpca_grammar(MPC_LANG_DEFAULT, " <value> (('*' | '/') <value>)* ", Value));
mpc_define(Value, mpca_grammar(MPC_LANG_DEFAULT, " /[0-9]+/ | '(' <expression> ')' ", Expr));
mpc_define(Maths, mpca_total(Expr));
t0 = mpc_ast_new("product|value|regex", "24");
@@ -66,7 +66,7 @@ void test_language(void) {
Value = mpc_new("value");
Maths = mpc_new("maths");
mpca_lang(
mpca_lang(MPC_LANG_DEFAULT,
" \
expression : <product> (('+' | '-') <product>)*; \
product : <value> (('*' | '/') <value>)*; \
@@ -87,7 +87,7 @@ void test_language_file(void) {
Value = mpc_new("value");
Maths = mpc_new("maths");
mpca_lang_contents("./tests/maths.grammar", Expr, Prod, Value, Maths);
mpca_lang_contents(MPC_LANG_DEFAULT,"./tests/maths.grammar", Expr, Prod, Value, Maths);
mpc_cleanup(4, Expr, Prod, Value, Maths);