Some language stuff

This commit is contained in:
Daniel Holden
2013-09-26 17:58:14 +01:00
parent d1881a0d0c
commit 751e3f6b9d
5 changed files with 274 additions and 59 deletions

View File

@@ -53,6 +53,50 @@ void test_grammar(void) {
mpc_cleanup(4, Expr, Prod, Value, Maths);
}
void test_language(void) {
mpc_parser_t* Expr = mpc_new("expression");
mpc_parser_t* Prod = mpc_new("product");
mpc_parser_t* Value = mpc_new("value");
mpc_parser_t* Maths = mpc_new("maths");
mpca_lang(
" \
expression : <product> (('+' | '-') <product>)*; \
product : <value> (('*' | '/') <value>)*; \
value : /[0-9]+/ | '(' <expression> ')'; \
maths : /^\\w*/ <expression> /\\w*$/; \
",
Expr, Prod, Value, Maths);
mpc_print(Expr);
mpc_print(Prod);
mpc_print(Value);
mpc_print(Maths);
mpc_cleanup(4, Expr, Prod, Value, Maths);
}
void test_language_file(void) {
mpc_parser_t* Expr = mpc_new("expression");
mpc_parser_t* Prod = mpc_new("product");
mpc_parser_t* Value = mpc_new("value");
mpc_parser_t* Maths = mpc_new("maths");
mpca_lang_file("maths.grammar", Expr, Prod, Value, Maths);
mpc_print(Expr);
mpc_print(Prod);
mpc_print(Value);
mpc_print(Maths);
mpc_cleanup(4, Expr, Prod, Value, Maths);
}
void suite_grammar(void) {
pt_add_test(test_grammar, "Test Grammar", "Suite Grammar");
pt_add_test(test_language, "Test Language", "Suite Grammar");
pt_add_test(test_language_file, "Test Language File", "Suite Grammar");
}