|
@ -5,6 +5,7 @@ |
|
|
# |
|
|
# |
|
|
# Last edited: 2022-09-30 16:23:05 by piumarta on zora-10.local |
|
|
# Last edited: 2022-09-30 16:23:05 by piumarta on zora-10.local |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
%{ |
|
|
%{ |
|
|
/* compile: leg -o ccmeta.c ccmeta.leg |
|
|
/* compile: leg -o ccmeta.c ccmeta.leg |
|
|
* cc -o ccmeta ccmeta.c -lgc -lm |
|
|
* cc -o ccmeta ccmeta.c -lgc -lm |
|
@ -29,7 +30,7 @@ |
|
|
_DO(PostDecVariable) _DO(PostDecMember) _DO(PostDecIndex) \ |
|
|
_DO(PostDecVariable) _DO(PostDecMember) _DO(PostDecIndex) \ |
|
|
_DO(GetVariable) _DO(GetMember) _DO(SetMember) _DO(GetIndex) _DO(SetIndex) \ |
|
|
_DO(GetVariable) _DO(GetMember) _DO(SetMember) _DO(GetIndex) _DO(SetIndex) \ |
|
|
_DO(Return) _DO(Break) _DO(Continue) _DO(Throw) _DO(Try) \ |
|
|
_DO(Return) _DO(Break) _DO(Continue) _DO(Throw) _DO(Try) \ |
|
|
/* _DO(Quasiquote) _DO(Unquote) */ \ |
|
|
|
|
|
|
|
|
_DO(Quote) /* _DO(Quasiquote) _DO(Unquote) */ \ |
|
|
DO_C_PROTOS() |
|
|
DO_C_PROTOS() |
|
|
|
|
|
|
|
|
#define META_PROTO_MAX t_Try |
|
|
#define META_PROTO_MAX t_Try |
|
@ -54,6 +55,7 @@ DO_PROTOS() |
|
|
#undef _DO |
|
|
#undef _DO |
|
|
} proto_t; |
|
|
} proto_t; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define SYMBOL_PAYLOAD proto_t prototype; |
|
|
#define SYMBOL_PAYLOAD proto_t prototype; |
|
|
#define DELTA 3 |
|
|
#define DELTA 3 |
|
|
|
|
|
|
|
@ -1347,6 +1349,7 @@ hexQuad = hexadecimalDigit hexadecimalDigit hexadecimalDigit hex |
|
|
constant = characterConstant |
|
|
constant = characterConstant |
|
|
| floatingConstant |
|
|
| floatingConstant |
|
|
| integerConstant |
|
|
| integerConstant |
|
|
|
|
|
#| META_AT m:meta_exp { $$ = m } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1443,8 +1446,11 @@ sCharSequence = ( escapeSequence | !EOL [^\"\\] )* |
|
|
# 6.5.1 |
|
|
# 6.5.1 |
|
|
|
|
|
|
|
|
primaryExpression = stringLiteral | constant | id |
|
|
primaryExpression = stringLiteral | constant | id |
|
|
| META_AT META_LPAREN x:mexp { $$ = eval(globals, x) } |
|
|
|
|
|
| l:LPAREN x:expression r:RPAREN { $$= new_C_subexpr(l, x, r) } |
|
|
|
|
|
|
|
|
| META_AT ( META_LCB x:mstmt |
|
|
|
|
|
| META_OPERATORS META_LPAREN x:mexp |
|
|
|
|
|
| META_LPAREN x:mexp |
|
|
|
|
|
) { $$ = 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) } |
|
|
| l:LPAREN x:compoundStatement r:RPAREN &{gnu} { $$= new_C_subexpr(l, x, r) } |
|
|
|
|
|
|
|
|
# 6.5.2 |
|
|
# 6.5.2 |
|
@ -1825,6 +1831,7 @@ typedefName = &{ isTypedefName(yytext) } { $$= new_C_id(yytext) } - |
|
|
|
|
|
|
|
|
initializer = l:LCURLY i:initializerList ( c:COMMA | {c=newNullObject()} ) r:RCURLY { $$= new_C_initializer(l, i, c, r) } |
|
|
initializer = l:LCURLY i:initializerList ( c:COMMA | {c=newNullObject()} ) r:RCURLY { $$= new_C_initializer(l, i, c, r) } |
|
|
| assignmentExpression |
|
|
| assignmentExpression |
|
|
|
|
|
| META_AT m:meta_exp { $$ = m } |
|
|
|
|
|
|
|
|
initializerList = { listBegin() } |
|
|
initializerList = { listBegin() } |
|
|
( d:designation { listAppend(d) } |
|
|
( d:designation { listAppend(d) } |
|
@ -1869,18 +1876,18 @@ labeledStatement = i:id c:COLON |
|
|
|
|
|
|
|
|
# 6.8.2 |
|
|
# 6.8.2 |
|
|
|
|
|
|
|
|
compoundStatement = @{ C_scopeBegin() } |
|
|
|
|
|
l:LCURLY { listBegin() } |
|
|
|
|
|
( x:localLabelDeclaration &{gnu} { listAppend(x) } |
|
|
|
|
|
|
|
|
compoundStatement = @{ C_scopeBegin() } |
|
|
|
|
|
l:LCURLY { listBegin() } |
|
|
|
|
|
( x:localLabelDeclaration &{gnu} { listAppend(x) } |
|
|
)* |
|
|
)* |
|
|
( x:declaration { listAppend(x) } |
|
|
|
|
|
| x:statement { listAppend(x) } |
|
|
|
|
|
| x:functionDefinition &{gnu} { listAppend(x) } |
|
|
|
|
|
|
|
|
( x:declaration { listAppend(x) } |
|
|
|
|
|
| x:statement { listAppend(x) } |
|
|
|
|
|
| x:functionDefinition &{gnu} { listAppend(x) } |
|
|
| !'}' &{ errmsg= "statement expected" } error |
|
|
| !'}' &{ errmsg= "statement expected" } error |
|
|
)* { x= listEnd() } |
|
|
|
|
|
r:RCURLY { $$= new_C_compound(l, x, r) } |
|
|
|
|
|
|
|
|
)* { x= listEnd() } |
|
|
|
|
|
r:RCURLY { $$= new_C_compound(l, x, r) } |
|
|
@{ C_scopeEnd() } |
|
|
@{ C_scopeEnd() } |
|
|
| &{ C_scopeAbort() } |
|
|
|
|
|
|
|
|
| &{ C_scopeAbort() } |
|
|
|
|
|
|
|
|
# 6.8.3 |
|
|
# 6.8.3 |
|
|
|
|
|
|
|
@ -2151,9 +2158,10 @@ _FLOAT128 = '_Float128' !IDREST &{gnu} { $$= newToken("_Float1 |
|
|
# the semicolon has to be explicit with no space eaten afterwards to prevent the |
|
|
# the semicolon has to be explicit with no space eaten afterwards to prevent the |
|
|
# input buffer from moving past it before redirecting input from the imported file |
|
|
# input buffer from moving past it before redirecting input from the imported file |
|
|
|
|
|
|
|
|
metaCatch = META_AT ( META_LPAREN m:mexp { $$ = m } |
|
|
|
|
|
| META_IMPORT s:META_STRING ";" { $$ = null; inputStackPush(get(s, String, value)) } |
|
|
|
|
|
| META_LCB { $$ = null; lang= META } |
|
|
|
|
|
|
|
|
metaCatch = META_AT ( META_OPERATORS META_LPAREN m:mexp { $$ = m } |
|
|
|
|
|
| META_LPAREN m:mexp { $$ = m } |
|
|
|
|
|
| META_IMPORT s:META_STRING ";" { $$ = null; inputStackPush(get(s, String, value)) } |
|
|
|
|
|
| META_LCB { $$ = null; lang= META } |
|
|
) |
|
|
) |
|
|
| &{ lang == META } - ( META_RCB { $$ = null; lang = C } |
|
|
| &{ lang == META } - ( META_RCB { $$ = null; lang = C } |
|
|
| s:meta_stmt { $$ = s } |
|
|
| s:meta_stmt { $$ = s } |
|
@ -2162,6 +2170,9 @@ metaCatch = META_AT ( META_LPAREN m:mexp { $$ = m } |
|
|
mexp = @{ lang = META } s:meta_exp META_RPAREN @{ lang = C } { $$= s } |
|
|
mexp = @{ lang = META } s:meta_exp META_RPAREN @{ lang = C } { $$= s } |
|
|
| @{ lang = C } &{ 0 } |
|
|
| @{ lang = C } &{ 0 } |
|
|
|
|
|
|
|
|
|
|
|
mstmt = @{ lang = META } s:meta_stmt META_RCB @{ lang = C } { $$= s } |
|
|
|
|
|
| @{ lang = C } &{ 0 } |
|
|
|
|
|
|
|
|
meta_stmt = s:meta_block { $$ = s } |
|
|
meta_stmt = s:meta_block { $$ = s } |
|
|
| META_SEMICOLON { $$ = null } |
|
|
| META_SEMICOLON { $$ = null } |
|
|
| l:META_IDENT p:meta_paramList e:meta_block { $$ = newFunc(l, p, e, null) } |
|
|
| l:META_IDENT p:meta_paramList e:meta_block { $$ = newFunc(l, p, e, null) } |
|
@ -2283,15 +2294,18 @@ meta_prod = l:meta_prefix |
|
|
| META_MODULO r:meta_prefix { l = newBinary(Mod_proto, l, r) } |
|
|
| META_MODULO r:meta_prefix { l = newBinary(Mod_proto, l, r) } |
|
|
)* { $$ = l } |
|
|
)* { $$ = l } |
|
|
|
|
|
|
|
|
meta_prefix = META_PLUS n:meta_prefix { $$= n } |
|
|
|
|
|
| META_NEGATE n:meta_prefix { $$= newUnary(Neg_proto, n) } |
|
|
|
|
|
| META_TILDE n:meta_prefix { $$= newUnary(Com_proto, 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 n:meta_prefix { $$ = newUnary(Quasiquote_proto, n) } |
|
|
|
|
|
# | META_AT n:meta_prefix { $$ = newUnary(Unquote_proto, n) } |
|
|
|
|
|
| n:meta_postfix { $$= n } |
|
|
|
|
|
|
|
|
meta_prefix = META_PLUS n:meta_prefix { $$= n } |
|
|
|
|
|
| META_NEGATE n:meta_prefix { $$= newUnary(Neg_proto, n) } |
|
|
|
|
|
| META_TILDE n:meta_prefix { $$= newUnary(Com_proto, 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 n:meta_prefix { $$ = newUnary(Quasiquote_proto, n) } |
|
|
|
|
|
# | META_AT n:meta_prefix { $$ = newUnary(Unquote_proto, n) } |
|
|
|
|
|
| n:meta_postfix { $$= n } |
|
|
|
|
|
|
|
|
meta_postfix = i:meta_value |
|
|
meta_postfix = i:meta_value |
|
|
( META_DOT s:META_IDENT a:meta_argumentList { i = newInvoke(i, s, a) } |
|
|
( META_DOT s:META_IDENT a:meta_argumentList { i = newInvoke(i, s, a) } |
|
@ -2318,8 +2332,7 @@ meta_argumentList = META_LPAREN m:meta_makeMap |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
meta_value = META_BACKTICK - m:meta2c_expr { $$ = m } |
|
|
|
|
|
| n:META_FLOAT { $$ = newFloat(n) } |
|
|
|
|
|
|
|
|
meta_value = n:META_FLOAT { $$ = newFloat(n) } |
|
|
| n:meta_integer { $$ = newInteger(n) } |
|
|
| n:meta_integer { $$ = newInteger(n) } |
|
|
| s:meta_string { $$ = newString(s) } |
|
|
| s:meta_string { $$ = newString(s) } |
|
|
| s:meta_symbol { $$ = s } |
|
|
| s:meta_symbol { $$ = s } |
|
@ -2329,21 +2342,6 @@ meta_value = META_BACKTICK - m:meta2c_expr { $$ |
|
|
| p:meta_paramList e:meta_block { $$ = newFunc(null, p, e, null) } |
|
|
| p:meta_paramList e:meta_block { $$ = newFunc(null, p, e, null) } |
|
|
| META_LPAREN ( i:meta_block | i:meta_exp ) META_RPAREN { $$ = i } |
|
|
| META_LPAREN ( i:meta_block | i:meta_exp ) META_RPAREN { $$ = i } |
|
|
|
|
|
|
|
|
meta2c_statement = m:meta2c_expr { $$ = m } |
|
|
|
|
|
| 'statement' { $$ = null } |
|
|
|
|
|
|
|
|
|
|
|
meta2c_expr = m:meta2c_constant { $$ = m } |
|
|
|
|
|
| 'expression' { $$ = null } |
|
|
|
|
|
|
|
|
|
|
|
meta2c_constant = 'constant' - m:meta2c_value { $$ = m } |
|
|
|
|
|
|
|
|
|
|
|
meta2c_value = m:meta_makeMap |
|
|
|
|
|
( < [0-9]+ > { map_set(m, intern("__proto__"), intern("C_int")) } { map_set(m, intern("text"), makeString(unescape(yytext))) } { $$ = newMap(m) } |
|
|
|
|
|
| s:meta2c_string { map_set(m, intern("__proto__"), intern("C_string")) } { map_set(m, intern("text"), s ) } { $$ = newMap(m) } |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
meta2c_string = META_DQUOTE < (!META_DQUOTE meta_char)* > META_DQUOTE {$$ = makeString(unescape(yytext)) } |
|
|
|
|
|
|
|
|
|
|
|
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)) } |
|
|
META_STRING = META_DQUOTE < (!META_DQUOTE meta_char)* > META_DQUOTE { $$ = makeString(unescape(yytext)) } |
|
@ -2391,6 +2389,17 @@ META_FLOAT = < [-+]* [0-9]+ '.' [0-9]* ('e'[-+]*[0-9]+)? > - { $$ = ma |
|
|
| < [-+]* [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)) } |
|
|
| < [-+]* [0-9]+ ('e'[-+]*[0-9]+) > - { $$ = makeFloat(strtold(yytext, 0)) } |
|
|
|
|
|
|
|
|
|
|
|
###### META operators ###### |
|
|
|
|
|
|
|
|
|
|
|
META_OPERATORS = META_INITIALIZER | META_CONSTANT | META_STATEMENT |
|
|
|
|
|
|
|
|
|
|
|
META_INITIALIZER = 'initializer' ![(a-zA-Z0-9_] - |
|
|
|
|
|
META_CONSTANT = 'constant' ![(a-zA-Z0-9_] - |
|
|
|
|
|
META_STATEMENT = 'statement' ![(a-zA-Z0-9_] - |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
############################ |
|
|
|
|
|
|
|
|
#META_FUN = 'fun' ![a-zA-Z0-9_] - |
|
|
#META_FUN = 'fun' ![a-zA-Z0-9_] - |
|
|
#META_SYNTAX = 'syntax' ![a-zA-Z0-9_] - |
|
|
#META_SYNTAX = 'syntax' ![a-zA-Z0-9_] - |
|
|
META_VAR = 'var' ![a-zA-Z0-9_] - |
|
|
META_VAR = 'var' ![a-zA-Z0-9_] - |
|
@ -2851,6 +2860,10 @@ oop eval(oop scope, oop ast) |
|
|
} |
|
|
} |
|
|
return map; |
|
|
return map; |
|
|
} |
|
|
} |
|
|
|
|
|
case t_Quote: { |
|
|
|
|
|
oop obj = map_get(ast, rhs_symbol); |
|
|
|
|
|
return obj; |
|
|
|
|
|
} |
|
|
#if 0 |
|
|
#if 0 |
|
|
case t_Quasiquote: { |
|
|
case t_Quasiquote: { |
|
|
oop obj = map_get(ast, rhs_symbol); |
|
|
oop obj = map_get(ast, rhs_symbol); |
|
@ -4554,6 +4567,9 @@ void outputTree(oop node, int depth) |
|
|
CASE(GetVariable) |
|
|
CASE(GetVariable) |
|
|
OUT(key) |
|
|
OUT(key) |
|
|
break; |
|
|
break; |
|
|
|
|
|
CASE(Quote) |
|
|
|
|
|
OUT(rhs); |
|
|
|
|
|
break; |
|
|
/** TODO |
|
|
/** TODO |
|
|
* CASE(Quasiquote) |
|
|
* CASE(Quasiquote) |
|
|
* PRINT(Quasiquote); |
|
|
* PRINT(Quasiquote); |
|
@ -4681,4 +4697,4 @@ int main(int argc, char **argv) |
|
|
|
|
|
|
|
|
// Local Variables: |
|
|
// Local Variables: |
|
|
// indent-tabs-mode: nil |
|
|
// indent-tabs-mode: nil |
|
|
// End: |
|
|
|
|
|
|
|
|
// End: |