Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Patterns Statement Summary

Patterns is a nonterminal metalanguage statement that initiates the definition of surface patterns for the operation codes in the intermediate language. A language specification may have multiple patterns statements that group the operation codes.


The Patterns statement has no attributes.


The substatements of the Patterns statement are as follows:


Substatement Description
PatternThis substatement defines the surface patterns for a given operation code in the intermediate language.


Pattern Substatement Summary

Pattern is a nonterminal metalanguage substatement that occurs within the Patterns statement and within the Replace refactoring statement. This substatement defines the surface patterns for a given operation code in the intermediate language. When used within a Patterns statements the definition must be for a previously undefined surface pattern. When used within a Replace statement a previous surface pattern may be replaced.


The attributes of the Pattern statement are as follows:


Attribute Description
IdThis attribute is the identifier of an operation code as defined in the Opcodes statement for the intermediate language.

The substatements of the Pattern statement are as follows:


Substatement Description
SubcodeThis nonterminal substatement specifies which suboperation of the operation code is to receive surface pattern definitions.
vbpThis deprecated terminal substatement specifies a surface pattern for the Basic project file syntax.
vb7This deprecated terminal substatement specifies a surface pattern for the VB6/ASP/VbScript source language syntaX.
cshThis terminal substatement specifies a surface pattern for C# syntax.
vbnThis terminal substatement specifies a surface pattern for VB.NET syntax.
gmsThis terminal substatement specifies a surface pattern for gmSL syntax.
jvsThis terminal substatement specifies a surface pattern for JavaScript syntax.
usrThis terminal substatement specifies a surface pattern for an external user specified syntax.
allThis terminal substatement specifies an all other syntax. When used it must be the final statement in the set of surface patterns being defined. The author will use this pattern if no explicit pattern exists for the target language syntax currently being authored.

The attributes of the Subcode substatement are as follows:


Attribute Description
IdThis attribute is the identifier of a suboperation code for the Pattern operation code as defined in the Opcodes statement for the intermediate language.


Any given operation code or operation code, subcode combination can have as many different surface patterns as needed associated with it. Operation codes that have no subcodes associated with them use this form.


Code Block
languagenone
themeEclipse
linenumberstrue
   <pattern id="opc">
       <syntax 1 .../>
         ...
       <syntax n .../>
    </pattern>
Operation codes that have subcodes associated with them use this form.


Code Block
languagenone
themeEclipse
linenumberstrue
   <pattern id="opc">
       <subcode id="subcode 1" >
          <syntax 1 .../>
            ...
          <syntax n .../>
       </subcode>
           ...
       <subcode id="subcode n" >
          <syntax 1 .../>
            ...
          <syntax n .../>
       </subcode>
    </pattern>
The script errors associated with the Pattern statement are as follows:


Error Description
1073Encountered following when expecting 'pattern': %1d
1074Pattern command missing required id attribute.
1075The pattern identifier [%1d] is not recognized.
1076The operation [%1d] already has surface forms specified.
1077Encountered following when expecting 'subcode': %1d
1078The required subcode identifier is missing.
1079The component [%1d] is not defined for the operation"
1080The subcode [%1d] already has surface forms specified.


vbp,vb7,csh,vbn,gms,jvs,usr,or all Substatement Summary

The dialect syntax specific statements all have the same form. They specify the expected state of the string stack before and after a particular operation is encountered by the string machine. In addition they supply additional information about the role and status of the operation needed within the string machine and elsewhere. Overall these specifications are referred to as "surface forms".


The attributes of the surface form statements are as follows:


Attribute Description
LevelAn integer value specifying the precedence of the operator relative to others. As the output production proceeds, it is necessary to enclose certain operations in parentheses to achieve the proper order of evaluation. The current precedence of each operand is maintained. When two operators of lower precedence are combined via an operator of higher precedence, then they are enclosed in parentheses.
StatusAn optional keyword describing the overall status of the operation: Ok, Delete, Deprecated, NotImplemented, MustCorrect, NotIdent, Postfix, or NeedsPren.
RoleAn optional keyword describing the overall role of the operation: Unknown, Property, Method, Define, Utility, Command, Constant, Function, Event, Control, Collection, Resource, Index, or Migclass.
NargAn integer value specifying the number of operands associated with the operation -- i.e., whether the operation is null, or unary, or binary, etc. -- for the particular language. All operations are reverse polish; therefore, when a given operation is encountered, its operand strings have already been placed on the string-machine stack. The operands are numbered starting with the oldest first. In other words, the operand deepest on the stack is argument 1 and the operand at the top of the stack is argument n, for an n-ary operator.
CodeA pattern string which specifies an arbitrary but fixed concatenation of the operands and of other character sequences which can be described via a linear pattern string. The pattern string describes not only how the operands are combined but also how the various constants, symbol table entries, and miscellaneous special-purpose conversion routines combine to form the final output.
Excerpt

