Changeset 6


Ignore:
Timestamp:
Nov 9, 2009, 8:59:48 AM (15 years ago)
Author:
george
Message:
  • Upraveno: Testování nyní prováděno přes oknovou aplikaci.
  • Přidáno: Podpora pro zobrazení řádku chyby.
Location:
branches/Void
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • branches/Void

    • Property svn:ignore
      •  

        old new  
        66project1.exe
        77*.dsk
         8*.~dsk
  • branches/Void/Example.void

    r5 r6  
     1Define Text
    12Define Text
    23Write Leave me
    34Write Heal the world
    45Assign Text Hell
     6Assign Texts Hell
    57Pause
  • branches/Void/UCompilator.pas

    r5 r6  
    99
    1010type
    11   TOnErrorEvent = procedure (Text: string; var Terminate: Boolean) of object;
     11  TOnErrorEvent = procedure (Text: string; var Terminate: Boolean; Position: TPoint) of object;
    1212
    1313  TVariable = class
     
    2525    Variables: TList;
    2626    Commands: TList;
     27    ParsePosition: TPoint;
    2728    procedure DoError(Text: string);
    2829    function FindVariableByName(AName: string): TVariable;
    2930  public
     31    SourceCode: TStringList;
    3032    Output: TStringList;
    31     procedure Compile(FileName: string);
     33    procedure Compile;
     34    procedure Clear;
    3235    procedure ProcessLine(Line: string);
    3336    constructor Create;
     
    4649begin
    4750  Terminate := False;
    48   if Assigned(FOnError) then FOnError(Text, Terminate);
     51  if Assigned(FOnError) then FOnError(Text, Terminate, ParsePosition);
    4952  if Terminate then raise Exception.Create('Compilation terminated');
    5053end;
     
    6063end;
    6164
    62 procedure TCompilator.Compile(FileName: string);
     65procedure TCompilator.Compile;
    6366var
    64   SourceCode: TStringList;
    6567  I: Integer;
    6668begin
    67   SourceCode := TStringList.Create;
    68   SourceCode.LoadFromFile(FileName);
     69  Clear;
    6970
    7071  // Process source lines
    7172  for I := 0 to SourceCode.Count - 1 do begin
     73    ParsePosition.Y := I;
    7274    ProcessLine(SourceCode[I]);
    7375  end;
     
    7577  // Prepare output
    7678  Output.Clear;
    77   Output.Add('program ' + ExtractFileName(FileName) + ';');
     79  Output.Add('program Test;');
    7880  Output.Add('{$APPTYPE CONSOLE}');
    7981
     
    9092      Output.Add(Text);
    9193  Output.Add('end.');
    92   Output.SaveToFile(ExtractFileName(FileName) + '.dpr');
    93   SourceCode.Destroy;
     94end;
     95
     96procedure TCompilator.Clear;
     97var
     98  I: Integer;
     99begin
     100  for I := 0 to Variables.Count - 1 do
     101    TVariable(Variables[I]).Destroy;
     102  Variables.Clear;
     103  for I := 0 to Commands.Count - 1 do
     104    TCommand(Commands[I]).Destroy;
     105  Commands.Clear;
     106  Output.Clear;
    94107end;
    95108
     
    99112  Variable: TVariable;
    100113  VariableName: string;
    101   begin
     114begin
    102115  Command := Parse(Line);
    103   WriteLn(Command);
    104116  if Command = 'Write' then
    105117  with TCommand(Commands[Commands.Add(TCommand.Create)]) do begin
     
    128140  end else if Command = 'Exit' then with TCommand(Commands[Commands.Add(TCommand.Create)]) do begin
    129141    Text := 'Exit;';
    130   end else DoError('Unknown command: ' + Command);
     142  end else DoError('Unknown command ' + Command);
    131143end;
    132144
    133145constructor TCompilator.Create;
    134146begin
     147  SourceCode := TStringList.Create;
    135148  Output := TStringList.Create;
    136149  Variables := TList.Create;
     
    149162    TCommand(Commands[I]).Destroy;
    150163  Commands.Destroy;
     164  SourceCode.Destroy;
    151165  inherited Destroy;
    152166end;
  • branches/Void/project1.lpi

    r5 r6  
    55    <Version Value="7"/>
    66    <General>
    7       <Flags>
    8         <MainUnitHasCreateFormStatements Value="False"/>
    9         <MainUnitHasTitleStatement Value="False"/>
    10       </Flags>
    117      <MainUnit Value="0"/>
    128      <TargetFileExt Value=".exe"/>
    139      <Icon Value="0"/>
    1410      <UseXPManifest Value="True"/>
    15       <ActiveEditorIndexAtStart Value="1"/>
     11      <ActiveEditorIndexAtStart Value="0"/>
    1612    </General>
    1713    <VersionInfo>
     
    3228      </local>
    3329    </RunParams>
    34     <Units Count="4">
     30    <RequiredPackages Count="1">
     31      <Item1>
     32        <PackageName Value="LCL"/>
     33      </Item1>
     34    </RequiredPackages>
     35    <Units Count="3">
    3536      <Unit0>
    3637        <Filename Value="project1.lpr"/>
    3738        <IsPartOfProject Value="True"/>
    3839        <UnitName Value="project1"/>
    39         <CursorPos X="3" Y="45"/>
    40         <TopLine Value="26"/>
    41         <EditorIndex Value="0"/>
    42         <UsageCount Value="25"/>
    43         <Loaded Value="True"/>
     40        <UsageCount Value="20"/>
    4441      </Unit0>
    4542      <Unit1>
    46         <Filename Value="UCompilator.pas"/>
     43        <Filename Value="UMainForm.pas"/>
    4744        <IsPartOfProject Value="True"/>
    48         <UnitName Value="UCompilator"/>
    49         <CursorPos X="58" Y="124"/>
    50         <TopLine Value="103"/>
    51         <EditorIndex Value="1"/>
    52         <UsageCount Value="25"/>
     45        <ComponentName Value="MainForm"/>
     46        <ResourceBaseClass Value="Form"/>
     47        <UnitName Value="UMainForm"/>
     48        <CursorPos X="23" Y="81"/>
     49        <TopLine Value="57"/>
     50        <EditorIndex Value="0"/>
     51        <UsageCount Value="20"/>
    5352        <Loaded Value="True"/>
    5453      </Unit1>
    5554      <Unit2>
    56         <Filename Value="Example.void"/>
    57         <IsPartOfProject Value="True"/>
    58         <CursorPos X="24" Y="4"/>
    59         <TopLine Value="1"/>
    60         <EditorIndex Value="2"/>
    61         <UsageCount Value="25"/>
     55        <Filename Value="UCompilator.pas"/>
     56        <UnitName Value="UCompilator"/>
     57        <CursorPos X="26" Y="73"/>
     58        <TopLine Value="41"/>
     59        <EditorIndex Value="1"/>
     60        <UsageCount Value="10"/>
    6261        <Loaded Value="True"/>
    63         <SyntaxHighlighter Value="None"/>
    6462      </Unit2>
    65       <Unit3>
    66         <Filename Value="Notices.txt"/>
    67         <IsPartOfProject Value="True"/>
    68         <CursorPos X="3" Y="1"/>
    69         <TopLine Value="1"/>
    70         <EditorIndex Value="3"/>
    71         <UsageCount Value="24"/>
    72         <Loaded Value="True"/>
    73         <SyntaxHighlighter Value="None"/>
    74       </Unit3>
    7563    </Units>
    7664    <JumpHistory Count="30" HistoryIndex="29">
    7765      <Position1>
    78         <Filename Value="UCompilator.pas"/>
    79         <Caret Line="51" Column="68" TopLine="36"/>
     66        <Filename Value="UMainForm.pas"/>
     67        <Caret Line="42" Column="9" TopLine="28"/>
    8068      </Position1>
    8169      <Position2>
    82         <Filename Value="UCompilator.pas"/>
    83         <Caret Line="52" Column="52" TopLine="37"/>
     70        <Filename Value="UMainForm.pas"/>
     71        <Caret Line="12" Column="1" TopLine="9"/>
    8472      </Position2>
    8573      <Position3>
    86         <Filename Value="UCompilator.pas"/>
    87         <Caret Line="20" Column="24" TopLine="9"/>
     74        <Filename Value="UMainForm.pas"/>
     75        <Caret Line="3" Column="14" TopLine="1"/>
    8876      </Position3>
    8977      <Position4>
    90         <Filename Value="UCompilator.pas"/>
    91         <Caret Line="57" Column="41" TopLine="42"/>
     78        <Filename Value="UMainForm.pas"/>
     79        <Caret Line="40" Column="8" TopLine="25"/>
    9280      </Position4>
    9381      <Position5>
    9482        <Filename Value="UCompilator.pas"/>
    95         <Caret Line="85" Column="1" TopLine="55"/>
     83        <Caret Line="31" Column="23" TopLine="16"/>
    9684      </Position5>
    9785      <Position6>
    98         <Filename Value="project1.lpr"/>
    99         <Caret Line="38" Column="5" TopLine="36"/>
     86        <Filename Value="UCompilator.pas"/>
     87        <Caret Line="89" Column="1" TopLine="62"/>
    10088      </Position6>
    10189      <Position7>
    10290        <Filename Value="UCompilator.pas"/>
    103         <Caret Line="28" Column="34" TopLine="10"/>
     91        <Caret Line="32" Column="23" TopLine="9"/>
    10492      </Position7>
    10593      <Position8>
    10694        <Filename Value="UCompilator.pas"/>
    107         <Caret Line="86" Column="21" TopLine="70"/>
     95        <Caret Line="63" Column="30" TopLine="48"/>
    10896      </Position8>
    10997      <Position9>
    11098        <Filename Value="UCompilator.pas"/>
    111         <Caret Line="11" Column="30" TopLine="3"/>
     99        <Caret Line="74" Column="24" TopLine="59"/>
    112100      </Position9>
    113101      <Position10>
    114         <Filename Value="UCompilator.pas"/>
    115         <Caret Line="24" Column="59" TopLine="10"/>
     102        <Filename Value="UMainForm.pas"/>
     103        <Caret Line="40" Column="8" TopLine="25"/>
    116104      </Position10>
    117105      <Position11>
    118         <Filename Value="UCompilator.pas"/>
    119         <Caret Line="41" Column="35" TopLine="39"/>
     106        <Filename Value="UMainForm.pas"/>
     107        <Caret Line="41" Column="9" TopLine="25"/>
    120108      </Position11>
    121109      <Position12>
    122110        <Filename Value="UCompilator.pas"/>
    123         <Caret Line="81" Column="9" TopLine="52"/>
     111        <Caret Line="141" Column="23" TopLine="128"/>
    124112      </Position12>
    125113      <Position13>
    126114        <Filename Value="UCompilator.pas"/>
    127         <Caret Line="24" Column="35" TopLine="9"/>
     115        <Caret Line="97" Column="11" TopLine="83"/>
    128116      </Position13>
    129117      <Position14>
    130         <Filename Value="UCompilator.pas"/>
    131         <Caret Line="44" Column="57" TopLine="60"/>
     118        <Filename Value="UMainForm.pas"/>
     119        <Caret Line="46" Column="1" TopLine="28"/>
    132120      </Position14>
    133121      <Position15>
    134         <Filename Value="UCompilator.pas"/>
    135         <Caret Line="25" Column="1" TopLine="13"/>
     122        <Filename Value="UMainForm.pas"/>
     123        <Caret Line="45" Column="1" TopLine="27"/>
    136124      </Position15>
    137125      <Position16>
    138         <Filename Value="UCompilator.pas"/>
    139         <Caret Line="48" Column="55" TopLine="48"/>
     126        <Filename Value="UMainForm.pas"/>
     127        <Caret Line="39" Column="10" TopLine="27"/>
    140128      </Position16>
    141129      <Position17>
    142         <Filename Value="UCompilator.pas"/>
    143         <Caret Line="89" Column="22" TopLine="70"/>
     130        <Filename Value="UMainForm.pas"/>
     131        <Caret Line="44" Column="10" TopLine="31"/>
    144132      </Position17>
    145133      <Position18>
    146         <Filename Value="UCompilator.pas"/>
    147         <Caret Line="19" Column="9" TopLine="1"/>
     134        <Filename Value="UMainForm.pas"/>
     135        <Caret Line="45" Column="42" TopLine="25"/>
    148136      </Position18>
    149137      <Position19>
    150         <Filename Value="UCompilator.pas"/>
    151         <Caret Line="89" Column="22" TopLine="74"/>
     138        <Filename Value="UMainForm.pas"/>
     139        <Caret Line="48" Column="1" TopLine="22"/>
    152140      </Position19>
    153141      <Position20>
    154         <Filename Value="UCompilator.pas"/>
    155         <Caret Line="100" Column="24" TopLine="88"/>
     142        <Filename Value="UMainForm.pas"/>
     143        <Caret Line="54" Column="1" TopLine="40"/>
    156144      </Position20>
    157145      <Position21>
    158         <Filename Value="UCompilator.pas"/>
    159         <Caret Line="114" Column="23" TopLine="99"/>
     146        <Filename Value="UMainForm.pas"/>
     147        <Caret Line="49" Column="1" TopLine="52"/>
    160148      </Position21>
    161149      <Position22>
    162         <Filename Value="project1.lpr"/>
    163         <Caret Line="18" Column="15" TopLine="1"/>
     150        <Filename Value="UMainForm.pas"/>
     151        <Caret Line="85" Column="1" TopLine="55"/>
    164152      </Position22>
    165153      <Position23>
    166         <Filename Value="project1.lpr"/>
    167         <Caret Line="48" Column="52" TopLine="45"/>
     154        <Filename Value="UMainForm.pas"/>
     155        <Caret Line="59" Column="14" TopLine="44"/>
    168156      </Position23>
    169157      <Position24>
    170         <Filename Value="project1.lpr"/>
    171         <Caret Line="44" Column="7" TopLine="30"/>
     158        <Filename Value="UMainForm.pas"/>
     159        <Caret Line="48" Column="24" TopLine="40"/>
    172160      </Position24>
    173161      <Position25>
    174         <Filename Value="project1.lpr"/>
    175         <Caret Line="1" Column="5" TopLine="1"/>
     162        <Filename Value="UCompilator.pas"/>
     163        <Caret Line="35" Column="21" TopLine="17"/>
    176164      </Position25>
    177165      <Position26>
    178         <Filename Value="project1.lpr"/>
    179         <Caret Line="40" Column="27" TopLine="26"/>
     166        <Filename Value="UCompilator.pas"/>
     167        <Caret Line="72" Column="19" TopLine="59"/>
    180168      </Position26>
    181169      <Position27>
    182         <Filename Value="project1.lpr"/>
    183         <Caret Line="18" Column="49" TopLine="1"/>
     170        <Filename Value="UCompilator.pas"/>
     171        <Caret Line="27" Column="27" TopLine="15"/>
    184172      </Position27>
    185173      <Position28>
    186         <Filename Value="project1.lpr"/>
    187         <Caret Line="51" Column="58" TopLine="50"/>
     174        <Filename Value="UCompilator.pas"/>
     175        <Caret Line="51" Column="69" TopLine="36"/>
    188176      </Position28>
    189177      <Position29>
    190         <Filename Value="project1.lpr"/>
    191         <Caret Line="41" Column="16" TopLine="26"/>
     178        <Filename Value="UMainForm.pas"/>
     179        <Caret Line="76" Column="3" TopLine="55"/>
    192180      </Position29>
    193181      <Position30>
    194         <Filename Value="UCompilator.pas"/>
    195         <Caret Line="11" Column="77" TopLine="1"/>
     182        <Filename Value="UMainForm.pas"/>
     183        <Caret Line="80" Column="61" TopLine="57"/>
    196184      </Position30>
    197185    </JumpHistory>
     
    207195      <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
    208196    </SearchPaths>
     197    <Linking>
     198      <Options>
     199        <Win32>
     200          <GraphicApplication Value="True"/>
     201        </Win32>
     202      </Options>
     203    </Linking>
    209204    <Other>
    210205      <CompilerPath Value="$(CompPath)"/>
  • branches/Void/project1.lpr

    r5 r6  
    11program project1;
    22
    3 {$mode Delphi}{$H+}
     3{$mode objfpc}{$H+}
    44
    55uses
     
    77  cthreads,
    88  {$ENDIF}{$ENDIF}
    9   Classes, SysUtils, CustApp, UCompilator;
    10 
    11 type
    12 
    13   { TApplication }
    14 
    15   TApplication = class(TCustomApplication)
    16   protected
    17     procedure DoRun; override;
    18     procedure CompilatorError(Text: string; var Terminate: Boolean);
    19   public
    20     Compilator: TCompilator;
    21     constructor Create(TheOwner: TComponent); override;
    22     destructor Destroy; override;
    23   end;
    24 
    25 { TApplication }
    26 
    27 procedure TApplication.DoRun;
    28 var
    29   ErrorMsg: String;
    30 begin
    31   // quick check parameters
    32   ErrorMsg := CheckOptions('h', 'help');
    33   if ErrorMsg <> '' then begin
    34     ShowException(Exception.Create(ErrorMsg));
    35     Terminate;
    36     Exit;
    37   end;
    38 
    39   Compilator := TCompilator.Create;
    40   with Compilator do begin
    41     OnError := CompilatorError;
    42     Compile('Example.void');
    43     Destroy;
    44   end;
    45   ReadLn;
    46 
    47   // stop program loop
    48   Terminate;
    49 end;
    50 
    51 procedure TApplication.CompilatorError(Text: string; var Terminate: Boolean);
    52 begin
    53   Terminate := False;
    54   WriteLn('Error: ' + Text);
    55 end;
    56 
    57 constructor TApplication.Create(TheOwner: TComponent);
    58 begin
    59   inherited Create(TheOwner);
    60   StopOnException := True;
    61 
    62   end;
    63 
    64 destructor TApplication.Destroy;
    65 begin
    66   inherited Destroy;
    67 end;
    68 
    69 var
    70   Application: TApplication;
     9  Interfaces, // this includes the LCL widgetset
     10  Forms, UMainForm, LResources
     11  { you can add units after this };
    7112
    7213{$IFDEF WINDOWS}{$R project1.rc}{$ENDIF}
    7314
    7415begin
    75   Application := TApplication.Create(nil);
    76   Application.Title := 'Application';
     16  {$I project1.lrs}
     17  Application.Initialize;
     18  Application.CreateForm(TMainForm, MainForm);
    7719  Application.Run;
    78   Application.Free;
    7920end.
    8021
Note: See TracChangeset for help on using the changeset viewer.