Annotation of parser3/src/main/compile.C, revision 1.51
1.32 paf 1: /** @file
1.33 paf 2: Parser: compiler part of request class.
3:
1.24 paf 4: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.50 parser 5: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.33 paf 6:
1.51 ! parser 7: $Id: compile.C,v 1.50 2001/09/26 10:32:25 parser Exp $
1.1 paf 8: */
9:
1.36 paf 10: #include "pa_opcode.h"
1.10 paf 11: #include "pa_request.h"
1.3 paf 12: #include "pa_string.h"
1.1 paf 13: #include "pa_array.h"
14: #include "compile_tools.h"
1.4 paf 15: #include "pa_exception.h"
1.1 paf 16:
17: #include <stdio.h>
18:
19: extern int yydebug;
20: extern int yyparse (void *);
21:
1.29 paf 22: VStateless_class& Request::real_compile(COMPILE_PARAMS) {
1.7 paf 23: // prepare to parse
1.1 paf 24: struct parse_control pc;
1.10 paf 25:
1.7 paf 26: // input
1.10 paf 27: pc.pool=&pool();
1.18 paf 28: pc.request=this;
1.29 paf 29: VStateless_class *cclass;
1.27 paf 30: if(aclass) // we were told the class to compile to?
1.28 paf 31: cclass=aclass; // yes, remember it [used in ^process]
1.27 paf 32: else if(name) { // we were told the name of compiled class?
1.20 paf 33: // yes. create it
1.27 paf 34: cclass=NEW VClass(pool());
1.20 paf 35: // defaulting base. may change with @BASE
1.37 parser 36: // dont use ?: for there would be getting & of temp object
1.34 paf 37: if(base_class)
38: cclass->set_base(*base_class);
1.27 paf 39: classes().put(*name, cclass);
40: cclass->set_name(*name);
1.20 paf 41: } else
1.35 paf 42: cclass=&OP; // until changed with @CLASS would consider operators loading
1.27 paf 43: pc.cclass=cclass;
1.9 paf 44:
1.1 paf 45: pc.source=source;
46: #ifndef NO_STRING_ORIGIN
47: pc.file=file;
1.7 paf 48: pc.line=pc.col=0;
1.1 paf 49: #endif
1.7 paf 50: // initialise state
1.44 parser 51: pc.trim_bof=true;
1.1 paf 52: pc.pending_state=0;
1.13 paf 53: pc.string=NEW String(pool());
1.1 paf 54: pc.ls=LS_USER;
55: pc.sp=0;
1.46 parser 56: pc.object_constructor_allowed=false;
1.7 paf 57:
1.12 paf 58: // parse=compile!
1.48 parser 59: //yydebug=1;
1.10 paf 60: if(yyparse(&pc)) { // error?
1.15 paf 61: if(pc.col==0) { // expecting something after EOL means they've expected it BEFORE
62: // step back. -1 col means EOL
1.8 paf 63: pc.line--;
1.16 paf 64: pc.col=-1;
65: }
1.51 ! parser 66: throw Exception(0,0,
1.6 paf 67: 0,
1.47 parser 68: #ifndef NO_STRING_ORIGIN
69: "%s(%d:%d): "
70: #endif
71: "%s",
72: #ifndef NO_STRING_ORIGIN
73: file, 1+pc.line, pc.col,
74: #endif
75: pc.error);
1.8 paf 76: }
1.7 paf 77:
78: // result
1.27 paf 79: return *pc.cclass;
1.1 paf 80: }
E-mail: