[Mono-list] some older MonoLogo code notes

George Birbilis birbilis@kagi.com
Mon, 7 Mar 2005 22:26:46 +0200


Sometime ago I took a look at MonoLOGO and also sent some e-mails to its
creator regarding enhancing it etc., but never got an answer. It seems
abandonned.

Nevertheless I'm senting some notes I kept while trying to build it, since
I'm going to throw away those files from my PC and the notes might be useful
to somebody in the future:

see //Birb in the code below

* console/console-gtk.cs (didn't make to build that I think):

 public ConsoleGtk ()
  {
   Window win = new Window ("MonoLOGO");
   //win.DeleteEvent += new EventHandler(Window_Delete); //Birb: commented
out
   win.BorderWidth = 4;
   win.DefaultSize = new Gdk.Size (450, 300); //Birb: added "Gdk."

   VBox vbox = new VBox (false, 4);
   win.Add (vbox); //Birb: changed from "EmitAdd"

   ...

   swin.Add (text); //Birb: changed from "swin.EmitAdd"

   Entry entry = new Entry ();
   entry.Activated += new EventHandler (Entry_Activate); //Birb: changed
"Activate" to "Activated"
   vbox.PackStart (entry, false, false, 0);

* console/console.cs:

namespace Mono.Languages.Logo
{
 using Mono.Languages.Logo.Compiler; //Birb: changed from "Mono.LOGO.Lib"
 using Mono.Languages.Logo.Runtime; //Birb: changed from "Mono.LOGO.Lib"
 using System;
 using System.IO;

 public abstract class LogoConsole
 {
  InstructionList stack = new InstructionList (); //Birb: changed from
"LogoStack"
  Parser parser = new Parser (); //Birb: changed from "LogoParser"
  Interpreter interpreter; //Birb: added

  IMessageStoreCollection funcs; //Birb: added
  LogoMessageTarget lmt; //Birb: added

  private void LoadFuncs ()  //Birb: added
  {
   if (interpreter==null){
    funcs = new IMessageStoreCollection ();
    funcs.Add (new CTSMessageTarget (typeof (Funcs)));
    lmt = new LogoMessageTarget ();
    funcs.Add (lmt);
    interpreter = new Interpreter(funcs);
   }
  }

  ...

  public void InputCommand (string cmd)
  {
   //int ret = -1; //Birb: removed
   object ret; //Birb: added

   Console.WriteLine ("? " + cmd);
   InstructionList tree; //Birb: added
   tree = parser.Parse (cmd); //Birb: changed from "ParseString" and added
assingment to tree variable
   if (tree != null) //Birb: changed from "parser.Tree"
   {
    try
    {
     LoadFuncs ();
     ret = interpreter.Execute (tree/*stack*/); //Birb: changed from
"parser.Tree.Eval"
    }
    catch (Exception e)
    {
     Console.WriteLine (e.Message);
    }
   }
   else
    Console.WriteLine ("parse error");
   stack.Clear ();
  }
 }
}

* console/textwriter-gtk.cs:

  public override void Write (string value)
  {
   buf.Insert (buf.EndIter, value/*, value.Length*/); //Birb: removed last
part
  }

* Tokenizer.cs:

 public class Tokenizer {

  ...

  private static bool IsNewline (char c) {
   return (c == '\n') || (c == '\r'); //Birb: added support for CRLF, not
just LF
  }

 ...

  private static bool IsNumber (string str, out double num) {
   num = 0;

   if (str.Length == 1 && IsInfix (str[0]))
    return false;

   try {
    num = Double.Parse (str);
    return true;
   } catch (Exception /*e*/) { //Birb: removed "e"
    return false;
   }
  }

 ...

  private Token TokenForChar (int c_prev_int, int c_peek_int, char c) {
   if (c == '-') {
    TokenType type;
    if (c_prev_int == -1)
     type = TokenType.Minus;
    else if (c_peek_int == -1)
     type = TokenType.Infix;
    else {
     char c_prev = (char) c_prev_int;
     char c_peek = (char) c_peek_int;
     if (IsNumber (c_peek) || IsSymbolStart (c_peek) || c_peek == '(') {
      if (c_prev == ')')
       type = TokenType.Infix;
      else
       type = TokenType.Minus;
     } else {
      type = TokenType.Infix;
     }
    }
    return new Token (type, c);
   } else if (c == '(')
    return new Token (TokenType.OpenParens, c);
   else if (c == ')')
    return new Token (TokenType.CloseParens, c);
   else if (c == '[')
    return new Token (TokenType.OpenBracket, c);
   else if (c == ']')
    return new Token (TokenType.CloseBracket, c);
   else if (IsNewline(c)) //Birb: changed from [c == '\n'] to add support
for CRLF instead of just LF
    return new Token (TokenType.Newline, c);
   else if (IsInfix (c))
    return new Token (TokenType.Infix, c);
   else if (allow_question_mark && c == '?')
    return new Token (TokenType.QuestionMark, c);
   else
    throw new Exception ("Unexpected input: " + c);
  }

regarding the 1st three files, I've never programmed Gtk+ so I might be
totally wrong, but I just couldn't compile the files from the CVS at all so
tried to fix them as I thought best. At the Tokenizer.cs, a change removes
some unused variable warning (make an exception unnamed instead of named
one) and added CRLF support too apart from LF one for newlines in parsed
content

cheers,
George

P.S. for the project I had I finally resulted in writing my own Logo
tokenizer, parser and (meta)compiler to RemObjects PascalScript. Was/Is an
interesting excercise, but would rather have merged MonoLogo and
TurtleTracks Logo functionality instead as was my original intent...

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
George Birbilis <birbilis@kagi.com>
Microsoft MVP J# for 2004, 2005
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ QuickTime controls (Delphi & ActiveX: VB, PowerPoint, .NET)
+ Plugs (InterProcess/Internet communication)
+ TranXform (VB6 form to ASP.net WebForm convertion)
http://www.kagi.com/birbilis
+ Robotics
http://www.mech.upatras.gr/~robgroup
........................................................................