Libeval: leading + is a sign, not an operator
Due to (presumably) a different lemon version, there are some formatting changes in the grammar, and some manual debug left in has been removed.
This commit is contained in:
parent
f30f5b3249
commit
157519d722
|
@ -1,92 +1,63 @@
|
||||||
/*
|
/* Driver template for the LEMON parser generator.
|
||||||
** 2000-05-29
|
** The author disclaims copyright to this source code.
|
||||||
**
|
|
||||||
** The author disclaims copyright to this source code. In place of
|
|
||||||
** a legal notice, here is a blessing:
|
|
||||||
**
|
|
||||||
** May you do good and not evil.
|
|
||||||
** May you find forgiveness for yourself and forgive others.
|
|
||||||
** May you share freely, never taking more than you give.
|
|
||||||
**
|
|
||||||
*************************************************************************
|
|
||||||
** Driver template for the LEMON parser generator.
|
|
||||||
**
|
|
||||||
** The "lemon" program processes an LALR(1) input grammar file, then uses
|
|
||||||
** this template to construct a parser. The "lemon" program inserts text
|
|
||||||
** at each "%%" line. Also, any "P-a-r-s-e" identifer prefix (without the
|
|
||||||
** interstitial "-" characters) contained in this template is changed into
|
|
||||||
** the value of the %name directive from the grammar. Otherwise, the content
|
|
||||||
** of this template is copied straight through into the generate parser
|
|
||||||
** source file.
|
|
||||||
**
|
|
||||||
** The following is the concatenation of all %include directives from the
|
|
||||||
** input grammar file:
|
|
||||||
*/
|
*/
|
||||||
|
/* First off, code is included that follows the "include" declaration
|
||||||
|
** in the input grammar file. */
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
/************ Begin %include sections from the grammar ************************/
|
|
||||||
#line 28 "grammar.lemon"
|
#line 28 "grammar.lemon"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <libeval/numeric_evaluator.h>
|
#include <libeval/numeric_evaluator.h>
|
||||||
#line 32 "grammar.c"
|
#line 12 "grammar.c"
|
||||||
/**************** End of %include directives **********************************/
|
/* Next is all token values, in a form suitable for use by makeheaders.
|
||||||
/* These constants specify the various numeric values for terminal symbols
|
** This section will be null unless lemon is run with the -m switch.
|
||||||
** in a format understandable to "makeheaders". This section is blank unless
|
*/
|
||||||
** "lemon" is run with the "-m" command-line option.
|
/*
|
||||||
***************** Begin makeheaders token definitions *************************/
|
** These constants (all generated automatically by the parser generator)
|
||||||
/**************** End makeheaders token definitions ***************************/
|
** specify the various kinds of tokens (terminals) that the parser
|
||||||
|
** understands.
|
||||||
/* The next sections is a series of control #defines.
|
**
|
||||||
|
** Each symbol here is a terminal symbol in the grammar.
|
||||||
|
*/
|
||||||
|
/* Make sure the INTERFACE macro is defined.
|
||||||
|
*/
|
||||||
|
#ifndef INTERFACE
|
||||||
|
# define INTERFACE 1
|
||||||
|
#endif
|
||||||
|
/* The next thing included is series of defines which control
|
||||||
** various aspects of the generated parser.
|
** various aspects of the generated parser.
|
||||||
** YYCODETYPE is the data type used to store the integer codes
|
** YYCODETYPE is the data type used for storing terminal
|
||||||
** that represent terminal and non-terminal symbols.
|
** and nonterminal numbers. "unsigned char" is
|
||||||
** "unsigned char" is used if there are fewer than
|
** used if there are fewer than 250 terminals
|
||||||
** 256 symbols. Larger types otherwise.
|
** and nonterminals. "int" is used otherwise.
|
||||||
** YYNOCODE is a number of type YYCODETYPE that is not used for
|
** YYNOCODE is a number of type YYCODETYPE which corresponds
|
||||||
** any terminal or nonterminal symbol.
|
** to no legal terminal or nonterminal number. This
|
||||||
|
** number is used to fill in empty slots of the hash
|
||||||
|
** table.
|
||||||
** YYFALLBACK If defined, this indicates that one or more tokens
|
** YYFALLBACK If defined, this indicates that one or more tokens
|
||||||
** (also known as: "terminal symbols") have fall-back
|
** have fall-back values which should be used if the
|
||||||
** values which should be used if the original symbol
|
** original value of the token will not parse.
|
||||||
** would not parse. This permits keywords to sometimes
|
** YYACTIONTYPE is the data type used for storing terminal
|
||||||
** be used as identifiers, for example.
|
** and nonterminal numbers. "unsigned char" is
|
||||||
** YYACTIONTYPE is the data type used for "action codes" - numbers
|
** used if there are fewer than 250 rules and
|
||||||
** that indicate what to do in response to the next
|
** states combined. "int" is used otherwise.
|
||||||
** token.
|
** ParseTOKENTYPE is the data type used for minor tokens given
|
||||||
** ParseTOKENTYPE is the data type used for minor type for terminal
|
** directly to the parser from the tokenizer.
|
||||||
** symbols. Background: A "minor type" is a semantic
|
** YYMINORTYPE is the data type used for all minor tokens.
|
||||||
** value associated with a terminal or non-terminal
|
|
||||||
** symbols. For example, for an "ID" terminal symbol,
|
|
||||||
** the minor type might be the name of the identifier.
|
|
||||||
** Each non-terminal can have a different minor type.
|
|
||||||
** Terminal symbols all have the same minor type, though.
|
|
||||||
** This macros defines the minor type for terminal
|
|
||||||
** symbols.
|
|
||||||
** YYMINORTYPE is the data type used for all minor types.
|
|
||||||
** This is typically a union of many types, one of
|
** This is typically a union of many types, one of
|
||||||
** which is ParseTOKENTYPE. The entry in the union
|
** which is ParseTOKENTYPE. The entry in the union
|
||||||
** for terminal symbols is called "yy0".
|
** for base tokens is called "yy0".
|
||||||
** YYSTACKDEPTH is the maximum depth of the parser's stack. If
|
** YYSTACKDEPTH is the maximum depth of the parser's stack. If
|
||||||
** zero the stack is dynamically sized using realloc()
|
** zero the stack is dynamically sized using realloc()
|
||||||
** ParseARG_SDECL A static variable declaration for the %extra_argument
|
** ParseARG_SDECL A static variable declaration for the %extra_argument
|
||||||
** ParseARG_PDECL A parameter declaration for the %extra_argument
|
** ParseARG_PDECL A parameter declaration for the %extra_argument
|
||||||
** ParseARG_STORE Code to store %extra_argument into yypParser
|
** ParseARG_STORE Code to store %extra_argument into yypParser
|
||||||
** ParseARG_FETCH Code to extract %extra_argument from yypParser
|
** ParseARG_FETCH Code to extract %extra_argument from yypParser
|
||||||
** YYERRORSYMBOL is the code number of the error symbol. If not
|
|
||||||
** defined, then do no error processing.
|
|
||||||
** YYNSTATE the combined number of states.
|
** YYNSTATE the combined number of states.
|
||||||
** YYNRULE the number of rules in the grammar
|
** YYNRULE the number of rules in the grammar
|
||||||
** YY_MAX_SHIFT Maximum value for shift actions
|
** YYERRORSYMBOL is the code number of the error symbol. If not
|
||||||
** YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions
|
** defined, then do no error processing.
|
||||||
** YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions
|
|
||||||
** YY_MIN_REDUCE Maximum value for reduce actions
|
|
||||||
** YY_ERROR_ACTION The yy_action[] code for syntax error
|
|
||||||
** YY_ACCEPT_ACTION The yy_action[] code for accept
|
|
||||||
** YY_NO_ACTION The yy_action[] code for no-op
|
|
||||||
*/
|
*/
|
||||||
#ifndef INTERFACE
|
|
||||||
# define INTERFACE 1
|
|
||||||
#endif
|
|
||||||
/************* Begin control #defines *****************************************/
|
|
||||||
#define YYCODETYPE unsigned char
|
#define YYCODETYPE unsigned char
|
||||||
#define YYNOCODE 19
|
#define YYNOCODE 19
|
||||||
#define YYACTIONTYPE unsigned char
|
#define YYACTIONTYPE unsigned char
|
||||||
|
@ -102,17 +73,11 @@ typedef union {
|
||||||
#define ParseARG_PDECL , NUMERIC_EVALUATOR* pEval
|
#define ParseARG_PDECL , NUMERIC_EVALUATOR* pEval
|
||||||
#define ParseARG_FETCH NUMERIC_EVALUATOR* pEval = yypParser->pEval
|
#define ParseARG_FETCH NUMERIC_EVALUATOR* pEval = yypParser->pEval
|
||||||
#define ParseARG_STORE yypParser->pEval = pEval
|
#define ParseARG_STORE yypParser->pEval = pEval
|
||||||
#define YYNSTATE 16
|
#define YYNSTATE 28
|
||||||
#define YYNRULE 16
|
#define YYNRULE 17
|
||||||
#define YY_MAX_SHIFT 15
|
#define YY_NO_ACTION (YYNSTATE+YYNRULE+2)
|
||||||
#define YY_MIN_SHIFTREDUCE 26
|
#define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1)
|
||||||
#define YY_MAX_SHIFTREDUCE 41
|
#define YY_ERROR_ACTION (YYNSTATE+YYNRULE)
|
||||||
#define YY_MIN_REDUCE 42
|
|
||||||
#define YY_MAX_REDUCE 57
|
|
||||||
#define YY_ERROR_ACTION 58
|
|
||||||
#define YY_ACCEPT_ACTION 59
|
|
||||||
#define YY_NO_ACTION 60
|
|
||||||
/************* End control #defines *******************************************/
|
|
||||||
|
|
||||||
/* The yyzerominor constant is used to initialize instances of
|
/* The yyzerominor constant is used to initialize instances of
|
||||||
** YYMINORTYPE objects to zero. */
|
** YYMINORTYPE objects to zero. */
|
||||||
|
@ -139,20 +104,16 @@ static const YYMINORTYPE yyzerominor = { 0 };
|
||||||
** Suppose the action integer is N. Then the action is determined as
|
** Suppose the action integer is N. Then the action is determined as
|
||||||
** follows
|
** follows
|
||||||
**
|
**
|
||||||
** 0 <= N <= YY_MAX_SHIFT Shift N. That is, push the lookahead
|
** 0 <= N < YYNSTATE Shift N. That is, push the lookahead
|
||||||
** token onto the stack and goto state N.
|
** token onto the stack and goto state N.
|
||||||
**
|
**
|
||||||
** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
|
** YYNSTATE <= N < YYNSTATE+YYNRULE Reduce by rule N-YYNSTATE.
|
||||||
** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE.
|
|
||||||
**
|
**
|
||||||
** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE
|
** N == YYNSTATE+YYNRULE A syntax error has occurred.
|
||||||
** and YY_MAX_REDUCE
|
|
||||||
|
|
||||||
** N == YY_ERROR_ACTION A syntax error has occurred.
|
|
||||||
**
|
**
|
||||||
** N == YY_ACCEPT_ACTION The parser accepts its input.
|
** N == YYNSTATE+YYNRULE+1 The parser accepts its input.
|
||||||
**
|
**
|
||||||
** N == YY_NO_ACTION No such action. Denotes unused
|
** N == YYNSTATE+YYNRULE+2 No such action. Denotes unused
|
||||||
** slots in the yy_action[] table.
|
** slots in the yy_action[] table.
|
||||||
**
|
**
|
||||||
** The action table is constructed as a single large table named yy_action[].
|
** The action table is constructed as a single large table named yy_action[].
|
||||||
|
@ -181,48 +142,47 @@ static const YYMINORTYPE yyzerominor = { 0 };
|
||||||
** yy_reduce_ofst[] For each state, the offset into yy_action for
|
** yy_reduce_ofst[] For each state, the offset into yy_action for
|
||||||
** shifting non-terminals after a reduce.
|
** shifting non-terminals after a reduce.
|
||||||
** yy_default[] Default action for each state.
|
** yy_default[] Default action for each state.
|
||||||
**
|
*/
|
||||||
*********** Begin parsing tables **********************************************/
|
#define YY_ACTTAB_COUNT (58)
|
||||||
#define YY_ACTTAB_COUNT (51)
|
|
||||||
static const YYACTIONTYPE yy_action[] = {
|
static const YYACTIONTYPE yy_action[] = {
|
||||||
/* 0 */ 31, 8, 7, 33, 5, 6, 30, 42, 15, 10,
|
/* 0 */ 24, 9, 8, 23, 6, 7, 25, 28, 17, 16,
|
||||||
/* 10 */ 15, 11, 4, 12, 4, 40, 29, 32, 2, 32,
|
/* 10 */ 17, 4, 5, 4, 5, 3, 26, 22, 2, 22,
|
||||||
/* 20 */ 2, 8, 7, 33, 5, 6, 15, 28, 9, 41,
|
/* 20 */ 2, 9, 8, 23, 6, 7, 47, 17, 15, 19,
|
||||||
/* 30 */ 4, 39, 13, 14, 29, 32, 2, 44, 3, 8,
|
/* 30 */ 4, 5, 21, 20, 47, 26, 22, 2, 27, 10,
|
||||||
/* 40 */ 7, 33, 5, 6, 59, 1, 27, 9, 33, 5,
|
/* 40 */ 9, 8, 23, 6, 7, 46, 1, 18, 10, 23,
|
||||||
/* 50 */ 6,
|
/* 50 */ 6, 7, 47, 47, 14, 13, 12, 11,
|
||||||
};
|
};
|
||||||
static const YYCODETYPE yy_lookahead[] = {
|
static const YYCODETYPE yy_lookahead[] = {
|
||||||
/* 0 */ 3, 4, 5, 6, 7, 8, 9, 0, 1, 17,
|
/* 0 */ 3, 4, 5, 6, 7, 8, 9, 0, 1, 17,
|
||||||
/* 10 */ 1, 17, 5, 17, 5, 17, 9, 10, 11, 10,
|
/* 10 */ 1, 4, 5, 4, 5, 2, 9, 10, 11, 10,
|
||||||
/* 20 */ 11, 4, 5, 6, 7, 8, 1, 16, 17, 12,
|
/* 20 */ 11, 4, 5, 6, 7, 8, 18, 1, 17, 12,
|
||||||
/* 30 */ 5, 17, 17, 17, 9, 10, 11, 18, 2, 4,
|
/* 30 */ 4, 5, 17, 17, 18, 9, 10, 11, 16, 17,
|
||||||
/* 40 */ 5, 6, 7, 8, 14, 15, 16, 17, 6, 7,
|
/* 40 */ 4, 5, 6, 7, 8, 14, 15, 16, 17, 6,
|
||||||
/* 50 */ 8,
|
/* 50 */ 7, 8, 18, 18, 17, 17, 17, 17,
|
||||||
};
|
};
|
||||||
#define YY_SHIFT_USE_DFLT (-4)
|
#define YY_SHIFT_USE_DFLT (-4)
|
||||||
#define YY_SHIFT_COUNT (15)
|
#define YY_SHIFT_COUNT (17)
|
||||||
#define YY_SHIFT_MIN (-3)
|
#define YY_SHIFT_MIN (-3)
|
||||||
#define YY_SHIFT_MAX (42)
|
#define YY_SHIFT_MAX (43)
|
||||||
static const signed char yy_shift_ofst[] = {
|
static const signed char yy_shift_ofst[] = {
|
||||||
/* 0 */ 25, 7, 9, 9, 9, 9, 9, 9, 9, -3,
|
/* 0 */ 26, 7, 9, 9, 9, 9, 9, 9, 9, 9,
|
||||||
/* 10 */ 17, 35, 42, 42, 42, 36,
|
/* 10 */ -3, 17, 36, 43, 43, 43, 43, 13,
|
||||||
};
|
};
|
||||||
#define YY_REDUCE_USE_DFLT (-9)
|
#define YY_REDUCE_USE_DFLT (-9)
|
||||||
#define YY_REDUCE_COUNT (8)
|
#define YY_REDUCE_COUNT (9)
|
||||||
#define YY_REDUCE_MIN (-8)
|
#define YY_REDUCE_MIN (-8)
|
||||||
#define YY_REDUCE_MAX (30)
|
#define YY_REDUCE_MAX (40)
|
||||||
static const signed char yy_reduce_ofst[] = {
|
static const signed char yy_reduce_ofst[] = {
|
||||||
/* 0 */ 30, 11, -8, -6, -4, -2, 14, 15, 16,
|
/* 0 */ 31, 22, 40, 39, 38, 37, 16, 15, 11, -8,
|
||||||
};
|
};
|
||||||
static const YYACTIONTYPE yy_default[] = {
|
static const YYACTIONTYPE yy_default[] = {
|
||||||
/* 0 */ 58, 58, 58, 58, 58, 58, 58, 58, 58, 58,
|
/* 0 */ 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
|
||||||
/* 10 */ 58, 52, 50, 54, 53, 51,
|
/* 10 */ 45, 45, 39, 37, 36, 41, 40, 38, 29, 44,
|
||||||
|
/* 20 */ 43, 42, 34, 35, 33, 32, 31, 30,
|
||||||
};
|
};
|
||||||
/********** End of lemon-generated parsing tables *****************************/
|
|
||||||
|
|
||||||
/* The next table maps tokens (terminal symbols) into fallback tokens.
|
/* The next table maps tokens into fallback tokens. If a construct
|
||||||
** If a construct like the following:
|
** like the following:
|
||||||
**
|
**
|
||||||
** %fallback ID X Y Z.
|
** %fallback ID X Y Z.
|
||||||
**
|
**
|
||||||
|
@ -230,10 +190,6 @@ static const YYACTIONTYPE yy_default[] = {
|
||||||
** and Z. Whenever one of the tokens X, Y, or Z is input to the parser
|
** and Z. Whenever one of the tokens X, Y, or Z is input to the parser
|
||||||
** but it does not parse, the type of the token is changed to ID and
|
** but it does not parse, the type of the token is changed to ID and
|
||||||
** the parse is retried before an error is thrown.
|
** the parse is retried before an error is thrown.
|
||||||
**
|
|
||||||
** This feature can be used, for example, to cause some keywords in a language
|
|
||||||
** to revert to identifiers if they keyword does not apply in the context where
|
|
||||||
** it appears.
|
|
||||||
*/
|
*/
|
||||||
#ifdef YYFALLBACK
|
#ifdef YYFALLBACK
|
||||||
static const YYCODETYPE yyFallback[] = {
|
static const YYCODETYPE yyFallback[] = {
|
||||||
|
@ -251,13 +207,9 @@ static const YYCODETYPE yyFallback[] = {
|
||||||
** + The semantic value stored at this level of the stack. This is
|
** + The semantic value stored at this level of the stack. This is
|
||||||
** the information used by the action routines in the grammar.
|
** the information used by the action routines in the grammar.
|
||||||
** It is sometimes called the "minor" token.
|
** It is sometimes called the "minor" token.
|
||||||
**
|
|
||||||
** After the "shift" half of a SHIFTREDUCE action, the stateno field
|
|
||||||
** actually contains the reduce action for the second half of the
|
|
||||||
** SHIFTREDUCE.
|
|
||||||
*/
|
*/
|
||||||
struct yyStackEntry {
|
struct yyStackEntry {
|
||||||
YYACTIONTYPE stateno; /* The state-number, or reduce action in SHIFTREDUCE */
|
YYACTIONTYPE stateno; /* The state-number */
|
||||||
YYCODETYPE major; /* The major token value. This is the code
|
YYCODETYPE major; /* The major token value. This is the code
|
||||||
** number for the token at this stack level */
|
** number for the token at this stack level */
|
||||||
YYMINORTYPE minor; /* The user-supplied minor token value. This
|
YYMINORTYPE minor; /* The user-supplied minor token value. This
|
||||||
|
@ -340,13 +292,14 @@ static const char *const yyRuleName[] = {
|
||||||
/* 6 */ "expr ::= VALUE",
|
/* 6 */ "expr ::= VALUE",
|
||||||
/* 7 */ "expr ::= expr UNIT",
|
/* 7 */ "expr ::= expr UNIT",
|
||||||
/* 8 */ "expr ::= MINUS expr",
|
/* 8 */ "expr ::= MINUS expr",
|
||||||
/* 9 */ "expr ::= VAR",
|
/* 9 */ "expr ::= PLUS expr",
|
||||||
/* 10 */ "expr ::= VAR ASSIGN expr",
|
/* 10 */ "expr ::= VAR",
|
||||||
/* 11 */ "expr ::= expr PLUS expr",
|
/* 11 */ "expr ::= VAR ASSIGN expr",
|
||||||
/* 12 */ "expr ::= expr MINUS expr",
|
/* 12 */ "expr ::= expr PLUS expr",
|
||||||
/* 13 */ "expr ::= expr MULT expr",
|
/* 13 */ "expr ::= expr MINUS expr",
|
||||||
/* 14 */ "expr ::= expr DIVIDE expr",
|
/* 14 */ "expr ::= expr MULT expr",
|
||||||
/* 15 */ "expr ::= PARENL expr PARENR",
|
/* 15 */ "expr ::= expr DIVIDE expr",
|
||||||
|
/* 16 */ "expr ::= PARENL expr PARENR",
|
||||||
};
|
};
|
||||||
#endif /* NDEBUG */
|
#endif /* NDEBUG */
|
||||||
|
|
||||||
|
@ -374,15 +327,6 @@ static void yyGrowStack(yyParser *p){
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Datatype of the argument to the memory allocated passed as the
|
|
||||||
** second argument to ParseAlloc() below. This can be changed by
|
|
||||||
** putting an appropriate #define in the %include section of the input
|
|
||||||
** grammar.
|
|
||||||
*/
|
|
||||||
#ifndef YYMALLOCARGTYPE
|
|
||||||
# define YYMALLOCARGTYPE size_t
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** This function allocates a new parser.
|
** This function allocates a new parser.
|
||||||
** The only argument is a pointer to a function which works like
|
** The only argument is a pointer to a function which works like
|
||||||
|
@ -395,9 +339,9 @@ static void yyGrowStack(yyParser *p){
|
||||||
** A pointer to a parser. This pointer is used in subsequent calls
|
** A pointer to a parser. This pointer is used in subsequent calls
|
||||||
** to Parse and ParseFree.
|
** to Parse and ParseFree.
|
||||||
*/
|
*/
|
||||||
void *ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE)){
|
void *ParseAlloc(void *(*mallocProc)(size_t)){
|
||||||
yyParser *pParser;
|
yyParser *pParser;
|
||||||
pParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) );
|
pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) );
|
||||||
if( pParser ){
|
if( pParser ){
|
||||||
pParser->yyidx = -1;
|
pParser->yyidx = -1;
|
||||||
#ifdef YYTRACKMAXSTACKDEPTH
|
#ifdef YYTRACKMAXSTACKDEPTH
|
||||||
|
@ -412,12 +356,10 @@ void *ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE)){
|
||||||
return pParser;
|
return pParser;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The following function deletes the "minor type" or semantic value
|
/* The following function deletes the value associated with a
|
||||||
** associated with a symbol. The symbol can be either a terminal
|
** symbol. The symbol can be either a terminal or nonterminal.
|
||||||
** or nonterminal. "yymajor" is the symbol code, and "yypminor" is
|
** "yymajor" is the symbol code, and "yypminor" is a pointer to
|
||||||
** a pointer to the value to be deleted. The code used to do the
|
** the value.
|
||||||
** deletions is derived from the %destructor and/or %token_destructor
|
|
||||||
** directives of the input grammar.
|
|
||||||
*/
|
*/
|
||||||
static void yy_destructor(
|
static void yy_destructor(
|
||||||
yyParser *yypParser, /* The parser */
|
yyParser *yypParser, /* The parser */
|
||||||
|
@ -433,11 +375,9 @@ static void yy_destructor(
|
||||||
** being destroyed before it is finished parsing.
|
** being destroyed before it is finished parsing.
|
||||||
**
|
**
|
||||||
** Note: during a reduce, the only symbols destroyed are those
|
** Note: during a reduce, the only symbols destroyed are those
|
||||||
** which appear on the RHS of the rule, but which are *not* used
|
** which appear on the RHS of the rule, but which are not used
|
||||||
** inside the C code.
|
** inside the C code.
|
||||||
*/
|
*/
|
||||||
/********* Begin destructor definitions ***************************************/
|
|
||||||
/********* End destructor definitions *****************************************/
|
|
||||||
default: break; /* If no destructor action specified: do nothing */
|
default: break; /* If no destructor action specified: do nothing */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -447,37 +387,45 @@ static void yy_destructor(
|
||||||
**
|
**
|
||||||
** If there is a destructor routine associated with the token which
|
** If there is a destructor routine associated with the token which
|
||||||
** is popped from the stack, then call it.
|
** is popped from the stack, then call it.
|
||||||
|
**
|
||||||
|
** Return the major token number for the symbol popped.
|
||||||
*/
|
*/
|
||||||
static void yy_pop_parser_stack(yyParser *pParser){
|
static int yy_pop_parser_stack(yyParser *pParser){
|
||||||
yyStackEntry *yytos;
|
YYCODETYPE yymajor;
|
||||||
assert( pParser->yyidx>=0 );
|
yyStackEntry *yytos = &pParser->yystack[pParser->yyidx];
|
||||||
yytos = &pParser->yystack[pParser->yyidx--];
|
|
||||||
|
if( pParser->yyidx<0 ) return 0;
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if( yyTraceFILE ){
|
if( yyTraceFILE && pParser->yyidx>=0 ){
|
||||||
fprintf(yyTraceFILE,"%sPopping %s\n",
|
fprintf(yyTraceFILE,"%sPopping %s\n",
|
||||||
yyTracePrompt,
|
yyTracePrompt,
|
||||||
yyTokenName[yytos->major]);
|
yyTokenName[yytos->major]);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
yy_destructor(pParser, yytos->major, &yytos->minor);
|
yymajor = yytos->major;
|
||||||
|
yy_destructor(pParser, yymajor, &yytos->minor);
|
||||||
|
pParser->yyidx--;
|
||||||
|
return yymajor;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Deallocate and destroy a parser. Destructors are called for
|
** Deallocate and destroy a parser. Destructors are all called for
|
||||||
** all stack elements before shutting the parser down.
|
** all stack elements before shutting the parser down.
|
||||||
**
|
**
|
||||||
** If the YYPARSEFREENEVERNULL macro exists (for example because it
|
** Inputs:
|
||||||
** is defined in a %include section of the input grammar) then it is
|
** <ul>
|
||||||
** assumed that the input pointer is never NULL.
|
** <li> A pointer to the parser. This should be a pointer
|
||||||
|
** obtained from ParseAlloc.
|
||||||
|
** <li> A pointer to a function used to reclaim memory obtained
|
||||||
|
** from malloc.
|
||||||
|
** </ul>
|
||||||
*/
|
*/
|
||||||
void ParseFree(
|
void ParseFree(
|
||||||
void *p, /* The parser to be deleted */
|
void *p, /* The parser to be deleted */
|
||||||
void (*freeProc)(void*) /* Function used to reclaim memory */
|
void (*freeProc)(void*) /* Function used to reclaim memory */
|
||||||
){
|
){
|
||||||
yyParser *pParser = (yyParser*)p;
|
yyParser *pParser = (yyParser*)p;
|
||||||
#ifndef YYPARSEFREENEVERNULL
|
|
||||||
if( pParser==0 ) return;
|
if( pParser==0 ) return;
|
||||||
#endif
|
|
||||||
while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser);
|
while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser);
|
||||||
#if YYSTACKDEPTH<=0
|
#if YYSTACKDEPTH<=0
|
||||||
free(pParser->yystack);
|
free(pParser->yystack);
|
||||||
|
@ -498,6 +446,10 @@ int ParseStackPeak(void *p){
|
||||||
/*
|
/*
|
||||||
** Find the appropriate action for a parser given the terminal
|
** Find the appropriate action for a parser given the terminal
|
||||||
** look-ahead token iLookAhead.
|
** look-ahead token iLookAhead.
|
||||||
|
**
|
||||||
|
** If the look-ahead token is YYNOCODE, then check to see if the action is
|
||||||
|
** independent of the look-ahead. If it is, return the action, otherwise
|
||||||
|
** return YY_NO_ACTION.
|
||||||
*/
|
*/
|
||||||
static int yy_find_shift_action(
|
static int yy_find_shift_action(
|
||||||
yyParser *pParser, /* The parser */
|
yyParser *pParser, /* The parser */
|
||||||
|
@ -506,64 +458,63 @@ static int yy_find_shift_action(
|
||||||
int i;
|
int i;
|
||||||
int stateno = pParser->yystack[pParser->yyidx].stateno;
|
int stateno = pParser->yystack[pParser->yyidx].stateno;
|
||||||
|
|
||||||
if( stateno>=YY_MIN_REDUCE ) return stateno;
|
if( stateno>YY_SHIFT_COUNT
|
||||||
assert( stateno <= YY_SHIFT_COUNT );
|
|| (i = yy_shift_ofst[stateno])==YY_SHIFT_USE_DFLT ){
|
||||||
do{
|
return yy_default[stateno];
|
||||||
i = yy_shift_ofst[stateno];
|
}
|
||||||
if( i==YY_SHIFT_USE_DFLT ) return yy_default[stateno];
|
assert( iLookAhead!=YYNOCODE );
|
||||||
assert( iLookAhead!=YYNOCODE );
|
i += iLookAhead;
|
||||||
i += iLookAhead;
|
if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
|
||||||
if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
|
if( iLookAhead>0 ){
|
||||||
if( iLookAhead>0 ){
|
|
||||||
#ifdef YYFALLBACK
|
#ifdef YYFALLBACK
|
||||||
YYCODETYPE iFallback; /* Fallback token */
|
YYCODETYPE iFallback; /* Fallback token */
|
||||||
if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
|
if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
|
||||||
&& (iFallback = yyFallback[iLookAhead])!=0 ){
|
&& (iFallback = yyFallback[iLookAhead])!=0 ){
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if( yyTraceFILE ){
|
if( yyTraceFILE ){
|
||||||
fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
|
fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
|
||||||
yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
|
yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
|
||||||
}
|
|
||||||
#endif
|
|
||||||
assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
|
|
||||||
iLookAhead = iFallback;
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
return yy_find_shift_action(pParser, iFallback);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef YYWILDCARD
|
#ifdef YYWILDCARD
|
||||||
{
|
{
|
||||||
int j = i - iLookAhead + YYWILDCARD;
|
int j = i - iLookAhead + YYWILDCARD;
|
||||||
if(
|
if(
|
||||||
#if YY_SHIFT_MIN+YYWILDCARD<0
|
#if YY_SHIFT_MIN+YYWILDCARD<0
|
||||||
j>=0 &&
|
j>=0 &&
|
||||||
#endif
|
#endif
|
||||||
#if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT
|
#if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT
|
||||||
j<YY_ACTTAB_COUNT &&
|
j<YY_ACTTAB_COUNT &&
|
||||||
#endif
|
#endif
|
||||||
yy_lookahead[j]==YYWILDCARD
|
yy_lookahead[j]==YYWILDCARD
|
||||||
){
|
){
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if( yyTraceFILE ){
|
if( yyTraceFILE ){
|
||||||
fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
|
fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
|
||||||
yyTracePrompt, yyTokenName[iLookAhead],
|
yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[YYWILDCARD]);
|
||||||
yyTokenName[YYWILDCARD]);
|
|
||||||
}
|
|
||||||
#endif /* NDEBUG */
|
|
||||||
return yy_action[j];
|
|
||||||
}
|
}
|
||||||
|
#endif /* NDEBUG */
|
||||||
|
return yy_action[j];
|
||||||
}
|
}
|
||||||
#endif /* YYWILDCARD */
|
|
||||||
}
|
}
|
||||||
return yy_default[stateno];
|
#endif /* YYWILDCARD */
|
||||||
}else{
|
|
||||||
return yy_action[i];
|
|
||||||
}
|
}
|
||||||
}while(1);
|
return yy_default[stateno];
|
||||||
|
}else{
|
||||||
|
return yy_action[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Find the appropriate action for a parser given the non-terminal
|
** Find the appropriate action for a parser given the non-terminal
|
||||||
** look-ahead token iLookAhead.
|
** look-ahead token iLookAhead.
|
||||||
|
**
|
||||||
|
** If the look-ahead token is YYNOCODE, then check to see if the action is
|
||||||
|
** independent of the look-ahead. If it is, return the action, otherwise
|
||||||
|
** return YY_NO_ACTION.
|
||||||
*/
|
*/
|
||||||
static int yy_find_reduce_action(
|
static int yy_find_reduce_action(
|
||||||
int stateno, /* Current state number */
|
int stateno, /* Current state number */
|
||||||
|
@ -606,31 +557,9 @@ static void yyStackOverflow(yyParser *yypParser, YYMINORTYPE *yypMinor){
|
||||||
while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
|
while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
|
||||||
/* Here code is inserted which will execute if the parser
|
/* Here code is inserted which will execute if the parser
|
||||||
** stack every overflows */
|
** stack every overflows */
|
||||||
/******** Begin %stack_overflow code ******************************************/
|
|
||||||
/******** End %stack_overflow code ********************************************/
|
|
||||||
ParseARG_STORE; /* Suppress warning about unused %extra_argument var */
|
ParseARG_STORE; /* Suppress warning about unused %extra_argument var */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
** Print tracing information for a SHIFT action
|
|
||||||
*/
|
|
||||||
#ifndef NDEBUG
|
|
||||||
static void yyTraceShift(yyParser *yypParser, int yyNewState){
|
|
||||||
if( yyTraceFILE ){
|
|
||||||
if( yyNewState<YYNSTATE ){
|
|
||||||
fprintf(yyTraceFILE,"%sShift '%s', go to state %d\n",
|
|
||||||
yyTracePrompt,yyTokenName[yypParser->yystack[yypParser->yyidx].major],
|
|
||||||
yyNewState);
|
|
||||||
}else{
|
|
||||||
fprintf(yyTraceFILE,"%sShift '%s'\n",
|
|
||||||
yyTracePrompt,yyTokenName[yypParser->yystack[yypParser->yyidx].major]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
# define yyTraceShift(X,Y)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Perform a shift action.
|
** Perform a shift action.
|
||||||
*/
|
*/
|
||||||
|
@ -665,7 +594,16 @@ static void yy_shift(
|
||||||
yytos->stateno = (YYACTIONTYPE)yyNewState;
|
yytos->stateno = (YYACTIONTYPE)yyNewState;
|
||||||
yytos->major = (YYCODETYPE)yyMajor;
|
yytos->major = (YYCODETYPE)yyMajor;
|
||||||
yytos->minor = *yypMinor;
|
yytos->minor = *yypMinor;
|
||||||
yyTraceShift(yypParser, yyNewState);
|
#ifndef NDEBUG
|
||||||
|
if( yyTraceFILE && yypParser->yyidx>0 ){
|
||||||
|
int i;
|
||||||
|
fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState);
|
||||||
|
fprintf(yyTraceFILE,"%sStack:",yyTracePrompt);
|
||||||
|
for(i=1; i<=yypParser->yyidx; i++)
|
||||||
|
fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]);
|
||||||
|
fprintf(yyTraceFILE,"\n");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The following table contains information about every rule that
|
/* The following table contains information about every rule that
|
||||||
|
@ -684,6 +622,7 @@ static const struct {
|
||||||
{ 17, 1 },
|
{ 17, 1 },
|
||||||
{ 17, 2 },
|
{ 17, 2 },
|
||||||
{ 17, 2 },
|
{ 17, 2 },
|
||||||
|
{ 17, 2 },
|
||||||
{ 17, 1 },
|
{ 17, 1 },
|
||||||
{ 17, 3 },
|
{ 17, 3 },
|
||||||
{ 17, 3 },
|
{ 17, 3 },
|
||||||
|
@ -713,13 +652,29 @@ static void yy_reduce(
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if( yyTraceFILE && yyruleno>=0
|
if( yyTraceFILE && yyruleno>=0
|
||||||
&& yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
|
&& yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
|
||||||
yysize = yyRuleInfo[yyruleno].nrhs;
|
fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt,
|
||||||
fprintf(yyTraceFILE, "%sReduce [%s], go to state %d.\n", yyTracePrompt,
|
yyRuleName[yyruleno]);
|
||||||
yyRuleName[yyruleno], yymsp[-yysize].stateno);
|
|
||||||
}
|
}
|
||||||
#endif /* NDEBUG */
|
#endif /* NDEBUG */
|
||||||
|
|
||||||
|
/* Silence complaints from purify about yygotominor being uninitialized
|
||||||
|
** in some cases when it is copied into the stack after the following
|
||||||
|
** switch. yygotominor is uninitialized when a rule reduces that does
|
||||||
|
** not set the value of its left-hand side nonterminal. Leaving the
|
||||||
|
** value of the nonterminal uninitialized is utterly harmless as long
|
||||||
|
** as the value is never used. So really the only thing this code
|
||||||
|
** accomplishes is to quieten purify.
|
||||||
|
**
|
||||||
|
** 2007-01-16: The wireshark project (www.wireshark.org) reports that
|
||||||
|
** without this code, their parser segfaults. I'm not sure what there
|
||||||
|
** parser is doing to make this happen. This is the second bug report
|
||||||
|
** from wireshark this week. Clearly they are stressing Lemon in ways
|
||||||
|
** that it has not been previously stressed... (SQLite ticket #2172)
|
||||||
|
*/
|
||||||
|
/*memset(&yygotominor, 0, sizeof(yygotominor));*/
|
||||||
yygotominor = yyzerominor;
|
yygotominor = yyzerominor;
|
||||||
|
|
||||||
|
|
||||||
switch( yyruleno ){
|
switch( yyruleno ){
|
||||||
/* Beginning here are the reduction cases. A typical example
|
/* Beginning here are the reduction cases. A typical example
|
||||||
** follows:
|
** follows:
|
||||||
|
@ -729,59 +684,63 @@ static void yy_reduce(
|
||||||
** #line <lineno> <thisfile>
|
** #line <lineno> <thisfile>
|
||||||
** break;
|
** break;
|
||||||
*/
|
*/
|
||||||
/********** Begin reduce actions **********************************************/
|
|
||||||
case 4: /* stmt ::= expr ENDS */
|
case 4: /* stmt ::= expr ENDS */
|
||||||
#line 49 "grammar.lemon"
|
#line 49 "grammar.lemon"
|
||||||
{ pEval->parseSetResult(yymsp[-1].minor.yy0.valid ? yymsp[-1].minor.yy0.dValue : NAN); }
|
{ pEval->parseSetResult(yymsp[-1].minor.yy0.valid ? yymsp[-1].minor.yy0.dValue : NAN); }
|
||||||
#line 737 "grammar.c"
|
#line 691 "grammar.c"
|
||||||
break;
|
break;
|
||||||
case 5: /* stmt ::= expr SEMCOL */
|
case 5: /* stmt ::= expr SEMCOL */
|
||||||
#line 50 "grammar.lemon"
|
#line 50 "grammar.lemon"
|
||||||
{ pEval->parseSetResult(NAN); }
|
{ pEval->parseSetResult(NAN); }
|
||||||
#line 742 "grammar.c"
|
#line 696 "grammar.c"
|
||||||
break;
|
break;
|
||||||
case 6: /* expr ::= VALUE */
|
case 6: /* expr ::= VALUE */
|
||||||
#line 52 "grammar.lemon"
|
#line 52 "grammar.lemon"
|
||||||
{ yygotominor.yy0.dValue = yymsp[0].minor.yy0.dValue; yygotominor.yy0.valid=true; }
|
{ yygotominor.yy0.dValue = yymsp[0].minor.yy0.dValue; yygotominor.yy0.valid=true; }
|
||||||
#line 747 "grammar.c"
|
#line 701 "grammar.c"
|
||||||
break;
|
break;
|
||||||
case 7: /* expr ::= expr UNIT */
|
case 7: /* expr ::= expr UNIT */
|
||||||
#line 53 "grammar.lemon"
|
#line 53 "grammar.lemon"
|
||||||
{ yygotominor.yy0.dValue = yymsp[-1].minor.yy0.dValue * yymsp[0].minor.yy0.dValue; yygotominor.yy0.valid=yymsp[-1].minor.yy0.valid; }
|
{ yygotominor.yy0.dValue = yymsp[-1].minor.yy0.dValue * yymsp[0].minor.yy0.dValue; yygotominor.yy0.valid=yymsp[-1].minor.yy0.valid; }
|
||||||
#line 752 "grammar.c"
|
#line 706 "grammar.c"
|
||||||
break;
|
break;
|
||||||
case 8: /* expr ::= MINUS expr */
|
case 8: /* expr ::= MINUS expr */
|
||||||
#line 54 "grammar.lemon"
|
#line 54 "grammar.lemon"
|
||||||
{ yygotominor.yy0.dValue = -yymsp[0].minor.yy0.dValue; yygotominor.yy0.valid=yymsp[0].minor.yy0.valid; }
|
{ yygotominor.yy0.dValue = -yymsp[0].minor.yy0.dValue; yygotominor.yy0.valid=yymsp[0].minor.yy0.valid; }
|
||||||
#line 757 "grammar.c"
|
#line 711 "grammar.c"
|
||||||
break;
|
break;
|
||||||
case 9: /* expr ::= VAR */
|
case 9: /* expr ::= PLUS expr */
|
||||||
#line 55 "grammar.lemon"
|
#line 55 "grammar.lemon"
|
||||||
{ yygotominor.yy0.dValue = pEval->GetVar(yymsp[0].minor.yy0.text); yygotominor.yy0.valid=true; }
|
{ yygotominor.yy0.dValue = yymsp[0].minor.yy0.dValue; yygotominor.yy0.valid=yymsp[0].minor.yy0.valid; }
|
||||||
#line 762 "grammar.c"
|
#line 716 "grammar.c"
|
||||||
break;
|
break;
|
||||||
case 10: /* expr ::= VAR ASSIGN expr */
|
case 10: /* expr ::= VAR */
|
||||||
#line 56 "grammar.lemon"
|
#line 56 "grammar.lemon"
|
||||||
{ pEval->SetVar(yymsp[-2].minor.yy0.text, yymsp[0].minor.yy0.dValue); yygotominor.yy0.dValue = yymsp[0].minor.yy0.dValue; yygotominor.yy0.valid=false; }
|
{ yygotominor.yy0.dValue = pEval->GetVar(yymsp[0].minor.yy0.text); yygotominor.yy0.valid=true; }
|
||||||
#line 767 "grammar.c"
|
#line 721 "grammar.c"
|
||||||
break;
|
break;
|
||||||
case 11: /* expr ::= expr PLUS expr */
|
case 11: /* expr ::= VAR ASSIGN expr */
|
||||||
#line 57 "grammar.lemon"
|
#line 57 "grammar.lemon"
|
||||||
{ yygotominor.yy0.dValue = yymsp[-2].minor.yy0.dValue + yymsp[0].minor.yy0.dValue; yygotominor.yy0.valid=yymsp[0].minor.yy0.valid; }
|
{ pEval->SetVar(yymsp[-2].minor.yy0.text, yymsp[0].minor.yy0.dValue); yygotominor.yy0.dValue = yymsp[0].minor.yy0.dValue; yygotominor.yy0.valid=false; }
|
||||||
#line 772 "grammar.c"
|
#line 726 "grammar.c"
|
||||||
break;
|
break;
|
||||||
case 12: /* expr ::= expr MINUS expr */
|
case 12: /* expr ::= expr PLUS expr */
|
||||||
#line 58 "grammar.lemon"
|
#line 58 "grammar.lemon"
|
||||||
{ yygotominor.yy0.dValue = yymsp[-2].minor.yy0.dValue - yymsp[0].minor.yy0.dValue; yygotominor.yy0.valid=yymsp[0].minor.yy0.valid; }
|
{ yygotominor.yy0.dValue = yymsp[-2].minor.yy0.dValue + yymsp[0].minor.yy0.dValue; yygotominor.yy0.valid=yymsp[0].minor.yy0.valid; }
|
||||||
#line 777 "grammar.c"
|
#line 731 "grammar.c"
|
||||||
break;
|
break;
|
||||||
case 13: /* expr ::= expr MULT expr */
|
case 13: /* expr ::= expr MINUS expr */
|
||||||
#line 59 "grammar.lemon"
|
#line 59 "grammar.lemon"
|
||||||
{ yygotominor.yy0.dValue = yymsp[-2].minor.yy0.dValue * yymsp[0].minor.yy0.dValue; yygotominor.yy0.valid=yymsp[0].minor.yy0.valid; }
|
{ yygotominor.yy0.dValue = yymsp[-2].minor.yy0.dValue - yymsp[0].minor.yy0.dValue; yygotominor.yy0.valid=yymsp[0].minor.yy0.valid; }
|
||||||
#line 782 "grammar.c"
|
#line 736 "grammar.c"
|
||||||
break;
|
break;
|
||||||
case 14: /* expr ::= expr DIVIDE expr */
|
case 14: /* expr ::= expr MULT expr */
|
||||||
#line 60 "grammar.lemon"
|
#line 60 "grammar.lemon"
|
||||||
|
{ yygotominor.yy0.dValue = yymsp[-2].minor.yy0.dValue * yymsp[0].minor.yy0.dValue; yygotominor.yy0.valid=yymsp[0].minor.yy0.valid; }
|
||||||
|
#line 741 "grammar.c"
|
||||||
|
break;
|
||||||
|
case 15: /* expr ::= expr DIVIDE expr */
|
||||||
|
#line 61 "grammar.lemon"
|
||||||
{
|
{
|
||||||
if (yymsp[0].minor.yy0.dValue != 0.0) {
|
if (yymsp[0].minor.yy0.dValue != 0.0) {
|
||||||
yygotominor.yy0.dValue = yymsp[-2].minor.yy0.dValue / yymsp[0].minor.yy0.dValue;
|
yygotominor.yy0.dValue = yymsp[-2].minor.yy0.dValue / yymsp[0].minor.yy0.dValue;
|
||||||
|
@ -789,12 +748,12 @@ static void yy_reduce(
|
||||||
else pEval->parseError("Div by zero");
|
else pEval->parseError("Div by zero");
|
||||||
yygotominor.yy0.valid=yymsp[0].minor.yy0.valid;
|
yygotominor.yy0.valid=yymsp[0].minor.yy0.valid;
|
||||||
}
|
}
|
||||||
#line 793 "grammar.c"
|
#line 752 "grammar.c"
|
||||||
break;
|
break;
|
||||||
case 15: /* expr ::= PARENL expr PARENR */
|
case 16: /* expr ::= PARENL expr PARENR */
|
||||||
#line 67 "grammar.lemon"
|
#line 68 "grammar.lemon"
|
||||||
{ yygotominor.yy0.dValue = yymsp[-1].minor.yy0.dValue; yygotominor.yy0.valid=yymsp[-1].minor.yy0.valid; }
|
{ yygotominor.yy0.dValue = yymsp[-1].minor.yy0.dValue; yygotominor.yy0.valid=yymsp[-1].minor.yy0.valid; }
|
||||||
#line 798 "grammar.c"
|
#line 757 "grammar.c"
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/* (0) main ::= in */ yytestcase(yyruleno==0);
|
/* (0) main ::= in */ yytestcase(yyruleno==0);
|
||||||
|
@ -802,16 +761,14 @@ static void yy_reduce(
|
||||||
/* (2) in ::= in stmt */ yytestcase(yyruleno==2);
|
/* (2) in ::= in stmt */ yytestcase(yyruleno==2);
|
||||||
/* (3) stmt ::= ENDS */ yytestcase(yyruleno==3);
|
/* (3) stmt ::= ENDS */ yytestcase(yyruleno==3);
|
||||||
break;
|
break;
|
||||||
/********** End reduce actions ************************************************/
|
|
||||||
};
|
};
|
||||||
assert( yyruleno>=0 && yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
|
|
||||||
yygoto = yyRuleInfo[yyruleno].lhs;
|
yygoto = yyRuleInfo[yyruleno].lhs;
|
||||||
yysize = yyRuleInfo[yyruleno].nrhs;
|
yysize = yyRuleInfo[yyruleno].nrhs;
|
||||||
yypParser->yyidx -= yysize;
|
yypParser->yyidx -= yysize;
|
||||||
yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto);
|
yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto);
|
||||||
if( yyact <= YY_MAX_SHIFTREDUCE ){
|
if( yyact < YYNSTATE ){
|
||||||
if( yyact>YY_MAX_SHIFT ) yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
|
#ifdef NDEBUG
|
||||||
/* If the reduce action popped at least
|
/* If we are not debugging and the reduce action popped at least
|
||||||
** one element off the stack, then we can push the new element back
|
** one element off the stack, then we can push the new element back
|
||||||
** onto the stack here, and skip the stack overflow test in yy_shift().
|
** onto the stack here, and skip the stack overflow test in yy_shift().
|
||||||
** That gives a significant speed improvement. */
|
** That gives a significant speed improvement. */
|
||||||
|
@ -821,12 +778,13 @@ static void yy_reduce(
|
||||||
yymsp->stateno = (YYACTIONTYPE)yyact;
|
yymsp->stateno = (YYACTIONTYPE)yyact;
|
||||||
yymsp->major = (YYCODETYPE)yygoto;
|
yymsp->major = (YYCODETYPE)yygoto;
|
||||||
yymsp->minor = yygotominor;
|
yymsp->minor = yygotominor;
|
||||||
yyTraceShift(yypParser, yyact);
|
}else
|
||||||
}else{
|
#endif
|
||||||
|
{
|
||||||
yy_shift(yypParser,yyact,yygoto,&yygotominor);
|
yy_shift(yypParser,yyact,yygoto,&yygotominor);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
assert( yyact == YY_ACCEPT_ACTION );
|
assert( yyact == YYNSTATE + YYNRULE + 1 );
|
||||||
yy_accept(yypParser);
|
yy_accept(yypParser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -847,8 +805,6 @@ static void yy_parse_failed(
|
||||||
while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
|
while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
|
||||||
/* Here code is inserted which will be executed whenever the
|
/* Here code is inserted which will be executed whenever the
|
||||||
** parser fails */
|
** parser fails */
|
||||||
/************ Begin %parse_failure code ***************************************/
|
|
||||||
/************ End %parse_failure code *****************************************/
|
|
||||||
ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
|
ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
|
||||||
}
|
}
|
||||||
#endif /* YYNOERRORRECOVERY */
|
#endif /* YYNOERRORRECOVERY */
|
||||||
|
@ -863,12 +819,10 @@ static void yy_syntax_error(
|
||||||
){
|
){
|
||||||
ParseARG_FETCH;
|
ParseARG_FETCH;
|
||||||
#define TOKEN (yyminor.yy0)
|
#define TOKEN (yyminor.yy0)
|
||||||
/************ Begin %syntax_error code ****************************************/
|
|
||||||
#line 33 "grammar.lemon"
|
#line 33 "grammar.lemon"
|
||||||
|
|
||||||
pEval->parseError("Syntax error");
|
pEval->parseError("Syntax error");
|
||||||
#line 871 "grammar.c"
|
#line 826 "grammar.c"
|
||||||
/************ End %syntax_error code ******************************************/
|
|
||||||
ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
|
ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -887,12 +841,10 @@ static void yy_accept(
|
||||||
while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
|
while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
|
||||||
/* Here code is inserted which will be executed whenever the
|
/* Here code is inserted which will be executed whenever the
|
||||||
** parser accepts */
|
** parser accepts */
|
||||||
/*********** Begin %parse_accept code *****************************************/
|
|
||||||
#line 37 "grammar.lemon"
|
#line 37 "grammar.lemon"
|
||||||
|
|
||||||
pEval->parseOk();
|
pEval->parseOk();
|
||||||
#line 895 "grammar.c"
|
#line 848 "grammar.c"
|
||||||
/*********** End %parse_accept code *******************************************/
|
|
||||||
ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
|
ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -923,9 +875,7 @@ void Parse(
|
||||||
){
|
){
|
||||||
YYMINORTYPE yyminorunion;
|
YYMINORTYPE yyminorunion;
|
||||||
int yyact; /* The parser action. */
|
int yyact; /* The parser action. */
|
||||||
#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
|
|
||||||
int yyendofinput; /* True if we are at the end of input */
|
int yyendofinput; /* True if we are at the end of input */
|
||||||
#endif
|
|
||||||
#ifdef YYERRORSYMBOL
|
#ifdef YYERRORSYMBOL
|
||||||
int yyerrorhit = 0; /* True if yymajor has invoked an error */
|
int yyerrorhit = 0; /* True if yymajor has invoked an error */
|
||||||
#endif
|
#endif
|
||||||
|
@ -946,34 +896,26 @@ void Parse(
|
||||||
yypParser->yyerrcnt = -1;
|
yypParser->yyerrcnt = -1;
|
||||||
yypParser->yystack[0].stateno = 0;
|
yypParser->yystack[0].stateno = 0;
|
||||||
yypParser->yystack[0].major = 0;
|
yypParser->yystack[0].major = 0;
|
||||||
#ifndef NDEBUG
|
|
||||||
if( yyTraceFILE ){
|
|
||||||
fprintf(yyTraceFILE,"%sInitialize. Empty stack. State 0\n",
|
|
||||||
yyTracePrompt);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
yyminorunion.yy0 = yyminor;
|
yyminorunion.yy0 = yyminor;
|
||||||
#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
|
|
||||||
yyendofinput = (yymajor==0);
|
yyendofinput = (yymajor==0);
|
||||||
#endif
|
|
||||||
ParseARG_STORE;
|
ParseARG_STORE;
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if( yyTraceFILE ){
|
if( yyTraceFILE ){
|
||||||
fprintf(yyTraceFILE,"%sInput '%s'\n",yyTracePrompt,yyTokenName[yymajor]);
|
fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
do{
|
do{
|
||||||
yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor);
|
yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor);
|
||||||
if( yyact <= YY_MAX_SHIFTREDUCE ){
|
if( yyact<YYNSTATE ){
|
||||||
if( yyact > YY_MAX_SHIFT ) yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
|
assert( !yyendofinput ); /* Impossible to shift the $ token */
|
||||||
yy_shift(yypParser,yyact,yymajor,&yyminorunion);
|
yy_shift(yypParser,yyact,yymajor,&yyminorunion);
|
||||||
yypParser->yyerrcnt--;
|
yypParser->yyerrcnt--;
|
||||||
yymajor = YYNOCODE;
|
yymajor = YYNOCODE;
|
||||||
}else if( yyact <= YY_MAX_REDUCE ){
|
}else if( yyact < YYNSTATE + YYNRULE ){
|
||||||
yy_reduce(yypParser,yyact-YY_MIN_REDUCE);
|
yy_reduce(yypParser,yyact-YYNSTATE);
|
||||||
}else{
|
}else{
|
||||||
assert( yyact == YY_ERROR_ACTION );
|
assert( yyact == YY_ERROR_ACTION );
|
||||||
#ifdef YYERRORSYMBOL
|
#ifdef YYERRORSYMBOL
|
||||||
|
@ -1023,7 +965,7 @@ void Parse(
|
||||||
yymx != YYERRORSYMBOL &&
|
yymx != YYERRORSYMBOL &&
|
||||||
(yyact = yy_find_reduce_action(
|
(yyact = yy_find_reduce_action(
|
||||||
yypParser->yystack[yypParser->yyidx].stateno,
|
yypParser->yystack[yypParser->yyidx].stateno,
|
||||||
YYERRORSYMBOL)) >= YY_MIN_REDUCE
|
YYERRORSYMBOL)) >= YYNSTATE
|
||||||
){
|
){
|
||||||
yy_pop_parser_stack(yypParser);
|
yy_pop_parser_stack(yypParser);
|
||||||
}
|
}
|
||||||
|
@ -1073,15 +1015,5 @@ void Parse(
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}while( yymajor!=YYNOCODE && yypParser->yyidx>=0 );
|
}while( yymajor!=YYNOCODE && yypParser->yyidx>=0 );
|
||||||
#ifndef NDEBUG
|
|
||||||
if( yyTraceFILE ){
|
|
||||||
int i;
|
|
||||||
fprintf(yyTraceFILE,"%sReturn. Stack=",yyTracePrompt);
|
|
||||||
for(i=1; i<=yypParser->yyidx; i++)
|
|
||||||
fprintf(yyTraceFILE,"%c%s", i==1 ? '[' : ' ',
|
|
||||||
yyTokenName[yypParser->yystack[i].major]);
|
|
||||||
fprintf(yyTraceFILE,"]\n");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,7 @@ stmt ::= expr SEMCOL. { pEval->parseSetResult(NAN); }
|
||||||
expr(A) ::= VALUE(B). { A.dValue = B.dValue; A.valid=true; }
|
expr(A) ::= VALUE(B). { A.dValue = B.dValue; A.valid=true; }
|
||||||
expr(A) ::= expr(B) UNIT(C). { A.dValue = B.dValue * C.dValue; A.valid=B.valid; }
|
expr(A) ::= expr(B) UNIT(C). { A.dValue = B.dValue * C.dValue; A.valid=B.valid; }
|
||||||
expr(A) ::= MINUS expr(B). { A.dValue = -B.dValue; A.valid=B.valid; }
|
expr(A) ::= MINUS expr(B). { A.dValue = -B.dValue; A.valid=B.valid; }
|
||||||
|
expr(A) ::= PLUS expr(B). { A.dValue = B.dValue; A.valid=B.valid; }
|
||||||
expr(A) ::= VAR(B). { A.dValue = pEval->GetVar(B.text); A.valid=true; }
|
expr(A) ::= VAR(B). { A.dValue = pEval->GetVar(B.text); A.valid=true; }
|
||||||
expr(A) ::= VAR(B) ASSIGN expr(C). { pEval->SetVar(B.text, C.dValue); A.dValue = C.dValue; A.valid=false; }
|
expr(A) ::= VAR(B) ASSIGN expr(C). { pEval->SetVar(B.text, C.dValue); A.dValue = C.dValue; A.valid=false; }
|
||||||
expr(A) ::= expr(B) PLUS expr(C). { A.dValue = B.dValue + C.dValue; A.valid=C.valid; }
|
expr(A) ::= expr(B) PLUS expr(C). { A.dValue = B.dValue + C.dValue; A.valid=C.valid; }
|
||||||
|
|
|
@ -143,8 +143,8 @@ static const std::vector<EVAL_CASE> eval_cases_valid = {
|
||||||
{ "(1)", "1" },
|
{ "(1)", "1" },
|
||||||
// Parens affect precedence
|
// Parens affect precedence
|
||||||
{ "-(1 + (2 - 4)) * 20.8 / 2", "10.4" },
|
{ "-(1 + (2 - 4)) * 20.8 / 2", "10.4" },
|
||||||
// Unary addition, not a leading operator
|
// Unary addition is a sign, not a leading operator
|
||||||
//{ "+2 - 1", "1" } // TODO: This does not come out as valid
|
{ "+2 - 1", "1" },
|
||||||
// Unknown vars are 0.0
|
// Unknown vars are 0.0
|
||||||
{ "1 + unknown", "1" },
|
{ "1 + unknown", "1" },
|
||||||
// Set var in-string
|
// Set var in-string
|
||||||
|
@ -187,7 +187,6 @@ static const std::vector<EVAL_INVALID_CASE> eval_cases_invalid = {
|
||||||
// Trailing operator
|
// Trailing operator
|
||||||
{ "1+" },
|
{ "1+" },
|
||||||
// Leading operator
|
// Leading operator
|
||||||
{ "+2 + 1" },
|
|
||||||
{ "*2 + 1" },
|
{ "*2 + 1" },
|
||||||
// No operator
|
// No operator
|
||||||
{ "1 2" },
|
{ "1 2" },
|
||||||
|
|
Loading…
Reference in New Issue