8.2 SubpatternRewriting
87
SubpatternRewriting
-
replace
-
modify
-
f
RewriteStatement
-
g
-
The subpattern rewriting specications s within the e subpattern declaration looks s like e a
nestedrewritingspecication,butadditionallytheremayberewriteparametersgiveninthe
subpatternheader(cf.8.1)whichcanbereferencedintherewritebody. (Mostelementscan
behandedinwithnormalparameters,butelementscreatedintherewritepartoftheuser
ofthesubpatterncanonlybehandedinatrewritetime.)
SubpatternRewriteApplication
-
Ident
-
(
-
Ident
,
-
)
-
;
-
SubpatternOccurence
-
SubpatternExecEmit
-
The SubpatternRewriteApplication n is s partofthe RewriteStatement t already y introduced(cf.
5.4.3). Thesubpatternrewrite e applicationis givenwithintherewrite part ofthe pattern
containing the subpattern entity declaration, , in n call notation on the e declared d subpattern
identier. Itcauses s therewrite partofthesubpatterntogetused;ifyouleaveitout,the
subpattern is s simply y kept t untouched. . The e SubpatternOccurence e is s explained d in the next
subsection8.2.1.TheSubpatternExecEmit isexplainedinchapter11.
Pdf to jpeg converter - Convert PDF to JPEG images in C#.net, ASP.NET MVC, WinForms, WPF project
How to convert PDF to JPEG using C#.NET PDF to JPEG conversion / converter library control SDK
batch pdf to jpg converter online; convert pdf to high quality jpg
Pdf to jpeg converter - VB.NET PDF Convert to Jpeg SDK: Convert PDF to JPEG images in vb.net, ASP.NET MVC, WinForms, WPF project
Online Tutorial for PDF to JPEG (JPG) Conversion in VB.NET Image Application
changing pdf to jpg file; convert pdf file to jpg format
88
SubpatternsandYielding
EXAMPLE(40)
Thisisanexampleforasubpatternrewriteapplication.
1
patternTwoParametersAddDelete(mp:Method)
2
{
3
mp<-- v1:Variable;
4
mp<-- :Variable;
5
6
modify {
7
delete(v1);
8
mp<--:Variable;
9
}
10
}
11
rulemethodAndFurtherAddDelete
12
{
13
m:Method<--n:Name;
14
tp:TwoParametersAddDelete(m);
15
16
modify {
17
tp(); // triggerrewritingof theTwoParametersAddDeleteinstance
18
}
19
}
EXAMPLE(41)
Thisisanotherexampleforasubpatternrewriteapplication,reversingthedirectionofthe
edgesonaniteratedpath.
1
patternIteratedPathReverse(prev:Node)
2
{
3
optional{
4
prev--> next:Node;
5
ipr:IteratedPathReverse(next);
6
7
replace {
8
prev<--next;
9
ipr();
10
}
11
}
12
13
replace{
14
}
15
}
Online Convert PDF to Jpeg images. Best free online PDF JPEG
Online PDF to JPEG Converter. Download Free Trial. Convert a PDF File to JPG. Drag and drop your PDF in the box above and we'll convert the files for you.
change pdf file to jpg; batch pdf to jpg converter
C#: How to Use SDK to Convert Document and Image Using XDoc.
You may use our converter SDK to easily convert PDF, Word, Excel, PowerPoint, Tiff, and Dicom files to raster images like Jpeg, Png, Bmp and Gif.
convert pdf file into jpg format; convert .pdf to .jpg online
8.2 SubpatternRewriting
89
EXAMPLE(42)
This is anexamplefor rewrite parameters,connecting every node on n an iteratedpath to
acommonnode(i.e. thelocalrewritegraphtothecontainingrewrite e graph). . It t can’t be
simulatedbysubpatternparameterswhichgetdenedatmatchingtimebecausethecommon
elementisonlycreatedlateron,atrewritetime.
1
patternChainFromToReverseToCommon(from:Node,to:Node) replace(common:Node)
2
{
3
alternative{
4
rec{
5
from-->intermediate:Node;
6
cftrtc:ChainFromToReverseToCommon(intermediate, to);
7
8
replace{
9
from <-- intermediate;
10
from --> common;
11
cftrtc(common);
12
}
13
}
14
base {
15
from-->to;
16
17
replace{
18
from <-- to;
19
from --> common;
20
to-->common;
21
}
22
}
23
}
24
25
replace{
26
from; to;
27
}
28
}
1
rulechainFromToReverseToCommon()
2
{
3
from:Node; to:Node;
4
cftrtc:ChainFromToReverseToCommon(from,to);
5
6
modify {
7
common:Node;
8
cftrtc(common);
9
}
10
}
8.2.1 DeletionandPreservationofSubpatterns
Inadditionto the ne-graindependentrewrite,subpatterns may get deleted or kept asa
whole.
C# PDF Convert: How to Convert Jpeg, Png, Bmp, & Gif Raster Images
Jpeg, Png, Bmp, Gif Image to PDF. |. Home ›› XDoc.Converter ›› C# Converter: Raster Image to PDF.
convert pdf image to jpg; .pdf to .jpg online
Online Convert Jpeg to PDF file. Best free online export Jpg image
Online JPEG to PDF Converter. Download Free Trial. Convert a JPG to PDF. You can drag and drop your JPG file in the box, and then start
change from pdf to jpg; convert .pdf to .jpg
90
SubpatternsandYielding
SubpatternOccurence
-
Ident
-
;
-
delete
-
(
-
Ident
,
-
)
-
;
-
Inmodifymode,they arekept bydefault,butdeletedifthenameofthedeclaredsub-
patternentityismentionedwithinadeletestatement. Inreplacemode,theyaredeletedby
default,butkeptifthenameofthedeclaredsubpatternentityismentioned(usingoccurrence,
sameaswithnodesoredges).
EXAMPLE(43)
1
rule R{
2
m1:Method; m2:Method;
3
tp1:TwoParameters(m1);
4
tp2:TwoParameters(m2);
5
6
replace{
7
tp1; //iskept
8
//tp2notincludedhere- willbedeleted
9
//tp1();ortp2(); -- wouldapplydependentreplacement
10
m1;m2;
11
}
12
}
NOTE(31)
You mayeven give aSubpatternEntityDeclarationwithinarewrite part t which h causesthe
subpatterntobecreated;butthisemploymenthasseveralissueswhichcanonlybeovercome
byintroducingexplicitcreation-onlysubpatterns{soyoubetteronlyuseitifyouthinkit
shouldobviouslywork(examplesfortheissuesarealternatives{whichcasetoinstantiate?
{andabstractnodeoredgetypes{whatconcretetypetochoose?).
1
patternForCreationOnly(mp:Method)
2
{
3
//somecomplexpatternyou wanttoinstantiateseveraltimes
4
//connecting ittothe mphandedin
5
}
6
rulecreateSubpattern
7
{
8
m:Method;
9
10
modify {
11
:ForCreationOnly(m);//instantiatepatternForCreationOnly
12
}
13
}
XDoc.Converter for .NET, Support Documents and Images Conversion
This .NET file converter SDK supports various commonly used document Office (2003 and 2007) Word, Excel, PowerPoint, PDF, Tiff, Dicom, SVG, Jpeg, Png, Bmp
reader pdf to jpeg; batch convert pdf to jpg
VB.NET PDF Converter Library SDK to convert PDF to other file
As this VB.NET PDF converter component plug-in embeds several image image converting applications, like PDF to tiff conversion, PDF to JPEG conversion and
convert multiple pdf to jpg online; change pdf to jpg on
8.3 LocalVariables,OrderedEvaluation,andYieldingOutwards
91
8.3 LocalVariables,OrderedEvaluation,andYieldingOutwards
LocalVariablesandOrderedEvaluation
Sometimesattributeevaluationbecomeseasierwithtemporaryvariables;suchlocalvariables
canbeintroducedonarighthandsideemployingtheknownvariablesyntaxvar name:type,
prexed withthe def f keyword. . From m then on they y can n be readand assigned to in eval
statementsoftheRHS,orusedasvariableparametersinsubpatternrewritecalls.Inaddition,
ontheirintroductionaninitializingexpressionmaybegiven.
EXAMPLE(44)
1
rule R{
2
n1:N;n2:N;n3:N; n4:N; n5:N;
3
4
modify {
5
defvarmean:double= (n1.v+ n2.v+ n3.v+ n4.v+ n5.v)/5;
6
eval {
7
n1.variance= (n1.v- mean)*(n1.v -mean);
8
n2.variance= (n2.v- mean)*(n2.v -mean);
9
n3.variance= (n3.v- mean)*(n3.v -mean);
10
n4.variance= (n4.v- mean)*(n4.v -mean);
11
n5.variance= (n5.v- mean)*(n5.v -mean);
12
}
13
}
14
}
Normallytherewriteorderisasgivenintable8.1:
1.
Extract elements s needed d from match
2.
Create new nodes
3.
Call rewrite code of used subpatternsandmore...
4.
Call rewrite code of nested d iterateds
5.
Call rewrite code of nested d alternatives
6.
Redirect edges
7.
Retype (and merge) nodes
8.
Create new edges
9.
Retype edges
10.
Create subpatterns
11.
Attribute reevaluation
12.
Remove edges
13.
Remove nodes
14.
Remove subpatterns
15.
Emit / Exec
16.
Return
andmore... at3. areevalhere,emithere,alternativeName,iteratedName
Table8.1: Executionorderrewriting
Sorstthesubpatternsrewrites,thentheiteratedrewrites,thenthealternativerewrites
areexecuted,andnallythelocalevalstatements(computations). Thismightbesucient
insomecases,butinothercaseswhenyouwanttocomputeanattributationoveratree/a
graph,youwanttohavelocalcomputationsin uencedbyattributesinnested/calledchildren
oritssiblings,andattributesinnested/calledchildrenin uencedbyitsparentsorsiblings.So
C# PDF Converter Library SDK to convert PDF to other file formats
Help to convert PDF to multiple image formats, including GIF, BMP, JPEG, PNG and so on. Remarkably, this PDF document converter control for C#.NET can
reader convert pdf to jpg; convert from pdf to jpg
C# Create PDF from images Library to convert Jpeg, png images to
NET converter control for It enables you to build a PDF file with one or more images. Various image forms are supported which include Png, Jpeg, Bmp, and Gif
convert pdf to 300 dpi jpg; change pdf file to jpg file
92
SubpatternsandYielding
weneedalanguagedevicewhichallowsustointermingleattributecomputationsinbetween
therewritepartexecutionsofnestedpatternsandsubpatternrewritecalls. Andalanguage
devicewhichallowsustogivetheexecutionoderofthealternativeanditeratedstatements
relativetothesubpatternrewritecallsandattributeevaluations.
To achieve e attribute e evaluation n in a dened d order r in between the e subpattern rewrite
calls,weuseorderedevaluationstatements,introducedwiththekeywordevalhere;theyget
executedintheorderinwhichtheyaregivensyntactically(afurtherstatementexecutedin
orderisemithere,introducedin11.2).
Toachieveiterated/alternativeexecutioninorder,weallownamestobegiventonested
patterns,andreusethisnameinanestedpatternrewriteorderspecication.Namingnested
patternsisdonewiththefollowingsyntax,asthealreadyintroducedsyntaxremainsvalid,on
aggregateweextendthenestedpatternswithoptionalnamestoformnamednestedpattern.
NamedNestedPattern
-
negative
-
independent
-
IdentDecl
-
f
-

-
g
-
-
iterated
-
multiple
-
optional
-
IdentDecl
-

-
g
-
-
alternative
-
IdentDecl
-
f
-

-
g
-
Alternativesanditeratedsnamedthiswaycanthenbereferencedintherewritepartwith
analternativerewriteorderspecicationoraniteratedrewriteorderspecication.
CardinalityRewriteUsage
-
iterated
-
multiple
-
optional
-
Ident
-
;
-
AlternativeRewriteUsage
-
alternative
-
Ident
-
;
-
What we’veseensofar is appliedinthe followingexample. . Ayield d prex is needed
wheneveradefvariableiswrittento(asassignmenttargetas wellasasubpatternoutput
argument).
8.3 LocalVariables,OrderedEvaluation,andYieldingOutwards
93
EXAMPLE(45)
1
rule R{
2
iteratedfoo{ .; modify{..read i.. }}
3
alternativebar{ case{ modify{..read i.. }} }
4
sub1:Subpattern1();
5
sub2:Subpattern2();
6
7
modify {
8
defvar i:int= 0; //initializesi to 0
9
evalhere{yieldi =i +1;} // afterwardsi==1
10
sub1(i); //input1 to subpatternrewrite
11
evalhere{yieldi =i +1;} // afterwardsi==2
12
iteratedfoo;//nestediteratedreads i==2
13
evalhere{yieldi =i +1;} // afterwardsi==3
14
alternative bar;//nestedalternativereadsi==3
15
evalhere{yieldi =i +1;} // afterwardsi==4
16
sub2(i); //input4 to subpatternrewrite
17
evalhere{yieldi =i +1;} // afterwardsi==5
18
eval {yieldj =i +1;} //assign 6toj
19
}
20
}
NOTE(32)
For rewriting the execution n order r of f the e parts s can be e dened, to allow programming at-
tributeevaluationordersofinterest,deningwhentodescendintowhichpartanddening
glueing/localcomputationsinbetween. (Adepthrstrunwithadenedorderinbetween
thesiblings,comparabletoanLAG/RAGrunincompilerconstruction,butwithanexplic-
itly denedsequence ofchildrenvisits,insteadofatemporalsuccessionimplicitlyinduced
bythesyntacticalleft-to-rightordering). Incontrasttorewriting,thematching g orderofthe
patternpartscannot be e dened,toallow the compiler/theruntime to use the evaluation
orderitestimatestobethebest. Sowecan’taccessattributesfromsiblingelements,wecan
onlycomputeattributestopdownfromlocalelementsorelementshandedinonmatching,
andlateronbottomupfromlocalelementsorelements bubblingupat matchobjecttree
construction. Topdownattributeevaluationoperatesonthealreadymatchedelementsand
attributevaluesortheonesreceivedasinputs,whicharehandeddownimplicitlyintonested
patterns or explicitly viasubpatternparametersintosubpatterninstances. . (Adepthrst
run too, but t without a denedorder in n betweenthe siblings, comparable toanIAG run
incompilerconstructionforcomputinginheritedattributesduringmatchingwhiledescend-
ing). Bottomupattributeevaluationoperatesonthematchedelementsandattributevalues
locallyavailableortheonesreceivedintodefelementsyieldedimplicitlyupwardsfromthe
nestedpatternsorexplicitlyaccumulatingiteratedresultsorwithassigningoutparameters
ofsubpatterns. (Thesamedepthrstrun,butwithattributescomputedwhileascending,
comparabletoanSAGrunincompilerconstructionforcomputingsynthesizedattributes.)
YieldingOutwardsDuringRewriting
Sometimesoneneedstobringsomethingmatchedwithinanestedorsubpatterntoanouter
patterncontainingit(nestedpatterns)orcallingit(subpatterns). Sothatonecandothere
(intheusingpattern)operationsonit,e.g.attachingafurtheredgetoanendnodeofachain
matchedwithrecursivepatterns(thusmodularizingthegraphrewritespecicationintochain
94
SubpatternsandYielding
matchingpatternsandpatternsusingchainsdoingthingsonthechainends),orsumming
attributesmatchediniteratedpatterninstances.
Therstthingoneneedstobringsomethingoutwardsisatargetinanestingorcalling
pattern. This s is s achievedby y nodes, edges, and variables s declared d with the e def keyword
in a rewrite e part, marking g them as s output t entities; ; variables s were already introduced in
previousparagraphs,butinadditiontothemnodesandedgesareallowed,too.Furthermore
subpatternrewriteparametersmaybedeclaredasdefparameters,markingthemasoutput
parameters. Theseelementsarethenyieldedtofromwithinevalorevalherestatements,
subpatternrewriteusages,andexecstatements.Whilethelatterwillbecoveredinchapter
11,theformerwillbeexplainedinthefollowing.
Yieldingis specied d by y prepending the yield keyword d tothe entity y yieldedto, , in an
assignmenttoavariableoramethodcallonavariable,insideanevalorevalhere-statement,
orachangeassignment;thetargetoftheassignmentmaybeanodeoredge(ifdeclaredas
outputvariable).Theyieldmustbeprependedtotheargumentforasubpatterndefrewrite
parameter,too.
EXAMPLE(46)
1
patternChain(begin:Node)modify(def end:Node)
2
{
3
alternative{
4
Further {
5
begin-->intermediate:Node;
6
c:Chain(intermediate);
7
8
modify {
9
c(yield end);
10
}
11
}
12
Done {
13
negative{
14
begin-->;
15
}
16
17
modify {
18
eval {
19
yield end =begin;
20
}
21
}
22
}
23
}
24
25
modify {}
26
}
27
28
rule R(begin:Node) :(Node){
29
c:Chain(begin);
30
31
modify {
32
defend:Node;
33
c(yieldend);//endisfilledwithchainend
34
return(end);
35
}
36
}
FirstexampleforRHSyielding: returningtheendnodeofachain.
8.3 LocalVariables,OrderedEvaluation,andYieldingOutwards
95
EXAMPLE(47)
1
ruleoutCount(head:Node): (int)
2
{
3
iterated{
4
head--> .;
5
modify{
6
eval{ yieldcount= count +1;}
7
}
8
}
9
10
modify {
11
defvarcount:int= 0;
12
return(count);
13
}
14
}
SecondexampleforRHSyielding:countingthenumberofedgesmatchedwithaniterated.
YieldingOutwardsDuringMatchObjectConstruction
Bubblinguptheelementsfromnestedpatternsandcalledpatternsduringrewritingmight
betoolateorinconvenient. Luckilyitcanbedonebefore,attheendpatternmatchingwhen
thematchobjecttreegetsconstructed.
AsforRHSyieldingthetargetsoftheyieldingmustbenodes,edges,orvariablesdeclared
withthe def keyword prepended, marking them as output t entities; ; but t this s time in the
patternpart.Furthermoresubpatternparametersmaybedeclaredasdefparametersinthe
subpatterndenitionheader,markingthemasoutputparameters.
Theseelementscanthenbeyieldedtofromwithinevalstatementsinsideayieldblock
(maybewithiteratedaccumulation)andsubpatternusages.Ayieldblockisaconstrained
evalblockwhichcanbegiveninthepatternpart;itdoesnotallowtoassigntoorchangenon-
defvariables,or carryoutgraph-changingcommands. . Yieldingis s speciedbyprepending
theyieldkeywordtotheentity yieldedto,intheassignmentor methodcall. . The e yield
mustbeprependedtotheargumentforasubpatterndefparameter,too.
NOTE(33)
Adefentityfromthepatternpartcan’tbeyieldedtofromtherewritepart,theyareconstant
aftermatching.
Let’shavealookattwoexamplesforyielding:
96
SubpatternsandYielding
EXAMPLE(48)
1
patternChain(begin:Node,def end:Node)
2
{
3
alternative{
4
further{
5
begin-->next:Node;
6
:Chain(next,yieldend);
7
}
8
done{
9
negative{
10
begin--> ;
11
}
12
yield{
13
yieldend= begin;
14
}
15
}
16
}
17
}
18
19
patternLinkChainTo(begin:Node)modify(n:Node)
20
{
21
alternative{
22
further{
23
begin-->next:Node;
24
o:LinkChainTo(next);
25
26
modify {
27
next--> n;
28
o(n);
29
}
30
}
31
done{
32
negative{
33
begin--> ;
34
}
35
36
modify {
37
}
38
}
39
}
40
41
modify{ }
42
}
43
44
rulelinkChainEndToStartIndependent(begin:Node) : (Node)
45
{
46
defend:Node;
47
48
independent{
49
c:Chain(begin,yieldend);
50
}
51
o:LinkChainTo(begin);
52
53
modify{
54
o(end);
55
return(end);
56
}
57
}
Documents you may be interested
Documents you may be interested