Skip to content

AST Specification

M2SF Project Administrator edited this page May 30, 2017 · 6 revisions

Abstract Syntax Tree

M2J encodes valid Modula-2 input in memory as an abstract syntax tree (AST).

The AST uses three kinds of nodes.

  • an EMPTY sentinel node
  • non-terminal nodes
  • terminal nodes

The Sentinel Node

The sentinel node EMPTY, is used to encode the absence of an optional sub-node in non-terminal nodes.

Non-Terminal Nodes

Non-terminal nodes are used to encode non-terminal symbols such as modules, imports, definitions, declarations, statements and expressions.

AST, DEFMOD, IMPLIST, IMPORT, UNQIMP, DEFLIST, CONSTDEF, TYPEDEF, PROCDEF, SUBR, ENUM, SET, ARRAY, RECORD, EXTREC, VRNTREC, POINTER, PROCTYPE, INDEXLIST, FIELDLISTSEQ, FIELDLIST, VFLISTSEQ, VFLIST, VARIANTLIST, VARIANT, CLABELLIST, CLABELS, FTYPELIST, OPENARRAY, CONSTP, VARP, FPARAMLIST, FPARAMS, IMPMOD, BLOCK, DECLLIST, TYPEDECL, VARDECL, PROC, MODDECL, VSR, VSFIELD, EXPORT, QUALEXP, STMTSEQ, ASSIGN, PCALL, RETURN, WITH, IF, SWITCH, LOOP, WHILE, REPEAT, FORTO, EXIT, ARGS, ELSIFSEQ, ELSIF, CASELIST, CASE, ELEMLIST, RANGE, FIELD, INDEX, DESIG, DEREF, NOT, AND, OR, EQ, NEQ, LT, LTEQ, GT, GTEQ, IN, NEG, PLUS, MINUS, STAR, SLASH, DIV, MOD, SETDIFF, FCALL, SETVAL.

Terminal Nodes

Terminal nodes are used to encode terminal symbols such as filenames, options, identifiers, integer literals, real number literals, character code and quoted literals.

FILENAME, OPTIONS, IDENT, IDENTLIST, QUALIDENT, INTVAL, REALVAL, CHRVAL, QUOTEDVAL.

Graphical Representation

AST nodes are represented graphically as follows:

Non-Terminal Nodes

Nodes are represented by rectangular boxes. Arrows indicate subnode connections.

node-legend

Terminal Nodes

The subnodes of terminal nodes are filled in grey.

termnode-legend

Labels

Labels are represented by rounded boxes.

label-legend

Alternatives

Labels with multiple connections represent alternatives.

altlabel-legend

Serialised Representation

Any AST node may be represented in a serialised format of the form

( nodetype subnode-0 subnode-1 subnode-2 ... subnode-N )

where the actual number of sub-nodes is dependent on the node type.

This form of tree representation is called an S-expression.

AST Node Reference

The structure of the common AST is described in detail below.

Empty Node

The EMPTY node encodes the absence of an optional sub-node.

Graph

empty

S-Expression

emptyNode :=
  '(' EMPTY ')'
  ;

Root Node

The AST node encodes the root of the syntax tree.

Graph

root

S-Expression

astRootNode :=
  '(' AST filename options compilationUnit ')'
  ;

filename := filenameNode ; /* terminal node */

options := optionsNode ; /* terminal node */

compilationUnit :=
  defModuleNode | impModuleNode
  ;

Definition Module Node

The DEFMOD node encodes a definition module.

Graph

defmod

S-Expression

defModuleNode :=
  '(' DEFMOD moduleIdent importList definitionList ')'
  ;

moduleIdent := identNode ; /* terminal node */

importList :=
  importListNode | emptyNode
  ;

definitionList :=
  definitionListNode | emptyNode
  ;

Import List Node

The IMPLIST node encodes the entirety of import directives in a module.

Graph

implist

S-Expression

importListNode :=
  '(' IMPLIST import+ ')'
  ;

Import Nodes

There are two types of import nodes:

IMPORT, UNQIMP.

imp-label

import :=
  importNode | unqImportNode
  ;

Qualified Import Node

The IMPORT node encodes a qualified import directive.

Graph

import

S-Expression

importNode :=
  '(' IMPORT identList ')'
  ;
  
identList := identListNode ; /* terminal node */

