diff --git a/ccmeta.leg b/ccmeta.leg index e1bab22..0ba28f9 100644 --- a/ccmeta.leg +++ b/ccmeta.leg @@ -1410,7 +1410,7 @@ floatingSuffix = [fFlL] imaginarySuffix? characterConstant = < "'" cCharSequence "'" > { $$ = new_C_char(yytext) } - | < "L'" cCharSequence "'" > { $$ = new_C_char(yytext) } - -cCharSequence = ( escapeSequence | !EOL [^\'\\] )* +cCharSequence = ( escapeSequence | !EOL [^\'\\] )* #' escapeSequence = simpleEscapeSequence | octalEscapeSequence @@ -1420,7 +1420,7 @@ escapeSequence = simpleEscapeSequence | '\\' Blank+ EOL &{gnu} | '\\' . &{gnu} -simpleEscapeSequence = '\\'([\'\"?\\abfnrtv] | 'e' &{gnu}) +simpleEscapeSequence = '\\'([\'\"?\\abfnrtv] | 'e' &{gnu}) #' octalEscapeSequence = '\\' octalDigit octalDigit? octalDigit? @@ -1437,14 +1437,14 @@ stringLiteral = { listBegin(); } stringLiteralPart = < '"' sCharSequence '"' > { $$= new_C_char(yytext) } - | < 'L''"' sCharSequence '"' > { $$= new_C_char(yytext) } - -sCharSequence = ( escapeSequence | !EOL [^\"\\] )* +sCharSequence = ( escapeSequence | !EOL [^\"\\] )* #" ### A.2.1 Expressions # 6.5.1 primaryExpression = stringLiteral | constant | id - | META_AT ( META_LCB x:mstmt { $$ = eval(globals, x) } + | META_AT ( META_LCB x:mstmts { $$ = 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) } @@ -1874,6 +1874,7 @@ labeledStatement = i:id c:COLON | d:DEFAULT c:COLON s:statement { $$= new_C_default(d, c, s) } # 6.8.2 +# todo add meta or list meta (@@ for list of things) compoundStatement = @{ C_scopeBegin() } l:LCURLY { listBegin() } @@ -2159,7 +2160,7 @@ _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_LCB m:mstmts | META_IMPORT s:META_STRING ";" { inputStackPush(get(s, String, value)) } ) @@ -2168,10 +2169,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 } -mcomma = @{ lang = META } s:meta_exp @{ lang = C } { $$= s } - | @{ lang = C } &{ 0 } +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 } +mstmts = @{ lang = META } -- ( s:meta_stmt { eval(globals, s) })* META_RCB { lang = C } | @{ lang = C } &{ 0 } meta_stmt = s:meta_block { $$ = s } @@ -2216,7 +2217,7 @@ meta_ident = l:META_IDENT { $$ = l # | META_AT n:meta_prefix { $$ = newUnary(Unquote_proto, n) } meta_syntax2 = < [a-zA-Z_][a-zA-Z0-9_]* > - &{ null != getSyntaxId(2, intern(yytext)) } - { $$ = getSyntaxId(2, intern(yytext)) } + &{ null != getSyntaxId(2, intern(yytext)) } -- { $$ = getSyntaxId(2, intern(yytext)) } meta_try = META_TRY t:meta_stmt i:meta_null c:meta_null f:meta_null ( META_CATCH META_LPAREN i:META_IDENT META_RPAREN c:meta_stmt ) ? @@ -2344,7 +2345,7 @@ meta_value = n:META_FLOAT { $$ | p:meta_paramList e:meta_block { $$ = newFunc(null, p, e, null) } | META_LPAREN ( i:meta_block | i:meta_exp ) META_RPAREN { $$ = i } -meta_string = s:META_STRING - { $$ = s } +meta_string = s:META_STRING -- { $$ = s } META_STRING = META_DQUOTE < (!META_DQUOTE meta_char)* > META_DQUOTE { $$ = makeString(unescape(yytext)) } @@ -2376,110 +2377,110 @@ meta_keyword = META_SWITCH | META_CASE | META_DEFAULT | META_DO | META_FOR | ME | META_THROW | META_TRY | META_CATCH | META_FINALLY # | META_SYNTAX -META_IDENT = !meta_keyword < [a-zA-Z_][a-zA-Z0-9_]* > - { $$ = intern(yytext) } +META_IDENT = !meta_keyword < [a-zA-Z_][a-zA-Z0-9_]* > -- { $$ = intern(yytext) } meta_integer = i:META_INTEGER { $$ = i } | '-' i:meta_integer { $$ = makeInteger(-getInteger(i)) } -META_INTEGER = '0b' < [01]+ > - { $$ = makeInteger(strtol(yytext, 0, 2)) } - | '0x' < [0-9a-fA-F]+ > - { $$ = makeInteger(strtol(yytext, 0, 16)) } - | '0' < [0-7]+ > - { $$ = makeInteger(strtol(yytext, 0, 8)) } - | < [0-9]+ > - { $$ = makeInteger(strtol(yytext, 0, 10)) } - | META_SQUOTE < (!META_SQUOTE meta_char) > META_SQUOTE - { $$ = makeInteger(unescape(yytext)[0]) } +META_INTEGER = '0b' < [01]+ > { $$ = makeInteger(strtol(yytext, 0, 2)) } -- + | '0x' < [0-9a-fA-F]+ > { $$ = makeInteger(strtol(yytext, 0, 16)) }-- + | '0' < [0-7]+ > { $$ = makeInteger(strtol(yytext, 0, 8)) }-- + | < [0-9]+ > { $$ = makeInteger(strtol(yytext, 0, 10)) }-- + | META_SQUOTE < (!META_SQUOTE meta_char) > META_SQUOTE { $$ = makeInteger(unescape(yytext)[0]) }-- -META_FLOAT = < [-+]* [0-9]+ '.' [0-9]* ('e'[-+]*[0-9]+)? > - { $$ = makeFloat(strtold(yytext, 0)) } - | < [-+]* [0-9]* '.' [0-9]+ ('e'[-+]*[0-9]+)? > - { $$ = makeFloat(strtold(yytext, 0)) } - | < [-+]* [0-9]+ ('e'[-+]*[0-9]+) > - { $$ = makeFloat(strtold(yytext, 0)) } +META_FLOAT = < [-+]* [0-9]+ '.' [0-9]* ('e'[-+]*[0-9]+)? > { $$ = makeFloat(strtold(yytext, 0)) } -- + | < [-+]* [0-9]* '.' [0-9]+ ('e'[-+]*[0-9]+)? > { $$ = makeFloat(strtold(yytext, 0)) } -- + | < [-+]* [0-9]+ ('e'[-+]*[0-9]+) > { $$ = makeFloat(strtold(yytext, 0)) } -- ###### META operators ###### META_OPERATORS = MO_INITIALIZER | MO_CONSTANT | MO_STATEMENT | MO_INTEGER -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_] - +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_] -- ############################ -#META_FUN = 'fun' ![a-zA-Z0-9_] - -#META_SYNTAX = 'syntax' ![a-zA-Z0-9_] - -META_VAR = 'var' ![a-zA-Z0-9_] - -META_SWITCH = 'switch' ![a-zA-Z0-9_] - -META_CASE = 'case' ![a-zA-Z0-9_] - -META_DEFAULT = 'default' ![a-zA-Z0-9_] - -META_DO = 'do' ![a-zA-Z0-9_] - -META_FOR = 'for' ![a-zA-Z0-9_] - -META_IN = 'in' ![a-zA-Z0-9_] - -META_WHILE = 'while' ![a-zA-Z0-9_] - -META_IF = 'if' ![a-zA-Z0-9_] - -META_ELSE = 'else' ![a-zA-Z0-9_] - -META_NULL = 'null' ![a-zA-Z0-9_] - -META_RETURN = 'return' ![a-zA-Z0-9_] - -META_BREAK = 'break' ![a-zA-Z0-9_] - -META_CONTINUE = 'continue' ![a-zA-Z0-9_] - -META_THROW = 'throw' ![a-zA-Z0-9_] - -META_TRY = 'try' ![a-zA-Z0-9_] - -META_CATCH = 'catch' ![a-zA-Z0-9_] - -META_FINALLY = 'finally' ![a-zA-Z0-9_] - -META_IMPORT = 'import' ![a-zA-Z0-9_] - -META_HASH = '#' - -META_LOGOR = '||' - -META_LOGAND = '&&' - -META_BITOR = '|' ![|=] - -META_BITXOR = '^' ![=] - -META_BITAND = '&' ![&=] - -META_EQUAL = '==' - -META_NOTEQ = '!=' - -META_LESS = '<' ![<=] - -META_LESSEQ = '<=' - -META_GREATEREQ = '>=' - -META_GREATER = '>' ![>=] - -META_SHLEFT = '<<' ![=] - -META_SHRIGHT = '>>' ![=] - -META_PLUS = '+' ![+=] - -META_MINUS = '-' ![-=] - -META_NEGATE = '-' ![-=0-9.] - -META_PLUSPLUS = '++' - -META_MINUSMINUS = '--' - -META_TILDE = '~' - -META_PLING = '!' ![=] - -META_MULTI = '*' ![=] - -META_DIVIDE = '/' ![/=] - -META_MODULO = '%' ![=] - -META_ASSIGN = '=' ![=] - -META_ASSIGNADD = '+=' - -META_ASSIGNSUB = '-=' - -META_ASSIGNMUL = '*=' - -META_ASSIGNDIV = '/=' - -META_ASSIGNMOD = '%=' - -META_ASSIGNBITOR = '|=' - -META_ASSIGNBITXOR = '^=' - -META_ASSIGNBITAND = '&=' - -META_ASSIGNSHLEFT = '<<=' - -META_ASSIGNSHRIGHT = '>>=' - -META_QUERY = '?' - -META_COLON = ':' - -META_SEMICOLON = ';' - -META_COMMA = ',' - -META_DOT = '.' - -META_BACKTICK = '`' - -META_AT = '@' - -META_LCB = '{' - -META_RCB = '}' - -META_LBRAC = '[' - -META_RBRAC = ']' - -META_LPAREN = '(' - -META_RPAREN = ')' - +#META_FUN = 'fun' ![a-zA-Z0-9_] -- +#META_SYNTAX = 'syntax' ![a-zA-Z0-9_] -- +META_VAR = 'var' ![a-zA-Z0-9_] -- +META_SWITCH = 'switch' ![a-zA-Z0-9_] -- +META_CASE = 'case' ![a-zA-Z0-9_] -- +META_DEFAULT = 'default' ![a-zA-Z0-9_] -- +META_DO = 'do' ![a-zA-Z0-9_] -- +META_FOR = 'for' ![a-zA-Z0-9_] -- +META_IN = 'in' ![a-zA-Z0-9_] -- +META_WHILE = 'while' ![a-zA-Z0-9_] -- +META_IF = 'if' ![a-zA-Z0-9_] -- +META_ELSE = 'else' ![a-zA-Z0-9_] -- +META_NULL = 'null' ![a-zA-Z0-9_] -- +META_RETURN = 'return' ![a-zA-Z0-9_] -- +META_BREAK = 'break' ![a-zA-Z0-9_] -- +META_CONTINUE = 'continue' ![a-zA-Z0-9_] -- +META_THROW = 'throw' ![a-zA-Z0-9_] -- +META_TRY = 'try' ![a-zA-Z0-9_] -- +META_CATCH = 'catch' ![a-zA-Z0-9_] -- +META_FINALLY = 'finally' ![a-zA-Z0-9_] -- +META_IMPORT = 'import' ![a-zA-Z0-9_] -- +META_HASH = '#' -- +META_LOGOR = '||' -- +META_LOGAND = '&&' -- +META_BITOR = '|' ![|=] -- +META_BITXOR = '^' ![=] -- +META_BITAND = '&' ![&=] -- +META_EQUAL = '==' -- +META_NOTEQ = '!=' -- +META_LESS = '<' ![<=] -- +META_LESSEQ = '<=' -- +META_GREATEREQ = '>=' -- +META_GREATER = '>' ![>=] -- +META_SHLEFT = '<<' ![=] -- +META_SHRIGHT = '>>' ![=] -- +META_PLUS = '+' ![+=] -- +META_MINUS = '-' ![-=] -- +META_NEGATE = '-' ![-=0-9.] -- +META_PLUSPLUS = '++' -- +META_MINUSMINUS = '--' -- +META_TILDE = '~' -- +META_PLING = '!' ![=] -- +META_MULTI = '*' ![=] -- +META_DIVIDE = '/' ![/=] -- +META_MODULO = '%' ![=] -- +META_ASSIGN = '=' ![=] -- +META_ASSIGNADD = '+=' -- +META_ASSIGNSUB = '-=' -- +META_ASSIGNMUL = '*=' -- +META_ASSIGNDIV = '/=' -- +META_ASSIGNMOD = '%=' -- +META_ASSIGNBITOR = '|=' -- +META_ASSIGNBITXOR = '^=' -- +META_ASSIGNBITAND = '&=' -- +META_ASSIGNSHLEFT = '<<=' -- +META_ASSIGNSHRIGHT = '>>=' -- +META_QUERY = '?' -- +META_COLON = ':' -- +META_SEMICOLON = ';' -- +META_COMMA = ',' -- +META_DOT = '.' -- +META_BACKTICK = '`' -- +META_AT = '@' -- +META_LCB = '{' -- +META_RCB = '}' -- +META_LBRAC = '[' -- +META_RBRAC = ']' -- +META_LPAREN = '(' -- +META_RPAREN = ')' -- META_DQUOTE = '"' META_SQUOTE = "'" #--------------------------------------------- Common rules ----------------------------------------------# -- = (blank | comment)* &{lang == META} - | < Space* > &{lang == C} { if (yyleng && $$) setComment($$, newComment(yytext)) } +-- = (blank | comment)* +- = < Space* > { if (yyleng && $$) setComment($$, newComment(yytext)) } #| C rules Space = Blank | Comment | EOL | Directive diff --git a/tests-parsimony/002.c b/tests-parsimony/002.c index b1a1abb..87ef222 100644 --- a/tests-parsimony/002.c +++ b/tests-parsimony/002.c @@ -1,15 +1,14 @@ @{ - saved = `initializer (1,2,"stringy thingy",21<<1); + saved = `initializer (1,2,"string",21<<1); cons = `constant 2; + two = `integer 2; } @(a = `constant 10) -char t = @(`constant 't'); +char t = @(`constant 't'); int i = @(cons); int q = @(`constant 10); int k = @(`initializer (1,2,"stringy thingy",21<<1)); - - int i = @(saved); int w = @(a); diff --git a/tests-parsimony/003.c b/tests-parsimony/003.c index 68ac570..ffb34a7 100644 --- a/tests-parsimony/003.c +++ b/tests-parsimony/003.c @@ -6,10 +6,8 @@ x = null; } - @{forLoop = `statement for (int i = 0; i < 10; ++i) printf("%d\n", i);;} - @{ if (useForLoop) { x = forLoop; @@ -18,13 +16,19 @@ } } - int main() { @(x); @(`statement for (int i = 0; i < @(nTimes); ++i) printf("%d\n", i);); + @{ + if (useForLoop) { + forLoop; + } else { + whileLoop; + } + }; @{ useForLoop = 0; if (useForLoop) { diff --git a/tests-parsimony/err_001.c b/tests-parsimony/err_001.c index e54c774..bf0fb1a 100644 --- a/tests-parsimony/err_001.c +++ b/tests-parsimony/err_001.c @@ -2,4 +2,4 @@ num = `integer 21; test = 2; `initializer @(num); -} +} \ No newline at end of file diff --git a/tests-parsimony/err_002.c b/tests-parsimony/err_002.c index 55b7ab6..bb4b4bd 100644 --- a/tests-parsimony/err_002.c +++ b/tests-parsimony/err_002.c @@ -1,6 +1,8 @@ @{ num = `integer 21; - test = `initializer 2 * @,num; + t = `initializer 2 * @(num); } -int x = @{`initializer 2 * @,num;}; \ No newline at end of file +int x = @{t;}; + +