@ -1343,6 +1343,9 @@ language printLang = C;
oop outputProgram= 0;
/// @brief Check if everyExternalDeclaration is define in parsimony and if so call it with the s parameter
/// @param s
/// @return Return the parameter s
oop everyExternalDeclaration(oop s)
{
oop eed = map_get(globals, intern("everyExternalDeclaration"));
@ -1352,11 +1355,14 @@ oop everyExternalDeclaration(oop s)
return s;
}
/// @brief Check if the object correspond to what is expected
/// @param id
/// @param s
/// @return Return the parameter s
oop ensure(int id, oop s)
{
if (is(Map, s)) {
oop protoSymbol = map_get(s, __proto___symbol);
// int protoNumber = get(map_get(map_get(s, __proto___symbol), __name___symbol), Symbol, prototype);
switch(id) {
case t_C_id: {
if (map_get(protoSymbol, __name___symbol) != map_get(C_id_proto, __name___symbol)) { // map_get for tree copy because __name__ : C_id != __name__ : C_id
@ -1374,6 +1380,9 @@ oop ensure(int id, oop s)
return s;
}
/// @brief Make a copy of the tree in input
/// @param obj
/// @return The copy of the object
oop clone(oop obj)
{
switch(getType(obj)) {
@ -1397,6 +1406,9 @@ oop clone(oop obj)
return obj;
}
/// @brief Make a deep copy of the tree in input
/// @param obj
/// @return The deep copy of the object
oop treeCopy(oop obj)
{
switch(getType(obj)) {
@ -1423,6 +1435,10 @@ oop treeCopy(oop obj)
return obj;
}
/// @brief Evaluate the remaining Parsimony code not evaluated
/// @param scope
/// @param obj
/// @return The same object with everything evaluated inside
oop treeCopyUnquoting(oop scope, oop obj)
{
switch(getType(obj)) {
@ -1498,9 +1514,6 @@ hexQuad = hexadecimalDigit hexadecimalDigit hexadecimalDigit hex
# constant rule
# constant = META_AT @{puts("-----------------------------------------")}
# < [a-zA-Z][a-zA-Z0-9]* >
# x:@{ printf("<%s>\n", yytext); exit(0) } { $$ = x }
constant = characterConstant
| floatingConstant
| integerConstant
@ -1598,10 +1611,11 @@ sCharSequence = ( escapeSequence | !EOL [^\"\\] )* #"
# primaryExpression rule
primaryExpression = stringLiteral | constant | id
| META_AT ( META_LCB mstmts
| mvalue
)
primaryExpression = META_AT ( META_LCB mstmts
#| < [a-zA-Z][a-zA-Z0-9]* > @{ printf("<%s>\n", yytext); exit(0) }
| mvalue
)
| stringLiteral | constant | id
| 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) }
@ -2312,6 +2326,7 @@ mvalue = ( i:META_IDENT { i= newGetVariable(i) } ( a:meta_argumentList {
)
| META_LPAREN ( i:meta_exp ) META_RPAREN
) { $$= eval(globals, i) }
#) { i = eval(globals, i); puts("mvalue-yylval");println(i);$$= i }
mstmts = ( s:eval_stmt )* META_RCB { $$= s } # return the last stmt
@ -3684,6 +3699,7 @@ void readEvalPrint(oop scope, char *fileName)
int jbt= sigsetjmp(jbs->jb, 0);
if (0 == jbt) {
while (yyparse(&ctx)) {
// println(yylval);
if (!yylval) { // EOF
assert(top == inputStack);
break;
@ -3774,19 +3790,37 @@ oop prim_parseFrom(oop scope, oop params)
if (!is(String, name)) return null;
char *s = get(name, String, value);
assert(inputStack);
struct _yycontext *yy = inputStack->yy;
if (!strcmp(s, "declaration" )) return yylval = yyparsefrom(yy, yy_declaration ) ? __ : null ;
else if (!strcmp(s, "expression" )) return yylval = yyparsefrom(yy, yy_expression ) ? __ : null ;
else if (!strcmp(s, "statement" )) return yylval = yyparsefrom(yy, yy_statement ) ? __ : null ;
else if (!strcmp(s, "id" )) return yylval = yyparsefrom(yy, yy_id ) ? __ : null ;
else if (!strcmp(s, "func" )) return yylval = yyparsefrom(yy, yy_functionDefinition) ? __ : null ;
else if (!strcmp(s, "error" )) return yylval = yyparsefrom(yy, yy_error) ? __ : null ;
struct _yycontext *zz = inputStack->yy;
struct _yycontext ctx, *yy = &ctx;
memcpy(&ctx, zz, sizeof(struct _yycontext));
yy->__thunkslen= YY_STACK_SIZE;
yy->__thunks= (yythunk *)YY_MALLOC(yy, sizeof(yythunk) * yy->__thunkslen);
yy->__valslen= YY_STACK_SIZE;
yy->__vals= (YYSTYPE *)YY_MALLOC(yy, sizeof(YYSTYPE) * yy->__valslen);
yy->__thunkpos= 0;
int res;
if (!strcmp(s, "declaration" )) res = yyparsefrom(yy, yy_declaration );
else if (!strcmp(s, "expression" )) res = yyparsefrom(yy, yy_expression );
else if (!strcmp(s, "statement" )) res = yyparsefrom(yy, yy_statement );
else if (!strcmp(s, "id" )) res = yyparsefrom(yy, yy_id );
else if (!strcmp(s, "func" )) res = yyparsefrom(yy, yy_functionDefinition);
else if (!strcmp(s, "error" )) res = yyparsefrom(yy, yy_error );
else {
fprintf(stderr, "parseFrom: %s not implemented", s);
exit(1);
}
printf("%s expected\n", s);
return null;
oop value;
if (res) {
value = __;
zz->__buf= yy->__buf;
zz->__buflen= yy->__buflen;
zz->__pos= yy->__pos;
zz->__limit= yy->__limit;
} else {
printf("%s expected\n", s);
value = null;
}
return value;
}
#include <sys/resource.h>
@ -3810,7 +3844,6 @@ void outputText(char *text)
void outputNode(oop node)
{
if (!node) return;
switch (getType(node)) {
case Undefined: