00001 #include "SIGEL_RobotIO/SIG_RobotScanner.h" 00002 #include "SIGEL_RobotIO/SIG_RobotIOExceptions.h" 00003 #include <iostream> 00004 00005 namespace SIGEL_RobotIO { 00006 namespace RobotSymbol { 00007 int const openingBrace = 1; 00008 int const closingBrace = 2; 00009 int const openingParen = 3; 00010 int const closingParen = 4; 00011 int const word = 5; 00012 int const number = 6; 00013 int const string = 7; 00014 int const semicolon = 8; 00015 int const comma = 9; 00016 int const equals = 10; 00017 int const slash = 11; 00018 } 00019 00020 SIG_RobotScanner::SIG_RobotScanner (QString liesdas) 00021 : SIG_Scanner (liesdas) 00022 { } 00023 00024 SIG_RobotScanner::~SIG_RobotScanner (void) 00025 { } 00026 00027 void SIG_RobotScanner::nextSymbol (void) 00028 { 00029 skipWhiteSpace (); 00030 if (position >= text.length ()) { 00031 currentSymbol = "(EOS)"; 00032 currentSymType = Symbol::EOS; 00033 } else if (text.at (position) == '{') { 00034 position++; 00035 currentSymbol = "{"; 00036 currentSymType = RobotSymbol::openingBrace; 00037 } else if (text.at (position) == '}') { 00038 position++; 00039 currentSymbol = "}"; 00040 currentSymType = RobotSymbol::closingBrace; 00041 } else if (text.at (position) == '(') { 00042 position++; 00043 currentSymbol = "("; 00044 currentSymType = RobotSymbol::openingParen; 00045 } else if (text.at (position) == ')') { 00046 position++; 00047 currentSymbol = ")"; 00048 currentSymType = RobotSymbol::closingParen; 00049 } else if (text.at (position).isLetter ()) { 00050 int fp = position; 00051 position++; 00052 while ((position < text.length ()) && 00053 (text.at (position).isLetterOrNumber () || 00054 (text.at (position) == '_'))) 00055 position++; 00056 currentSymbol = text.mid (fp, position - fp); 00057 currentSymType = RobotSymbol::word; 00058 } else if ((text.at (position) == '-') || 00059 (text.at (position) == '+') || 00060 (text.at (position).isNumber ())) { 00061 int fp = position; 00062 position++; 00063 while ((position < text.length ()) && 00064 text.at (position).isNumber ()) 00065 position++; 00066 if ((position < text.length ()) && 00067 (text.at (position) == '.')) { 00068 position++; 00069 while ((position < text.length ()) && 00070 text.at (position).isNumber ()) 00071 position++; 00072 } 00073 if ((position < text.length ()) && 00074 ((text.at (position) == 'e') || 00075 (text.at (position) == 'E'))) { 00076 position++; 00077 if ((position < text.length ()) && 00078 ((text.at (position) == '+') || 00079 (text.at (position) == '-'))) 00080 position++; 00081 while ((position < text.length ()) && 00082 text.at (position).isNumber ()) 00083 position++; 00084 } 00085 currentSymbol = text.mid (fp, position - fp); 00086 currentSymType = RobotSymbol::number; 00087 } else if (text.at (position) == '\"') { 00088 int fp = position; 00089 position++; 00090 while ((position < text.length ()) && 00091 (text.at (position) != '\"')) { 00092 if ((text.at (position) == '\n') || 00093 (text.at (position) == '\r')) 00094 throw SIG_SyntaxError (__FILE__, __LINE__, 00095 "String contains EOL", 00096 "(unknown)", lineposition); 00097 position++; 00098 } 00099 if (position >= text.length ()) 00100 throw SIG_SyntaxError (__FILE__, __LINE__, 00101 "Unexpected end of text in string scanning", 00102 "(unknown)", lineposition); 00103 position++; 00104 currentSymbol = text.mid (fp + 1, position - fp - 2); 00105 currentSymType = RobotSymbol::string; 00106 } else if (text.at (position) == ';') { 00107 position++; 00108 currentSymbol = ";"; 00109 currentSymType = RobotSymbol::semicolon; 00110 } else if (text.at (position) == ',') { 00111 position++; 00112 currentSymbol = ","; 00113 currentSymType = RobotSymbol::comma; 00114 } else if (text.at (position) == '=') { 00115 position++; 00116 currentSymbol = "="; 00117 currentSymType = RobotSymbol::equals; 00118 } else if (text.at (position) == '/') { 00119 position++; 00120 currentSymbol = "/"; 00121 currentSymType = RobotSymbol::slash; 00122 } else { 00123 throw SIG_SyntaxError (__FILE__, __LINE__, 00124 "Unknown symbol.", 00125 "(unknown)", lineposition); 00126 } 00127 } 00128 }