Frontend

ampl.l is the LEX/FLEX input file.

It mainly consists of a list of tokens that should be recognised in SML.

ampl.ypp is the YACC/BISON grammar file. It specifies the grammar of SML in Backus-Naur form (BNF). Large parts of it follow the specification of the AMPL grammar in the appendix of the AMPL book. In YACC/BISON every "rule" returns a "value" that is computed from the values of its components. In SML most rules return a pointer to a SyntaxNode. A SyntaxNode represents an AMPL/SML operator, and an AMPL/SML expression is thus represented as a tree of SyntaxNodes.

The grammar processor recognizes the start and end of a block/submodel and creates an AmplModel object for each of these. It classifies all other lines into set/parameter/variable/constraint/objective/submodel declarations - which are stored in a ModelComp object - and attaches them to the appropriate (current) model.

Stochastic Programming models defined by the "block stochastic" commands are treated specially. They will be read into a StochModel object.

Every declaration is further divided into a name, indexing and attribute (body) section. These are attached to the appropriate ModelComp object. The indexing and attribute expressions are represented as a tree of SyntaxNodes. The indexing expression is actually represented by the subobject SyntaxNodeIx, which has extra fields and methods that allow a quick recovery of the defined dummy variables and their dimension.

The indexing and attributes trees are postprocessed: they are scanned for name references. Every reference is compared with the names of model components that are currently in scope (this includes dummy variables that are used in the indexing expression), and if found the reference in the SyntaxNode tree is replaced by a pointer to the appropriate ModelComp (done by find_var_ref_in_context()).

Bug:
Currently no hashing is done in this search.

Internally all names are represented by a SyntaxNode with SyntaxNode.opCode==ID. These are replaced by an object of subclass SyntaxNodeIDREF with SyntaxNodeIDREF.opCode==IDREF, which carry a pointer to the appropriate ModelComponent.

The output of the frontend is a tree of AmplModel objects (each representing a node of the model tree), consisting of ModelComp objects (each representing an AMPL declaration). These in turn consist of several SyntaxNode trees representing the indexing and attribute (body) section of the declaration

Note:
Also need to describe the data file parser and its classes