Appendix B

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.

BNF Conventions

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.

 

 

How to Use the BNF Grammar

To illustrate the use of the BNF, Figure B.1 diagrams the definition of the TYPEDEF directive, starting with the nonterminal typedefDir.

The entries under each horizontal brace in Figure B.1 are terminals (such as NEAR16, NEAR32, FAR16, and FAR32) or nonterminals (such as qualifier, qualifiedType, distance, and protoSpec) that can be further defined. Each italicized nonterminal in the typedefDir definition is also an entry in the BNF. Three vertical dots indicate a branching definition for a nonterminal that, for the sake of simplicity, this figure does not illustrate.

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
| comment

=Dir

id = immExpr ;;

addOp

+ | -

aExpr

term
| aExpr && term

 

Nonterminal

Definition

altId

id

arbitraryText

charList

asmInstruction

mnemonic [[ exprList ]]

assumeDir

ASSUME assumeList ;;
| ASSUME NOTHING ;;

assumeList

assumeRegister
| assumeList , assumeRegister

assumeReg

register : assumeVal

assumeRegister

assumeSegReg
| assumeReg

assumeSegReg

segmentRegister : assumeSegVal

assumeSegVal

frameExpr
| NOTHING | ERROR

assumeVal

qualifiedType
| NOTHING | ERROR

bcdConst

[[ sign ]] decNumber

binaryOp

== | != | >= | <= | > | < | &

bitDef

bitFieldId : bitFieldSize [[ = constExpr ]]

bitDefList

bitDef
| bitDefList , [[ ;; ]] bitDef

bitFieldId

id

bitFieldSize

constExpr

blockStatements

directiveList
| .CONTINUE [[ .IF cExpr ]]
| .BREAK [[ .IF cExpr ]]

bool

TRUE | FALSE

byteRegister

AL | AH | BL | BH | CL | CH | DL | DH

cExpr

aExpr
| cExpr || aExpr

character

Any character with ordinal in the range 0–255
except linefeed (10)

charList

character
| charList character

className

string

commDecl

[[ nearfar ]] [[ langType ]] id : commType
[[ : constExpr ]]

commDir

COMM commList ;;

comment

; text ;;

 

Nonterminal

Definition

commentDir

COMMENT delimiter
text
text delimiter text ;;

commList

commDecl
| commList , commDecl

commType

type
| constExpr

constant

digits [[ radixOverride ]]

constExpr

expr

contextDir

PUSHCONTEXT contextItemList ;;
| POPCONTEXT contextItemList ;;

contextItem

ASSUMES | RADIX | LISTING | CPU | ALL

contextItemList

contextItem
| contextItemList , contextItem

controlBlock

whileBlock
| repeatBlock

controlDir

controlIf
| controlBlock

controlElseif

.ELSEIF cExpr ;;
directiveList
[[ controlElseif ]]

controlIf

.IF cExpr ;;
directiveList
[[ controlElseif ]]
[[ .ELSE ;;
directiveList ]]
.ENDIF ;;

coprocessor

.8087 | .287 | .387 | .NO87

crefDir

crefOption ;;

crefOption

.CREF
| .XCREF [[ idList ]]
| .NOCREF [[ idList ]]

cxzExpr

expr
| ! expr
| expr == expr
| expr != expr

dataDecl

DB | DW | DD | DF | DQ | DT | dataType | typeId

dataDir

[[ id ]] dataItem ;;

 

Nonterminal

Definition

dataItem

dataDecl scalarInstList
| structTag structInstList
| typeId structInstList
| unionTag structInstList
| recordTag recordInstList

dataType

BYTE | SBYTE | WORD | SWORD | DWORD
| SDWORD | FWORD | QWORD | TBYTE
| REAL4 | REAL8 | REAL10

decdigit

0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

decNumber

decdigit
| decNumber decdigit

delimiter

Any character except whiteSpaceCharacter

digits

decdigit
| digits decdigit
| digits hexdigit

directive

generalDir
| segmentDef

directiveList

directive
| directiveList directive

distance

nearfar
| NEAR16 | NEAR32 | FAR16 | FAR32

e01

e01 orOp e02
| e02

e02

e02 AND e03
| e03

e03

NOT e04
| e04

e04

e04 relOp e05
| e05

e05

e05 addOp e06
| e06

e06

e06 mulOp e07
| e06 shiftOp e07
| e07

e07

e07 addOp e08
| e08

e08

HIGH e09
| LOW e09
| HIGHWORD e09
| LOWWORD e09
| e09

 

Nonterminal

Definition

e09

OFFSET e10
| SEG e10
| LROFFSET e10
| TYPE e10
| THIS e10
| e09 PTR e10
| e09 : e10
| e10

e10

e10 . e11
| e10 [[ expr ]]
| e11

e11

( expr )
| [[ expr ]]
| WIDTH id
| MASK id
| SIZE sizeArg
| SIZEOF sizeArg
| LENGTH id
| LENGTHOF id
| recordConst
| string
| constant
| type
| id
| $
| segmentRegister
| register
|