/* parse.cc * by Will Wagner * last updated 20 Sep 1997, 17:24:21 wwagner * * This file contains the main part of the parser, and support * routines for the recursive-descent style parsing of objects and * textures. * * Changes * 18 Aug 1997 * - Added this comment block; added keyword table and * registration routine; fixed get/unget routines. * * 06 Sep 1997 * - We're going to have to handle execs here because we need to * be able to parse arbitrary string expressions, instead of plain * string constants; uncommented exec keyword. * * 20 Sep 1997 * - We now handle includes in here as well. * * Things to do * */ #include "registry.h" #include "parse.h" static void Register_Parser_Keywords(void) __attribute__ ((constructor)); static RESERVED_WORD Parser_Reserved_Words[] = { /* first, the expression keywords */ /* string_literal token resides with the global table */ { ABS_TOKEN, "abs" }, { ACOSH_TOKEN, "acosh" }, { ACOS_TOKEN, "acos" }, { ASC_TOKEN, "asc" }, { ASINH_TOKEN, "asinh" }, { ASIN_TOKEN, "asin" }, { ATAN2_TOKEN, "atan2" }, { ATANH_TOKEN, "atanh" }, { ATAN_TOKEN, "atan" }, { BLUE_TOKEN, "blue" }, { CEIL_TOKEN, "ceil" }, { CHR_TOKEN, "chr" }, { CLOCK_TOKEN, "clock" }, { CONCAT_TOKEN, "concat" }, { COSH_TOKEN, "cosh" }, { COS_TOKEN, "cos" }, { DEGREES_TOKEN, "degrees" }, { DIV_TOKEN, "div" }, { EXP_TOKEN, "exp" }, { FALSE_TOKEN, "false" }, { FILE_EXISTS_TOKEN, "file_exists" }, { FILTER_TOKEN, "filter" }, { FLOAT_ID_TOKEN, NULL }, { FLOAT_TOKEN, "float" }, { FLOOR_TOKEN, "floor" }, { GREEN_TOKEN, "green" }, { INT_TOKEN, "int" }, { LOG_TOKEN, "log" }, { MAX_TOKEN, "max" }, { MIN_TOKEN, "min" }, { MOD_TOKEN, "mod" }, { NO_TOKEN, "no" }, { OFF_TOKEN, "off" }, { ON_TOKEN, "on" }, { PI_TOKEN, "pi" }, { POW_TOKEN, "pow" }, { RADIANS_TOKEN, "radians" }, { RAND_TOKEN, "rand" }, { RED_TOKEN, "red" }, { SEED_TOKEN, "seed" }, { SINH_TOKEN, "sinh" }, { SIN_TOKEN, "sin" }, { SQRT_TOKEN, "sqrt" }, { STRCMP_TOKEN, "strcmp" }, { STRING_ID_TOKEN, NULL }, { STRLEN_TOKEN, "strlen" }, { STRLWR_TOKEN, "strlwr" }, { STRUPR_TOKEN, "strupr" }, { STR_TOKEN, "str" }, { SUBSTR_TOKEN, "substr" }, { TANH_TOKEN, "tanh" }, { TAN_TOKEN, "tan" }, { TRANSMIT_TOKEN, "transmit" }, { TRUE_TOKEN, "true" }, { T_TOKEN, "t" }, { U_TOKEN, "u" }, { VAL_TOKEN, "val" }, { VAXIS_ROTATE_TOKEN, "vaxis_rotate" }, { VCROSS_TOKEN, "vcross" }, { VDOT_TOKEN, "vdot" }, { VECTOR_ID_TOKEN, NULL }, { VLENGTH_TOKEN, "vlength" }, { VNORMALIZE_TOKEN, "vnormalize" }, { VROTATE_TOKEN, "vrotate" }, { V_TOKEN, "v" }, { X_TOKEN, "x" }, { YES_TOKEN, "yes" }, { Y_TOKEN, "y" }, { Z_TOKEN, "z" }, /* now for the parser directives */ { BREAK_TOKEN, "break" }, { CASE_TOKEN, "case" }, { DEBUG_TOKEN, "debug" }, { DECLARE_TOKEN, "declare" }, { DEFAULT_TOKEN, "default" }, { ELSE_TOKEN, "else" }, { END_TOKEN, "end" }, { ERROR_TOKEN, "error" }, { EXEC_TOKEN, "exec" }, { IFDEF_TOKEN, "ifdef" }, { IFNDEF_TOKEN, "ifndef" }, { IF_TOKEN, "if" }, { INCLUDE_TOKEN, "include" }, { RANGE_TOKEN, "range" }, { RENDER_TOKEN, "render" }, { STATISTICS_TOKEN, "statistics" }, { SWITCH_TOKEN, "switch" }, { VERSION_TOKEN, "version" }, { WARNING_TOKEN, "warning" }, { WHILE_TOKEN, "while" }, { LAST_TOKEN, NULL } }; static void Register_Parser_Keywords(void) { RESERVED_WORD *rws = Parser_Reserved_Words; while (rws->Token_Number != LAST_TOKEN) { registry.res().Add(rws->Token_Name, rws->Token_Number); ++rws; } } Parser::Parser() { } Parser::~Parser() { } Frame *Parse(char *fname) { } void Parser::ParseBegin(void) { brace_stack.push(this->GetToken()); if (GetToken() != LEFT_CURLY_TOKEN) throw ParserError("", "", "", 0, 0); } void Parser::ParseEnd(void) { if (GetToken() != RIGHT_CURLY_TOKEN) throw ParserError("", "", "", 0, 0); brace_stack.pop(); } void Parser::ParseComma(void) { if (GetToken() != COMMA_TOKEN) throw ParserError("", "", "", 0, 0); } DBL Parser::ParseFloatExpr(void) { pov_vector v = *(pov_vector *)((this->expr_parse()).noval); if (/* find out if the vector is valid */) return v[0]; throw ParserError("", "", "", 0, 0); } pov_vector Parser::ParseVectorExpr(void) { pov_vector v = *(pov_vector *)((this->expr_parse()).noval); if (/* find out if the vector is valid */) return v; throw ParserError("", "", "", 0, 0); } char *Parser::ParseStringExpr(void) { char *str = (char *)(this->expr_parse()).noval; if (/* find out if the string is valid */) return str; throw ParserError("", "", "", 0, 0); } Matrix Parser::ParseMatrix(void) { } Transformation Parser::ParseTransformation(void) { } TOKEN Parser::GetToken(void) { return tok.GetToken(); } void Parser::UngetToken(void) { tok.UngetToken(); }