Skip to content

Commit

Permalink
ADD: REPL function #1
Browse files Browse the repository at this point in the history
  • Loading branch information
anak10thn committed Mar 14, 2018
1 parent 5d64f0c commit 2223d82
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 96 deletions.
15 changes: 6 additions & 9 deletions src/baik_header.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------
//
// BAIK (Bahasa Anak Indonesia untuk Komputer) versi 8.15
//
// BAIK (Bahasa Anak Indonesia untuk Komputer) versi 8.15
// Object Oriented Programming Language
//
// BAIK ver.8.15 Ready for Professional Web, Desktop and Cloud Computing
Expand Down Expand Up @@ -81,10 +81,10 @@ extern DIR *owndir;

#include "val_label.h"

extern BAIK_LEX lex;
extern BAIK_ADDR pg;
extern BAIK_LEX lex;
extern BAIK_ADDR pg;

extern BAIK_ADDR tmp_pg;
extern BAIK_ADDR tmp_pg;

#include "baik_lexer.h"
#include "haris_node_struct.h"
Expand All @@ -101,13 +101,10 @@ extern BAIK_ADDR tmp_pg;
// ---------------------------------------------------------------------

void showBaikVersion() {
fprintf( stderr, "BAIK (Bahasa Anak Indonesia untuk Komputer) versi 8.15\n");
fprintf( stderr, "Dengan implementasi GPIO, OOP, DB, Anim, PDF dan UTF-8 \n");
fprintf( stderr, "uBAIK (Bahasa Anak Indonesia untuk Komputer) versi 8.15\n");
fprintf( stderr, "Copyright Haris Hasanudin 2005-2014\n\n");
fprintf( stderr, "cara pakai: baik [-v|-h ] <source file>\n");
fprintf( stderr, "-v : lihat versi\n" );
fprintf( stderr, "-h : lihat cara pakai\n" );
exit(0);
}


61 changes: 30 additions & 31 deletions src/interpreter.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extern int sub_deep;
extern int isLyrSub;
extern int isTimerSub;

extern int posSub[MAX_SUB_DEPTH];
extern int posSub[MAX_SUB_DEPTH];

extern VAL_LABEL get_Minus_Val(void);

Expand Down Expand Up @@ -545,12 +545,12 @@ void ReadSource( void )
getlex();

if( lex.type == _LONCATLABEL ){

getlex();

if( lex.type != TYPE_IDENT )
Error("Salah kalimat LONCATLABEL");

strcpy(tmpdat.ident, lex.detail.ident);
tmpdat.val = pg.pt;
ValLabel( lex.detail.ident, 0, tmpdat, VAL_FLAG_SEARCH_W );
Expand All @@ -565,12 +565,12 @@ void ReadSource( void )
memset(&sub_param, '\0', sizeof(sub_param));

getlex();

if( lex.type != TYPE_IDENT ) {
Error("kode SUB salah 0");
}

valdat.val = pg.pt;
valdat.val = pg.pt;
valdat.datatype = 9;

/* printf("sub name string: %s\n", lex.detail.string);
Expand All @@ -580,7 +580,7 @@ void ReadSource( void )
// printf("sub name: %s\n", sub_name);

getlex();


if( lex.type != TYPE_SYM || strncmp(lex.detail.string , "(", 1) != 0 ) {
Error("kode SUB salah : tanpa tanda (");
Expand All @@ -605,7 +605,7 @@ void ReadSource( void )
}

// printf("sub param: %s\n", sub_param);

getlex();
/* printf("sub { string: %s\n", lex.detail.string);
*/
Expand Down Expand Up @@ -641,12 +641,12 @@ void ReadSource( void )
memset(&obj_name, '\0', sizeof(obj_name));

getlex();

if( lex.type != TYPE_IDENT ) {
Error("kode DefinisiBenda salah");
}

objdat.val = pg.pt;
objdat.val = pg.pt;
objdat.datatype = 30; // Class Definition

strcpy(obj_name, lex.detail.string);
Expand Down Expand Up @@ -923,7 +923,7 @@ void ReadSource( void )
} // end if( lex.type == _DEF_BENDA ) {

}while( lex.type != _EOF );

memset( &lex, 0, sizeof(BAIK_LEX) );

memset(&tmpdat, '\0', sizeof(tmpdat));
Expand Down Expand Up @@ -1000,15 +1000,15 @@ void IncludeCodeReader( )
inc_tmp_source = (char *)malloc(strlen(pg.source)+1);
for(i=0; i<(int)strlen(pg.source); i++)
inc_tmp_source[i] = pg.source[i];
inc_tmp_source[i] = '\0';
inc_tmp_source[i] = '\0';

do{
getlex();

if( lex.type == _LONCATLABEL ) {

getlex();

if( lex.type != TYPE_IDENT ) {
Error("kode LONCATLABEL salah");
}
Expand Down Expand Up @@ -1092,14 +1092,14 @@ void IncludeCodeReader( )
if(pg.source != NULL) free (pg.source);
pg.source = (char *)malloc(strlen(allsrc)+1);
for(i=0; i<(int)strlen(allsrc); i++)
pg.source[i] = allsrc[i];
pg.source[i] = allsrc[i];
pg.source[i] = '\0';

if(allsrc != NULL)
free( allsrc );

if(inc_tmp_source != NULL)
free( inc_tmp_source );
free( inc_tmp_source );


//printf("&&&&&&&&&&&&&&&&&&&&&&\n");
Expand All @@ -1114,7 +1114,7 @@ void IncludeCodeReader( )
memset(&lineCode, '\0', sizeof(lineCode));
memset(&entireCode, '\0', sizeof(entireCode));


// printf("Include File finished ...\n");

}
Expand Down Expand Up @@ -1200,10 +1200,10 @@ void Interpreter( void )
case _MUSIK:
keyMusik();
break;
case _MUSIK_BGM:
keyMusikBGM();
break;
break;
case _JENDELA:
// Windows Only
Expand Down Expand Up @@ -1234,7 +1234,7 @@ void Interpreter( void )
}
returnVal.datatype = 3;
break;

case TYPE_NUM:
returnVal.val = lex.detail.num;
returnVal.datatype = 0;
Expand Down Expand Up @@ -1305,7 +1305,7 @@ void Interpreter( void )
else
Error("Salah kalimat Masuk");
break;

// # ############################ PILIH ###############################
case _PILIH:
keyPilih();
Expand All @@ -1321,7 +1321,7 @@ void Interpreter( void )
break;
// # ############################ -PILIH- ###############################

// # ############################ KALAU ################################
// # ############################ KALAU ################################
case _KALAU:
keyKalau();
// printf("after KALAU: curr result %d\n", currKalauResult[if_deep]);
Expand All @@ -1334,7 +1334,7 @@ void Interpreter( void )
} else {
do {
getlex();
}while( (lex.type != _STOPKALAU ) &&
}while( (lex.type != _STOPKALAU ) &&
lex.type != _EOF );
if( lex.type == _EOF )
Error("KALAU tanpa STOPKALAU");
Expand Down Expand Up @@ -1504,14 +1504,14 @@ void Interpreter( void )
//we need to initialize all these functions so that gtk knows
//to be thread-aware
#ifdef WIN32
if (!g_thread_supported()){
if (!g_thread_supported()){
g_thread_init(NULL);
}

gdk_threads_init();
gdk_threads_enter();
#endif

gtk_set_locale();

gtk_init(NULL, NULL);
Expand Down Expand Up @@ -2215,7 +2215,7 @@ void Interpreter( void )
// printf(" GLOBAL %s lex.type %d\n", ident, lex.type);
if( lex.type == TYPE_IDENT ){
memset(&tmpdat,'\0',sizeof(tmpdat));
tmpdat.scope = 2; // set to GLOBAL
tmpdat.scope = 2; // set to GLOBAL
ValLabel( ident , sub_deep, tmpdat, VAL_FLAG_SEARCH_W );
} else
if( lex.type == TYPE_ARRAY ){
Expand All @@ -2224,7 +2224,7 @@ void Interpreter( void )
getArrayName(lex.detail.array_str, (char *)&ident);

memset(&tmpdat,'\0',sizeof(tmpdat));
tmpdat.scope = 2; // set to GLOBAL
tmpdat.scope = 2; // set to GLOBAL
//printf(" GLOBAL %s scope %d\n", ident, tmpdat.scope);
ValLabel( ident , sub_deep, tmpdat, VAL_FLAG_SEARCH_W );
} else {
Expand Down Expand Up @@ -2288,7 +2288,7 @@ void Interpreter( void )

case _END:
lex.type = _EOF;
BaikGarbageCollection();
//BaikGarbageCollection();
break;

case TYPE_SYM:
Expand Down Expand Up @@ -2481,12 +2481,11 @@ void Interpreter( void )
default:
Error("Perintah tidak dimengerti: %s , nilai kode %d ", lex.detail.ident, lex.type);
break;

}

//memset(&tmpdat, '\0', sizeof(tmpdat));
//memset(&valdat, '\0', sizeof(valdat));


}

Loading

0 comments on commit 2223d82

Please sign in to comment.