// Integer arithmetic interpreter value (avalue) // definition. // // File: iavalue.cc // Author: course // Version: 2 // // This file defines the arithmetic interpreter value // type, or avalue. #include "lexeme.h" // Defines lexemes, includes // avalue.h. // `Zero' avalue, which becomes value of empty program. // avalue zero_avalue = 0; // Produce an avalue from a lexeme, which must be a // LEX_NUMBER or a LEX_SYMBOL. // avalue evaluate (lexeme lex) { if (lex->type == LEX_NUMBER) return lex->value; else if (lex->type == LEX_SYMBOL) { if (lex->inited) return lex->value; else error ("Undefined symbol: ", lex->pname); } else assert (false); // We should never execute // this. } // Assign to a lexeme. Returns the value assigned. // avalue assign (lexeme lex, avalue v) { assert (lex->type == LEX_SYMBOL); lex->value = v; lex->inited = true; return v; } // Initialize avalues. // void init_avalues (void) {}