<<>> <> <> <<>> IntCode Language Definition - As extracted from an analysis of the module ParseIntCodeImpl.mesa This grammar describes legal Mimosa intermediate code in its ASCII form, as nearly as I can determine from a reading of the intcode parser. That is, it is the result of reverse engineering. The names used in the grammar are meaningful, for the most part, and the intention is that this grammar will help compiler writers who need to deal with the intermediate code. Notation: The notation is a modified and extended form of BNF. Syntactic variables are written as sequences of upper and lower case letters and digits. Character constants are enclosed in single quotes. Parentheses are used for grouping. A variable, constant, or parenthesized group may be followed by a question mark, indicating that it is optional, or by an asterisk signifying that it may occur zero or any positive number of times. The vertical stroke separates alternatives. A subexpression may be preceded by a label consisting of an indentifier followed by a colon. The label generally is some sort of comment on the use of the following subexpression. IntCode = Node * Node = '{' INT[-1] ( varNode | constNode | blockNode | enableNode | declNode | assignNode | condNode | labelNode | gotoNode | applyNode | lambdaNode | returnNode | operNode | machineCodeNode | moduleNode | sourceNode | commentNode ) ? '}' varNode = 'var' variableFlags variableId location variableFlags = ('T' | 't' | 'F' | 'f' ) * variableId = INT[0] location = '(' ( systemLocation | globalVarLocation | localVarLocation | registerLocation | linkLocation | stackLocation | derefLocation | indexedLocation | fieldLocation | xfieldLocation | upLevelLocation | compositeLocation | escapeLocation | dummyLocation ) ')' constNode = 'const' (wordConst | bytesConst | refLiteralConst | numLiteral blockNode = 'block' nodeList nodeList = node * enableNode = 'enable' handlerContext:node handlerProc:node nodeList declNode = 'decl' var init:node assignNode = 'assign' lhs:var rhs:node condNode = 'cond' ( '(' 'test' tests:nodeList ')' body:node? ) * var = varNode labelNode = 'label' label node? label = '%' INT gotoNode = 'goto' label:label labNode:node ? applyNode = 'apply' proc:node args:nodeList handler:('!' context:node proc:node)? lambdaNode = 'lambda' parent:label? var? ( 'outer' | 'inner' | 'install' | 'init' | 'catch' | 'scope' | 'fork' )? bitsOut:INT? formalArgs:varList body:nodeList varList = '(' var* ')' returnNode = 'return' nodeList operNode = 'oper' operRep operRep = 'arith' ArithClass ( 'add' | 'sub' | 'mul' | 'div' | 'mod' | 'pow' | 'abs' | 'neg' | 'min' | 'max' ) | 'boolean' ( 'and' | 'not' | 'or' | 'xor' ) INT[defaultBits] | 'code' label INT FLAG | 'convert' to:ArithClass from:ArithClass | 'check' ArithClass ('eq' | 'lt' | 'le' | 'ne' | 'ge' | 'gt') | 'compare' ArithClass ('eq' | 'lt' | 'le' | 'ne' | 'ge' | 'gt') | 'mesa' ( 'addr' | 'all' | 'equal' | 'notEqual' | 'nilck' | 'alloc' | 'free' | 'fork' | 'join' | 'monitorEntry' | 'monitorExit' | 'notify' | 'broadcast' | 'wait' | 'unnamedError' | 'unwindError' | 'abortedError' | 'uncaughtError' | 'boundsError' | 'narrowFault' | 'signal' | 'error' | 'unwind' | 'resume' | 'reject' | 'copyGlobal' | 'startGlobal' | 'restartGlobal' | 'stopGlobal' | 'checkInit' | 'globalFrame' ) INT[] | 'cedar' ( 'simpleAssign' | 'simpleAssignInit' | 'complexAssign' | 'complexAssignInit' | 'new' | 'code' | 'narrow' | 'referentType' | 'procCheck' ) INT[] | 'escape' ID INT[] ArithClass = ( signed:('s' | 'S') | unsigned:('u' | 'U') | address:('a' | 'A') | real:('r' | 'R') | ('x' | 'X') INT[ORD[LAST[ArithClassKind]]] ) precision:INT[defaultBits]? checked:FLAG? machineCodeNode = 'machineCode' bytes bytes = ropeLiteral moduleNode = 'module' vars:varList procs:NodeList sourceNode = 'source' sourceRange nodeList sourceRange = (start:INT (chars:INT fileNum:INT?) ? ) ? commentNode = 'comment' msg:bytes systemLocation = 'system' ID globalVarLocation = 'globalVar' ID localVarLocation = 'localVar' ID label registerLocation = 'register' ID linkLocation = 'link' ID stackLocation = 'stack' offset:INT[] derefLocation = 'deref' node align:INT[defaultBits] indexedLocation = 'indexed' base:node index:node fieldLocation = 'field' offset:INT[] node xfieldLocation = 'xfield' offset:INT[] node upLevelLocation = 'upLevel' link:var reg:var format:ID compositeLocation = 'composite' list:nodeList escapeLocation = 'escape' id:ID offset:INT[] base:node dummyLocation = 'dummy'