Files
bds.fx2.prgc/src.prgc/grammar/prgParser.g
T
2026-01-03 18:57:08 +01:00

248 lines
6.5 KiB
Plaintext

unit prgParser;
// ----------------------------------------------------------------------------
// This section is used for generating "uses" clause in the unit 'prgParser'.
// Every unit name must be terminated with ';'
// e.g:
//
// uses
// {
// Classes;
// SysUtils;
// }
// ----------------------------------------------------------------------------
uses
{
Classes;
}
// ----------------------------------------------------------------------------
// This section is used for generating "const" clause in the unit 'prgParser'.
// The content of the section is verbatim copied into the generated code.
// ----------------------------------------------------------------------------
//const
//{
//}
// ----------------------------------------------------------------------------
// This section is used for generating "type" clause in the unit 'prgParser'.
// The content of the section is verbatim copied into the generated code.
// ----------------------------------------------------------------------------
type
{
TprgCommand =
(
cmdNone,
cmdList,
cmdListDSOs,
cmdListJTAGs,
cmdListFX2s,
cmdListDSO,
cmdListJTAG,
cmdProgramDSO,
cmdProgramJTAG,
cmdProgramFX2,
cmdProgramFX2Perm,
cmdEepromDump,
cmdEepromRead,
cmdEepromWrite
);
}
// ============================================================================
// Parser class declaration
// ============================================================================
parser TprgParser;
// ----------------------------------------------------------------------------
// Parser options
// ----------------------------------------------------------------------------
options
{
k = 2;
importVocab = prgLexer;
exportVocab = prgParser;
}
// ----------------------------------------------------------------------------
// Parser member declarations.
// All user defined member declarations should be placed here.
// The content of the section is verbatim copied into the generated code.
// ----------------------------------------------------------------------------
memberdecl
{
protected
fCommand : TprgCommand;
fDevice : string;
fFiles : TStringList;
fVerbose : string;
private
function GetFileCount: integer;
function GetFile( Idx: integer): string;
public
procedure AfterConstruction; override;
procedure BeforeDestruction; override;
public
property Command : TprgCommand read fCommand;
property Verbose : string read fVerbose;
property DeviceID : string read fDevice;
property FileCount : integer read GetFileCount;
property Files[i:integer] : string read GetFile;
}
// ============================================================================
// Begin rule definitions
//
// Remember: All parser rule names must begin with LOWERCASE letter!
// ============================================================================
prg
{
fCommand := cmdNone;
fVerbose := '';
fDevice := '';
}
: "/list"
{
fCommand := cmdList;
}
|
(
"fx2" (WS)?
(
"/list"
{
fCommand := cmdListFX2s;
}
| "/loc" COLON (x:INT | x:REXP) EQ prgfile
{
fCommand := cmdProgramFX2;
fDevice := x.TokenText;
}
(
"/perm"
{
fCommand := cmdProgramFX2Perm;
}
)?
)
)
|
(
"dso" { fCommand := cmdListDSOs; }
| "jtag" { fCommand := cmdListJTAGs; }
)
(WS)?
(
"/id"
COLON
x:ID { fDevice := x.TokenText; }
{
if fCommand = cmdListDSOs then fCommand := cmdListDSO;
if fCommand = cmdListJTAGs then fCommand := cmdListJTAG;
}
(WS)?
)?
(
"/list"
| EQ prgfile
{
if fCommand = cmdListDSO then fCommand := cmdProgramDSO;
if fCommand = cmdListJTAG then fCommand := cmdProgramJTAG;
}
(
v:"/v" { fVerbose := '0'; }
| v:"/v1" { fVerbose := '1'; }
)?
)
;
//prgfiles:
// (prgfile)+
// ;
prgfile
local
{
pos : AnsiString;
name : AnsiString;
}
{
pos := '0';
name := '';
}
: x:QID { name := x.TokenText; }
// SLASH "pos" COLON
// x:INT { pos := x.TokenText; }
{
fFiles.Add(pos+'='+name);
}
;
// ============================================================================
// End rule definitions
// ============================================================================
// ----------------------------------------------------------------------------
// This section is used for generating member defintions in the unit 'prgParser'.
// The content of the section is verbatim copied into the generated code.
// ----------------------------------------------------------------------------
memberdef
{
// ============================================================================
// After construction
// ============================================================================
procedure TprgParser.AfterConstruction;
begin
inherited;
fFiles := TStringList.Create
end;
// ============================================================================
// Before Destruction
// ============================================================================
procedure TprgParser.BeforeDestruction;
begin
fFiles.Free;
inherited
end;
// ============================================================================
// Get File Count
// ============================================================================
function TprgParser.GetFileCount: integer;
begin
result := fFiles.Count
end;
// ============================================================================
// Get File
// ============================================================================
function TprgParser.GetFile( Idx: integer): string;
var
i: integer;
p: integer;
begin
result := '';
for i:=0 to fFiles.Count -1 do
begin
p := StrToIntDef( fFiles.Names[i], -1);
if p = Idx then
begin
result := fFiles.ValueFromIndex[i];
break;
end
end;
end;
}