BNF Grammar |
This appendix provides a complete description of symbols, operators, and directives for MASM 6.1. It uses the Backus-Naur Form (BNF) for grammar notation. You can use BNF grammar to determine the exact syntax for any language component and find all available options for any MASM command.
BNF definitions consist of nonterminals and terminals. Nonterminals are placeholders within a BNF definition, defined elsewhere in the BNF grammar. Terminals are endpoints in a BNF definition, consisting of MASM 6.1 keywords. In this Appendix, all nonterminals appear in italics type and all terminals appear in bold type.
The conventions use different font attributes for different items in the BNF. The symbols and formats are as follows:
Attribute | Description |
| |
nonterminal | Italic type indicates nonterminals. |
RESERVED | Terminals in boldface type are literal reserved words and symbols that must be entered as shown. Characters in this context are always case insensitive. |
[[ ]] | Objects enclosed in double brackets ([[ ]]) are optional. The brackets do not actually appear in the source code. |
| | A vertical bar indicates a choice between the items on each side of the bar. |
.8086 | Underlined items indicate the default option if one is given. |
default typeface | Characters in the set described or listed can be used as terminals in MASM statements. |
|
To illustrate the use of the BNF, Figure B.1 diagrams the definition of the TYPEDEF directive, starting with the nonterminal typedefDir.
The BNF grammar allows recursive definitions. For example, the grammar uses qualifiedType as a possible definition for qualifiedType, which is also a component of the definition for qualifier.
Figure B.1 BNF Definition of the TYPEDEF Directive
Nonterminal | Definition |
| |
;; | endOfLine |
=Dir | id = immExpr ;; |
addOp | + | - |
aExpr | term |
|
Nonterminal | Definition |
| |
altId | id |
arbitraryText | charList |
asmInstruction | mnemonic [[ exprList ]] |
assumeDir | ASSUME assumeList ;; |
assumeList | assumeRegister |
assumeReg | register : assumeVal |
assumeRegister | assumeSegReg |
assumeSegReg | segmentRegister : assumeSegVal |
assumeSegVal | frameExpr |
assumeVal | qualifiedType |
bcdConst | [[ sign ]] decNumber |
binaryOp | == | != | >= | <= | > | < | & |
bitDef | bitFieldId : bitFieldSize [[ = constExpr ]] |
bitDefList | bitDef |
bitFieldId | id |
bitFieldSize | constExpr |
blockStatements | directiveList |
bool | TRUE | FALSE |
byteRegister | AL | AH | BL | BH | CL | CH | DL | DH |
cExpr | aExpr |
character | Any character with ordinal in the range 0255 |
charList | character |
className | string |
commDecl | [[ nearfar ]] [[ langType ]] id : commType |
commDir | COMM commList ;; |
comment | ; text ;; |
|
Nonterminal | Definition |
| |
commentDir | COMMENT delimiter |
commList | commDecl |
commType | type |
constant | digits [[ radixOverride ]] |
constExpr | expr |
contextDir | PUSHCONTEXT contextItemList ;; |
contextItem | ASSUMES | RADIX | LISTING | CPU | ALL |
contextItemList | contextItem |
controlBlock | whileBlock |
controlDir | controlIf |
controlElseif | .ELSEIF cExpr ;; |
controlIf | .IF cExpr ;; |
coprocessor | .8087 | .287 | .387 | .NO87 |
crefDir | crefOption ;; |
crefOption | .CREF |
cxzExpr | expr |
dataDecl | DB | DW | DD | DF | DQ | DT | dataType | typeId |
dataDir | [[ id ]] dataItem ;; |
|
Nonterminal | Definition |
| |
dataItem | dataDecl scalarInstList |
dataType | BYTE | SBYTE | WORD | SWORD | DWORD |
decdigit | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
decNumber | decdigit |
delimiter | Any character except whiteSpaceCharacter |
digits | decdigit |
directive | generalDir |
directiveList | directive |
distance | nearfar |
e01 | e01 orOp e02 |
e02 | e02 AND e03 |
e03 | NOT e04 |
e04 | e04 relOp e05 |
e05 | e05 addOp e06 |
e06 | e06 mulOp e07 |
e07 | e07 addOp e08 |
e08 | HIGH e09 |
|
Nonterminal | Definition |
| |
e09 | OFFSET e10 |
e10 | e10 . e11 |
e11 | ( expr ) |
echoDir | ECHO arbitraryText ;; |
elseifBlock | elseifStatement ;; |
elseifStatement | ELSEIF constExpr |
|
Nonterminal | Definition |
| |
endDir | END [[ immExpr ]] ;; |
endpDir | procId ENDP ;; |
endsDir | id ENDS ;; |
equDir | textMacroId EQU equType ;; |
equType | immExpr |
errorDir | errorOpt ;; |
errorOpt | .ERR [[ textItem ]] |
exitDir | .EXIT [[ expr ]] ;; |
exitmDir: | EXITM |
exponent | E [[ sign ]] decNumber |
expr | SHORT e05 |
exprList | expr |
externDef | [[ langType ]] id [[ ( altId ) ]] : externType |
externDir | externKey externList ;; |
externKey | EXTRN | EXTERN | EXTERNDEF |
externList | externDef |
externType | ABS |
fieldAlign | constExpr |
fieldInit | [[ initValue ]] |
|
Nonterminal | Definition |
| |
fieldInitList | fieldInit |
fileChar | delimiter |
fileCharList | fileChar |
fileSpec | fileCharList |
flagName | ZERO? | CARRY? | OVERFLOW? |
floatNumber | [[ sign ]] decNumber . [[ decNumber ]] [[ exponent ]] |
forcDir | FORC | IRPC |
forDir | FOR | IRP |
forParm | id [[ : forParmType ]] |
forParmType | REQ |
frameExpr | SEG id |
generalDir | modelDir | segOrderDir | nameDir |
gpRegister | AX | EAX | BX | EBX | CX | ECX | DX | EDX |
groupDir | groupId GROUP segIdList |
groupId | id |
hexdigit | a | b | c | d | e | f |
|
Nonterminal | Definition |
| |
id | alpha |
idList | id |
ifDir | ifStatement ;; |
ifStatement | IF constExpr |
immExpr | expr |
includeDir | INCLUDE fileSpec ;; |
includeLibDir | INCLUDELIB fileSpec ;; |
initValue | immExpr |
inSegDir | [[ labelDef ]] inSegmentDir |
inSegDirList | inSegDir |
|
Nonterminal | Definition |
| |
inSegmentDir | instruction |
instrPrefix | REP | REPE | REPZ | REPNE | REPNZ | LOCK |
instruction | [[ instrPrefix ]] asmInstruction |
invokeArg | register :: register |
invokeDir | INVOKE expr [[ , [[ ;; ]] invokeList ]] ;; |
invokeList | invokeArg |
keyword | Any reserved word |
keywordList | keyword |
labelDef | id : |
labelDir | id LABEL qualifiedType ;; |
langType | C | PASCAL | FORTRAN | BASIC |
listDir | listOption ;; |
listOption | .LIST |
localDef | LOCAL idList ;; |
localDir | LOCAL parmList ;; |
localDirList | localDir |
|
Nonterminal | Definition |
| |
localList | localDef |
macroArg | % constExpr |
macroArgList | macroArg |
macroBody | [[ localList ]] |
macroCall | id macroArgList ;; |
macroDir | id MACRO [[ macroParmList ]] ;; |
macroFor | forDir forParm , < macroArgList > ;; |
macroForc | forcDir id , textLiteral ;; |
macroFuncId | id |
macroId | macroProcId |
macroIdList | macroId |
macroLabel | id |
macroParm | id [[ : parmType ]] |
macroParmList | macroParm |
macroProcId | id |
macroRepeat | repeatDir constExpr ;; |
macroStmt | directive |
|
Nonterminal | Definition |
| |
macroStmtList | macroStmt ;; |
macroWhile | WHILE constExpr ;; |
mapType | ALL | NONE | NOTPUBLIC |
memOption | TINY | SMALL | MEDIUM | COMPACT |
mnemonic | Instruction name |
modelDir | .MODEL memOption [[ , modelOptlist ]] ;; |
modelOpt | langType |
modelOptlist | modelOpt |
module | [[ directiveList ]] endDir |
mulOp | * | / | MOD |
nameDir | NAME id ;; |
nearfar | NEAR | FAR |
nestedStruct | structHdr [[ id ]] ;; |
offsetDir | offsetDirType ;; |
offsetDirType | EVEN |
offsetType | GROUP | SEGMENT | FLAT |
oldRecordFieldList | [[ constExpr ]] |
optionDir | OPTION optionList ;; |
|
Nonterminal | Definition |
| |
optionItem | CASEMAP : mapType |
optionList | optionItem |
optText | , textItem |
orOp | OR | XOR |
oVisibility | PUBLIC | PRIVATE | EXPORT |
pageDir | PAGE [[ pageExpr ]] ;; |
pageExpr | + |
pageLength | constExpr |
pageWidth | constExpr |
parm | parmId [[ : qualifiedType ]] |
parmId | id |
parmList | parm |
parmType | REQ |
pOptions | [[ distance ]] [[ langType ]] [[ oVisibility ]] |
primary | expr binaryOp expr |
|
Nonterminal | Definition |
| |
procDir | procId PROC [[ pOptions ]] [[ < macroArgList > ]] |
processor | .8086 |
processorDir | processor ;; |
procId | id |
procParmList | [[ , [[ ;; ]] parmList ]] |
protoArg | [[ id ]] : qualifiedType |
protoArgList | [[ , [[ ;; ]] protoList ]] |
protoList | protoArg |
protoSpec | [[ distance ]] [[ langType ]] [[ protoArgList ]] |
protoTypeDir | id PROTO protoSpec |
pubDef | [[ langType ]] id |
publicDir | PUBLIC pubList ;; |
pubList | pubDef |
purgeDir | PURGE macroIdList |
qualifiedType | type |
qualifier | qualifiedType |
quote | |
radixDir | .RADIX constExpr ;; |
radixOverride | h | o | q | t | y |
recordConst | recordTag { oldRecordFieldList } |
recordDir | recordTag RECORD bitDefList ;; |
recordFieldList | [[ constExpr ]] |
|
Nonterminal | Definition |
| |
recordInstance | { [[ ;; ]] recordFieldList [[ ;; ]] } |
recordInstList | recordInstance |
recordTag | id |
register | specialRegister |
regList | register |
relOp | EQ | NE | LT | LE | GT | GE |
repeatBlock | .REPEAT ;; |
repeatDir | REPEAT | REPT |
scalarInstList | initValue |
segAlign | BYTE | WORD | DWORD | PARA | PAGE |
segAttrib | PUBLIC |
segDir | .CODE [[ segId ]] |
segId | id |
segIdList | segId |
segmentDef | segmentDir [[ inSegDirList ]] endsDir |
segmentDir | segId SEGMENT [[ segOptionList ]] ;; |
segmentRegister | CS | DS | ES | FS | GS | SS |
|
Nonterminal | Definition |
| |
segOption | segAlign |
segOptionList | segOption |
segOrderDir | .ALPHA | .SEQ | .DOSSEG | DOSSEG |
segRO | READONLY |
segSize | USE16 | USE32 | FLAT |
shiftOp | SHR | SHL |
sign | - | + |
simpleExpr | ( cExpr ) |
simpleSegDir | segDir ;; |
sizeArg | id |
specialChars | : | . | [[ | ]] | ( | ) | < | > | { | } |
specialRegister | CR0 | CR2 | CR3 |
stackOption | NEARSTACK | FARSTACK |
startupDir | .STARTUP ;; |
stext | stringChar |
string | quote [[ stext ]] quote |
stringChar | quote quote |
structBody | structItem ;; |
structDir | structTag structHdr [[ fieldAlign ]] |
structHdr | STRUC | STRUCT | UNION |
|
Nonterminal | Definition |
| |
structInstance | < [[ fieldInitList ]] > |
structInstList | structInstance |
structItem | dataDir |
structTag | id |
term | simpleExpr |
text | textLiteral |
textDir | id textMacroDir ;; |
textItem | textLiteral |
textLen | constExpr |
textList | textItem |
textLiteral | < text >;; |
textMacroDir | CATSTR [[ textList ]] |
textMacroId | id |
textStart | constExpr |
titleDir | titleType arbitraryText ;; |
titleType | TITLE | SUBTITLE | SUBTTL |
type | structTag |
typedefDir | typeId TYPEDEF qualifier |
|
Nonterminal | Definition |
| |
typeId | id |
unionTag | id |
untilDir | .UNTIL cExpr ;; |
usesRegs | USES regList |
whileBlock | .WHILE cExpr ;; |
whiteSpaceCharacter | ASCII 8, 9, 1113, 26, 32 |