Warning, /graphics/kst-plot/src/libkstmath/eparse.y is written in an unsupported language. File is not indexed.

0001 
0002 %{
0003 #include <assert.h>
0004 #include <stdlib.h>
0005 #include <stdio.h>
0006 
0007 #include <objectstore.h>
0008 
0009 #include "enodefactory.h"
0010 
0011 #include "eparse-eh.h"
0012 extern int yylex(Kst::ObjectStore *store);
0013 void *ParsedEquation = 0L;
0014 
0015 %}
0016 
0017 %parse-param { Kst::ObjectStore *store }
0018 %lex-param { Kst::ObjectStore *store }
0019 
0020 %union {
0021                 char *data;
0022                 double number;
0023                 void *n; /* tree node */
0024                 char character;
0025            }
0026 
0027 
0028 %token T_NUMBER T_IDENTIFIER T_DATA T_OPENPAR T_CLOSEPAR T_COMMA T_INVALID
0029 
0030 %left <operator> T_LOR
0031 %left <operator> T_LAND
0032 %left <operator> T_OR
0033 %left <operator> T_AND
0034 %left <operator> T_EQ T_NE
0035 %left <operator> T_LT T_LE T_GT T_GE
0036 %left <operator> T_ADD T_SUBTRACT
0037 %left <operator> T_MULTIPLY T_DIVIDE T_MOD
0038 %left <operator> T_NOT
0039 %nonassoc U_SUBTRACT
0040 %right <operator> T_EXP
0041 
0042 %start WRAPPER
0043 
0044 %%
0045 
0046 WRAPPER         :       { $<n>$ = 0L; yyClearErrors(); ParsedEquation = 0L; } PRESTART
0047                         { $<n>$ = ParsedEquation = $<n>2;
0048                                 if (yyErrorCount() > 0) {
0049                                         DeleteNode($<n>$);
0050                                         $<n>$ = 0L;
0051                                         ParsedEquation = 0L;
0052                                         YYERROR;
0053                                 }
0054                         }
0055                 ;
0056 
0057 PRESTART        :       START
0058                         { $<n>$ = $<n>1; }
0059                 |       /**/
0060                         { $<n>$ = 0L; yyerror(store, EParseErrorEmpty); }
0061                 ;
0062 
0063 START           :       BOOLEAN_OR
0064                         { $<n>$ = $<n>1; }
0065                 ;
0066 
0067 BOOLEAN_OR      :       BOOLEAN_OR T_LOR BOOLEAN_AND
0068                         { $<n>$ = NewLogicalOr($<n>1, $<n>3); }
0069                 |       T_LOR error
0070                         { yyerror(store, EParseErrorTwoOperands); $<n>$ = 0L; }
0071                 |       BOOLEAN_AND
0072                         { $<n>$ = $<n>1; }
0073                 ;
0074 
0075 BOOLEAN_AND     :       BOOLEAN_AND T_LAND COMPARISON
0076                         { $<n>$ = NewLogicalAnd($<n>1, $<n>3); }
0077                 |       T_LAND error
0078                         { yyerror(store, EParseErrorTwoOperands); $<n>$ = 0L; }
0079                 |       COMPARISON
0080                         { $<n>$ = $<n>1; }
0081                 ;
0082 
0083 COMPARISON      :       COMPARISON T_LT EQUATION
0084                         { $<n>$ = NewLessThan($<n>1, $<n>3); }
0085                 |       COMPARISON T_LE EQUATION
0086                         { $<n>$ = NewLessThanEqual($<n>1, $<n>3); }
0087                 |       COMPARISON T_GT EQUATION
0088                         { $<n>$ = NewGreaterThan($<n>1, $<n>3); }
0089                 |       COMPARISON T_GE EQUATION
0090                         { $<n>$ = NewGreaterThanEqual($<n>1, $<n>3); }
0091                 |       COMPARISON T_EQ EQUATION
0092                         { $<n>$ = NewEqualTo($<n>1, $<n>3); }
0093                 |       COMPARISON T_NE EQUATION
0094                         { $<n>$ = NewNotEqualTo($<n>1, $<n>3); }
0095                 |       T_LT error
0096                         { yyerror(store, EParseErrorTwoOperands); $<n>$ = 0L; }
0097                 |       T_GT error
0098                         { yyerror(store, EParseErrorTwoOperands); $<n>$ = 0L; }
0099                 |       T_LE error
0100                         { yyerror(store, EParseErrorTwoOperands); $<n>$ = 0L; }
0101                 |       T_GE error
0102                         { yyerror(store, EParseErrorTwoOperands); $<n>$ = 0L; }
0103                 |       T_EQ error
0104                         { yyerror(store, EParseErrorTwoOperands); $<n>$ = 0L; }
0105                 |       T_NE error
0106                         { yyerror(store, EParseErrorTwoOperands); $<n>$ = 0L; }
0107                 |       EQUATION
0108                         { $<n>$ = $<n>1; }
0109                 ;
0110 
0111 EQUATION        :       EQUATION T_ADD TERM
0112                         { $<n>$ = NewAddition($<n>1, $<n>3); }
0113                 |       EQUATION T_SUBTRACT TERM 
0114                         { $<n>$ = NewSubtraction($<n>1, $<n>3); }
0115                 |       EQUATION T_OR TERM 
0116                         { $<n>$ = NewBitwiseOr($<n>1, $<n>3); }
0117                 |       EQUATION T_AND TERM 
0118                         { $<n>$ = NewBitwiseAnd($<n>1, $<n>3); }
0119                 |       TERM
0120                         { $<n>$ = $<n>1; }
0121                 |       T_OR error
0122                         { yyerror(store, EParseErrorTwoOperands); $<n>$ = 0L; }
0123                 |       T_AND error
0124                         { yyerror(store, EParseErrorTwoOperands); $<n>$ = 0L; }
0125                 ;
0126 
0127 TERM            :       TERM T_MULTIPLY NEG
0128                         { $<n>$ = NewMultiplication($<n>1, $<n>3); }
0129                 |       TERM T_DIVIDE NEG
0130                         { $<n>$ = NewDivision($<n>1, $<n>3); }
0131                 |       TERM T_MOD NEG
0132                         { $<n>$ = NewModulo($<n>1, $<n>3); }
0133                 |       T_MULTIPLY error
0134                         { yyerror(store, EParseErrorTwoOperands); $<n>$ = 0L; }
0135                 |       T_DIVIDE error
0136                         { yyerror(store, EParseErrorTwoOperands); $<n>$ = 0L; }
0137                 |       T_MOD error
0138                         { yyerror(store, EParseErrorTwoOperands); $<n>$ = 0L; }
0139                 |       NEG
0140                         { $<n>$ = $<n>1; }
0141                 ;
0142 
0143 NEG             :       T_SUBTRACT NEG %prec U_SUBTRACT
0144                         { $<n>$ = NewNegation($<n>2); }
0145                 |       T_NOT NEG
0146                         { $<n>$ = NewNot($<n>2); }
0147                 |       T_NOT error
0148                         { $<n>$ = 0L; yyerror(store, EParseErrorRequiresOperand); }
0149                 |       EXP
0150                         { $<n>$ = $<n>1; }
0151                 ;
0152 
0153 EXP             :       EXP T_EXP EXP
0154                         { $<n>$ = NewPower($<n>1, $<n>3); }
0155                 |       EXP T_EXP error
0156                         { DeleteNode($<n>1); $<n>$ = 0L; yyerror(store, EParseErrorTwoOperands); }
0157                 |       EXP T_EXP /**/
0158                         { DeleteNode($<n>1); $<n>$ = 0L; yyerror(store, EParseErrorTwoOperands); }
0159                 |       T_EXP error
0160                         { $<n>$ = 0L; yyerror(store, EParseErrorTwoOperands); }
0161                 |       ATOMIC
0162                         { $<n>$ = $<n>1; }
0163                 ;
0164 
0165 ATOMIC          :       T_OPENPAR BOOLEAN_OR T_CLOSEPAR
0166                         { $<n>$ = $<n>2; ParenthesizeNode($<n>$); }
0167                 |       T_OPENPAR error
0168                         { yyerror(store, EParseErrorMissingClosingParenthesis); $<n>$ = 0L; }
0169                 |       T_IDENTIFIER
0170                         { $<n>$ = NewIdentifier($<data>1); }
0171                 |       T_DATA
0172                         { $<n>$ = NewData(store, $<data>1); }
0173                 |       T_IDENTIFIER T_OPENPAR T_CLOSEPAR error
0174                         { yyerror(store, EParseErrorNoImplicitMultiply); free($<data>1); $<n>$ = 0L; }
0175                 |       T_IDENTIFIER T_OPENPAR T_CLOSEPAR
0176                         { $<n>$ = NewFunction($<data>1, NewArgumentList()); }
0177 /*              |       T_IDENTIFIER T_OPENPAR ARGUMENTS error
0178                         { yyerror(store, EParseErrorMissingClosingParenthesis); DeleteNode($<n>3); free($<data>1); $<n>$ = 0L; }
0179 */
0180                 |       T_IDENTIFIER T_OPENPAR ARGUMENTS T_CLOSEPAR error
0181                         { yyerror(store, EParseErrorNoImplicitMultiply); DeleteNode($<n>3); free($<data>1); $<n>$ = 0L; }
0182                 |       T_IDENTIFIER T_OPENPAR ARGUMENTS T_CLOSEPAR
0183                         { $<n>$ = NewFunction($<data>1, $<n>3); }
0184                 |       T_IDENTIFIER T_OPENPAR error
0185                         { yyerror(store, EParseErrorMissingClosingParenthesis); free($<data>1); $<n>$ = 0L; }
0186                 |       T_NUMBER
0187                         { $<n>$ = NewNumber($<number>1); }
0188                 |       T_NUMBER error
0189                         { yyerror(store, EParseErrorNoImplicitMultiply); $<n>$ = 0L; }
0190                 |       T_INVALID
0191                         { yyerrortoken($<character>1); $<n>$ = 0L; }
0192                 |       T_OPENPAR T_CLOSEPAR
0193                         { yyerror(store, EParseErrorEmptyParentheses); $<n>$ = 0L; }
0194                 ;
0195 
0196 ARGUMENTS       :       ARGLIST
0197                         { $<n>$ = $<n>1; }
0198                 ;
0199 
0200 ARGLIST         :       ARGLIST T_COMMA ARGUMENT
0201                         { if ($<n>1 && $<n>3) { AppendArgument($<n>1, $<n>3); } else { DeleteNode($<n>1); DeleteNode($<n>3); $<n>1 = 0L; } $<n>$ = $<n>1; }
0202                 |       ARGUMENT
0203                         { if ($<n>1) { $<n>$ = NewArgumentList(); AppendArgument($<n>$, $<n>1); } else { $<n>$ = 0L; } }
0204                 |       ARGLIST T_COMMA error
0205                         { $<n>$ = 0L; DeleteNode($<n>1); yyerror(store, EParseErrorEmptyArg); }
0206                 |       {} /**/ T_COMMA ARGUMENT
0207                         { yyerror(store, EParseErrorEmptyArg); DeleteNode($<n>3); $<n>$ = 0L; }
0208                 ;
0209 
0210 ARGUMENT        :       START
0211                         { $<n>$ = $<n>1; }
0212                 ;
0213 
0214 %%
0215