Content of pattern strings

Within the pattern strings there are three types of specifications. First, there are special operation parameters which consist of a backslash followed by a letter. These parameters trigger special conversions. Second, there are operand conversion parameters which consist of a percent sign, followed by a numeric digit, followed by a conversion code. The numeric digit specifies which operand is to be entered at this point in the string, and the conversion code specifies any special operation to be performed. Third, there are simple character specifications which are any characters not forming one of the two specifications above. Simple characters are entered into result strings exactly as entered.


The special operation parameter characters are as follows:


Char Description
cA statement has been completed. Write it to the current output text buffer and continue processing the pattern string. If the syntax of the dialect being authored requires an end of statement like ";" then add it. These end of statement characters should not be entered into the pattern strings directly.
eThe operation code is followed by the storage offset of an enumeration entry in an external library or language file. Obtain the offset and enter its library-style identifier into the current statement.
kiThe operation code is followed by a short integer value. Convert the value to string and enter it into the current statement.
klThe operation is followed by the offset of the string representation of a long or exact representation constant. Retrieve it, do any dialect specific editing that is needed, and enter it into the current statement.
krThe operation is followed by the offset of the string representation or a real constant. Retrieve it, do any dialect specific editing that is needed, and enter it into the current statement.
ksThe operation is followed by the offset of a character string. Retrieve it and enter it into the current statement surrounded by quotes.
kpThe operation is followed by the offset of a character string. Retrieve it and enter it as is into the current statement -- i.e., without quotes.
kcThe operation is followed by the offset of a single-character string. Retrieve it and enter it into the current record surrounded by single or double quotes, depending upon the requirements for character constants in the target dialect.
lThe operation is followed by the root offset of a component in an external library. Display the identifier of this component either as a fully qualified identifier (library.class.component) or as a simple identifier depending upon the context of its use in the intermediate code.
vThe operation is followed by the root offset of a component in the user code. In cases where a qualified identifier is needed, simplify it depending upon the location of the reference.
VThe operation is followed by the root offset of a user code component that is in a different project than the reference. The qualifications that have to be associated with the reference may have to be fully specified.
pThe operation increases the logical nesting of the authored code. Write the current record and then increase the margin setting for the following records by the indentation margin width.
qThe operation decreases the logical nesting of the authored code. Write the current record and then decrease the margin setting for the following records by the indentation margin width.
nSimply write the current record without associating any language specific end-of-statement characters.
fFlush the string stack -- enter all active entries on the string stack into the output record
mEnter without margin -- write the current record without a margin. The "m" pattern opcodes have a 0,1, or 2 to distinguish #if, #else, and #end; however that is not used in this implementation.
wWrite the current record without a new line. This means that the following record written will be concatenated with this record in the final written record.
tTab to an indicated position -- the "t" pattern code is optionally followed by an integer constant which indicates the absolute character position to which the current record should be tabbed. A value of 0 or no value, simply inserts a tab into the current record.
sEnter a single double quote character into the current record. These pattern codes are tracked by pair by the surface pattern author. If this is a second one entered, the characters after the first one are scanned for double quotes that need to be escaped and if found the language specific conventions are used.
SEnter a single or double quote into the output record depending upon the presence of <% in the current record. This is a special operator used for writing the ends of attribute values for HTML statements within ASP code. It switches between single and double quotes when the language level change.
RThe operation is followed is by the offset of a stored resource. The label of that resource is entered into the current record.
BThe operation is followed by the root offset of a control whose code needs to be written. First write the current record and then author the code associated with the control.
CThe current record contains a comment that needs to be authored as such using the conventions of the target language and the various Select attributes that control the form and spacing of comments.
DThe operation code is followed by the root offset of a component whose declaration needs to be authored. Do so and associate any inline comment that follows it with the declaration -- if possible.
EThe operation ends the authoring of a control code started by the "B" pattern opcode. If it is followed by a 1 decrement the current indentation nesting level.
HThis operation is a specialty operator for writing the arguments to be associated with a direct call to an event handler. The operation scans the code looking for the event handler being call and then determines from its description what the appropriate event arguments are in the target language.
QThis operation simply enters two double quotes -- typically indicating an empty string -- into the output record.
QoOne of the problems faced by the author involves authoring strings with embedded quotes in quoted form. The term for this is "Quote-enclosure". The Qcontext characters are used to control the process which uses special characters called "hard quotes" to distinguish quotes that have to be escaped from quotes that do not. The basic issue is that once the quotes in part of an output string have been escaped, they must not be escaped again. The terminal hard quote of a string then is a blocking quote. The "Qo" operation opens a string to be quoted by entering a blocking hard quote
QqThis Qcontext operation simple enters a hard quote at the possible end of a string.
QrThis Qcontext operation removes a terminating hard quote. It is needed for multiple concatenations where the termination expected by the proceeding pattern is now delayed to the end of the current pattern.
QeThis Qcontext operation ends a string to be quoted. This is where all the work is done. The entire current output record starting at the last blocking quote is searched for soft quotes which are then escaped. When the record is actually written, all hard quotes are displayed as quotes.
TThe operation code is followed by the root offset of a component whose binary type display needs to be entered into the current record.
,This specialty operator, replace with comma, is used when possibly indexed assignments must be authored as calls to a Set operation. The current record is checked for an ending right-parenthesis and if present it is removed before a comma is entered into the record.
XThis specialty operator, author asp Xml comment, checks the current record to see if it is an ASP include. If not it uses the target language appropriate annotations to make it a comment. If it is an include it then authors using the appropriate markup conventions.
bThis operator enters a blank into the current record if it is needed to create a token break -- if the current ending character in the record is an identifier character.
N

