summaryrefslogtreecommitdiff
path: root/parser.c
diff options
context:
space:
mode:
Diffstat (limited to 'parser.c')
-rw-r--r--parser.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/parser.c b/parser.c
index 6f2ce2d..63c865b 100644
--- a/parser.c
+++ b/parser.c
@@ -37,17 +37,17 @@ static char hexencode(int n){
}
static bool semicolon_needed_after(const AST *after){
- DBGF("semicolon_needed_after(type %d) -> ",after->type);
+ //DBGF("semicolon_needed_after(type %d) -> ",after->type);
switch(after->type){
case AST_BLOCK:
case AST_IF:
case AST_WHILE:
case AST_FUNC:
- DBGF("false\n");
+ //DBGF("false\n");
return false;
default:
- DBGF("true\n");
+ //DBGF("true\n");
return true;
}
}
@@ -720,7 +720,8 @@ static void ast_debug_(FILE *stream,const AST *ast,int indent){
for(int i=0;i<ast->b.len;i++){
INDENT
ast_debug_(stream,ast->b.exprs[i],indent);
- fprintf(stream,";\n");
+ if(semicolon_needed_after(ast->b.exprs[i]))fputc(';',stream);
+ fputc('\n',stream);
}
indent--;
INDENT
@@ -771,19 +772,15 @@ static void ast_debug_(FILE *stream,const AST *ast,int indent){
case AST_IF:
fprintf(stream,"if ");
ast_debug_(stream,ast->i.cond,indent);
- fputc('\n',stream);
- indent++;
- INDENT
+ fputc(' ',stream);
ast_debug_(stream,ast->i.thenb,indent);
- indent--;
+ if(semicolon_needed_after(ast->i.thenb))fputc(';',stream);
if(ast->i.elseb){
fputc('\n',stream);
INDENT
- fprintf(stream,"else\n");
- indent++;
- INDENT
+ fprintf(stream,"else ");
ast_debug_(stream,ast->i.elseb,indent);
- indent--;
+ if(semicolon_needed_after(ast->i.elseb))fputc(';',stream);
}
break;
@@ -794,7 +791,7 @@ static void ast_debug_(FILE *stream,const AST *ast,int indent){
case AST_FUNC:
fprintf(stream,"def %s(",ast->f.name);
for(int j=0;j<ast->f.nargs;j++){
- if(j!=0)fputc(',',stream);
+ if(j!=0)fprintf(stream,", ");
fprintf(stream,"%s",ast->f.args[j]);
}
fprintf(stream,") ");