Unqualified Import Node

The UNQIMP node encodes an unqualified import directive.

Graph

unqimp

S-Expression

unqImportNode :=
  '(' UNQIMP moduleIdent identList ')'
  ;

Definition List Node

The DEFLIST node encodes one or more definitions.

Graph

deflist

S-Expression

definitionListNode :=
  '(' DEFLIST definition+ ')'
  ;

Definition Nodes

There are four types of definition nodes:

CONSTDEF, TYPEDEF, VARDECL, PROCDEF.

definition-label

  
definition :=
  constDefNode | typeDefNode | varDeclNode | ProcDefNode
  ;

Constant Definition Node

The CONSTDEF node encodes a constant definition.

Graph

constdef

S-Expression

constDefNode :=
  '(' CONSTDEF identNode exprNode ')'
  ;

Type Definition Node

The TYPEDEF node encodes a type definition.

Graph

typedef

S-Expression

typeDefNode :=
  '(' TYPEDEF identNode ( typeNode | emptyNode ) ')'
  ;

Procedure Definition Node

The PROCDEF node encodes a procedure definition.

Graph

procdef

S-Expression

procDefNode :=
  '(' PROCDEF identNode formalParamList returnedType ')'
  ;

formalParamList :=
  formalParamListNode | emptyNode
  ;

returnedType := qualidentNode ; /* terminal node */

Type Nodes

There are eleven nodes that may represent the definition part of a type definition or an anonymous type.

IDENT, QUALIDENT, SUBR, ENUM, SET, ARRAY, RECORD, EXTREC, VRNTREC, POINTER, PROCTYPE.

type-label

typeNode :=
  identNode | qualidentNode |
  subrTypeNode | enumTypeNode | setTypeNode | arrayTypeNode | recTypeNode |
  extRecTypeNode | vrntRecTypeNode | pointerTypeNode | procTypeNode
  ;

Nine nodes may represent the type definition part of a field definition or an array base type.

IDENT, QUALIDENT, SUBR, ENUM, SET, ARRAY, RECORD, POINTER, PROCTYPE.

fieldtype-label

fieldType :=
  identNode | qualidentNode | subrTypeNode | enumTypeNode | setTypeNode |
  arrayTypeNode | recTypeNode | pointerTypeNode | procTypeNode
  ;

Three nodes may represent the type definition part of a derived type.

IDENT, QUALIDENT, SUBR.

derivedtype-label

derivedType :=
  identNode | qualidentNode | subrTypeNode
  ;

Three nodes represent the type definition part of a record type.

RECORD, EXTREC, VRNTREC.

recordtype-label

recordType :=
  recTypeNode | extRecTypeNode | vrntRecTypeNode
  ;

Subrange Type Definition Node

The SUBR node encodes a subrange type definition.

Graph

subrange

S-Expression

subrTypeNode :=
  '(' SUBR lowerBound upperBound subrBaseType ')'
  ;

lowerBound := exprNode ;

upperBound := exprNode ;

subrBaseType :=
  qualidentNode | emptyNode
  ;

Enumeration Type Definition Node

The ENUM node encodes an enumeration type definition.

Graph

enumeration

S-Expression

enumTypeNode :=
  '(' ENUM identListNode ')'
  ;

Set Type Definition Node

The SET node encodes a set type definition.

Graph

set

S-Expression

setTypeNode :=
  '(' SET countableType ')'
  ;

countableType :=
  qualidentNode | subrTypeNode | enumTypeNode
  ; 

Array Type Definition Node

The ARRAY node encodes an array type definition.

Graph

array

S-Expression

arrayTypeNode :=
  '(' ARRAY indexTypeListNode arrayBaseType ')'
  ;

arrayBaseType := fieldType ;

Simple Record Type Definition Node

The RECORD node encodes a non-variant non-extensible record type definition.

Graph

record

S-Expression

recTypeNode :=
  '(' RECORD fieldListSeqNode ')'
  ;

Pointer Type Definition Node

The POINTER node encodes a pointer type definition.

Graph

pointer

S-Expression

pointerTypeNode :=
  '(' POINTER typeNode ')'
  ;

Procedure Type Definition Node

The PROCTYPE node encodes a procedure type definition.

Graph

proctype

S-Expression

procTypeNode :=
  '(' PROCTYPE formalTypeList returnedType ')'
  ;

formalTypeList :=
  formalTypeListNode | emptyNode
  ;

returnedType :=
   qualidentNode | emptyNode
   ;

Extensible Record Type Definition Node

The EXTREC node encodes an extensible record type definition.

Graph

extrec

S-Expression

extRecTypeNode :=
  '(' EXTREC recBaseType fieldListSeqNode ')'
  ;

recBaseType := qualidentNode ; /* terminal node */

Variant Record Type Definition Node

The VRNTREC node encodes a variant record type definition.

Graph

vrntrec

S-Expression

variantRecTypeNode :=
  '(' VRNTREC variantFieldListSeqNode ')'
  ;

Array Index Type List Node

The INDEXLIST node encodes one or more index types within an array type definition.

Graph

indexlist

S-Expression

indexTypeListNode :=
  '(' INDEXLIST indexType+ ')'
  ;

indexType := countableType ;

Simple FieldList Sequence Node

The FIELDLISTSEQ node encodes a non-variant field list sequence within a record type definition.

Graph

fieldlistseq

S-Expression

fieldListSeqNode :=
  '(' FIELDLISTSEQ fieldListNode+ ')'
  ;

Simple FieldList Node

The FIELDLIST node encodes a non-variant field list within a field list sequence

Graph

fieldlist

S-Expression

fieldListNode :=
  '(' FIELDLIST identListNode fieldType ')'
  ;

Variant FieldList Sequence Node

The VFLISTSEQ node encodes a field list sequence within a variant record type definition.

Graph

vflistseq

S-Expression

variantFieldListSeqNode :=
  '(' VFLISTSEQ ( fieldListNode | variantFieldListNode )+ ')'
  ;

Variant Field List Node

The VFLIST node encodes a variant field list within a variant record field list sequence.

Graph

vflist

S-Expression

variantFieldListNode :=
  '(' VFLIST caseIdent caseType variantList defaultFieldListSeq ')'
  ;

caseIdent :=
  identNode | emptyNode
  ;

caseType := qualidentNode ; /* terminal node */

defaultFieldListSeq :=
  fieldListSeqNode | emptyNode
  ;

Variant List Node

The VARIANTLIST node encodes a variant list within a variant field list.

Graph

variantlist

S-Expression

variantList :=
  '(' VARIANTLIST variantNode+ ')'
  ;

Variant Node

The VARIANT node encodes a variant within a variant list.

Graph

variant

S-Expression

variantNode :=
  '(' VARIANT caseLabelListNode fieldListSeqNode ')'
  ;

Case Label List Node

The CLABELLIST node encodes a case label list within a variant record definition or case statement.

Graph

clabellist

S-Expression

caseLabelListNode :=
  '(' CLABELLIST caseLabelsNode+ ')
  ;

Case Labels Node

The CLABELS node encodes start and end labels within a case label list.

Graph

clabels

S-Expression

caseLabelsNode :=
  '(' CLABELS startLabel endLabel ')'
  ;

startLabel := exprNode ;

endLabel :=
  exprNode | emptyNode
  ;

Formal Type List Node

The FTYPELIST node encodes a formal type list within a procedure type definition.

Graph

ftypelist

S-Expression

formalTypeListNode :
  '(' FTYPELIST formalType+ ')'
  ;

formalType :=
  simpleFormalType | attrFormalType
  ;

simpleFormalType :=
  typeIdent | openArrayTypeNode
  ;

attrFormalType :=
  constAttrFormalTypeNode | varAttrFormalTypeNode
  ;

Open Array Parameter Node

The OPENARRAY node encodes an open array parameter within a formal type list.

Graph

openarray

S-Expression

openArrayTypeNode :=
  '(' OPENARRAY typeIdent ')'
  ;

typeIdent := qualidentNode ; /* terminal node */

CONST Parameter Node

The CONSTP node encodes a CONST parameter within a formal type list.

Graph

constp

S-Expression

constAttrFormalTypeNode :=
  '(' CONSTP simpleFormalType ')'
  ;

VAR Parameter Node

The VARP node encodes a VAR parameter within a formal type list.

Graph

varp

S-Expression

varAttrFormalTypeNode :=
  '(' VARP simpleFormalType ')'
  ;

Formal Parameter List Node

The FPARAMLIST node encodes a formal parameter list within a procedure type definition or procedure signature.

Graph

fparamlist

S-Expression

formalParamListNode :=
  '(' FPARAMLIST formalParamsNode+ ')'
  ;

Formal Parameters Node

The FPARAMS node encodes formal parameters within a formal parameter list.

Graph

fparams

S-Expression

formalParamsNode :=
  '(' FPARAMS identListNode formalTypeNode ')'
  ;

Program Or Implementation Module Node

The IMPMOD node encodes an implementation module.

Graph

impmod

S-Expression

impModuleNode :=
  '(' IMPMOD moduleIdent importListNode blockNode ')'
  ;

Block Node

The BLOCK node encodes a block within a module or procedure.

Graph

block

S-Expression

blockNode :=
  '(' BLOCK declarationList body ')'
  ;

declarationList :=
  declarationListNode | emptyNode
  ;

body :=
  statementSeqNode | emptyNode
  ;

Declaration List Node

The DECLLIST node encodes one or more declarations within a block.

Graph

decllist

S-Expression

declarationListNode :=
  '(' DECLLIST declarationNode+ ')'
  ;

Declaration Nodes

There are five types of declaration nodes:

CONSTDEF, TYPEDECL, VARDECL, PROC, MODDECL.

declaration-label

declarationNode :=
  constDefNode | typeDeclNode | varDeclNode | procDeclNode | modDeclNode
  ;

Type Declaration Node

The TYPEDECL node encodes a type declaration.

Graph

typedecl

S-Expression

typeDeclNode :=
  '(' TYPEDECL identNode ( typeNode | vsrTypeNode ) ')'
  ;

Variable Declaration Node

The VARDECL node encodes a variable or field declaration.

Graph

vardecl

S-Expression

varDeclNode :=
  '(' VARDECL identListNode fieldType ')'
  ;

Procedure Declaration Node

The PROC node encodes a procedure declaration.

Graph

proc

S-Expression

procDeclNode :=
  '(' PROC identNode formalParamListNode returnedType blockNode ')'
  ;

Module Declaration Node

The MODDECL node encodes a local module declaration.

Graph

moddecl

S-Expression

modDeclNode :=
  '(' MODDECL moduleIdent importListNode exportList blockNode ')'
  ;

exportList :=
  unqualExportNode | qualExportNode | emptyNode
  ;

Variable Size Record Type Declaration Node

The VSR node encodes a variable size record type declaration.

Graph

vsr

S-Expression

vsrTypeNode :=
  '(' VSR fieldListSeqNode varSizeFieldNode ')'
  ;

Variable Size Field Node

The VSFIELD node encodes the indeterminate field of a variable size record type.

Graph

vsfield

S-Expression

varSizeFieldNode :=
  '(' VSFIELD varSizeField determinantField varSizeFieldType ')'
  ;

varSizeField := identNode ; /* terminal node */

determinantField := identNode ; /* terminal node */

varSizeFieldType := qualidentNode ; /* terminal node */

Unqualified Export Node

The EXPORT node encodes an unqualified export directive within a local module declaration.

Graph

export

S-Expression

unqualExportNode :=
  '(' EXPORT identListNode ')'
  ;

Qualified Export Node

The QUALEXP node encodes a qualified export directive within a local module declaration.

Graph

qualexp

S-Expression

qualExportNode :=
  '(' QUALEXP identListNode ')'
  ;

Statement Sequence Node

The STMTSEQ node encodes a statement sequence.

Graph

stmtseq

S-Expression

statementSeqNode :=
  '(' STMTSEQ statementNode+ ')'
  ;

Statement Nodes

There are eleven types of statement nodes:

ASSIGN, PCALL, RETURN, WITH, IF, SWITCH, LOOP, WHILE, REPEAT, FORTO, EXIT.

stmt-label

statementNode :=
  assignmentNode | controlStmt | withStmtNode
  ;

Nine statement nodes represent control statements:

PCALL, RETURN, IF, SWITCH, LOOP, WHILE, REPEAT, FORTO, EXIT.

ctrlstmt-label

controlStmt :=
  procCallNode | returnStmtNode | ifStmtNode | caseStmtNode | loopCtrlStmt
  ;

Five statement nodes represent loop control statements:

LOOP, WHILE, REPEAT, FORTO, EXIT.

loopctrlstmt-label

