previous next contentsExampleSkipExcl =
{ ('%%' | any); !c#1; }
-> SOURCETEXT.
ExampleSkipIncl =
c:= 2;
{!c#1; ('%%' | any) }
-> SOURCETEXT.
ExampleSkipExcl stops in front of the keyword, ExampleSkipIncl skips
the keyword, too.ExampleSkipExcl =
{ ('REPEAT' $ | ident | any); !c#1; }
-> SOURCETEXT.
Otherwards it would be possible that the parser stops already on something like NOREPEAT.
A call to Skip in front of large alternative may also speed up the parser if it is likely
to have to skip many characters at this point.
Skip() before entering the respective rule.
idcp = ident -> SOURCETEXT.
withhd = idcp -> idcp_.
withouthd = Skip(); idcp -> idcp_.
Then withhd will translate " alfa" into
" alfa",
while withouthd produces just "alfa".
IMPORTS Dp4Streams, Dp4Chars, Dp4DocFiles;
ExampleTwoPasses =
ExampleFirstPass;
(* write 1st target of ExampleFirstPass on file: *)
Dp4Streams.Tar2Strm(ExampleFirstPass_, Dp4DocFiles.New("Temp1File"));
(* make this file the source for further processing: *)
From(Dp4DocFiles.IFile("Temp1File"));
ExampleSecndPass;
-> ExampleSecndPass_.
ExampleFirstPass = ident -> ident_ '1st'.
ExampleSecndPass = ident -> '2nd Pass:' ident_.
ident4root.
Test your productions by putting their name in front of the source.TestRoot=
GLOBVAR DCL globvar1, globvar2,....; (* declarations *)
globvar1:= ... (* initializations - if needed *)
ident4root (* calls the wanted production *)
-> ident4root_ . (* gives the result *)
Lets say, you want to test your rule MyExpr, then select TestRoot as root and write as source
MyExpr a+(B*Pi)/128
and the result will be quite similar to selecting MyExpr as root in a simple grammar
without global variables.
Instead of
one should better use
('keyword1' $ ... |'keyword2' $ ... |'keyword3' $... )
This avoids touching the source repeatedly. ident
(!ident_0='keyword1'...|!ident_0='keyword2'...|!ident_0='keyword3'...)
(Do not expect too much. More often than not this tuning will not result in sensible speed-ups. If there is
realy a big number of keywords, i.e. >20...40, and the selection is touched really frequently, one should
think about using an importet hash table. Thus, replace the second line by
(/My.hash(Ident_0)/ ...|...|...) )
One can achieve a nominal speed-up by placing a Skip() in front of alternatives.
But be careful, this may interfer with suppression of skipping (<...> constructs).
line terminal.
makeComment = { line[i] }
-> {'// ' line_[i] }.
This rule describes a translation which converts any text in a C++ comment format.
Dp4Tools.translate
is possible too.
previous next contents