source: XIOS/dev/dev_olga/src/parse_expr/yacc_parser.yacc @ 1243

Last change on this file since 1243 was 1158, checked in by oabramkina, 7 years ago

Two server levels: merging with trunk r1137.
There are bugs.

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
File size: 7.6 KB
RevLine 
[458]1%{
[642]2#include "filter_expr_node.hpp"
[458]3#include <string>
4#include <iostream>
[493]5#include "exception.hpp"
6
[642]7using namespace std;
8using namespace xios;
[493]9
[458]10extern "C"
11{
12  int yyparse(void);
13  int yylex(void);
[642]14  int yyerror(const char *s);
[458]15}
16
[642]17  IFilterExprNode* parsed;
18  std::string globalInputText;
19  size_t globalReadOffset = 0;
20
21  int readInputForLexer(char* buffer, size_t* numBytesRead, size_t maxBytesToRead)
22  {
23    size_t numBytesToRead = maxBytesToRead;
24    size_t bytesRemaining = globalInputText.length()-globalReadOffset;
25    size_t i;
26    if (numBytesToRead > bytesRemaining) numBytesToRead = bytesRemaining;
27    for (i = 0; i < numBytesToRead; i++) buffer[i] = globalInputText.c_str()[globalReadOffset + i];
[458]28    *numBytesRead = numBytesToRead;
29    globalReadOffset += numBytesToRead;
30    return 0;
[642]31  }
[458]32%}
33
34%union
35{
[642]36  std::string* str;                /* symbol table index */
37  xios::IScalarExprNode* scalarNode;
38  xios::IFilterExprNode* filterNode;
[458]39};
40
41%token <str> NUMBER
[642]42%token <str> VAR ID AVERAGE
[458]43%token PLUS MINUS TIMES DIVIDE POWER
[1158]44%token EQ LT GT LE GE NE
[458]45%token LEFT_PARENTHESIS RIGHT_PARENTHESIS
[1158]46%token QUESTION_MARK COLON
[458]47%token <str> END
48
[1158]49%nonassoc QUESTION_MARK COLON
50%left EQ LT GT LE GE NE
[458]51%left PLUS MINUS
52%left TIMES DIVIDE
53%nonassoc NEG
54%right POWER
55
[642]56%type <scalarNode> Expression
57%type <filterNode> Line Field_expr
[458]58%start Line
59%%
60
61
62Line:
[642]63     END            { /* Nothing to do */ }
64   | Field_expr END { parsed = $1; }
65  ;
[458]66
67Expression:
[642]68            NUMBER { $$ = new CScalarValExprNode(*$1); delete $1; }
69          | VAR    { $$ = new CScalarVarExprNode(*$1); delete $1; }
70          | Expression PLUS Expression   { $$ = new CScalarBinaryOpExprNode($1, "add", $3); }
71          | Expression MINUS Expression  { $$ = new CScalarBinaryOpExprNode($1, "minus", $3); }
72          | Expression TIMES Expression  { $$ = new CScalarBinaryOpExprNode($1, "mult", $3); }
73          | Expression DIVIDE Expression { $$ = new CScalarBinaryOpExprNode($1, "div", $3); }
74          | MINUS Expression %prec NEG   { $$ = new CScalarUnaryOpExprNode("neg", $2); }
75          | Expression POWER Expression  { $$ = new CScalarBinaryOpExprNode($1, "pow", $3); }
[728]76          | Expression EQ Expression  { $$ = new CScalarBinaryOpExprNode($1, "eq", $3); }
77          | Expression LT Expression  { $$ = new CScalarBinaryOpExprNode($1, "lt", $3); }
78          | Expression GT Expression  { $$ = new CScalarBinaryOpExprNode($1, "gt", $3); }
79          | Expression LE Expression  { $$ = new CScalarBinaryOpExprNode($1, "le", $3); }
80          | Expression GE Expression  { $$ = new CScalarBinaryOpExprNode($1, "ge", $3); }
[1158]81          | Expression NE Expression  { $$ = new CScalarBinaryOpExprNode($1, "ne", $3); }
82          | Expression QUESTION_MARK Expression COLON Expression {$$ = new CScalarTernaryOpExprNode($1, "cond", $3, $5);}
[642]83          | LEFT_PARENTHESIS Expression RIGHT_PARENTHESIS    { $$ = $2; }
84          | ID LEFT_PARENTHESIS Expression RIGHT_PARENTHESIS { $$ = new CScalarUnaryOpExprNode(*$1, $3); delete $1; }
[458]85          ;
86
87Field_expr:
[642]88            ID      { $$ = new CFilterFieldExprNode(*$1); delete $1; }
[643]89          | AVERAGE { $$ = new CFilterTemporalFieldExprNode(*$1); delete $1; }
[642]90          | Field_expr PLUS Field_expr   { $$ = new CFilterFieldFieldOpExprNode($1, "add", $3); }
91          | Field_expr MINUS Field_expr  { $$ = new CFilterFieldFieldOpExprNode($1, "minus", $3); }
92          | Field_expr TIMES Field_expr  { $$ = new CFilterFieldFieldOpExprNode($1, "mult", $3); }
93          | Field_expr DIVIDE Field_expr { $$ = new CFilterFieldFieldOpExprNode($1, "div", $3); }
94          | MINUS Field_expr %prec NEG   { $$ = new CFilterUnaryOpExprNode("neg", $2); }
95          | Field_expr POWER Field_expr  { $$ = new CFilterFieldFieldOpExprNode($1, "pow", $3); }
[728]96          | Field_expr EQ Field_expr { $$ = new CFilterFieldFieldOpExprNode($1, "eq", $3); }
97          | Field_expr LT Field_expr { $$ = new CFilterFieldFieldOpExprNode($1, "lt", $3); }
98          | Field_expr GT Field_expr { $$ = new CFilterFieldFieldOpExprNode($1, "gt", $3); }
99          | Field_expr LE Field_expr { $$ = new CFilterFieldFieldOpExprNode($1, "le", $3); }
100          | Field_expr GE Field_expr { $$ = new CFilterFieldFieldOpExprNode($1, "ge", $3); }
[1158]101          | Field_expr NE Field_expr { $$ = new CFilterFieldFieldOpExprNode($1, "ne", $3); }
[642]102          | LEFT_PARENTHESIS Field_expr RIGHT_PARENTHESIS       { $$ = $2; }
[1158]103          | Expression QUESTION_MARK Expression COLON Field_expr {$$ = new CFilterScalarScalarFieldOpExprNode($1, "cond",$3, $5);}
104          | Expression QUESTION_MARK Field_expr COLON Expression {$$ = new CFilterScalarFieldScalarOpExprNode($1, "cond",$3, $5);}
105          | Expression QUESTION_MARK Field_expr COLON Field_expr {$$ = new CFilterScalarFieldFieldOpExprNode($1, "cond",$3, $5);}
106          | Field_expr QUESTION_MARK Expression COLON Expression {$$ = new CFilterFieldScalarScalarOpExprNode($1, "cond",$3, $5);}
107          | Field_expr QUESTION_MARK Expression COLON Field_expr {$$ = new CFilterFieldScalarFieldOpExprNode($1, "cond",$3, $5);}
108          | Field_expr QUESTION_MARK Field_expr COLON Expression {$$ = new CFilterFieldFieldScalarOpExprNode($1, "cond",$3, $5);}
109          | Field_expr QUESTION_MARK Field_expr COLON Field_expr {$$ = new CFilterFieldFieldFieldOpExprNode($1, "cond",$3, $5);}
[642]110          | Field_expr PLUS Expression   { $$ = new CFilterFieldScalarOpExprNode($1, "add", $3); }
111          | Expression PLUS Field_expr   { $$ = new CFilterScalarFieldOpExprNode($1, "add", $3); }
112          | Field_expr MINUS Expression  { $$ = new CFilterFieldScalarOpExprNode($1, "minus", $3); }
113          | Expression MINUS Field_expr  { $$ = new CFilterScalarFieldOpExprNode($1, "minus", $3); }
114          | Field_expr TIMES Expression  { $$ = new CFilterFieldScalarOpExprNode($1, "mult", $3); }
115          | Expression TIMES Field_expr  { $$ = new CFilterScalarFieldOpExprNode($1, "mult", $3); }
116          | Field_expr DIVIDE Expression { $$ = new CFilterFieldScalarOpExprNode($1, "div", $3); }
117          | Expression DIVIDE Field_expr { $$ = new CFilterScalarFieldOpExprNode($1, "div", $3); }
118          | Field_expr POWER Expression  { $$ = new CFilterFieldScalarOpExprNode($1, "pow", $3); }
[728]119          | Field_expr EQ Expression { $$ = new CFilterFieldScalarOpExprNode($1, "eq", $3); }
120          | Expression EQ Field_expr { $$ = new CFilterScalarFieldOpExprNode($1, "eq", $3); }
121          | Field_expr LT Expression { $$ = new CFilterFieldScalarOpExprNode($1, "lt", $3); }
122          | Expression LT Field_expr { $$ = new CFilterScalarFieldOpExprNode($1, "lt", $3); }
123          | Field_expr GT Expression { $$ = new CFilterFieldScalarOpExprNode($1, "gt", $3); }
124          | Expression GT Field_expr { $$ = new CFilterScalarFieldOpExprNode($1, "gt", $3); }
125          | Field_expr LE Expression { $$ = new CFilterFieldScalarOpExprNode($1, "le", $3); }
126          | Expression LE Field_expr { $$ = new CFilterScalarFieldOpExprNode($1, "le", $3); }
127          | Field_expr GE Expression { $$ = new CFilterFieldScalarOpExprNode($1, "ge", $3); }
128          | Expression GE Field_expr { $$ = new CFilterScalarFieldOpExprNode($1, "ge", $3); }
[1158]129          | Field_expr NE Expression { $$ = new CFilterFieldScalarOpExprNode($1, "ne", $3); }
130          | Expression NE Field_expr { $$ = new CFilterScalarFieldOpExprNode($1, "ne", $3); }
[642]131          | ID LEFT_PARENTHESIS Field_expr RIGHT_PARENTHESIS { $$ = new CFilterUnaryOpExprNode(*$1, $3); delete $1; }
[458]132          ;
133%%
134
135extern "C"
136{
[642]137  int yyerror(const char *s)
[458]138  {
[642]139    ERROR("int yyerror(const char *s)", << "Parsing error: " << s << endl);
[458]140  }
141}
142
143namespace xios
144{
[642]145  IFilterExprNode* parseExpr(const string& strExpr)
[458]146  {
[642]147    globalInputText = strExpr;
148    globalReadOffset = 0;
[458]149    yyparse();
[642]150    return parsed;
[458]151  }
152}
153
154
Note: See TracBrowser for help on using the repository browser.