Ejemplo n.º 1
0
Archivo: cb.c Proyecto: 00001/plan9port
void
gotop(int c)
{
	char optmp[OPLENGTH];
	char *op_ptr;
	struct op *s_op;
	char *a, *b;
	op_ptr = optmp;
	*op_ptr++ = c;
	while (isop((uchar)( *op_ptr = getch())))op_ptr++;
	if(!strict)unget(*op_ptr);
	else if (*op_ptr != ' ')unget( *op_ptr);
	*op_ptr = '\0';
	s_op = op;
	b = optmp;
	while ((a = s_op->name) != 0){
		op_ptr = b;
		while ((*op_ptr == *a) && (*op_ptr != '\0')){
			a++;
			op_ptr++;
		}
		if (*a == '\0'){
			keep(s_op);
			opflag = s_op->setop;
			if (*op_ptr != '\0'){
				b = op_ptr;
				s_op = op;
				continue;
			}
			else break;
		}
		else s_op++;
	}
}
Ejemplo n.º 2
0
char CharMapper::trigraph()
{
	if (settings.trigraph) {
		char c = charmap();
		if (c == '?') {
			c = charmap();
			if (c == '?') {
				c = charmap();
				switch (c) {
				case '=': return '#';
				case '/': return '\\';
				case '(': return '[';
				case ')': return ']';
				case '\'': return '^';
				case '!': return '|';
				case '<': return '{';
				case '>': return '}';
				case '-': return '~';
				}
				unget(c);
				unget('?');
			} else {
				unget(c);
			}
			return '?';
		} else {
			return c;
		}
	} else {
		return in.get();
	}
}
Ejemplo n.º 3
0
static int _fact(void * bp, int get(void * bp), int unget(int c, void * bp))

{
	signed c;
	int n = 1;
	while ((c = get(bp)) != EOF)
	{
		if (isblank(c)) continue;
		else if(isdigit(c))
		{
			unget (c, bp);
			n *= _numb(bp, get, unget);
		}
		else if(c == '(')
		{
			n *= _numb(bp, get, unget);
			if ((c = get(bp)) != ')') unget(c, bp);
		}
		else 
		{
			unget (c, bp);
			break;
		}
	}
	return (n);
}
Ejemplo n.º 4
0
std::string Parser::readString()
{
    do {
        char c = get();

        if (isspace(c)) {
            continue;
        } else if (c == '#') {
            forgetLine();
            continue;
        } else {
            unget();
            break;
        }
    } while (mStream);

    if (not mStream) {
        throw utils::InternalError();
    } else {
        std::string result;

        do {
            char c = get();

            if (isalnum(c)) {
                result += c;
            } else {
                unget();
                return result;
            }
        } while (mStream);

        return result;
    }
}
Ejemplo n.º 5
0
Sym*
getimpsym(void)
{
	int c;
	char *cp;

	c = getnsc();
	if(isspace(c) || c == '"') {
		unget(c);
		return S;
	}
	for(cp = symb;;) {
		if(cp <= symb+NSYMB-4)
			*cp++ = c;
		c = getc();
		if(c > 0 && !isspace(c) && c != '"')
			continue;
		unget(c);
		break;
	}
	*cp = 0;
	if(cp > symb+NSYMB-4)
		yyerror("symbol too large: %s", symb);
	return lookup();
}
Ejemplo n.º 6
0
  Error parseExport() {
    COFFShortExport E;
    E.Name = Tok.Value;
    read();
    if (Tok.K == Equal) {
      read();
      if (Tok.K != Identifier)
        return createError("identifier expected, but got " + Tok.Value);
      E.ExtName = E.Name;
      E.Name = Tok.Value;
    } else {
      unget();
    }

    if (Machine == IMAGE_FILE_MACHINE_I386) {
      if (!isDecorated(E.Name, MingwDef))
        E.Name = (std::string("_").append(E.Name));
      if (!E.ExtName.empty() && !isDecorated(E.ExtName, MingwDef))
        E.ExtName = (std::string("_").append(E.ExtName));
    }

    for (;;) {
      read();
      if (Tok.K == Identifier && Tok.Value[0] == '@') {
        Tok.Value.drop_front().getAsInteger(10, E.Ordinal);
        read();
        if (Tok.K == KwNoname) {
          E.Noname = true;
        } else {
          unget();
        }
        continue;
      }
      if (Tok.K == KwData) {
        E.Data = true;
        continue;
      }
      if (Tok.K == KwConstant) {
        E.Constant = true;
        continue;
      }
      if (Tok.K == KwPrivate) {
        E.Private = true;
        continue;
      }
      unget();
      Info.Exports.push_back(E);
      return Error::success();
    }
  }
Ejemplo n.º 7
0
Archivo: cb.c Proyecto: 00001/plan9port
void
gottype(struct keyw *lptr)
{
	char *pt;
	struct keyw *tlptr;
	int c;
	while(1){
		pt = getnext(1);
		if((tlptr=lookup(pt,lastplace+1))!=0){
			putch(' ',YES);
			copy(tlptr->name);
			*pt='\0';
			lastplace = pt;
			if(tlptr->type == STRUCT){
				putch(tlptr->punc,YES);
				gotstruct();
				break;
			}
			lptr=tlptr;
			continue;
		}
		else{
			putch(lptr->punc,NO);
			while((c=getch())== ' ' || c == '\t');
			unget(c);
			break;
		}
	}
}
Ejemplo n.º 8
0
void bootstrap( void )
{
	for( ;; ) {
		get();
		switch( *sp ) {
		case '#':
			drop();
			skip_to_nl();
			break;
		
		case ':':
			drop();
			get_name();
			make_def();
			compile_to_def();
			bootcompile();
			fixate_colon_def();
			break;
			
		default:
			unget();
			compile_to_buffer();
			bootcompile();
			bootinterpreter();
			break;
		}
	}		
 }  
Ejemplo n.º 9
0
int CredReader::ReadNumber()
{
	int num = atoi(&data[dataindex]);
	while(isdigit(get())) ;
	unget();
	return num;
}
Ejemplo n.º 10
0
//
// SourceTokenizerC::doCommand
//
void SourceTokenizerC::doCommand()
{
   SourceTokenC::Reference tok = getRaw(); doAssert(tok, SourceTokenC::TT_NAM);

        if (tok->data == "define")  doCommand_define(tok);
   else if (tok->data == "else")    doCommand_else(tok);
   else if (tok->data == "elif")    doCommand_elif(tok);
   else if (tok->data == "endif")   doCommand_endif(tok);
   else if (tok->data == "error")   doCommand_error(tok);
   else if (tok->data == "if")      doCommand_if(tok);
   else if (tok->data == "ifdef")   doCommand_ifdef(tok);
   else if (tok->data == "ifndef")  doCommand_ifndef(tok);
   else if (tok->data == "include") doCommand_include(tok);
   else if (tok->data == "undef")   doCommand_undef(tok);
   else if (tok->data == "warning") doCommand_warning(tok);

   else if(isSkip())
   {
      while(tok->type != SourceTokenC::TT_ENDL)
         tok = getRaw();

      unget(tok);
   }
   else Error(tok->pos, "unknown command: %s", tok->data.c_str());
}
Ejemplo n.º 11
0
static int esc_char(int in_char_literal)
{
	int c = get();
	int v, i;

	switch (c)
	{
	case 'b':
		return '\b';
	case 'e':
		return 033;
	case 'f':
		return '\f';
	case 'n':
		return '\n';
	case 't':
		return '\t';
	default:
		if (c >= '0' && c <= '7')
		{
			for(v = i = 0; i < 3 && c >= '0' && c <= '7'; c = get())
				v = v*8 + c-'0';
			unget();
			return v;
		}
		return c;
	}
}
Ejemplo n.º 12
0
/*
 * Read the rest of a line that starts `\c'. Including nothing at
 * all (tok_word with empty text).
 */
token get_codepar_token(input * in)
{
  int c;
  token ret;
  rdstring rs = { 0, 0, NULL };
  filepos cpos;

  ret.type = tok_word;
  c = get(in, &cpos);           /* expect (and discard) one space */
  ret.pos = cpos;
  if (c == ' ')
  {
    c = get(in, &cpos);
    ret.pos = cpos;
  }
  while (!isnl(c) && c != EOF)
  {
    int c2 = c;
    c = get(in, &cpos);
    /* Discard \r just before \n. */
    if (c2 != 13 || !isnl(c))
      rdadd(&rs, (wchar_t)c2);
  }
  unget(in, c, &cpos);
  ret.text = ustrdup(rs.text);
  sfree(rs.text);
  return ret;
}
Ejemplo n.º 13
0
//---------------------------------------------------------------------------
bool SPARQLLexer::hasNext(Token value)
   // Peek at the next token
{
   Token peek=getNext();
   unget(peek);
   return peek==value;
}
Ejemplo n.º 14
0
double Parser::readReal()
{
    do {
        char c = get();

        if (isspace(c)) {
            continue;
        } else if (c == '#') {
            forgetLine();
            continue;
        } else {
            unget();
            break;
        }
    } while (mStream);

    if (not mStream) {
        throw utils::InternalError();
    } else {
        std::string result;

        do {
            char c = get();

            if (isspace(c)) {
                unget();
                break;
            } else if (c == '#') {
                forgetLine();
                break;
            } else if (isdigit(c)) {
                result += c;
            } else if (c == '.') {
                if (result.find(".") != std::string::npos){
                    throw utils::ParseError(fmt(
                       _("Multiple '.' while parsing real `%1%.' ")) % result);
                }
                result += c;
            } else {
                unget();
                break;
            }
        } while (mStream);

        return boost::lexical_cast < double >(result);
    }
}
Ejemplo n.º 15
0
/*
 * Determine whether the next input character is an open brace (for
 * telling code paragraphs from paragraphs which merely start with
 * code).
 */
int isbrace(input * in)
{
  int c;
  filepos cpos;

  c = get(in, &cpos);
  unget(in, c, &cpos);
  return (c == '{');
}
Ejemplo n.º 16
0
Archivo: cpp2.c Proyecto: cjapes/core
FILE_LOCAL
void doif(int hash)
/*
 * Process an #if, #ifdef, or #ifndef.  The latter two are straightforward,
 * while #if needs a subroutine of its own to evaluate the expression.
 *
 * doif() is called only if compiling is TRUE.  If false, compilation
 * is always supressed, so we don't need to evaluate anything.  This
 * supresses unnecessary warnings.
 */
{
        register int            c;
        register int            found;

        if ((c = skipws()) == '\n' || c == EOF_CHAR) {
            unget();
            goto badif;
        }
        if (hash == L_if) {
            unget();
            found = (eval() != 0);      /* Evaluate expr, != 0 is  TRUE */
            hash = L_ifdef;             /* #if is now like #ifdef       */
        }
        else {
            if (type[c] != LET)         /* Next non-blank isn't letter  */
                goto badif;             /* ... is an error              */
            found = (lookid(c) != NULL); /* Look for it in symbol table */
        }
        if (found == (hash == L_ifdef)) {
            compiling = TRUE;
            *ifptr |= TRUE_SEEN;
        }
        else {
            compiling = FALSE;
        }
        return;

badif:  cerror("#if, #ifdef, or #ifndef without an argument", NULLST);
#if !OLD_PREPROCESSOR
        skipnl();                               /* Prevent an extra     */
        unget();                                /* Error message        */
#endif
        return;
}
Ejemplo n.º 17
0
Lizt_old_ATTLC&
Lizt_old_ATTLC::unget(const Lizt_old_ATTLC& ll)
{
	if (ll.sz) {
	    register lnk_old_ATTLC*    aLink = ll.t;
	    do unget(aLink->copy());
	    while ((aLink = aLink->prv) != ll.t);
	}
	return *this;
}
Ejemplo n.º 18
0
 int skipSpaces()
 {
     int c = get();
     while (c != EOF && ::isspace(c))
     {
         c = get();
     }
     unget();
     return c;
 }
