--[[ Expression Language 1, Values Module CSci 450: Organization of Programming Languages, Fall 2016 H. Conrad Cunningham, Professor Computer and Information Science University of Mississippi 1234567890123456789012345678901234567890123456789012345678901234567890 2016-09-13: Separated as module from Assignment #1 code 2016-09-21: Added valToString function Added global variables for module names This module encapsulates implementations of the Values used in the Expression Language interpreter. This module will need modification for languages with richer sets of values than integers. For example, the representation for the concepts false and true differs from one language to another and likely differs from the values used by Lua. The intentions of features FALSEVAL, TRUEVAL, isFalse, isTrue, and asBoolVal are to isolate the differences between Lua and how those are handled in the interpreted languages. Note: The features of this layer should be sufficient for Assignment #1, Public constants: TRUEVAL, FALSEVAL Public query functions: isTrue, isFalse Public conversion function: asBoolVal, valToString --]] --[[ Module names now global local UTILITIES = "utilities" --]] -- Import Utilities module local util = require(UTILITIES) local treeConcat, show_data = util.treeConcat, util.show_data -- BOOLEAN VALUES -- Public constants for true and false in interpreted language local FALSEVAL = 0 local TRUEVAL = 1 -- Public query functions local function isFalse(v) return v == FALSEVAL end local function isTrue(v) return v ~= FALSEVAL end -- Public conversion function "asBoolVal" takes a Lua falsey or truthy -- value and returns the corresponding value used in the interpreted -- language (FALSEVAL or TRUEVAL). local function asBoolVal(b) if b then return TRUEVAL else return FALSEVAL end end -- Public function "valToString" converts value "v" to a string -- and returns it. local function valToString(v) local tv = type(v) if tv == "number" then return tostring(v) else return "Bad value: " .. show_data(v) end end -- MODULE EXPORT LIST return { TRUEVAL = TRUEVAL, FALSEVAL = FALSEVAL, isTrue = isTrue, isFalse = isFalse, asBoolVal = asBoolVal, valToString = valToString }