1a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block/****************************************************************************\ 2a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve BlockCopyright (c) 2002, NVIDIA Corporation. 3a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 4a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve BlockNVIDIA Corporation("NVIDIA") supplies this software to you in 5a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Blockconsideration of your agreement to the following terms, and your use, 6a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Blockinstallation, modification or redistribution of this NVIDIA software 7a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Blockconstitutes acceptance of these terms. If you do not agree with these 8a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Blockterms, please do not use, install, modify or redistribute this NVIDIA 9a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Blocksoftware. 10a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 11a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve BlockIn consideration of your agreement to abide by the following terms, and 12a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Blocksubject to these terms, NVIDIA grants you a personal, non-exclusive 13a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Blocklicense, under NVIDIA's copyrights in this original NVIDIA software (the 14a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block"NVIDIA Software"), to use, reproduce, modify and redistribute the 15a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve BlockNVIDIA Software, with or without modifications, in source and/or binary 16a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Blockforms; provided that if you redistribute the NVIDIA Software, you must 17a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Blockretain the copyright notice of NVIDIA, this notice and the following 18a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Blocktext and disclaimers in all such redistributions of the NVIDIA Software. 19a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve BlockNeither the name, trademarks, service marks nor logos of NVIDIA 20a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve BlockCorporation may be used to endorse or promote products derived from the 21a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve BlockNVIDIA Software without specific prior written permission from NVIDIA. 22a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve BlockExcept as expressly stated in this notice, no other rights or licenses 23a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Blockexpress or implied, are granted by NVIDIA herein, including but not 24a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Blocklimited to any patent rights that may be infringed by your derivative 25a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Blockworks or by other works in which the NVIDIA Software may be 26a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Blockincorporated. No hardware is licensed hereunder. 27a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 28a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve BlockTHE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT 29a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve BlockWARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, 30a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve BlockINCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE, 31a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve BlockNON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR 32a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve BlockITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER 33a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve BlockPRODUCTS. 34a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 35a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve BlockIN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, 36a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve BlockINCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 37a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve BlockTO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 38a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve BlockUSE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY 39a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve BlockOUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE 40a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve BlockNVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, 41a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve BlockTORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF 42a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve BlockNVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 43a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block\****************************************************************************/ 44a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block// 45a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block// scanner.c 46a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block// 47a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 48ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch#include <assert.h> 49a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block#include <stdarg.h> 50a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block#include <stdio.h> 51a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block#include <stdlib.h> 52a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block#include <string.h> 53a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 54a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block#if 0 55a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block #include <ieeefp.h> 56ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch#else 57a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block #define isinff(x) (((*(int *)&(x) & 0x7f800000L)==0x7f800000L) && \ 58a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ((*(int *)&(x) & 0x007fffffL)==0000000000L)) 59a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block#endif 60a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 61a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block#include "compiler/preprocessor/slglobals.h" 62ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch#include "compiler/util.h" 63a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 64a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Blocktypedef struct StringInputSrc { 65a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block InputSrc base; 66a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block char *p; 67a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block} StringInputSrc; 68a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 69a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Blockstatic int eof_scan(InputSrc *is, yystypepp * yylvalpp) 70a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block{ 71a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return EOF; 72a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block} // eof_scan 73a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 74a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Blockstatic void noop(InputSrc *in, int ch, yystypepp * yylvalpp) {} 75a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 76a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Blockstatic InputSrc eof_inputsrc = { 0, &eof_scan, &eof_scan, &noop }; 77a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 78a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Blockstatic int byte_scan(InputSrc *, yystypepp * yylvalpp); 79a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 80a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block#define EOL_SY '\n' 81a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 82a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block#if defined(_MSC_VER) 83a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block #define DBG_BREAKPOINT() __asm int 3 84a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block#elif defined(_M_AMD64) 85a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block #define DBG_BREAKPOINT() assert(!"Dbg_Breakpoint"); 86a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block#else 87a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block #define DBG_BREAKPOINT() 88a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block#endif 89a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 90a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block#if defined(_MSC_VER) && !defined(_M_AMD64) 91a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block __int64 RDTSC ( void ) { 92a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 93a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block __int64 v; 94a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 95a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block __asm __emit 0x0f 96a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block __asm __emit 0x31 97a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block __asm mov dword ptr v, eax 98a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block __asm mov dword ptr v+4, edx 99a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 100a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return v; 101a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 102a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block#endif 103a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 104a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 105a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Blockint InitScanner(CPPStruct *cpp) 106a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block{ 107a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block // Add various atoms needed by the CPP line scanner: 108a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (!InitCPP()) 109a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return 0; 110a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 111a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block cpp->mostRecentToken = 0; 112a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block cpp->tokenLoc = &cpp->ltokenLoc; 113a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 114a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block cpp->ltokenLoc.file = 0; 115a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block cpp->ltokenLoc.line = 0; 116a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 117a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block cpp->currentInput = &eof_inputsrc; 118a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block cpp->previous_token = '\n'; 119a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block cpp->pastFirstStatement = 0; 120a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 121a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return 1; 122a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block} // InitScanner 123a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 124a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Blockint FreeScanner(void) 125a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block{ 126a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return (FreeCPP()); 127a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block} 128a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 129a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block/* 130a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block * str_getch() 131a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block * takes care of reading from multiple strings. 132a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block * returns the next-char from the input stream. 133a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block * returns EOF when the complete shader is parsed. 134a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block */ 135a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Blockstatic int str_getch(StringInputSrc *in) 136a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block{ 137ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch for(;;){ 138ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch if (*in->p){ 139ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch if (*in->p == '\n') { 140a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block in->base.line++; 141a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block IncLineNumber(); 142a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 143a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return *in->p++; 144ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch } 145ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch if(++(cpp->PaWhichStr) < cpp->PaArgc){ 146ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch free(in); 147ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch SetStringNumber(cpp->PaWhichStr); 148ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch SetLineNumber(1); 149ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch ScanFromString(cpp->PaArgv[cpp->PaWhichStr]); 150ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch in=(StringInputSrc*)cpp->currentInput; 151ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch continue; 152ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch } 153ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch else{ 154ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch cpp->currentInput = in->base.prev; 155ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch cpp->PaWhichStr=0; 156a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block free(in); 157a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return EOF; 158a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 159ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch } 160a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block} // str_getch 161a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 162a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Blockstatic void str_ungetch(StringInputSrc *in, int ch, yystypepp *type) { 163a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (in->p[-1] == ch)in->p--; 164ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch else { 165ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch *(in->p)='\0'; //this would take care of shifting to the previous string. 166ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch cpp->PaWhichStr--; 167ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch } 168ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch if (ch == '\n') { 169a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block in->base.line--; 170a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block DecLineNumber(); 171a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 172a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block} // str_ungetch 173a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 174ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdochint ScanFromString(const char *s) 175a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block{ 176a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 177ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch StringInputSrc *in = malloc(sizeof(StringInputSrc)); 178a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block memset(in, 0, sizeof(StringInputSrc)); 179ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch in->p = (char*) s; 180a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block in->base.line = 1; 181a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block in->base.scan = byte_scan; 182a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block in->base.getch = (int (*)(InputSrc *, yystypepp *))str_getch; 183a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block in->base.ungetch = (void (*)(InputSrc *, int, yystypepp *))str_ungetch; 184a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block in->base.prev = cpp->currentInput; 185a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block cpp->currentInput = &in->base; 186a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 187a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return 1; 188a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block} // ScanFromString; 189a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 190a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 191a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block/////////////////////////////////////////////////////////////////////////////////////////////// 192a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block/////////////////////////////////// Floating point constants: ///////////////////////////////// 193a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block/////////////////////////////////////////////////////////////////////////////////////////////// 194a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 195ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch#define APPEND_CHAR_S(ch, str, len, max_len) \ 196ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch if (len < max_len) { \ 197ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch str[len++] = ch; \ 198ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch } else if (!alreadyComplained) { \ 199ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch CPPErrorToInfoLog("BUFFER OVERFLOW"); \ 200ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch alreadyComplained = 1; \ 201ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch } 202a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 203a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block/* 204a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block * lFloatConst() - Scan a floating point constant. Assumes that the scanner 205a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block * has seen at least one digit, followed by either a decimal '.' or the 206a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block * letter 'e'. 207ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch * ch - '.' or 'e' 208ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch * len - length of string already copied into yylvalpp->symbol_name. 209a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block */ 210a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 211ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdochstatic int lFloatConst(int ch, int len, yystypepp * yylvalpp) 212a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block{ 213ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch int alreadyComplained = 0; 214ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch assert((ch == '.') || (ch == 'e') || (ch == 'E')); 215ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch 216a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch == '.') { 217ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch do { 218ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch APPEND_CHAR_S(ch, yylvalpp->symbol_name, len, MAX_SYMBOL_NAME_LEN); 219ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 220ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch } while (ch >= '0' && ch <= '9'); 221a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 222a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 223a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block // Exponent: 224a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch == 'e' || ch == 'E') { 225ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch APPEND_CHAR_S(ch, yylvalpp->symbol_name, len, MAX_SYMBOL_NAME_LEN); 226a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 227a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch == '+') { 228ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch APPEND_CHAR_S(ch, yylvalpp->symbol_name, len, MAX_SYMBOL_NAME_LEN); 229ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 230a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } else if (ch == '-') { 231ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch APPEND_CHAR_S(ch, yylvalpp->symbol_name, len, MAX_SYMBOL_NAME_LEN); 232a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 233a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 234a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch >= '0' && ch <= '9') { 235a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block while (ch >= '0' && ch <= '9') { 236ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch APPEND_CHAR_S(ch, yylvalpp->symbol_name, len, MAX_SYMBOL_NAME_LEN); 237a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 238a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 239a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } else { 240ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch CPPErrorToInfoLog("EXPONENT INVALID"); 241a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 242a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 243ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp); 244ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch 245ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch assert(len <= MAX_SYMBOL_NAME_LEN); 246ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch yylvalpp->symbol_name[len] = '\0'; 247ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch yylvalpp->sc_fval = (float) atof_dot(yylvalpp->symbol_name); 248ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch if (isinff(yylvalpp->sc_fval)) { 249ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch CPPErrorToInfoLog("FLOAT CONSTANT OVERFLOW"); 250a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 251a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return CPP_FLOATCONSTANT; 252a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block} // lFloatConst 253a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 254a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block/////////////////////////////////////////////////////////////////////////////////////////////// 255a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block///////////////////////////////////////// Normal Scanner ////////////////////////////////////// 256a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block/////////////////////////////////////////////////////////////////////////////////////////////// 257a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 258a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Blockstatic int byte_scan(InputSrc *in, yystypepp * yylvalpp) 259a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block{ 260a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block char string_val[MAX_STRING_LEN + 1]; 261ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch int alreadyComplained = 0; 262a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block int len, ch, ii, ival = 0; 263a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 264a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block for (;;) { 265a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block yylvalpp->sc_int = 0; 266a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 267ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch 268a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block while (ch == ' ' || ch == '\t' || ch == '\r') { 269a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block yylvalpp->sc_int = 1; 270a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 271a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 272ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch 273a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block cpp->ltokenLoc.file = cpp->currentInput->name; 274a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block cpp->ltokenLoc.line = cpp->currentInput->line; 275ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch alreadyComplained = 0; 276a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block len = 0; 277a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block switch (ch) { 278a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block default: 279ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch return ch; // Single character token 280a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block case EOF: 281a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return -1; 282ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch case 'A': case 'B': case 'C': case 'D': case 'E': 283a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block case 'F': case 'G': case 'H': case 'I': case 'J': 284a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block case 'K': case 'L': case 'M': case 'N': case 'O': 285a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block case 'P': case 'Q': case 'R': case 'S': case 'T': 286a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block case 'U': case 'V': case 'W': case 'X': case 'Y': 287a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block case 'Z': case '_': 288a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block case 'a': case 'b': case 'c': case 'd': case 'e': 289a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block case 'f': case 'g': case 'h': case 'i': case 'j': 290a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block case 'k': case 'l': case 'm': case 'n': case 'o': 291a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block case 'p': case 'q': case 'r': case 's': case 't': 292a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block case 'u': case 'v': case 'w': case 'x': case 'y': 293a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block case 'z': 294a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block do { 295ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch APPEND_CHAR_S(ch, yylvalpp->symbol_name, len, MAX_SYMBOL_NAME_LEN); 296ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 297a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } while ((ch >= 'a' && ch <= 'z') || 298a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block (ch >= 'A' && ch <= 'Z') || 299a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block (ch >= '0' && ch <= '9') || 300a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ch == '_'); 301ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch assert(len <= MAX_SYMBOL_NAME_LEN); 302ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch yylvalpp->symbol_name[len] = '\0'; 303a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp); 304ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch yylvalpp->sc_ident = LookUpAddString(atable, yylvalpp->symbol_name); 305a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return CPP_IDENTIFIER; 306a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block break; 307a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block case '0': 308ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch APPEND_CHAR_S(ch, yylvalpp->symbol_name, len, MAX_SYMBOL_NAME_LEN); 309a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 310ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch if (ch == 'x' || ch == 'X') { // hexadecimal integer constants 311ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch APPEND_CHAR_S(ch, yylvalpp->symbol_name, len, MAX_SYMBOL_NAME_LEN); 312a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 313a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if ((ch >= '0' && ch <= '9') || 314a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block (ch >= 'A' && ch <= 'F') || 315a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block (ch >= 'a' && ch <= 'f')) 316a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block { 317a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ival = 0; 318a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block do { 319ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch if ((ival <= 0x0fffffff) && (len < MAX_SYMBOL_NAME_LEN)) { 320ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch yylvalpp->symbol_name[len++] = ch; 321a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch >= '0' && ch <= '9') { 322a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ii = ch - '0'; 323a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } else if (ch >= 'A' && ch <= 'F') { 324a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ii = ch - 'A' + 10; 325a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } else { 326a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ii = ch - 'a' + 10; 327a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 328a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ival = (ival << 4) | ii; 329ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch } else if (!alreadyComplained) { 330ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch CPPErrorToInfoLog("HEX CONSTANT OVERFLOW"); 331ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch alreadyComplained = 1; 332a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 333a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 334a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } while ((ch >= '0' && ch <= '9') || 335a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block (ch >= 'A' && ch <= 'F') || 336a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block (ch >= 'a' && ch <= 'f')); 337a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } else { 338ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch CPPErrorToInfoLog("HEX CONSTANT INVALID"); 339a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 340ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch assert(len <= MAX_SYMBOL_NAME_LEN); 341a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block yylvalpp->symbol_name[len] = '\0'; 342ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp); 343ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch yylvalpp->sc_int = ival; 344a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return CPP_INTCONSTANT; 345a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } else if (ch >= '0' && ch <= '7') { // octal integer constants 346a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ival = 0; 347a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block do { 348ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch if ((ival <= 0x1fffffff) && (len < MAX_SYMBOL_NAME_LEN)) { 349ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch yylvalpp->symbol_name[len++] = ch; 350a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ii = ch - '0'; 351a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ival = (ival << 3) | ii; 352ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch } else if (!alreadyComplained) { 353ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch CPPErrorToInfoLog("OCT CONSTANT OVERFLOW"); 354ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch alreadyComplained = 1; 355a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 356a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 357a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } while (ch >= '0' && ch <= '7'); 358a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch == '.' || ch == 'e' || ch == 'f' || ch == 'h' || ch == 'x'|| ch == 'E') 359ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch return lFloatConst(ch, len, yylvalpp); 360ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch assert(len <= MAX_SYMBOL_NAME_LEN); 361a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block yylvalpp->symbol_name[len] = '\0'; 362ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp); 363ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch yylvalpp->sc_int = ival; 364a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return CPP_INTCONSTANT; 365a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } else { 366ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp); 367ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch ch = '0'; 368a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 369a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block // Fall through... 370a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block case '1': case '2': case '3': case '4': 371a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block case '5': case '6': case '7': case '8': case '9': 372a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block do { 373ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch APPEND_CHAR_S(ch, yylvalpp->symbol_name, len, MAX_SYMBOL_NAME_LEN); 374ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 375a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } while (ch >= '0' && ch <= '9'); 376a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch == '.' || ch == 'e' || ch == 'f' || ch == 'h' || ch == 'x'|| ch == 'E') { 377ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch return lFloatConst(ch, len, yylvalpp); 378a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } else { 379ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch assert(len <= MAX_SYMBOL_NAME_LEN); 380a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block yylvalpp->symbol_name[len] = '\0'; 381ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp); 382a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ival = 0; 383a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block for (ii = 0; ii < len; ii++) { 384a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ch = yylvalpp->symbol_name[ii] - '0'; 385ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch ival = ival*10 + ch; 386a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if ((ival > 214748364) || (ival == 214748364 && ch >= 8)) { 387ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch CPPErrorToInfoLog("INTEGER CONSTANT OVERFLOW"); 388ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch break; 389a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 390a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 391a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block yylvalpp->sc_int = ival; 392a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if(ival==0) 393a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block strcpy(yylvalpp->symbol_name,"0"); 394a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return CPP_INTCONSTANT; 395a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 396a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block break; 397a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block case '-': 398a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 399a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch == '-') { 400a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return CPP_DEC_OP; 401a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } else if (ch == '=') { 402a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return CPP_SUB_ASSIGN; 403a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } else { 404a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp); 405a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return '-'; 406a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 407a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block case '+': 408a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 409a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch == '+') { 410a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return CPP_INC_OP; 411a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } else if (ch == '=') { 412a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return CPP_ADD_ASSIGN; 413a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } else { 414a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp); 415a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return '+'; 416a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 417a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block case '*': 418a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 419a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch == '=') { 420a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return CPP_MUL_ASSIGN; 421a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } else { 422a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp); 423a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return '*'; 424a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 425a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block case '%': 426a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 427a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch == '=') { 428a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return CPP_MOD_ASSIGN; 429a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } else if (ch == '>'){ 430a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return CPP_RIGHT_BRACE; 431a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } else { 432a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp); 433a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return '%'; 434a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 435a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block case ':': 436a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 437a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch == '>') { 438a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return CPP_RIGHT_BRACKET; 439a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } else { 440a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp); 441a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return ':'; 442a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 443a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block case '^': 444a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 445a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch == '^') { 446a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return CPP_XOR_OP; 447a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } else { 448a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch == '=') 449a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return CPP_XOR_ASSIGN; 450a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block else{ 451a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp); 452a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return '^'; 453a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 454a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 455a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 456a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block case '=': 457a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 458a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch == '=') { 459a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return CPP_EQ_OP; 460a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } else { 461a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp); 462a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return '='; 463a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 464a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block case '!': 465a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 466a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch == '=') { 467a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return CPP_NE_OP; 468a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } else { 469a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp); 470a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return '!'; 471a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 472a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block case '|': 473a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 474a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch == '|') { 475a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return CPP_OR_OP; 476a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } else { 477a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch == '=') 478a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return CPP_OR_ASSIGN; 479a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block else{ 480a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp); 481a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return '|'; 482a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 483a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 484a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block case '&': 485a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 486a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch == '&') { 487a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return CPP_AND_OP; 488a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } else { 489a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch == '=') 490a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return CPP_AND_ASSIGN; 491a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block else{ 492a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp); 493a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return '&'; 494a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 495a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 496a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block case '<': 497a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 498a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch == '<') { 499a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 500a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if(ch == '=') 501a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return CPP_LEFT_ASSIGN; 502a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block else{ 503a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp); 504a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return CPP_LEFT_OP; 505a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 506a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } else { 507a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch == '=') { 508a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return CPP_LE_OP; 509a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } else { 510a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch == '%') 511a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return CPP_LEFT_BRACE; 512a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block else if (ch == ':') 513a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return CPP_LEFT_BRACKET; 514a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block else{ 515a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp); 516a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return '<'; 517a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 518a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 519a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 520a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block case '>': 521a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 522a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch == '>') { 523a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 524a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if(ch == '=') 525a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return CPP_RIGHT_ASSIGN; 526a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block else{ 527a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp); 528a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return CPP_RIGHT_OP; 529a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 530a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } else { 531a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch == '=') { 532a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return CPP_GE_OP; 533a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } else { 534a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp); 535a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return '>'; 536a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 537a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 538a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block case '.': 539a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 540a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch >= '0' && ch <= '9') { 541a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp); 542ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch return lFloatConst('.', 0, yylvalpp); 543a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } else { 544a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch == '.') { 545a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return -1; // Special EOF hack 546a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } else { 547a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp); 548a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return '.'; 549a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 550a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 551a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block case '/': 552a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 553a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch == '/') { 554a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block do { 555a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 556a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } while (ch != '\n' && ch != EOF); 557a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch == EOF) 558a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return -1; 559a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return '\n'; 560a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } else if (ch == '*') { 561a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block int nlcount = 0; 562a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 563a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block do { 564a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block while (ch != '*') { 565a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch == '\n') nlcount++; 566a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch == EOF) { 567ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch CPPErrorToInfoLog("EOF IN COMMENT"); 568a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return -1; 569a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 570a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 571a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 572a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 573a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch == EOF) { 574ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch CPPErrorToInfoLog("EOF IN COMMENT"); 575a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return -1; 576a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 577a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } while (ch != '/'); 578a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (nlcount) { 579a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return '\n'; 580a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 581a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block // Go try it again... 582a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } else if (ch == '=') { 583a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return CPP_DIV_ASSIGN; 584a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } else { 585a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp); 586a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return '/'; 587a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 588a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block break; 589a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block case '"': 590a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 591a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block while (ch != '"' && ch != '\n' && ch != EOF) { 592a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch == '\\') { 593a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block CPPErrorToInfoLog("The line continuation character (\\) is not part of the OpenGL ES Shading Language"); 594a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return -1; 595a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 596ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch APPEND_CHAR_S(ch, string_val, len, MAX_STRING_LEN); 597ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp); 598a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block }; 599ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch assert(len <= MAX_STRING_LEN); 600a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block string_val[len] = '\0'; 601a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (ch == '"') { 602a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block yylvalpp->sc_ident = LookUpAddString(atable, string_val); 603a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return CPP_STRCONSTANT; 604a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } else { 605ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch CPPErrorToInfoLog("EOL IN STRING"); 606a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return ERROR_SY; 607a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 608ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch break; 609a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 610a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 611a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block} // byte_scan 612a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 613a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Blockint yylex_CPP(char* buf, int maxSize) 614a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block{ 615ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch yystypepp yylvalpp; 616a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block int token = '\n'; 617a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 618a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block for(;;) { 619a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 620a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block char* tokenString = 0; 621a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block token = cpp->currentInput->scan(cpp->currentInput, &yylvalpp); 622ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch if(check_EOF(token)) 623ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch return 0; 624a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (token == '#') { 625a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (cpp->previous_token == '\n'|| cpp->previous_token == 0) { 626ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch token = readCPPline(&yylvalpp); 627a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if(check_EOF(token)) 628a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return 0; 629ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch continue; 630a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } else { 631a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block CPPErrorToInfoLog("preprocessor command must not be preceded by any other statement in that line"); 632a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return 0; 633a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 634a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 635a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block cpp->previous_token = token; 636a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block // expand macros 637a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (token == CPP_IDENTIFIER && MacroExpand(yylvalpp.sc_ident, &yylvalpp)) { 638a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block cpp->pastFirstStatement = 1; 639a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block continue; 640a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 641ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch 642a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (token == '\n') 643a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block continue; 644ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch cpp->pastFirstStatement = 1; 645ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch 646ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch if (token == CPP_IDENTIFIER) { 647a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block tokenString = GetStringOfAtom(atable,yylvalpp.sc_ident); 648ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch } else if (token == CPP_FLOATCONSTANT || token == CPP_INTCONSTANT){ 649a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block tokenString = yylvalpp.symbol_name; 650ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch } else { 651a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block tokenString = GetStringOfAtom(atable,token); 652ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch } 653a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 654a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if (tokenString) { 655ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch int len = strlen(tokenString); 656ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch cpp->tokensBeforeEOF = 1; 657ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch if (len >= maxSize) { 658ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch return maxSize; 659ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch } else if (len > 0) { 660ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch strcpy(buf, tokenString); 661ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch return len; 662ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch } 663a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 664a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return 0; 665a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 666a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 667a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 668a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return 0; 669a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block} // yylex 670a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 671a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block//Checks if the token just read is EOF or not. 672a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Blockint check_EOF(int token) 673a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block{ 674a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if(token==-1){ 675a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block if(cpp->ifdepth >0){ 676ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch CPPErrorToInfoLog("#endif missing!! Compilation stopped"); 677a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block cpp->CompileError=1; 678a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 679a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return 1; 680a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block } 681a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block return 0; 682a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block} 683a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 684a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block/////////////////////////////////////////////////////////////////////////////////////////////// 685a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block/////////////////////////////////////// End of scanner.c ////////////////////////////////////// 686a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block/////////////////////////////////////////////////////////////////////////////////////////////// 687a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block 688