Ejemplo n.º 19
0
	void nextword(std::string& rv)
	{
		int ch = next();
		while (isspace(ch))
			ch = next();
		while (isalnum(ch) || ch == '_'|| ch == '-')
		{
			rv.push_back(ch);
			ch = next();
		}
		unget(ch);
	}
Ejemplo n.º 20
0
 // NAME outputPath [BASE=address]
 Error parseName(std::string *Out, uint64_t *Baseaddr) {
   read();
   if (Tok.K == Identifier) {
     *Out = Tok.Value;
   } else {
     *Out = "";
     unget();
     return Error::success();
   }
   read();
   if (Tok.K == KwBase) {
     if (Error Err = expect(Equal, "'=' expected"))
       return Err;
     if (Error Err = readAsInt(Baseaddr))
       return Err;
   } else {
     unget();
     *Baseaddr = 0;
   }
   return Error::success();
 }
Ejemplo n.º 21
0
Archivo: cb.c Proyecto: 00001/plan9port
int
getnl(void){
	int ch;
	char *savp;
	int gotcmt;
	gotcmt = 0;
	savp = p;
	while ((ch = getch()) == '\t' || ch == ' ')putch(ch,NO);
	if (ch == '/'){
		if ((ch = getch()) == '*'){
			putch('/',NO);
			putch('*',NO);
			comment(NO);
			ch = getch();
			gotcmt=1;
		}
		else if (ch == '/') {
			putch('/',NO);
			putch('/',NO);
			cpp_comment(NO);
			ch = getch();
			gotcmt = 1;
		}
		else {
			if(inswitch)*(++lastplace) = ch;
			else {
				inswitch = 1;
				*lastplace = ch;
			}
			unget('/');
			return(0);
		}
	}
	if(ch == '\n'){
		if(gotcmt == 0)p=savp;
		return(1);
	}
	unget(ch);
	return(0);
}
Ejemplo n.º 22
0
 // HEAPSIZE/STACKSIZE reserve[,commit]
 Error parseNumbers(uint64_t *Reserve, uint64_t *Commit) {
   if (Error Err = readAsInt(Reserve))
     return Err;
   read();
   if (Tok.K != Comma) {
     unget();
     Commit = nullptr;
     return Error::success();
   }
   if (Error Err = readAsInt(Commit))
     return Err;
   return Error::success();
 }
Ejemplo n.º 23
0
Parser::Token Parser::nextToken()
{
    while (mStream) {
        char c = get();

        if (not mStream) {
            return Parser::Error;
        } else if (isspace(c)) {
            continue;
        } else if (c == '#') {
            forgetLine();
            continue;
        } else if (std::isdigit(c)) {
            unget();
            return Parser::Real;
        } else if (c == '+') {
            unget();
            return Parser::RelativeReal;
        } else if (c == '"') {
            unget();
            return Parser::QuoteStr;
        } else if (c == '{') {
            unget();
            return Parser::Begin;
        } else if (c == '}') {
            unget();
            return Parser::End;
        } else if (c == '=') {
            unget();
            return Parser::Equal;
        } else if (c == ',') {
            unget();
            return Parser::Comma;
        } else if (c == ';') {
            unget();
            return Parser::Semicolon;
        } else {
            unget();
            return Parser::Str;
        }
    }

    return Parser::Error;
}
Ejemplo n.º 24
0
Archivo: cpp2.c Proyecto: zzz99977/core
/*
 * Process an #if, #ifdef, or #ifndef.  The latter two are straightforward,
 * while #if needs a subroutine of its own to evaluate the expression.
 *
 * doif() is called only if compiling is TRUE.  If false, compilation
 * is always suppressed, so we don't need to evaluate anything.  This
 * suppresses unnecessary warnings.
 */