loopCtrlStatement :=
  loopStmtNode | whileStmtNode | repeatStmtNode | ForToStmtNode | exitStmtNode
  ;

Assignment Node

The ASSIGN node encodes an assignment statement.

Graph

assign

S-Expression

assignmentNode :=
  '(' ASSIGN designator exprNode ')'
  ;

designator :=
  identNode | qualidentNode | derefNode | designatorNode
  ;

Procedure Call Node

The PCALL node encodes a procedure call statement.

Graph

pcall

S-Expression

procCallNode :=
  '( PCALL designator actualParams ')'
  ;

actualParams :=
  actualParamsNode | emptyNode
  ;

RETURN Statement Node

The RETURN node encodes a RETURN statement.

Graph

return

S-Expression

returnStmtNode :=
  '(' RETURN returnValue ')'
  ;

returnValue :=
  exprNode | emptyNode
  ;

WITH Statement Node

The WITH node encodes a WITH statement.

Graph

with

S-Expression

withStmtNode :=
  '(' WITH designator statementSeqNode ')'
  ;

IF Statement Node

The IF node encodes an IF statement.

Graph

if

S-Expression

ifStmtNode :=
  '(' IF exprNode ifBranch elsifSeq elseBranch ')'
  ;

ifBranch := statementSeqNode ;

elsifSeq :=
  elsifSeqNode | emptyNode
  ;

elseBranch :=
  statementSeqNode | emptyNode
  ;

CASE Statement Node

The SWITCH node encodes a CASE statement.

Graph

switch

S-Expression

caseStmtNode :=
  '(' SWITCH designator caseListNode elseBranch ')'
  ;

LOOP Statement Node

The LOOP node encodes a LOOP statement.

Graph

loop

S-Expression

loopStmtNode :=
  '(' LOOP statementSeqNode ')'
  ;

WHILE Statement Node

The WHILE node encodes a WHILE statement.

Graph

while

S-Expression

whileStmtNode :=
  '(' WHILE exprNode statementSeqNode ')'
  ;

REPEAT Statement Node

The REPEAT node encodes a REPEAT statement.

Graph

repeat

S-Expression

repeatStmtNode :=
  '(' REPEAT statementSeqNode exprNode ')'
  ;

FOR Statement Node

The FORTO node encodes a FOR statement.

Graph

forto

S-Expression

forToStmtNode :=
  '(' FORTO identNode startValue endValue stepValue statementSeqNode ')'
  ;

startValue : exprNode ;

endValue := expNode ;

stepValue :=
  exprNode | emptyNode
  ;

EXIT Statement Node

The EXIT node encodes an EXIT statement.

Graph

exit

S-Expression

exitStmtNode :=
  '(' EXIT ')'
  ;

Actual Parameters Node

The ARGS node encodes actual parameters in a procedure or function call.

Graph

args

S-Expression

actualParamsNode :=
  '(' ARGS exprNode+ ')'
  ;

ELSIFSEQ Node

The ELSIFSEQ node encodes an ELSIF sequence within an IF statement.

Graph

elsifseq

S-Expression

elsifSeqNode :=
  '(' ELSIFSEQ elsifNode+ ')'
  ;

ELSIF Node

The ELSIF node encodes a single ELSIF branch within an IF statement.

Graph

elsif

S-Expression

elsifNode :=
  '(' ELSIF exprNode statementSeqNode ')'
  ;

CASE List Node

The CASELIST node encodes a case list within a CASE statement.

Graph

caselist

S-Expression

caseListNode :=
  '(' CASELIST caseBranchNode+ ')'
  ;

CASE Branch Node

The CASE node encodes a case branch within a CASE statement.

Graph

case

S-Expression

caseBranchNode :=
  '(' CASE caseLabelListNode statementSeqNode ')'
  ;

Set Element List Node

The ELEMLIST node encodes the element list within a set value.

Graph

elemlist

S-Expression

elementListNode :=
  '(' ELEMLIST element+ ')'
  ;

element :=
  expr | range
  ;

Expression Range Node

The RANGE node encodes a value range.

Graph

range

S-Expression

range :=
  '(' RANGE lowerValue upperValue ')'
  ;

lowerValue := exprNode ;

upperValue := exprNode ;

Record Field Selector Node

The FIELD node encodes a record field selector.

Graph

field

S-Expression

fieldSelectorNode :=
  '(' FIELD selector ')'
  ;

selector :=
  qualidentNode | designatorNode
  ;

Array Index Node

The INDEX node encodes an array subscript selector.

Graph

index

S-Expression

arrayIndexNode :=
  '(' INDEX subscript+ ')'
  ;

subscript := exprNode ;

Designator Node

The DESIG node encodes a designator.

Graph

desig

S-Expression

designatorNode :=
  '(' DESIG head tail ')'
  ;

head :=
  qualidentNode | derefNode
  ;

tail :=
  fieldSelectorNode | arrayIndexNode | emptyNode
  ;

Pointer Dereference Node

The DEREF node encodes a pointer dereference.

Graph

deref

S-Expression

derefNode :=
  '(' DEREF pointer ')'
  ;

pointer :=
  qualident | derefNode | designatorNode
  ;

Expression Nodes

There are 25 nodes that may represent expressions or sub-expressions:

NOT, AND, OR, EQ, NEQ, LT, LTEQ, GT, GTEQ, IN, NEG, PLUS, MINUS, STAR, SLASH, DIV, MOD, SETDIFF, DESIG, FCALL, SETVAL. INTVAL, REALVAL, CHRVAL, QUOTEDVAL.

expr-label

expr :=
  boolExpr | relationalExpr | arithmeticExpr |
  designator | funcCallNode | setValNode | literalValue
  ;

There are three boolean expression nodes:

NOT, AND, OR.

boolexpr-label

boolExpr :=
  notNode | andNode | orNode
  ;

There are seven relational expression nodes:

EQ, NEQ, LT, LTEQ, GT, GTEQ, IN.

relexpr-label

relationalExpr :=
  eqNode | neqNode | ltNode | ltEqNode | gtNode | gtEqNode | inNode
  ;

There are eight arithmetic expression nodes:

NEG, PLUS, MINUS, STAR, SLASH, DIV, MOD, SETDIFF.

arithmexpr-label

arithmeticExpr :=
  negNode | plusNode | minusNode | starNode | slashNode |
  divNode | modulusNode | setDiffNode
  ;

There are four literal value expression nodes:

INTVAL, REALVAL, CHRVAL, QUOTEDVAL.

litval-label

literalValue :=
  intValNode | realValNode | chrValNode | quotedValNode
  ;

Logical Negation Expression Node

The NOT node encodes an expression of the form NOT expr.

Graph

not

S-Expression

notNode :=
  '(' NOT right ')'
  ;

Logical Conjunction Expression Node

The AND node encodes an expression of the form expr1 AND expr2.

Graph

and

S-Expression

andNode :=
  '(' AND left right ')'
  ;

Logical Disjunction Expression Node

The OR node encodes an expression of the form expr1 OR expr2.

Graph

or

S-Expression

orNode :=
  '(' OR left right ')'
  ;

Equality Expression Node

The EQ node encodes an expression of the form expr1 = expr2.

Graph

eq

S-Expression

eqNode :=
  '(' EQ left right ')'
  ;

left : exprNode ;

Inequality Expression Node

The NEQ node encodes an expression of the form expr1 # expr2.

Graph

neq

S-Expression

neqNode :=
  '(' NEQ left right ')'
  ;

Less-Than Expression Node

The LT node encodes an expression of the form expr1 < expr2.

Graph

lt

S-Expression

ltNode :=
  '(' LT left right ')'
  ;

Less-Than-Or-Equal Expression Node

The LTEQ node encodes an expression of the form expr1 <= expr2.

Graph

lteq

S-Expression

ltEqNode :=
  '(' LTEQ left right ')'
  ;

Greater-Than Expression Node

The GT node encodes an expression of the form expr1 > expr2.

Graph

gt

S-Expression

gtNode :=
  '(' GT left right ')'
  ;

Greater-Than-Or-Equal Expression Node

The GTEQ node encodes an expression of the form expr1 >= expr2.

Graph

gteq

S-Expression

gtEqNode :=
  '(' GTEQ left right ')'
  ;

Set Membership Expression Node

The IN node encodes an expression of the form expr1 IN expr2.

Graph

in

S-Expression

inNode :=
  '(' IN left right ')'
  ;

Arithmetic Negation Expression Node

The NEG node encodes an expression of the form - expr.

Graph

