Esempio n. 1
0
/** Setup the input buffer state to scan the given bytes. The next call to yylex() will
 * scan from a @e copy of @a bytes.
 * @param bytes the byte buffer to scan
 * @param len the number of bytes in the buffer pointed to by @a bytes.
 * 
 * @return the newly allocated buffer state object.
 */
YY_BUFFER_STATE yy_scan_bytes  (yyconst char * yybytes, int  _yybytes_len )
{
	YY_BUFFER_STATE b;
	char *buf;
	yy_size_t n;
	int i;
    
	/* Get memory for full buffer, including space for trailing EOB's. */
	n = _yybytes_len + 2;
	buf = (char *) yyalloc(n  );
	if ( ! buf )
		YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );

	for ( i = 0; i < _yybytes_len; ++i )
		buf[i] = yybytes[i];

	buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;

	b = yy_scan_buffer(buf,n );
	if ( ! b )
		YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );

	/* It's okay to grow etc. this buffer, and we should throw it
	 * away when we're done.
	 */
	b->yy_is_our_buffer = 1;

	return b;
}
Esempio n. 2
0
File: main.c Progetto: t-k-/math-se
int main(int argc, char *argv[]) 
{
	char *str, *str0;
	size_t str0_sz;
	char *url;
	FILE *fout;
	uint suc_cnt = 0, fail_cnt = 0;

	if (argc != 2) {
		printf("invalid argument format. \n");
		return 0;
	}

	url = argv[1];
	fout = fopen("parser.output", "w");
	fprintf(fout, "%s\n", url);

	/* disable auto-complete */
	rl_bind_key('\t', rl_abort);

	while (1) {
		str = readline("edit: ");
		if (str == NULL) {
			printf("\n");
			break;
		} 

		/* user can use UP and DOWN key to 
		search through the history. */
		add_history(str); 

		str0 = to_scan_str(str, &str0_sz);

		YY_BUFFER_STATE buffer = 
			yy_scan_buffer(str0, str0_sz);

		yyparse();

		if (parser_error_flag) {
			fail_cnt ++;
			parser_error_flag = 0;
			printf("[ %s ]\n", parser_error_dscr);
		} else {
			suc_cnt ++;
			fprintf(fout, "%s\n", str);
			parser_out(fout);
		}

		yy_delete_buffer(buffer);
		free(str);
		free(str0);
	} 

	fclose(fout);
	printf("[ %d successfully parsed, %d fail(s) ]\n", 
	       suc_cnt, fail_cnt);

	return suc_cnt;
}