FILE_LOCAL void doif(int hash)
{
    int c;
    int found;

    if ((c = skipws()) == '\n' || c == EOF_CHAR)
    {
        unget();
        goto badif;
    }
    if (hash == L_if)
    {
        unget();
        found = (eval() != 0);      /* Evaluate expr, != 0 is  TRUE */
        hash = L_ifdef;             /* #if is now like #ifdef       */
    }
    else
    {
        if (type[c] != LET)         /* Next non-blank isn't letter  */
            goto badif;             /* ... is an error              */
        found = (lookid(c) != NULL); /* Look for it in symbol table */
    }
    if (found == (hash == L_ifdef))
    {
        compiling = TRUE;
        *ifptr |= TRUE_SEEN;
    }
    else
    {
        compiling = FALSE;
    }
    return;

  badif:  cerror("#if, #ifdef, or #ifndef without an argument", NULLST);
    skipnl();                               /* Prevent an extra     */
    unget();                                /* Error message        */
    return;
}
Ejemplo n.º 25
0
static int _numb(void * bp, int get(void * bp), int unget(int c, void * bp))

{
	int c = get(bp);
	int n = 0;
	while (isdigit(c))
	{
		n *= 10;
		n += (c - '0');
		c = get(bp);
	}
	unget (c, bp);
	return (n);
}
Ejemplo n.º 26
0
a_uint
eval()
{
	int c, v;
	a_uint n;

	c = getnb();
	n = 0;
	while ((v = digit(c, radix)) >= 0) {
		n = n*radix + v;
		c = get();
	}
	unget(c);
	return((n & s_mask) ? n | ~v_mask : n & v_mask);
}
Ejemplo n.º 27
0
Archivo: cb.c Proyecto: 00001/plan9port
void
gotstruct(void){
	int c;
	int cc;
	char *pt;
	while((c=getch()) == ' ' || c == '\t')
		if(!strict)putch(c,NO);
	if(c == '{'){
		structlev++;
		unget(c);
		return;
	}
	if(isalpha(c)){
		putch(c,NO);
		while(isalnum(c=getch()))putch(c,NO);
	}
	unget(c);
	pt = getnext(1);
	if(*pt == '{')structlev++;
	if(strict){
		eatallsp();
		putch(' ',NO);
	}
}
Ejemplo n.º 28
0
/*
 * Enter admode() to search a specific addressing mode table
 * for a match. Return the addressing value on a match or
 * -1 for no match.
 */
int
admode(struct adsym *sp)
{
        char *ptr;
        int i;

        unget(getnb());
        i = 0;
        while ( *(ptr = &sp[i].a_str[0]) ) {
                if (srch(ptr)) {
                        return(sp[i].a_val);
                }
                i++;
        }
        return(-1);
}
Ejemplo n.º 29
0
void skip_space( void )
{
	for(;;){
		get();
		if( !flag ) { drop(); return; }
		if( !isspace( *sp )) {
			unget();
			flag = 1;
			return;
		}
		if( *sp++ == '\n' ) {
			flag = 0;
			return;
		}
	}
}
Ejemplo n.º 30
0
void get_token( void )
{
	int n;
	
	skip_space();
	if( !flag ) return;
	
	for( n = 0;; n += 1) {
		get();
		if( !flag ) break;
		if( isspace( *sp ) ) break;
		constop[ D_DATA + 1 + n ] = *sp++;
	}
	constop[ D_DATA ] = n;
	if( flag ) unget(); else drop();
	flag = 1;
}