diff --git a/CMakeLists.txt b/CMakeLists.txt index 0aa0124..bb288d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,7 +49,7 @@ set(ibcp_COPYRIGHT_YEAR 2012) set(ibcp_RELEASE_MAJOR 0) set(ibcp_RELEASE_MINOR 2) -set(ibcp_RELEASE_PATCH -6) +set(ibcp_RELEASE_PATCH 0) set(ibcp_RELEASE_STRING release${ibcp_RELEASE_MAJOR}.${ibcp_RELEASE_MINOR}) if (ibcp_RELEASE_PATCH LESS 0) diff --git a/README b/README index bd4c711..f30dedc 100644 --- a/README +++ b/README @@ -16,6 +16,7 @@ generated by 'cmake' cross-platform, open-source make system. This project is currently being developed on Linux (Ubuntu based Mint 13) but is also be tested on 32-bit Windows XP and 64-bit Windows 7. On the Windows system, the MinGW Minimal GNU for Windows is used for building. +The Qt toolkit is being used for development of the GUI. Information for this project can be found at the project's blog located at http://interactivebasiccompilerproject.blogspot.com, which contains @@ -32,7 +33,8 @@ converts text input into BASIC language tokens. The translator is currently being developed and currently supports the translation of BASIC expressions along a few BASIC commands (LET, PRINT, and INPUT) into a reverse polish notation format that will be used for fast -execution of the BASIC program. +execution of the BASIC program. The GUI implementation has been +started but currently only displays an about box. Building The Program @@ -54,9 +56,17 @@ zip or tar file, the project is build with a few short commands: Running Regression Tests ------------------------ -To run the include regression tests, run the regtest script that was +To run the included regression tests, run the regtest script that was copied into the ibcp/build directory. The test will report whether the -tests pass or fail. +tests pass or fail. The memtest script (Linux only) will run all the +tests but also look for memory leaks (requires the valgrind program). + + +Command Line Options +-------------------- +The -v option will output the version string and exit. The -h or -? +option will output the usage message and exit. No options will start +the GUI, which currently only displays the about box and then exits. Running Interactively diff --git a/enums.awk b/enums.awk index 9f8e91b..9782341 100644 --- a/enums.awk +++ b/enums.awk @@ -20,31 +20,7 @@ # # Change History: # -# 2010-03-20 initial release -# -# 2010-04-04 added comment header with GPL, change history and usage -# modified script to handle digits in code names -# -# 2010-04-28 added code to allow for multiple codes on a line -# allow for Invalid_Code = -1 -# added -d to sort command to ignore "_" in codes names -# -# 2010-09-06 modified to only look for codes in the Code enumeration -# -# 2011-02-26 rewrote script to generate codes.h and codes.txt directly from -# the table.cpp source file (all code performed in BEGIN block) -# -# 2011-03-26 renamed from codes.awk to enums.awk -# updated to write autoenums.h that includes enum Code and -# enum TokenStatus (which comes from ibcp.cpp) -# added exit code upon failure to terminate build -# 2011-06-12 for use with cmake, added an optional path to the source files -# as the first argument on the awk command line -# 2012-10-06 modified to remove the CR at the end of the lines in DOS format -# files, but do nothing with Unix format files -# -# 2012-11-01 changed 'const char *' to 'QString' for message_array[] -# 2012-11-03 changed ibcp.cpp to token.cpp +# 2010-03-20 initial version # # # Usage: awk -f enums.awk [source path] diff --git a/ibcp.h b/ibcp.h index b97c625..27a407f 100644 --- a/ibcp.h +++ b/ibcp.h @@ -20,292 +20,7 @@ // // Change History: // -// 2010-02-18 initial release -// -// 2010-03-01 support for Parser class added, which includes: -// Token and CmdArgs structures; Parser class -// new CmdArgs_DataType and Error_Flag -// renamed ImCommand_TokenType to ImmCmd_TokenType -// -// 2010-03-06 replaced DefFunc_TokenType with DefFuncN_TokenType and -// DefFuncP_TokenType so that it can be determined if the define -// function name has a parentheses or not -// -// 2010-03-07 added length of token with error to Token along with two new -// set_error() functions -// -// 2010-03-11 support for Translator class initiated, which includes: -// replaced IntFunc_TokenType With IntFuncN_TokenType and -// IntFuncP_TokenType; and added new static members to Token -// -// 2010-03-17 added codes Null_Code, Neq_Code, and EOL_Code -// added unary_code to TableEntry -// renamed code to index in Token to avoid confusion -// -// 2010-03-18 added Translator class; -// added default to Token constructor -// added set_token() function to Table class -// -// 2010-03-20 added precedence to TableEntry -// added more access functions to Table -// made numerous changes to Translator class -// -// 2010-03-21 initialized length field in Token to 1 -// added is_unary_operator() to Table -// added additional diagnostic errors to Translator -// -// 2010-03-25 added variables to Table and Translator to support parentheses, -// added Highest_Precedence constant -// -// 2010-03-26 added do_pending_paren() to Translator class -// -// 2010-04-02 add support to Token and Table to get precedence values for -// token types that don't have table entries (DefFuncP and Paren) -// added count_stack of new type SimpleStack to Translator to -// support commas (for subscripts in arrays and arguments in -// functions) -// added more errors to Translator -// -// 2010-04-04 added support for number of argument checking for internal -// functions including added codes for functions with different -// number of arguments; adding Multiple_Flag -// added nargs to TableEntry; new Table access function and search -// function -// added new error to Translator -// made token argument a reference in Translator::add_token() -// added debug_name() to Table -// -// 2010-04-11 added assignment operator codes -// added mode with enumerator to Translator -// added more error codes to Translator -// 2010-04-12 added reference flag to Token -// 2010-04-13 made token argument a reference in Translator::add_operator() -// 2010-04-16 added more error codes to Translator -// added expression mode flag option to Translator for testing -// 2010-04-17 added another error code to Translator -// -// 2010-04-24 added the associated codes for the specific data types codes for -// all the operators and internal functions where applicable -// add new Frac_Code -// rearranged DataType enumeration names so that the actual data -// types are listed at the beginning with Double (the default) -// listed first; added number_DataType for actual number of data -// types -// renamed nargs to noperands in TableEntry and Table (now -// applicable operators in addition to internal functions) -// added Max_Operands and Max_Assoc_Codes definitions; added -// operand_datatype[] and assoc_codes[] arrays to TableEntry; -// added related access functions to Table -// 2010-04-25 added Invalid_Code set to -1 -// updated Translator for data type handling: -// added exptected data type errors -// renamed BUG_StackEmpty to BUG_HoldStackEmpty -// added BUG_DoneStackEmpty -// added set_default_datatype() to set the data type for -// operands that didn't have a specific data type -// added find_code() and match_code() with Match enum -// -// 2010-05-03 added ExprInfo to hold expression related information for the -// table entries; replaced these members with ExprInto pointer in -// TableEntry; modified the access functions in Table -// 2010-05-05 added Reference_Flag and AssignList_Flag -// 2010-05-07 added associated codes for Assign and AssignList -// 2010-05-08 added check for null exprinfo in datatype() and unary_code() -// access functions of Table -// added last_operand argument to Table::find_code() -// -// 2010-05-15 added TmpStr_DataType -// added RpnItem structure, changed done_stack and output list from -// holding Token* to RpnItem* -// moved operand[] array from find_code() to Translator as member, -// removed operand argument from Translator::match_code() -// added logic to Translator::set_default_datatype() to set data -// type to TmpStr for token types DefFuncN/DefFuncP when the data -// type is String -// -// 2010-05-19 added new SubStr_DataType -// added new associated code AssignSubStr_Code to Assign_Code -// 2010-05-20 increased Max_Assoc_Codes from 2 to 3 because of -// AssignSubStr_Code -// added new maximum table errors -// -// 2010-05-20 added new associated code AssignListMixStr_Code to -// AssignList_Code -// added RpnItem::set() to set rpn item members without allocating -// a new array and copying to the array -// -// 2010-05-27 added SubCode enumeration and subcode member to Token -// 2010-05-28 changed hold_stack and done_stack from List to SimpleStack in -// Translator (a linked list is unnecessary for these stacks) -// moved/renamed Translator::Status to TokenStatus -// added CmdItem struct and cmd_stack to Translator -// moved/renamed Translator::Mode to TokenMode along with -// token_mode to TableEntry (next token mode for command) and -// access function to Table -// added TokenHandler typedef along with token_handler to -// TableEntry and access function to Table, added friend -// definitions for new translator token handler functions and -// extern definitions for actual functions -// 2010-05-29 added static token has table entry flag (table) to Token along -// with access function (used by Table access functions) -// added Hidden_Flag to mark table entry of hidden codes -// added new flags Table access function with token pointer -// argument - returns no flags (0) for non-table entrytokens -// changed argument to Translator::do_pending_paren() from index -// to token pointer so that it will work with tokens that don't -// have a table entry (arrays and functions) -// -// 2010-06-01 added support for print-only functions -// added generic flag member to CmdItem that can be used by -// commands (for PRINT it will be used to determine if a PRINT -// token should be added at the end of a translated print -// statement, i.e. advance to a new line) -// 2010-06-02 added support for semicolon with token handler -// added Table::new_token() for allocating a new token and setting -// it up for a specific code -// 2010-06-03 added Translator::expression_end() for checking if expression -// was ended correctly -// 2010-06-04 added Translator::add_print_code() for adding new data type -// specific print codes that were also added -// 2010-06-05 added support for command handler function pointers -// (was necessary to move CmdItem structure outside Translator) -// 2010-06-06 added EndExpr_Flag for token codes that can end an expression -// corrected issue with special Translator expression only mode -// 2010-06-08 added PrintFunc_CmdFlag and SemiColon_SubCode -// 2010-06-09 changed count_stack from to new , which -// contains the old count and expected number of arguments -// 2010-06-10 added new FirstOperand translator state - used for identifying -// if any tokens for expression have been received yet -// 2010-06-13 added token pointer argument to command handlers so that -// command handlers have accessed to calling token -// 2010-06-14 added Translator::paren_status() for checking if there is an -// outstanding token with parentheses on the hold stack and if -// there is, to return the appropriate error -// 2010-06-14 removed AssignList_Flag because it is unnecessary (the code can -// be checked for AssignList_Code) -// 2010-06-01/14 added, renamed and deleted many TokenStatus enumeration -// values for matching error messages that were changed for -// better clarity -// -// 2010-06-24 added another TokenStatus -// 2010-06-25 replaced TableErrType enum and TableError struct with -// ErrorType enum and Error struct template so that this can also -// be used for TokenStatus -// TableSearch renamed to SearchType -// 2010-06-26 added EndStatement_Flag -// 2010-06-29 added new ExprType enumeration -// added expr_type member to Translator (initialize for expr mode) -// added expr_type member to TableEntry (with access function) -// updated expected expression related token statuses -// 2010-06-30 updated expected expression related token statuses -// 2010-07-01 added AssignList_CmdFlag back -// removed last_operand argument from Table::find_code(), which was -// needed for assign list operators, but assign list is no -// handled by comma, semicolor and Assign handlers -// added new check_assignlist_token() and set_assign_command() -// to Translator -// 2010-07-02 updated TokenStatus -// added new search and match functions to Table -// 2010-07-04 updated TokenStatus -// -// 2010-08-01 removed support for multiple equal assignments (now only commas -// used for multiple assignments) -// 2010-07-18 added second associated index to ExprInfo for support of -// checking each operand when processed instead of processing -// all operands at the end -// 2010-08-10 added several multiple error types used for additional table -// checking during initialization -// 2010-09-03 added new Translator::process_final_operand(), -// modified Translator::find_code(), -// removed Translator::match_code() -// 2010-12-13 added number of string arguments to ExprInfo for Table entries -// -// 2011-01-02 added Translator::get_expr_datatype() -// 2011-01-05 put datatype back into TableEntry, removed expr_type -// modified datatype access function to get main datatype if there -// is not exprinfo (this may be temporary) -// 2011-01-07 removed datatype from ExprInfo -// -// 2011-01-11 moved length from union in Token so it can be used for all types -// 2011-01-13 implemented new Translator::HoldStackItem and changed hold_stack -// added argument to Translator:: add_operator() -// and process_final_operand() for handling first/last operands -// 2011-01-15 implemented new Translator::DoneStackItem and changed done_stack -// added argument to Translator::find_code() for handling -// first/last operands -// implemented new Translator:: process_first_operand() and -// delete_close_paren() -// 2011-01-16 added Token::include() for reporting range of tokens for errors -// 2011-01-22 added last and used sub-code flags for close paren tokens so -// they don't get deleted until they are not used anymore -// added Translator::delete_open_paren() -// 2011-01-29 added list element pointer to Token for memory leak detection -// added new and delete operator Token functions for memory leaks -// added static list and del_list to Token for memory leaks -// moved all static members of Token to the end so that it is -// easier to see the regular members when debugging -// 2011-01-30 reset string pointer to NULL in Token deconstructor -// made Translator::delete_open_paren() public to be accessible -// by caller of Translator (to correct a memory leak) -// 2011-02-04 added associated codes for temporary strings -// -// 2011-02-10 added Translator::call_command_handler() -// added BUG_CmdStackEmptyCmd token status -// 2011-02-11 added BUG_UnexpToken token status -// 2011-02-12 renamed ExpStatement_TokenStatus to ExpCommand -// 2011-02-20 renamed SimpleStack to Stack -// -// 2011-02-26 removed Code enumeration (now auto gen'd in codes.h) -// changed Token::index back to code -// moved Table::index_code[], code() and index() -// removed TableEntry::code (index now same as code) -// added new ImmCmd search type -// added Code operator overload functions -// 2011-03-01 started INPUT command handler implementation -// added Question_SubCode -// 2011-03-04 added non-IntFunc check to Translator::set_default_datatype() -// 2011-03-05 removed PrintOnlyIntFunc, added ExpSemiCommaOrEnd_TokenStatus -// added "_State" to enum Translator::State values -// added Translator::EndExpr_State -// 2011-03-10 renamed ExpCommand_TokenStatus to ExpCmd_TokenStatus -// 2011-03-13 removed ExpAssignRef_TokenStatus, UnExpCommand_TokenStatus, -// UnexpAssignComma_TokenStatus, UnexpParenInComma_TokenStatus -// 2011-03-19 renamed EndStatement_Flag to EndStmt_Flag -// added Keep_SubCode (for INPUT), ExpEndStmt_TokenStatus -// renamed EndStatment_Flag to EndStmt_Flag -// added Translator::EndStmt_State -// added ExpEndStmt_TokenStatus -// implemented Translator::assoc2_code() access function -// 2011-03-20 added End_SubCode (for INPUT), added input command flags -// 2011-03-22 renamed Translator::FirstOperand_State to OperandOrEnd_State -// 2011-03-24 added ExpOpSemiOrComma_TokenStatus -// -// 2011-03-26 enum TokenStatus is now automatically generated from the -// ibcp.cpp source file by the enums.awk script so it was -// removed, -// The automatic codes.h was renamed autoenums.h -// removed Duplicate and Missing error types (no longer used) -// changed several shorts (index values) to type T in Error -// changed Token::message_array[] to simply string pointer array -// 2011-03-27 added operand_state flag to Parser with set access function -// added get operand state access function to Translator -// -// 2012-10-25 added new function Token::isNull() to properly check for the -// null token (not all token types have a valid code) -// 2012-10-27 converted translator output rpn list from List class to QList -// also required changes to done_stack (element list pointer to -// rpn item pointer), cmd_stack (element list pointer to index -// into output rpn list), and RpnItem.operands[] (element list -// pointer array to RpnItem pointer array) -// 2012-10-28 removed token lists and new/delete overload functions -// 2012-10-28 removed Error Template (no longer needed) -// changed Table class (constructor and new initialize() function) -// 2012-10-29 converted translator stacks from Stack class to QStack -// 2012-10-31 added 'const' to 'char *' variables in Parser -// 2012-11-01 removed support for immediate commands -// changed all String to QString -// renamed Parser functions and variables to Qt Style naming -// 2012-11-03 separated classes to individual header files +// 2010-02-18 initial version #ifndef IBCP_H #define IBCP_H diff --git a/ibcp_config.h.in b/ibcp_config.h.in index 7570e8c..bd96d9e 100644 --- a/ibcp_config.h.in +++ b/ibcp_config.h.in @@ -21,9 +21,6 @@ // Change History: // // 2011-06-11 initial version -// -// 2012-10-23 renamed variables from VERSION to RELEASE -// added new ibcp_RELEASE_STRING // the configured options and settings for ibcp // (for passing values from cmake to ibcp source files) diff --git a/memtest.in b/memtest.in index d376147..2a6d212 100755 --- a/memtest.in +++ b/memtest.in @@ -20,8 +20,7 @@ # # Change History: # -# 2012-10-25 initial release (started from regtest) -# 2012-10-29 added version output +# 2012-10-25 initial version (started from regtest) # # # Usage: diff --git a/parser.cpp b/parser.cpp index 1245674..77bc2ed 100644 --- a/parser.cpp +++ b/parser.cpp @@ -20,66 +20,7 @@ // // Change History: // -// 2010-03-01 initial release -// -// 2010-03-06 split DefFunc_TokenType into DefFuncN_TokenType and -// DefFuncP_TokenType so that it can be determined if define -// function name has a parentheses or not -// -// 2010-03-07 in get_number() changed situation of 0 leading another digit -// from terminating the number at the first 0 to a leading zero -// error (no legal BASIC would have this situation; -// changed several set_error() calls to have a length -// argument for the new length of token error field in Token -// -// 2010-03-08 removed no closing quote check from get_string() since this -// condition was made acceptable in scan_string() -// -// 2010-03-10 rewrote get_operator() to properly handle two character -// operators -// -// 2010-03-11 allow tabs to be white space in skip_whitespace() -// -// 2010-03-17 modified get_token() to return special end-of-line token -// instead of a NULL pointer -// changed all token->code to token->index -// -// 2010-03-18 replaced code with call to set_token() -// -// 2010-03-20 set length of token field for words, two words, string -// constants, one and two character operators -// -// 2010-03-21 FIXME removed an error check for translator simple expression -// testing -// -// 2010-04-16 removed the unexpected character errors in scan_command() that -// was occurring in a statements like "A,B=3" because these were -// not valid immediate commands, so these errors were removed to -// let the Translator process it (and report an error as necessary) -// -// 2010-05-29 corrected a problem in the get_number() function where a -// constant of a single '0' caused "invalid leading zero in numeric -// constant" error, the solution was to check if the next character -// is a digit, the number is complete, otherwise an error occurs -// -// 2010-06-25 TableSearch replaced with SearchType -// -// 2011-01-11 set token length for identifiers and number constants -// -// 2011-02-26 changed all table index to code, search() now returns code -// -// 2011-03-14 also set token length for FN identifiers -// -// 2011-03-26 modified get_identifier() to not store the open parentheses of -// DefFuncP and Paren token types -// 2011-03-27 modified get_number() to look for a negative sign in front of -// constants if the new operand_state flag is set -// 2011-06-07 added checks for maximum integer in scan_command() and -// get_number(), necessary when compiling on with 64-bit -// 2012-10-31 added 'const' to 'char *' variables (input not modified) -// 2012-11-01 removed immediate command parsing -// replaced String, char processing with QString and QChar -// renamed variables and functions to Qt style naming +// 2010-03-01 initial version #include "parser.h" #include "table.h" diff --git a/regtest.bat b/regtest.bat index 9683089..56df06c 100644 --- a/regtest.bat +++ b/regtest.bat @@ -20,20 +20,7 @@ rem rem rem Change History: rem -rem 2010-05-29 initial release -rem 2010-06-10 added translator tests 10 and 11 -rem 2010-06-29 added translator test 12 -rem 2010-07-04 added translator test 13 -rem 2011-01-04 added translator test 14 -rem 2011-02-05 added translator test 15 -rem 2011-03-20 added translator test 16 -rem 2011-03-27 added translator test 17 -rem -rem 2012-10-13 modified to change in test code that now reads test inputs -rem from test input files -rem removed specific test numbers, batch file now runs tests for -rem add the *.dat files present in the test directory -rem added compare for expression tests +rem 2010-05-29 initial version rem rem rem Usage: diff --git a/regtest.in b/regtest.in index a4a7c24..463f482 100755 --- a/regtest.in +++ b/regtest.in @@ -20,26 +20,7 @@ # # Change History: # -# 2010-05-29 initial release -# 2010-06-10 added translator tests 10 and 11 -# 2010-06-29 added translator test 12 -# 2010-07-04 added translator test 13 -# 2011-01-04 added translator test 14 -# 2011-01-09 changed name of executable from ibcp to ibcp.exe to make -# it work properly on Linux (this still works under windows; -# before the .exe was being added automatically) -# 2011-02-05 added translator test 15 -# 2011-03-20 added translator test 16 -# 2011-03-27 added translator test 17 -# -# 2012-10-13 renamed to regtest.in so that source directory can be -# confingured when cmake is run; replaced the parser and -# translator test loops with a single loop that tests all the -# available *.dat test input files -# 2012-10-22 added "./" in front of "ibcp" so that program can be run without -# having to have "." in the current PATH -# -# 2012-10-29 added version output +# 2010-05-29 initial version # # # Usage: diff --git a/rel_notes.txt b/rel_notes.txt index 3ec7b14..841b147 100644 --- a/rel_notes.txt +++ b/rel_notes.txt @@ -20,6 +20,7 @@ see . Planned Roadmap (needs to redone): + Implement GUI Translator - Colons (Parser issues, Token Status Enumeration) Encoder - (for commands implemented so far) Dictionary Definition (variables and arrays) @@ -36,6 +37,34 @@ Planned Roadmap (needs to redone): Command - Single line DEF FN To be defined... + Note: For this release on, changes to individual source files will no + longer be listed (there are too many files). However, changes to the + major classes will be included. Complete details of the changes can be + found in the git repository at https://github.com/thunder422/ibcp. + + +Release 0.2.0 (2012-12-09) + + Project developmental release - the project was transitioned to using + the Qt graphical development toolkit. This includes using the Qt tool + classes instead of the C standard library functions. Implementation + of the GUI was started, but only the about box is functional when the + program is started with no command line options. The following + additional major changes were made in this release: + + - new tester, command line and main window classes + - class definitions put into their own header files + - translator token and command handlers in their own source files + - test functions put into new tester class + - list, stack and string classes replaced with Qt classes + - variable and function names renamed using camel casing + - main source file changed from ibcp.cpp to main.cpp + - header change commands were removed from source files + (see the git repository for details of changes) + - cmake now detects when version number mismatches with git repository + - new memory leak detection test script + - test programs and results removed (no longer applicable) + Release 0.1.16 (2011-03-25) diff --git a/table.h b/table.h index 5856ca6..009d948 100644 --- a/table.h +++ b/table.h @@ -21,11 +21,6 @@ // Change History: // // 2012-11-03 initial version (parts removed from ibcp.h) -// 2012-11-04 moved all table specific (private) definitions to table.cpp -// moved code for access functions to table.cpp -// renamed variables and functions to Qt style naming -// changed the rest of char* to QString -// 2012-11-04 modified table class so that only one instance can be created #ifndef TABLE_H #define TABLE_H diff --git a/test_names.awk b/test_names.awk index 680e49c..83e0d51 100644 --- a/test_names.awk +++ b/test_names.awk @@ -23,24 +23,6 @@ # # 2010-09-06 initial release (started with codes.awk) # -# 2011-02-26 rewrote script to generate test_codes.h directly from the -# table.cpp source file (all code performed in BEGIN block) -# -# 2011-06-12 for use with cmake, added an optional path to the source files -# as the first argument on the awk command line -# 2012-10-06 changed the length argument of the substr() that extracts the -# name of the code from the "_Code" suffix so that it will also -# work with a DOS format file that contains the extra CR character -# on the end of the line, because if the RS variable was set to -# "/r/n" then this script no longer works on Linux -# 2012-10-14 renamed from test_codes.awk and now writes test_names.h -# changed to write complete code_name[] array along with generating -# the tokentype_name[] and datatype_name[] arrays from ibcp.h -# 2012-10-14 continued lines cause problems on Windows, so these were removed -# by using an output variable to hold the "test_names.h" name -# -# 2012-11-03 modified for header file location changes of enumerations -# # # Usage: awk -f test_names.awk # diff --git a/token.h b/token.h index 414f794..97bb3a9 100644 --- a/token.h +++ b/token.h @@ -21,7 +21,6 @@ // Change History: // // 2012-11-02 initial version (parts removed from ibcp.h) -// 2012-11-03 changed to class, renamed variables and functions to Qt style #ifndef TOKEN_H #define TOKEN_H diff --git a/translator.cpp b/translator.cpp index 98cc78e..e045d8a 100644 --- a/translator.cpp +++ b/translator.cpp @@ -20,358 +20,7 @@ // // Change History: // -// 2010-03-01 initial release -// -// 2010-03-20 continued development - functions now implemented for -// handling simple expressions (basic operands and operators) -// -// 2010-03-21 needed to pop final result off of done stack, added checks -// added check for EOL at begin of line -// changed unary operator check, corrected in add_operator() -// -// 2010-03-25 added parentheses support -// added switch for special operator token processing -// -// 2010-03-26 corrected issue with setting last_precedence by moving it from -// being set with '(' to being set with ')' added -// do_pending_paren() to replace code in three locations, and call -// from two new locations -// -// 2010-04-02 added array and function support -// added count stack to keep track of (count) commas within -// arrays (subscripts) and functions (arguments), and to make -// sure commas are not found within regular parentheses -// modified close parentheses processing to handle the operands -// (subscripts and arguments) within arrays and functions -// -// 2010-04-04 added internal function number of arguments checking -// changed argument of add_token() to reference so that it can -// modified to point to the token with the error -// -// 2010-04-11 added assignment operator handling including multiple -// assignments (additional comma handling) -// 2010-04-12 added reference support -// 2010-04-13 changed add_operator() argument to reference so that different -// token can be returned -// added code to add_operator() to check for references for -// assignment operator -// 2010-04-14 added code to add_operator() to check for references for -// list assignment operator -// 2010-04-16 added mode checking for the open parentheses token processing -// clear reference flag to top item in done stack for close paren -// added count stack is empty check before checking mode for open -// parentheses, equal operator and no special operator -// -// 2010-04-25 set default data type for operands -// corrected memory leak of comma and close parentheses tokens -// added data type handling for internal functions and operators -// implemented new find_code() and match_code() functions for data -// type handling -// 2010-04-26 changed bug error names -// -// 2010-05-08 implemented data type handling for assignment operators -// modified find_code() to handle references on first operand -// modified find_code() to get number of associated codes -// modified match_code() to handle references on first operand -// added last_operand argument to find_code() -// -// 2010-05-15 added temporary string support: -// changed output list and done stack from Token* to RpnItem* -// for arrays and functions, save pointers to operands -// for internal functions with string operands, saved operands -// for operators with string operands, saved operands -// moved find_code() operand[] array to class for all to access -// removed operandp[] argument from match_code(), now uses member -// added entries to match_code() conversion code table for TmpStr -// -// 2010-05-16 corrected problem where saved operand was not pointing to a -// conversion code that was inserted after the operand - the -// operand was set to the return value of the append call when the -// conversion code is inserted -// -// 2010-05-19 added sub-string support: -// in find_code() rearranged first operand code and added check for -// a sub-string function to get the string operands reference -// flag -// added SubStr entries to the convert code table in match_code() -// 2010-05-21 when an error occurs with a sub-string function where its string -// operand cannot be assigned, the change the token with the error -// to the string operand that can't be assigned instead of pointing -// to the sub-string function -// -// 2010-05-22 corrected issue where string list assignments were not saving -// all of the operands instead of just the last two -// updated add_operator() to handle mix string list assignments -// -// 2010-05-28 changed hold_stack and done_stack from List to SimpleStack, -// which required some small changes of push and pop calls -// replaced switch and case code to token handler functions -// moved special token processing in switch statement to individual -// token handler functions, switch statement was removed -// 2010-05-29 moved no special operator code was also moved to a token handler -// function -// updated for moving/renaming Translator::Status and -// Translator::Mode to TokenStatus and TokenMode -// changed do_pending_paren() from appending dummy parentheses -// token to output list to setting parentheses sub-code of the -// last token appended to list -// changed argument of do_pending_paren() from table entry index -// to token pointer (which was only used to get the precedence); -// this corrects a problem where the token on top of the hold -// stack was an identifier with parentheses (array or function) -// because these tokens don't have an index value, therefore the -// precedence access function needs to be used, which takes these -// token types into account -// added setting of comma sub-code flag of assignment list token -// when receiving an equal in comma assignment mode -// added section of code at beginning of add_token for doing -// initial processing for Command tokens when received, -// if command has token_mode table entry value then command is -// pushed on new command stack, otherwise unexpected command -// occurs -// added check to add_operator() that if operator is an assignment -// (Reference_Flag is set) then check if there is a LET command -// on the command stack, pop it, and set LET sub-code flag on -// assignment operator token -// -// 2010-06-01 corrected a bug when an operand is processed, if the mode is -// currently Command mode, the mode needs to be changed to -// Assignment mode to prevent commands from being accepted -// additional support for commands and command stack -// added support for print-only functions -// 2010-06-02 added token handler for semicolon (for PRINT command) -// 2010-06-03 added PRINT support for comma -// created expression_end() from parts of EndOfLine_Handler for -// end of expression checks (also used by comma and semicolon) -// 2010-06-04 implemented new add_print_code() function to be used by -// Comma_Handler(), SemiColon_Handler() and Print_CmdHandler() -// 2010-06-05 implemented Assign_CmdHandler() and Print_CmdHandler() -// push assignment token to command stack instead of done stack so -// the end of statement is handled properly and simply -// 2010-06-06 correctly check for expression only mode at end-of-line -// end-of-line no longer pops a result off from done stack, which -// should now be empty (commands deal with done stack) except for -// special expression only mode -// added support for end expression flag - codes that can end an -// expression (currently comma, semicolon and EOL) -// switch back to operand state after comma and semicolon -// 2010-06-08 set a print function flag in print command stack item to -// indicate a print function flag was just added to the output, -// which semicolon checks for and sets the semicolon sub-code -// flag on the print function token in case the print function is -// at the end of the print statement -// moved end expression flag check to operand section before unary -// operator check, if in the middle of a parentheses expression -// or array/function, then return expected closing parentheses -// error -// 2010-06-09 changed count stack from holding just a counter to holding the -// counter and the expected number of arguments for internal -// functions, so that the number of arguments for internal -// functions can be checked as each comma token is received -// 2010-06-10 added new state FirstOperand set at the beginning of an -// expression -// renamed errors for clarity -// 2010-06-11 added check to detect invalid print-only functions sooner -// 2010-06-13 changed to push AssignList token to hold stack when first comma -// token is received instead of when equal token is received -// (necessary for proper error condition tests) -// Let_CmdHandler implemented, necessary to catch errors when a -// LET command statement was not completed correctly -// 2010-06-14 added check for immediate command token (append to output list -// and return Done) -// added paren_status() from duplicated code in add_token() and -// expression_end() -// 2010-06-10/14 various changes to return appropriate easy to understand -// error messages -// -// 2010-06-24 corrected errors for internal functions not in expressions -// except for sub-string functions that can be used for -// assignments -// at end of expression, added check if in assignment due to an -// an array or sub-string function, to report correct errors -// 2010-06-26 added end of statement checking in the binary operator section -// made more error reporting corrections related to checking if the -// done stack is empty to determine the correct error to report -// 2010-06-29 added support for expression type -// added data type to expression type conversion array -// 2010-06-30 continues to add support for expression type -// added expected variable messages for assign list errors -// 2010-07-01 moved cvtcode_have_need[], equivalent_datatype[] to begin of -// source file so all can access -// implemented new assign and assign list code to Comma_Handler(), -// Semicolon_Handler() and Assign_CmdHandler() with support -// functions set_assign_command() and check_assignlist_token() -// removed last_operand argument from find_code(), which was for -// assign list support -// 2010-07-02 added more expr_type checking code -// 2010-07-03 added errstatus_datatype[] -// 2010-07-04 temporarily removed all expr_type code (may be removed) -// 2010-07-05 many changes for error reporting -// 2010-07-06 many changes for error reporting -// -// 2010-07-29 set reference of sub-string tokens within assignments so that -// first operand (string being assigned) can be checked -// 2010-08-01 removed EqualAssignment, replaced CommaAssignment with -// AssignmentList (multiple equal assignment statements no longer -// being supported) -// 2010-08-07 begin modification of find_code() to only process one operand -// at a time -// removed match_code() since it's not necessary to match all -// operands of operators or internal functions -// 2010-08-14 changed the way multiple argument codes are handled (due to -// processing one operand at a time) -// 2010-08-30 begin implementation of process_final_operand() to handle -// processing of last operand of operand or internal function -// 2010-09-11 begin implementation of leaving only string operands on stack -// to be attached to an operand or internal function token -// 2010-10-01 corrected code to return expected type errors -// 2010-10-10 check first operand of sub-string assignment is not a string -// variable -// 2010-12-24 corrected process_final_operand() to pop the correct number of -// string operands to attach -// 2010-12-25 modified to leave string operand on stack for sub-string -// functions and not push the sub-string token to the done stack -// -// 2010-12-28 corrected call to process_final_operand() in add_print_code() -// 2010-12-29 modified EndOfLine_Handler() to wait to pop the command on top -// of the command stack until after the command handler is called -// 2011-01-01 made None_DataType return expected error instead of bug error -// 2011-01-03 implemented new function get_expr_datatype() to get the current -// datatype of the expression by looking back at what was -// processed so far; called when an error occurs so that the -// appropriate error can be reported) -// 2011-01-04 assign datatype to open parentheses when being pushed to the -// hold stack (to be used later when getting the datatype for an -// expression) -// -// 2011-01-08 get datatype of expression to get appropriate error when a -// binary operator occurs when an operand is expected -// corrected paren_status() when at last argument of first form -// of a function with multiple forms to report the appropriate -// error (that a comma could also be expected) -// in Comma_Handler() when an error occurs and the done stack is -// empty, get data type of expression to get appropriate error -// in Comma_Handler() when moving to the next multiple form of a -// function, corrected the setting of the index on count stack -// -// 2011-01-13 started implementation of storing first and last operands -// converted hold stack from holding token pointers to holding -// hold stack items (with a token and first pointer) -// added argument to process_final_operand() for passing in an -// operand (either first operand or CloseParen token) -// 2011-01-14 implemented new process_first_operand() with code from -// Operator/Equal handlers -// 2011-01-15 converted done stack from holding output list element pointers -// to holding done stack items (with element, first, and last -// pointers) -// added arguments to find_code() for return first/last operands -// implemented new delete_close_paren() to check for and delete a -// CloseParen token that may be in done stack last token -// 2011-01-16 in delete_close_paren(), also check if token has table entry -// added reporting range of tokens for expression type errors -// in clean_up(), fixed to not delete tokens until after stacks -// in EndOfLine_Handler(), corrected cleanup for expression mode -// 2011-01-20 in process_final_operand(), current unary operators to only set -// last operand (first operand should be the unary operator) -// 2011-01-22 in do_pending_paren(), corrected to delete pending paren token -// when setting parentheses sub-code -// implement new function delete_open_paren() -// in delete_close_paren(), check if close paren token still being -// used as pending paren (don't delete, just clear last sub-code) -// modified find_code() to use work first/last token pointers -// 2011-01-23 in CloseParen_Handler(), save both open and close paren tokens -// as first/last operands (don't delete open paren token), -// and set last and used sub-code flags of close paren token so -// it doesn't get deleted until its not used anymore -// 2011-01-30 corrected token memory leaks -// 2011-02-01 corrected token memory leaks -// 2011-02-02 in find_code() upon a no match error, removed checks if last -// token added was sub-string; not necessary with first/last code -// 2011-02-05 in process_final_operand() added check if token is assignment -// operator to not push to done stack (strings still attached) -// replaced most code in Assign_CmdHandler() with call to -// process_final_operand() -// -// 2011-02-10 implemented new call_command_handler() for comma and semicolon -// token handlers to call for command on top of command stack -// moved code from comma and semicolon token handlers to assign -// and print command handlers (into new switch statements) -// 2011-02-11 in Assign_CmdHandler(), when an error occurs, need to set set -// the command item's token to the passed in token -// in Print_CmdHandler(), make sure good status is returned when -// add_print_code() returns null status for nothing done -// 2011-02-13 moved code from add_token() to add_operator(), which was renamed -// to process_operator() -// moved code from add_token() to process_binary_operator() -// -// 2011-02-22 changed all pop() calls not using return value to null_pop() -// 2011-02-26 updated for change of table index to code -// 2011-03-01 initialized new element member for command stack item -// removed code member from command stack item (now token->code) -// started implementation of Input_CmdHandler() -// 2011-03-03 changed process_final_operand() from checking for print -// functions to functions with no return value, fixed problem -// with deleting second token when not set (for print functions) -// 2011-03-05 added non-empty hold stack to print function token check -// added "_State" to enum Translator::State values -// added new EndExpr_State, check to process_binary_operator() -// replaced PrintOnlyIntFunc with expected xxx expression error -// 2011-03-07 implemented reference mode -// corrected problem with print functions within parentheses -// 2011-03-09 moved sub-string function operand check to begin of -// process_binary_operator() to prevent acceptance of operators -// 2011-03-10 removed unexpected command error, just pass command token on -// 2011-03-11 changed to assignment mode after an operand is received while -// in command mode, changed code for with mode change -// return appropriate error for mode in process_operand() and -// Comma_Handler() -// 2011-03-12 added new operator_error() to determine error when token is not -// an expected operator from parts of process_binary_operator() -// and now also called from process_operator() for command tokens -// that have no token handler -// check for command token with no handler in process_operator() -// implemented new operator_error() from parts of -// process_binary_operator() so that code in process_operator() -// can also call it -// removed extra empty count stack mode check from middle of -// processed_unary_operator() - now at begin of function -// 2011-03-13 added check to make sure first operand of a sub-string function -// assignment is not a unary operator in process_unary_operator() -// changed non-reference return error in find_code() -// 2011-03-14 return error at parentheses for DefFuncP tokens in -// process_operand() and check_assignlist_item() -// don't set DefFuncP reference flag in CloseParen_Handler() -// 2011-03-19 implemented end statement state -// completed implementation of Input_CmdHandler() -// renamed EndStatment_Flag to EndStmt_Flag -// 2011-03-20 don't delete EOL token if not EOL code in EndOfLine_Handler() -// changed to insert InputBegin at beginning of statement, -// required initializing CmdStackItem element to output->last(), -// and new InputBegin_CmdFlag support -// set reference flag of input assign to handle variable correctly -// added reference mode support to Comma_Handler() -// 2011-03-21 set reference mode after string prompt in Input_CmdHandler() -// 2011-03-22 set Operand_State after string prompt in Input_CmdHandler() -// renamed FirstOperand_State to OperandOrEnd_State -// 2011-03-24 set token with error in cmd_item to return in Input_CmdHandler() -// added reference mode to end_expression_error() -// 2011-03-25 removed token delete with prompt error in Input_CmdHandler() -// -// 2011-03-26 modified the token error pointer for DefFuncP tokens to -// to compensate for the lack of the open parentheses that is no -// longer stored in the token string -// 2011-03-27 modified process_operator() to not allow unary operators to -// force other tokens from hold stack -// -// 2012-10-25 corrected if statements that were checking token code without -// making sure code was valid (some token types don't used code) -// 2012-10-27 converted output rpn list from List class to QList -// also required changes to done_stack (element list pointer to -// rpn item pointer), cmd_stack (element list pointer to index -// into output rpn list), and RpnItem.operands[] (element list -// pointer array to RpnItem pointer array) -// 2012-10-29 converted translator stacks from Stack class to QStack -// 2012-11-01 removed immediate command support +// 2010-03-01 initial version #include "translator.h" #include "token.h"