Exemplo n.º 1
0
cbool parseSpaceAndComments( parse *p )
{
  while ( 1 )
  {
    if ( parseThisChar( p, ' ' )             
      || parseThisChar( p, '\t' )
      || parseThisChar( p, '\n' )
       )
      ;
    
    else if ( parseThisString( p, "/*" ) )
      while ( !parseThisString( p, "*/" )
           && parseAnyChar( p )
            );
 
    else if ( parseThisString( p, "//" ) )
      while ( !parseThisChar( p, '\n' )
           && parseAnyChar( p )
            );

    else
      break;
  }
          
  return true;
}
Exemplo n.º 2
0
/**
	Add a bit to a flag value. If the next char is '1', OR {value} into the
	result value {result}. If the next char is '0', do nothing. Otherwise,
	it's a parsing error.
*/
cbool parseBitChar(parse *p, unsigned value, unsigned *result){
	return (
		parseThisChar(p,'0')
		|| (
			parseThisChar(p,'1')
			&& assign(*result |= value)
		)
	);
}
Exemplo n.º 3
0
cbool parseSignedNumber( parse *p, int *n ){
	unsigned un;
	return (
		(parseThisChar( p, '-' )
			&& parseLexNumber( p, &un )
			&& assign( *n = -(*n) )
		) || (parseThisChar( p, '+' )
			&& parseLexNumber( p, &un )
		) || (
			parseNumber( p, &un )
		)
	) && assign(*n = un);
}
Exemplo n.º 4
0
static bool
parseCFG(HashedSet<HashedPtr<cfg_node> > &roots,
	 std::map<const cfg_node *, _getStoreCFGs::cfgflavour_store_t> &flavours,
	 const char *buf, const char **suffix)
{
	std::map<named_string, cfg_node *> nodes;
	while (1) {
		if (!parseNodeDecl(nodes, flavours, buf, &buf))
			break;
	}
	if (!parseEdgeDecl(nodes, buf, &buf))
		return false;
	if (!parseThisString("Roots:\n", buf, &buf))
		return false;
	while (!parseThisString("End of roots\n", buf, suffix)) {
		if (!*buf)
			return false;
		named_string key;
		if (!parseWord(&key, buf, &buf) ||
		    !parseThisChar('\n', buf, &buf))
			return false;
		if (!nodes.count(key))
			return false;
		roots.insert(nodes[key]);
	}
	return true;
}
Exemplo n.º 5
0
cbool parseLexThisCategory( parse *p, category cat, char *s )
{
  int i;
  char c;
  
  parseSpaceAndComments( p );
  
  for ( i = 0
      ; s[i] != '\0' && parseThisChar( p, s[i] )
      ; i++
      );
  
  if ( s[i] == '\0' )
	if(
		!parseAChar( p, &c )
      	|| (
			parseUnParseChar( p, c )
			&& !( cat & p->judge[(short)c])
		)
    ){
		return true;
	}
  
  for ( i-- ; i >= 0; i-- )
    parseUnParseChar( p, s[i] );
  
  return false;
}
Exemplo n.º 6
0
static bool
parseNodeDecl(std::map<named_string, cfg_node *> &nodes,
	      std::map<const cfg_node *, _getStoreCFGs::cfgflavour_store_t> &cfgFlavours,
	      const char *buf,
	      const char **suffix)
{
	named_string label;
	_getStoreCFGs::cfgflavour_store_t flavour;
	if (!parseWord(&label, buf, &buf) ||
	    !parseThisChar(' ', buf, &buf) ||
	    !parseCfgFlavour(&flavour, buf, &buf) ||
	    !parseThisChar('\n', buf, suffix))
		return false;
	if (nodes.count(label))
		return false;
	cfg_node *n = new cfg_node(label, CfgLabel::uninitialised());
	nodes[label] = n;
	cfgFlavours[n] = flavour;
	return true;
}
Exemplo n.º 7
0
Arquivo: util.cpp Projeto: sos22/SLI
IRExpr *
readIRExpr(int fd)
{
	char *buf = readfile(fd);
	IRExpr *r;
	const char *succ;
	if (!parseIRExpr(&r, buf, &succ))
		errx(1, "cannot parse %s as IRExpr", buf);
	parseThisChar(' ', succ, &succ);
	if (*succ)
		errx(1, "garbage after irexpr: %s", succ);
	free(buf);
	return r;
}
Exemplo n.º 8
0
static void
read_cfg_and_depth(HashedSet<HashedPtr<cfg_node> > &roots, std::map<const cfg_node *, _getStoreCFGs::cfgflavour_store_t> &flavours, int *maxDepth, int fd)
{
	char *buf = readfile(fd);
	const char *suffix;
	const char *p = buf;
	if (!parseThisString("depth = ", p, &p) ||
	    !parseDecimalInt(maxDepth, p, &p) ||
	    !parseThisChar('\n', p, &p) ||
	    !parseCFG(roots, flavours, p, &suffix))
		errx(1, "cannot parse %s as test specification", buf);
	if (*suffix)
		warnx("trailing garbage after cfg: %s", suffix);
	free(buf);
}
Exemplo n.º 9
0
cbool parseThisString( parse *p, const char *s )
{
  int i;
  //char c;
  
  for ( i = 0
      ; s[i] != '\0' && parseThisChar( p, s[i] )
      ; i++
      );
  
  if ( s[i] == '\0' )
    return true;
  
  for ( i-- ; i >= 0; i-- )
    parseUnParseChar( p, s[i] );
  
  return false;
}
Exemplo n.º 10
0
static void
loadSchedule(const char *path, std::vector<DynAnalysisRip> &out)
{
	int fd = open(path, O_RDONLY);
	if (fd < 0)
		err(1, "opening %s", path);
	char *cont = readfile(fd);
	close(fd);
	if (!cont)
		err(1, "reading %s", path);
	DynAnalysisRip dr;
	const char *buf = cont;
	while (parseDynAnalysisRip(&dr, buf, &buf) &&
	       parseThisChar('\n', buf, &buf))
		out.push_back(dr);
	if (buf[0] != 0)
		errx(1, "junk at end of %s", path);
	free(cont);
}
Exemplo n.º 11
0
static bool
parseEdgeDecl(std::map<named_string, cfg_node *> &nodes,
	      const char *buf,
	      const char **suffix)
{
	while (1) {
		named_string start, end;
		const char *p;
		if (!parseWord(&start, buf, &p) ||
		    !parseThisString(" -> ", p, &p) ||
		    !parseWord(&end, p, &p) ||
		    !parseThisChar('\n', p, &buf))
			break;
		cfg_node *s = nodes[start];
		cfg_node *e = nodes[end];
		if (!s || !e)
			return false;
		s->successors.push_back(cfg_node::successor_t::branch(e));
	}
	*suffix = buf;
	return true;
}
Exemplo n.º 12
0
cbool parseWhiteChar(parse *p){
	return (
		parseThisChar(p,' ')
		|| parseThisChar(p,'\t')	
	);
}
Exemplo n.º 13
0
cbool parseEOL(parse *p){
	return (
		parseThisChar(p,'\n')
		|| (parseThisChar(p,'\r') && maybe(parseThisChar(p,'\n')))
	);
}
Exemplo n.º 14
0
cbool parseLexThisChar( parse *p, char c )
{
  return ( parseSpaceAndComments( p )
        && parseThisChar( p, c )
         );
}