int skip_comment(void) { if(checkop(L'*')) { skip_1comment(); return(TRUE); } else if(checkop(L'/')) { skip_NLonly(); return(TRUE); } else { return(FALSE); } }
/************************************************************************ ** dump_comment : while skipping a comment, output it. ************************************************************************/ void dump_comment() { if( ! Cflag ) { skip_1comment(); return; } myfwrite(L"/*", 2 * sizeof(WCHAR), 1, OUTPUTFILE); for(;;) { WCHAR c; switch(CHARMAP(c = GETCH())) { case LX_STAR: if(checkop(L'/')) { myfwrite(L"*/", 2 * sizeof(WCHAR), 1, OUTPUTFILE); return; } break; case LX_EOS: handle_eos(); continue; case LX_NL: Linenumber++; break; /* output below */ // must manually write '\r' with '\n' when writing 16-bit strings //case LX_CR: // continue; } myfwrite(&c, sizeof(WCHAR), 1, OUTPUTFILE); } }
void compileterm(std::vector<std::string> &lines, std::vector<std::string>::iterator &beg) { int unary=0; while(((*beg).find("<integerConstant>"))!=std::string::npos || ((*beg).find("<stringConstant>"))!=std::string::npos || ((*beg).find("<identifier>"))!=std::string::npos || ((*beg).find(" true "))!=std::string::npos || ((*beg).find(" false "))!=std::string::npos || ((*beg).find(" null "))!=std::string::npos || ((*beg).find(" this "))!=std::string::npos || ((*beg).find(" ( "))!=std::string::npos || ((*beg).find(" . "))!=std::string::npos || ((*(beg+1)).find(" ( "))!=std::string::npos || ((*(beg+1)).find(" . "))!=std::string::npos || ((*(beg+1)).find(" [ "))!=std::string::npos || ((*beg).find(" - "))!=std::string::npos || ((*beg).find(" ~ "))!=std::string::npos) { if(((*beg).find(" - "))!=std::string::npos || ((*beg).find(" ~ "))!=std::string::npos) { unary=1; } beg = lines.insert(beg, "<term>"); ++beg; if(unary==1) { unary=0; compileterm(lines, ++beg); } if(((*beg).find(" ( "))!=std::string::npos) { compileexpression(lines, beg); } if(((*(beg+1)).find(" [ "))!=std::string::npos) { compileexpression(lines, ++beg); } if(((*(beg+1)).find(" ( "))!=std::string::npos) { compileexpressionlist(lines, ++beg); } if(((*(beg+1)).find(" . "))!=std::string::npos) { beg=beg+2; compileexpressionlist(lines, ++beg); } beg = lines.insert(beg+1, "</term>"); checkop(++beg); } }
/************************************************************************ ** can_expand: tries to expand the macro passed to it - returns ** true if it succeeded in expanding it. It will only return FALSE ** if a macro name was found, a paren was expected, and a paren was ** not the next non white character. ************************************************************************/ int can_expand(pdefn_t pdef) { UCHAR c; int n_formals; int return_value = FALSE; Tiny_lexer_nesting = 0; Save_Exp_ptr = Exp_ptr; /* not necessarily EXP_BUFFER */ Macro_line = Linenumber; expand_name: P_actuals = Act_ptr; N_actuals = 0; n_formals = DEFN_NFORMALS(pdef); if( PRE_DEFINED(pdef) ) { push_macro(pdef); DEFN_EXPANDING(CURRENT_MACRO)++; if(rescan_expansion()) { return(TRUE); /* could expand macro */ } } else if( n_formals == 0 ) { return_value = TRUE; if(DEFN_TEXT(pdef)) { push_macro(pdef); expand_definition(); } else { /* ** Macro expands to nothing (no definition). Since it ** didn't have any actuals, Act_ptr is already correct. ** Exp_ptr must be changed however to delete the ** identifier from the expanded text. */ Exp_ptr = Save_Exp_ptr; } } else { if( n_formals == -1 ) { n_formals = 0; } name_comment_paren: if( can_get_non_white()) { if(CHARMAP(CHECKCH()) == LX_SLASH) { SKIPCH(); if(skip_comment()) { goto name_comment_paren; } else { UNGETCH(); } } if(CHARMAP(CHECKCH())==LX_OPAREN) { SKIPCH(); return_value = TRUE; get_actuals(pdef, n_formals); } else { /* ** #define xx(a) a ** xx bar(); ** don't lose white space between "xx" and "bar" */ ptext_t p = Exp_ptr; push_macro(pdef); DEFN_EXPANDING(CURRENT_MACRO)++; Exp_ptr = p; if( rescan_expansion() ) { return(FALSE); } } } else { } } /* ** makes sure a macro is being worked on. At this point, there will ** be a macro to expand, unless the macro expand_the_named_macro was ** passed had no definition text. If it had no defintion text, ** Tiny_lexer_nesting was not incremented. */ while(Tiny_lexer_nesting != 0) { if(Exp_ptr >= ELIMIT) { fatal_in_macro(10056); } switch(CHARMAP(c = GETCH())) { case LX_ID: case LX_MACFORMAL: Save_Exp_ptr = Exp_ptr; if(tl_getid(c) && ((pdef = get_defined())!= 0)) { if(DEFN_EXPANDING(pdef)) { /* ** the macro is already being expanded, so just ** write the do not expand marker and the ** identifier to the expand area. The do not ** expand marker is necessary so this macro ** doesn't get expanded on the rescan */ int len = Reuse_1_length - 1; *Exp_ptr++ = LX_NOEXPANDMARK; *Exp_ptr++ = ((UCHAR)len); } else { /* ** a legal identifier was read, it is defined, and ** it is not currently being expanded. This means ** there is reason to believe it can be expanded. */ goto expand_name; } } if(InIf &&(memcmp(Reuse_1, "defined", 8) ==0)) { do_defined(Reuse_1); } continue; break; case LX_NUMBER: /* getnum with Prep on to keep leading 0x on number */ { int Save_prep = Prep; Prep = TRUE; getnum(c); Prep = Save_prep; } continue; break; case LX_DOT: *Exp_ptr++ = '.'; dot_switch: switch(CHARMAP(c = GETCH())) { case LX_EOS: if(handle_eos() != BACKSLASH_EOS) { if(Tiny_lexer_nesting > 0) { goto dot_switch; } continue; } break; case LX_DOT: *Exp_ptr++ = '.'; if( ! checkop('.')) { break; /* error will be caught on rescan */ } *Exp_ptr++ = '.'; continue; break; case LX_NUMBER: *Exp_ptr++ = c; get_real(Exp_ptr); continue; } UNGETCH(); continue; case LX_CHARFORMAL: move_to_exp_esc('\'', do_strformal()); continue; break; case LX_STRFORMAL: move_to_exp_esc('"', do_strformal()); continue; break; case LX_DQUOTE: case LX_SQUOTE: /* ** gather_chars is called even though the error reported ** on overflow may need to be changed. */ Exp_ptr = gather_chars(Exp_ptr, c); continue; break; case LX_WHITE: while(LXC_IS_WHITE(GETCH())) { ; } UNGETCH(); c = ' '; break; case LX_EOS: if(handle_eos() == BACKSLASH_EOS) { *Exp_ptr++ = c; c = GETCH(); break; } continue; break; } *Exp_ptr++ = c; } return(return_value); }