Class: Blocks09

Seven~ Blocks09

Example 7/09: compile global functions with block structure.


new Blocks09()

Source:

Extends

Classes

Block
Fun
Symbol
Var

Members


context

Manages a stack of contexts for assign or call to a name

Inherited From:
Source:

funct

Describes current function

Inherited From:
Source:

size

Manages next (global) variable address

Inherited From:
Source:

Methods


Do()

Do: 'do';

Overrides:
Source:

Else()

Else: 'else';

Overrides:
Source:

Then()

Then: 'then';

Overrides:
Source:

While()

While: 'while'; returns address for branch to while

Inherited From:
Source:

_alloc()

Replace: returns new Var at next local/global address.

Inherited From:
Source:

_check_defs()

Flags undefined functions, returns main if defined

Inherited From:
Source:

_dcl()

Replace: sets innermost map, returns sym

Inherited From:
Source:

_find()

Replace: searches innermost to outermost blocks and global

Overrides:
Source:

_startup(main)

[Extend] Push 0 for main parameters.

Parameters:
Name Type Description
main Fun

describes main().

Inherited From:
Source:

add()

add: '+' product;

Inherited From:
Source:

args()

args: '(' [ sums ] ')'; expects context, codes call

Inherited From:
Source:

assign()

assign: symbol action; codes Pop, pops context

Inherited From:
Source:

begin()

begin: 'begin';

Source:

block()

block: begin [ vars ] stmts 'end';

Source:

divide()

divide: '/' signed;

Inherited From:
Source:

else()

else: Else [ vars ] stmts;

Source:

eq()

eq: '=' sum;

Inherited From:
Source:

fun()

fun: head parms [ block ] ';';

Inherited From:
Source:

ge()

ge: '>=' sum;

Inherited From:
Source:

gt()

gt: '>' sum;

Inherited From:
Source:

head: 'function' Name; returns function symbol

Inherited From:
Source:

input()

input: 'input' [ Number ];

Inherited From:
Source:

le()

le: '<=' sum;

Inherited From:
Source:

loop()

loop: While cmp Do [ vars ] stmts 'od';

Overrides:
Source:

lt()

lt: '<' sum;

Inherited From:
Source:

multiply()

multiply: '*' signed;

Inherited From:
Source:

name()

name: symbol [ args ]; codes variable load, pops context

Inherited From:
Source:

names()

names: Name [{ ',' Name }]; defines new variables, returns number of names

Inherited From:
Source:

ne()

ne: '<>' sum;

Inherited From:
Source:

number()

number: Number;

Inherited From:
Source:

parms()

parms: '(' [ names ] ')';

Inherited From:
Source:

print()

print: 'print' sums;

Inherited From:
Source:

prog()

prog: [ vars ] funs; returns executable

Inherited From:
Source:

return()

return: 'return' [ sum ];

Inherited From:
Source:

run()

Creates stack machine

Inherited From:
Source:

select()

select: 'if' cmp then [ else ] 'fi';

Overrides:
Source:

signed()

signed: [ '-' ] term;

Inherited From:
Source:

stmt()

stmt: assign | print | loop | select; [replace] no op

Inherited From:
Source:

store()

store: '=' sum; expects context, codes assignment

Inherited From:
Source:

subtract()

subtract: '-' product;

Inherited From:
Source:

sum()

sum: 'let' Name '=' sum | product [{ add | subtract }];

Inherited From:
Source:

sums()

sums: sum [{ ',' sum }]; returns number of values

Inherited From:
Source:

symbol()

symbol: Name; pushes context, returns symbol

Inherited From:
Source:

then()

then: Then [ [ vars ] stmts ];

Source:

toString()

Represents code as text

Inherited From:
Source: