Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

ShTokenizer.cpp

00001 // Sh: A GPU metaprogramming language. 00002 // 00003 // Copyright (c) 2003 University of Waterloo Computer Graphics Laboratory 00004 // Project administrator: Michael D. McCool 00005 // Authors: Zheng Qin, Stefanus Du Toit, Kevin Moule, Tiberiu S. Popa, 00006 // Michael D. McCool 00007 // 00008 // This software is provided 'as-is', without any express or implied 00009 // warranty. In no event will the authors be held liable for any damages 00010 // arising from the use of this software. 00011 // 00012 // Permission is granted to anyone to use this software for any purpose, 00013 // including commercial applications, and to alter it and redistribute it 00014 // freely, subject to the following restrictions: 00015 // 00016 // 1. The origin of this software must not be misrepresented; you must 00017 // not claim that you wrote the original software. If you use this 00018 // software in a product, an acknowledgment in the product documentation 00019 // would be appreciated but is not required. 00020 // 00021 // 2. Altered source versions must be plainly marked as such, and must 00022 // not be misrepresented as being the original software. 00023 // 00024 // 3. This notice may not be removed or altered from any source 00025 // distribution. 00027 #include "ShTokenizer.hpp" 00028 #include "ShError.hpp" 00029 00030 namespace SH { 00031 00032 ShTokenizerException::ShTokenizerException(const std::string& error) 00033 : ShException("Tokenizer error: " + error) 00034 { 00035 } 00036 00037 ShTokenizer::ShTokenizer() 00038 { 00039 m_listStack.push(new ShBlockList()); 00040 } 00041 00042 bool ShTokenizer::pushArgQueue() 00043 { 00044 m_argQueueStack.push(std::queue<ShTokenArgument>()); 00045 return true; 00046 } 00047 00048 bool ShTokenizer::pushArg() 00049 { 00050 m_listStack.push(new ShBlockList(true)); 00051 return true; 00052 } 00053 00054 bool ShTokenizer::processArg(const ShVariable& result) 00055 { 00056 00057 if (!m_listStack.top()->isArgument()) { 00058 shError( ShTokenizerException("Attempt to process an argument outside of an argument context.") ); 00059 } 00060 00061 if (m_argQueueStack.empty()) { 00062 shError( ShTokenizerException("Attempt to process an argument without a context.") ); 00063 } 00064 00065 m_argQueueStack.top().push(ShTokenArgument(result, m_listStack.top())); 00066 m_listStack.pop(); 00067 return true; 00068 } 00069 00070 ShBlockListPtr ShTokenizer::blockList() 00071 { 00072 if (m_listStack.empty()) { 00073 shError( ShTokenizerException("No current tokenized list.") ); 00074 } 00075 return m_listStack.top(); 00076 } 00077 00078 ShTokenArgument ShTokenizer::getArgument() 00079 { 00080 if (m_argQueueStack.empty()) { 00081 shError( ShTokenizerException("getArgument(): Argument stack underflow") ); 00082 } 00083 if (m_argQueueStack.top().empty()) { 00084 shError( ShTokenizerException("getArgument(): Argument is empty") ); 00085 } 00086 ShTokenArgument r = m_argQueueStack.top().front(); 00087 m_argQueueStack.top().pop(); 00088 return r; 00089 } 00090 00091 void ShTokenizer::popArgQueue() 00092 { 00093 if (m_argQueueStack.empty()) { 00094 shError( ShTokenizerException("popArgQueue(): Argument stack underflow") ); 00095 } 00096 m_argQueueStack.pop(); 00097 } 00098 00099 } 00100 00101 00102

Generated on Mon Oct 18 14:17:40 2004 for Sh by doxygen 1.3.7