Menu

#1 grammere debugging code

open
nobody
None
5
2003-05-31
2003-05-31
No

Interested in adding a few features.
1) automatic generation of messages for
entering production
checking production
found production
exiting production
2) check boxes to turn generation of these on & off
3) properties in parser to turn message printing on & off

Putting the ProductionCheck in is not redundant with
the ProductionStart because (it looks like) some tokens
are checked without going into the production.
I am currently (Lord help me) manually putting these
into the the semantic actions for each and every line:

Production1 =
(. ProductionStart( 'Production1'); .)
( (. ProductionCheck( 'Production2'); .)
Production2
(. ProductionFound('Production2'); .)
) |
( (. ProductionCheck( 'Production3'); .)
Production3
(. ProductionFound('Production3'); .)
)
(. ProductionEnd; .)
.
Ad Naueseum
I know it's only 4 lines of code to fix this. I even
know the four lines that are required (12 to 16 with
IDE support for turning on&off). I just am not
familiar enough with the project to know where to put
them.

I've also fat-finger automated the production of a
file that parallels -->grammermoduleG.pas. I take the
token IDs and wrap them as strings, putting them in an
array so that I can print out the string associated
with the expected token when I don't get it.
There is Property support given below for turning
that on and off, as well as for printing the token
input string and name string (from array above) in
PerformGet:

if PrintTokens then WriteStr( GetLexString + ' '
+GetNextString + ' ' + SymbolText[sym]);

Where GetLexString and GetNextString just made
functions out of existing procedures.

In Expect:

if PrintExpected then ProductionComment('Expect:
'+SymbolText[n] + ' Got: ' + SymbolText[sym]);

Hope this isn't too wordy.
Thanks

The actual message printing procedures & support:
---------------------------------------------------------------------------------
fPrintChecks : boolean;
fPrintFound : boolean;
fPrintProds : boolean;
fIndent : boolean;
fPrintTkns : boolean;
fPrintXpctd : boolean;
fStrLst : TStringList;
fProdStack : TStringList;
fLevel : integer;
--------------------------------------------------------------------------------
procedure ProductionStart( str : string );
procedure ProductionComment( str : string );
procedure ProductionCheck( str : string );
procedure ProductionFound( str : string );
procedure ProductionEnd;
--------------------------------------------------------------------------------
Property PrintChecks : boolean read fPrintChecks
write fPrintChecks;
Property PrintFound : boolean read fPrintFound
write fPrintFound ;
Property PrintProds : boolean read fPrintProds
write fPrintProds ;
Property PrintIndent : boolean read fIndent
write fIndent ;
Property PrintTokens : boolean read fPrintTkns
write fPrintTkns ;
Property PrintExpected: boolean read fPrintXpctd
write fPrintXpctd ;
--------------------------------------------------------------------------------
Procedure T-->modulenameParser.ProductionStart( str :
string );
Begin
if fProdStack.Capacity <= fLevel then
fProdStack.Capacity := fLevel * 2;
while fLevel >= fProdStack.Count do
fProdStack.Add('' );
fProdStack[fLevel] := str;
if PrintProds then ProductionComment(
fProdStack[fLevel] + ' -->' );
inc(fLevel);
End;

Procedure T-->modulenameParser.ProductionComment( str :
string );
var
s : string;
i : integer;
Begin
s := '' ;
if PrintIndent then i := fLevel else i := 0;
while i > 25 do
begin
s := s+' ' ;
dec(i,25);
end;
while i > 5 do
begin
s := s+' ' ;
dec(i, 5);
end;
while i > 0 do
begin
s := s+' ' ;
dec(i);
end;
s := s + str;
WriteStr(s);
End;

Procedure T-->modulenameParser.ProductionCheck( str :
string );
begin
if PrintChecks then ProductionComment( 'in ' +
fProdStack[fLevel-1] + ' checking ' +str);
end;

Procedure T-->modulenameParser.ProductionFound( str :
string );
begin
if PrintFound then ProductionComment('in ' +
fProdStack[fLevel-1] + ' found ' + str);
end;

Procedure T-->modulenameParser.ProductionEnd;
Begin
dec(fLevel);
if PrintProds then ProductionComment(
fProdStack[fLevel] + ' <--' );
Application.ProcessMessages;
End;
--------------------------------------------------------------------------------

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.