1 /*****************************************************************************/
2 /* 8888888 88888888 88888888 */
5 /* 8 88888888 88888888 */
8 /* 888888 888888888 888888888 */
10 /* A Two-Dimensional General Purpose Semiconductor Simulator. */
13 /* Last update: May 14, 2006 */
17 /* NINT, No.69 P.O.Box, Xi'an City, China */
19 /*****************************************************************************/
31 //structures work with lex/yacc
33 const int BOOLVAR
= 20;
34 const int INTERGER
= 21;
35 const int DOUBLE
= 22;
38 // value can be double ,int, bool or string
47 //this structure storage: parameter_name = arg_value;
55 typedef multimap
<string
, Arg
> ARG_MAP
;
57 //this structure storage: cmd_type Keyword line number and arg_map
58 //the sequence of parameters is not critical, multimap is very efficent.
65 ARG_MAP::iterator parg
;
67 int get_current_lineno() {return lineno
;};
68 // search the arg list of current cmd
69 bool allowed_args(int argc
,...);
70 void arg_search_begin() {parg
=arg_map
.begin();}
71 void goto_next_arg() {parg
++;}
72 bool arg_search_end() {return parg
==arg_map
.end();}
73 const char *get_cmd_keyword() { return KeyWord
.c_str();}
74 const char *get_current_arg_label() { return parg
->second
.arg_label
.c_str();}
75 Arg_value
get_current_arg_value() { return parg
->second
.arg_value
;}
76 // get parameter value of current cmd
77 double get_number(const char *name
, int alias_num
, ...);
78 int get_integer(const char *name
, int alias_num
, ...);
79 bool get_bool(const char *name
, int alias_num
, ...);
80 char * get_string(const char *name
, int alias_num
, ...);
81 bool is_arg_exist(const char *name
);
82 bool is_arg_value(const char *name
, const char * value
);
86 extern int yyparse(list
<Cmd
> & cmd_list
);
89 // because the sequence of commands must be keep,
90 // I choose list as data structure.
95 list
<Cmd
>::iterator pcmd
;
96 stack
<list
<Cmd
>::iterator
> cmd_iterator_stack
;
98 int parse_file(char *cmd_file
)
100 yyin
=fopen(cmd_file
,"r");
102 { printf("Can't open input file, does it exist?\n"); return 1; }
103 if(yyparse(cmd_list
))
104 { printf("Input parse interrupt.\n"); return 1; }
109 void cmd_search_begin() {cmd_iterator_stack
.push(pcmd
);pcmd
=cmd_list
.begin();}
110 void goto_next_cmd() {pcmd
++;}
111 bool cmd_search_end()
113 if(pcmd
==cmd_list
.end())
115 pcmd
=cmd_iterator_stack
.top();
116 cmd_iterator_stack
.pop();
122 list
<Cmd
>::iterator
get_current_cmd() {return pcmd
;}
123 bool is_current_cmd(const char *cmd_name
) {return !strcmp(pcmd
->KeyWord
.c_str(),cmd_name
);}
124 void delete_current_cmd() {pcmd
= cmd_list
.erase(pcmd
);}
125 void delete_cmd(const char *cmd_name
)
127 for(pcmd
=cmd_list
.begin();pcmd
!=cmd_list
.end();pcmd
++)
128 if(!strcmp(cmd_name
,pcmd
->KeyWord
.c_str())) pcmd
= cmd_list
.erase(pcmd
);