10.3 ExactDynamicType
117
Atypeconstraintisusedtoexcludepartsofthetypehierarchy. Theoperator r +isusedto
createaunionofitsoperandtypes. Sothefollowingpatternstatementsareidentical:
x:T \ (T1 1 + +   + + Tn);
x:T;
if f!(typeof(x) ) >= = T1) && 
&& !(typeof(x) ) >= = Tn)g
EXAMPLE(60)
T
T1
T2
T4
T3
ThetypeconstraintT\(T2+T3)appliedtothetypehierarchyontheleft
sideyieldsonlythetypesTandT1asvalid.
10.3 ExactDynamicType
Inthefollowingsectionwe’llhavealookatalanguageconstructwhichallowstorequirean
elementtobetypedthesameasanotherelementortocreateanelementwiththesameexact
dynamictypeasanotherelement.
Type
-
TypeIdent
-
typeof
-
(
-
NodeOrEdge
-
)
-
The type of a graphelement may be givenby atype identier,or atypeofdenoting the
exact dynamic type of amatchedgraphelement. . The e element declaration el:typeof(x)
introduces agraph h elementofthetypethehost t graphelement xis actuallyboundto. . It
may appearinthepatternorintherewritepart. . Ifitisgiveninthepattern,theelement
tomatchmustbeofthesameexactdynamictypeastheelementreferencedinthetypeof,
otherwisematchingwillfail.Ifisisgivenintherewritepart,theelementtocreateiscreated
withthesameexactdynamictypeastheelementreferencedinthetypeof;havealookat
thenextsectionforthebigbrotherofthislanguageconstruct,thecopyoperator,whichis
onlyapplicableintherewritepart.
Convert multipage pdf to jpg - 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
changing pdf to jpg on; best pdf to jpg converter
Convert multipage pdf to jpg - 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
convert pdf image to jpg image; .net pdf to jpg
118
AdvancedMatchingandRewriting
EXAMPLE(61)
Thefollowingrulewilladdareverseedgetoaone-waystreet.
1
ruleoneway {
2
a:Node-x:street-> y:Node;
3
negative{
4
y -:typeof(x)-> a;
5
}
6
replace {
7
a -x->y;
8
y -:typeof(x)-> a;
9
}
10
}
Rememberthatwehaveseveralsubtypesofstreet.Bytheaidofthetypeofoperator,the
reverseedgewillbeautomaticallytypedcorrectly(thesametypeastheone-wayedge).This
behaviorisnotpossiblewithoutthetypeofoperator.
10.4 Retyping
Inadditiontographrewriting,GrGen.NETallowsgraphrelabeling[LMS99],too;weprefer
to call itretyping. . Nodes s as well l as s edges may be retypedtoa dierent type; ; attributes
commontotheinitialandnaltypearekept.Thetargettypedoesnotneedtobeasubtypeor
supertypeoftheoriginaltype. Retypingisusefulforrewritinganodebutkeepingitsincident
edges;withoutityou’dneedtorememberandrestorethose. Syntacticallyitisspeciedby
givingtheoriginalnodeenclosedinleftandrightangles.
Retyping
-
<
-
Ident
-
>
-
Pattern(LHS) Rewrite(RHS) ) r:L !R
Meaning
x:N1;
y:N2<x>;
r:lhs:x7!rhs:x Matchx,thenretypexfromN1
toN2 and d bindname y y tore-
typedversionofx.
e:E1;
f:E2<e>;
r:lhs:e7!rhs:e Matche,thenretypeefromE1
toE2andbindnameftothe
retypedversionofe.
Table10.3:Retypingofmatchednodesandedges
Retypingenablesustokeepalladjacentnodesandallattributesstemmingfromcommon
supertypesofagraphelementwhilechangingitstype(table10.3showshowretypingcan
beexpressedbothfornodesandedges).Retypingdiersfromatypecast:Duringrewriting
bothofthegraphelementsarealive. Specicallybothofthemareavailableforevaluation,
arespectiveevaluationcould,e.g.,looklikethis:
eval{
y.b= ( 2*x.i == 42 );
f.a= e.a;
}
Furthermorethesourceanddestinationtypesneednot tobeonapathinthedirectedtype
hierarchy graph,rather theirrelationcanbearbitrary. . However,ifsourceanddestination
VB.NET PDF Convert to Images SDK: Convert PDF to png, gif images
Convert PDF documents to multiple image formats, including Jpg, Png, Bmp, Gif, Tiff, Bitmap, .NET Graphics, and REImage. Turn multipage PDF file into image
pdf to jpg converter; convert multiple pdf to jpg
C# PDF Convert to Images SDK: Convert PDF to png, gif images in C#
NET control able to batch convert PDF documents to image Create image files including all PDF contents, like Turn multipage PDF file into single image files
batch pdf to jpg converter; reader convert pdf to jpg
10.5 Copy
119
typehaveoneoremorecommonsupertypes,thentherespectiveattributevaluesareadopted
by the retypedversionoftherespectivenode(or edge). . The e edgespecicationas wellas
ReplaceNode supportsretyping. . InExample58node e n5 isaretypednodestemming from
node n1. . Note, , that|conceptually|the retyping is s performed d after r the e SPOconforming
rewrite.
EXAMPLE(62)
ThefollowingrulewillpromotethematchedcityxfromaCitytoaMetropoliskeepingall
itsincidentedges/streets,withexceptionofthematchedstreet y,whichwillgetpromoted
fromStreettoHighway,keepingallitsadjacentnodes/cities.
1
ruleoneway {
2
x:City -y:Street->;
3
4
replace{
5
x_rt:Metropolies<x> -y_rt:Highway<y>->;
6
}
7
}
Thefollowingrule willretypethematchedcity x to the exactydynamic typeof z (which
mightbee.g.Metropolis).
1
ruleretypeToTypeof{
2
x:City; z:City;
3
4
modify {
5
x_rt:typeof(z)<x>;
6
}
7
}
Theretypingclausenew:type<old>canbeusedontheLHS,too.Whenitappearsonthe
lefthandside,thenode(/edge)oldisnotchangedinanyway,insteadafurthernode(/edge)
newismadeavailableforquerying,beingidenticaltooldregardingtheobjectreference,but
additionallygivingaccesstotheattributesknowntothetype{ifmatchingwassuccessful.
Theconstructtriestocastoldtonew,ifsuccessfulnewallowstoaccessoldastype,otherwise
matchingfailsforthisold(andbindinganothergraphelementtooldistriedout). Please
havealookatexample30formoreonthis.
10.5 Copy
Thecopyoperatorallowstocreateanodeoredgeofthetypeofanothernode/edge,bearing
thesameattributesasthatothernode.Itcanbeseenasanextendedversionofthetypeof
constructnotonly copyingtheexactdynamictypebut alsothe attributes ofthematched
graphelement.Togetherwiththeiteratedconstructitallowstosimulatenodereplacement
grammarsortocopyentirestructures,see19and19.5.
CopyOperator
-
copy
-
<
-
Ident
-
>
-
C# PDF insert image Library: insert images into PDF in C#.net, ASP
Add multiple images to multipage PDF document in .NET WinForms. Support various image formats, like Jpeg or Jpg, Png, Gif, Bmp, Tiff and other bitmap images.
change pdf file to jpg online; convert multi page pdf to jpg
C# Create PDF Library SDK to convert PDF from other file formats
such as tiff, jpg, png, gif, bmp, etc. Create writable PDF from text (.txt) file. HTML webpage to interactive PDF file creator freeware. Create multipage PDF from
convert pdf to jpeg; convert pdf image to jpg
120
AdvancedMatchingandRewriting
EXAMPLE(63)
Thefollowingrulewilladdareverseedgetoaone-waystreet,oftheexactdynamicsubtype
ofstreet,bearingthesameattributevaluesastheoriginalstreet.
1
ruleoneway {
2
a:Node -x:street->y:Node;
3
negative{
4
y-:typeof(x)-> a;
5
}
6
7
replace{
8
a -x->y;
9
y-:copy<x>->a;
10
}
11
}
10.6 NodeMerging
The retyping construct for r nodes s can n be e extended d into a node merging construct, which
internallyredirectsedges.
Merging
-
<
-
Ident
,
-
>
-
Mergingenablesustofuseseveralnodes intoonenode. . Syntactically y it is givenbya
retypingclausewhichnotonlymentionstheoriginalnodeinsideanglebrackets,butseveral
originalnodes.Semanticallytherstnodeintheclauseisretyped,thenalledgesoftheother
originalnodes are redirectedto the retypednode, , andnally y theotheroriginalnodes are
deleted.Asthetypeofthemergingclausecanbesettotypeof(first original node),a
puremergingwithoutretypingcanbeachieved.
EXAMPLE(64)
ThefollowingrulewillmatchtwoStatesandmergethem.Everyedgeincidenttobbeforeand
everyedgeincidenttowbeforewillbeincidenttothemergedsuccessorstatebwafterwards;
edgesconnectingthetwoStatesbecomere exiveedges.
1
rulemerge{
2
b:State;
3
w:State;
4
if{ b.name=="Baden"&&w.name=="Wuerttemberg"; }
5
6
modify {
7
bw:typeof(b)<b,w>;
8
eval {bw.name =b.name+ w.name;}
9
}
10
}
VB.NET Create PDF Library SDK to convert PDF from other file
Best VB.NET component to convert Microsoft Office Word HTML webpage to interactive PDF file creator freeware. Create multipage PDF from OpenOffice and CSV file.
advanced pdf to jpg converter; change pdf to jpg on
C# PDF Convert to Tiff SDK: Convert PDF to tiff images in C#.net
multipage tiff image files can be created from PDF. Supports tiff compression selection. Supports for changing image size. Also supports convert PDF files to jpg
convert pdf to jpg converter; .pdf to .jpg converter online
10.7 EdgeRedirection
121
10.7 EdgeRedirection
Theredirectstatementallows toexchangethesourceorthetargetnodeofadirectededge
(orboth)withadierentnode;itcanbeseenassyntacticsugarforremovingoneedgeand
creatinganewonewiththesource/targetnodebeingreplacedbyadierentnode,withthe
additionaleectofkeepingedgeidentity.
Redirect
-
!
-
-
-
EdgeRenement
-
->
-
!

-
!
-
<-
-
EdgeRenement
-
-
-
!
-
Redirectionis speciedwith h anexclamation mark k at theendtoberedirected d as s seen
fromtheedgecenter;theexclamationmarkenforcestheredirectionwhichwouldnormally
berejectedbythecompiler"Thisisdierentfromwhatwasmatched,butthat’sintentionally,
makeithappen!"
EXAMPLE(65)
Thefollowingrulewillreversetheone-waystreetinbetween aandy y by rewritingtheold
sourcetothenewtargetandtheoldtargettothenewsource.
1
ruleoneway {
2
a:Node -x:street->y:Node;
3
4
modify {
5
a !<-x-! y;
6
}
7
}
10.8 AttributeInitialization
Atanodeoredgedeclarationinthemodifyorreplacepart(causingcreationoftheelement),
youcan give an attribute initializationlist, with the name of the element t (the persistent
nameofanamedgraph)seenasaspecialattribute.
AttributeInitializationList
-
@
-
(
-
AttributeInitialization
,
-
)
-
AttributeInitialization
-
AttributeName
-
=
-
Expression
-
$
-
=
-
Expression
-
Theinitializationlistis appendedtothedeclarationwithanat-Symbol,thedollar sign
standsforthenameoftheelement,whereastheotherattributesofthetypearesimplygiven
122
AdvancedMatchingandRewriting
by theirname. . Theexpressionmustbeof f the typeoftheattribute(andstringincaseof
thename). Theinitializationlistismoreconvenientthantheotherwiseneededevalblock,
containinganassignmentperline{infactitissyntacticsugarthatisdissolvedtoeval-like
assignments. Pleasetakeintoaccountthatthenamesmustbeuniqueifyouintendtoset
themfromtherules.
EXAMPLE(66)
ThefollowingexamplerulecreatesanewnodenoftypeN,initializingthenameto"foo",
theattributeito42,andtheattributesto"Hallo Welt".
1
rulecreate {
2
modify {
3
n:N@($="foo",i=42,s="Hallo Welt");
4
}
5
}
CHAPTER 11
EMBEDDED SEQUENCES AND TEXTUAL OUTPUT
Inthischapterwe’llhavealookatlanguageconstructswhichallowtoemittextfromrules/-
subpatternsandwhichallowtoexecuteagraphrewritesequenceattheendofaruleinvo-
cation. Theabilitytoexecuteasequenceattheendofaruleinvocationallowstocombine
rulesandbuildcomplexrules.
11.1 ExecandEmitinRules
The followingsyntax diagramgives anextensionstothe syntaxdiagrams of theRule Set
Languagechapter5:
ExecStatement
-
emit
-
(
-
StringExpr
,
-
)
-
;
-
exec
-
(
-
RewriteSequence
-
)
-
;
-
Thestatementsemitandexecenhancethedeclarativerewritepartbyimperativeclauses.
Thatmeans,i)thesestatementsareexecutedinthesameorderastheyappear withinthe
rule,andii) they are executedafter all l the rewrite operations s are done,i.e.they operate
onthemodiedhost graph. . However, , attribute values s of deletedgraphelements arestill
availableforreading.Theevalstatementsareexecutedbeforetheexecutionstatements,i.e.
theexecutionstatementsworkontherecalculatedattributes.
XGRSExecution
Theexecstatementexecutesagraphrewritesequence,whichisacompositionofgraph
rewriterules.GraphelementsmaybeyieldedtodefvariablesintheRHSpattern. See
Chapter9foradescriptionofgraphrewritesequences. Theexecstatementisoneof
themeansavailableinGrGen.NETtobuildcomplexrulesandsplitworkintoseveral
parts,see19foradiscussionofthistopic.
TextOutput
The emitstatement printsa stringor acomma-separatedsequenceof strings to the
currentlyassociatedoutputstream(defaultisstdout).SeeChapter6foradescription
ofstringexpressions.Theargument(s)mustbeofstringtype,butanytypeisautomati-
callycastedintoitsstringrepresentationasneeded.Prefercommaseparatedarguments
over stringconcatenation,theyarearemoreecientas nointermediatestrings need
tobecomputed,justtobegarbagecollectedthereafter. Foremittinginbetweenthe
emitsfromsubpatterns,thereisanadditionalemitherestatementavailable.
123
124
EmbeddedSequencesandTextualOutput
EXAMPLE(67)
Thefollowingexampleworksonahypotheticalnetwork ow. Wedon’tdenealltherules
northegraphmetamodel. It’sjustaboutthelookandfeeloftheexecandemitstatements
1
ruleAddRedundancy
2
{
3
s:SourceNode;
4
t:DestinationNode;
5
modify {
6
emit ("Source node is ",s.name, , ". Destination node is ",t.name, , ".");
7
exec ((x:SourceNode) =DuplicateNode(s)&ConnectNeighbors(s, x)* );
8
exec ([DuplicateCriticalEdge]);
9
exec (MaxCapacityIncidentEdge(t)*);
10
emit ("Redundancy added");
11
}
12
}
EXAMPLE(68)
Thisis anexampleforreturningelementsyieldedfromanexec statement. . Theresultsof
therule bar are writtento the variables a andb;Theyieldis aprex toanassignment
showingthatthetargetisfromtheoutside.
1
rulefoo :(A,B)
2
{
3
modify {
4
defu:A; defv:B;
5
exec( (a,b)=bar ;> yieldu=a ;>yieldv=b) );
6
return(u,v);
7
}
8
}
11.2 DeferredExecandEmithereinNestedandSubpatterns
ThefollowingsyntaxdiagramgivesanextensionstothesyntaxdiagramsoftheSubpatterns
chapter8:
SubpatternExecEmit
-
emithere
-
(
-
StringExpr
-
)
-
;
-
emit
-
(
-
StringExpr
-
)
-
;
-
exec
-
(
-
RewriteSequence
-
)
-
;
-
Thestatementsemit,emithereandexecenhancethedeclarativenested(andsubpattern)
rewritepartbyimperativeclauses. Theemitandemitherestatementsgetexecutedduring
rewritingbeforetheexecstatements;theemithere-statementsgetexecutedbeforetheemit
statements,inthe order inbetween the subpatternrewriteapplicationstheyare specied
syntactically(see8.3formoreonthis). Theexecstatementsareexecutedi)aftertherule
which used the pattern they are contained in was s executed d and ii) in the e order as they
11.2 DeferredExecandEmithereinNestedandSubpatterns
125
appear withinthe rule. . They y area slightly dierent version n of the e exec-statements s from
theExecStatement introducedin5.4.3,onlyavailableintherewritepartsofsubpatternsor
nestedalternatives/iterateds (butnotintherewritepartofrules astheoriginalembedded
sequences). They y are e executedafter the original rule calling them was executed,so they
can’tgetextendedbyyields,asthecontainingruleisnotavailableanymorewhentheyget
executed.
NOTE(36)
Theembeddedsequencesareexecutedafterthetop-levelrulewhichcontainsthem(inanested
pattern or r in n a used subpattern) ) was s executed; they y are not t executedduring g subpattern
rewriting. Theyallowyouto o put workyoucan’tdowhile executingtherule proper(e.g.
becauseanelementwasalreadymatchedandisnowlockedduetotheisomorphyconstraint)
toawaitingqueuewhichgetsprocessedafterwards|withaccesstotheelementsoftherule
andcontainedparts whichareavailablewhenthe rule gets executed. . Or r tojust splitthe
workintoseveralparts,reusingalreadyavailablefunctionality,see19foradiscussiononthis
topic.
NOTE(37)
Andagain|theembeddedsequencesareexecutedaftertherulecontainingthem;thusrule
executionis splitintotwoparts,adeclarativeof parts a)andb),andanimperative. . The
declarativeissplitintotwosubparts:Firsttheruleincludingallitsnestedandsubpatterns
is matched. . Thenthe e rulemodications are applied,including allnestedandsubpattern
modication.
Afterthisdeclarativestep,containingonlythechangesoftheruleanditsnestedandused
subpatterns,thedeferredexecswhichwerespawnedduringthemainrewritingareexecuted
in asecond, imperativestep; during this, arulecalledfrom the sequenceto execute may
dootherniftythings,usingfurtherownsequences,evencallingitselfrecursivelywiththem.
Firstallsequencesfromacalledruleareexecuted,beforethecurrentsequencesiscontinued
orothersequencesofitsparentrulegetexecuted(depthrst).
Note:allchangesfromsuchdynamicallynestedsequencesarerolledbackifatransaction/a
backtrackenclosingaparentruleistoberolledback(butnopendingsequencesofaparent
ofthisparent).
126
EmbeddedSequencesandTextualOutput
EXAMPLE(69)
TheexecfromSubpattern subgetsexecutedaftertheexecfromrule e callerwasexecuted.
1
rulecaller
2
{
3
n:Node;
4
sub:Subpattern();
5
6
modify {
7
sub();
8
exec(r(n));
9
}
10
}
11
patternSubpattern
12
{
13
n:Node;
14
modify {
15
exec(s(n));
16
}
17
}
EXAMPLE(70)
Thisisanexampleforemithere,showinghowtolinearizeanexpressiontreeininxorder.
1
patternBinaryExpression(root:Expr)
2
{
3
root-->l:Expr;le:Expression(l);
4
root-->r:Expr;re:Expression(r);
5
root<--binOp:Operator;
6
7
modify {
8
le(); // rewritesandemitstheleftexpression
9
emithere(binOp.name); //emitstheoperatorsymbolin betweenthelefttreeandthe
righttree
10
re(); // rewritesandemitstherightexpression
11
}
12
}
Documents you may be interested
Documents you may be interested