|
|
@ -104,8 +104,22 @@ jb_record *jbs= NULL; |
|
|
|
|
|
|
|
// this is the global scope |
|
|
|
oop globals= 0; |
|
|
|
|
|
|
|
oop program= 0; |
|
|
|
oop prop_enums= 0; |
|
|
|
|
|
|
|
oop prog_last= 0; |
|
|
|
|
|
|
|
oop prog_objects= 0; |
|
|
|
oop objects_elements= 0; |
|
|
|
oop objects_last= 0; |
|
|
|
|
|
|
|
oop prog_enums= 0; |
|
|
|
oop prog_structs= 0; |
|
|
|
oop prog_unions= 0; |
|
|
|
|
|
|
|
oop enum_last= 0; |
|
|
|
oop struct_last= 0; |
|
|
|
oop union_last= 0; |
|
|
|
|
|
|
|
#define DO_SYMBOLS() \ |
|
|
|
DO_PROTOS() _DO(__proto__) _DO(__name__) _DO(__default__) _DO(__arguments__) \ |
|
|
@ -844,6 +858,14 @@ oop new_C_structSpec(oop structTok, oop attributeSpecifier1, oop id, oop leftCur |
|
|
|
map_set(object, declarationL_symbol,declarationList); |
|
|
|
map_set(object, rightCurly_symbol, rightCurly); |
|
|
|
map_set(object, attribute2_symbol, attributeSpecifier2); |
|
|
|
if (strcmp(get(map_get(structTok, text_symbol), String, value), "union") == 0) { |
|
|
|
map_set(prog_unions, map_get(id, identifier_symbol), object); |
|
|
|
map_set(prog_unions, intern("last" ), object); |
|
|
|
} else { |
|
|
|
map_set(prog_structs, map_get(id, identifier_symbol), object); |
|
|
|
map_set(prog_structs, intern("last" ), object); |
|
|
|
} |
|
|
|
map_set(program, intern("last"), object); |
|
|
|
return object; |
|
|
|
} |
|
|
|
|
|
|
@ -863,8 +885,10 @@ oop new_C_enumSpec(oop enumTok, oop id, oop leftCurly, oop enumeratorList, oop r |
|
|
|
map_set(object, enumList_symbol, enumeratorList); |
|
|
|
map_set(object, rightCurly_symbol, rightCurly); |
|
|
|
if (id != null) { |
|
|
|
map_set(prop_enums, map_get(id, identifier_symbol), object); |
|
|
|
map_set(prog_enums, map_get(id, identifier_symbol), object); |
|
|
|
} |
|
|
|
map_set(prog_enums, intern("last"), object); |
|
|
|
map_set(program, intern("last"), object); |
|
|
|
return object; |
|
|
|
} |
|
|
|
|
|
|
@ -1606,7 +1630,7 @@ constantExpression = conditionalExpression |
|
|
|
|
|
|
|
# 6.7 |
|
|
|
|
|
|
|
declaration = @{ C_declarationBegin() } |
|
|
|
declaration = @{ C_declarationBegin() } |
|
|
|
( s:declarationSpecifiers |
|
|
|
d:initDeclaratorListOpt |
|
|
|
t:SEMI { $$= new_C_declaration(s, d, t) } |
|
|
@ -1616,7 +1640,7 @@ declaration = @{ C_declarationBegin() } |
|
|
|
|
|
|
|
declarationSpecifiers = @{ int specified= 0 } { listBegin() } |
|
|
|
( s:storageClassSpecifier { listAppend(s) } |
|
|
|
| s:typeSpecifier @{ specified++ } { listAppend(s) } |
|
|
|
| s:typeSpecifier @{ specified++ } { listAppend(s) } |
|
|
|
# Any list of specifiers and qualifiers at the start |
|
|
|
# of a declaration may contain attribute specifiers |
|
|
|
| s:attributeSpecifier &{gnu} { listAppend(s) } |
|
|
@ -1638,7 +1662,7 @@ initDeclarator = d:declarator |
|
|
|
|
|
|
|
# 6.7.1 |
|
|
|
|
|
|
|
storageClassSpecifier = TYPEDEF @{ declarationTypedef() } |
|
|
|
storageClassSpecifier = TYPEDEF @{ declarationTypedef() } |
|
|
|
| AUTO |
|
|
|
| parameterStorageClassSpecifier |
|
|
|
| functionStorageClassSpecifier |
|
|
@ -1930,9 +1954,9 @@ jumpStatement = g:GOTO i:id t:SEMI { $$= new_C_goto(g, |
|
|
|
## translationUnit = externalDeclaration+ |
|
|
|
|
|
|
|
externalDeclaration = <Space+> { $$= newComment(yytext); } |
|
|
|
| ( SEMI &{gnu} |
|
|
|
| ( SEMI &{gnu} |
|
|
|
| declaration |
|
|
|
| functionDefinition |
|
|
|
| functionDefinition |
|
|
|
| &. &{ errmsg= "declaration expected" } error |
|
|
|
) |
|
|
|
|
|
|
@ -2165,21 +2189,17 @@ _FLOAT128 = '_Float128' !IDREST &{gnu} { $$= newToken("_Float128" |
|
|
|
# input buffer from moving past it before redirecting input from the imported file |
|
|
|
|
|
|
|
metaCatch = META_AT ( META_IMPORT s:META_STRING ";" { inputStackPush(get(s, String, value)) ; $$= 0 } |
|
|
|
| m:mvalue { $$= m } |
|
|
|
| m:mvalue { map_append(outputProgram, m); $$= null } |
|
|
|
| META_LCB s:mstmts { map_append(outputProgram, s); $$= null } |
|
|
|
) |
|
|
|
|
|
|
|
mvalue = i:META_IDENT { i= newGetVariable(i) } |
|
|
|
( a:meta_argumentList { i = (null != getSyntax(1, i)) ? apply(globals, globals, getSyntax(1, i), a, i) : newCall(i, a) } )? |
|
|
|
{ $$= eval(globals, i)} |
|
|
|
| META_LPAREN ( i:MO_OPERATION |
|
|
|
| i:meta_exp |
|
|
|
) META_RPAREN { $$= eval(globals, i) } |
|
|
|
mvalue = ( i:META_IDENT { i= newGetVariable(i) } |
|
|
|
( a:meta_argumentList { i = (null != getSyntax(1, i)) ? apply(globals, globals, getSyntax(1, i), a, i) : newCall(i, a) } )? |
|
|
|
| META_LPAREN ( i:meta_exp ) META_RPAREN |
|
|
|
) { $$= eval(globals, i) } |
|
|
|
|
|
|
|
|
|
|
|
mstmts = ( s:eval_stmt )* ( META_NIL META_SEMICOLON META_RCB { $$= null } |
|
|
|
| META_RCB { $$= s } |
|
|
|
) |
|
|
|
mstmts = ( s:eval_stmt )* META_RCB { $$= s } |
|
|
|
|
|
|
|
eval_stmt = s:meta_stmt { $$= eval(globals, s) } |
|
|
|
|
|
|
@ -2213,6 +2233,7 @@ meta_exp = META_VAR l:meta_ident META_ASSIGN e:meta_exp |
|
|
|
# | META_SYNTAX p:meta_paramList q:META_IDENT e:meta_block { $$= (map_append(p, q), newFunc(null, p, e, makeInteger(2))) } |
|
|
|
# | META_SYNTAX l:META_IDENT p:meta_paramList e:meta_block { $$= newFunc(l, p, e, makeInteger(1)) } |
|
|
|
# | META_SYNTAX p:meta_paramList e:meta_block { $$= newFunc(null, p, e, makeInteger(1)) } |
|
|
|
| m:MO_OPERATION { $$= m } |
|
|
|
| l:META_IDENT o:meta_assignOp e:meta_exp { $$= newAssign(Assign_proto, l, o, e) } |
|
|
|
| l:meta_postfix META_DOT i:META_IDENT o:meta_assignOp e:meta_exp { $$= newSetMap(SetMember_proto, l, i, o, e) } |
|
|
|
| l:meta_postfix META_LBRAC i:meta_exp META_RBRAC o:meta_assignOp e:meta_exp { $$= newSetMap(SetIndex_proto, l, i, o, e) } |
|
|
@ -2308,7 +2329,6 @@ 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) } |
|
|
|
| m:MO_OPERATION { $$= m } |
|
|
|
# | META_BACKTICK n:meta_prefix { $$= newUnary(Quasiquote_proto, n) } |
|
|
|
# | META_AT n:meta_prefix { $$= newUnary(Unquote_proto, n) } |
|
|
|
| n:meta_postfix { $$= n } |
|
|
@ -2404,6 +2424,8 @@ MO_OPERATION = META_BACKTICK ( MO_INITIALIZER i:initializer { $$= newUn |
|
|
|
| MO_INTEGER i:integerConstant { $$= newUnary(Quote_proto ,i) } |
|
|
|
| MO_DECLARATION i:declaration { $$= newUnary(Quote_proto ,i) } |
|
|
|
| MO_STRING i:stringLiteral { $$= newUnary(Quote_proto ,i) } |
|
|
|
| MO_FUN i:functionDefinition { $$= newUnary(Quote_proto ,i) } |
|
|
|
| MO_ED i:externalDeclaration{ $$= newUnary(Quote_proto ,i) } |
|
|
|
) |
|
|
|
|
|
|
|
MO_INITIALIZER = 'initializer' ![(a-zA-Z0-9_] -- |
|
|
@ -2412,6 +2434,8 @@ MO_STATEMENT = 'statement' ![(a-zA-Z0-9_] -- |
|
|
|
MO_INTEGER = 'integer' ![(a-zA-Z0-9_] -- |
|
|
|
MO_DECLARATION = 'declaration' ![(a-zA-Z0-9_] -- |
|
|
|
MO_STRING = 'string' ![(a-zA-Z0-9_] -- |
|
|
|
MO_FUN = 'fun' ![(a-zA-Z0-9_] -- |
|
|
|
MO_ED = 'ed' ![(a-zA-Z0-9_] -- |
|
|
|
|
|
|
|
|
|
|
|
#--------------------------------------------- Meta rules ----------------------------------------------# |
|
|
@ -2429,7 +2453,7 @@ 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_NULL = ('null'|'nil') ![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_] -- |
|
|
@ -3453,6 +3477,15 @@ oop prim_keys(oop scope, oop params) |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
oop prim_all_keys(oop scope, oop params) |
|
|
|
{ |
|
|
|
if (map_hasIntegerKey(params, 0)) { |
|
|
|
oop arg= get(params, Map, elements)[0].value; |
|
|
|
if (is(Map, arg)) return map_allKeys(arg); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
oop prim_values(oop scope, oop params) |
|
|
|
{ |
|
|
|
if (map_hasIntegerKey(params, 0)) { |
|
|
@ -3504,7 +3537,7 @@ oop prim_print(oop scope, oop params) |
|
|
|
} |
|
|
|
return params; |
|
|
|
} |
|
|
|
|
|
|
|
//TRY |
|
|
|
oop evalArgs(oop scope, oop args) |
|
|
|
{ |
|
|
|
int i = 0; |
|
|
@ -4634,6 +4667,7 @@ int main(int argc, char **argv) |
|
|
|
|
|
|
|
map_set(globals, intern("exit" ), makeFunction(prim_exit, intern("exit" ), null, null, globals, null)); |
|
|
|
map_set(globals, intern("keys" ), makeFunction(prim_keys, intern("keys" ), null, null, globals, null)); |
|
|
|
map_set(globals, intern("allKeys" ), makeFunction(prim_all_keys, intern("allKeys" ), null, null, globals, null)); |
|
|
|
map_set(globals, intern("values" ), makeFunction(prim_values, intern("values" ), null, null, globals, null)); |
|
|
|
map_set(globals, intern("length" ), makeFunction(prim_length, intern("length" ), null, null, globals, null)); |
|
|
|
map_set(globals, intern("print" ), makeFunction(prim_print, intern("print" ), null, null, globals, null)); |
|
|
@ -4644,7 +4678,7 @@ int main(int argc, char **argv) |
|
|
|
map_set(globals, intern("microseconds"), makeFunction(prim_microseconds, intern("microseconds"), null, null, globals, null)); |
|
|
|
map_set(globals, intern("string" ), makeFunction(prim_String , intern("string" ), null, null, globals, null)); |
|
|
|
|
|
|
|
map_set(globals, intern("scope"), makeFunction(prim_scope, intern("scope"), null, null, globals, null)); |
|
|
|
map_set(globals, intern("scope" ), makeFunction(prim_scope, intern("scope" ), null, null, globals, null)); |
|
|
|
|
|
|
|
#define _DO(NAME) NAME##_symbol=intern(#NAME); |
|
|
|
DO_SYMBOLS() |
|
|
@ -4668,10 +4702,28 @@ int main(int argc, char **argv) |
|
|
|
DO_PROTOS() |
|
|
|
#undef _DO |
|
|
|
|
|
|
|
program = makeMap(); |
|
|
|
prop_enums = makeMap(); |
|
|
|
map_set(program, intern("enums"), prop_enums); |
|
|
|
map_set(globals, intern("program"), program); |
|
|
|
program = makeMap(); |
|
|
|
prog_enums = makeMap(); |
|
|
|
prog_structs = makeMap(); |
|
|
|
prog_unions = makeMap(); |
|
|
|
prog_last = makeMap(); |
|
|
|
enum_last = makeMap(); |
|
|
|
struct_last = makeMap(); |
|
|
|
union_last = makeMap(); |
|
|
|
prog_objects = makeMap(); |
|
|
|
objects_elements = makeMap(); |
|
|
|
objects_last = makeMap(); |
|
|
|
|
|
|
|
map_set(prog_enums , intern("last" ), enum_last ); |
|
|
|
map_set(prog_structs , intern("last" ), struct_last ); |
|
|
|
map_set(prog_unions , intern("last" ), union_last ); |
|
|
|
map_set(prog_objects , intern("elements" ), objects_elements ); |
|
|
|
map_set(prog_objects , intern("last" ), objects_last ); |
|
|
|
map_set(program , intern("structs" ), prog_structs ); |
|
|
|
map_set(program , intern("unions" ), prog_unions ); |
|
|
|
map_set(program , intern("enums" ), prog_enums ); |
|
|
|
map_set(program , intern("objects" ), prog_objects ); |
|
|
|
map_set(globals , intern("program" ), program ); |
|
|
|
|
|
|
|
fixScope(globals); |
|
|
|
|
|
|
|