Return previous argument string to the string stack so it may be used again in authoring the next operation pattern.  For example

Code Block
VB6\COM using MSComCtlLib.TabStrip
   Set objTab = Me.TabStrip1.Tabs.Add(1, "key1", "Browser")

Refactor Command
   <Migrate id="ITabs.Add" migPattern="%1d\Nnew TabPage(%5d); %1d.Name=%4d; %2d.Add(%1d)" nPram="6" />

Output
    objTab = new TabPage("Browser"); objTab.Name="key1"; this.TabStrip1.TabPages.Add(objTab);
\\This operator simply enters a backslash into the current record.


Each conversion code has an argument string associated with it that was removed from the string stack. They all also compare the hierarchy levels as described above to determine if parentheses have to be entered. The conversion codes differ in what changes they make in the argument string before they enter it into the current record. The conversion code characters are as follows:


Char Description
dThis code simply enters the argument with no editing.
iThis code assumes that the argument is a class name whose corresponding interface name should be displayed instead.
UThe standard way that transforms convert complex identifiers of the form id1.id2.id3 into simple identifiers is by changing the periods to underscores. This code here performs this operation on the argument string before it is entered.
oThe argument string is the representation of an optional argument being passed to a subprogram. If it is empty and the current record ends in a comma then remove the comma.
qThe argument from the stack is to be enclosed in quotes.
QHere the string argument is to be entered into a context which will be subject the quote-enclosure. However any quotes within this string should not be escaped. This display type converts any soft quotes it finds in the argument into hard quotes. See the Qcontext discussion above.
uIf the argument is enclosed in quotes, then remove them before entering it.
DThe argument is to be decremented by one. It it is a valid numeric constant, compute its value, decrement it, and then redisplay it. If it is not a valid numeric constant append "-1" to it.
HThis is a deprecated speciality operator which takes the argument as a hexadecimal constant which must be broken into a three part comma-delimited string.
PThis is a speciality operator. The argument is an identifier with the possible form name1.name. Only the name1 part is desired.



Panel
bgColorCCFFFF
titleTable of Contents

Table of Contents