From 3ee7b209270e7b2948086ccc48639102eb937e1d Mon Sep 17 00:00:00 2001 From: jriegel Date: Sun, 22 Sep 2013 18:03:28 +0200 Subject: [PATCH] first finished implementation of Quantity parser --- src/Base/Parser.bat | 4 +- src/Base/Parser.sh | 2 + src/Base/Quantity.cpp | 1 + src/Base/Quantity.h | 3 + src/Base/QuantityLexer.c | 1810 +++++++++++++++++++++--------------- src/Base/QuantityParser.c | 1040 +++++++++++++-------- src/Base/QuantityParser.l | 96 +- src/Base/QuantityParser.y | 51 +- src/Base/QuantityPyImp.cpp | 6 +- src/Base/Unit.cpp | 130 ++- src/Base/Unit.h | 1 + src/Base/UnitsApi.h | 1 + src/Base/UnitsApiPy.cpp | 27 + 13 files changed, 1988 insertions(+), 1184 deletions(-) create mode 100644 src/Base/Parser.sh diff --git a/src/Base/Parser.bat b/src/Base/Parser.bat index 8d9394cf2..9a8ced0a8 100644 --- a/src/Base/Parser.bat +++ b/src/Base/Parser.bat @@ -1,2 +1,2 @@ -C:\Tools\GnuWin32\bin\flex.exe -oQuantityLexer.c QuantityParser.l -C:\Tools\GnuWin32\bin\bison -oQuantityParser.c QuantityParser.y \ No newline at end of file +C:\cygwin\bin\flex.exe -oQuantityLexer.c QuantityParser.l +C:\cygwin\bin\bison -oQuantityParser.c QuantityParser.y \ No newline at end of file diff --git a/src/Base/Parser.sh b/src/Base/Parser.sh new file mode 100644 index 000000000..20b8d91f6 --- /dev/null +++ b/src/Base/Parser.sh @@ -0,0 +1,2 @@ +flex -oQuantityLexer.c QuantityParser.l +bison -oQuantityParser.c QuantityParser.y \ No newline at end of file diff --git a/src/Base/Quantity.cpp b/src/Base/Quantity.cpp index 29e6e4bfb..1c80c56b4 100644 --- a/src/Base/Quantity.cpp +++ b/src/Base/Quantity.cpp @@ -127,6 +127,7 @@ void Quantity_yyerror(char *errorinfo) namespace QuantityParser { +#define YYINITDEPTH 20 // show the parser the lexer method #define yylex QuantityLexer int QuantityLexer(void); diff --git a/src/Base/Quantity.h b/src/Base/Quantity.h index 232435bf6..524d0e473 100644 --- a/src/Base/Quantity.h +++ b/src/Base/Quantity.h @@ -55,6 +55,9 @@ public: static Quantity parse(const char* buffer); + const Unit & getUnit(void) const{return _Unit;} + double getValue(void) const{return _Value;} + protected: double _Value; Unit _Unit; diff --git a/src/Base/QuantityLexer.c b/src/Base/QuantityLexer.c index 3ed01975a..52830709a 100644 --- a/src/Base/QuantityLexer.c +++ b/src/Base/QuantityLexer.c @@ -1,67 +1,113 @@ #line 2 "QuantityLexer.c" -/* A lexical scanner generated by flex */ -/* Scanner skeleton version: - * $Header: /home/daffy/u0/vern/flex/RCS/flex.skl,v 2.91 96/09/10 16:58:48 vern Exp $ - */ +#line 4 "QuantityLexer.c" + +#define YY_INT_ALIGNED short int + +/* A lexical scanner generated by flex */ #define FLEX_SCANNER #define YY_FLEX_MAJOR_VERSION 2 #define YY_FLEX_MINOR_VERSION 5 +#define YY_FLEX_SUBMINOR_VERSION 35 +#if YY_FLEX_SUBMINOR_VERSION > 0 +#define FLEX_BETA +#endif +/* First, we deal with platform-specific or compiler-specific issues. */ + +/* begin standard C headers. */ #include - - -/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */ -#ifdef c_plusplus -#ifndef __cplusplus -#define __cplusplus -#endif -#endif - - -#ifdef __cplusplus - +#include +#include #include -/* Use prototypes in function declarations. */ -#define YY_USE_PROTOS +/* end standard C headers. */ + +/* flex integer type definitions */ + +#ifndef FLEXINT_H +#define FLEXINT_H + +/* C99 systems have . Non-C99 systems may or may not. */ + +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + +/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, + * if you want the limit (max/min) macros for int types. + */ +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif + +#include +typedef int8_t flex_int8_t; +typedef uint8_t flex_uint8_t; +typedef int16_t flex_int16_t; +typedef uint16_t flex_uint16_t; +typedef int32_t flex_int32_t; +typedef uint32_t flex_uint32_t; +#else +typedef signed char flex_int8_t; +typedef short int flex_int16_t; +typedef int flex_int32_t; +typedef unsigned char flex_uint8_t; +typedef unsigned short int flex_uint16_t; +typedef unsigned int flex_uint32_t; +#endif /* ! C99 */ + +/* Limits of integral types. */ +#ifndef INT8_MIN +#define INT8_MIN (-128) +#endif +#ifndef INT16_MIN +#define INT16_MIN (-32767-1) +#endif +#ifndef INT32_MIN +#define INT32_MIN (-2147483647-1) +#endif +#ifndef INT8_MAX +#define INT8_MAX (127) +#endif +#ifndef INT16_MAX +#define INT16_MAX (32767) +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif +#ifndef UINT8_MAX +#define UINT8_MAX (255U) +#endif +#ifndef UINT16_MAX +#define UINT16_MAX (65535U) +#endif +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + +#endif /* ! FLEXINT_H */ + +#ifdef __cplusplus /* The "const" storage-class-modifier is valid. */ #define YY_USE_CONST #else /* ! __cplusplus */ -#if __STDC__ +/* C99 requires __STDC__ to be defined as 1. */ +#if defined (__STDC__) -#define YY_USE_PROTOS #define YY_USE_CONST -#endif /* __STDC__ */ +#endif /* defined (__STDC__) */ #endif /* ! __cplusplus */ -#ifdef __TURBOC__ - #pragma warn -rch - #pragma warn -use -#include -#include -#define YY_USE_CONST -#define YY_USE_PROTOS -#endif - #ifdef YY_USE_CONST #define yyconst const #else #define yyconst #endif - -#ifdef YY_USE_PROTOS -#define YY_PROTO(proto) proto -#else -#define YY_PROTO(proto) () -#endif - /* Returned upon end-of-file. */ #define YY_NULL 0 @@ -76,71 +122,70 @@ * but we do it the disgusting crufty way forced on us by the ()-less * definition of BEGIN. */ -#define BEGIN yy_start = 1 + 2 * +#define BEGIN (yy_start) = 1 + 2 * /* Translate the current start state into a value that can be later handed * to BEGIN to return to the state. The YYSTATE alias is for lex * compatibility. */ -#define YY_START ((yy_start - 1) / 2) +#define YY_START (((yy_start) - 1) / 2) #define YYSTATE YY_START /* Action number for EOF rule of a given start state. */ #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) /* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE yyrestart( yyin ) +#define YY_NEW_FILE yyrestart(yyin ) #define YY_END_OF_BUFFER_CHAR 0 /* Size of default input buffer. */ +#ifndef YY_BUF_SIZE #define YY_BUF_SIZE 16384 +#endif +/* The state buf must be large enough to hold one state per character in the main buffer. + */ +#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) + +#ifndef YY_TYPEDEF_YY_BUFFER_STATE +#define YY_TYPEDEF_YY_BUFFER_STATE typedef struct yy_buffer_state *YY_BUFFER_STATE; +#endif extern int yyleng; + extern FILE *yyin, *yyout; #define EOB_ACT_CONTINUE_SCAN 0 #define EOB_ACT_END_OF_FILE 1 #define EOB_ACT_LAST_MATCH 2 -/* The funky do-while in the following #define is used to turn the definition - * int a single C statement (which needs a semi-colon terminator). This - * avoids problems with code like: - * - * if ( condition_holds ) - * yyless( 5 ); - * else - * do_something_else(); - * - * Prior to using the do-while the compiler would get upset at the - * "else" because it interpreted the "if" statement as being all - * done when it reached the ';' after the yyless() call. - */ - -/* Return all but the first 'n' matched characters back to the input stream. */ - + #define YY_LESS_LINENO(n) + +/* Return all but the first "n" matched characters back to the input stream. */ #define yyless(n) \ do \ { \ /* Undo effects of setting up yytext. */ \ - *yy_cp = yy_hold_char; \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + *yy_cp = (yy_hold_char); \ YY_RESTORE_YY_MORE_OFFSET \ - yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \ + (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ YY_DO_BEFORE_ACTION; /* set up yytext again */ \ } \ while ( 0 ) -#define unput(c) yyunput( c, yytext_ptr ) - -/* The following is because we cannot portably get our hands on size_t - * (without autoconf's help, which isn't available because we want - * flex-generated scanners to compile on their own). - */ -typedef unsigned int yy_size_t; +#define unput(c) yyunput( c, (yytext_ptr) ) +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif +#ifndef YY_STRUCT_YY_BUFFER_STATE +#define YY_STRUCT_YY_BUFFER_STATE struct yy_buffer_state { FILE *yy_input_file; @@ -177,12 +222,16 @@ struct yy_buffer_state */ int yy_at_bol; + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + /* Whether to try to fill the input buffer when we reach the * end of it. */ int yy_fill_buffer; int yy_buffer_status; + #define YY_BUFFER_NEW 0 #define YY_BUFFER_NORMAL 1 /* When an EOF's been seen but there's still some text to process @@ -196,28 +245,38 @@ struct yy_buffer_state * just pointing yyin at a new input file. */ #define YY_BUFFER_EOF_PENDING 2 - }; -static YY_BUFFER_STATE yy_current_buffer = 0; + }; +#endif /* !YY_STRUCT_YY_BUFFER_STATE */ + +/* Stack of input buffers. */ +static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ +static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ +static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ /* We provide macros for accessing buffer states in case in the * future we want to put the buffer states in a more general * "scanner state". + * + * Returns the top of the stack, or NULL. */ -#define YY_CURRENT_BUFFER yy_current_buffer +#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ + ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ + : NULL) +/* Same as previous macro, but useful when we know that the buffer stack is not + * NULL or when we need an lvalue. For internal use only. + */ +#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] /* yy_hold_char holds the character lost when yytext is formed. */ static char yy_hold_char; - static int yy_n_chars; /* number of characters read into yy_ch_buf */ - - int yyleng; /* Points to current character in buffer. */ static char *yy_c_buf_p = (char *) 0; -static int yy_init = 1; /* whether we need to initialize */ +static int yy_init = 0; /* whether we need to initialize */ static int yy_start = 0; /* start state number */ /* Flag which is used to allow yywrap()'s to do buffer switches @@ -225,95 +284,124 @@ static int yy_start = 0; /* start state number */ */ static int yy_did_buffer_switch_on_eof; -void yyrestart YY_PROTO(( FILE *input_file )); +void yyrestart (FILE *input_file ); +void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ); +YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ); +void yy_delete_buffer (YY_BUFFER_STATE b ); +void yy_flush_buffer (YY_BUFFER_STATE b ); +void yypush_buffer_state (YY_BUFFER_STATE new_buffer ); +void yypop_buffer_state (void ); -void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer )); -void yy_load_buffer_state YY_PROTO(( void )); -YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size )); -void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b )); -void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file )); -void yy_flush_buffer YY_PROTO(( YY_BUFFER_STATE b )); -#define YY_FLUSH_BUFFER yy_flush_buffer( yy_current_buffer ) +static void yyensure_buffer_stack (void ); +static void yy_load_buffer_state (void ); +static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ); -YY_BUFFER_STATE yy_scan_buffer YY_PROTO(( char *base, yy_size_t size )); -YY_BUFFER_STATE yy_scan_string YY_PROTO(( yyconst char *yy_str )); -YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst char *bytes, int len )); +#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ) -static void *yy_flex_alloc YY_PROTO(( yy_size_t )); -static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t )); -static void yy_flex_free YY_PROTO(( void * )); +YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); +YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); +YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len ); + +void *yyalloc (yy_size_t ); +void *yyrealloc (void *,yy_size_t ); +void yyfree (void * ); #define yy_new_buffer yy_create_buffer #define yy_set_interactive(is_interactive) \ { \ - if ( ! yy_current_buffer ) \ - yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \ - yy_current_buffer->yy_is_interactive = is_interactive; \ + if ( ! YY_CURRENT_BUFFER ){ \ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer(yyin,YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ } #define yy_set_bol(at_bol) \ { \ - if ( ! yy_current_buffer ) \ - yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \ - yy_current_buffer->yy_at_bol = at_bol; \ + if ( ! YY_CURRENT_BUFFER ){\ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer(yyin,YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ } -#define YY_AT_BOL() (yy_current_buffer->yy_at_bol) +#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) - -#define yywrap() 1 +#define yywrap(n) 1 #define YY_SKIP_YYWRAP + typedef unsigned char YY_CHAR; + FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; + typedef int yy_state_type; + +extern int yylineno; + +int yylineno = 1; + extern char *yytext; #define yytext_ptr yytext -static yy_state_type yy_get_previous_state YY_PROTO(( void )); -static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state )); -static int yy_get_next_buffer YY_PROTO(( void )); -static void yy_fatal_error YY_PROTO(( yyconst char msg[] )); +static yy_state_type yy_get_previous_state (void ); +static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); +static int yy_get_next_buffer (void ); +static void yy_fatal_error (yyconst char msg[] ); /* Done after the current pattern has been matched and before the * corresponding action - sets up yytext. */ #define YY_DO_BEFORE_ACTION \ - yytext_ptr = yy_bp; \ - yyleng = (int) (yy_cp - yy_bp); \ - yy_hold_char = *yy_cp; \ + (yytext_ptr) = yy_bp; \ + yyleng = (size_t) (yy_cp - yy_bp); \ + (yy_hold_char) = *yy_cp; \ *yy_cp = '\0'; \ - yy_c_buf_p = yy_cp; + (yy_c_buf_p) = yy_cp; -#define YY_NUM_RULES 40 -#define YY_END_OF_BUFFER 41 -static yyconst short int yy_accept[63] = +#define YY_NUM_RULES 63 +#define YY_END_OF_BUFFER 64 +/* This struct is not used in this scanner, + but its presence is necessary. */ +struct yy_trans_info + { + flex_int32_t yy_verify; + flex_int32_t yy_nxt; + }; +static yyconst flex_int16_t yy_accept[107] = { 0, - 0, 0, 41, 40, 1, 2, 10, 12, 3, 37, - 29, 30, 40, 40, 39, 40, 16, 28, 40, 40, - 35, 5, 40, 40, 40, 26, 18, 40, 2, 36, - 37, 31, 6, 0, 0, 7, 11, 0, 9, 15, - 8, 19, 17, 0, 34, 4, 0, 20, 38, 0, - 21, 13, 33, 14, 36, 22, 23, 25, 27, 32, - 24, 0 + 0, 0, 64, 63, 1, 2, 33, 35, 3, 44, + 20, 24, 63, 63, 63, 63, 46, 63, 14, 19, + 63, 63, 11, 9, 63, 63, 63, 63, 17, 16, + 63, 2, 43, 44, 23, 0, 0, 0, 0, 28, + 7, 0, 0, 0, 8, 0, 34, 0, 32, 22, + 15, 10, 38, 0, 21, 25, 13, 0, 6, 0, + 4, 39, 45, 0, 0, 0, 0, 40, 0, 36, + 26, 12, 5, 37, 43, 0, 53, 0, 0, 0, + 51, 41, 29, 52, 31, 55, 18, 54, 27, 57, + 30, 58, 0, 60, 0, 42, 47, 48, 49, 0, + + 59, 62, 61, 50, 56, 0 } ; -static yyconst int yy_ec[256] = +static yyconst flex_int32_t yy_ec[256] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 4, 1, 1, 1, 1, 5, 6, - 6, 6, 6, 1, 6, 7, 6, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 1, 1, 1, - 6, 1, 1, 1, 9, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 10, 1, 1, 1, 1, 1, + 6, 6, 7, 8, 7, 8, 6, 9, 10, 11, + 12, 12, 12, 12, 12, 12, 12, 1, 1, 1, + 6, 1, 1, 1, 13, 1, 1, 1, 14, 1, + 1, 1, 1, 1, 15, 1, 16, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 6, 1, 1, 11, 12, 13, 14, + 1, 1, 1, 6, 1, 1, 17, 18, 19, 20, - 15, 16, 17, 18, 19, 1, 20, 21, 22, 23, - 24, 25, 1, 26, 27, 28, 1, 1, 29, 1, - 30, 31, 1, 1, 1, 1, 1, 1, 1, 1, + 21, 22, 23, 24, 25, 1, 26, 27, 28, 29, + 30, 31, 32, 33, 34, 35, 1, 1, 36, 37, + 38, 39, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -330,71 +418,98 @@ static yyconst int yy_ec[256] = 1, 1, 1, 1, 1 } ; -static yyconst int yy_meta[32] = +static yyconst flex_int32_t yy_meta[40] = { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1 + 1, 1, 1, 2, 1, 1, 1, 2, 3, 3, + 3, 3, 1, 4, 1, 1, 1, 1, 1, 1, + 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1 } ; -static yyconst short int yy_base[63] = +static yyconst flex_int16_t yy_base[109] = { 0, - 0, 0, 69, 70, 70, 65, 70, 70, 70, 25, - 70, 70, 20, 21, 70, 43, 42, 70, 42, 18, - 52, 33, 32, 43, 50, 32, 41, 18, 55, 48, - 30, 70, 70, 25, 34, 70, 70, 25, 70, 70, - 70, 70, 70, 24, 70, 70, 25, 70, 70, 31, - 70, 70, 70, 70, 33, 70, 70, 70, 70, 70, - 70, 70 + 0, 0, 134, 135, 135, 130, 135, 135, 135, 36, + 135, 135, 119, 23, 23, 24, 94, 100, 99, 135, + 99, 33, 30, 49, 99, 87, 24, 108, 38, 51, + 61, 121, 57, 61, 135, 89, 92, 96, 103, 135, + 135, 85, 83, 94, 135, 85, 135, 86, 135, 135, + 135, 135, 135, 91, 135, 135, 135, 84, 135, 60, + 135, 135, 135, 76, 91, 63, 58, 135, 61, 135, + 135, 135, 135, 135, 67, 86, 135, 52, 56, 54, + 135, 135, 135, 135, 135, 72, 135, 135, 135, 135, + 135, 43, 31, 31, 90, 94, 135, 135, 39, 38, + + 135, 135, 135, 135, 135, 135, 105, 106 } ; -static yyconst short int yy_def[63] = +static yyconst flex_int16_t yy_def[109] = { 0, - 62, 1, 62, 62, 62, 62, 62, 62, 62, 62, - 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, - 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, - 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, - 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, - 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, - 62, 0 + 106, 1, 106, 106, 106, 106, 106, 106, 106, 107, + 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, + 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, + 106, 106, 108, 107, 106, 106, 106, 106, 106, 106, + 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, + 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, + 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, + 106, 106, 106, 106, 108, 106, 106, 106, 106, 106, + 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, + 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, + + 106, 106, 106, 106, 106, 0, 106, 106 } ; -static yyconst short int yy_nxt[102] = +static yyconst flex_int16_t yy_nxt[175] = { 0, - 4, 5, 6, 7, 8, 9, 4, 10, 11, 12, - 4, 4, 13, 14, 15, 16, 17, 18, 19, 20, - 21, 22, 4, 23, 24, 25, 26, 27, 4, 28, - 4, 30, 31, 32, 40, 35, 30, 31, 53, 41, - 55, 33, 36, 54, 61, 60, 59, 58, 34, 43, - 57, 44, 56, 45, 46, 55, 47, 29, 52, 51, - 50, 49, 48, 42, 39, 38, 37, 29, 62, 3, - 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, - 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, - 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, + 4, 5, 6, 7, 8, 9, 9, 4, 10, 10, + 10, 10, 11, 4, 12, 13, 14, 4, 15, 16, + 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, + 27, 4, 28, 29, 30, 4, 4, 31, 4, 33, + 36, 37, 40, 33, 44, 50, 105, 53, 63, 104, + 41, 45, 42, 64, 103, 51, 38, 39, 43, 54, + 52, 55, 66, 56, 33, 102, 101, 69, 33, 67, + 76, 57, 68, 58, 70, 71, 59, 76, 60, 88, + 76, 100, 99, 72, 98, 97, 89, 76, 73, 94, + 93, 92, 95, 74, 96, 96, 96, 96, 96, 96, - 62 + 96, 96, 96, 96, 96, 96, 34, 34, 75, 75, + 91, 90, 87, 86, 85, 84, 83, 82, 81, 80, + 79, 78, 77, 32, 65, 62, 61, 49, 48, 47, + 46, 35, 32, 106, 3, 106, 106, 106, 106, 106, + 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, + 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, + 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, + 106, 106, 106, 106 } ; -static yyconst short int yy_chk[102] = +static yyconst flex_int16_t yy_chk[175] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 10, 10, 13, 20, 14, 31, 31, 28, 20, - 55, 13, 14, 28, 50, 47, 44, 38, 13, 22, - 35, 22, 34, 22, 22, 30, 22, 29, 27, 26, - 25, 24, 23, 21, 19, 17, 16, 6, 3, 62, - 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, - 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, - 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 10, + 14, 14, 15, 10, 16, 22, 100, 23, 27, 99, + 15, 16, 15, 27, 94, 22, 14, 14, 15, 23, + 22, 24, 29, 24, 34, 93, 92, 30, 34, 29, + 33, 24, 29, 24, 30, 31, 24, 33, 24, 60, + 75, 86, 80, 31, 79, 78, 60, 75, 31, 69, + 67, 66, 76, 31, 76, 76, 76, 76, 95, 95, - 62 + 95, 95, 96, 96, 96, 96, 107, 107, 108, 108, + 65, 64, 58, 54, 48, 46, 44, 43, 42, 39, + 38, 37, 36, 32, 28, 26, 25, 21, 19, 18, + 17, 13, 6, 3, 106, 106, 106, 106, 106, 106, + 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, + 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, + 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, + 106, 106, 106, 106 } ; static yy_state_type yy_last_accepting_state; static char *yy_last_accepting_cpos; +extern int yy_flex_debug; +int yy_flex_debug = 0; + /* The intent behind this definition is that it'll catch * any uses of REJECT which flex missed. */ @@ -404,7 +519,6 @@ static char *yy_last_accepting_cpos; #define YY_RESTORE_YY_MORE_OFFSET char *yytext; #line 1 "QuantityParser.l" -#define INITIAL 0 #line 2 "QuantityParser.l" /* Lexer for the FreeCAD Units language */ /* (c) 2013 Juergen Riegel LGPL */ @@ -416,10 +530,53 @@ char *yytext; /*** Flex Declarations and Options ***/ /* the manual says "somewhat more optimized" */ -#define YY_NEVER_INTERACTIVE 1 /* no support for include files is planned */ -#define YY_NO_UNPUT 1 -#line 424 "QuantityLexer.c" +#line 535 "QuantityLexer.c" + +#define INITIAL 0 + +#ifndef YY_NO_UNISTD_H +/* Special case for "unistd.h", since it is non-ANSI. We include it way + * down here because we want the user's section 1 to have been scanned first. + * The user has a chance to override it with an option. + */ +#include +#endif + +#ifndef YY_EXTRA_TYPE +#define YY_EXTRA_TYPE void * +#endif + +static int yy_init_globals (void ); + +/* Accessor methods to globals. + These are made visible to non-reentrant scanners for convenience. */ + +int yylex_destroy (void ); + +int yyget_debug (void ); + +void yyset_debug (int debug_flag ); + +YY_EXTRA_TYPE yyget_extra (void ); + +void yyset_extra (YY_EXTRA_TYPE user_defined ); + +FILE *yyget_in (void ); + +void yyset_in (FILE * in_str ); + +FILE *yyget_out (void ); + +void yyset_out (FILE * out_str ); + +int yyget_leng (void ); + +char *yyget_text (void ); + +int yyget_lineno (void ); + +void yyset_lineno (int line_number ); /* Macros after this point can all be overridden by user definitions in * section 1. @@ -427,65 +584,28 @@ char *yytext; #ifndef YY_SKIP_YYWRAP #ifdef __cplusplus -extern "C" int yywrap YY_PROTO(( void )); +extern "C" int yywrap (void ); #else -extern int yywrap YY_PROTO(( void )); +extern int yywrap (void ); #endif #endif -#ifndef YY_NO_UNPUT -static void yyunput YY_PROTO(( int c, char *buf_ptr )); -#endif - #ifndef yytext_ptr -static void yy_flex_strncpy YY_PROTO(( char *, yyconst char *, int )); +static void yy_flex_strncpy (char *,yyconst char *,int ); #endif #ifdef YY_NEED_STRLEN -static int yy_flex_strlen YY_PROTO(( yyconst char * )); +static int yy_flex_strlen (yyconst char * ); #endif #ifndef YY_NO_INPUT + #ifdef __cplusplus -static int yyinput YY_PROTO(( void )); +static int yyinput (void ); #else -static int input YY_PROTO(( void )); -#endif +static int input (void ); #endif -#if YY_STACK_USED -static int yy_start_stack_ptr = 0; -static int yy_start_stack_depth = 0; -static int *yy_start_stack = 0; -#ifndef YY_NO_PUSH_STATE -static void yy_push_state YY_PROTO(( int new_state )); -#endif -#ifndef YY_NO_POP_STATE -static void yy_pop_state YY_PROTO(( void )); -#endif -#ifndef YY_NO_TOP_STATE -static int yy_top_state YY_PROTO(( void )); -#endif - -#else -#define YY_NO_PUSH_STATE 1 -#define YY_NO_POP_STATE 1 -#define YY_NO_TOP_STATE 1 -#endif - -#ifdef YY_MALLOC_DECL -YY_MALLOC_DECL -#else -#if __STDC__ -#ifndef __cplusplus -#include -#endif -#else -/* Just try to get by without declaring the routines. This will fail - * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int) - * or sizeof(void*) != sizeof(int). - */ -#endif #endif /* Amount of stuff to slurp up with each read. */ @@ -494,12 +614,11 @@ YY_MALLOC_DECL #endif /* Copy whatever the last rule matched to the standard output. */ - #ifndef ECHO /* This used to be an fputs(), but since the string might contain NUL's, * we now use fwrite(). */ -#define ECHO (void) fwrite( yytext, yyleng, 1, yyout ) +#define ECHO fwrite( yytext, yyleng, 1, yyout ) #endif /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, @@ -507,9 +626,10 @@ YY_MALLOC_DECL */ #ifndef YY_INPUT #define YY_INPUT(buf,result,max_size) \ - if ( yy_current_buffer->yy_is_interactive ) \ + if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ { \ - int c = '*', n; \ + int c = '*'; \ + int n; \ for ( n = 0; n < max_size && \ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ buf[n] = (char) c; \ @@ -519,9 +639,22 @@ YY_MALLOC_DECL YY_FATAL_ERROR( "input in flex scanner failed" ); \ result = n; \ } \ - else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \ - && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); + else \ + { \ + errno=0; \ + while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ + { \ + if( errno != EINTR) \ + { \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + break; \ + } \ + errno=0; \ + clearerr(yyin); \ + } \ + }\ +\ + #endif /* No semi-colon after return; correct usage is to write "yyterminate();" - @@ -542,12 +675,18 @@ YY_MALLOC_DECL #define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) #endif +/* end tables serialization structures and prototypes */ + /* Default declaration of generated scanner - a define so the user can * easily add parameters. */ #ifndef YY_DECL -#define YY_DECL int yylex YY_PROTO(( void )) -#endif +#define YY_DECL_IS_OURS 1 + +extern int yylex (void); + +#define YY_DECL int yylex (void) +#endif /* !YY_DECL */ /* Code executed at the beginning of each rule, after yytext and yyleng * have been set up. @@ -564,28 +703,30 @@ YY_MALLOC_DECL #define YY_RULE_SETUP \ YY_USER_ACTION +/** The main scanner function which does all the work. + */ YY_DECL - { +{ register yy_state_type yy_current_state; register char *yy_cp, *yy_bp; register int yy_act; - + #line 27 "QuantityParser.l" -#line 579 "QuantityLexer.c" +#line 719 "QuantityLexer.c" - if ( yy_init ) + if ( !(yy_init) ) { - yy_init = 0; + (yy_init) = 1; #ifdef YY_USER_INIT YY_USER_INIT; #endif - if ( ! yy_start ) - yy_start = 1; /* first start state */ + if ( ! (yy_start) ) + (yy_start) = 1; /* first start state */ if ( ! yyin ) yyin = stdin; @@ -593,64 +734,64 @@ YY_DECL if ( ! yyout ) yyout = stdout; - if ( ! yy_current_buffer ) - yy_current_buffer = - yy_create_buffer( yyin, YY_BUF_SIZE ); + if ( ! YY_CURRENT_BUFFER ) { + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer(yyin,YY_BUF_SIZE ); + } - yy_load_buffer_state(); + yy_load_buffer_state( ); } while ( 1 ) /* loops until end-of-file is reached */ { - yy_cp = yy_c_buf_p; + yy_cp = (yy_c_buf_p); /* Support of yytext. */ - *yy_cp = yy_hold_char; + *yy_cp = (yy_hold_char); /* yy_bp points to the position in yy_ch_buf of the start of * the current run. */ yy_bp = yy_cp; - yy_current_state = yy_start; + yy_current_state = (yy_start); yy_match: do { register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; if ( yy_accept[yy_current_state] ) { - yy_last_accepting_state = yy_current_state; - yy_last_accepting_cpos = yy_cp; + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; } while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 63 ) + if ( yy_current_state >= 107 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; ++yy_cp; } - while ( yy_current_state != 62 ); - yy_cp = yy_last_accepting_cpos; - yy_current_state = yy_last_accepting_state; + while ( yy_current_state != 106 ); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); yy_find_action: yy_act = yy_accept[yy_current_state]; YY_DO_BEFORE_ACTION; - do_action: /* This label is used only to access EOF actions. */ - switch ( yy_act ) { /* beginning of action switch */ case 0: /* must back up */ /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = yy_hold_char; - yy_cp = yy_last_accepting_cpos; - yy_current_state = yy_last_accepting_state; + *yy_cp = (yy_hold_char); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); goto yy_find_action; case 1: @@ -659,6 +800,7 @@ YY_RULE_SETUP ; YY_BREAK case 2: +/* rule 2 can match eol */ YY_RULE_SETUP #line 31 "QuantityParser.l" ; @@ -671,215 +813,330 @@ YY_RULE_SETUP case 4: YY_RULE_SETUP #line 35 "QuantityParser.l" -yylval = 1.0; return UNIT; // millimeter (internal standard length) +yylval = Quantity(1.0e-6 ,Unit(1)); return UNIT; // nano meter YY_BREAK case 5: YY_RULE_SETUP #line 36 "QuantityParser.l" -yylval = 1000.0; return UNIT; // meter +yylval = Quantity(1.0e-3 ,Unit(1)); return UNIT; // micro meter YY_BREAK case 6: YY_RULE_SETUP #line 37 "QuantityParser.l" -yylval = 10.0; return UNIT; // centimeter +yylval = Quantity(1.0 ,Unit(1)); return UNIT; // milli meter YY_BREAK case 7: YY_RULE_SETUP #line 38 "QuantityParser.l" -yylval = 100.0; return UNIT; // decimeter +yylval = Quantity(10.0 ,Unit(1)); return UNIT; // centi meter YY_BREAK case 8: YY_RULE_SETUP #line 39 "QuantityParser.l" -yylval = 1000000.0; return UNIT; // kilometer +yylval = Quantity(100.0 ,Unit(1)); return UNIT; // deci meter YY_BREAK case 9: YY_RULE_SETUP -#line 41 "QuantityParser.l" -yylval = 25.4; return UNIT; // inch +#line 40 "QuantityParser.l" +yylval = Quantity(1.0e3 ,Unit(1)); return UNIT; // meter YY_BREAK case 10: YY_RULE_SETUP -#line 42 "QuantityParser.l" -yylval = 25.4; return UNIT; // inch +#line 41 "QuantityParser.l" +yylval = Quantity(1.0e6 ,Unit(1)); return UNIT; // kilo meter YY_BREAK case 11: YY_RULE_SETUP -#line 43 "QuantityParser.l" -yylval = 304.8; return UNIT; // foot +#line 42 "QuantityParser.l" +yylval = Quantity(1000000.0 ,Unit(3)); return UNIT; // Liter dm^3 YY_BREAK case 12: YY_RULE_SETUP #line 44 "QuantityParser.l" -yylval = 304.8; return UNIT; // foot +yylval = Quantity(1.0e-9 ,Unit(0,1)); return UNIT; // milli gram YY_BREAK case 13: YY_RULE_SETUP #line 45 "QuantityParser.l" -yylval = 0.0254; return UNIT; // thou +yylval = Quantity(1.0e-6 ,Unit(0,1)); return UNIT; // milli gram YY_BREAK case 14: YY_RULE_SETUP #line 46 "QuantityParser.l" -yylval = 914.4; return UNIT; // yard +yylval = Quantity(1.0e-3 ,Unit(0,1)); return UNIT; // gram YY_BREAK case 15: YY_RULE_SETUP -#line 48 "QuantityParser.l" -yylval = 1.0; return UNIT; // kilogram (internal standard mass) +#line 47 "QuantityParser.l" +yylval = Quantity(1.0 ,Unit(0,1)); return UNIT; // kilo gram YY_BREAK case 16: YY_RULE_SETUP -#line 49 "QuantityParser.l" -yylval = 0.001; return UNIT; // gram +#line 48 "QuantityParser.l" +yylval = Quantity(1000.0 ,Unit(0,1)); return UNIT; // ton YY_BREAK case 17: YY_RULE_SETUP #line 50 "QuantityParser.l" -yylval = 0.000001; return UNIT; // milligram +yylval = Quantity(1.0 ,Unit(0,0,1)); return UNIT; // second (internal standard time) YY_BREAK case 18: YY_RULE_SETUP #line 51 "QuantityParser.l" -yylval = 1000.0; return UNIT; // ton +yylval = Quantity(60.0 ,Unit(0,0,1)); return UNIT; // minute YY_BREAK case 19: YY_RULE_SETUP -#line 53 "QuantityParser.l" -yylval = 0.45359237; return UNIT; // pound +#line 52 "QuantityParser.l" +yylval = Quantity(3600.0 ,Unit(0,0,1)); return UNIT; // hour YY_BREAK case 20: YY_RULE_SETUP #line 54 "QuantityParser.l" -yylval = 0.45359237; return UNIT; // ounce +yylval = Quantity(1.0 ,Unit(0,0,0,1)); return UNIT; // Ampere (internal standard electric current) YY_BREAK case 21: YY_RULE_SETUP #line 55 "QuantityParser.l" -yylval = 6.35029318; return UNIT; // Stone +yylval = Quantity(0.001 ,Unit(0,0,0,1)); return UNIT; // milli Ampere YY_BREAK case 22: YY_RULE_SETUP #line 56 "QuantityParser.l" -yylval = 50.80234544;return UNIT; // hundredweights +yylval = Quantity(1000.0 ,Unit(0,0,0,1)); return UNIT; // kilo Ampere YY_BREAK case 23: YY_RULE_SETUP -#line 58 "QuantityParser.l" -yylval = 1.0; return UNIT; // degree (internal standard angle) +#line 57 "QuantityParser.l" +yylval = Quantity(1.0e6 ,Unit(0,0,0,1)); return UNIT; // Mega Ampere YY_BREAK case 24: YY_RULE_SETUP #line 59 "QuantityParser.l" -yylval = 180/M_PI; return UNIT; // radian +yylval = Quantity(1.0 ,Unit(0,0,0,0,1)); return UNIT; // Kelvin (internal standard thermodynamic temperature) YY_BREAK case 25: YY_RULE_SETUP #line 60 "QuantityParser.l" -yylval = 360.0/400.0;return UNIT; // gon +yylval = Quantity(0.001 ,Unit(0,0,0,0,1)); return UNIT; // Kelvin YY_BREAK case 26: YY_RULE_SETUP -#line 62 "QuantityParser.l" -yylval = 1.0; return UNIT; // second (internal standard time) +#line 61 "QuantityParser.l" +yylval = Quantity(0.000001 ,Unit(0,0,0,0,1)); return UNIT; // Kelvin YY_BREAK case 27: YY_RULE_SETUP #line 63 "QuantityParser.l" -yylval = 60.0; return UNIT; // minute +yylval = Quantity(1.0 ,Unit(0,0,0,0,0,1)); return UNIT; // Mole (internal standard amount of substance) YY_BREAK case 28: YY_RULE_SETUP -#line 64 "QuantityParser.l" -yylval = 3600.0; return UNIT; // hour +#line 65 "QuantityParser.l" +yylval = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); return UNIT; // Candela (internal standard luminous intensity) YY_BREAK case 29: YY_RULE_SETUP -#line 66 "QuantityParser.l" -yylval = 1.0; return UNIT; // Ampere (internal standard electric current) +#line 67 "QuantityParser.l" +yylval = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); return UNIT; // degree (internal standard angle) YY_BREAK case 30: YY_RULE_SETUP -#line 67 "QuantityParser.l" -yylval = 1.0; return UNIT; // Kelvin (internal standard thermodynamic temperature) +#line 68 "QuantityParser.l" +yylval = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); return UNIT; // radian YY_BREAK case 31: YY_RULE_SETUP -#line 68 "QuantityParser.l" -yylval = 1.0; return UNIT; // Candela (internal standard luminous intensity) +#line 69 "QuantityParser.l" +yylval = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); return UNIT; // gon YY_BREAK case 32: YY_RULE_SETUP -#line 69 "QuantityParser.l" -yylval = 1.0; return UNIT; // Mole (internal standard amount of substance) +#line 71 "QuantityParser.l" +yylval = Quantity(25.4 ,Unit(1)); return UNIT; // inch YY_BREAK case 33: YY_RULE_SETUP -#line 71 "QuantityParser.l" -yylval = 1.0; return UNIT; // microliter mm^3(derived standard volume) +#line 72 "QuantityParser.l" +yylval = Quantity(25.4 ,Unit(1)); return UNIT; // inch YY_BREAK case 34: YY_RULE_SETUP -#line 72 "QuantityParser.l" -yylval = 1000.0; return UNIT; // milliliter cm^3 +#line 73 "QuantityParser.l" +yylval = Quantity(304.8 ,Unit(1)); return UNIT; // foot YY_BREAK case 35: YY_RULE_SETUP -#line 73 "QuantityParser.l" -yylval = 1000000.0; return UNIT; // Liter dm^3 +#line 74 "QuantityParser.l" +yylval = Quantity(304.8 ,Unit(1)); return UNIT; // foot YY_BREAK case 36: YY_RULE_SETUP -#line 78 "QuantityParser.l" -{yylval = atof( yytext ); return NUM;} +#line 75 "QuantityParser.l" +yylval = Quantity(0.0254 ,Unit(1)); return UNIT; // thou YY_BREAK case 37: YY_RULE_SETUP -#line 79 "QuantityParser.l" -{yylval = atof( yytext ); return NUM;} +#line 76 "QuantityParser.l" +yylval = Quantity(914.4 ,Unit(1)); return UNIT; // yard YY_BREAK case 38: YY_RULE_SETUP -#line 81 "QuantityParser.l" -{yylval = M_PI ; return NUM;} // constant pi +#line 79 "QuantityParser.l" +yylval = Quantity(0.45359237 ,Unit(0,1)); return UNIT; // pound YY_BREAK case 39: YY_RULE_SETUP -#line 82 "QuantityParser.l" -{yylval = M_E ; return NUM;} // constant e +#line 80 "QuantityParser.l" +yylval = Quantity(0.45359237 ,Unit(0,1)); return UNIT; // ounce YY_BREAK case 40: YY_RULE_SETUP +#line 81 "QuantityParser.l" +yylval = Quantity(6.35029318 ,Unit(0,1)); return UNIT; // Stone + YY_BREAK +case 41: +YY_RULE_SETUP +#line 82 "QuantityParser.l" +yylval = Quantity(50.80234544 ,Unit(0,1)); return UNIT; // hundredweights + YY_BREAK +case 42: +YY_RULE_SETUP #line 86 "QuantityParser.l" +{for(char* c=yytext;*c!='\0';c++)if(*c==',')*c='.'; yylval = atof( yytext ); return NUM;} + YY_BREAK +case 43: +YY_RULE_SETUP +#line 87 "QuantityParser.l" +{for(char* c=yytext;*c!='\0';c++)if(*c==',')*c='.'; yylval = atof( yytext ); return NUM;} + YY_BREAK +case 44: +YY_RULE_SETUP +#line 88 "QuantityParser.l" +{yylval = atof( yytext ); return NUM;} + YY_BREAK +case 45: +YY_RULE_SETUP +#line 90 "QuantityParser.l" +{yylval = M_PI ; return NUM;} // constant pi + YY_BREAK +case 46: +YY_RULE_SETUP +#line 91 "QuantityParser.l" +{yylval = M_E ; return NUM;} // constant e + YY_BREAK +case 47: +YY_RULE_SETUP +#line 93 "QuantityParser.l" +return ACOS; + YY_BREAK +case 48: +YY_RULE_SETUP +#line 94 "QuantityParser.l" +return ASIN; + YY_BREAK +case 49: +YY_RULE_SETUP +#line 95 "QuantityParser.l" +return ATAN; + YY_BREAK +case 50: +YY_RULE_SETUP +#line 96 "QuantityParser.l" +return ATAN2; + YY_BREAK +case 51: +YY_RULE_SETUP +#line 97 "QuantityParser.l" +return COS; + YY_BREAK +case 52: +YY_RULE_SETUP +#line 98 "QuantityParser.l" +return EXP; + YY_BREAK +case 53: +YY_RULE_SETUP +#line 99 "QuantityParser.l" +return ABS; + YY_BREAK +case 54: +YY_RULE_SETUP +#line 100 "QuantityParser.l" +return MOD; + YY_BREAK +case 55: +YY_RULE_SETUP +#line 101 "QuantityParser.l" +return LOG; + YY_BREAK +case 56: +YY_RULE_SETUP +#line 102 "QuantityParser.l" +return LOG10; + YY_BREAK +case 57: +YY_RULE_SETUP +#line 103 "QuantityParser.l" +return POW; + YY_BREAK +case 58: +YY_RULE_SETUP +#line 104 "QuantityParser.l" +return SIN; + YY_BREAK +case 59: +YY_RULE_SETUP +#line 105 "QuantityParser.l" +return SINH; + YY_BREAK +case 60: +YY_RULE_SETUP +#line 106 "QuantityParser.l" +return TAN; + YY_BREAK +case 61: +YY_RULE_SETUP +#line 107 "QuantityParser.l" +return TANH; + YY_BREAK +case 62: +YY_RULE_SETUP +#line 108 "QuantityParser.l" +return SQRT; + YY_BREAK +case 63: +YY_RULE_SETUP +#line 110 "QuantityParser.l" ECHO; YY_BREAK -#line 858 "QuantityLexer.c" +#line 1114 "QuantityLexer.c" case YY_STATE_EOF(INITIAL): yyterminate(); case YY_END_OF_BUFFER: { /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - yytext_ptr) - 1; + int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = yy_hold_char; + *yy_cp = (yy_hold_char); YY_RESTORE_YY_MORE_OFFSET - if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_NEW ) + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) { /* We're scanning a new file or input source. It's * possible that this happened because the user * just pointed yyin at a new source and called * yylex(). If so, then we have to assure - * consistency between yy_current_buffer and our + * consistency between YY_CURRENT_BUFFER and our * globals. Here is the right place to do so, because * this is the first action (other than possibly a * back-up) that will match for the new input source. */ - yy_n_chars = yy_current_buffer->yy_n_chars; - yy_current_buffer->yy_input_file = yyin; - yy_current_buffer->yy_buffer_status = YY_BUFFER_NORMAL; + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; } /* Note that here we test for yy_c_buf_p "<=" to the position @@ -889,13 +1146,13 @@ case YY_STATE_EOF(INITIAL): * end-of-buffer state). Contrast this with the test * in input(). */ - if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] ) + if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) { /* This was really a NUL. */ yy_state_type yy_next_state; - yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text; + (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; - yy_current_state = yy_get_previous_state(); + yy_current_state = yy_get_previous_state( ); /* Okay, we're now positioned to make the NUL * transition. We couldn't have @@ -908,31 +1165,31 @@ case YY_STATE_EOF(INITIAL): yy_next_state = yy_try_NUL_trans( yy_current_state ); - yy_bp = yytext_ptr + YY_MORE_ADJ; + yy_bp = (yytext_ptr) + YY_MORE_ADJ; if ( yy_next_state ) { /* Consume the NUL. */ - yy_cp = ++yy_c_buf_p; + yy_cp = ++(yy_c_buf_p); yy_current_state = yy_next_state; goto yy_match; } else { - yy_cp = yy_last_accepting_cpos; - yy_current_state = yy_last_accepting_state; + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); goto yy_find_action; } } - else switch ( yy_get_next_buffer() ) + else switch ( yy_get_next_buffer( ) ) { case EOB_ACT_END_OF_FILE: { - yy_did_buffer_switch_on_eof = 0; + (yy_did_buffer_switch_on_eof) = 0; - if ( yywrap() ) + if ( yywrap( ) ) { /* Note: because we've taken care in * yy_get_next_buffer() to have set up @@ -943,7 +1200,7 @@ case YY_STATE_EOF(INITIAL): * YY_NULL, it'll still work - another * YY_NULL will get returned. */ - yy_c_buf_p = yytext_ptr + YY_MORE_ADJ; + (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; yy_act = YY_STATE_EOF(YY_START); goto do_action; @@ -951,30 +1208,30 @@ case YY_STATE_EOF(INITIAL): else { - if ( ! yy_did_buffer_switch_on_eof ) + if ( ! (yy_did_buffer_switch_on_eof) ) YY_NEW_FILE; } break; } case EOB_ACT_CONTINUE_SCAN: - yy_c_buf_p = - yytext_ptr + yy_amount_of_matched_text; + (yy_c_buf_p) = + (yytext_ptr) + yy_amount_of_matched_text; - yy_current_state = yy_get_previous_state(); + yy_current_state = yy_get_previous_state( ); - yy_cp = yy_c_buf_p; - yy_bp = yytext_ptr + YY_MORE_ADJ; + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; goto yy_match; case EOB_ACT_LAST_MATCH: - yy_c_buf_p = - &yy_current_buffer->yy_ch_buf[yy_n_chars]; + (yy_c_buf_p) = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; - yy_current_state = yy_get_previous_state(); + yy_current_state = yy_get_previous_state( ); - yy_cp = yy_c_buf_p; - yy_bp = yytext_ptr + YY_MORE_ADJ; + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; goto yy_find_action; } break; @@ -985,8 +1242,7 @@ case YY_STATE_EOF(INITIAL): "fatal flex scanner internal error--no action found" ); } /* end of action switch */ } /* end of scanning one token */ - } /* end of yylex */ - +} /* end of yylex */ /* yy_get_next_buffer - try to read in a new buffer * @@ -995,21 +1251,20 @@ case YY_STATE_EOF(INITIAL): * EOB_ACT_CONTINUE_SCAN - continue scanning from current position * EOB_ACT_END_OF_FILE - end of file */ - -static int yy_get_next_buffer() - { - register char *dest = yy_current_buffer->yy_ch_buf; - register char *source = yytext_ptr; +static int yy_get_next_buffer (void) +{ + register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + register char *source = (yytext_ptr); register int number_to_move, i; int ret_val; - if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] ) + if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) YY_FATAL_ERROR( "fatal flex scanner internal error--end of buffer missed" ); - if ( yy_current_buffer->yy_fill_buffer == 0 ) + if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) { /* Don't try to fill the buffer, so this is an EOF. */ - if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 ) + if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) { /* We matched a single character, the EOB, so * treat this as a final EOF. @@ -1029,34 +1284,30 @@ static int yy_get_next_buffer() /* Try to read more data. */ /* First move last chars to start of buffer. */ - number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1; + number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; for ( i = 0; i < number_to_move; ++i ) *(dest++) = *(source++); - if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) /* don't do the read, it's not guaranteed to return an EOF, * just force an EOF */ - yy_current_buffer->yy_n_chars = yy_n_chars = 0; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; else { - int num_to_read = - yy_current_buffer->yy_buf_size - number_to_move - 1; + int num_to_read = + YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; while ( num_to_read <= 0 ) { /* Not enough room in the buffer - grow it. */ -#ifdef YY_USES_REJECT - YY_FATAL_ERROR( -"input buffer overflow, can't enlarge buffer because scanner uses REJECT" ); -#else /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = yy_current_buffer; + YY_BUFFER_STATE b = YY_CURRENT_BUFFER; int yy_c_buf_p_offset = - (int) (yy_c_buf_p - b->yy_ch_buf); + (int) ((yy_c_buf_p) - b->yy_ch_buf); if ( b->yy_is_our_buffer ) { @@ -1069,8 +1320,7 @@ static int yy_get_next_buffer() b->yy_ch_buf = (char *) /* Include room in for 2 EOB chars. */ - yy_flex_realloc( (void *) b->yy_ch_buf, - b->yy_buf_size + 2 ); + yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); } else /* Can't grow it, we don't own it. */ @@ -1080,35 +1330,35 @@ static int yy_get_next_buffer() YY_FATAL_ERROR( "fatal error - scanner input buffer overflow" ); - yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; + (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; - num_to_read = yy_current_buffer->yy_buf_size - + num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; -#endif + } if ( num_to_read > YY_READ_BUF_SIZE ) num_to_read = YY_READ_BUF_SIZE; /* Read in more data. */ - YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]), - yy_n_chars, num_to_read ); + YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + (yy_n_chars), (size_t) num_to_read ); - yy_current_buffer->yy_n_chars = yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); } - if ( yy_n_chars == 0 ) + if ( (yy_n_chars) == 0 ) { if ( number_to_move == YY_MORE_ADJ ) { ret_val = EOB_ACT_END_OF_FILE; - yyrestart( yyin ); + yyrestart(yyin ); } else { ret_val = EOB_ACT_LAST_MATCH; - yy_current_buffer->yy_buffer_status = + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_EOF_PENDING; } } @@ -1116,152 +1366,108 @@ static int yy_get_next_buffer() else ret_val = EOB_ACT_CONTINUE_SCAN; - yy_n_chars += number_to_move; - yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR; - yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; - - yytext_ptr = &yy_current_buffer->yy_ch_buf[0]; - - return ret_val; + if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + /* Extend the array by 50%, plus the number we really need. */ + yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); } + (yy_n_chars) += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; + + (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + + return ret_val; +} /* yy_get_previous_state - get the state just before the EOB char was reached */ -static yy_state_type yy_get_previous_state() - { + static yy_state_type yy_get_previous_state (void) +{ register yy_state_type yy_current_state; register char *yy_cp; + + yy_current_state = (yy_start); - yy_current_state = yy_start; - - for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp ) + for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) { register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); if ( yy_accept[yy_current_state] ) { - yy_last_accepting_state = yy_current_state; - yy_last_accepting_cpos = yy_cp; + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; } while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 63 ) + if ( yy_current_state >= 107 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; } return yy_current_state; - } - +} /* yy_try_NUL_trans - try to make a transition on the NUL character * * synopsis * next_state = yy_try_NUL_trans( current_state ); */ - -#ifdef YY_USE_PROTOS -static yy_state_type yy_try_NUL_trans( yy_state_type yy_current_state ) -#else -static yy_state_type yy_try_NUL_trans( yy_current_state ) -yy_state_type yy_current_state; -#endif - { + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) +{ register int yy_is_jam; - register char *yy_cp = yy_c_buf_p; + register char *yy_cp = (yy_c_buf_p); register YY_CHAR yy_c = 1; if ( yy_accept[yy_current_state] ) { - yy_last_accepting_state = yy_current_state; - yy_last_accepting_cpos = yy_cp; + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; } while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 63 ) + if ( yy_current_state >= 107 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - yy_is_jam = (yy_current_state == 62); + yy_is_jam = (yy_current_state == 106); return yy_is_jam ? 0 : yy_current_state; - } - - -#ifndef YY_NO_UNPUT -#ifdef YY_USE_PROTOS -static void yyunput( int c, register char *yy_bp ) -#else -static void yyunput( c, yy_bp ) -int c; -register char *yy_bp; -#endif - { - register char *yy_cp = yy_c_buf_p; - - /* undo effects of setting up yytext */ - *yy_cp = yy_hold_char; - - if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) - { /* need to shift things up to make room */ - /* +2 for EOB chars. */ - register int number_to_move = yy_n_chars + 2; - register char *dest = &yy_current_buffer->yy_ch_buf[ - yy_current_buffer->yy_buf_size + 2]; - register char *source = - &yy_current_buffer->yy_ch_buf[number_to_move]; - - while ( source > yy_current_buffer->yy_ch_buf ) - *--dest = *--source; - - yy_cp += (int) (dest - source); - yy_bp += (int) (dest - source); - yy_current_buffer->yy_n_chars = - yy_n_chars = yy_current_buffer->yy_buf_size; - - if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) - YY_FATAL_ERROR( "flex scanner push-back overflow" ); - } - - *--yy_cp = (char) c; - - - yytext_ptr = yy_bp; - yy_hold_char = *yy_cp; - yy_c_buf_p = yy_cp; - } -#endif /* ifndef YY_NO_UNPUT */ - +} +#ifndef YY_NO_INPUT #ifdef __cplusplus -static int yyinput() + static int yyinput (void) #else -static int input() + static int input (void) #endif - { + +{ int c; + + *(yy_c_buf_p) = (yy_hold_char); - *yy_c_buf_p = yy_hold_char; - - if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) + if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) { /* yy_c_buf_p now points to the character we want to return. * If this occurs *before* the EOB characters, then it's a * valid NUL; if not, then we've hit the end of the buffer. */ - if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] ) + if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) /* This was really a NUL. */ - *yy_c_buf_p = '\0'; + *(yy_c_buf_p) = '\0'; else { /* need more input */ - int offset = yy_c_buf_p - yytext_ptr; - ++yy_c_buf_p; + int offset = (yy_c_buf_p) - (yytext_ptr); + ++(yy_c_buf_p); - switch ( yy_get_next_buffer() ) + switch ( yy_get_next_buffer( ) ) { case EOB_ACT_LAST_MATCH: /* This happens because yy_g_n_b() @@ -1275,16 +1481,16 @@ static int input() */ /* Reset buffer status. */ - yyrestart( yyin ); + yyrestart(yyin ); - /* fall through */ + /*FALLTHROUGH*/ case EOB_ACT_END_OF_FILE: { - if ( yywrap() ) + if ( yywrap( ) ) return EOF; - if ( ! yy_did_buffer_switch_on_eof ) + if ( ! (yy_did_buffer_switch_on_eof) ) YY_NEW_FILE; #ifdef __cplusplus return yyinput(); @@ -1294,90 +1500,92 @@ static int input() } case EOB_ACT_CONTINUE_SCAN: - yy_c_buf_p = yytext_ptr + offset; + (yy_c_buf_p) = (yytext_ptr) + offset; break; } } } - c = *(unsigned char *) yy_c_buf_p; /* cast for 8-bit char's */ - *yy_c_buf_p = '\0'; /* preserve yytext */ - yy_hold_char = *++yy_c_buf_p; - + c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ + *(yy_c_buf_p) = '\0'; /* preserve yytext */ + (yy_hold_char) = *++(yy_c_buf_p); return c; +} +#endif /* ifndef YY_NO_INPUT */ + +/** Immediately switch to a different input stream. + * @param input_file A readable stream. + * + * @note This function does not reset the start condition to @c INITIAL . + */ + void yyrestart (FILE * input_file ) +{ + + if ( ! YY_CURRENT_BUFFER ){ + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer(yyin,YY_BUF_SIZE ); } + yy_init_buffer(YY_CURRENT_BUFFER,input_file ); + yy_load_buffer_state( ); +} -#ifdef YY_USE_PROTOS -void yyrestart( FILE *input_file ) -#else -void yyrestart( input_file ) -FILE *input_file; -#endif - { - if ( ! yy_current_buffer ) - yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); - - yy_init_buffer( yy_current_buffer, input_file ); - yy_load_buffer_state(); - } - - -#ifdef YY_USE_PROTOS -void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer ) -#else -void yy_switch_to_buffer( new_buffer ) -YY_BUFFER_STATE new_buffer; -#endif - { - if ( yy_current_buffer == new_buffer ) +/** Switch to a different input buffer. + * @param new_buffer The new input buffer. + * + */ + void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) +{ + + /* TODO. We should be able to replace this entire function body + * with + * yypop_buffer_state(); + * yypush_buffer_state(new_buffer); + */ + yyensure_buffer_stack (); + if ( YY_CURRENT_BUFFER == new_buffer ) return; - if ( yy_current_buffer ) + if ( YY_CURRENT_BUFFER ) { /* Flush out information for old buffer. */ - *yy_c_buf_p = yy_hold_char; - yy_current_buffer->yy_buf_pos = yy_c_buf_p; - yy_current_buffer->yy_n_chars = yy_n_chars; + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); } - yy_current_buffer = new_buffer; - yy_load_buffer_state(); + YY_CURRENT_BUFFER_LVALUE = new_buffer; + yy_load_buffer_state( ); /* We don't actually know whether we did this switch during * EOF (yywrap()) processing, but the only time this flag * is looked at is after yywrap() is called, so it's safe * to go ahead and always set it. */ - yy_did_buffer_switch_on_eof = 1; - } + (yy_did_buffer_switch_on_eof) = 1; +} +static void yy_load_buffer_state (void) +{ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; + (yy_hold_char) = *(yy_c_buf_p); +} -#ifdef YY_USE_PROTOS -void yy_load_buffer_state( void ) -#else -void yy_load_buffer_state() -#endif - { - yy_n_chars = yy_current_buffer->yy_n_chars; - yytext_ptr = yy_c_buf_p = yy_current_buffer->yy_buf_pos; - yyin = yy_current_buffer->yy_input_file; - yy_hold_char = *yy_c_buf_p; - } - - -#ifdef YY_USE_PROTOS -YY_BUFFER_STATE yy_create_buffer( FILE *file, int size ) -#else -YY_BUFFER_STATE yy_create_buffer( file, size ) -FILE *file; -int size; -#endif - { +/** Allocate and initialize an input buffer state. + * @param file A readable stream. + * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. + * + * @return the allocated buffer state. + */ + YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) +{ YY_BUFFER_STATE b; - - b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) ); + + b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); @@ -1386,80 +1594,71 @@ int size; /* yy_ch_buf has to be 2 characters longer than the size given because * we need to put in 2 end-of-buffer characters. */ - b->yy_ch_buf = (char *) yy_flex_alloc( b->yy_buf_size + 2 ); + b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ); if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); b->yy_is_our_buffer = 1; - yy_init_buffer( b, file ); + yy_init_buffer(b,file ); return b; - } +} - -#ifdef YY_USE_PROTOS -void yy_delete_buffer( YY_BUFFER_STATE b ) -#else -void yy_delete_buffer( b ) -YY_BUFFER_STATE b; -#endif - { +/** Destroy the buffer. + * @param b a buffer created with yy_create_buffer() + * + */ + void yy_delete_buffer (YY_BUFFER_STATE b ) +{ + if ( ! b ) return; - if ( b == yy_current_buffer ) - yy_current_buffer = (YY_BUFFER_STATE) 0; + if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ + YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; if ( b->yy_is_our_buffer ) - yy_flex_free( (void *) b->yy_ch_buf ); + yyfree((void *) b->yy_ch_buf ); - yy_flex_free( (void *) b ); - } + yyfree((void *) b ); +} +/* Initializes or reinitializes a buffer. + * This function is sometimes called more than once on the same buffer, + * such as during a yyrestart() or at EOF. + */ + static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) -#ifndef YY_ALWAYS_INTERACTIVE -#ifndef YY_NEVER_INTERACTIVE -extern int isatty YY_PROTO(( int )); -#endif -#endif - -#ifdef YY_USE_PROTOS -void yy_init_buffer( YY_BUFFER_STATE b, FILE *file ) -#else -void yy_init_buffer( b, file ) -YY_BUFFER_STATE b; -FILE *file; -#endif - - - { - yy_flush_buffer( b ); +{ + int oerrno = errno; + + yy_flush_buffer(b ); b->yy_input_file = file; b->yy_fill_buffer = 1; -#if YY_ALWAYS_INTERACTIVE - b->yy_is_interactive = 1; -#else -#if YY_NEVER_INTERACTIVE - b->yy_is_interactive = 0; -#else - b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; -#endif -#endif - } + /* If b is the current buffer, then yy_init_buffer was _probably_ + * called from yyrestart() or through yy_get_next_buffer. + * In that case, we don't want to reset the lineno or column. + */ + if (b != YY_CURRENT_BUFFER){ + b->yy_bs_lineno = 1; + b->yy_bs_column = 0; + } + b->yy_is_interactive = 0; + + errno = oerrno; +} -#ifdef YY_USE_PROTOS -void yy_flush_buffer( YY_BUFFER_STATE b ) -#else -void yy_flush_buffer( b ) -YY_BUFFER_STATE b; -#endif - - { - if ( ! b ) +/** Discard all buffered characters. On the next scan, YY_INPUT will be called. + * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. + * + */ + void yy_flush_buffer (YY_BUFFER_STATE b ) +{ + if ( ! b ) return; b->yy_n_chars = 0; @@ -1476,29 +1675,125 @@ YY_BUFFER_STATE b; b->yy_at_bol = 1; b->yy_buffer_status = YY_BUFFER_NEW; - if ( b == yy_current_buffer ) - yy_load_buffer_state(); + if ( b == YY_CURRENT_BUFFER ) + yy_load_buffer_state( ); +} + +/** Pushes the new state onto the stack. The new state becomes + * the current state. This function will allocate the stack + * if necessary. + * @param new_buffer The new state. + * + */ +void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) +{ + if (new_buffer == NULL) + return; + + yyensure_buffer_stack(); + + /* This block is copied from yy_switch_to_buffer. */ + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + /* Only push if top exists. Otherwise, replace top. */ + if (YY_CURRENT_BUFFER) + (yy_buffer_stack_top)++; + YY_CURRENT_BUFFER_LVALUE = new_buffer; + + /* copied from yy_switch_to_buffer. */ + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; +} + +/** Removes and deletes the top of the stack, if present. + * The next element becomes the new top. + * + */ +void yypop_buffer_state (void) +{ + if (!YY_CURRENT_BUFFER) + return; + + yy_delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + if ((yy_buffer_stack_top) > 0) + --(yy_buffer_stack_top); + + if (YY_CURRENT_BUFFER) { + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; + } +} + +/* Allocates the stack if it does not exist. + * Guarantees space for at least one push. + */ +static void yyensure_buffer_stack (void) +{ + int num_to_alloc; + + if (!(yy_buffer_stack)) { + + /* First allocation is just for 2 elements, since we don't know if this + * scanner will even need a stack. We use 2 instead of 1 to avoid an + * immediate realloc on the next call. + */ + num_to_alloc = 1; + (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc + (num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); + + (yy_buffer_stack_max) = num_to_alloc; + (yy_buffer_stack_top) = 0; + return; } + if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ -#ifndef YY_NO_SCAN_BUFFER -#ifdef YY_USE_PROTOS -YY_BUFFER_STATE yy_scan_buffer( char *base, yy_size_t size ) -#else -YY_BUFFER_STATE yy_scan_buffer( base, size ) -char *base; -yy_size_t size; -#endif - { + /* Increase the buffer to prepare for a possible push. */ + int grow_size = 8 /* arbitrary grow size */; + + num_to_alloc = (yy_buffer_stack_max) + grow_size; + (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc + ((yy_buffer_stack), + num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + /* zero only the new slots.*/ + memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); + (yy_buffer_stack_max) = num_to_alloc; + } +} + +/** Setup the input buffer state to scan directly from a user-specified character buffer. + * @param base the character buffer + * @param size the size in bytes of the character buffer + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) +{ YY_BUFFER_STATE b; - + if ( size < 2 || base[size-2] != YY_END_OF_BUFFER_CHAR || base[size-1] != YY_END_OF_BUFFER_CHAR ) /* They forgot to leave room for the EOB's. */ return 0; - b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) ); + b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); @@ -1512,56 +1807,51 @@ yy_size_t size; b->yy_fill_buffer = 0; b->yy_buffer_status = YY_BUFFER_NEW; - yy_switch_to_buffer( b ); + yy_switch_to_buffer(b ); return b; - } -#endif +} +/** Setup the input buffer state to scan a string. The next call to yylex() will + * scan from a @e copy of @a str. + * @param yystr a NUL-terminated string to scan + * + * @return the newly allocated buffer state object. + * @note If you want to scan bytes that may contain NUL values, then use + * yy_scan_bytes() instead. + */ +YY_BUFFER_STATE yy_scan_string (yyconst char * yystr ) +{ + + return yy_scan_bytes(yystr,strlen(yystr) ); +} -#ifndef YY_NO_SCAN_STRING -#ifdef YY_USE_PROTOS -YY_BUFFER_STATE yy_scan_string( yyconst char *yy_str ) -#else -YY_BUFFER_STATE yy_scan_string( yy_str ) -yyconst char *yy_str; -#endif - { - int len; - for ( len = 0; yy_str[len]; ++len ) - ; - - return yy_scan_bytes( yy_str, len ); - } -#endif - - -#ifndef YY_NO_SCAN_BYTES -#ifdef YY_USE_PROTOS -YY_BUFFER_STATE yy_scan_bytes( yyconst char *bytes, int len ) -#else -YY_BUFFER_STATE yy_scan_bytes( bytes, len ) -yyconst char *bytes; -int len; -#endif - { +/** Setup the input buffer state to scan the given bytes. The next call to yylex() will + * scan from a @e copy of @a bytes. + * @param bytes the byte buffer to scan + * @param len the number of bytes in the buffer pointed to by @a bytes. + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, int _yybytes_len ) +{ YY_BUFFER_STATE b; char *buf; yy_size_t n; int i; - + /* Get memory for full buffer, including space for trailing EOB's. */ - n = len + 2; - buf = (char *) yy_flex_alloc( n ); + n = _yybytes_len + 2; + buf = (char *) yyalloc(n ); if ( ! buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); - for ( i = 0; i < len; ++i ) - buf[i] = bytes[i]; + for ( i = 0; i < _yybytes_len; ++i ) + buf[i] = yybytes[i]; - buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR; + buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; - b = yy_scan_buffer( buf, n ); + b = yy_scan_buffer(buf,n ); if ( ! b ) YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); @@ -1571,78 +1861,17 @@ int len; b->yy_is_our_buffer = 1; return b; - } -#endif - - -#ifndef YY_NO_PUSH_STATE -#ifdef YY_USE_PROTOS -static void yy_push_state( int new_state ) -#else -static void yy_push_state( new_state ) -int new_state; -#endif - { - if ( yy_start_stack_ptr >= yy_start_stack_depth ) - { - yy_size_t new_size; - - yy_start_stack_depth += YY_START_STACK_INCR; - new_size = yy_start_stack_depth * sizeof( int ); - - if ( ! yy_start_stack ) - yy_start_stack = (int *) yy_flex_alloc( new_size ); - - else - yy_start_stack = (int *) yy_flex_realloc( - (void *) yy_start_stack, new_size ); - - if ( ! yy_start_stack ) - YY_FATAL_ERROR( - "out of memory expanding start-condition stack" ); - } - - yy_start_stack[yy_start_stack_ptr++] = YY_START; - - BEGIN(new_state); - } -#endif - - -#ifndef YY_NO_POP_STATE -static void yy_pop_state() - { - if ( --yy_start_stack_ptr < 0 ) - YY_FATAL_ERROR( "start-condition stack underflow" ); - - BEGIN(yy_start_stack[yy_start_stack_ptr]); - } -#endif - - -#ifndef YY_NO_TOP_STATE -static int yy_top_state() - { - return yy_start_stack[yy_start_stack_ptr - 1]; - } -#endif +} #ifndef YY_EXIT_FAILURE #define YY_EXIT_FAILURE 2 #endif -#ifdef YY_USE_PROTOS -static void yy_fatal_error( yyconst char msg[] ) -#else -static void yy_fatal_error( msg ) -char msg[]; -#endif - { - (void) fprintf( stderr, "%s\n", msg ); +static void yy_fatal_error (yyconst char* msg ) +{ + (void) fprintf( stderr, "%s\n", msg ); exit( YY_EXIT_FAILURE ); - } - - +} /* Redefine yyless() so it works in section 3 code. */ @@ -1651,68 +1880,177 @@ char msg[]; do \ { \ /* Undo effects of setting up yytext. */ \ - yytext[yyleng] = yy_hold_char; \ - yy_c_buf_p = yytext + n; \ - yy_hold_char = *yy_c_buf_p; \ - *yy_c_buf_p = '\0'; \ - yyleng = n; \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + yytext[yyleng] = (yy_hold_char); \ + (yy_c_buf_p) = yytext + yyless_macro_arg; \ + (yy_hold_char) = *(yy_c_buf_p); \ + *(yy_c_buf_p) = '\0'; \ + yyleng = yyless_macro_arg; \ } \ while ( 0 ) +/* Accessor methods (get/set functions) to struct members. */ -/* Internal utility routines. */ +/** Get the current line number. + * + */ +int yyget_lineno (void) +{ + + return yylineno; +} + +/** Get the input stream. + * + */ +FILE *yyget_in (void) +{ + return yyin; +} + +/** Get the output stream. + * + */ +FILE *yyget_out (void) +{ + return yyout; +} + +/** Get the length of the current token. + * + */ +int yyget_leng (void) +{ + return yyleng; +} + +/** Get the current token. + * + */ + +char *yyget_text (void) +{ + return yytext; +} + +/** Set the current line number. + * @param line_number + * + */ +void yyset_lineno (int line_number ) +{ + + yylineno = line_number; +} + +/** Set the input stream. This does not discard the current + * input buffer. + * @param in_str A readable stream. + * + * @see yy_switch_to_buffer + */ +void yyset_in (FILE * in_str ) +{ + yyin = in_str ; +} + +void yyset_out (FILE * out_str ) +{ + yyout = out_str ; +} + +int yyget_debug (void) +{ + return yy_flex_debug; +} + +void yyset_debug (int bdebug ) +{ + yy_flex_debug = bdebug ; +} + +static int yy_init_globals (void) +{ + /* Initialization is the same as for the non-reentrant scanner. + * This function is called from yylex_destroy(), so don't allocate here. + */ + + (yy_buffer_stack) = 0; + (yy_buffer_stack_top) = 0; + (yy_buffer_stack_max) = 0; + (yy_c_buf_p) = (char *) 0; + (yy_init) = 0; + (yy_start) = 0; + +/* Defined in main.c */ +#ifdef YY_STDINIT + yyin = stdin; + yyout = stdout; +#else + yyin = (FILE *) 0; + yyout = (FILE *) 0; +#endif + + /* For future reference: Set errno on error, since we are called by + * yylex_init() + */ + return 0; +} + +/* yylex_destroy is for both reentrant and non-reentrant scanners. */ +int yylex_destroy (void) +{ + + /* Pop the buffer stack, destroying each element. */ + while(YY_CURRENT_BUFFER){ + yy_delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + yypop_buffer_state(); + } + + /* Destroy the stack itself. */ + yyfree((yy_buffer_stack) ); + (yy_buffer_stack) = NULL; + + /* Reset the globals. This is important in a non-reentrant scanner so the next time + * yylex() is called, initialization will occur. */ + yy_init_globals( ); + + return 0; +} + +/* + * Internal utility routines. + */ #ifndef yytext_ptr -#ifdef YY_USE_PROTOS -static void yy_flex_strncpy( char *s1, yyconst char *s2, int n ) -#else -static void yy_flex_strncpy( s1, s2, n ) -char *s1; -yyconst char *s2; -int n; -#endif - { +static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) +{ register int i; for ( i = 0; i < n; ++i ) s1[i] = s2[i]; - } +} #endif #ifdef YY_NEED_STRLEN -#ifdef YY_USE_PROTOS -static int yy_flex_strlen( yyconst char *s ) -#else -static int yy_flex_strlen( s ) -yyconst char *s; -#endif - { +static int yy_flex_strlen (yyconst char * s ) +{ register int n; for ( n = 0; s[n]; ++n ) ; return n; - } +} #endif - -#ifdef YY_USE_PROTOS -static void *yy_flex_alloc( yy_size_t size ) -#else -static void *yy_flex_alloc( size ) -yy_size_t size; -#endif - { +void *yyalloc (yy_size_t size ) +{ return (void *) malloc( size ); - } +} -#ifdef YY_USE_PROTOS -static void *yy_flex_realloc( void *ptr, yy_size_t size ) -#else -static void *yy_flex_realloc( ptr, size ) -void *ptr; -yy_size_t size; -#endif - { +void *yyrealloc (void * ptr, yy_size_t size ) +{ /* The cast to (char *) in the following accommodates both * implementations that use char* generic pointers, and those * that use void* generic pointers. It works with the latter @@ -1721,23 +2059,13 @@ yy_size_t size; * as though doing an assignment. */ return (void *) realloc( (char *) ptr, size ); - } +} -#ifdef YY_USE_PROTOS -static void yy_flex_free( void *ptr ) -#else -static void yy_flex_free( ptr ) -void *ptr; -#endif - { - free( ptr ); - } +void yyfree (void * ptr ) +{ + free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ +} -#if YY_MAIN -int main() - { - yylex(); - return 0; - } -#endif -#line 86 "QuantityParser.l" +#define YYTABLES_NAME "yytables" + +#line 110 "QuantityParser.l" diff --git a/src/Base/QuantityParser.c b/src/Base/QuantityParser.c index 0410baa6c..bd758491f 100644 --- a/src/Base/QuantityParser.c +++ b/src/Base/QuantityParser.c @@ -1,10 +1,8 @@ +/* A Bison parser, made by GNU Bison 2.7.12-4996. */ -/* A Bison parser, made by GNU Bison 2.4.1. */ - -/* Skeleton implementation for Bison's Yacc-like parsers in C +/* Bison implementation for Yacc-like parsers in C - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 - Free Software Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -46,7 +44,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "2.4.1" +#define YYBISON_VERSION "2.7.12-4996" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -60,28 +58,27 @@ /* Pull parsers. */ #define YYPULL 1 -/* Using locations. */ -#define YYLSP_NEEDED 0 /* Copy the first part of user declarations. */ - -/* Line 189 of yacc.c */ +/* Line 371 of yacc.c */ #line 6 "QuantityParser.y" #define YYSTYPE Quantity #define yyparse Quantity_yyparse #define yyerror Quantity_yyerror +/* Line 371 of yacc.c */ +#line 74 "QuantityParser.c" -/* Line 189 of yacc.c */ -#line 80 "QuantityParser.c" - -/* Enabling traces. */ -#ifndef YYDEBUG -# define YYDEBUG 0 -#endif +# ifndef YY_NULL +# if defined __cplusplus && 201103L <= __cplusplus +# define YY_NULL nullptr +# else +# define YY_NULL 0 +# endif +# endif /* Enabling verbose error messages. */ #ifdef YYERROR_VERBOSE @@ -91,11 +88,14 @@ # define YYERROR_VERBOSE 0 #endif -/* Enabling the token table. */ -#ifndef YYTOKEN_TABLE -# define YYTOKEN_TABLE 0 -#endif +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif +#if YYDEBUG +extern int yydebug; +#endif /* Tokens. */ #ifndef YYTOKENTYPE @@ -105,12 +105,27 @@ enum yytokentype { UNIT = 258, NUM = 259, - NEG = 260 + ACOS = 260, + ASIN = 261, + ATAN = 262, + ATAN2 = 263, + COS = 264, + EXP = 265, + ABS = 266, + MOD = 267, + LOG = 268, + LOG10 = 269, + POW = 270, + SIN = 271, + SINH = 272, + TAN = 273, + TANH = 274, + SQRT = 275, + NEG = 276 }; #endif - #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED typedef int YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 @@ -118,12 +133,28 @@ typedef int YYSTYPE; # define YYSTYPE_IS_DECLARED 1 #endif +extern YYSTYPE yylval; + +#ifdef YYPARSE_PARAM +#if defined __STDC__ || defined __cplusplus +int yyparse (void *YYPARSE_PARAM); +#else +int yyparse (); +#endif +#else /* ! YYPARSE_PARAM */ +#if defined __STDC__ || defined __cplusplus +int yyparse (void); +#else +int yyparse (); +#endif +#endif /* ! YYPARSE_PARAM */ + + /* Copy the second part of user declarations. */ - -/* Line 264 of yacc.c */ -#line 127 "QuantityParser.c" +/* Line 390 of yacc.c */ +#line 158 "QuantityParser.c" #ifdef short # undef short @@ -173,27 +204,36 @@ typedef short int yytype_int16; #define YYSIZE_MAXIMUM ((YYSIZE_T) -1) #ifndef YY_ -# if YYENABLE_NLS +# if defined YYENABLE_NLS && YYENABLE_NLS # if ENABLE_NLS # include /* INFRINGES ON USER NAME SPACE */ -# define YY_(msgid) dgettext ("bison-runtime", msgid) +# define YY_(Msgid) dgettext ("bison-runtime", Msgid) # endif # endif # ifndef YY_ -# define YY_(msgid) msgid +# define YY_(Msgid) Msgid +# endif +#endif + +#ifndef __attribute__ +/* This feature is available in gcc versions 2.5 and later. */ +# if (! defined __GNUC__ || __GNUC__ < 2 \ + || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)) +# define __attribute__(Spec) /* empty */ # endif #endif /* Suppress unused-variable warnings by "using" E. */ #if ! defined lint || defined __GNUC__ -# define YYUSE(e) ((void) (e)) +# define YYUSE(E) ((void) (E)) #else -# define YYUSE(e) /* empty */ +# define YYUSE(E) /* empty */ #endif + /* Identity function, used to suppress warnings about constant conditions. */ #ifndef lint -# define YYID(n) (n) +# define YYID(N) (N) #else #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) @@ -226,11 +266,12 @@ YYID (yyi) # define alloca _alloca # else # define YYSTACK_ALLOC alloca -# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ +# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) # include /* INFRINGES ON USER NAME SPACE */ -# ifndef _STDLIB_H -# define _STDLIB_H 1 + /* Use EXIT_SUCCESS as a witness for stdlib.h. */ +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 # endif # endif # endif @@ -253,24 +294,24 @@ YYID (yyi) # ifndef YYSTACK_ALLOC_MAXIMUM # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM # endif -# if (defined __cplusplus && ! defined _STDLIB_H \ +# if (defined __cplusplus && ! defined EXIT_SUCCESS \ && ! ((defined YYMALLOC || defined malloc) \ && (defined YYFREE || defined free))) # include /* INFRINGES ON USER NAME SPACE */ -# ifndef _STDLIB_H -# define _STDLIB_H 1 +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 # endif # endif # ifndef YYMALLOC # define YYMALLOC malloc -# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ +# if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ # endif # endif # ifndef YYFREE # define YYFREE free -# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ +# if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) void free (void *); /* INFRINGES ON USER NAME SPACE */ # endif @@ -299,23 +340,7 @@ union yyalloc ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ + YYSTACK_GAP_MAXIMUM) -/* Copy COUNT objects from FROM to TO. The source and destination do - not overlap. */ -# ifndef YYCOPY -# if defined __GNUC__ && 1 < __GNUC__ -# define YYCOPY(To, From, Count) \ - __builtin_memcpy (To, From, (Count) * sizeof (*(From))) -# else -# define YYCOPY(To, From, Count) \ - do \ - { \ - YYSIZE_T yyi; \ - for (yyi = 0; yyi < (Count); yyi++) \ - (To)[yyi] = (From)[yyi]; \ - } \ - while (YYID (0)) -# endif -# endif +# define YYCOPY_NEEDED 1 /* Relocate STACK from its old location to the new one. The local variables YYSIZE and YYSTACKSIZE give the old and new number of @@ -335,23 +360,43 @@ union yyalloc #endif +#if defined YYCOPY_NEEDED && YYCOPY_NEEDED +/* Copy COUNT objects from SRC to DST. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if defined __GNUC__ && 1 < __GNUC__ +# define YYCOPY(Dst, Src, Count) \ + __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src))) +# else +# define YYCOPY(Dst, Src, Count) \ + do \ + { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (Dst)[yyi] = (Src)[yyi]; \ + } \ + while (YYID (0)) +# endif +# endif +#endif /* !YYCOPY_NEEDED */ + /* YYFINAL -- State number of the termination state. */ -#define YYFINAL 10 +#define YYFINAL 43 /* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 30 +#define YYLAST 259 /* YYNTOKENS -- Number of terminals. */ -#define YYNTOKENS 13 +#define YYNTOKENS 30 /* YYNNTS -- Number of nonterminals. */ -#define YYNNTS 3 +#define YYNNTS 5 /* YYNRULES -- Number of rules. */ -#define YYNRULES 12 +#define YYNRULES 34 /* YYNRULES -- Number of states. */ -#define YYNSTATES 22 +#define YYNSTATES 102 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ #define YYUNDEFTOK 2 -#define YYMAXUTOK 260 +#define YYMAXUTOK 276 #define YYTRANSLATE(YYX) \ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) @@ -363,12 +408,12 @@ static const yytype_uint8 yytranslate[] = 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 11, 12, 7, 6, 2, 5, 2, 8, 2, 2, + 27, 28, 23, 22, 29, 21, 2, 24, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 10, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 26, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, @@ -385,7 +430,8 @@ static const yytype_uint8 yytranslate[] = 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, - 9 + 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 25 }; #if YYDEBUG @@ -393,34 +439,51 @@ static const yytype_uint8 yytranslate[] = YYRHS. */ static const yytype_uint8 yyprhs[] = { - 0, 0, 3, 5, 7, 9, 12, 16, 20, 24, - 28, 31, 35 + 0, 0, 3, 5, 7, 9, 12, 14, 18, 22, + 26, 30, 33, 37, 41, 46, 51, 56, 63, 68, + 73, 80, 85, 90, 97, 102, 107, 112, 117, 122, + 127, 129, 133, 137, 141 }; /* YYRHS -- A `-1'-separated list of the rules' RHS. */ static const yytype_int8 yyrhs[] = { - 14, 0, -1, 15, -1, 4, -1, 3, -1, 4, - 3, -1, 15, 6, 15, -1, 15, 5, 15, -1, - 15, 7, 15, -1, 15, 8, 15, -1, 5, 15, - -1, 15, 10, 4, -1, 11, 15, 12, -1 + 31, 0, -1, 32, -1, 33, -1, 34, -1, 34, + 34, -1, 4, -1, 32, 22, 32, -1, 32, 21, + 32, -1, 32, 23, 32, -1, 32, 24, 32, -1, + 21, 32, -1, 32, 26, 32, -1, 27, 32, 28, + -1, 5, 27, 32, 28, -1, 6, 27, 32, 28, + -1, 7, 27, 32, 28, -1, 8, 27, 32, 29, + 32, 28, -1, 11, 27, 32, 28, -1, 10, 27, + 32, 28, -1, 12, 27, 32, 29, 32, 28, -1, + 13, 27, 32, 28, -1, 14, 27, 32, 28, -1, + 15, 27, 32, 29, 32, 28, -1, 16, 27, 32, + 28, -1, 17, 27, 32, 28, -1, 18, 27, 32, + 28, -1, 19, 27, 32, 28, -1, 20, 27, 32, + 28, -1, 9, 27, 32, 28, -1, 3, -1, 33, + 23, 33, -1, 33, 24, 33, -1, 33, 26, 32, + -1, 32, 33, -1 }; /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const yytype_uint8 yyrline[] = { - 0, 25, 25, 28, 29, 30, 31, 32, 33, 34, - 35, 36, 37 + 0, 26, 26, 27, 28, 29, 31, 32, 33, 34, + 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, + 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, + 57, 58, 59, 60, 62 }; #endif -#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE +#if YYDEBUG || YYERROR_VERBOSE || 0 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = { - "$end", "error", "$undefined", "UNIT", "NUM", "'-'", "'+'", "'*'", - "'/'", "NEG", "'^'", "'('", "')'", "$accept", "input", "exp", 0 + "$end", "error", "$undefined", "UNIT", "NUM", "ACOS", "ASIN", "ATAN", + "ATAN2", "COS", "EXP", "ABS", "MOD", "LOG", "LOG10", "POW", "SIN", + "SINH", "TAN", "TANH", "SQRT", "'-'", "'+'", "'*'", "'/'", "NEG", "'^'", + "'('", "')'", "','", "$accept", "input", "num", "unit", "quantity", YY_NULL }; #endif @@ -429,85 +492,163 @@ static const char *const yytname[] = token YYLEX-NUM. */ static const yytype_uint16 yytoknum[] = { - 0, 256, 257, 258, 259, 45, 43, 42, 47, 260, - 94, 40, 41 + 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, + 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, + 275, 45, 43, 42, 47, 276, 94, 40, 41, 44 }; # endif /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ static const yytype_uint8 yyr1[] = { - 0, 13, 14, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15 + 0, 30, 31, 31, 31, 31, 32, 32, 32, 32, + 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, + 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, + 33, 33, 33, 33, 34 }; /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ static const yytype_uint8 yyr2[] = { - 0, 2, 1, 1, 1, 2, 3, 3, 3, 3, - 2, 3, 3 + 0, 2, 1, 1, 1, 2, 1, 3, 3, 3, + 3, 2, 3, 3, 4, 4, 4, 6, 4, 4, + 6, 4, 4, 6, 4, 4, 4, 4, 4, 4, + 1, 3, 3, 3, 2 }; -/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state - STATE-NUM when YYTABLE doesn't specify something else to do. Zero +/* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM. + Performed when YYTABLE doesn't specify something else to do. Zero means the default is an error. */ static const yytype_uint8 yydefact[] = { - 0, 4, 3, 0, 0, 0, 2, 5, 10, 0, - 1, 0, 0, 0, 0, 0, 12, 7, 6, 8, - 9, 11 + 0, 30, 6, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 2, 3, 4, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 11, 0, 1, 0, 0, 0, 0, 0, 34, + 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 13, 8, 7, 9, 10, 12, 31, 32, 33, + 14, 15, 16, 0, 29, 19, 18, 0, 21, 22, + 0, 24, 25, 26, 27, 28, 0, 0, 0, 17, + 20, 23 }; /* YYDEFGOTO[NTERM-NUM]. */ static const yytype_int8 yydefgoto[] = { - -1, 5, 6 + -1, 21, 22, 49, 24 }; /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing STATE-NUM. */ -#define YYPACT_NINF -4 -static const yytype_int8 yypact[] = +#define YYPACT_NINF -25 +static const yytype_int16 yypact[] = { - 1, -4, -1, 1, 1, 3, 16, -4, 7, 8, - -4, 1, 1, 1, 1, 15, -4, 20, 20, 7, - 7, -4 + 69, -25, -25, -24, -23, -5, -4, -3, 3, 4, + 5, 27, 28, 29, 35, 40, 72, 78, 86, 30, + 30, 70, 88, 229, 30, 30, 30, 30, 30, 30, + 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, + 30, 81, 80, -25, 30, 30, 30, 30, 30, 229, + 95, 95, 30, 88, -25, 103, 111, 119, 37, 127, + 135, 143, 71, 151, 159, 94, 167, 175, 183, 191, + 199, -25, 233, 233, 81, 81, 81, 93, 93, 43, + -25, -25, -25, 30, -25, -25, -25, 30, -25, -25, + 30, -25, -25, -25, -25, -25, 207, 215, 223, -25, + -25, -25 }; /* YYPGOTO[NTERM-NUM]. */ static const yytype_int8 yypgoto[] = { - -4, -4, -3 + -25, -25, -19, 2, 97 }; /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If positive, shift that token. If negative, reduce the rule which - number is the opposite. If zero, do what YYDEFACT says. - If YYTABLE_NINF, syntax error. */ + number is the opposite. If YYTABLE_NINF, syntax error. */ #define YYTABLE_NINF -1 static const yytype_uint8 yytable[] = { - 8, 9, 7, 10, 1, 2, 3, 0, 17, 18, - 19, 20, 4, 11, 12, 13, 14, 15, 15, 21, - 16, 11, 12, 13, 14, 0, 15, 13, 14, 0, - 15 + 41, 42, 23, 25, 26, 53, 55, 56, 57, 58, + 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, + 69, 70, 27, 28, 29, 72, 73, 74, 75, 76, + 30, 31, 32, 79, 2, 3, 4, 5, 6, 7, + 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, + 18, 19, 77, 78, 33, 34, 35, 20, 44, 45, + 46, 47, 36, 48, 96, 45, 83, 37, 97, 48, + 43, 98, 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, + 19, 1, 44, 45, 46, 47, 20, 48, 1, 38, + 87, 44, 45, 46, 47, 39, 48, 48, 71, 44, + 45, 46, 47, 40, 48, 44, 45, 46, 47, 52, + 48, 54, 0, 90, 44, 45, 46, 47, 0, 48, + 0, 80, 44, 45, 46, 47, 0, 48, 0, 81, + 44, 45, 46, 47, 0, 48, 0, 82, 44, 45, + 46, 47, 0, 48, 0, 84, 44, 45, 46, 47, + 0, 48, 0, 85, 44, 45, 46, 47, 0, 48, + 0, 86, 44, 45, 46, 47, 0, 48, 0, 88, + 44, 45, 46, 47, 0, 48, 0, 89, 44, 45, + 46, 47, 0, 48, 0, 91, 44, 45, 46, 47, + 0, 48, 0, 92, 44, 45, 46, 47, 0, 48, + 0, 93, 44, 45, 46, 47, 0, 48, 0, 94, + 44, 45, 46, 47, 0, 48, 0, 95, 44, 45, + 46, 47, 0, 48, 0, 99, 44, 45, 46, 47, + 0, 48, 0, 100, 44, 45, 46, 47, 0, 48, + 0, 101, 50, 51, 0, 52, 46, 47, 0, 48 }; +#define yypact_value_is_default(Yystate) \ + (!!((Yystate) == (-25))) + +#define yytable_value_is_error(Yytable_value) \ + YYID (0) + static const yytype_int8 yycheck[] = { - 3, 4, 3, 0, 3, 4, 5, -1, 11, 12, - 13, 14, 11, 5, 6, 7, 8, 10, 10, 4, - 12, 5, 6, 7, 8, -1, 10, 7, 8, -1, - 10 + 19, 20, 0, 27, 27, 24, 25, 26, 27, 28, + 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, + 39, 40, 27, 27, 27, 44, 45, 46, 47, 48, + 27, 27, 27, 52, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 50, 51, 27, 27, 27, 27, 21, 22, + 23, 24, 27, 26, 83, 22, 29, 27, 87, 26, + 0, 90, 3, 4, 5, 6, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 21, 3, 21, 22, 23, 24, 27, 26, 3, 27, + 29, 21, 22, 23, 24, 27, 26, 26, 28, 21, + 22, 23, 24, 27, 26, 21, 22, 23, 24, 26, + 26, 24, -1, 29, 21, 22, 23, 24, -1, 26, + -1, 28, 21, 22, 23, 24, -1, 26, -1, 28, + 21, 22, 23, 24, -1, 26, -1, 28, 21, 22, + 23, 24, -1, 26, -1, 28, 21, 22, 23, 24, + -1, 26, -1, 28, 21, 22, 23, 24, -1, 26, + -1, 28, 21, 22, 23, 24, -1, 26, -1, 28, + 21, 22, 23, 24, -1, 26, -1, 28, 21, 22, + 23, 24, -1, 26, -1, 28, 21, 22, 23, 24, + -1, 26, -1, 28, 21, 22, 23, 24, -1, 26, + -1, 28, 21, 22, 23, 24, -1, 26, -1, 28, + 21, 22, 23, 24, -1, 26, -1, 28, 21, 22, + 23, 24, -1, 26, -1, 28, 21, 22, 23, 24, + -1, 26, -1, 28, 21, 22, 23, 24, -1, 26, + -1, 28, 23, 24, -1, 26, 23, 24, -1, 26 }; /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing symbol of state STATE-NUM. */ static const yytype_uint8 yystos[] = { - 0, 3, 4, 5, 11, 14, 15, 3, 15, 15, - 0, 5, 6, 7, 8, 10, 12, 15, 15, 15, - 15, 4 + 0, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, + 27, 31, 32, 33, 34, 27, 27, 27, 27, 27, + 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, + 27, 32, 32, 0, 21, 22, 23, 24, 26, 33, + 23, 24, 26, 32, 34, 32, 32, 32, 32, 32, + 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, + 32, 28, 32, 32, 32, 32, 32, 33, 33, 32, + 28, 28, 28, 29, 28, 28, 28, 29, 28, 28, + 29, 28, 28, 28, 28, 28, 32, 32, 32, 28, + 28, 28 }; #define yyerrok (yyerrstatus = 0) @@ -522,78 +663,50 @@ static const yytype_uint8 yystos[] = /* Like YYERROR except do call yyerror. This remains here temporarily to ease the transition to the new meaning of YYERROR, for GCC. - Once GCC version 2 has supplanted version 1, this can go. */ + Once GCC version 2 has supplanted version 1, this can go. However, + YYFAIL appears to be in use. Nevertheless, it is formally deprecated + in Bison 2.4.2's NEWS entry, where a plan to phase it out is + discussed. */ #define YYFAIL goto yyerrlab +#if defined YYFAIL + /* This is here to suppress warnings from the GCC cpp's + -Wunused-macros. Normally we don't worry about that warning, but + some users do, and we want to make it easy for users to remove + YYFAIL uses, which will produce warnings from Bison 2.5. */ +#endif #define YYRECOVERING() (!!yyerrstatus) -#define YYBACKUP(Token, Value) \ -do \ - if (yychar == YYEMPTY && yylen == 1) \ - { \ - yychar = (Token); \ - yylval = (Value); \ - yytoken = YYTRANSLATE (yychar); \ - YYPOPSTACK (1); \ - goto yybackup; \ - } \ - else \ - { \ +#define YYBACKUP(Token, Value) \ +do \ + if (yychar == YYEMPTY) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + YYPOPSTACK (yylen); \ + yystate = *yyssp; \ + goto yybackup; \ + } \ + else \ + { \ yyerror (YY_("syntax error: cannot back up")); \ YYERROR; \ } \ while (YYID (0)) - +/* Error token number */ #define YYTERROR 1 #define YYERRCODE 256 -/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. - If N is 0, then set CURRENT to the empty location which ends - the previous symbol: RHS[0] (always defined). */ - -#define YYRHSLOC(Rhs, K) ((Rhs)[K]) -#ifndef YYLLOC_DEFAULT -# define YYLLOC_DEFAULT(Current, Rhs, N) \ - do \ - if (YYID (N)) \ - { \ - (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ - (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ - (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ - (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ - } \ - else \ - { \ - (Current).first_line = (Current).last_line = \ - YYRHSLOC (Rhs, 0).last_line; \ - (Current).first_column = (Current).last_column = \ - YYRHSLOC (Rhs, 0).last_column; \ - } \ - while (YYID (0)) -#endif - - -/* YY_LOCATION_PRINT -- Print the location on the stream. - This macro was not mandated originally: define only if we know - we won't break user code: when these are the locations we know. */ - +/* This macro is provided for backward compatibility. */ #ifndef YY_LOCATION_PRINT -# if YYLTYPE_IS_TRIVIAL -# define YY_LOCATION_PRINT(File, Loc) \ - fprintf (File, "%d.%d-%d.%d", \ - (Loc).first_line, (Loc).first_column, \ - (Loc).last_line, (Loc).last_column) -# else -# define YY_LOCATION_PRINT(File, Loc) ((void) 0) -# endif +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) #endif /* YYLEX -- calling `yylex' with the right arguments. */ - #ifdef YYLEX_PARAM # define YYLEX yylex (YYLEX_PARAM) #else @@ -643,6 +756,8 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep) YYSTYPE const * const yyvaluep; #endif { + FILE *yyo = yyoutput; + YYUSE (yyo); if (!yyvaluep) return; # ifdef YYPRINT @@ -651,11 +766,7 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep) # else YYUSE (yyoutput); # endif - switch (yytype) - { - default: - break; - } + YYUSE (yytype); } @@ -780,7 +891,6 @@ int yydebug; # define YYMAXDEPTH 10000 #endif - #if YYERROR_VERBOSE @@ -883,115 +993,145 @@ yytnamerr (char *yyres, const char *yystr) } # endif -/* Copy into YYRESULT an error message about the unexpected token - YYCHAR while in state YYSTATE. Return the number of bytes copied, - including the terminating null byte. If YYRESULT is null, do not - copy anything; just return the number of bytes that would be - copied. As a special case, return 0 if an ordinary "syntax error" - message will do. Return YYSIZE_MAXIMUM if overflow occurs during - size calculation. */ -static YYSIZE_T -yysyntax_error (char *yyresult, int yystate, int yychar) +/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message + about the unexpected token YYTOKEN for the state stack whose top is + YYSSP. + + Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is + not large enough to hold the message. In that case, also set + *YYMSG_ALLOC to the required number of bytes. Return 2 if the + required number of bytes is too large to store. */ +static int +yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, + yytype_int16 *yyssp, int yytoken) { - int yyn = yypact[yystate]; + YYSIZE_T yysize0 = yytnamerr (YY_NULL, yytname[yytoken]); + YYSIZE_T yysize = yysize0; + enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + /* Internationalized format string. */ + const char *yyformat = YY_NULL; + /* Arguments of yyformat. */ + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + /* Number of reported tokens (one for the "unexpected", one per + "expected"). */ + int yycount = 0; - if (! (YYPACT_NINF < yyn && yyn <= YYLAST)) - return 0; - else + /* There are many possibilities here to consider: + - Assume YYFAIL is not used. It's too flawed to consider. See + + for details. YYERROR is fine as it does not invoke this + function. + - If this state is a consistent state with a default action, then + the only way this function was invoked is if the default action + is an error action. In that case, don't check for expected + tokens because there are none. + - The only way there can be no lookahead present (in yychar) is if + this state is a consistent state with a default action. Thus, + detecting the absence of a lookahead is sufficient to determine + that there is no unexpected or expected token to report. In that + case, just report a simple "syntax error". + - Don't assume there isn't a lookahead just because this state is a + consistent state with a default action. There might have been a + previous inconsistent state, consistent state with a non-default + action, or user semantic action that manipulated yychar. + - Of course, the expected token list depends on states to have + correct lookahead information, and it depends on the parser not + to perform extra reductions after fetching a lookahead from the + scanner and before detecting a syntax error. Thus, state merging + (from LALR or IELR) and default reductions corrupt the expected + token list. However, the list is correct for canonical LR with + one exception: it will still contain any token that will not be + accepted due to an error action in a later state. + */ + if (yytoken != YYEMPTY) { - int yytype = YYTRANSLATE (yychar); - YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]); - YYSIZE_T yysize = yysize0; - YYSIZE_T yysize1; - int yysize_overflow = 0; - enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; - int yyx; + int yyn = yypact[*yyssp]; + yyarg[yycount++] = yytname[yytoken]; + if (!yypact_value_is_default (yyn)) + { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yyx; -# if 0 - /* This is so xgettext sees the translatable formats that are - constructed on the fly. */ - YY_("syntax error, unexpected %s"); - YY_("syntax error, unexpected %s, expecting %s"); - YY_("syntax error, unexpected %s, expecting %s or %s"); - YY_("syntax error, unexpected %s, expecting %s or %s or %s"); - YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"); -# endif - char *yyfmt; - char const *yyf; - static char const yyunexpected[] = "syntax error, unexpected %s"; - static char const yyexpecting[] = ", expecting %s"; - static char const yyor[] = " or %s"; - char yyformat[sizeof yyunexpected - + sizeof yyexpecting - 1 - + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) - * (sizeof yyor - 1))]; - char const *yyprefix = yyexpecting; - - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn + 1; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yycount = 1; - - yyarg[0] = yytname[yytype]; - yyfmt = yystpcpy (yyformat, yyunexpected); - - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - yyformat[sizeof yyunexpected - 1] = '\0'; - break; - } - yyarg[yycount++] = yytname[yyx]; - yysize1 = yysize + yytnamerr (0, yytname[yyx]); - yysize_overflow |= (yysize1 < yysize); - yysize = yysize1; - yyfmt = yystpcpy (yyfmt, yyprefix); - yyprefix = yyor; - } - - yyf = YY_(yyformat); - yysize1 = yysize + yystrlen (yyf); - yysize_overflow |= (yysize1 < yysize); - yysize = yysize1; - - if (yysize_overflow) - return YYSIZE_MAXIMUM; - - if (yyresult) - { - /* Avoid sprintf, as that infringes on the user's name space. - Don't have undefined behavior even if the translation - produced a string with the wrong number of "%s"s. */ - char *yyp = yyresult; - int yyi = 0; - while ((*yyp = *yyf) != '\0') - { - if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) - { - yyp += yytnamerr (yyp, yyarg[yyi++]); - yyf += 2; - } - else - { - yyp++; - yyf++; - } - } - } - return yysize; + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR + && !yytable_value_is_error (yytable[yyx + yyn])) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + break; + } + yyarg[yycount++] = yytname[yyx]; + { + YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]); + if (! (yysize <= yysize1 + && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + } + } + } } + + switch (yycount) + { +# define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + YYCASE_(0, YY_("syntax error")); + YYCASE_(1, YY_("syntax error, unexpected %s")); + YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); + YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); + YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); + YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); +# undef YYCASE_ + } + + { + YYSIZE_T yysize1 = yysize + yystrlen (yyformat); + if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + } + + if (*yymsg_alloc < yysize) + { + *yymsg_alloc = 2 * yysize; + if (! (yysize <= *yymsg_alloc + && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) + *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; + return 1; + } + + /* Avoid sprintf, as that infringes on the user's name space. + Don't have undefined behavior even if the translation + produced a string with the wrong number of "%s"s. */ + { + char *yyp = *yymsg; + int yyi = 0; + while ((*yyp = *yyformat) != '\0') + if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) + { + yyp += yytnamerr (yyp, yyarg[yyi++]); + yyformat += 2; + } + else + { + yyp++; + yyformat++; + } + } + return 0; } #endif /* YYERROR_VERBOSE */ - /*-----------------------------------------------. | Release the memory associated to this symbol. | @@ -1016,44 +1156,34 @@ yydestruct (yymsg, yytype, yyvaluep) yymsg = "Deleting"; YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); - switch (yytype) - { - - default: - break; - } + YYUSE (yytype); } -/* Prevent warnings from -Wmissing-prototypes. */ -#ifdef YYPARSE_PARAM -#if defined __STDC__ || defined __cplusplus -int yyparse (void *YYPARSE_PARAM); -#else -int yyparse (); -#endif -#else /* ! YYPARSE_PARAM */ -#if defined __STDC__ || defined __cplusplus -int yyparse (void); -#else -int yyparse (); -#endif -#endif /* ! YYPARSE_PARAM */ + /* The lookahead symbol. */ int yychar; + +#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_END +#endif +#ifndef YY_INITIAL_VALUE +# define YY_INITIAL_VALUE(Value) /* Nothing. */ +#endif + /* The semantic value of the lookahead symbol. */ -YYSTYPE yylval; +YYSTYPE yylval YY_INITIAL_VALUE(yyval_default); /* Number of syntax errors so far. */ int yynerrs; - -/*-------------------------. -| yyparse or yypush_parse. | -`-------------------------*/ +/*----------. +| yyparse. | +`----------*/ #ifdef YYPARSE_PARAM #if (defined __STDC__ || defined __C99__FUNC__ \ @@ -1077,8 +1207,6 @@ yyparse () #endif #endif { - - int yystate; /* Number of tokens to shift before error messages enabled. */ int yyerrstatus; @@ -1087,7 +1215,7 @@ yyparse () `yyss': related to states. `yyvs': related to semantic values. - Refer to the stacks thru separate pointers, to allow yyoverflow + Refer to the stacks through separate pointers, to allow yyoverflow to reallocate them elsewhere. */ /* The state stack. */ @@ -1105,7 +1233,7 @@ yyparse () int yyn; int yyresult; /* Lookahead token as an internal (translated) token number. */ - int yytoken; + int yytoken = 0; /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval; @@ -1123,9 +1251,8 @@ yyparse () Keep to zero when no symbol should be popped. */ int yylen = 0; - yytoken = 0; - yyss = yyssa; - yyvs = yyvsa; + yyssp = yyss = yyssa; + yyvsp = yyvs = yyvsa; yystacksize = YYINITDEPTH; YYDPRINTF ((stderr, "Starting parse\n")); @@ -1134,14 +1261,6 @@ yyparse () yyerrstatus = 0; yynerrs = 0; yychar = YYEMPTY; /* Cause a token to be read. */ - - /* Initialize stack pointers. - Waste one element of value and location stack - so that they stay on the same level as the state stack. - The wasted elements are never initialized. */ - yyssp = yyss; - yyvsp = yyvs; - goto yysetstate; /*------------------------------------------------------------. @@ -1233,7 +1352,7 @@ yybackup: /* First try to decide what to do without reference to lookahead token. */ yyn = yypact[yystate]; - if (yyn == YYPACT_NINF) + if (yypact_value_is_default (yyn)) goto yydefault; /* Not known => get a lookahead token if don't already have one. */ @@ -1264,8 +1383,8 @@ yybackup: yyn = yytable[yyn]; if (yyn <= 0) { - if (yyn == 0 || yyn == YYTABLE_NINF) - goto yyerrlab; + if (yytable_value_is_error (yyn)) + goto yyerrlab; yyn = -yyn; goto yyreduce; } @@ -1282,7 +1401,9 @@ yybackup: yychar = YYEMPTY; yystate = yyn; + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END goto yynewstate; @@ -1319,88 +1440,219 @@ yyreduce: switch (yyn) { case 2: - -/* Line 1455 of yacc.c */ -#line 25 "QuantityParser.y" - { QuantResult = (yyvsp[(1) - (1)]) ; ;} +/* Line 1787 of yacc.c */ +#line 26 "QuantityParser.y" + { QuantResult = (yyvsp[(1) - (1)]) ; } break; case 3: - -/* Line 1455 of yacc.c */ -#line 28 "QuantityParser.y" - { (yyval) = (yyvsp[(1) - (1)]); ;} +/* Line 1787 of yacc.c */ +#line 27 "QuantityParser.y" + { QuantResult = (yyvsp[(1) - (1)]) ; } break; case 4: - -/* Line 1455 of yacc.c */ -#line 29 "QuantityParser.y" - { (yyval) = (yyvsp[(1) - (1)]); ;} +/* Line 1787 of yacc.c */ +#line 28 "QuantityParser.y" + { QuantResult = (yyvsp[(1) - (1)]) ; } break; case 5: - -/* Line 1455 of yacc.c */ -#line 30 "QuantityParser.y" - { (yyval) = (yyvsp[(1) - (2)])*(yyvsp[(2) - (2)]); ;} +/* Line 1787 of yacc.c */ +#line 29 "QuantityParser.y" + { QuantResult = (yyvsp[(1) - (2)]) + (yyvsp[(2) - (2)]); } break; case 6: - -/* Line 1455 of yacc.c */ +/* Line 1787 of yacc.c */ #line 31 "QuantityParser.y" - { (yyval) = (yyvsp[(1) - (3)]) + (yyvsp[(3) - (3)]); ;} + { (yyval) = (yyvsp[(1) - (1)]); } break; case 7: - -/* Line 1455 of yacc.c */ +/* Line 1787 of yacc.c */ #line 32 "QuantityParser.y" - { (yyval) = (yyvsp[(1) - (3)]) - (yyvsp[(3) - (3)]); ;} + { (yyval) = (yyvsp[(1) - (3)]).getValue() + (yyvsp[(3) - (3)]).getValue(); } break; case 8: - -/* Line 1455 of yacc.c */ +/* Line 1787 of yacc.c */ #line 33 "QuantityParser.y" - { (yyval) = (yyvsp[(1) - (3)]) * (yyvsp[(3) - (3)]); ;} + { (yyval) = (yyvsp[(1) - (3)]).getValue() - (yyvsp[(3) - (3)]).getValue(); } break; case 9: - -/* Line 1455 of yacc.c */ +/* Line 1787 of yacc.c */ #line 34 "QuantityParser.y" - { (yyval) = (yyvsp[(1) - (3)]) / (yyvsp[(3) - (3)]); ;} + { (yyval) = (yyvsp[(1) - (3)]).getValue() * (yyvsp[(3) - (3)]).getValue(); } break; case 10: - -/* Line 1455 of yacc.c */ +/* Line 1787 of yacc.c */ #line 35 "QuantityParser.y" - { (yyval) = -(yyvsp[(2) - (2)]); ;} + { (yyval) = (yyvsp[(1) - (3)]).getValue() / (yyvsp[(3) - (3)]).getValue(); } break; case 11: - -/* Line 1455 of yacc.c */ +/* Line 1787 of yacc.c */ #line 36 "QuantityParser.y" - { (yyval) = (yyvsp[(1) - (3)]).pow((yyvsp[(3) - (3)])); ;} + { (yyval) = -(yyvsp[(2) - (2)]).getValue(); } break; case 12: - -/* Line 1455 of yacc.c */ +/* Line 1787 of yacc.c */ #line 37 "QuantityParser.y" - { (yyval) = (yyvsp[(2) - (3)]); ;} + { (yyval) = pow ((yyvsp[(1) - (3)]).getValue(), (yyvsp[(3) - (3)]).getValue());} + break; + + case 13: +/* Line 1787 of yacc.c */ +#line 38 "QuantityParser.y" + { (yyval) = (yyvsp[(2) - (3)]); } + break; + + case 14: +/* Line 1787 of yacc.c */ +#line 39 "QuantityParser.y" + { (yyval) = acos((yyvsp[(3) - (4)]).getValue()); } + break; + + case 15: +/* Line 1787 of yacc.c */ +#line 40 "QuantityParser.y" + { (yyval) = asin((yyvsp[(3) - (4)]).getValue()); } + break; + + case 16: +/* Line 1787 of yacc.c */ +#line 41 "QuantityParser.y" + { (yyval) = atan((yyvsp[(3) - (4)]).getValue()); } + break; + + case 17: +/* Line 1787 of yacc.c */ +#line 42 "QuantityParser.y" + { (yyval) = atan2((yyvsp[(3) - (6)]).getValue(),(yyvsp[(5) - (6)]).getValue());} + break; + + case 18: +/* Line 1787 of yacc.c */ +#line 43 "QuantityParser.y" + { (yyval) = fabs((yyvsp[(3) - (4)]).getValue()); } + break; + + case 19: +/* Line 1787 of yacc.c */ +#line 44 "QuantityParser.y" + { (yyval) = exp((yyvsp[(3) - (4)]).getValue()); } + break; + + case 20: +/* Line 1787 of yacc.c */ +#line 45 "QuantityParser.y" + { (yyval) = fmod((yyvsp[(3) - (6)]).getValue(),(yyvsp[(5) - (6)]).getValue()); } + break; + + case 21: +/* Line 1787 of yacc.c */ +#line 46 "QuantityParser.y" + { (yyval) = log((yyvsp[(3) - (4)]).getValue()); } + break; + + case 22: +/* Line 1787 of yacc.c */ +#line 47 "QuantityParser.y" + { (yyval) = log10((yyvsp[(3) - (4)]).getValue()); } + break; + + case 23: +/* Line 1787 of yacc.c */ +#line 48 "QuantityParser.y" + { (yyval) = pow((yyvsp[(3) - (6)]).getValue(),(yyvsp[(5) - (6)]).getValue()); } + break; + + case 24: +/* Line 1787 of yacc.c */ +#line 49 "QuantityParser.y" + { (yyval) = sin((yyvsp[(3) - (4)]).getValue()); } + break; + + case 25: +/* Line 1787 of yacc.c */ +#line 50 "QuantityParser.y" + { (yyval) = sinh((yyvsp[(3) - (4)]).getValue()); } + break; + + case 26: +/* Line 1787 of yacc.c */ +#line 51 "QuantityParser.y" + { (yyval) = tan((yyvsp[(3) - (4)]).getValue()); } + break; + + case 27: +/* Line 1787 of yacc.c */ +#line 52 "QuantityParser.y" + { (yyval) = tanh((yyvsp[(3) - (4)]).getValue()); } + break; + + case 28: +/* Line 1787 of yacc.c */ +#line 53 "QuantityParser.y" + { (yyval) = tanh((yyvsp[(3) - (4)]).getValue()); } + break; + + case 29: +/* Line 1787 of yacc.c */ +#line 54 "QuantityParser.y" + { (yyval) = cos((yyvsp[(3) - (4)]).getValue()); } + break; + + case 30: +/* Line 1787 of yacc.c */ +#line 57 "QuantityParser.y" + { (yyval) = (yyvsp[(1) - (1)]); } + break; + + case 31: +/* Line 1787 of yacc.c */ +#line 58 "QuantityParser.y" + { (yyval) = (yyvsp[(1) - (3)]) * (yyvsp[(3) - (3)]); } + break; + + case 32: +/* Line 1787 of yacc.c */ +#line 59 "QuantityParser.y" + { (yyval) = (yyvsp[(1) - (3)]) / (yyvsp[(3) - (3)]); } + break; + + case 33: +/* Line 1787 of yacc.c */ +#line 60 "QuantityParser.y" + { (yyval) = (yyvsp[(1) - (3)]).pow ((yyvsp[(3) - (3)])); } + break; + + case 34: +/* Line 1787 of yacc.c */ +#line 62 "QuantityParser.y" + { (yyval) = (yyvsp[(1) - (2)])*(yyvsp[(2) - (2)]); } break; - -/* Line 1455 of yacc.c */ -#line 1402 "QuantityParser.c" +/* Line 1787 of yacc.c */ +#line 1643 "QuantityParser.c" default: break; } + /* User semantic actions sometimes alter yychar, and that requires + that yytoken be updated with the new translation. We take the + approach of translating immediately before every use of yytoken. + One alternative is translating here after every semantic action, + but that translation would be missed if the semantic action invokes + YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or + if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an + incorrect destructor might then be invoked immediately. In the + case of YYERROR or YYBACKUP, subsequent parser actions might lead + to an incorrect destructor call or verbose syntax error message + before the lookahead is translated. */ YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); YYPOPSTACK (yylen); @@ -1428,6 +1680,10 @@ yyreduce: | yyerrlab -- here on detecting error | `------------------------------------*/ yyerrlab: + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); + /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { @@ -1435,37 +1691,36 @@ yyerrlab: #if ! YYERROR_VERBOSE yyerror (YY_("syntax error")); #else +# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ + yyssp, yytoken) { - YYSIZE_T yysize = yysyntax_error (0, yystate, yychar); - if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM) - { - YYSIZE_T yyalloc = 2 * yysize; - if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM)) - yyalloc = YYSTACK_ALLOC_MAXIMUM; - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); - yymsg = (char *) YYSTACK_ALLOC (yyalloc); - if (yymsg) - yymsg_alloc = yyalloc; - else - { - yymsg = yymsgbuf; - yymsg_alloc = sizeof yymsgbuf; - } - } - - if (0 < yysize && yysize <= yymsg_alloc) - { - (void) yysyntax_error (yymsg, yystate, yychar); - yyerror (yymsg); - } - else - { - yyerror (YY_("syntax error")); - if (yysize != 0) - goto yyexhaustedlab; - } + char const *yymsgp = YY_("syntax error"); + int yysyntax_error_status; + yysyntax_error_status = YYSYNTAX_ERROR; + if (yysyntax_error_status == 0) + yymsgp = yymsg; + else if (yysyntax_error_status == 1) + { + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); + yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); + if (!yymsg) + { + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + yysyntax_error_status = 2; + } + else + { + yysyntax_error_status = YYSYNTAX_ERROR; + yymsgp = yymsg; + } + } + yyerror (yymsgp); + if (yysyntax_error_status == 2) + goto yyexhaustedlab; } +# undef YYSYNTAX_ERROR #endif } @@ -1524,7 +1779,7 @@ yyerrlab1: for (;;) { yyn = yypact[yystate]; - if (yyn != YYPACT_NINF) + if (!yypact_value_is_default (yyn)) { yyn += YYTERROR; if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) @@ -1547,7 +1802,9 @@ yyerrlab1: YY_STACK_PRINT (yyss, yyssp); } + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END /* Shift the error token. */ @@ -1571,7 +1828,7 @@ yyabortlab: yyresult = 1; goto yyreturn; -#if !defined(yyoverflow) || YYERROR_VERBOSE +#if !defined yyoverflow || YYERROR_VERBOSE /*-------------------------------------------------. | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ @@ -1583,8 +1840,13 @@ yyexhaustedlab: yyreturn: if (yychar != YYEMPTY) - yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval); + { + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = YYTRANSLATE (yychar); + yydestruct ("Cleanup: discarding lookahead", + yytoken, &yylval); + } /* Do not reclaim the symbols of the rule which action triggered this YYABORT or YYACCEPT. */ YYPOPSTACK (yylen); @@ -1608,8 +1870,6 @@ yyreturn: } - -/* Line 1675 of yacc.c */ -#line 41 "QuantityParser.y" - +/* Line 2050 of yacc.c */ +#line 66 "QuantityParser.y" diff --git a/src/Base/QuantityParser.l b/src/Base/QuantityParser.l index 07434bac3..8a9fbec01 100644 --- a/src/Base/QuantityParser.l +++ b/src/Base/QuantityParser.l @@ -32,54 +32,78 @@ ID [a-z][a-z0-9]* [-+()=/*^] { return *yytext; } -"mm" yylval = 1.0; return UNIT; // millimeter (internal standard length) -"m" yylval = 1000.0; return UNIT; // meter -"cm" yylval = 10.0; return UNIT; // centimeter -"dm" yylval = 100.0; return UNIT; // decimeter -"km" yylval = 1000000.0; return UNIT; // kilometer +"nm" yylval = Quantity(1.0e-6 ,Unit(1)); return UNIT; // nano meter +"ym" yylval = Quantity(1.0e-3 ,Unit(1)); return UNIT; // micro meter +"mm" yylval = Quantity(1.0 ,Unit(1)); return UNIT; // milli meter +"cm" yylval = Quantity(10.0 ,Unit(1)); return UNIT; // centi meter +"dm" yylval = Quantity(100.0 ,Unit(1)); return UNIT; // deci meter +"m" yylval = Quantity(1.0e3 ,Unit(1)); return UNIT; // meter +"km" yylval = Quantity(1.0e6 ,Unit(1)); return UNIT; // kilo meter +"l" yylval = Quantity(1000000.0 ,Unit(3)); return UNIT; // Liter dm^3 -"in" yylval = 25.4; return UNIT; // inch -"\"" yylval = 25.4; return UNIT; // inch -"fo" yylval = 304.8; return UNIT; // foot -"'" yylval = 304.8; return UNIT; // foot -"th" yylval = 0.0254; return UNIT; // thou -"yr" yylval = 914.4; return UNIT; // yard +"yg" yylval = Quantity(1.0e-9 ,Unit(0,1)); return UNIT; // milli gram +"mg" yylval = Quantity(1.0e-6 ,Unit(0,1)); return UNIT; // milli gram +"g" yylval = Quantity(1.0e-3 ,Unit(0,1)); return UNIT; // gram +"kg" yylval = Quantity(1.0 ,Unit(0,1)); return UNIT; // kilo gram +"t" yylval = Quantity(1000.0 ,Unit(0,1)); return UNIT; // ton -"kg" yylval = 1.0; return UNIT; // kilogram (internal standard mass) -"g" yylval = 0.001; return UNIT; // gram -"mg" yylval = 0.000001; return UNIT; // milligram -"t" yylval = 1000.0; return UNIT; // ton +"s" yylval = Quantity(1.0 ,Unit(0,0,1)); return UNIT; // second (internal standard time) +"min" yylval = Quantity(60.0 ,Unit(0,0,1)); return UNIT; // minute +"h" yylval = Quantity(3600.0 ,Unit(0,0,1)); return UNIT; // hour -"lb" yylval = 0.45359237; return UNIT; // pound -"oz" yylval = 0.45359237; return UNIT; // ounce -"st" yylval = 6.35029318; return UNIT; // Stone -"cwt" yylval = 50.80234544;return UNIT; // hundredweights +"A" yylval = Quantity(1.0 ,Unit(0,0,0,1)); return UNIT; // Ampere (internal standard electric current) +"mA" yylval = Quantity(0.001 ,Unit(0,0,0,1)); return UNIT; // milli Ampere +"kA" yylval = Quantity(1000.0 ,Unit(0,0,0,1)); return UNIT; // kilo Ampere +"MA" yylval = Quantity(1.0e6 ,Unit(0,0,0,1)); return UNIT; // Mega Ampere -"deg" yylval = 1.0; return UNIT; // degree (internal standard angle) -"rad" yylval = 180/M_PI; return UNIT; // radian -"gon" yylval = 360.0/400.0;return UNIT; // gon +"K" yylval = Quantity(1.0 ,Unit(0,0,0,0,1)); return UNIT; // Kelvin (internal standard thermodynamic temperature) +"mK" yylval = Quantity(0.001 ,Unit(0,0,0,0,1)); return UNIT; // Kelvin +"yK" yylval = Quantity(0.000001 ,Unit(0,0,0,0,1)); return UNIT; // Kelvin -"s" yylval = 1.0; return UNIT; // second (internal standard time) -"min" yylval = 60.0; return UNIT; // minute -"h" yylval = 3600.0; return UNIT; // hour +"mol" yylval = Quantity(1.0 ,Unit(0,0,0,0,0,1)); return UNIT; // Mole (internal standard amount of substance) -"A" yylval = 1.0; return UNIT; // Ampere (internal standard electric current) -"K" yylval = 1.0; return UNIT; // Kelvin (internal standard thermodynamic temperature) -"cd" yylval = 1.0; return UNIT; // Candela (internal standard luminous intensity) -"mol" yylval = 1.0; return UNIT; // Mole (internal standard amount of substance) +"cd" yylval = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); return UNIT; // Candela (internal standard luminous intensity) -"yl" yylval = 1.0; return UNIT; // microliter mm^3(derived standard volume) -"ml" yylval = 1000.0; return UNIT; // milliliter cm^3 -"l" yylval = 1000000.0; return UNIT; // Liter dm^3 +"deg" yylval = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); return UNIT; // degree (internal standard angle) +"rad" yylval = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); return UNIT; // radian +"gon" yylval = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); return UNIT; // gon + +"in" yylval = Quantity(25.4 ,Unit(1)); return UNIT; // inch +"\"" yylval = Quantity(25.4 ,Unit(1)); return UNIT; // inch +"fo" yylval = Quantity(304.8 ,Unit(1)); return UNIT; // foot +"'" yylval = Quantity(304.8 ,Unit(1)); return UNIT; // foot +"th" yylval = Quantity(0.0254 ,Unit(1)); return UNIT; // thou +"yr" yylval = Quantity(914.4 ,Unit(1)); return UNIT; // yard + + +"lb" yylval = Quantity(0.45359237 ,Unit(0,1)); return UNIT; // pound +"oz" yylval = Quantity(0.45359237 ,Unit(0,1)); return UNIT; // ounce +"st" yylval = Quantity(6.35029318 ,Unit(0,1)); return UNIT; // Stone +"cwt" yylval = Quantity(50.80234544 ,Unit(0,1)); return UNIT; // hundredweights - -{DIGIT}+"."{DIGIT}* {yylval = atof( yytext ); return NUM;} -{DIGIT}+ {yylval = atof( yytext ); return NUM;} +{DIGIT}+["."","]{DIGIT}*[eE][-+]?[0-9]+ {for(char* c=yytext;*c!='\0';c++)if(*c==',')*c='.'; yylval = atof( yytext ); return NUM;} +{DIGIT}+["."","]{DIGIT}* {for(char* c=yytext;*c!='\0';c++)if(*c==',')*c='.'; yylval = atof( yytext ); return NUM;} +{DIGIT}+ {yylval = atof( yytext ); return NUM;} "pi" {yylval = M_PI ; return NUM;} // constant pi "e" {yylval = M_E ; return NUM;} // constant e - +"acos" return ACOS; +"asin" return ASIN; +"atan" return ATAN; +"atan2" return ATAN2; +"cos" return COS; +"exp" return EXP; +"abs" return ABS; +"mod" return MOD; +"log" return LOG; +"log10" return LOG10; +"pow" return POW; +"sin" return SIN; +"sinh" return SINH; +"tan" return TAN; +"tanh" return TANH; +"sqrt" return SQRT; diff --git a/src/Base/QuantityParser.y b/src/Base/QuantityParser.y index 5ab6b1723..29177622c 100644 --- a/src/Base/QuantityParser.y +++ b/src/Base/QuantityParser.y @@ -11,6 +11,7 @@ /* Bison declarations. */ %token UNIT NUM + %token ACOS ASIN ATAN ATAN2 COS EXP ABS MOD LOG LOG10 POW SIN SINH TAN TANH SQRT; %left '-' '+' %left '*' '/' %left NEG /* negation--unary minus */ @@ -22,19 +23,43 @@ %% - input: exp { QuantResult = $1 ; } - ; - - exp: NUM { $$ = $1; } - | UNIT { $$ = $1; } - | NUM UNIT { $$ = $1*$2; } - | exp '+' exp { $$ = $1 + $3; } - | exp '-' exp { $$ = $1 - $3; } - | exp '*' exp { $$ = $1 * $3; } - | exp '/' exp { $$ = $1 / $3; } - | '-' exp %prec NEG { $$ = -$2; } - | exp '^' NUM { $$ = $1.pow($3); } - | '(' exp ')' { $$ = $2; } + input: num { QuantResult = $1 ; } + | unit { QuantResult = $1 ; } + | quantity { QuantResult = $1 ; } + | quantity quantity { QuantResult = $1 + $2; } + ; + num: NUM { $$ = $1; } + | num '+' num { $$ = $1.getValue() + $3.getValue(); } + | num '-' num { $$ = $1.getValue() - $3.getValue(); } + | num '*' num { $$ = $1.getValue() * $3.getValue(); } + | num '/' num { $$ = $1.getValue() / $3.getValue(); } + | '-' num %prec NEG { $$ = -$2.getValue(); } + | num '^' num { $$ = pow ($1.getValue(), $3.getValue());} + | '(' num ')' { $$ = $2; } + | ACOS '(' num ')' { $$ = acos($3.getValue()); } + | ASIN '(' num ')' { $$ = asin($3.getValue()); } + | ATAN '(' num ')' { $$ = atan($3.getValue()); } + | ATAN2 '(' num ',' num ')' { $$ = atan2($3.getValue(),$5.getValue());} + | ABS '(' num ')' { $$ = fabs($3.getValue()); } + | EXP '(' num ')' { $$ = exp($3.getValue()); } + | MOD '(' num ',' num ')' { $$ = fmod($3.getValue(),$5.getValue()); } + | LOG '(' num ')' { $$ = log($3.getValue()); } + | LOG10 '(' num ')' { $$ = log10($3.getValue()); } + | POW '(' num ',' num ')' { $$ = pow($3.getValue(),$5.getValue()); } + | SIN '(' num ')' { $$ = sin($3.getValue()); } + | SINH '(' num ')' { $$ = sinh($3.getValue()); } + | TAN '(' num ')' { $$ = tan($3.getValue()); } + | TANH '(' num ')' { $$ = tanh($3.getValue()); } + | SQRT '(' num ')' { $$ = tanh($3.getValue()); } + | COS '(' num ')' { $$ = cos($3.getValue()); } +; + + unit: UNIT { $$ = $1; } + | unit '*' unit { $$ = $1 * $3; } + | unit '/' unit { $$ = $1 / $3; } + | unit '^' num { $$ = $1.pow ($3); } +; + quantity: num unit { $$ = $1*$2; } ; diff --git a/src/Base/QuantityPyImp.cpp b/src/Base/QuantityPyImp.cpp index 3deecf491..2a605ecd1 100644 --- a/src/Base/QuantityPyImp.cpp +++ b/src/Base/QuantityPyImp.cpp @@ -13,7 +13,11 @@ using namespace Base; // returns a string which represents the object e.g. when printed in python std::string QuantityPy::representation(void) const { - return std::string(""); + std::stringstream ret; + ret << getQuantityPtr()->getValue() << " "; + ret << getQuantityPtr()->getUnit().getString(); + + return ret.str(); } PyObject *QuantityPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper diff --git a/src/Base/Unit.cpp b/src/Base/Unit.cpp index cc2d37847..bf00f2aa8 100644 --- a/src/Base/Unit.cpp +++ b/src/Base/Unit.cpp @@ -51,7 +51,14 @@ Unit::Unit(int8_t Length, Unit::Unit() { - + Sig.Length = 0; + Sig.Mass = 0; + Sig.Time = 0; + Sig.ElectricCurrent = 0; + Sig.ThermodynamicTemperature = 0; + Sig.AmountOfSubstance = 0; + Sig.LuminoseIntensity = 0; + Sig.Angle = 0; } Unit::Unit(const Unit& that) @@ -148,4 +155,125 @@ Unit& Unit::operator = (const Unit &New) Sig.Angle = New.Sig.Angle ; return *this; +} + +std::string Unit::getString(void) const +{ + std::stringstream ret; + + if(isEmpty()) + return ""; + + if( Sig.Length > 0 || + Sig.Mass > 0 || + Sig.Time > 0 || + Sig.ElectricCurrent > 0 || + Sig.ThermodynamicTemperature> 0 || + Sig.AmountOfSubstance > 0 || + Sig.LuminoseIntensity > 0 || + Sig.Angle > 0 ){ + if(Sig.Length > 0){ + ret << "mm"; + if(Sig.Length >1) + ret << "^" << Sig.Length; + } + if(Sig.Mass > 0){ + ret << "kg"; + if(Sig.Mass >1) + ret << "^" << Sig.Mass; + } + if(Sig.Time > 0){ + ret << "s"; + if(Sig.Time >1) + ret << "^" << Sig.Time; + } + if(Sig.ElectricCurrent > 0){ + ret << "A"; + if(Sig.ElectricCurrent >1) + ret << "^" << Sig.ElectricCurrent; + } + if(Sig.ThermodynamicTemperature > 0){ + ret << "K"; + if(Sig.ThermodynamicTemperature >1) + ret << "^" << Sig.ThermodynamicTemperature; + } + if(Sig.AmountOfSubstance > 0){ + ret << "mol"; + if(Sig.AmountOfSubstance >1) + ret << "^" << Sig.AmountOfSubstance; + } + if(Sig.LuminoseIntensity > 0){ + ret << "cd"; + if(Sig.LuminoseIntensity >1) + ret << "^" << Sig.LuminoseIntensity; + } + if(Sig.Angle > 0){ + ret << "deg"; + if(Sig.Angle >1) + ret << "^" << Sig.Angle; + } + }else{ + ret << "1"; + } + + if( Sig.Length < 0 || + Sig.Mass < 0 || + Sig.Time < 0 || + Sig.ElectricCurrent < 0 || + Sig.ThermodynamicTemperature< 0 || + Sig.AmountOfSubstance < 0 || + Sig.LuminoseIntensity < 0 || + Sig.Angle < 0 ){ + ret << "/"; + if(Sig.Length < 0){ + ret << "mm"; + if(Sig.Length <-1) + ret << "^" << abs(Sig.Length); + } + if(Sig.Mass < 0){ + ret << "kg"; + if(Sig.Mass <-1) + ret << "^" << abs(Sig.Mass); + } + if(Sig.Time < 0){ + ret << "s"; + if(Sig.Time <-1) + ret << "^" << abs(Sig.Time); + } + if(Sig.ElectricCurrent < 0){ + ret << "A"; + if(Sig.ElectricCurrent <-1) + ret << "^" << abs(Sig.ElectricCurrent); + } + if(Sig.ThermodynamicTemperature < 0){ + ret << "K"; + if(Sig.ThermodynamicTemperature <-1) + ret << "^" << abs(Sig.ThermodynamicTemperature); + } + if(Sig.AmountOfSubstance < 0){ + ret << "mol"; + if(Sig.AmountOfSubstance <-1) + ret << "^" << abs(Sig.AmountOfSubstance); + } + if(Sig.LuminoseIntensity < 0){ + ret << "cd"; + if(Sig.LuminoseIntensity <-1) + ret << "^" << abs(Sig.LuminoseIntensity); + } + if(Sig.Angle < 0){ + ret << "deg"; + if(Sig.Angle <-1) + ret << "^" << abs(Sig.Angle); + } + } + + + + + + + + + + return ret.str(); } \ No newline at end of file diff --git a/src/Base/Unit.h b/src/Base/Unit.h index 8c1f92701..ce5fb3fb7 100644 --- a/src/Base/Unit.h +++ b/src/Base/Unit.h @@ -73,6 +73,7 @@ public: bool isEmpty(void)const; char getLengthDimension(void){return Sig.Length;} + std::string getString(void) const; protected: UnitSignature Sig; diff --git a/src/Base/UnitsApi.h b/src/Base/UnitsApi.h index 1b2fdcd64..40fdfb673 100644 --- a/src/Base/UnitsApi.h +++ b/src/Base/UnitsApi.h @@ -132,6 +132,7 @@ protected: protected: // the python API wrapper methodes static PyObject *sTranslateUnit (PyObject *self,PyObject *args,PyObject *kwd); static PyObject *sGetWithPrefs (PyObject *self,PyObject *args,PyObject *kwd); + static PyObject *sParseQuantity (PyObject *self,PyObject *args,PyObject *kwd); }; } // namespace Base diff --git a/src/Base/UnitsApiPy.cpp b/src/Base/UnitsApiPy.cpp index 6af4bf725..f8b8eb5c8 100644 --- a/src/Base/UnitsApiPy.cpp +++ b/src/Base/UnitsApiPy.cpp @@ -31,6 +31,8 @@ #include "Exception.h" /// Here the FreeCAD includes sorted by Base,App,Gui...... #include "UnitsApi.h" +#include "Quantity.h" +#include "QuantityPy.h" @@ -66,6 +68,9 @@ PyMethodDef UnitsApi::Methods[] = { " Temperature \n" }, + {"parseQuantity", (PyCFunction) UnitsApi::sParseQuantity ,1, + "parseQuantity(string) -> Base.Quantity()\n\n" + }, {NULL, NULL, 0, NULL} /* Sentinel */ }; @@ -116,3 +121,25 @@ PyObject* UnitsApi::sGetWithPrefs(PyObject * /*self*/, PyObject *args,PyObject * } } +PyObject* UnitsApi::sParseQuantity(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/) +{ + char *pstr; + if (!PyArg_ParseTuple(args, "s", &pstr)) // convert args: Python->C + return NULL; // NULL triggers exception + + Quantity rtn; + try { + rtn = Quantity::parse(pstr); + } + catch (const Base::Exception&) { + PyErr_Format(PyExc_IOError, "invalid unit expression \n"); + return 0L; + } + catch (const std::exception&) { + PyErr_Format(PyExc_IOError, "invalid unit expression \n"); + return 0L; + } + + return new QuantityPy(new Quantity(rtn)); + +}