diff --git a/src/Makefile b/src/Makefile index a377e82ca9553eaca31fe9bea095985642b5a753..29a35ec4701c2b0d7eca3f231c773136e46276e7 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,6 +1,6 @@ ############################################################################# # Makefile for building: ../../bin/frida2 -# Generated by qmake (1.07a) (Qt 3.3.8b) on: Thu Apr 3 10:22:19 2008 +# Generated by qmake (1.07a) (Qt 3.3.8b) on: Thu Apr 3 14:44:29 2008 # Project: src.pro # Template: app # Command: $(QMAKE) -o Makefile src.pro @@ -576,7 +576,8 @@ obj/xax_yacc.o: xax_yacc.cpp xax_yacc.h \ range.h.tpl $(CXX) -c $(CXXFLAGS) $(INCPATH) -o obj/xax_yacc.o xax_yacc.cpp -obj/yin_yacc.o: yin_yacc.cpp yin_yacc.h +obj/yin_yacc.o: yin_yacc.cpp yin_yacc.h \ + yamc.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o obj/yin_yacc.o yin_yacc.cpp xax_yacc.cpp: xax.y diff --git a/src/expr.h b/src/expr.h index b0b65fa399ba31e7920230dcf1e77c903d3b9109..999b774c9db6542109db76bc01a178830aa03b8c 100644 --- a/src/expr.h +++ b/src/expr.h @@ -2,7 +2,6 @@ #include <iostream> #include <vector> - //! Context a generic expression is used in. class CContext { diff --git a/src/file_io.cpp b/src/file_io.cpp index ce570ec1496e3a7ee9218bbdc429e56c8949f574..03c2ddf7438f664e0c2ccbd5624af48751d2a9a2 100644 --- a/src/file_io.cpp +++ b/src/file_io.cpp @@ -10,6 +10,7 @@ #include <string> #include <vector> +#include <map> #include "olm.h" #include "asi.h" @@ -72,13 +73,25 @@ void NFileIO::Load_08( FILE *F_in, string flong ) { string lin, key, val, fdir, fshort, fext; uint iz, nj=0, j; + CYam *yin; COld old; CCoord co; CScan sout; mystd::fname_divide( flong, &fdir, &fshort, &fext); + if( yin_parse_file( F_in, yin ) ){ + printf( "yin_parse_file failed\n" ); + return; + } + if( yin==0 ){ + printf( "yin=0\n" ); + return; + } + + yin->show( 0 ); + delete yin; } //! Load a .a01 formatted file. diff --git a/src/src.pro b/src/src.pro index 85c54e57105165ef04b97b0d70813b3f8d80bce0..996cd928c4e8803e65b6b98752e528a44df0bb75 100644 --- a/src/src.pro +++ b/src/src.pro @@ -1,5 +1,5 @@ ###################################################################### -# Automatically generated by qmake (1.07a) Thu Apr 3 10:22:19 2008 +# Automatically generated by qmake (1.07a) Thu Apr 3 14:44:29 2008 ###################################################################### unix:LIBS += -lgsl -lgslcblas -lreadline -lhistory -lfftw3 -lxml2 -lyaml -l:../../lmfit/lmmin.o diff --git a/src/yamc.cpp b/src/yamc.cpp index 4892d150caa0f965c4fa6d43a1f902a40f46dc24..8cf0165241cf3983e5eaed4f61713d678f2b91bc 100644 --- a/src/yamc.cpp +++ b/src/yamc.cpp @@ -1,4 +1,31 @@ -// #include "yamc.h" +#include <stdlib.h> +#include <stdio.h> +#include<vector> +#include<map> +#include<string> +#include<iostream> + +using namespace std; +#include "yamc.h" + +void CYam::show( int indent ) const +{ + int i; + for( i=0; i<indent; ++i ) cout << " " ; + switch( t ){ + case _S: + cout << s; + break; + case _A: + cout << "ARR"; + break; + case _M: + cout << "MAP"; + break; + }; + cout << "\n"; +} + #include <yaml/yaml.h> #define CC (const char*) @@ -11,18 +38,17 @@ int yinparse(void*); int yinerror( const char* errmsg ) { - printf( "yaml read error: %s\n", errmsg ); + printf( "yinerror: yaml read error: %s\n", errmsg ); } -int yinlex(void* yinlval) { +int yinlex( yaml_event_t* yinlval ) { yaml_event_delete(&input_event); if (!yaml_parser_parse(&parser, &input_event)){ - printf( "parser error\n" ); + printf( "yinlex: parser error\n" ); yinerror; return 0; } - yinlval = (void*) &input_event; - switch (input_event.type){ + switch ( input_event.type ){ case YAML_STREAM_START_EVENT: return YI; case YAML_STREAM_END_EVENT: @@ -40,26 +66,30 @@ int yinlex(void* yinlval) { case YAML_MAPPING_END_EVENT: return MF; case YAML_SCALAR_EVENT: + yinlval->str = string ( (const char*) input_event->data.scalar.value ); return S; case YAML_ALIAS_EVENT: return ALIAS; } } -void yin_parse_file( FILE *F_in ) +int yin_parse_file( FILE *F_in, CYam *yin ) { + int ret; memset(&parser, 0, sizeof(parser)); memset(&input_event, 0, sizeof(input_event)); if (!yaml_parser_initialize(&parser)) { fprintf(stderr, "Could not initialize the parser object\n"); - return; + return -1; } yaml_parser_set_input_file( &parser, F_in ); - // yinparse( (void*)&j ); + ret = yinparse( (void*)yin ); yaml_event_delete(&input_event); yaml_parser_delete(&parser); + + return ret; } diff --git a/src/yamc.h b/src/yamc.h index 3489cc6ccf81b8e1cad3580acdc73318e825d960..94be600e2e4c7f85d2a7d15c0f3f047559faab80 100644 --- a/src/yamc.h +++ b/src/yamc.h @@ -1,9 +1,5 @@ -#include<vector> -#include<map> -#include<string> - -typedef vector<void*> yarr; -typedef map< string, void* > ymap; +typedef vector< class CYam*> yarr; +typedef map< string, class CYam* > ymap; class CYam { public: @@ -23,4 +19,7 @@ class CYam { break; }; }; + void show( int indent) const; }; + +int yin_parse_file( FILE *F_in, CYam *yin ); diff --git a/src/yin.y b/src/yin.y index bd0e50fcaf03b5dc3d3a5187151233b952b2a3b2..560fe1b6df09b0ae57de3ee64643e51851f096f1 100644 --- a/src/yin.y +++ b/src/yin.y @@ -3,28 +3,44 @@ /* developed with GNU Bison 2.3 */ /* not expected to work with pre-GNU yacc */ -%{ -using namespace std; -/* #define YYSTYPE void* */ -%} %pure-parser %debug %{ +#include<vector> +#include<map> +#include<string> +using namespace std; +#include "yamc.h" +#include "yaml/yaml.h" +#define YYSTYPE yaml_event_t* #define YYPARSE_PARAM ret +#define CC (const char*) int yinerror(const char*); int yinlex(void *yinlval); %} -%token <ptr> YI YF DI DF S AI AF MI MF ALIAS +%union{ + CYam* yam; + yarr* arr; + ymap* map; + string str; +} + +%token YI YF DI DF AI AF MI MF ALIAS +%token <str> S +%type <yam> input multidoc doc ele +%type <arr> arr +%type <map> map /* Grammar */ %% input: - YI multidoc YF { printf( "fine\n" ); return 0; } + YI doc YF { ret = $2; return 0; } + /* multidoc not used */ ; multidoc: @@ -33,18 +49,18 @@ multidoc: ; doc: /* double-valued expression */ - DI ele DF {} + DI ele DF { $$ = $2; } ; ele: - S { /*printf( "scalar\n" );*/ } - | arr - | map + S { $$ = new CYam( $1 ); } + | arr { $$ = new CYam( $1 ); } + | map { $$ = new CYam( $1 ); } | { printf( "empty document\n" ); } ; arr: - AI multimember AF { printf( "array\n" ); } + AI multimember AF { ); } ; multimember: