OberonScript compiler

See http://www.ralphsommerer.com/obn.htm for more information.July 6, 2007

 

Scan

Scanner (tokenizer)

  

sym()

Next token

id

Ident, string, keyword

num

Numeric value

numtyp

intT, hexT, floatT

eat()

Advance scan position

Parse

Parser

  

next()

Next symbol

eat()

Check and consume symbol

top

Current top scope

push(o)

Push new scope (becomes new top)

add(o)

Append object to top scope

pop()

Close top scope

mark()

Index of last top-scope object

setT(i,t)

Fixup type on all sub-objects from i .. last

find(n,m)

Find object n in all scopes (top to bottom), or in module m (if not null)

findT(n,m)

Find type object n in all scopes (top to bottom), or in module m (if not null)

findQ(n)

Find object n given as qualident (module.object)

addMod

Keep module symbols (only exported objects)

  

  

ident()

Parse ident, add Itm to top scope if mode given

identDef()

Parse [marked] ident, add Itm to top scope if mode given

xx()

Terminal /non-terminal EBNF symbol xx

range()

Parse & evaluate n .. m

rset()

Range operation for SET

rcase()

Range operation for CASE

Obj

Symbol Table

  

id

Object name

mk

Export mark (module name)

typ

Object type

md

Object mode, or object form, if id='_'

dsc

Contained objects

id_()

Object name for output

frm()

Object type form

find(n)

Find sub-object with id=n

init()

Init value for type

dim

Dimensions, if md='A'

  

Obj modes

M

Module

P

Procedure

T

Type

P

Procedure

V

Variable (also expression in Items)

W

VAR parameter

C

Constant

H

Host item

Obj forms

R

Record Type

A

Array Type

X

Procedure Type

Itm

Item, tracks location/value of an expression

  

v

Item value

typ

Item type

md

Item mode (see Obj)

toString()

Item value for output

arg(a,p)

Return arg a with respect to formal param p, handles VAR params

undesig() separate last selector of designator

op

Evaluate unary operators

op2

Evaluate binary operators (no constant folding)

setop

Evaluate set operators (constant folding)

JS

Code generator

  

putI()

Output item surrounded by prefix/suffix

putT()

Output type declaration

flds()

Output record field declarations

putFor()

Implement FOR loop (O2)

vars()

Output var declarations

stdFn()

Standard functions (INC, ASH, …)

fn()

function heading

ext()

Setup type extension

updV

Update operator (+=, etc.) for VAR params

  

  

Oberon
Global

Runtime

_vp()

VAR-par "bubble" for compound designators

_narr()

Init array of scalars (max 3 dims)

_arr()

Init array

_ext()

Setup type extension

_chrarr()

Implement CHRARR (String --> ARR OF CHAR)

_cpa()

Value copy of array (t := s) see below

_cp()

Value copy of record see below

  

 

 

RECORD/ARRAY assignments and value parameters in Oberon are implemented by block copying. JavaScript requires a field-by-field copying which is inefficient, but acceptable because such assignments are usually rare. Therefore, in order not to expend the effort of manufacturing a copy method at compile time for each type, a generic copy method factory _cp() is provided instead. The factory assembles the corresponding type-specific copy methods at runtime when the method is called the first time.