Fixed bug in state tagging. Updated examples to use concatinated preprocessor strings

This commit is contained in:
Daniel Holden
2014-04-16 17:06:16 +01:00
parent 842835aaa5
commit 8d9bf9fdda
7 changed files with 95 additions and 80 deletions

View File

@@ -8,12 +8,10 @@ int main(int argc, char **argv) {
mpc_parser_t* Doge = mpc_new("doge");
mpca_lang(MPCA_LANG_DEFAULT,
" \
adjective : \"wow\" | \"many\" | \"so\" | \"such\"; \
noun : \"lisp\" | \"language\" | \"c\" | \"book\" | \"build\"; \
phrase : <adjective> <noun>; \
doge : /^/ <phrase>* /$/; \
",
" adjective : \"wow\" | \"many\" | \"so\" | \"such\"; "
" noun : \"lisp\" | \"language\" | \"c\" | \"book\" | \"build\"; "
" phrase : <adjective> <noun>; "
" doge : /^/ <phrase>* /$/; ",
Adjective, Noun, Phrase, Doge);
if (argc > 1) {

View File

@@ -12,17 +12,15 @@ int main(int argc, char **argv) {
mpc_parser_t* Lispy = mpc_new("lispy");
mpca_lang(MPCA_LANG_PREDICTIVE,
" \
number \"number\" : /[0-9]+/ ; \
symbol \"symbol\" : /[a-zA-Z0-9_+\\-*\\/\\\\=<>!&]+/ ; \
string \"string\" : /\"(\\\\.|[^\"])*\"/ ; \
comment : /;[^\\r\\n]*/ ; \
sexpr : '(' <expr>* ')' ; \
qexpr : '{' <expr>* '}' ; \
expr : <number> | <symbol> | <string> \
| <comment> | <sexpr> | <qexpr> ; \
lispy : /^/ <expr>* /$/ ; \
",
" number \"number\" : /[0-9]+/ ; "
" symbol \"symbol\" : /[a-zA-Z0-9_+\\-*\\/\\\\=<>!&]+/ ; "
" string \"string\" : /\"(\\\\.|[^\"])*\"/ ; "
" comment : /;[^\\r\\n]*/ ; "
" sexpr : '(' <expr>* ')' ; "
" qexpr : '{' <expr>* '}' ; "
" expr : <number> | <symbol> | <string> "
" | <comment> | <sexpr> | <qexpr> ; "
" lispy : /^/ <expr>* /$/ ; ",
Number, Symbol, String, Comment, Sexpr, Qexpr, Expr, Lispy);
if (argc > 1) {

View File

@@ -8,12 +8,10 @@ int main(int argc, char **argv) {
mpc_parser_t *Maths = mpc_new("maths");
mpca_lang(MPCA_LANG_PREDICTIVE,
" \
expression : <product> (('+' | '-') <product>)*; \
product : <value> (('*' | '/') <value>)*; \
value : /[0-9]+/ | '(' <expression> ')'; \
maths : /^/ <expression> /$/; \
",
" expression : <product> (('+' | '-') <product>)*; "
" product : <value> (('*' | '/') <value>)*; "
" value : /[0-9]+/ | '(' <expression> ')'; "
" maths : /^/ <expression> /$/; ",
Expr, Prod, Value, Maths);
if (argc > 1) {

View File

@@ -21,46 +21,44 @@ int main(int argc, char **argv) {
mpc_parser_t* Smallc = mpc_new("smallc");
mpc_err_t* err = mpca_lang(MPCA_LANG_DEFAULT,
" \n\
ident : /[a-zA-Z_][a-zA-Z0-9_]*/ ; \n\
number : /[0-9]+/ ; \n\
character : /'.'/ ; \n\
string : /\"(\\\\.|[^\"])*\"/ ; \n\
\n\
factor : '(' <lexp> ')' \n\
| <number> \n\
| <character> \n\
| <string> \n\
| <ident> '(' <lexp>? (',' <lexp>)* ')' \n\
| <ident> ; \n\
\n\
term : <factor> (('*' | '/' | '%') <factor>)* ; \n\
lexp : <term> (('+' | '-') <term>)* ; \n\
\n\
stmt : '{' <stmt>* '}' \n\
| \"while\" '(' <exp> ')' <stmt> \n\
| \"if\" '(' <exp> ')' <stmt> \n\
| <ident> '=' <lexp> ';' \n\
| \"print\" '(' <lexp>? ')' ';' \n\
| \"return\" <lexp>? ';' \n\
| <ident> '(' <ident>? (',' <ident>)* ')' ';' ; \n\
\n\
exp : <lexp> '>' <lexp> \n\
| <lexp> '<' <lexp> \n\
| <lexp> \">=\" <lexp> \n\
| <lexp> \"<=\" <lexp> \n\
| <lexp> \"!=\" <lexp> \n\
| <lexp> \"==\" <lexp> ; \n\
\n\
typeident : (\"int\" | \"char\") <ident> ; \n\
decls : (<typeident> ';')* ; \n\
args : <typeident>? (',' <typeident>)* ; \n\
body : '{' <decls> <stmt>* '}' ; \n\
procedure : (\"int\" | \"char\") <ident> '(' <args> ')' <body> ; \n\
main : \"main\" '(' ')' <body> ; \n\
includes : (\"#include\" <string>)* ; \n\
smallc : /^/ <includes> <decls> <procedure>* <main> /$/ ; \n\
",
" ident : /[a-zA-Z_][a-zA-Z0-9_]*/ ; \n"
" number : /[0-9]+/ ; \n"
" character : /'.'/ ; \n"
" string : /\"(\\\\.|[^\"])*\"/ ; \n"
" \n"
" factor : '(' <lexp> ')' \n"
" | <number> \n"
" | <character> \n"
" | <string> \n"
" | <ident> '(' <lexp>? (',' <lexp>)* ')' \n"
" | <ident> ; \n"
" \n"
" term : <factor> (('*' | '/' | '%') <factor>)* ; \n"
" lexp : <term> (('+' | '-') <term>)* ; \n"
" \n"
" stmt : '{' <stmt>* '}' \n"
" | \"while\" '(' <exp> ')' <stmt> \n"
" | \"if\" '(' <exp> ')' <stmt> \n"
" | <ident> '=' <lexp> ';' \n"
" | \"print\" '(' <lexp>? ')' ';' \n"
" | \"return\" <lexp>? ';' \n"
" | <ident> '(' <ident>? (',' <ident>)* ')' ';' ; \n"
" \n"
" exp : <lexp> '>' <lexp> \n"
" | <lexp> '<' <lexp> \n"
" | <lexp> \">=\" <lexp> \n"
" | <lexp> \"<=\" <lexp> \n"
" | <lexp> \"!=\" <lexp> \n"
" | <lexp> \"==\" <lexp> ; \n"
" \n"
" typeident : (\"int\" | \"char\") <ident> ; \n"
" decls : (<typeident> ';')* ; \n"
" args : <typeident>? (',' <typeident>)* ; \n"
" body : '{' <decls> <stmt>* '}' ; \n"
" procedure : (\"int\" | \"char\") <ident> '(' <args> ')' <body> ; \n"
" main : \"main\" '(' ')' <body> ; \n"
" 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);