00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00034 %{
00035
00037 using namespace std;
00038
00039 #include <iostream>
00040 #include <vector>
00041 #include <cstdio>
00042 #include <utility>
00043 #include <list>
00044 #include <math.h>
00045 #include <sstream>
00046 #include "streammanager.h"
00047 #include "debug.h"
00048 #include "expression.h"
00049 #include "docexpression.h"
00050 #include "commentexpression.h"
00051 #include "emptyexpression.h"
00052 #include "constexpression.h"
00053 #include "stringconstexpression.h"
00054 #include "numericconstexpression.h"
00055 #include "sequenceexpression.h"
00056 #include "forexpression.h"
00057 #include "varstepexpression.h"
00058 #include "varexpression.h"
00059 #include "nodeconstructexpression.h"
00060 #include "ifexpression.h"
00061 #include "whereexpression.h"
00062 #include "signoffexpression.h"
00063 #include "operandexpression.h"
00064 #include "condexpression.h"
00065 #include "andcondexpression.h"
00066 #include "orcondexpression.h"
00067 #include "notcondexpression.h"
00068 #include "existscondexpression.h"
00069 #include "emptycondexpression.h"
00070 #include "varstepcondexpression.h"
00071 #include "condoperandexpression.h"
00072 #include "truecondexpression.h"
00073 #include "falsecondexpression.h"
00074 #include "pathexpression.h"
00075 #include "pathsteptagexpression.h"
00076 #include "pathstepstarexpression.h"
00077 #include "pathstepnodeexpression.h"
00078 #include "pathsteptextexpression.h"
00079 #include "aggregatefunctexpression.h"
00080 #include "aggregatefunctsumexpression.h"
00081 #include "aggregatefunctavgexpression.h"
00082 #include "aggregatefunctminexpression.h"
00083 #include "aggregatefunctmaxexpression.h"
00084 #include "aggregatefunctcountexpression.h"
00085 #include "aggregatefunctstddevsampexpression.h"
00086 #include "aggregatefunctstddevpopexpression.h"
00087 #include "aggregatefunctvarsampexpression.h"
00088 #include "aggregatefunctvarpopexpression.h"
00089 #include "aggregatefunctmedianexpression.h"
00090 #include "roundingexpression.h"
00091 #include "functabsexpression.h"
00092 #include "functceilingexpression.h"
00093 #include "functcoverexpression.h"
00094 #include "functfloorexpression.h"
00095 #include "functroundexpression.h"
00096 #include "functroundhalftoevenexpression.h"
00097 #include "functtruncateexpression.h"
00098 #include "typeenums.h"
00099 #include "parseexception.h"
00100 #include "varname.h"
00101 #include "miscfunctions.h"
00102
00103
00104 #ifdef DBG_YACC
00105
00109 #define YYDEBUG 1
00110
00114
00115 #endif
00116
00117
00122 extern FILE* yyin;
00123
00128 DocExpression* doc;
00129
00137 int parse_query(DocExpression* _doc);
00138
00144 int yylex();
00145
00151 int yylex_destroy();
00152
00158 int yyparse();
00159
00166 extern void yyerror(const char *text);
00167
00172 Expression* parsed_query;
00173
00178 PathExpression* p;
00179
00184 typedef list< pair<VarExpression*, Expression*> > var_list_type;
00185
00193 Expression* make_for_expression(var_list_type* var_list, Expression* return_expr);
00194
00202 void ensure_wellformedness(const char* start_tag, const char* end_tag);
00203
00204 %}
00205
00206 %left OR
00207 %left AND
00208 %right NOT
00209
00210 %union
00211 {
00212 unsigned tok;
00213 unsigned ct;
00214 char* str;
00215 Expression* query;
00216 PathExpression* path;
00217 PathStepExpression* pathstep;
00218 VarExpression* varexpr;
00219 ConstExpression* constexpr;
00220 CondExpression* condexpr;
00221 OperandExpression* operandexpr;
00222 VarStepExpression* varstep;
00223 AggregateFunctExpression* aggfunct;
00224 RoundingExpression* rounding;
00225 COMP_TYPE comptype;
00226 var_list_type* varlist;
00227 }
00228
00229 %token SLASH DSLASH NT_STAR AND OR EXISTS EMPTY NOT XTRUE XFALSE
00230 %token CHILD DESCENDANT
00231 %token FOR IN XRETURN IF THEN ELSE WHERE
00232 %token RELOP_LT RELOP_LEQ RELOP_EQ RELOP_GT RELOP_GEQ RELOP_NEQ
00233 %token VAR_SIGN LTSLASH GTSLASH
00234 %token STRINGCONST NUMERICCONST QNAME VARNAME
00235 %token COMMA CBOPEN CBCLOSE BOPEN BCLOSE
00236 %token ELEMENTCONTENT XP_TEXT XP_NODE
00237 %token SUM AVG MIN MAX COUNT STDDEV_SAMP STDDEV_POP VAR_SAMP VAR_POP MEDIAN
00238 %token ABS CEILING COVER FLOOR ROUND ROUNDHALFTOEVEN TRUNCATE
00239 %token COMMENT_START COMMENTCONTENT
00240 %token DOC
00241
00242 %type <query> Query VarExpr FWRExpr ReturnQExpr QExpr QExprSingle IfExpr
00243 %type <query> NestedXMLExpr ElementContents XMLExpr
00244
00245 %type <str> COMMENTCONTENT STRINGCONST NUMERICCONST QNAME VARNAME ELEMENTCONTENT QName
00246 %type <str> StartTag EndTag BachelorTag
00247
00248 %type <varexpr> VarRef
00249 %type <path> PathExpr
00250 %type <pathstep> PathStepExpr NodeTest
00251 %type <constexpr> StringConst NumericConst
00252 %type <condexpr> Condition ComparisonExpr WhereClause
00253 %type <operandexpr> OperandExpr
00254 %type <varstep> VarAxisExpr
00255 %type <aggfunct> AggregateFunct
00256 %type <rounding> Rounding
00257 %type <comptype> RelOp
00258 %type <varlist> ExprAppendix ForClause
00259
00260 %%
00261
00262 start: Query {
00263 parsed_query = $1;
00264
00265 vector<unsigned> x;
00266 x.push_back(TAGID_ROOT);
00267 vector<unsigned> introduced_vars;
00268 introduced_vars.push_back(VarName::getInstance()->insertVarname(ROOTVAR));
00269 vector<unsigned> violating_vars;
00270 parsed_query->scopeCheck(x,introduced_vars,violating_vars);
00271
00272 if (violating_vars.size()>0) {
00273 std::ostringstream os;
00274 os << "Scope Check Failed For The Following Variable(s): ";
00275 for (unsigned i=0;i<violating_vars.size();i++) {
00276 if (i>0) os << ", ";
00277 os << "$" << VarName::getInstance()->getVarname(violating_vars[i]);
00278 }
00279 yyerror(os.str().c_str());
00280 }
00281 }
00282 ;
00283
00284 Query :
00285
00286
00287 {
00288 SequenceExpression* seq = new SequenceExpression(new CommentExpression(NULL), doc);
00289 seq->insertExp(new EmptyExpression());
00290 $$ = seq;
00291 }
00292
00293 | XMLExpr
00294 {
00295 SequenceExpression* seq = new SequenceExpression(new CommentExpression(NULL), doc);
00296 seq->insertExp($1);
00297 $$ = seq;
00298 }
00299
00300 | COMMENT_START COMMENTCONTENT
00301 {
00302 SequenceExpression* seq = new SequenceExpression(new CommentExpression($2), doc);
00303 seq->insertExp(new EmptyExpression());
00304 $$ = seq;
00305 }
00306
00307 | COMMENT_START COMMENTCONTENT XMLExpr
00308 {
00309 SequenceExpression* seq = new SequenceExpression(new CommentExpression($2), doc);
00310 seq->insertExp($3);
00311 $$ = seq;
00312 }
00313 ;
00314
00315 StartTag :
00316
00317 RELOP_LT QName RELOP_GT
00318 {
00319 $$ = $2;
00320 }
00321 ;
00322
00323 EndTag :
00324
00325 LTSLASH QName RELOP_GT
00326 {
00327 $$ = $2;
00328 }
00329 ;
00330
00331 BachelorTag :
00332
00333 RELOP_LT QName GTSLASH
00334 {
00335 $$ = $2;
00336 }
00337 ;
00338
00339 XMLExpr :
00340
00341 StartTag NestedXMLExpr EndTag
00342 {
00343 ensure_wellformedness($1, $3);
00344 $$ = new NodeConstructExpression($1, $2);
00345 free((char*)$1);
00346 free((char*)$3);
00347 }
00348
00349 | BachelorTag
00350 {
00351 $$ = new NodeConstructExpression($1, new EmptyExpression());
00352 free((char*)$1);
00353 }
00354
00355 | StartTag EndTag
00356 {
00357 $$ = new NodeConstructExpression($1, new EmptyExpression());
00358 free((char*)$1);
00359 free((char*)$2);
00360 }
00361 ;
00362
00363 NestedXMLExpr :
00364
00365 CBOPEN QExpr CBCLOSE
00366 {
00367 $$ = $2;
00368 }
00369
00370 | ElementContents
00371 {
00372 $$ = $1;
00373 }
00374
00375 | XMLExpr
00376 {
00377 $$ = $1;
00378 }
00379
00380 | NestedXMLExpr NestedXMLExpr
00381 {
00382 $$ = new SequenceExpression($1, $2);
00383 }
00384 ;
00385
00386 ElementContents :
00387
00388 ELEMENTCONTENT
00389 {
00390 $$ = new StringConstExpression($1);
00391 }
00392 ;
00393
00394 QExpr :
00395
00396 ReturnQExpr
00397 {
00398 $$ = $1;
00399 }
00400
00401 | QExpr COMMA QExpr
00402 {
00403 $$ = new SequenceExpression($1, $3);
00404 }
00405 ;
00406
00407 QExprSingle :
00408
00409 StringConst
00410 {
00411 $$ = $1;
00412 }
00413
00414 | NumericConst
00415 {
00416 $$ = $1;
00417 }
00418
00419 | FWRExpr
00420 {
00421 $$ = $1;
00422 }
00423
00424 | IfExpr
00425 {
00426 $$ = $1;
00427 }
00428
00429 | VarExpr
00430 {
00431 $$ = $1;
00432 }
00433
00434 | AggregateFunct
00435 {
00436 $$ = $1;
00437 }
00438
00439 | Rounding
00440 {
00441 $$ = $1;
00442 }
00443
00444 | NestedXMLExpr
00445 {
00446 $$ = $1;
00447 }
00448 ;
00449
00450 StringConst :
00451
00452 STRINGCONST
00453 {
00454 $$ = new StringConstExpression($1);
00455 }
00456 ;
00457
00458 NumericConst :
00459
00460 NUMERICCONST
00461 {
00462 $$ = new NumericConstExpression($1);
00463 }
00464
00465 FWRExpr :
00466
00467 ForClause XRETURN ReturnQExpr
00468 {
00469 $$ = make_for_expression($1, $3);
00470 }
00471
00472 | ForClause WhereClause XRETURN ReturnQExpr
00473 {
00474 $$ = make_for_expression($1, new WhereExpression($2, $4));
00475 }
00476 ;
00477
00478 ReturnQExpr :
00479
00480 QExprSingle
00481 {
00482 $$ = $1;
00483 }
00484
00485 | BOPEN QExpr BCLOSE
00486 {
00487 $$ = $2;
00488 }
00489
00490 | BOPEN BCLOSE
00491 {
00492 $$ = new EmptyExpression();
00493 };
00494
00495 ForClause :
00496
00497 FOR VarRef IN VarExpr ExprAppendix
00498 {
00499 if ($4->getType()==et_var) {
00500 $5->push_back(pair<VarExpression*, Expression*>($2, (VarExpression*) $4));
00501 } else {
00502 $5->push_back(pair<VarExpression*, Expression*>($2, (VarStepExpression*) $4));
00503 }
00504 $$ = $5;
00505 }
00506 ;
00507
00508 WhereClause:
00509
00510 WHERE Condition
00511 {
00512 $$ = $2;
00513 }
00514 ;
00515
00516 Condition :
00517
00518 VarExpr
00519 {
00520 if ($1->getType()==et_var) {
00521 $$ = new VarstepCondExpression((VarExpression*) $1);
00522 } else {
00523 $$ = new VarstepCondExpression((VarStepExpression*) $1);
00524 }
00525 }
00526
00527 | XTRUE
00528 {
00529 $$ = new TrueCondExpression();
00530 }
00531
00532 | XFALSE
00533 {
00534 $$ = new FalseCondExpression();
00535 }
00536
00537 | EXISTS BOPEN VarExpr BCLOSE
00538 {
00539 if ($3->getType()==et_var) {
00540 $$ = new ExistsCondExpression((VarExpression*) $3);
00541 } else {
00542 $$ = new ExistsCondExpression((VarStepExpression*) $3);
00543 }
00544 }
00545
00546 | EMPTY BOPEN VarExpr BCLOSE
00547 {
00548 if ($3->getType()==et_var) {
00549 $$ = new EmptyCondExpression((VarExpression*) $3);
00550 } else {
00551 $$ = new EmptyCondExpression((VarStepExpression*) $3);
00552 }
00553 }
00554
00555 | NOT Condition
00556 {
00557 $$ = new NotCondExpression($2);
00558 }
00559
00560 | BOPEN Condition BCLOSE
00561 {
00562 $$ = $2;
00563 }
00564
00565 | Condition AND Condition
00566 {
00567 $$ = new AndCondExpression($1, $3);
00568 }
00569
00570 | Condition OR Condition
00571 {
00572 $$ = new OrCondExpression($1, $3);
00573 }
00574
00575 | ComparisonExpr
00576 {
00577 $$ = $1;
00578 }
00579 ;
00580
00581 ComparisonExpr :
00582
00583 OperandExpr RelOp OperandExpr
00584 {
00585 EXP_TYPE lop_type = $1->getOperandType();
00586 EXP_TYPE rop_type = $3->getOperandType();
00587
00588 bool is_lop_aggfunct = lop_type==et_operandaggregatefunct;
00589
00590 bool is_rop_aggfunct = rop_type==et_operandaggregatefunct;
00591
00592 bool is_lop_rounding = lop_type==et_operandrounding;
00593
00594 bool is_rop_rounding = rop_type==et_operandrounding;
00595
00596 lop_type = $1->getType();
00597 rop_type = $3->getType();
00598
00599 bool is_lop_string = lop_type==et_stringconst;
00600
00601 bool is_rop_string = rop_type==et_stringconst;
00602
00603 bool is_lop_numeric = lop_type==et_numericconst;
00604
00605 bool is_rop_numeric = rop_type==et_numericconst;
00606
00607 if (is_lop_aggfunct && is_rop_string ||
00608 is_rop_aggfunct && is_lop_string ||
00609 is_lop_rounding && is_rop_string ||
00610 is_rop_rounding && is_lop_string ||
00611 is_lop_string && is_rop_numeric ||
00612 is_rop_string && is_lop_numeric) {
00613 yyerror("Cannot Compare Numeric To String Or String To Numeric");
00614 }
00615
00616 $$ = new CondOperandExpression($1, $2, $3);
00617 }
00618 ;
00619
00620 OperandExpr :
00621
00622 VarExpr
00623 {
00624 $$ = (OperandExpression*)$1;
00625 }
00626
00627 | AggregateFunct
00628 {
00629 $$ = (OperandExpression*)$1;
00630 }
00631
00632 | Rounding
00633 {
00634 $$ = (OperandExpression*)$1;
00635 }
00636
00637 | StringConst
00638 {
00639 $$ = (OperandExpression*)$1;
00640 }
00641
00642 | NumericConst
00643 {
00644 $$ = (OperandExpression*)$1;
00645 }
00646 ;
00647
00648 ExprAppendix :
00649
00650
00651 {
00652 $$ = new var_list_type();
00653 }
00654
00655 | COMMA VarRef IN VarExpr ExprAppendix
00656 {
00657 if ($4->getType()==et_var) {
00658 $5->push_back( pair<VarExpression*, Expression*>($2, (VarExpression*) $4));
00659 } else {
00660 $5->push_back( pair<VarExpression*, Expression*>($2, (VarStepExpression*) $4));
00661 }
00662 $$ = $5;
00663 }
00664 ;
00665
00666 RelOp :
00667
00668 RELOP_EQ
00669 {
00670 $$ = ct_eq;
00671 }
00672
00673 | RELOP_LT
00674 {
00675 $$ = ct_lt;
00676 }
00677
00678 | RELOP_GT
00679 {
00680 $$ = ct_gt;
00681 }
00682
00683 | RELOP_GEQ
00684 {
00685 $$ = ct_geq;
00686 }
00687
00688 | RELOP_LEQ
00689 {
00690 $$ = ct_leq;
00691 }
00692
00693 | RELOP_NEQ
00694 {
00695 $$ = ct_neq;
00696 }
00697 ;
00698
00699 AggregateFunct :
00700
00701 SUM BOPEN VarExpr BCLOSE
00702 {
00703 if ($3->getType()==et_var) {
00704 $$ = new AggregateFunctSumExpression((VarExpression*) $3);
00705 } else {
00706 $$ = new AggregateFunctSumExpression((VarStepExpression*) $3);
00707 }
00708 }
00709
00710 | AVG BOPEN VarExpr BCLOSE
00711 {
00712 if ($3->getType()==et_var) {
00713 $$ = new AggregateFunctAvgExpression((VarExpression*) $3);
00714 } else {
00715 $$ = new AggregateFunctAvgExpression((VarStepExpression*) $3);
00716 }
00717 }
00718
00719 | MIN BOPEN VarExpr BCLOSE
00720 {
00721 if ($3->getType()==et_var) {
00722 $$ = new AggregateFunctMinExpression((VarExpression*) $3);
00723 } else {
00724 $$ = new AggregateFunctMinExpression((VarStepExpression*) $3);
00725 }
00726 }
00727
00728 | MAX BOPEN VarExpr BCLOSE
00729 {
00730 if ($3->getType()==et_var) {
00731 $$ = new AggregateFunctMaxExpression((VarExpression*) $3);
00732 } else {
00733 $$ = new AggregateFunctMaxExpression((VarStepExpression*) $3);
00734 }
00735 }
00736
00737 | COUNT BOPEN VarExpr BCLOSE
00738 {
00739 if ($3->getType()==et_var) {
00740 $$ = new AggregateFunctCountExpression((VarExpression*) $3);
00741 } else {
00742 $$ = new AggregateFunctCountExpression((VarStepExpression*) $3);
00743 }
00744 }
00745
00746 | STDDEV_SAMP BOPEN VarExpr BCLOSE
00747 {
00748 if ($3->getType()==et_var) {
00749 $$ = new AggregateFunctStdDevSampExpression((VarExpression*) $3);
00750 } else {
00751 $$ = new AggregateFunctStdDevSampExpression((VarStepExpression*) $3);
00752 }
00753 }
00754
00755 | STDDEV_POP BOPEN VarExpr BCLOSE
00756 {
00757 if ($3->getType()==et_var) {
00758 $$ = new AggregateFunctStdDevPopExpression((VarExpression*) $3);
00759 } else {
00760 $$ = new AggregateFunctStdDevPopExpression((VarStepExpression*) $3);
00761 }
00762 }
00763
00764 | VAR_SAMP BOPEN VarExpr BCLOSE
00765 {
00766 if ($3->getType()==et_var) {
00767 $$ = new AggregateFunctVarSampExpression((VarExpression*) $3);
00768 } else {
00769 $$ = new AggregateFunctVarSampExpression((VarStepExpression*) $3);
00770 }
00771 }
00772
00773 | VAR_POP BOPEN VarExpr BCLOSE
00774 {
00775 if ($3->getType()==et_var) {
00776 $$ = new AggregateFunctVarPopExpression((VarExpression*) $3);
00777 } else {
00778 $$ = new AggregateFunctVarPopExpression((VarStepExpression*) $3);
00779 }
00780 }
00781
00782 | MEDIAN BOPEN VarExpr BCLOSE
00783 {
00784 if ($3->getType()==et_var) {
00785 $$ = new AggregateFunctMedianExpression((VarExpression*) $3);
00786 } else {
00787 $$ = new AggregateFunctMedianExpression((VarStepExpression*) $3);
00788 }
00789 }
00790 ;
00791
00792 Rounding :
00793
00794 ABS BOPEN AggregateFunct BCLOSE
00795 {
00796 $$ = new FunctAbsExpression((AggregateFunctExpression*) $3);
00797 }
00798
00799 | CEILING BOPEN AggregateFunct BCLOSE
00800 {
00801 $$ = new FunctCeilingExpression((AggregateFunctExpression*) $3);
00802 }
00803
00804 | COVER BOPEN AggregateFunct BCLOSE
00805 {
00806 $$ = new FunctCoverExpression((AggregateFunctExpression*) $3);
00807 }
00808
00809 | FLOOR BOPEN AggregateFunct BCLOSE
00810 {
00811 $$ = new FunctFloorExpression((AggregateFunctExpression*) $3);
00812 }
00813
00814 | ROUND BOPEN AggregateFunct BCLOSE
00815 {
00816 $$ = new FunctRoundExpression((AggregateFunctExpression*) $3);
00817 }
00818
00819 | ROUNDHALFTOEVEN BOPEN AggregateFunct BCLOSE
00820 {
00821 $$ = new FunctRoundHalfToEvenExpression((AggregateFunctExpression*) $3);
00822 }
00823
00824 | TRUNCATE BOPEN AggregateFunct BCLOSE
00825 {
00826 $$ = new FunctTruncateExpression((AggregateFunctExpression*) $3);
00827 }
00828 ;
00829
00830 PathStepExpr :
00831
00832 ChildAxis NodeTest
00833 {
00834 p = new PathExpression();
00835 p->addPathStep($2);
00836 }
00837
00838 | DescendantAxis NodeTest
00839 {
00840 p = new PathExpression();
00841 PathStepExpression* ps = $2;
00842 ps->setAxisType(at_descendant);
00843 p->addPathStep(ps);
00844 }
00845
00846 | PathStepExpr ChildAxis NodeTest
00847 {
00848 p->addPathStep($3);
00849 }
00850
00851 | PathStepExpr DescendantAxis NodeTest
00852 {
00853 PathStepExpression* ps = $3;
00854 ps->setAxisType(at_descendant);
00855 p->addPathStep(ps);
00856 }
00857 ;
00858
00859 ChildAxis :
00860
00861 SLASH
00862
00863 | SLASH CHILD
00864 ;
00865
00866 DescendantAxis :
00867
00868 DSLASH
00869
00870 | SLASH DESCENDANT
00871 ;
00872
00873 NodeTest:
00874
00875 XP_NODE
00876 {
00877 $$ = new PathStepNodeExpression();
00878 }
00879
00880 | XP_TEXT
00881 {
00882 $$ = new PathStepTextExpression();
00883 }
00884
00885 | NT_STAR
00886 {
00887 $$ = new PathStepStarExpression();
00888 }
00889
00890 | QName
00891 {
00892 $$ = new PathStepTagExpression($1);
00893 free((char*)$1);
00894 }
00895 ;
00896
00897 QName :
00898
00899 QNAME
00900 {
00901 $$ = $1;
00902 }
00903 ;
00904
00905 PathExpr :
00906
00907 PathStepExpr
00908 {
00909 $$ = p;
00910 }
00911 ;
00912
00913 IfExpr :
00914
00915 IF BOPEN Condition BCLOSE THEN ReturnQExpr ELSE ReturnQExpr
00916 {
00917 $$ = new IfExpression($3, $6, $8);
00918 }
00919 ;
00920
00921 VarExpr:
00922
00923 DOC BOPEN STRINGCONST BCLOSE
00924 {
00925 if (doc->isEmptyPath()) {
00926 doc->setPath($3);
00927 } else {
00928 if (!doc->isPathEqualTo($3)) {
00929 delete[] $3;
00930 yyerror("DocExpression: Paths Not Equal");
00931 }
00932 delete[] $3;
00933 }
00934 $$ = new VarExpression();
00935 }
00936
00937 | BOPEN SLASH BCLOSE
00938 {
00939 $$ = new VarExpression();
00940 }
00941
00942 | SLASH
00943 {
00944 $$ = new VarExpression();
00945 }
00946
00947 | VarRef
00948 {
00949 $$ = $1;
00950 }
00951
00952 | VarAxisExpr
00953 {
00954 $$ = $1;
00955 }
00956 ;
00957
00958 VarRef :
00959
00960 VAR_SIGN VARNAME
00961 {
00962 $$ = new VarExpression($2);
00963 }
00964 ;
00965
00966 VarAxisExpr :
00967
00968 DOC BOPEN STRINGCONST BCLOSE PathExpr
00969 {
00970 if (doc->isEmptyPath()) {
00971 doc->setPath($3);
00972 } else {
00973 if (!doc->isPathEqualTo($3)) {
00974 delete[] $3;
00975 yyerror("DocExpression: Paths Not Equal");
00976 }
00977 delete[] $3;
00978 }
00979 VarExpression* var = new VarExpression();
00980 $$ = new VarStepExpression(var->getId(), $5);
00981 delete var;
00982 }
00983
00984 | VarRef PathExpr
00985 {
00986 $$ = new VarStepExpression($1->getId(), $2);
00987 delete $1;
00988 }
00989
00990 | PathExpr
00991 {
00992 VarExpression* var = new VarExpression();
00993 $$ = new VarStepExpression(var->getId(), $1);
00994 delete var;
00995 }
00996 ;
00997
00998 %%
00999
01007 int parse_query(DocExpression* _doc) {
01008 doc = _doc;
01009 InputStream* query_istream = StreamManager::getInstance()->getQueryInputStream();
01010
01011 yyin=query_istream->getParserStream();
01012
01013
01014 int ret=yyparse();
01015
01016 #if defined(LINUX) || defined(linux) || defined(_LINUX) || defined(_linux) || defined(__LINUX__) || defined(__linux__)
01017 yylex_destroy();
01018 #endif
01019
01020 return ret;
01021 }
01022
01030 Expression* make_for_expression(var_list_type* var_list, Expression* sub_expression) {
01031 var_list_type::const_iterator it;
01032
01033 for(it=var_list->begin(); it!=var_list->end(); it++) {
01034 if (it->second->getType()==et_var) {
01035 sub_expression = new ForExpression(it->first, (VarExpression*) it->second, sub_expression);
01036 } else {
01037 sub_expression = new ForExpression(it->first, (VarStepExpression*) it->second, sub_expression);
01038 }
01039 }
01040 delete var_list;
01041
01042 return sub_expression;
01043 }
01044
01052 void ensure_wellformedness(const char* start_tag, const char* end_tag) {
01053 if(strcmp(start_tag, end_tag)!=0) {
01054 std::ostringstream o;
01055 o << "Not Well-Formed <" << start_tag << ">...<" << end_tag << "> XML";
01056 yyerror(o.str().c_str());
01057 }
01058 }