|
|
| version 1.3, 2001/02/21 06:21:19 | version 1.26, 2001/03/11 12:04:44 |
|---|---|
| Line 1 | Line 1 |
| /* | /* |
| $Id$ | Parser |
| Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) | |
| Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf) | |
| $Id$ | |
| */ | */ |
| #include "pa_request.h" | |
| #include "pa_string.h" | #include "pa_string.h" |
| #include "pa_array.h" | #include "pa_array.h" |
| #include "code.h" | #include "code.h" |
| #include "compile_tools.h" | #include "compile_tools.h" |
| #include "compile.h" | #include "pa_exception.h" |
| #include <stdio.h> | #include <stdio.h> |
| extern int yydebug; | extern int yydebug; |
| extern int yyparse (void *); | extern int yyparse (void *); |
| Array *real_compile(COMPILE_PARAMS) { | VClass& Request::real_compile(COMPILE_PARAMS) { |
| if(!source) | // prepare to parse |
| return 0; | |
| yydebug=1; | |
| struct parse_control pc; | struct parse_control pc; |
| /* input */ | |
| pc.pool=pool; | // input |
| pc.pool=&pool(); | |
| pc.request=this; | |
| VClass *vclass; | |
| if(name) { // we were told the name of compiled class? | |
| // yes. create it | |
| vclass=NEW VClass(pool()); | |
| // defaulting base. may change with @BASE | |
| vclass->set_base(base_class?*base_class:root_class); | |
| // append to request's classes | |
| classes_array()+=vclass; | |
| classes().put(*name, vclass); | |
| vclass->set_name(*name); | |
| } else | |
| vclass=&root_class; // until changed with @CLASS would consider operators loading | |
| pc.vclass=vclass; | |
| pc.source=source; | pc.source=source; |
| #ifndef NO_STRING_ORIGIN | #ifndef NO_STRING_ORIGIN |
| pc.file=file; | pc.file=file; |
| pc.line=1; | pc.line=pc.col=0; |
| #endif | #endif |
| /* state to initial */ | // initialise state |
| pc.pending_state=0; | pc.pending_state=0; |
| pc.string=new(*pool) String(*pool); | pc.string=NEW String(pool()); |
| pc.ls=LS_USER; | pc.ls=LS_USER; |
| pc.sp=0; | pc.sp=0; |
| /* parse! */ | |
| int parse_error=yyparse(&pc); | // parse=compile! |
| /* result */ | // yydebug=1; |
| return parse_error?0:static_cast<Array *>(pc.result); | if(yyparse(&pc)) { // error? |
| if(pc.col==0) { // expecting something after EOL means they've expected it BEFORE | |
| // step back. -1 col means EOL | |
| pc.line--; | |
| pc.col=-1; | |
| } | |
| THROW(0,0, | |
| 0, | |
| "%s(%d:%d): %s", file, 1+pc.line, pc.col, pc.error); | |
| } | |
| // result | |
| return *pc.vclass; | |
| } | } |