コード例 #1
0
jsgf_t *
jsgf_parse_string(const char *string, jsgf_t * parent)
{
    yyscan_t yyscanner;
    jsgf_t *jsgf;
    int yyrv;
    YY_BUFFER_STATE buf;

    yylex_init(&yyscanner);
    buf = yy_scan_string(string, yyscanner);

    jsgf = jsgf_grammar_new(parent);
    if (!parent)
        jsgf_set_search_path(jsgf, NULL);

    yyrv = yyparse(yyscanner, jsgf);
    if (yyrv != 0) {
        E_ERROR("Failed to parse JSGF grammar from input string\n");
        jsgf_grammar_free(jsgf);
        yy_delete_buffer(buf, yyscanner);
        yylex_destroy(yyscanner);
        return NULL;
    }
    yy_delete_buffer(buf, yyscanner);
    yylex_destroy(yyscanner);

    return jsgf;
}
コード例 #2
0
ファイル: emflexsup.c プロジェクト: Rajesh-Veeranki/MACEK
int	yywrap() {
	
	if (!include_app) {	/* all input files and strings get a newline appended to them */
		include_app = 1;
		yy_scan_string("\n");
		return 0;
	} else {
		include_app = 0;
		if (inpfile) {	/* (this is just an informal input text for printing-out...) */
			FREE(inpfile);  inpfile = NULL;
		}
			/* delete the input buffer, and possibly close the input file */
		yy_delete_buffer(YY_CURRENT_BUFFER);
#if CLOSE_AFTER_FLEX>0
		if (include_stack_file[include_stack_ptr])
			fclose(include_stack_file[include_stack_ptr]);
#endif
			/* pop the previous saved state from the stack */
		if (--include_stack_ptr>=0) {
			yy_switch_to_buffer(include_stack[include_stack_ptr]);
			inpfile = include_stack_fn[include_stack_ptr];
			inpline = include_stack_ln[include_stack_ptr];
			yy_pop_state();
			return 0;
		} /*** else  yyterminate();	does not work ??? ***/
	}
	return 1;	/* (means the end of current input) */
}
コード例 #3
0
ファイル: Text.cpp プロジェクト: FGRE/libnpengine-new
void Text::CreateFromXML(const string& XML)
{
    ::pText = this;
    YY_BUFFER_STATE buffer = yy_scan_bytes(XML.c_str(), XML.size());
    yyparse();
    yy_delete_buffer(buffer);
}
コード例 #4
0
ファイル: source.c プロジェクト: amirsalah/cs2007
int source_parse_file(source *src, const char *filename, const char *modname)
{
  YY_BUFFER_STATE bufstate;
  int r;

  if (NULL == (yyin = fopen(filename,"r"))) {
    perror(filename);
    return -1;
  }

  yyfilename = filename;
  yyfileno = add_parsedfile(src,filename);    ////yyfileno is the index in the src->parsedfiles
  yylloc.first_line = 1;

  bufstate = yy_create_buffer(yyin,YY_BUF_SIZE);
  yy_switch_to_buffer(bufstate);
  parse_src = src;
  parse_modname = modname ? modname : "";
  r = yyparse();
  yy_delete_buffer(bufstate);
#if HAVE_YYLEX_DESTROY
  yylex_destroy();
#endif

  if (yyin)
    fclose(yyin);

  return r;
}
コード例 #5
0
ファイル: parse_ctrl.cpp プロジェクト: LubosD/twinkle
t_sip_message *t_parser::parse(const string &s, list<string> &parse_errors_) {
	t_mutex_guard guard(mtx_parser);
	
	int ret;
	struct yy_buffer_state *b;
	msg = NULL;

	parse_errors.clear();

	string x = unfold(s);

	b = yy_scan_string(x.c_str());
	ret = yyparse();
	yy_delete_buffer(b);

	if (ret != 0) {
		if (msg) {
			MEMMAN_DELETE(msg);
			delete msg;
			msg = NULL;
		}
		throw ret;
	}

	parse_errors_ = parse_errors;
	return msg;
}
コード例 #6
0
ファイル: main.cpp プロジェクト: Groterik/dlang-ast
ModuleNode *getAST(const char *expr)
{
    ModuleNode *expression;
    yyscan_t scanner;
    YY_BUFFER_STATE state;

    if (yylex_init(&scanner)) {
        // couldn't initialize
        return NULL;
    }

    state = yy_scan_string(expr, scanner);

    yydebug = 0;
    if (yyparse(&expression, scanner)) {
        // error parsing
        return NULL;
    }

    yy_delete_buffer(state, scanner);

    yylex_destroy(scanner);

    return expression;
}
コード例 #7
0
ファイル: Main.c プロジェクト: Winter-M/Trot
pt_node *buildAST(const char *expr) {
	extern int yyparse(pt_node **, yyscan_t);

	FILE *file;
	yyscan_t scanner;
	pt_node *node = NULL;
	YY_BUFFER_STATE state;

	if(yylex_init(&scanner)) {
		fprintf(stderr, "Failed to initialize parser.\n");
		exit(-1);
	}

	file = fopen(expr, "r");
	if(file == NULL) {
		perror("fopen");
		exit(-1);
	}

	state = yy_create_buffer(file, 1024, scanner);
	yy_switch_to_buffer(state, scanner);

	if(yyparse(&node, scanner)) {
		fprintf(stderr, "Error parsing input.\n");
		exit(-1);
	}

	yy_delete_buffer(state, scanner);
	yylex_destroy(scanner);

	return node;
}
コード例 #8
0
//////////////////////////////////////////////////////////////////////////
// EXPORTED FUNCTIONS
//////////////////////////////////////////////////////////////////////////
__declspec(dllexport) BYTE* CompileBuffer(BYTE* Buffer, char* Source, DWORD BufferSize, DWORD* CompiledSize){
	
	YY_BUFFER_STATE state;
	BYTE* ret = NULL;

	if(Buffer==NULL){
		if(CompiledSize)*CompiledSize = 0;
		return NULL;
	}

	state = yy_scan_bytes(Buffer, BufferSize);
	lineno=1;
	yyparse();
	yy_delete_buffer(state);
	if(errorCheck()) goto finish_error;

	weedSCRIPTCOLLECTION(thescriptcollection);
	if(errorCheck()) goto finish_error;
	
	symSCRIPTCOLLECTION(thescriptcollection);
	if(errorCheck()) goto finish_error;
	
	ret = opcodeSCRIPTCOLLECTION(thescriptcollection, Source, CompiledSize);
	if(errorCheck()) goto finish_error;

	FinalCleanup();
	return ret;


finish_error:
	if(ret!=NULL) free(ret);
	*CompiledSize = 0;
	FinalCleanup();
	return NULL;
}
コード例 #9
0
int como_ast_create(const char *filename)
{
    ast_node* statements;
    yyscan_t scanner;
    YY_BUFFER_STATE state;
    char* text;

    text = file_get_contents(filename);

    if(!text) {
        printf("file '%s' not found\n", filename);
        return 1;
    }
    
    if(yylex_init(&scanner)) {
        como_error_noreturn("yylex_init returned NULL");
    }

    state = yy_scan_string(text, scanner);

    if(yyparse(&statements, scanner)) {
        como_error_noreturn("yyparse returned NULL");
    }

    yy_delete_buffer(state, scanner);

    yylex_destroy(scanner);

    como_compile_ast(statements, filename);

    return 0;
}
コード例 #10
0
ファイル: ne.c プロジェクト: gentooinit/n00b-expression
int ne_parse(const char *formula)
{
	int err;
	struct symbol_table *sym;

	ne.buf = yy_scan_string(formula, ne.scanner);

	yyset_lineno(1, ne.scanner);
	yyset_column(1, ne.scanner);
	__ne_clear_error(&ne);

	err = yyparse(&ne);

	if (!err) {
		__ne_put_result(&ne, eval(&ne, ne.root));

		sym = get_sym(&ne, "y");
		if (sym && sym->dirty) {
			__ne_put_result(&ne, __ne_get_y(&ne));
			clean_output_sym(&ne);
		}
	}

	if (ne.error != 0)
		err = ne.error;
	else if (ne.warrning != 0)
		err = ne.warrning;

	free_ast(ne.root);
	ne.root = NULL;
	ne.stop = 0;
	yy_delete_buffer(ne.buf, ne.scanner);

	return err;
}
コード例 #11
0
ファイル: trans.c プロジェクト: juzer10/FSE-2014-Aalta
ltl_formula *
getAST (const char *input)
{
  ltl_formula *formula;
  yyscan_t scanner;
  YY_BUFFER_STATE state;

  if (yylex_init (&scanner))
    {
      // couldn't initialize
      return NULL;
    }

  state = yy_scan_string (input, scanner);
  if (yyparse (&formula, scanner))
    {
      // error parsing
      return NULL;
    }

  yy_delete_buffer (state, scanner);
  yylex_destroy (scanner);

  return formula;
}
コード例 #12
0
ファイル: debugger.c プロジェクト: 32bitmicro/mera400
// -----------------------------------------------------------------------
int dbg_parse(char *c)
{
	YY_BUFFER_STATE yb = yy_scan_string(c);
	int res = yyparse();
	yy_delete_buffer(yb);
	return res;
}
コード例 #13
0
ファイル: mysh.c プロジェクト: jerryxzhang/Kernel-Sanders
/**
 * @function    runCommand
 *
 * @abstract    Parses and executes a command given a NULL terminated string.
 * @discussion  Parses the command and adds it to the history if it is
 *              nontrivial.
 *
 * @param       cmd_buffer      Pointer to NULL terminated string containing
 *                              the user input.
 * @result      Returns nothing, but runs a command, most likely printing to
 *              the terminal.
 */
void runCommand(char* cmd_buffer) {
    Command *command = NULL;
    yyscan_t scanner;
    YY_BUFFER_STATE state;

    // Check if there is anything in the line.  It is useless to store
    // a history of empty lines.  If it is not empty, then add it to our
    // history.  Also don't want to record line rerun calls.
    if ((cmd_buffer[0] != 0) && (cmd_buffer[0] != '!')) {
        add_history(cmd_buffer);
    }

    state = yy_scan_string(cmd_buffer);

    if (yyparse(&command, scanner)) {
        printf("Error in parsing command.\n");
        deleteCommand(command);
        return;
    }

    executeCommand(command, -1);
    deleteCommand(command);

    // Wait on all child processes
    while (wait(NULL) > 0) {}

    yy_delete_buffer(state);

    yylex_destroy();

    return;
}
コード例 #14
0
ファイル: entmgr.c プロジェクト: TEIC/Carthage
char *PCCloseentity(void) {
    char * pc;
    PEntRec per;

#ifdef DEBUGGING
    FILESTATUS(stdout,"stdout");
    MsgKwS(msgTRACE,"Closing the current entity ...",NULL);
    MsgKwS(msgTRACE,"PCCloseentity() called ...",NULL);
    FILESTATUS(stdout,"stdout");
    FILESTATUS(stdin,"stdin");
    FILESTATUS(stderr,"stderr");
    FILESTATUS(yyin,"yyin");
#endif

    if (cEntCur > 0) {
         per = rgEntities[cEntCur];
         pc = per->pcEntname;
         if (per->fExtern)
              fclose(yyin);
         /* close yyin.  We don't need to reset it,
            that happens in yy_switch_to_buffer, below */
         yy_delete_buffer(YY_CURRENT_BUFFER);
         yy_switch_to_buffer(rgBuffers[--cEntCur]);
         /* reset pcEntpos and fRdexternal */
         if (cEntCur > 0) {
              per = rgEntities[cEntCur];
              if (per->fExtern) {
                   fRdexternal = 1;
                   pcEntpos = "";
              } else {
                   fRdexternal = 0;
                   pcEntpos = rgPCPos[cEntCur];
              }
         } else { /* back to stdin */
              fRdexternal = 1;
              pcEntpos = "";
         }
         cLinecount = rgILine[cEntCur];
         fnCurrent  = rgPCFn[cEntCur];


#ifdef DEBUGGING
    FILESTATUS(stdout,"stdout");
    FILESTATUS(stdin,"stdin");
    FILESTATUS(stderr,"stderr");
    FILESTATUS(yyin,"yyin");
#endif

         return pc;
    } else {
#ifdef DEBUGGING
    FILESTATUS(stdout,"stdout");
    FILESTATUS(stdin,"stdin");
    FILESTATUS(stderr,"stderr");
    FILESTATUS(yyin,"yyin");
#endif
         return NULL;
    }
}
コード例 #15
0
int command_parse_string( const char *buffer )
{
    typedef struct yy_buffer_state* YY_BUFFER_STATE;
    extern YY_BUFFER_STATE yy_scan_string( const char *yy_str );
    extern void yy_delete_buffer( YY_BUFFER_STATE state );
    int rv = 1;
    YY_BUFFER_STATE state = yy_scan_string( (char*)buffer );

    switch ( yylex() ) {
    case SET:
        /* get the next token */
        rv = command_parse_set();
        break;

    case UNSET:
    case BIND:
    case MACRO:
        /* ignore this stuff for now. */
        rv = 1;
        break;

    case NUMBER: {
        const char *number = get_token();
        if ( number[0] == '+' ) {
            source_vscroll( if_get_sview(), atoi( number+1 ));
            rv = 0;
        } else if ( number[0] == '-' ) {
            source_vscroll( if_get_sview(), -atoi( number+1 ));
            rv = 0;
        } else {
            source_set_sel_line(if_get_sview(), atoi( number ));
            rv = 0;
        }
        if_draw();
    } break;

    case IDENTIFIER: {
        COMMANDS *command = get_command( get_token() );
        if ( command ) {
            command->action(command->param);
            rv = 0;
        } else {
            rv = 1;
        }
    } break;

    case EOL: 
        /* basically just an empty line, don't do nothin. */
        rv = 0;
        break;

    default:
        rv = 1;
        break;
    }

    yy_delete_buffer( state );
    return rv;
}
コード例 #16
0
ファイル: main.c プロジェクト: 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;
}
コード例 #17
0
ファイル: val.c プロジェクト: blynn/symple
void val_parse_forall(char *s, val_callback_t callback) {
  yyscan_t scanner;
  if (yylex_init(&scanner)) die("yylex_init error");
  YY_BUFFER_STATE buf = s ? yy_scan_string(s, scanner) : 0;
  if (yyparse(scanner, callback)) die("parse error");
  yy_delete_buffer(buf, scanner);
  yylex_destroy(scanner);
}
コード例 #18
0
ファイル: lexer.c プロジェクト: GregBowyer/regex-markup
void
lexer_restore_buffer(RemarkFile *rf)
{
	file = rf;
	yy_delete_buffer(YY_CURRENT_BUFFER);
	if (rf != NULL)
		yy_switch_to_buffer(rf->lex_buffer);
}
コード例 #19
0
ファイル: read.c プロジェクト: orodley/ali
LispObj *read_from_string(char *str)
{
	YY_BUFFER_STATE yy_buf = yy_scan_string(str);
	LispObj *obj = read_from_yybuf(yy_buf);
	yy_delete_buffer(yy_buf);

	return obj;
}
コード例 #20
0
ファイル: read.c プロジェクト: orodley/ali
LispObj *read_from_stream(FILE *stream)
{
	YY_BUFFER_STATE yy_buf = yy_create_buffer(stream, YY_BUF_SIZE);
	LispObj *obj = read_from_yybuf(yy_buf);
	yy_delete_buffer(yy_buf);

	return obj;
}
コード例 #21
0
ファイル: parse.c プロジェクト: ddjfreedom/Shell
int parse(const char *input, cmd *cmds[], int size)
{
  elementType type;
  redirectMode redir;
  int cmd_count = -1, fd;
  int valid_pipe = 0;
  char *str;
  YY_BUFFER_STATE buf = yy_scan_string(input);
  while ((type = yylex()) != 0) {
    if (cmd_count == -1) cmd_count = 0;
    fd = -1;
    str = NULL;
    switch (type) {
    case SEMICOLON:
      cmd_count++; valid_pipe = 0; break;
    case PIPE:
      if (!valid_pipe) {
        fprintf(stderr, "shell: invalid pipe\n");
        yy_delete_buffer(buf);
        return -1;
      }
      cmd_add_pcmd(&cmds[cmd_count]); break;
    case CMD:
      valid_pipe = 1;
    case STRING:
      str = handle_escaped_chs(yytext);
      //fprintf(stderr, "%s %s\n", yytext, str);
      cmd_addarg(cmds[cmd_count], str); break;
    case FD_IN_RED: case FD_OUT_RED: case FD_APPEND:
      fd = get_fd(yytext, type);
    case IN_RED: case OUT_RED: case OUT_APPEND: case OUT_ERR_RED: case OUT_ERR_APPEND:
      yylex();
      str = handle_escaped_chs(yytext);
      cmd_redirect(cmds[cmd_count], fd, type, str); break;
    case BACKGROUND:
      cmd_set_bg(cmds[cmd_count]); break;
    default:
      fprintf(stderr, "Unknown type: %d, %s\n", type, yytext);
    }
    free(str);
  }
  yy_delete_buffer(buf);
  return cmd_count + 1;
}
コード例 #22
0
ファイル: compileST.c プロジェクト: actility/ong
int compileST (char *pgm) {
	extern char *yy_scan_bytes();
	char *my_string_buffer = yy_scan_bytes (pgm, strlen(pgm)+1);
	int my_parse_result  = yyparse ();
	if	(my_parse_result)
		return	-1;
	yy_delete_buffer (my_string_buffer);
	yylex_destroy();
	return 0;
}
コード例 #23
0
ファイル: parser.cpp プロジェクト: Albaraa2010/AI_CHESS
void parseFile(FILE* in)
{
  YY_BUFFER_STATE* tmp =  new YY_BUFFER_STATE;
  *tmp = yy_create_buffer(in, YY_BUF_SIZE);
  yy_switch_to_buffer(*tmp);
  if(buffer)
    yy_delete_buffer(*buffer);
    delete buffer;
  buffer = tmp;
}
コード例 #24
0
ファイル: fancy_parser.c プロジェクト: IFFranciscoME/fancy
static VALUE
parse_string(VALUE self, VALUE code) {
  VALUE lineno = rb_funcall(self, rb_intern("lineno"), 0);
  char *str = StringValueCStr(code);
  YY_BUFFER_STATE buffstate = yy_scan_string(str);
  yy_switch_to_buffer(buffstate);
  yylineno = NUM2INT(lineno);
  yyparse(self);
  yy_delete_buffer(buffstate);
  return self;
}
コード例 #25
0
ファイル: stemmer.c プロジェクト: KWARC/deprecated-LLaMaPUn
void close_stemmer() {
  //fclose(morpha_instream);
  //free(morpha_instream_buff_ptr);
  //fclose(morpha_outstream);
  //free(morpha_outstream_buff_ptr);
  yy_delete_buffer(yy_current_buffer);
  int i;
  for (i=0; i<verbstem_n; i++) {
    free(verbstem_list[i]);
  }
  free(verbstem_list);
}
コード例 #26
0
ファイル: nsscompiler.cpp プロジェクト: DaZombieKiller/libnpa
void Compile(const char* pBuffer, uint32_t Length, Buffer* NsbBuffer, Buffer* MapBuffer)
{
    Counter = 1;
    SymCounter = 1;
    Output = NsbBuffer;
    MapOutput = MapBuffer;
    YY_BUFFER_STATE buffer = yy_scan_bytes(pBuffer, Length);
    yyparse();
    pRoot->Compile();
    yy_delete_buffer(buffer);
    delete pRoot;
}
コード例 #27
0
ファイル: entry.c プロジェクト: hand-code/whistlepig
// tokenizes and adds everything under a single field
wp_error* wp_entry_add_string(wp_entry* entry, const char* field, const char* string) {
  yyscan_t scanner;
  lexinfo charpos = {0, 0};

  yylex_init_extra(&charpos, &scanner);
  YY_BUFFER_STATE state = yy_scan_string(string, scanner);
  RELAY_ERROR(add_from_lexer(entry, &scanner, field));
  yy_delete_buffer(state, scanner);
  yylex_destroy(scanner);

  return NO_ERROR;
}
コード例 #28
0
ファイル: filter.c プロジェクト: alberto98fx/zmap
int parse_filter_string(char *filter)
{
	YY_BUFFER_STATE buffer_state = yy_scan_string(filter);
	int status = yyparse();
	yy_delete_buffer(buffer_state);
	if (status) {
		// Error
		log_error("zmap", "Unable to parse filter string: '%s'", filter);
		return 0;
	}
	zconf.filter.expression = zfilter;
	return 1;
}
コード例 #29
0
ファイル: compiler.cpp プロジェクト: Raekye/hmmm
ASTNode* Compiler::parse(std::string code) {
	ASTNode* root;
	yyscan_t scanner;
	YY_BUFFER_STATE buffer;
	if (yylex_init(&scanner)) {
		return NULL;
	}
	buffer = yy_scan_string(code.c_str(), scanner);
	yyparse(&root, scanner);
	yy_delete_buffer(buffer, scanner);
	yylex_destroy(scanner);
	return root;
}
コード例 #30
0
ファイル: do_inter.c プロジェクト: actility/ong
param_ret_t *do_ST_interpreter (void *userctx, char *pgm) {
	extern char *yy_scan_bytes();
	char *my_string_buffer = yy_scan_bytes (pgm, strlen(pgm)+1);
	int my_parse_result  = yyparse ();
	if	(my_parse_result)
		return	NULL;
	yy_delete_buffer (my_string_buffer);
	yylex_destroy();

	param_ret_t *pret = codeGen (programBlock, userctx);
	cleanUp (programBlock);

	return	pret;
}