File tree Expand file tree Collapse file tree
FAST.FBasic.InteractiveConsole
FAST.FBasic.LibraryToolkit/Core Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -90,6 +90,8 @@ private void setupEnvironment()
9090 env . AddLibrary ( new FBasicJsonLibrary ( ) ) ;
9191 env . AddLibrary ( new FBasicTemplatingLibrary ( ) ) ;
9292 env . AddLibrary ( new FBasicAIChat ( ) ) ;
93+ env . AddLibrary ( new FBasicLanguageExtensions ( ) ) ;
94+
9395 env . AddVariable ( "table.column" , "myColumn1" ) ;
9496
9597 FBasicEvents . Reset ( ) ;
Original file line number Diff line number Diff line change 1+ REM Test program for EVAL statements
2+ REM Category: Flow Control
3+ REM
4+ RESULT 5
5+
6+ let code ="
7+ print RESULTVALUE
8+ let X=10
9+ print X
10+ "
11+
12+ eval code
13+ let X =X +1
14+ print " X=" +X
15+
16+
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ public static bool IsStatement(Token token)
3535 case Token . Dump :
3636 case Token . Call :
3737 case Token . Chain :
38+ case Token . Eval :
3839 case Token . ForEach :
3940 case Token . EndForEach :
4041 case Token . SData :
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ public enum Token
3030 Dump ,
3131 Call ,
3232 Chain ,
33+ Eval ,
3334 ForEach ,
3435 EndForEach ,
3536 SData ,
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ void Statement()
3131 case Token . Dump : DumpStatement ( ) ; break ;
3232 case Token . Call : CallStatement ( ) ; break ;
3333 case Token . Chain : ChainStatement ( ) ; break ;
34+ case Token . Eval : EvalStatement ( ) ; break ;
3435 case Token . ForEach : ForEachStatement ( ) ; break ;
3536 case Token . EndForEach : EndForEachStatement ( ) ; break ;
3637 case Token . SData : SDataStatement ( ) ; break ;
Original file line number Diff line number Diff line change @@ -138,6 +138,34 @@ void ChainStatement()
138138 return ;
139139 }
140140
141+ /// <summary>
142+ /// EVAL
143+ /// </summary>
144+ void EvalStatement ( )
145+ {
146+ // (v) load the chain source program
147+ string srcCode = Expr ( ) . ToString ( ) ;
148+
149+ // (v) save the current program state
150+ var oldState = this . GetState ( ) ;
151+
152+ //// (v) Set the new chain program and execute it
153+ lex . SetSource ( srcCode ) ;
154+ exit = false ;
155+ GetNextToken ( ) ;
156+ while ( ! exit ) Line ( ) ; // do all lines
157+ exit = false ;
158+
159+ // (v) restore the old program state
160+ this . SetState ( oldState ) ;
161+
162+ // (v) continue with the next instruction
163+
164+ return ;
165+ }
166+
167+
168+
141169 /// <summary>
142170 /// HALT | END
143171 /// </summary>
Original file line number Diff line number Diff line change @@ -168,6 +168,7 @@ public Token GetToken()
168168 case "RETURN" : return Token . Return ;
169169 case "CALL" : return Token . Call ;
170170 case "CHAIN" : return Token . Chain ;
171+ case "EVAL" : return Token . Eval ;
171172 case "FOREACH" : return Token . ForEach ;
172173 case "ENDFOREACH" : return Token . EndForEach ;
173174
Original file line number Diff line number Diff line change 1+ //
2+ // Language Extensions Statements:
3+ //
4+ //
5+
6+ using System . Text ;
7+
8+ namespace FAST . FBasicInterpreter
9+ {
10+ public class FBasicLanguageExtensions : IFBasicLibraryWithMemory , IDisposable
11+ {
12+ private IInterpreter inter ;
13+
14+ public string uniqueName => "FBasicLanguageExtensions" ;
15+
16+ public FBasicLanguageExtensions ( )
17+ {
18+ //IFBasicFileManagementLayer fileManager=new zzzzzzz();
19+ //this.fileManager=fileManager;
20+ }
21+
22+ public void InstallAll ( IInterpreter interpreter )
23+ {
24+ this . inter = interpreter ;
25+
26+ interpreter . AddStatement ( "EVAL" , EVAL ) ;
27+
28+ }
29+
30+ private static void EVAL ( IInterpreter interpreter )
31+ {
32+ // Syntax: EVAL value|variable
33+ //
34+ string code = interpreter . ValueOrVariable ( true ) . String ;
35+ interpreter . GetNextToken ( ) ;
36+
37+
38+ }
39+
40+ public void ClearMemory ( )
41+ {
42+ var variables = inter . GetVariables ( ) ;
43+ foreach ( var variable in variables )
44+ {
45+ if ( variable . Value . Type != ValueType . Object ) continue ;
46+
47+ if ( variable . Value . Object is Stream )
48+ {
49+ var stream = ( ( Stream ) variable . Value . Object ) ;
50+ stream . Flush ( ) ;
51+ stream . Close ( ) ;
52+ stream . Dispose ( ) ;
53+ stream = null ;
54+ }
55+ }
56+ }
57+
58+ public void Dispose ( )
59+ {
60+ ClearMemory ( ) ;
61+ }
62+ }
63+
64+ }
You can’t perform that action at this time.
0 commit comments