Annotation of parser3/src/main/compile.C, revision 1.21

1.1       paf         1: /*
1.21    ! paf         2:   $Id: compile.C,v 1.20 2001/03/08 11:27:48 paf Exp $
1.1       paf         3: */
                      4: 
1.10      paf         5: #include "pa_request.h"
1.3       paf         6: #include "pa_string.h"
1.1       paf         7: #include "pa_array.h"
                      8: #include "code.h"
                      9: #include "compile_tools.h"
1.4       paf        10: #include "pa_exception.h"
1.1       paf        11: 
                     12: #include <stdio.h>
                     13: 
                     14: extern int yydebug;
                     15: extern int yyparse (void *);
                     16: 
1.18      paf        17: VClass& Request::real_compile(COMPILE_PARAMS) {
1.7       paf        18:        // prepare to parse
1.1       paf        19:        struct parse_control pc;
1.10      paf        20: 
1.7       paf        21:        // input 
1.10      paf        22:        pc.pool=&pool();
1.18      paf        23:        pc.request=this;
1.20      paf        24:        VClass *vclass;
                     25:        if(name) { // we were told the name of a class?
                     26:                // yes. create it
                     27:                vclass=NEW VClass(pool());
                     28:                vclass->set_name(*name);
                     29:                // defaulting base. may change with @BASE
1.21    ! paf        30:                vclass->set_base(root_class);
1.20      paf        31:                // append to request's classes
                     32:                classes_array()+=vclass;
                     33:                classes().put(*name, vclass);
                     34:        } else
1.21    ! paf        35:                vclass=&root_class; // until changed with @CLASS would consider operators loading
1.19      paf        36:        pc.vclass=vclass;
1.9       paf        37: 
1.1       paf        38:        pc.source=source;
                     39: #ifndef NO_STRING_ORIGIN
                     40:        pc.file=file;
1.7       paf        41:        pc.line=pc.col=0;
1.1       paf        42: #endif
1.7       paf        43:        // initialise state
1.1       paf        44:        pc.pending_state=0;
1.13      paf        45:        pc.string=NEW String(pool());   
1.1       paf        46:        pc.ls=LS_USER;
                     47:        pc.sp=0;
1.7       paf        48:        
1.12      paf        49:        // parse=compile! 
1.14      paf        50:        yydebug=1;
1.10      paf        51:        if(yyparse(&pc)) { // error?
1.15      paf        52:                if(pc.col==0) { // expecting something after EOL means they've expected it BEFORE
                     53:                        // step back.  -1 col means EOL
1.8       paf        54:                        pc.line--;
1.16      paf        55:                        pc.col=-1;
                     56:                } 
1.13      paf        57:                THROW(0,0,
1.6       paf        58:                        0,
1.17      paf        59:                        "%s(%d:%d): %s", file, 1+pc.line, pc.col, pc.error);
1.8       paf        60:        }
1.7       paf        61: 
                     62:        // result
1.18      paf        63:        return *pc.vclass;
1.1       paf        64: }

E-mail: