General Information
Tutorials
Reference Manuals
Libraries
Translation Tasks
Tools
Administration
|
Name analysis according to scope rulesTree Grammar Preconditions
Names are usually represented by identifier terminals. Their notation
is determined by a scanner specification. The grammar
has one (or several) terminals representing
identifiers, e.g.
Identifiers occur in different contexts: Defining and applied
occurrences, or different kinds of identifiers (variables, labels,
etc.) may be distinguished. Usually the concrete syntax
is designed first, and the different computational roles of identifiers
are incrementally developed during the design of the
Our running example has the concrete productions
ObjDecl: TypeDenoter Ident. TypeDenoter: Ident. Variable: Ident.We distinguish the different roles of identifiers by introducing new symbol names in the corresponding LIDO RULE s:
RULE: ObjDecl ::= TypeDenoter DefIdent END; RULE: TypeDenoter ::= TypeUseIdent END; RULE: Variable ::= UseIdent END;Furthermore, we have to add the necessary chain RULE s:
RULE: DefIdent ::= Ident END; RULE: UseIdent ::= Ident END; RULE: TypeUseIdent ::= Ident END;
The name analysis modules require that identifier occurrences are
represented by nonterminals, like
ATTR Sym: int SYNT; SYMBOL IdentOcc COMPUTE SYNT.Sym = TERM; END; SYMBOL DefIdent INHERITS IdentOcc END; SYMBOL UseIdent INHERITS IdentOcc END; SYMBOL TypeUseIdent INHERITS IdentOcc END;
If your language does not syntactically distinguish between defining and
applied identifier occurrences, i.e. objects are introduced by using
their name, the
above distinction is not necessary. You just introduce
Your grammar should have a symbol representing a
phrase that contains all (defining and applied) occurrences of a
name space. It is usually the root of the whole grammar, e.g. in the
running example the symbol
If your language has hierarchically nested ranges defining boundaries
for the scope of definitions, the abstract syntax should have one
or several symbols, e.g. |