Close

First star on the right, then straight on 'till Morning.

A project log for Computer Motivator

If you don't know what a computer motivator is by now, then you have been reading too many textbooks and not watching enough TV.

glgormanglgorman 10/07/2021 at 03:560 Comments

O.K., UCSD p-system Pascal in now compiling under Visual Studio to the point that I can load a Pascal file in a Microsoft MFC CEditView derived class, and then attempt to compile it, even though I only have about 2500 or so lines converted so far, i.e., mostly by using find and replace in a word processor and then manually fixing the VAR statements and the WITH statements.  Had to write my own versions of BLOCKREAD, IDSEARCH, and TREESEARCH, among other things; as these were nowhere to be found in the UCSD distribution.  TREESEARCH I already had, in my bTreeType class, but my earlier version uses recursion, so I redid that one.  IDSEARCH is the one that is going to be more interesting, since the whole concept of checking to see whether a token is on a list of keywords and then calling an appropriate function is also something that I am doing with Rubidium.  Thus the Pascal version looks like this:

#include "stdafx.h"
#include "afxmt.h"
#include <iostream>
#include "../Frame Lisp/defines.h"
#include "../Frame Lisp/symbol_table.h"
#include "../Frame Lisp/btreetype.h"
#include "../Frame Lisp/node_list.h"
#include "../Frame Lisp/text_object.h"
#include "../Frame Lisp/scripts.h"
#include "../Frame Lisp/frames.h"
#include "../Frame Lisp/frames1.h"
#include "../Frame Lisp/extras.h"
#include "compiler.h"

namespace SEARCH
{
    char *keywords[] = 
    {
        "DO","WITH","IN","TO","GOTO","SET","DOWNTO","LABEL",
        "PACKED","END","CONST","ARRAY","UNTIL","TYPE","RECORD",
        "OF","VAR","FILE","THEN","PROCSY","PROCEDURE","USES",
        "ELSE","FUNCTION","UNIT","BEGIN","PROGRAM","INTERFACE",
        "IF","SEGMENT","IMPLEMENTATION","CASE","FORWARD","EXTERNAL",
        "REPEAT","NOT","OTHERWISE","WHILE","AND","DIV","MOD",
        "FOR","OR",
    };
    frame m_pFrame;
    symbol_table *m_keywords;
    void RESET_SYMBOLS();
    void IDSEARCH(int &pos, char *&str);
};

void SEARCH::RESET_SYMBOLS()
{
    frame &f = SEARCH::m_pFrame;
    symbol_table *t=NULL;
    t = f.cons(keywords)->sort();
     m_keywords = t;
}

void SEARCH::IDSEARCH(int &pos, char *&str)
{
    char buf[32];
    SEARCH::RESET_SYMBOLS();
    symbol_table &T = *SEARCH::m_keywords;
    size_t i, len, sz;
    sz = T.size();
    token *t;
    pos = -1;
    for (i=0;i<sz;i++)
    {
        t = &T[(int)i];
        len = strlen(t->ascii);
        memcpy(buf,str,len);
        buf[len]=0;
        if (strcmp(buf,t->ascii)==0)
        {
            pos=(int)i;
//            PASCALCOMPILER::SY;
//            PASCALCOMPILER::OP;
//            PASCALCOMPILER::ID;
            break;
        }
    }
}

Now as it turns out, on the Apple II, we are told that this function was actually implemented in 6502 assembly; which is why it is not in the UCSD distribution.  What it does of course, is check to see whether the symbols that are extracted by INSYMBOL are in the list of Pascal keywords, and then modify a bunch of ordinal values, enumerated types or whatever in the global variable space; which is exactly what I need to do, but don't want to do in Rubidium; with respect to not wanting to use global variables, that is.  That would be TOO simple.  Even if this should turn out to be a refactoring job from hell, the payoff in the end will be well worth it - once I have clean C code that can be complied, or transmogrified or whatever to also run on the Propeller, or the Pi, or an Arduino, etc., such as by trans-compiling C to Forth, or C to SPIN, or C to Propeller assembly (PASM) or perhaps a mixture of all three.  Oh, and let's not forget about LISP.

Discussions