aboutsummaryrefslogtreecommitdiff
path: root/tools/bison++/Example/MyParser.y
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2010-11-19 13:18:48 +0000
committermarha <marha@users.sourceforge.net>2010-11-19 13:18:48 +0000
commit12f606ce06ef926f366a03079c5e3107c23f18af (patch)
tree28d7be4328bca9c31c1ab0f7cb5924c196be23a0 /tools/bison++/Example/MyParser.y
parent773752eab55047c33bad0d88006bb69f5c601502 (diff)
downloadvcxsrv-12f606ce06ef926f366a03079c5e3107c23f18af.tar.gz
vcxsrv-12f606ce06ef926f366a03079c5e3107c23f18af.tar.bz2
vcxsrv-12f606ce06ef926f366a03079c5e3107c23f18af.zip
Added tool bison++-1.21.11
Diffstat (limited to 'tools/bison++/Example/MyParser.y')
-rw-r--r--tools/bison++/Example/MyParser.y55
1 files changed, 55 insertions, 0 deletions
diff --git a/tools/bison++/Example/MyParser.y b/tools/bison++/Example/MyParser.y
new file mode 100644
index 000000000..f8787eb34
--- /dev/null
+++ b/tools/bison++/Example/MyParser.y
@@ -0,0 +1,55 @@
+%{
+#define YY_MyParser_STYPE yy_MyParser_stype
+%}
+%name MyParser
+%define LSP_NEEDED
+%define ERROR_BODY =0
+%define LEX_BODY =0
+%header{
+#include <iostream>
+#include <string>
+ using namespace std;
+#define YY_DECL int yyFlexLexer::yylex(YY_MyParser_STYPE *val)
+#ifndef FLEXFIX
+#define FLEXFIX YY_MyParser_STYPE *val
+#define FLEXFIX2 val
+#endif
+%}
+
+%union {
+ int num;
+ bool statement;
+ }
+
+
+
+%token <num> PLUS INTEGER MINUS AND OR NOT LPARA RPARA
+%token <statement> BOOLEAN
+%type <num> exp result
+%type <statement> bexp
+%start result
+
+%left OR
+%left AND
+%left PLUS MINUS
+%left NOT
+%left LPARA RPARA
+
+%%
+
+result : exp {cout << "Result = " << $1 << endl;}
+ | bexp {cout << "Result = " << $1 << endl;}
+
+exp : exp PLUS exp {$$ = $1 + $3;}
+ | INTEGER {$$ = $1;}
+ | MINUS exp { $$ = -$2;}
+ | exp MINUS exp {$$ = $1 - $3;}
+
+bexp : BOOLEAN {$$ = $1;}
+ | bexp AND bexp { $$ = $1 && $3;}
+ | bexp OR bexp { $$ = $1 || $3;}
+ | NOT bexp {$$ = !$2;}
+ | LPARA bexp RPARA {$$ = $2}
+%%
+/* -------------- body section -------------- */
+// feel free to add your own C/C++ code here