You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
165 lines
3.5 KiB
165 lines
3.5 KiB
16 years ago
|
%{
|
||
8 years ago
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
||
16 years ago
|
/*
|
||
|
|
||
|
This file must be translated to C and modified to build everywhere.
|
||
|
|
||
|
Run bison like this:
|
||
|
|
||
|
bison --yacc --name-prefix=cmExpr_yy --defines=cmExprParserTokens.h -ocmExprParser.cxx cmExprParser.y
|
||
|
|
||
|
Modify cmExprParser.cxx:
|
||
8 years ago
|
- "#if 0" out yyerrorlab block in range ["goto yyerrlab1", "yyerrlab1:"]
|
||
16 years ago
|
|
||
|
*/
|
||
|
|
||
8 years ago
|
#include "cmConfigure.h" // IWYU pragma: keep
|
||
|
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
|
||
16 years ago
|
/*-------------------------------------------------------------------------*/
|
||
8 years ago
|
#define YYDEBUG 1
|
||
16 years ago
|
#include "cmExprParserHelper.h" /* Interface to parser object. */
|
||
|
#include "cmExprLexer.h" /* Interface to lexer object. */
|
||
|
#include "cmExprParserTokens.h" /* Need YYSTYPE for YY_DECL. */
|
||
|
|
||
|
/* Forward declare the lexer entry point. */
|
||
|
YY_DECL;
|
||
|
|
||
8 years ago
|
/* Helper function to forward error callback from parser. */
|
||
|
static void cmExpr_yyerror(yyscan_t yyscanner, const char* message);
|
||
16 years ago
|
|
||
|
/* Disable some warnings in the generated code. */
|
||
|
#ifdef _MSC_VER
|
||
|
# pragma warning (disable: 4102) /* Unused goto label. */
|
||
|
# pragma warning (disable: 4065) /* Switch statement contains default but no case. */
|
||
|
#endif
|
||
|
%}
|
||
|
|
||
|
/* Generate a reentrant parser object. */
|
||
8 years ago
|
%define api.pure
|
||
|
|
||
|
/* Configure the parser to use a lexer object. */
|
||
|
%lex-param {yyscan_t yyscanner}
|
||
|
%parse-param {yyscan_t yyscanner}
|
||
|
|
||
|
%define parse.error verbose
|
||
16 years ago
|
|
||
|
/*-------------------------------------------------------------------------*/
|
||
|
/* Tokens */
|
||
|
%token exp_PLUS
|
||
|
%token exp_MINUS
|
||
|
%token exp_TIMES
|
||
|
%token exp_DIVIDE
|
||
|
%token exp_MOD
|
||
|
%token exp_SHIFTLEFT
|
||
|
%token exp_SHIFTRIGHT
|
||
|
%token exp_OPENPARENT
|
||
|
%token exp_CLOSEPARENT
|
||
|
%token exp_OR;
|
||
|
%token exp_AND;
|
||
|
%token exp_XOR;
|
||
|
%token exp_NOT;
|
||
|
%token exp_NUMBER;
|
||
|
|
||
|
/*-------------------------------------------------------------------------*/
|
||
|
/* grammar */
|
||
|
%%
|
||
|
|
||
|
|
||
8 years ago
|
start:
|
||
|
exp {
|
||
|
cmExpr_yyget_extra(yyscanner)->SetResult($<Number>1);
|
||
|
}
|
||
16 years ago
|
|
||
|
exp:
|
||
8 years ago
|
bitwiseor {
|
||
|
$<Number>$ = $<Number>1;
|
||
|
}
|
||
|
| exp exp_OR bitwiseor {
|
||
|
$<Number>$ = $<Number>1 | $<Number>3;
|
||
|
}
|
||
16 years ago
|
|
||
|
bitwiseor:
|
||
8 years ago
|
bitwisexor {
|
||
|
$<Number>$ = $<Number>1;
|
||
|
}
|
||
|
| bitwiseor exp_XOR bitwisexor {
|
||
|
$<Number>$ = $<Number>1 ^ $<Number>3;
|
||
|
}
|
||
16 years ago
|
|
||
|
bitwisexor:
|
||
8 years ago
|
bitwiseand {
|
||
|
$<Number>$ = $<Number>1;
|
||
|
}
|
||
|
| bitwisexor exp_AND bitwiseand {
|
||
|
$<Number>$ = $<Number>1 & $<Number>3;
|
||
|
}
|
||
16 years ago
|
|
||
|
bitwiseand:
|
||
8 years ago
|
shift {
|
||
|
$<Number>$ = $<Number>1;
|
||
|
}
|
||
|
| bitwiseand exp_SHIFTLEFT shift {
|
||
|
$<Number>$ = $<Number>1 << $<Number>3;
|
||
|
}
|
||
|
| bitwiseand exp_SHIFTRIGHT shift {
|
||
|
$<Number>$ = $<Number>1 >> $<Number>3;
|
||
|
}
|
||
16 years ago
|
|
||
|
shift:
|
||
8 years ago
|
term {
|
||
|
$<Number>$ = $<Number>1;
|
||
|
}
|
||
|
| shift exp_PLUS term {
|
||
|
$<Number>$ = $<Number>1 + $<Number>3;
|
||
|
}
|
||
|
| shift exp_MINUS term {
|
||
|
$<Number>$ = $<Number>1 - $<Number>3;
|
||
|
}
|
||
16 years ago
|
|
||
|
term:
|
||
8 years ago
|
unary {
|
||
|
$<Number>$ = $<Number>1;
|
||
|
}
|
||
|
| term exp_TIMES unary {
|
||
|
$<Number>$ = $<Number>1 * $<Number>3;
|
||
|
}
|
||
|
| term exp_DIVIDE unary {
|
||
|
$<Number>$ = $<Number>1 / $<Number>3;
|
||
|
}
|
||
|
| term exp_MOD unary {
|
||
|
$<Number>$ = $<Number>1 % $<Number>3;
|
||
|
}
|
||
|
|
||
|
unary:
|
||
|
factor {
|
||
|
$<Number>$ = $<Number>1;
|
||
|
}
|
||
|
| exp_PLUS unary {
|
||
|
$<Number>$ = + $<Number>2;
|
||
|
}
|
||
|
| exp_MINUS unary {
|
||
|
$<Number>$ = - $<Number>2;
|
||
|
}
|
||
16 years ago
|
|
||
|
factor:
|
||
8 years ago
|
exp_NUMBER {
|
||
|
$<Number>$ = $<Number>1;
|
||
|
}
|
||
|
| exp_OPENPARENT exp exp_CLOSEPARENT {
|
||
|
$<Number>$ = $<Number>2;
|
||
|
}
|
||
16 years ago
|
;
|
||
|
|
||
|
%%
|
||
|
/* End of grammar */
|
||
|
|
||
|
/*--------------------------------------------------------------------------*/
|
||
8 years ago
|
void cmExpr_yyerror(yyscan_t yyscanner, const char* message)
|
||
16 years ago
|
{
|
||
8 years ago
|
cmExpr_yyget_extra(yyscanner)->Error(message);
|
||
16 years ago
|
}
|