diff --git a/ccmeta.leg b/ccmeta.leg index fb1026d..e1bab22 100644 --- a/ccmeta.leg +++ b/ccmeta.leg @@ -1295,6 +1295,10 @@ typedef enum { language lang = C, printLang = C; +int getProtoNumber(oop obj) { + return get(map_get(map_get(obj, __proto___symbol), __name___symbol), Symbol, prototype); +} + %} @@ -1443,6 +1447,7 @@ primaryExpression = stringLiteral | constant | id | META_AT ( META_LCB x:mstmt { $$ = eval(globals, x) } | META_OPERATORS META_LPAREN x:mexp { $$ = eval(globals, x) } | META_LPAREN x:mexp { $$ = eval(globals, x) } + | META_COMMA x:mcomma { $$ = eval(globals, x) } ) | l:LPAREN x:expression r:RPAREN { $$= new_C_subexpr(l, x, r) } | l:LPAREN x:compoundStatement r:RPAREN &{gnu} { $$= new_C_subexpr(l, x, r) } @@ -2154,8 +2159,8 @@ _FLOAT128 = '_Float128' !IDREST &{gnu} { $$= newToken("_Float1 metaCatch = META_AT @{ lang= META } ( META_OPERATORS META_LPAREN m:mexp { eval(globals, m) } | META_LPAREN m:mexp { eval(globals, m) } + | META_LCB m:mstmt | META_IMPORT s:META_STRING ";" { inputStackPush(get(s, String, value)) } - | META_LCB - (s:meta_stmt { eval(globals, s) })* META_RCB { lang = C } ) @@ -2163,7 +2168,10 @@ metaCatch = META_AT @{ lang= META } ( META_OPERATORS META_LPAREN m:mexp mexp = @{ lang = META } s:meta_exp META_RPAREN @{ lang = C } { $$= s } | @{ lang = C } &{ 0 } -mstmt = @{ lang = META } - (s:meta_stmt { eval(globals, s) })* META_RCB { lang = C; $$ = s } # The last one must be a C operator +mcomma = @{ lang = META } s:meta_exp @{ lang = C } { $$= s } + | @{ lang = C } &{ 0 } + +mstmt = @{ lang = META } - (s:meta_stmt { eval(globals, s) })* META_RCB { lang = C } | @{ lang = C } &{ 0 } meta_stmt = s:meta_block { $$ = s } @@ -2293,9 +2301,10 @@ meta_prefix = META_PLUS n:meta_prefix { $$= n } | META_PLING n:meta_prefix { $$= newUnary(Not_proto, n) } | META_PLUSPLUS n:meta_prefix { $$= newPreIncrement(n) } | META_MINUSMINUS n:meta_prefix { $$= newPreDecrement(n) } - | META_BACKTICK META_INITIALIZER i:initializer { $$ = newUnary(Quote_proto ,i) } - | META_BACKTICK META_CONSTANT c:constant { $$ = newUnary(Quote_proto ,c) } - | META_BACKTICK META_STATEMENT c:statement { $$ = newUnary(Quote_proto ,c) } + | META_BACKTICK MO_INITIALIZER i:initializer { $$ = newUnary(Quote_proto ,i) } + | META_BACKTICK MO_CONSTANT c:constant { $$ = newUnary(Quote_proto ,c) } + | META_BACKTICK MO_STATEMENT c:statement { $$ = newUnary(Quote_proto ,c) } + | META_BACKTICK MO_INTEGER i:integerConstant { $$ = newUnary(Quote_proto ,i) } # | META_BACKTICK n:meta_prefix { $$ = newUnary(Quasiquote_proto, n) } # | META_AT n:meta_prefix { $$ = newUnary(Unquote_proto, n) } | n:meta_postfix { $$= n } @@ -2384,11 +2393,12 @@ META_FLOAT = < [-+]* [0-9]+ '.' [0-9]* ('e'[-+]*[0-9]+)? > - { $$ = ma ###### META operators ###### -META_OPERATORS = META_INITIALIZER | META_CONSTANT | META_STATEMENT +META_OPERATORS = MO_INITIALIZER | MO_CONSTANT | MO_STATEMENT | MO_INTEGER -META_INITIALIZER = 'initializer' ![(a-zA-Z0-9_] - -META_CONSTANT = 'constant' ![(a-zA-Z0-9_] - -META_STATEMENT = 'statement' ![(a-zA-Z0-9_] - +MO_INITIALIZER = 'initializer' ![(a-zA-Z0-9_] - +MO_CONSTANT = 'constant' ![(a-zA-Z0-9_] - +MO_STATEMENT = 'statement' ![(a-zA-Z0-9_] - +MO_INTEGER = 'integer' ![(a-zA-Z0-9_] - ############################ diff --git a/tests-parsimony/002.c b/tests-parsimony/002.c index b8c2dd8..b1a1abb 100644 --- a/tests-parsimony/002.c +++ b/tests-parsimony/002.c @@ -1,6 +1,6 @@ @{ saved = `initializer (1,2,"stringy thingy",21<<1); - cons = `constant 2; + cons = `constant 2; } @(a = `constant 10) diff --git a/tests-parsimony/004.c b/tests-parsimony/004.c new file mode 100644 index 0000000..3a56528 --- /dev/null +++ b/tests-parsimony/004.c @@ -0,0 +1,22 @@ +@{ + num = `integer 21; + // print(num.text); + // print("\n"); + test = `initializer 2 * 10; +} + + +int x = @{`initializer 2 * @,num;}; + +int main() { + int i = @(`initializer 2 * @,num); + int y = @,test; + + int a = @{ + num = `integer 21; + test = 2; + `initializer @(num); + }; + + return 0; +} \ No newline at end of file diff --git a/tests-parsimony/err_001.c b/tests-parsimony/err_001.c new file mode 100644 index 0000000..e54c774 --- /dev/null +++ b/tests-parsimony/err_001.c @@ -0,0 +1,5 @@ +@{ + num = `integer 21; + test = 2; + `initializer @(num); +} diff --git a/tests-parsimony/err_002.c b/tests-parsimony/err_002.c new file mode 100644 index 0000000..55b7ab6 --- /dev/null +++ b/tests-parsimony/err_002.c @@ -0,0 +1,6 @@ +@{ + num = `integer 21; + test = `initializer 2 * @,num; +} + +int x = @{`initializer 2 * @,num;}; \ No newline at end of file