Attribute Grammar Parser

syntax

  • ↑: Synthesized attribute
    • computed from child node values (and node inherited attribtues?)
  • ↓: Inherited attribute
    • computed from parent attributes OR synthesized sibling attributes

Translation scheme

= in what order the attributes will be read

  • top down
  • bottom up (problem: non-LL grammars)

attribute (semantic) function:

attribute (env) {
	return val
}

framework

attribute operation

= functions used to manipulate attribute instances (e.g. set)

semantic function manager (exec)

= supplementary component, which applies semantic functions (FUN_IDENTIFIER) to attribute instances (ARGS) → dynamic generation? → necessary?

exec(FUN_IDENTIFIER, ARGS) {
	if (FUN_IDENTIFIER == "ADD") {
		return val(ARGS[0]) + val(ARGS[1])
	}
	...
}

Attribute class

bottom up approach
attribution (semantic) functions
fun(CTXTS_RHS) {
	// mkCtx for CTXT_LHS initiate num of attributes
	
	// eq
	// mkDep for CTX_LHS attributes to make dependencies
	// inst to instrument (set sem fun) for all CTX_LHS and CTXTS_RHS attributes
	
	return CTXT_LHS
}

eq(lhsAttr, rhsAttrs, semFun) {

	// connect attribute dependency
	foreach rhsAttr in rhsAttrs{
		mkDep(lhsAttr, rhsAttr)
	}
	
	// set sem fun for lhsAttr
	inst(lhsAttr, semFunIdent)
}