summaryrefslogtreecommitdiffstats
path: root/hl/src/H5LTanalyze.l
diff options
context:
space:
mode:
authorRaymond Lu <songyulu@hdfgroup.org>2005-11-03 14:11:09 (GMT)
committerRaymond Lu <songyulu@hdfgroup.org>2005-11-03 14:11:09 (GMT)
commit47b0c3b356cca31ffae47c86dc4ebd649ce6bef6 (patch)
tree1306b6407ab049d50ffbcfbfc9b450924d7e5713 /hl/src/H5LTanalyze.l
parent7fd6ff2413d3ecf65e77c9474f410a7acb9f4e52 (diff)
downloadhdf5-47b0c3b356cca31ffae47c86dc4ebd649ce6bef6.zip
hdf5-47b0c3b356cca31ffae47c86dc4ebd649ce6bef6.tar.gz
hdf5-47b0c3b356cca31ffae47c86dc4ebd649ce6bef6.tar.bz2
[svn-r11676] Purpose: New feature
Description: Adding the new function H5LTtext_to_dtype() for converting text description to data type. The next step will be H5LTdtype_to_text(). Solution: Use Lex and Yacc to do parsing of the text. H5LTanalyze.l is the lexer for analyzing the input; H5LTparse.y is the parser. They are not part of HL library, but are used to generate lex.yy.c (from H5LTanalyze.l) as well as y.tab.c and y.tab.h (from H5LTparse.y). The tools used to create these source files are GNU FLEX and YACC on a Linux machine (fuss). The commands are "lex H5LTanalyze.l" and "yacc -d H5LTparse.y". Detailed document will be added later. Platforms tested: h5committest and fuss. Misc. update: MANIFEST
Diffstat (limited to 'hl/src/H5LTanalyze.l')
-rw-r--r--hl/src/H5LTanalyze.l161
1 files changed, 161 insertions, 0 deletions
diff --git a/hl/src/H5LTanalyze.l b/hl/src/H5LTanalyze.l
new file mode 100644
index 0000000..364272f
--- /dev/null
+++ b/hl/src/H5LTanalyze.l
@@ -0,0 +1,161 @@
+%{
+#include <string.h>
+#include<hdf5.h>
+#include "y.tab.h"
+#undef YY_INPUT
+#define YY_INPUT(b, r, ms) (r=my_yyinput(b, ms))
+#define token(x) (int)x
+extern char *myinput;
+extern int input_len;
+
+#define STACK_SIZE 16
+
+/*variables for compound type*/
+extern struct cmpd_info {
+ hid_t id;
+ hbool_t is_field;
+ hbool_t first_memb;
+};
+extern struct cmpd_info cmpd_stack[STACK_SIZE];
+extern int csindex;
+
+/*variables for array type*/
+extern struct arr_info {
+ hsize_t dims[H5S_MAX_RANK];
+ int ndim;
+ hbool_t is_dim;
+};
+extern struct arr_info arr_stack[STACK_SIZE];
+extern int asindex;
+
+/*variables for enumerate type*/
+extern hbool_t is_enum;
+extern hbool_t is_enum_memb;
+
+/*variables for string type*/
+extern hbool_t is_str_size;
+extern hbool_t is_str_pad;
+
+/*variables for opaque type*/
+extern hbool_t is_opq_size;
+extern hbool_t is_opq_tag;
+
+hbool_t first_quote = 1;
+
+%}
+
+%s TAG_STRING
+
+%%
+
+H5T_STD_I8BE {return token(H5T_STD_I8BE_TOKEN);}
+H5T_STD_I8LE {return token(H5T_STD_I8LE_TOKEN);}
+H5T_STD_I16BE {return token(H5T_STD_I16BE_TOKEN);}
+H5T_STD_I16LE {return token(H5T_STD_I16LE_TOKEN);}
+H5T_STD_I32BE {return token(H5T_STD_I32BE_TOKEN);}
+H5T_STD_I32LE {return token(H5T_STD_I32LE_TOKEN);}
+H5T_STD_I64BE {return token(H5T_STD_I64BE_TOKEN);}
+H5T_STD_I64LE {return token(H5T_STD_I64LE_TOKEN);}
+
+H5T_STD_U8BE {return token(H5T_STD_U8BE_TOKEN);}
+H5T_STD_U8LE {return token(H5T_STD_U8LE_TOKEN);}
+H5T_STD_U16BE {return token(H5T_STD_U16BE_TOKEN);}
+H5T_STD_U16LE {return token(H5T_STD_U16LE_TOKEN);}
+H5T_STD_U32BE {return token(H5T_STD_U32BE_TOKEN);}
+H5T_STD_U32LE {return token(H5T_STD_U32LE_TOKEN);}
+H5T_STD_U64BE {return token(H5T_STD_U64BE_TOKEN);}
+H5T_STD_U64LE {return token(H5T_STD_U64LE_TOKEN);}
+
+H5T_NATIVE_CHAR {return token(H5T_NATIVE_CHAR_TOKEN);}
+H5T_NATIVE_SCHAR {return token(H5T_NATIVE_SCHAR_TOKEN);}
+H5T_NATIVE_UCHAR {return token(H5T_NATIVE_UCHAR_TOKEN);}
+H5T_NATIVE_SHORT {return token(H5T_NATIVE_SHORT_TOKEN);}
+H5T_NATIVE_USHORT {return token(H5T_NATIVE_USHORT_TOKEN);}
+H5T_NATIVE_INT {return token(H5T_NATIVE_INT_TOKEN);}
+H5T_NATIVE_UINT {return token(H5T_NATIVE_UINT_TOKEN);}
+H5T_NATIVE_LONG {return token(H5T_NATIVE_LONG_TOKEN);}
+H5T_NATIVE_ULONG {return token(H5T_NATIVE_ULONG_TOKEN);}
+H5T_NATIVE_LLONG {return token(H5T_NATIVE_LLONG_TOKEN);}
+H5T_NATIVE_ULLONG {return token(H5T_NATIVE_ULLONG_TOKEN);}
+
+H5T_IEEE_F32BE {return token(H5T_IEEE_F32BE_TOKEN);}
+H5T_IEEE_F32LE {return token(H5T_IEEE_F32LE_TOKEN);}
+H5T_IEEE_F64BE {return token(H5T_IEEE_F64BE_TOKEN);}
+H5T_IEEE_F64LE {return token(H5T_IEEE_F64LE_TOKEN);}
+H5T_NATIVE_FLOAT {return token(H5T_NATIVE_FLOAT_TOKEN);}
+H5T_NATIVE_DOUBLE {return token(H5T_NATIVE_DOUBLE_TOKEN);}
+H5T_NATIVE_LDOUBLE {return token(H5T_NATIVE_LDOUBLE_TOKEN);}
+
+H5T_STRING {return token(H5T_STRING_TOKEN);}
+STRSIZE {return token(STRSIZE_TOKEN);}
+STRPAD {return token(STRPAD_TOKEN);}
+CSET {return token(CSET_TOKEN);}
+CTYPE {return token(CTYPE_TOKEN);}
+H5T_STR_NULLTERM {return token(H5T_STR_NULLTERM_TOKEN);}
+H5T_STR_NULLPAD {return token(H5T_STR_NULLPAD_TOKEN);}
+H5T_STR_SPACEPAD {return token(H5T_STR_SPACEPAD_TOKEN);}
+H5T_CSET_ASCII {return token(H5T_CSET_ASCII_TOKEN);}
+H5T_C_S1 {return token(H5T_C_S1_TOKEN);}
+H5T_FORTRAN_S1 {return token(H5T_FORTRAN_S1_TOKEN);}
+H5T_VARIABLE {return token(H5T_VARIABLE_TOKEN);}
+
+H5T_COMPOUND {return token(H5T_COMPOUND_TOKEN);}
+H5T_ENUM {return token(H5T_ENUM_TOKEN);}
+H5T_ARRAY {return token(H5T_ARRAY_TOKEN);}
+H5T_VLEN {return token(H5T_VLEN_TOKEN);}
+
+H5T_OPAQUE {return token(H5T_OPAQUE_TOKEN);}
+OPQ_SIZE {return token(OPQ_SIZE_TOKEN);}
+OPQ_TAG {return token(OPQ_TAG_TOKEN);}
+
+[0-9]+ {
+ if(is_str_size || (is_enum && is_enum_memb) ||
+ is_opq_size || (asindex>-1 && arr_stack[asindex].is_dim)) {
+ yylval.ival = atoi(yytext);
+ return NUMBER;
+ } else
+ REJECT;
+ }
+
+"\"" {
+ /*if it's first quote, and is a opaque tag or an enum symbol*/
+ if((is_opq_tag || is_enum || (csindex>-1 && cmpd_stack[csindex].is_field)) && first_quote) {
+ first_quote = 0;
+ BEGIN TAG_STRING;
+ } else /*if it's second quote*/
+ first_quote = 1;
+ return token('"');
+ }
+<TAG_STRING>[^\"]+ {
+ yylval.sval = strdup(yytext);
+ BEGIN INITIAL;
+ return STRING;
+ }
+
+"{" {return token('{');}
+"}" {return token('}');}
+"[" {return token('[');}
+"]" {return token(']');}
+";" {return token(';');}
+[ \t\n]* ;
+"\n" { return 0; }
+
+%%
+int my_yyinput(char *buf, int max_size)
+{
+ int ret;
+
+ memcpy(buf, myinput, input_len);
+ ret = input_len;
+ return ret;
+}
+
+yyerror(msg)
+{
+ printf("ERROR: %s before \"%s\".\n", msg, yytext);
+}
+
+yywrap()
+{
+ return(1);
+}