neg

S-Expression

negNode :=
  '(' NEG right ')'
  ;

right : exprNode ;

Plus Expression Node

The PLUS node encodes an expression of the form expr1 + expr2.

Graph

plus

S-Expression

plusNode :=
  '(' PLUS left right ')'
  ;

Minus Expression Node

The MINUS node encodes an expression of the form expr1 - expr2.

Graph

minus

S-Expression

minusNode :=
  '(' MINUS left right ')'
  ;

Star Expression Node

The STAR node encodes an expression of the form expr1 * expr2.

Graph

star

S-Expression

starNode :=
  '(' STAR left right ')'
  ;

Slash Expression Node

The SLASH node encodes an expression of the form expr1 / expr2.

Graph

slash

S-Expression

slashNode :=
  '(' SLASH left right ')'
  ;

Euclidean Division Expression Node

The DIV node encodes an expression of the form expr1 DIV expr2.

Graph

div

S-Expression

divNode :=
  '(' DIV left right ')'
  ;

Remainder of Euclidean Division Expression Node

The MOD node encodes an expression of the form expr1 MOD expr2.

Graph

mod

S-Expression

modulusNode :=
  '(' MOD left right ')'
  ;

Set Difference Expression Node

The SETDIFF node encodes an expression of the form expr1 \ expr2.

Graph

setdiff

S-Expression

setDiffNode :=
  '(' SETDIFF left right ')'
  ;

Function Call Expression Node

The FCALL node encodes a function call expression.

Graph

fcall

S-Expression

funcCallNode :=
  '( FCALL designator actualParams ')'
  ;

Set Value Expression Node

The SETVAL node encodes a set value expression.

Graph

setval

S-Expression

setValNode :=
  '( SETVAL elementList setTypeIdent ')'
  ;

elementList :=
  actualParams | emptyNode
  ;

setTypeIdent :=
  ident | qualident | emptyNode
  ;

Filename Node

The FILENAME node encodes the filename of the source file.

Graph

filename

S-Expression

filenameNode :=
  '(' FILENAME '"' filename '"' ')'
  ;

Example

(FILENAME "parser.mod")

Compiler Options Node

The OPTIONS node encodes the compiler options used when compiling the source file.

Graph

options

S-Expression

optionsNode :=
  '(' OPTIONS ( '"' option-name '"' )+ ')'
  ;

Example

(OPTIONS "--pim4" "--no-synonyms" "--no-coroutines" ...)

Identifier Node

The IDENT node encodes an identifier.

Graph

ident

S-Expression

identNode :=
  '(' IDENT '"' Ident '"' ')'
  ;

Example

(IDENT "foobar")

Identifier List Node

The IDENTLIST node encodes an identifier list.

Graph

identlist

S-Expression

identListNode :=
  '(' IDENTLIST ( '"' Ident '"' )+ ')'
  ;

Example

(IDENTLIST "foo" "bar" "baz" ...)

Qualified Identifier Node

The QUALIDENT node encodes the component identifiers of a qualified identifier.

Graph

qualident

S-Expression

qualidentNode :=
  '(' QUALIDENT ( '"' Ident '"' ) ( '"' Ident '"' )+ ')'
  ;

Example

(QUALIDENT "foo" "bar" ...)

Whole Number Value Node

The INTVAL node encodes a whole number value.

Graph

intval

S-Expression

intValNode :=
  '(' INTVAL ( lexeme | '#' lexeme ) ')'
  ;

Examples

(INTVAL 12345)
(INTVAL #0x7FFF)

Real Number Value Node

The REALVAL node encodes a real number value.

Graph

realval

S-Expression

realValNode :=
  '(' REALVAL lexeme ')'
  ;

Examples

(REALVAL 1.234)
(REALVAL 5.678e9)

Character Code Value Node

The CHRVAL node encodes a character code value.

Graph

chrval

S-Expression

chrValNode :=
  '(' CHRVAL '#' lexeme ')'
  ;

Example

(CHRVAL #0u7F)

Quoted Character or String Value Node

The QUOTEDVAL node encodes a quoted character or string value.

Graph

quotedval

S-Expression

quotedValNode :=
  '(' QUOTEDVAL '"' lexeme '"' ')'
  ;

Example

(QUOTEDVAL "quoted character or string")

+++

Clone this wiki locally