Annotation of parser3/src/targets/parser/parser.C, revision 1.14

1.1       paf         1: /*
1.14    ! paf         2:   $Id: parser.C,v 1.13 2001/02/21 15:27:00 paf Exp $
1.1       paf         3: */
                      4: 
                      5: #include <stdio.h>
                      6: #include <stdlib.h>
                      7: 
                      8: #include "pa_hash.h"
                      9: #include "pa_array.h"
                     10: #include "pa_table.h"
                     11: #include "pa_common.h"
1.4       paf        12: #include "pa_pool.h"
1.7       paf        13: #include "compile.h"
                     14: #include "execute.h"
1.10      paf        15: #include "pa_vclass.h"
1.1       paf        16: 
1.14    ! paf        17: #include "core.h"
        !            18: 
1.1       paf        19: char *itoa(int n, char *buf){
                     20:     snprintf(buf,MAX_STRING,"%d",n);
                     21:     return buf;
                     22: }
                     23: 
                     24: int main(int argc, char *argv[]) {
1.14    ! paf        25:        core();
        !            26:        exit 0;
        !            27: 
1.2       paf        28:        Exception fatal_exception;
                     29:        if(EXCEPTION_TRY(fatal_exception)) {
1.4       paf        30:                Pool pool(fatal_exception);
1.2       paf        31:                
                     32:                char *file="file1";
1.5       paf        33:                String& string=*new(pool) String(pool);
1.7       paf        34:                string.APPEND("Hello, ", 0,file, 1);
                     35:                string.APPEND("w", 0,file, 2);
                     36:                string.APPEND("o", 0,file, 3);
                     37:                string.APPEND("r", 0,file, 4);
                     38:                string.APPEND("l", 0,file, 5);
                     39:                string.APPEND("d", 0,file, 6);
                     40:                string.APPEND("!\n ", 0,file, 7);
1.2       paf        41:                printf(string.cstr());
                     42:                
                     43:                char *key1_file="key1_file";
1.10      paf        44:                Hash& hash=*new(pool) Hash(pool);
1.2       paf        45:                String key1=string;
1.7       paf        46:                key1.APPEND("1", 0,key1_file, 1);
1.5       paf        47:                String& value1=*new(pool) String(pool);
1.7       paf        48:                value1.APPEND("i'm value1\n", 0,file, 1);
1.5       paf        49:                String& value2=*new(pool) String(pool);
1.7       paf        50:                value2.APPEND("i'm value2\n", 0,file, 1);
1.2       paf        51:                hash.put(key1, &value1);
                     52:                char *key2_file="key2_file";
                     53:                String key2=string;
1.7       paf        54:                key2.APPEND("2", 0,key2_file, 1);
1.2       paf        55:                hash.put(key2, &value2);
                     56:                String *found_value=(String*)hash.get(key2);
                     57:                printf(found_value?found_value->cstr():"not found\n");
                     58:                
1.7       paf        59:                String& a=*new(pool) String(pool);      a.APPEND("fi", 0,file, 1); a.APPEND("rst", 0,file, 2);
                     60:                String& b=*new(pool) String(pool);      b.APPEND("fir", 0,file, 1); b.APPEND("st", 0,file, 2);
1.2       paf        61:                printf(a==b?"eq\n":"ne\n");
                     62:                
                     63:                
1.5       paf        64:                Array& array=*new(pool) Array(pool, 2);
1.2       paf        65:                array+="first";
                     66:                array+="second";
                     67:                array+="third";
                     68:                printf("%s-%s-%s\n", 
1.1       paf        69:                        array.get_cstr(0), 
                     70:                        array.get_cstr(1),
                     71:                        array.get_cstr(2));
1.2       paf        72:                
1.5       paf        73:                Array& a1=*new(pool) Array(pool);
1.2       paf        74:                a1+="first";
1.5       paf        75:                Array& a2=*new(pool) Array(pool);
1.2       paf        76:                a2+="second";
1.5       paf        77:                Array& asum=*new(pool) Array(pool);
1.2       paf        78:                asum.append_array(a1);
                     79:                asum.append_array(a2);
                     80:                printf("%s-%s\n", 
1.1       paf        81:                        asum.get_cstr(0), 
                     82:                        asum.get_cstr(1));
                     83: 
1.4       paf        84:                Pool request_pool(fatal_exception);
1.2       paf        85:                Request request(request_pool);
                     86: 
                     87:                Exception operator_exception;
                     88:                Local_request_exception subst(request, operator_exception);
                     89:                if(EXCEPTION_TRY(request.exception())) {
1.3       paf        90:                        /*
1.2       paf        91:                        Array acolumns(request.pool());
1.1       paf        92:                        acolumns+="id";
                     93:                        acolumns+="name";
                     94:                        acolumns+="age";
1.3       paf        95:                        Table table(request, "_file.cfg", 1, &acolumns);
                     96:                        */
                     97:                        Table table(request, "_file.cfg", 1, 0);
1.1       paf        98:                        for(int n=1; n<=5; n++) {
1.5       paf        99:                                Array& row=*new(request.pool()) Array(request.pool(), 3/*table.columns()->size()*/);
1.2       paf       100:                                char *buf=static_cast<char *>(request.pool().malloc(MAX_STRING));
1.1       paf       101:                                row+=itoa(n, buf);
                    102:                                row+="paf";
                    103:                                row+="99";
                    104:                                
1.3       paf       105:                                table+=&row;
1.1       paf       106:                        }
1.3       paf       107:                        /*
                    108:                        for(int i=0; i<table.columns()->size(); i++) 
                    109:                                printf("%s\t", table.columns()->get_cstr(i));
1.1       paf       110:                        printf("\n");
1.3       paf       111:                        */
                    112:                        for(table.set_current(0); table.get_current()<table.size(); table.inc_current()) {
1.2       paf       113:                                String line(request.pool());
1.3       paf       114:                                for(int i=0; i<5/*table.columns()->size()*/; i++) {
                    115:                                        /**/
                    116:                                        String name(request.pool());
                    117:                                        char *buf=static_cast<char *>(request.pool().malloc(MAX_STRING));
1.7       paf       118:                                        name.APPEND(itoa(i, buf), 0,"names file", 0);
1.1       paf       119:                                        //name.APPEND("id", "names file", 0);
1.3       paf       120:                                        table.read_item(line, name);
                    121:                                        /*
                    122:                                        const char *cstr_name=table.columns()->get_cstr(i);
1.2       paf       123:                                        String name(request.pool());
1.1       paf       124:                                        name.APPEND(cstr_name, 0, 0);
1.3       paf       125:                                        table.read_item(line, name);
                    126:                                        /**/
1.7       paf       127:                                        line.APPEND("\t", 0,0, 0);
1.1       paf       128:                                }
                    129:                                printf("%s\n", line.cstr());
                    130:                        }
1.6       paf       131: 
1.7       paf       132: /*
1.6       paf       133:                        String it(request.pool());
                    134:                        it.APPEND("ab.cd[zzz]", 0,0);
                    135:                        String_iterator si(it);
1.7       paf       136:                        / *si++;
1.6       paf       137:                        si++;
                    138:                        si++;
                    139:                        si++;
                    140:                        si++;
                    141:                        si++;
1.7       paf       142:                        * /
                    143:                        / *bool found=si.skip_to('.');
1.6       paf       144:                        si++;
1.7       paf       145:                        * /
1.6       paf       146:                        si++;
                    147:                        Char_types types;
                    148:                        types.set(' ', 1);
                    149:                        types.set('[', 2);
                    150:                        types.set(']', 3);
                    151:                        int type=si.skip_to(types);
                    152:                        si++;
1.7       paf       153: */
1.1       paf       154:                } else {
1.2       paf       155:                        Exception& e=request.exception();
1.3       paf       156:                        printf("operator_error occured: %s\n", e.comment());
1.2       paf       157:                        const String *type=e.type();
                    158:                        if(type) {
                    159:                                printf("  type: %s", type->cstr());
                    160:                                const String *code=e.code();
                    161:                                if(code)
                    162:                                        printf(", code: %s", code->cstr());
                    163:                                printf("\n");
                    164:                        }
                    165:                        const String *problem_source=e.problem_source();
1.1       paf       166:                        if(problem_source) {
                    167:                                const Origin& origin=problem_source->origin();
1.12      paf       168:                                printf("  '%s'\n", 
                    169:                                        problem_source->cstr());
                    170:                                if(origin.file)
                    171:                                        printf(" [%s:%d]",
                    172:                                                origin.file, origin.line);
                    173:                                printf("\n");
1.1       paf       174:                        }
                    175:                }
                    176:        } else {
1.2       paf       177:                printf("fatal exception occured: %s\n", fatal_exception.comment());
1.1       paf       178:        }
                    179: 
                    180:        return 0;
                    181: }

E-mail: