Routines for customizing AST building

  import builder walker

Each node in the Abstract Syntax Tree (AST) is labeled with a routine from walker.slm (and optionally, custwalk.slm) which is used to process the node during traversal (walking) of the tree. Module walker is imported here to incorporate all of its exported routines into the name space of the current module. Module builder is imported to gain access to the parse stack.

  export Build_start_list, Build_add_to_list


These routines are exported for use by the parser, which will call them when the corresponding <start_list> and <add_to_list> annotations in the EBNF is reached. (See expr.bnf).

  proc Build_start_list
    Stack +:= [[Walk_list]]


This routine is called whenever <start_list> is reached in the EBNF. It creates a list node with no children and labels it with the Walk_list routine. When the list is walked, routine Walk_list will be called with the list of children as its parameter.

  proc Build_add_to_list
    O1, Stack := delete_last(Stack)
    O2, Stack := delete_last(Stack)
    Stack +:= [O2 + [O1]]


This routine is called whenever <add_to_list> is reached in the EBNF. It pops the top two elements of the stack and appends the top most element to the end of the other. The modified element is then pushed back onto the stack. The intended use is to add AST children to a list node created by Build_start_list. See the Walk_list routine in walker.slm.