TINY IDE

This section shows how you can make a simple IDE. We offer suggestions for development after the code on the next page.

These screenshots show error messages from TINY test programs running in the TINY IDE on the Pi. You can see the error messages in the memo below the editor. The cursor is positioned on the row of the error. All the errors are deliberate and intended to predict the type of syntax errors that you are likely to make after programming in Pascal. Remember that TINY does without "syntactic sugar" such as do and to keywords.

"TO" error message

"TO" error message from the TINY IDE

"DO" error message

"DO" error message from the TINY IDE

Note that "do" and "to" are not highlighted as keywords, making it possible to discover some errors as you type.

While TINY14PI allows you add semicolons to separate statements if you wish to, like many languages it uses = and does not accept := for assignment:

":" error message

":" error message from the TINY IDE

For a procedure without parameters, TINY requires an empty pair of brackets. If you forget them, this is your error message:

Testing "(" error message

"(" error message from the TINY IDE

When you compile the TINY_IDE in Lazarus you are advised to select menu item Run > Run Parameters then type the full pathname of the source file into the edit box marked "Command line parameters" e.g. /home/pi/TINY/Demo/PrimesDemo.txt. Alternatively, you can edit the appropriate line in TINY_IDE.lpi.

If you are not planning to develop the IDE, after you have compiled it in Lazarus run TINY_IDE from the command line with your instruction giving the full pathname of source such as TINY/TINY_IDE /home/pi/TINY/Demo/FactDemo.txt. (The output from the TINY program will appear in its own window if the compilation is successful). Thereafter you can browse to other source files and save to other locations. The assembler file and the binary ELF file will be saved to the same directory as the source. The source named myfile.xxx results in an assembly file named myfile.s and an ELF file named myfile.

You must append to some source files a read(DeclaredVariable) statement so that the console does not disappear after the program has been executed. To exit, enter an integer.

You can download a compressed file of the TINY_IDE executable.

Adapting the code of the TINY14PI compiler

  1. In order to direct straightforwardly the compiler error messages to the IDE we must delete the ReadLn statements from procedure Error in uErrors.pas.
  2. In order to output the approximate line number of the error we
    1. declare an integer variable LineCount initialised to 1 in uGlobals.pas
    2. increment LineCount when the linefeed character #10 is scanned in the source file (procedure getChar in uInput.pas);
    3. append the line count to the error message in procedure Error in uErrors.pas;
  3. We have positioned the output of .ltorg after calling procedures (procedure Call in uCodeGenPi.pas), but some programs work when it is emitted instead just before the final lines of each procedure (at the start of procedure ProcEpilog in uCodeGenPi.pas. Sometimes it is possible to prevent runtime errors by moving writeln statements in the source code of the TINY programs from within procedures to the main code.

Code of TINY_IDE.lpr

program TINY_IDE;

{$mode objfpc}{$H+}

uses
 {$IFDEF UseCThreads}
  cthreads,
 {$ENDIF}
  Interfaces, Forms, uEdit;

begin
  Application.Initialize;
  Application.CreateForm(TfrmEdit, frmEdit);
  Application.Run;
end.

Code of TINY_IDE.lpi

You can change the value of CommandLineParams to the pathname of your start-up source file.

<?xml version="1.0"?>
<CONFIG>
  <ProjectOptions>
    <Version Value="9"/>
    <General>
      <MainUnit Value="0"/>
      <ResourceType Value="res"/>
      <UseXPManifest Value="True"/>
      <Icon Value="0"/>
    </General>
    <i18n>
      <EnableI18N LFM="False"/>
    </i18n>
    <VersionInfo>
      <StringTable ProductVersion=""/>
    </VersionInfo>
    <BuildModes Count="1">
      <Item1 Name="Default" Default="True"/>
    </BuildModes>
    <RunParams>
      <local>
        <FormatVersion Value="1"/>
        <CommandLineParams Value="/home/pi/TINY/Demo/PrimesDemo.txt"/>
      </local>
    </RunParams>
    <RequiredPackages Count="3">
      <Item1>
        <PackageName Value="SynEdit"/>
      </Item1>
      <Item2>
        <PackageName Value="FCL"/>
      </Item2>
      <Item3>
        <PackageName Value="LCL"/>
      </Item3>
    </RequiredPackages>
    <Units Count="3">
      <Unit0>
        <Filename Value="TINY_IDE.lpr"/>
        <IsPartOfProject Value="True"/>
      </Unit0>
      <Unit1>
        <Filename Value="uEdit.pas"/>
        <IsPartOfProject Value="True"/>
        <ComponentName Value="frmEdit"/>
        <ResourceBaseClass Value="Form"/>
      </Unit1>
      <Unit2>
        <Filename Value="uEdit.lfm"/>
        <ComponentName Value="frmEdit"/>
        <HasResources Value="True"/>
        <ResourceBaseClass Value="Form"/>      
        <DefaultSyntaxHighlighter Value="LFM"/>
      </Unit2>
    </Units>
  </ProjectOptions>
  <CompilerOptions>
    <Version Value="9"/>
    <Target>
      <Filename Value="TINY_IDE"/>
    </Target>
    <SearchPaths>
      <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
    </SearchPaths>    
    <Other>
      <CompilerPath Value="$(CompPath)"/>
    </Other>
  </CompilerOptions>
</CONFIG>

See the code of uEdit.pas and the text view of frmEdit.lfm by following the links below.

Programming - a skill for life!

by PPS in association with Jack Crenshaw