diff --git a/Engine/bin/bison-flex/FlexLexer.h b/Engine/bin/bison-flex/FlexLexer.h new file mode 100644 index 000000000..c4dad2b14 --- /dev/null +++ b/Engine/bin/bison-flex/FlexLexer.h @@ -0,0 +1,220 @@ +// -*-C++-*- +// FlexLexer.h -- define interfaces for lexical analyzer classes generated +// by flex + +// Copyright (c) 1993 The Regents of the University of California. +// All rights reserved. +// +// This code is derived from software contributed to Berkeley by +// Kent Williams and Tom Epperly. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: + +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. + +// Neither the name of the University nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. + +// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE. + +// This file defines FlexLexer, an abstract class which specifies the +// external interface provided to flex C++ lexer objects, and yyFlexLexer, +// which defines a particular lexer class. +// +// If you want to create multiple lexer classes, you use the -P flag +// to rename each yyFlexLexer to some other xxFlexLexer. You then +// include in your other sources once per lexer class: +// +// #undef yyFlexLexer +// #define yyFlexLexer xxFlexLexer +// #include +// +// #undef yyFlexLexer +// #define yyFlexLexer zzFlexLexer +// #include +// ... + +#ifndef __FLEX_LEXER_H +// Never included before - need to define base class. +#define __FLEX_LEXER_H + +#include + +extern "C++" { + +struct yy_buffer_state; +typedef int yy_state_type; + +class FlexLexer +{ +public: + virtual ~FlexLexer() { } + + const char* YYText() const { return yytext; } + int YYLeng() const { return yyleng; } + + virtual void + yy_switch_to_buffer( yy_buffer_state* new_buffer ) = 0; + virtual yy_buffer_state* yy_create_buffer( std::istream* s, int size ) = 0; + virtual yy_buffer_state* yy_create_buffer( std::istream& s, int size ) = 0; + virtual void yy_delete_buffer( yy_buffer_state* b ) = 0; + virtual void yyrestart( std::istream* s ) = 0; + virtual void yyrestart( std::istream& s ) = 0; + + virtual int yylex() = 0; + + // Call yylex with new input/output sources. + int yylex( std::istream& new_in, std::ostream& new_out ) + { + switch_streams( new_in, new_out ); + return yylex(); + } + + int yylex( std::istream* new_in, std::ostream* new_out = 0) + { + switch_streams( new_in, new_out ); + return yylex(); + } + + // Switch to new input/output streams. A nil stream pointer + // indicates "keep the current one". + virtual void switch_streams( std::istream* new_in, + std::ostream* new_out ) = 0; + virtual void switch_streams( std::istream& new_in, + std::ostream& new_out ) = 0; + + int lineno() const { return yylineno; } + + int debug() const { return yy_flex_debug; } + void set_debug( int flag ) { yy_flex_debug = flag; } + +protected: + char* yytext; + int yyleng; + int yylineno; // only maintained if you use %option yylineno + int yy_flex_debug; // only has effect with -d or "%option debug" +}; + +} +#endif // FLEXLEXER_H + +#if defined(yyFlexLexer) || ! defined(yyFlexLexerOnce) +// Either this is the first time through (yyFlexLexerOnce not defined), +// or this is a repeated include to define a different flavor of +// yyFlexLexer, as discussed in the flex manual. +# define yyFlexLexerOnce + +extern "C++" { + +class yyFlexLexer : public FlexLexer { +public: + // arg_yyin and arg_yyout default to the cin and cout, but we + // only make that assignment when initializing in yylex(). + yyFlexLexer( std::istream& arg_yyin, std::ostream& arg_yyout ); + yyFlexLexer( std::istream* arg_yyin = 0, std::ostream* arg_yyout = 0 ); +private: + void ctor_common(); + +public: + + virtual ~yyFlexLexer(); + + void yy_switch_to_buffer( yy_buffer_state* new_buffer ); + yy_buffer_state* yy_create_buffer( std::istream* s, int size ); + yy_buffer_state* yy_create_buffer( std::istream& s, int size ); + void yy_delete_buffer( yy_buffer_state* b ); + void yyrestart( std::istream* s ); + void yyrestart( std::istream& s ); + + void yypush_buffer_state( yy_buffer_state* new_buffer ); + void yypop_buffer_state(); + + virtual int yylex(); + virtual void switch_streams( std::istream& new_in, std::ostream& new_out ); + virtual void switch_streams( std::istream* new_in = 0, std::ostream* new_out = 0 ); + virtual int yywrap(); + +protected: + virtual int LexerInput( char* buf, int max_size ); + virtual void LexerOutput( const char* buf, int size ); + virtual void LexerError( const char* msg ); + + void yyunput( int c, char* buf_ptr ); + int yyinput(); + + void yy_load_buffer_state(); + void yy_init_buffer( yy_buffer_state* b, std::istream& s ); + void yy_flush_buffer( yy_buffer_state* b ); + + int yy_start_stack_ptr; + int yy_start_stack_depth; + int* yy_start_stack; + + void yy_push_state( int new_state ); + void yy_pop_state(); + int yy_top_state(); + + yy_state_type yy_get_previous_state(); + yy_state_type yy_try_NUL_trans( yy_state_type current_state ); + int yy_get_next_buffer(); + + std::istream yyin; // input source for default LexerInput + std::ostream yyout; // output sink for default LexerOutput + + // yy_hold_char holds the character lost when yytext is formed. + char yy_hold_char; + + // Number of characters read into yy_ch_buf. + int yy_n_chars; + + // Points to current character in buffer. + char* yy_c_buf_p; + + int yy_init; // whether we need to initialize + int yy_start; // start state number + + // Flag which is used to allow yywrap()'s to do buffer switches + // instead of setting up a fresh yyin. A bit of a hack ... + int yy_did_buffer_switch_on_eof; + + + size_t yy_buffer_stack_top; /**< index of top of stack. */ + size_t yy_buffer_stack_max; /**< capacity of stack. */ + yy_buffer_state ** yy_buffer_stack; /**< Stack as an array. */ + void yyensure_buffer_stack(void); + + // The following are not always needed, but may be depending + // on use of certain flex features (like REJECT or yymore()). + + yy_state_type yy_last_accepting_state; + char* yy_last_accepting_cpos; + + yy_state_type* yy_state_buf; + yy_state_type* yy_state_ptr; + + char* yy_full_match; + int* yy_full_state; + int yy_full_lp; + + int yy_lp; + int yy_looking_for_trail_begin; + + int yy_more_flag; + int yy_more_len; + int yy_more_offset; + int yy_prev_more_offset; +}; + +} + +#endif // yyFlexLexer || ! yyFlexLexerOnce diff --git a/Engine/bin/bison-flex/README.md b/Engine/bin/bison-flex/README.md new file mode 100644 index 000000000..b4e96ec46 --- /dev/null +++ b/Engine/bin/bison-flex/README.md @@ -0,0 +1,34 @@ +# WinFlexBison - Flex and Bison for Microsoft Windows + +WinFlexBison is a Windows port of [Flex (the fast lexical analyser)](https://github.com/westes/flex/) and [GNU Bison (parser generator)](https://www.gnu.org/software/bison/). +Both win_flex and win_bison are based on upstream sources but depend on system libraries only. + +**NOTE**: +* 2.4.x versions include GNU Bison version 2.7 +* 2.5.x versions include GNU Bison version 3.x.x + +## License +Flex uses a [BSD license](flex/src/COPYING), GNU Bison is [licensed under the GNU General Public License (GPLv3+)](bison/src/COPYING). +All build scripts in WinFlexBison are distributed under GPLv3+. See [COPYING](COPYING) for details. + +All documentation, especially those under custom_build_rules/doc, is distributed under the GNU Free Documentation License (FDL 1.3+). + +## Build status +Bison 3.x (master) [![Build status](https://ci.appveyor.com/api/projects/status/58lcjnr0mb9uc8c8/branch/master?svg=true)](https://ci.appveyor.com/project/lexxmark/winflexbison/branch/master) and, for compatibility reasons, Bison 2.7 (bison2.7) [![Build status](https://ci.appveyor.com/api/projects/status/58lcjnr0mb9uc8c8/branch/bison2.7?svg=true)](https://ci.appveyor.com/project/lexxmark/winflexbison/branch/bison2.7) + +## Downloads +https://github.com/lexxmark/winflexbison/releases provides stable versions. +To test non-released development versions see the artifacts provided by CI under "Build status". + +## Changelog +The release page includes the full Changelog but you may also see the [changelog.md](changelog.md) file. + +## Build requirements +* Visual Studio 2017 or newer +* optional: CMake (when building with CMake) + +## HowTo +You may use win_flex and win_bison directly on the command line or [use them via CustomBuildRules in VisualStudio](custom_build_rules/README.md). + +## Example flex/bison files +See https://github.com/meyerd/flex-bison-example diff --git a/Engine/bin/bison/bison.hairy b/Engine/bin/bison-flex/bison.hairy similarity index 100% rename from Engine/bin/bison/bison.hairy rename to Engine/bin/bison-flex/bison.hairy diff --git a/Engine/bin/bison/bison.simple b/Engine/bin/bison-flex/bison.simple similarity index 100% rename from Engine/bin/bison/bison.simple rename to Engine/bin/bison-flex/bison.simple diff --git a/Engine/bin/bison-flex/changelog.md b/Engine/bin/bison-flex/changelog.md new file mode 100644 index 000000000..5d80cecce --- /dev/null +++ b/Engine/bin/bison-flex/changelog.md @@ -0,0 +1,166 @@ +## Changelog + +**NOTE**: + * 2.4.x versions include bison version 2.7 + * 2.5.x versions include bison version 3.x + +### version 2.5.25 + * upgrade win_bison to version 3.8.2 + * upgrade m4 to version 1.4.19 + +### version 2.5.24 + * upgrade win_bison to version 3.7.4 + * upgrade m4 to version 1.4.18 + * upgrade gnulib + * removed VS2015 support + * fixed win_bison --update option (renaming opened file) + +### version 2.5.23 + * upgrade win_bison to version 3.7.1 + +### version 2.5.22 + * upgrade win_bison to version 3.5.0 + +### version 2.5.21 + * avoid _m4eof lines in generated bison code while printing warnings + +### version 2.5.20 + * recovered invoking win_bison from different folders + +### version 2.5.19 + * upgrade win_bison to version 3.4.1 + +### version 2.5.18 + * upgrade win_bison to version 3.3.2 + +### version 2.5.17 + * upgrade win_bison to version 3.3.1 + +### version 2.5.16 + * upgrade win_bison to version 3.1 + * write output flex/bison files in binary mode "wb" that means use '\n' EOL not '\r\n' + * documentation about how to use the custom build-rules is now included + +### versions 2.4.12/2.5.15 + * upgrade win_bison to version 3.0.5 + +### versions 2.4.12/2.5.14 + * revert to Visual Studio 2015 due to false positive virus alarms for win_flex.exe + +### versions 2.4.11/2.5.13 + * fixed VS 2017 compilation errors in location.cc + +### versions 2.4.11/2.5.12 + * migrate to Visual Studio 2017 + +### versions 2.4.10/2.5.11 + * upgrade win_flex to version 2.6.4 + * fixed compilation warnings + +### versions 2.4.9/2.5.10 + * data folder was up to dated for bison 3.0.4 + +### versions 2.4.9/2.5.9 + * recovered --header-file win_flex option + +### versions 2.4.8/2.5.8 + * fixed outdated FlexLexer.h file + +### versions 2.4.7/2.5.7 + * upgrade win_flex to version 2.6.3 + * fixed compilation warnings + +### versions 2.4.6/2.5.6 + * upgrade win_bison to version 3.0.4 + * win_bison v2.7 is unchanged + * add separate custom build rules + * for win_bison `custom_build_rules\win_bison_only` + * and win_flex `custom_build_rules\win_flex_only` + +### versions 2.4.5/2.5.5 + * fix missing Additional Options in custom build rules + * fix incorrect "----header-file" option in flex custom build rules + * add some extra flex options to Visual Studio property pages: + 1. Prefix (--prefix="...") + 2. C++ Class Name (--yyclass="...") + +###versions 2.4.4/2.5.4 + * fix silent errors in custom build rules + * add some flex/bison options to Visual Studio property pages: + * Bison: + 1. Output File Name (--output="...") + 2. Defines File Name (--defines="...") + 3. Debug (--debug) + 4. Verbose (--verbose) + 5. No lines (--no-lines) + 6. File Prefix (--file-prefix="...") + 7. Graph File (--graph="...") + 8. Warnings (--warnings="...") + 9. Report (--report="...") + 10. Report File Name (--report-file="...") + + * Flex: + 1. Output File Name (--outfile="...") + 2. Header File Name (--header-file="...") + 3. Windows compatibility mode (--wincompat) + 4. Case-insensitive mode (--case-insensitive) + 5. Lex-compatibility mode (--lex-compat) + 6. Start Condition Stacks (--stack) + 7. Bison Bridge Mode (--bison-bridge) + 8. No #line Directives (--noline) + 9. Generate Reentrant Scanner (--reentrant) + 10. Generate C++ Scanner (--c++) + 11. Debug Mode (--debug) + +### versions 2.4.3/2.5.3 + * fix incorrect #line directives in win_flex.exe +see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=542482 + +### versions 2.4.2/2.5.2 + * backport parallel invocations of win_bison version 2.7 + * win_bison of version 3.0 is unchanged + +### versions 2.4.1/2.5.1 + * remove XSI extention syntax for fprintf function (not implemented in windows) + * this fixes Graphviz files generation for bison + +**NOTE**: + * 2.4.x versions will include bison version 2.7 + * 2.5.x versions will include bison version 3.0 + +### version 2.5 + * upgrade win_bison to version 3.0 and make temporary win_bison's files process unique (so parallel invocations of win_bison are possible) + +**NOTE**: Several deprecated features were removed in bison 3.0 so this version can break your projects. +Please see http://savannah.gnu.org/forum/forum.php?forum_id=7663 +For the reason of compatibility I don't change win_flex_bison-latest.zip to refer to win_flex_bison-2.5.zip file. +It still refer to win_flex_bison-2.4.zip + +### version 2.4 + * fix problem with "m4_syscmd is not implemented" message. + * Now win_bison should output correct diagnostic and error messages. + +### version 2.3 + * hide __attribute__ construction for non GCC compilers + +### version 2.2 + * added --wincompat option to win_flex (this option changes `` unix include with `` windows analog + also `isatty/fileno` functions changed to `_isatty/_fileno`) +fixed two "'<' : signed/unsigned mismatch" warnings in win_flex generated file + +### version 2.1 + * fixed crash when execute win_bison.exe under WindowsXP (argv[0] don't have full application path) + * added win_flex_bison-latest.zip package to freeze download link + +### version 2.0 + * upgrade win_bison to version 2.7 and win_flex to version 2.5.37 + +### version 1.2 + * fixed win_flex.exe #line directives (some #line directives in output file were with unescaped backslashes) + +### version 1.1 + * fixed win_flex.exe parallel invocations (now all temporary files are process specific) + * added FLEX_TMP_DIR environment variable support to redirect temporary files folder + * added '.exe' to program name in win_flex.exe --version output (CMake support) + * fixed win_bison.exe to use "/data" subfolder related to executable path rather than current working directory + * added BISON_PKGDATADIR environment variable to redirect "/data" subfolder to a different place diff --git a/Engine/bin/bison-flex/custom_build_rules/README.md b/Engine/bin/bison-flex/custom_build_rules/README.md new file mode 100644 index 000000000..181d7d80f --- /dev/null +++ b/Engine/bin/bison-flex/custom_build_rules/README.md @@ -0,0 +1,173 @@ + +How to setup custom build rules for Visual Studio 2010 and up. +--------------- + +First of all you should have the necessary files. +Custom Build rules are separated into a file triplet of `.xml`, `.targets` and `.props`. + +You find the custom build rules for win_flex_bison in the **custom_build_rules** directory of the win_flex_bison archive. + +You may choose to install one of the following rule set + +* the combined rules - [alternative download][1]: + * [win_flex_bison_custom_build.props ](win_flex_bison/win_flex_bison_custom_build.props) + * [win_flex_bison_custom_build.targets](win_flex_bison/win_flex_bison_custom_build.targets) + * [win_flex_bison_custom_build.xml ](win_flex_bison/win_flex_bison_custom_build.xml) + +* flex only rules - [alternative download][2]: + * [win_flex_custom_build.props ](win_flex_only/win_flex_custom_build.props) + * [win_flex_custom_build.targets ](win_flex_only/win_flex_custom_build.targets) + * [win_flex_custom_build.xml ](win_flex_only/win_flex_custom_build.xml) + +* bison only rules - [alternative download][3]: + * [win_bison_custom_build.props ](win_bison_only/win_bison_custom_build.props) + * [win_bison_custom_build.targets](win_bison_only/win_bison_custom_build.targets) + * [win_bison_custom_build.xml ](win_bison_only/win_bison_custom_build.xml) + +This documentation uses the combined rule-set but can be used for all rule-sets. + +[1]: https://sourceforge.net/projects/winflexbison/files/win_flex_bison_custom_build_rules.zip/download "Combined build rules for Bison and Flex" +[2]: https://sourceforge.net/projects/winflexbison/files/win_flex_custom_build_rules.zip/download "Build rules for Flex only" +[3]: https://sourceforge.net/projects/winflexbison/files/win_bison_custom_build_rules.zip/download "Build rules for Bison only" + +---- + +Launch Visual Studio and open an VC/VC++ project. +Open context menu for project item in Solution Explorer panel and select "**Build Customizations...**" menu item. +(Note: newer VS versions have this below sub-menu "**Build Dependencies...**".) + +![Build Customizations in Solution Explorer](docs/1.png) + +---- + +In popup dialog "Visual C++ Build Customization Files" press "**Find Existing...**" button. + +![Customization Files](docs/2.png) + +---- + +In Open File dialog select "**win_flex_bison_custom_build.targets**" file and press "Open". +(Note: you may have to switch the file filter to "(*.*) all files".) + +---- + +You will see "Add Search Path?" message box, press "Yes". + +![Adding Search Path](docs/3.png) + +---- + +In "Visual C++ Build Customization Files" dialog check just added item **win_flex_bison_custom_build** and press "OK". + +![activate custom build rule](docs/4.png) + +---- + +Now you can add flex and bison files to the project... + +![project with flex and bison files added](docs/5.png) + +... and build. +In build output you should see something like this: + +~~~~ + +1>------ Rebuild All started: Project: ConsoleApplication1, Configuration: Debug Win32 ------ +1> Process sample bison file +1> Process sample flex file +1> stdafx.cpp +1> ConsoleApplication1.cpp +1> Generating Code... +1> ConsoleApplication1.vcxproj -> C:\Users\ConsoleApplication1\Debug\ConsoleApplication1.exe +========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ========== + +~~~~ + +----- + +For **sample.y** bison file there are two output files: **sample.tab.h** and **sample.tab.cpp**. +For **sample.l** flex file you'll got **sample.flex.cpp**. + +Now you can add them to the project and build. (*Don't forget to exclude cpp files from using precompiled headers*) + +![Include generated files into Solution](docs/6.png) + +~~~~ + +1>------ Build started: Project: ConsoleApplication1, Configuration: Debug Win32 ------ +1> Process sample bison file +1> Process sample flex file +1> sample.tab.cpp +1> sample.flex.cpp +1> Generating Code... +1> ConsoleApplication1.vcxproj -> C:\Users\ConsoleApplication1\Debug\ConsoleApplication1.exe +========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ========== + +~~~~ + +---- + +If your flex/bison file is incorrect and you've got an error. But you don't see actual error message, something like this: + +~~~~ + +1>------ Build started: Project: ConsoleApplication2, Configuration: Debug Win32 ------ +1> Process "grammar.y" bison file +1>C:...\custom_build_rules\win_flex_bison_custom_build.targets(55,5): error MSB3721: The command " +1>C:...\custom_build_rules\win_flex_bison_custom_build.targets(55,5): error MSB3721: start /B /WAIT /D "C:...\ConsoleApplication2\ConsoleApplication2\" win_bison.exe --output="grammar.tab.cpp" --defines="grammar.tab.h" --graph="1.dot" "grammar.y" +1>C:...\custom_build_rules\win_flex_bison_custom_build.targets(55,5): error MSB3721: exit /b %errorlevel%" exited with code 1. +========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== + +~~~~ + +You can change Build Output Verbosity from "Minimal" to "Normal" in "Options" dialog + +![Verbosity](docs/Verbosity.png) + +Then you will see more detailed output: + +~~~~ + +1>BisonTarget: +1> Process "grammar.y" bison file +1> grammar.y:51.1-4: error: invalid directive: '%sdw' +1>C:...\custom_build_rules\win_flex_bison_custom_build.targets(55,5): error MSB3721: The command " +1>C:...\custom_build_rules\win_flex_bison_custom_build.targets(55,5): error MSB3721: start /B /WAIT /D "C:...\ConsoleApplication2\" win_bison.exe --output="grammar.tab.cpp" --defines="grammar.tab.h" --graph="1.dot" "grammar.y" +1>C:...\custom_build_rules\win_flex_bison_custom_build.targets(55,5): error MSB3721: exit /b %errorlevel%" exited with code 1. +1> +1>Build FAILED. +1> +1>Time Elapsed 00:00:01.21 +========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== + +~~~~ + +---- + +Also you can tune some flex/bison options in files properties dialog: + +![Opening File Properties](docs/Properties.png) +![Property Page for Flex sources](docs/FlexProperties.png) +![Property Page for Bison sources](docs/BisonProperties.png) + +---- + + +To debug your scanner or parser you can set break points right into **sample.y** or **sample.l** code. + +![Debugging Flex source files](docs/Flex_debuging.png) + +---- + + +To use the Visual C++ Code editor for Flex/Bison files instead of the text editor adjust your editor settings as follows: + +* click **Options** on the **Tools** menu, expand the **Text Editor** node and select **File Extension** +* type extension **`l`** in the **Extension** field and choose **Microsoft Visual C++** in the **Editor** drop-down field, click **Add** +* do the same for the extension **`y`** + +You now have syntax highlighting, code-completion and show definition options in your Flex/Bison source. + +---- + +Enjoy! diff --git a/Engine/bin/bison-flex/custom_build_rules/docs/1.png b/Engine/bin/bison-flex/custom_build_rules/docs/1.png new file mode 100644 index 000000000..e29510ecb Binary files /dev/null and b/Engine/bin/bison-flex/custom_build_rules/docs/1.png differ diff --git a/Engine/bin/bison-flex/custom_build_rules/docs/2.png b/Engine/bin/bison-flex/custom_build_rules/docs/2.png new file mode 100644 index 000000000..9dd9532bb Binary files /dev/null and b/Engine/bin/bison-flex/custom_build_rules/docs/2.png differ diff --git a/Engine/bin/bison-flex/custom_build_rules/docs/3.png b/Engine/bin/bison-flex/custom_build_rules/docs/3.png new file mode 100644 index 000000000..8790139fa Binary files /dev/null and b/Engine/bin/bison-flex/custom_build_rules/docs/3.png differ diff --git a/Engine/bin/bison-flex/custom_build_rules/docs/4.png b/Engine/bin/bison-flex/custom_build_rules/docs/4.png new file mode 100644 index 000000000..288d79a2a Binary files /dev/null and b/Engine/bin/bison-flex/custom_build_rules/docs/4.png differ diff --git a/Engine/bin/bison-flex/custom_build_rules/docs/5.png b/Engine/bin/bison-flex/custom_build_rules/docs/5.png new file mode 100644 index 000000000..5b9e18f6d Binary files /dev/null and b/Engine/bin/bison-flex/custom_build_rules/docs/5.png differ diff --git a/Engine/bin/bison-flex/custom_build_rules/docs/6.png b/Engine/bin/bison-flex/custom_build_rules/docs/6.png new file mode 100644 index 000000000..5f51155ff Binary files /dev/null and b/Engine/bin/bison-flex/custom_build_rules/docs/6.png differ diff --git a/Engine/bin/bison-flex/custom_build_rules/docs/BisonProperties.png b/Engine/bin/bison-flex/custom_build_rules/docs/BisonProperties.png new file mode 100644 index 000000000..309365884 Binary files /dev/null and b/Engine/bin/bison-flex/custom_build_rules/docs/BisonProperties.png differ diff --git a/Engine/bin/bison-flex/custom_build_rules/docs/FlexProperties.png b/Engine/bin/bison-flex/custom_build_rules/docs/FlexProperties.png new file mode 100644 index 000000000..6f2c131b2 Binary files /dev/null and b/Engine/bin/bison-flex/custom_build_rules/docs/FlexProperties.png differ diff --git a/Engine/bin/bison-flex/custom_build_rules/docs/Flex_debuging.png b/Engine/bin/bison-flex/custom_build_rules/docs/Flex_debuging.png new file mode 100644 index 000000000..0ac6a6392 Binary files /dev/null and b/Engine/bin/bison-flex/custom_build_rules/docs/Flex_debuging.png differ diff --git a/Engine/bin/bison-flex/custom_build_rules/docs/Properties.png b/Engine/bin/bison-flex/custom_build_rules/docs/Properties.png new file mode 100644 index 000000000..e636e764f Binary files /dev/null and b/Engine/bin/bison-flex/custom_build_rules/docs/Properties.png differ diff --git a/Engine/bin/bison-flex/custom_build_rules/docs/Verbosity.png b/Engine/bin/bison-flex/custom_build_rules/docs/Verbosity.png new file mode 100644 index 000000000..b2997ba70 Binary files /dev/null and b/Engine/bin/bison-flex/custom_build_rules/docs/Verbosity.png differ diff --git a/Engine/bin/bison-flex/custom_build_rules/win_bison_only/win_bison_custom_build.props b/Engine/bin/bison-flex/custom_build_rules/win_bison_only/win_bison_custom_build.props new file mode 100644 index 000000000..d27b3a4b0 --- /dev/null +++ b/Engine/bin/bison-flex/custom_build_rules/win_bison_only/win_bison_custom_build.props @@ -0,0 +1,23 @@ + + + + Midl + CustomBuild + + + _SelectedFiles;$(BisonDependsOn) + + + + %(Filename).tab.cpp + %(Filename).tab.h + +start /B /WAIT /D "%(RootDir)%(Directory)" win_bison.exe [AllOptions] [AdditionalOptions] "%(Filename)%(Extension)" +exit /b %errorlevel% + %(RootDir)%(Directory)%(OutputFile);%(RootDir)%(Directory)%(DefinesFile); + Process "%(Filename)%(Extension)" bison file + + + \ No newline at end of file diff --git a/Engine/bin/bison-flex/custom_build_rules/win_bison_only/win_bison_custom_build.targets b/Engine/bin/bison-flex/custom_build_rules/win_bison_only/win_bison_custom_build.targets new file mode 100644 index 000000000..feb0de252 --- /dev/null +++ b/Engine/bin/bison-flex/custom_build_rules/win_bison_only/win_bison_custom_build.targets @@ -0,0 +1,91 @@ + + + + + + BisonTarget + + + + $(MSBuildThisFileDirectory)$(MSBuildThisFileName).xml + + + + + + + + @(Bison, '|') + + + + + + + + + $(ComputeLinkInputsTargets); + ComputeBisonOutput; + + + $(ComputeLibInputsTargets); + ComputeBisonOutput; + + + + + + + + + + + + \ No newline at end of file diff --git a/Engine/bin/bison-flex/custom_build_rules/win_bison_only/win_bison_custom_build.xml b/Engine/bin/bison-flex/custom_build_rules/win_bison_only/win_bison_custom_build.xml new file mode 100644 index 000000000..1d51e6260 --- /dev/null +++ b/Engine/bin/bison-flex/custom_build_rules/win_bison_only/win_bison_custom_build.xml @@ -0,0 +1,281 @@ + + + + + + + + + + General + + + + + Bison Options + + + + + Command Line + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Execute Before + + + Specifies the targets for the build customization to run before. + + + + + + + + + + + Execute After + + + Specifies the targets for the build customization to run after. + + + + + + + + + + + + + + Additional Options + + + Additional Options + + + + + + + \ No newline at end of file diff --git a/Engine/bin/bison-flex/custom_build_rules/win_flex_bison/win_flex_bison_custom_build.props b/Engine/bin/bison-flex/custom_build_rules/win_flex_bison/win_flex_bison_custom_build.props new file mode 100644 index 000000000..17317d6cb --- /dev/null +++ b/Engine/bin/bison-flex/custom_build_rules/win_flex_bison/win_flex_bison_custom_build.props @@ -0,0 +1,43 @@ + + + + Midl + CustomBuild + + + _SelectedFiles;$(BisonDependsOn) + + + + %(Filename).tab.cpp + %(Filename).tab.h + +start /B /WAIT /D "%(RootDir)%(Directory)" win_bison.exe [AllOptions] [AdditionalOptions] "%(Filename)%(Extension)" +exit /b %errorlevel% + %(RootDir)%(Directory)%(OutputFile);%(RootDir)%(Directory)%(DefinesFile); + Process "%(Filename)%(Extension)" bison file + + + + Midl + CustomBuild + + + _SelectedFiles;$(FlexDependsOn) + + + + %(Filename).flex.cpp + true + +start /B /WAIT /D "%(RootDir)%(Directory)" win_flex.exe [AllOptions] [AdditionalOptions] "%(Filename)%(Extension)" +exit /b %errorlevel% + %(RootDir)%(Directory)%(OutputFile); + Process "%(Filename)%(Extension)" flex file + + + \ No newline at end of file diff --git a/Engine/bin/bison-flex/custom_build_rules/win_flex_bison/win_flex_bison_custom_build.targets b/Engine/bin/bison-flex/custom_build_rules/win_flex_bison/win_flex_bison_custom_build.targets new file mode 100644 index 000000000..2fabf7453 --- /dev/null +++ b/Engine/bin/bison-flex/custom_build_rules/win_flex_bison/win_flex_bison_custom_build.targets @@ -0,0 +1,178 @@ + + + + + + BisonTarget + + + FlexTarget + + + + $(MSBuildThisFileDirectory)$(MSBuildThisFileName).xml + + + $(MSBuildThisFileDirectory)$(MSBuildThisFileName).xml + + + + + + + + @(Bison, '|') + + + + + + + + + $(ComputeLinkInputsTargets); + ComputeBisonOutput; + + + $(ComputeLibInputsTargets); + ComputeBisonOutput; + + + + + + + + + + + + + + + + + + @(Flex, '|') + + + + + + + + + $(ComputeLinkInputsTargets); + ComputeFlexOutput; + + + $(ComputeLibInputsTargets); + ComputeFlexOutput; + + + + + + + + + + + + \ No newline at end of file diff --git a/Engine/bin/bison-flex/custom_build_rules/win_flex_bison/win_flex_bison_custom_build.xml b/Engine/bin/bison-flex/custom_build_rules/win_flex_bison/win_flex_bison_custom_build.xml new file mode 100644 index 000000000..20c429ca2 --- /dev/null +++ b/Engine/bin/bison-flex/custom_build_rules/win_flex_bison/win_flex_bison_custom_build.xml @@ -0,0 +1,521 @@ + + + + + + + + + + General + + + + + Bison Options + + + + + Command Line + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Execute Before + + + Specifies the targets for the build customization to run before. + + + + + + + + + + + Execute After + + + Specifies the targets for the build customization to run after. + + + + + + + + + + + + + + Additional Options + + + Additional Options + + + + + + + + + + + + + + General + + + + + Flex Options + + + + + Command Line + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Execute Before + + + Specifies the targets for the build customization to run before. + + + + + + + + + + + Execute After + + + Specifies the targets for the build customization to run after. + + + + + + + + + + + + + + Additional Options + + + Additional Options + + + + + + + \ No newline at end of file diff --git a/Engine/bin/bison-flex/custom_build_rules/win_flex_only/win_flex_custom_build.props b/Engine/bin/bison-flex/custom_build_rules/win_flex_only/win_flex_custom_build.props new file mode 100644 index 000000000..9203b4ae0 --- /dev/null +++ b/Engine/bin/bison-flex/custom_build_rules/win_flex_only/win_flex_custom_build.props @@ -0,0 +1,23 @@ + + + + Midl + CustomBuild + + + _SelectedFiles;$(FlexDependsOn) + + + + %(Filename).flex.cpp + true + +start /B /WAIT /D "%(RootDir)%(Directory)" win_flex.exe [AllOptions] [AdditionalOptions] "%(Filename)%(Extension)" +exit /b %errorlevel% + %(RootDir)%(Directory)%(OutputFile); + Process "%(Filename)%(Extension)" flex file + + + \ No newline at end of file diff --git a/Engine/bin/bison-flex/custom_build_rules/win_flex_only/win_flex_custom_build.targets b/Engine/bin/bison-flex/custom_build_rules/win_flex_only/win_flex_custom_build.targets new file mode 100644 index 000000000..2e8155507 --- /dev/null +++ b/Engine/bin/bison-flex/custom_build_rules/win_flex_only/win_flex_custom_build.targets @@ -0,0 +1,94 @@ + + + + + + FlexTarget + + + + $(MSBuildThisFileDirectory)$(MSBuildThisFileName).xml + + + + + + + + @(Flex, '|') + + + + + + + + + $(ComputeLinkInputsTargets); + ComputeFlexOutput; + + + $(ComputeLibInputsTargets); + ComputeFlexOutput; + + + + + + + + + + + + \ No newline at end of file diff --git a/Engine/bin/bison-flex/custom_build_rules/win_flex_only/win_flex_custom_build.xml b/Engine/bin/bison-flex/custom_build_rules/win_flex_only/win_flex_custom_build.xml new file mode 100644 index 000000000..a47157445 --- /dev/null +++ b/Engine/bin/bison-flex/custom_build_rules/win_flex_only/win_flex_custom_build.xml @@ -0,0 +1,243 @@ + + + + + + + + + + General + + + + + Flex Options + + + + + Command Line + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Execute Before + + + Specifies the targets for the build customization to run before. + + + + + + + + + + + Execute After + + + Specifies the targets for the build customization to run after. + + + + + + + + + + + + + + Additional Options + + + Additional Options + + + + + + + \ No newline at end of file diff --git a/Engine/bin/bison-flex/data/README.md b/Engine/bin/bison-flex/data/README.md new file mode 100644 index 000000000..09886ea81 --- /dev/null +++ b/Engine/bin/bison-flex/data/README.md @@ -0,0 +1,227 @@ +This directory contains data needed by Bison. + +# Directory Content +## Skeletons +Bison skeletons: the general shapes of the different parser kinds, that are +specialized for specific grammars by the bison program. + +Currently, the supported skeletons are: + +- yacc.c + It used to be named bison.simple: it corresponds to C Yacc + compatible LALR(1) parsers. + +- lalr1.cc + Produces a C++ parser class. + +- lalr1.java + Produces a Java parser class. + +- glr.c + A Generalized LR C parser based on Bison's LALR(1) tables. + +- glr.cc + A Generalized LR C++ parser. Actually a C++ wrapper around glr.c. + +These skeletons are the only ones supported by the Bison team. Because the +interface between skeletons and the bison program is not finished, *we are +not bound to it*. In particular, Bison is not mature enough for us to +consider that "foreign skeletons" are supported. + +## m4sugar +This directory contains M4sugar, sort of an extended library for M4, which +is used by Bison to instantiate the skeletons. + +## xslt +This directory contains XSLT programs that transform Bison's XML output into +various formats. + +- bison.xsl + A library of routines used by the other XSLT programs. + +- xml2dot.xsl + Conversion into GraphViz's dot format. + +- xml2text.xsl + Conversion into text. + +- xml2xhtml.xsl + Conversion into XHTML. + +# Implementation Notes About the Skeletons + +"Skeleton" in Bison parlance means "backend": a skeleton is fed by the bison +executable with LR tables, facts about the symbols, etc. and they generate +the output (say parser.cc, parser.hh, location.hh, etc.). They are only in +charge of generating the parser and its auxiliary files, they do not +generate the XML output, the parser.output reports, nor the graphical +rendering. + +The bits of information passing from bison to the backend is named +"muscles". Muscles are passed to M4 via its standard input: it's a set of +m4 definitions. To see them, use `--trace=muscles`. + +Except for muscles, whose names are generated by bison, the skeletons have +no constraint at all on the macro names: there is no technical/theoretical +limitation, as long as you generate the output, you can do what you want. +However, of course, that would be a bad idea if, say, the C and C++ +skeletons used different approaches and had completely different +implementations. That would be a maintenance nightmare. + +Below, we document some of the macros that we use in several of the +skeletons. If you are to write a new skeleton, please, implement them for +your language. Overall, be sure to follow the same patterns as the existing +skeletons. + +## Vocabulary + +We use "formal arguments", or "formals" for short, to denote the declared +parameters of a function (e.g., `int argc, const char **argv`). Yes, this +is somewhat contradictory with `param` in the `%param` directives. + +We use "effective arguments", or "args" for short, to denote the values +passed in function calls (e.g., `argc, argv`). + +## Symbols + +### `b4_symbol(NUM, FIELD)` +In order to unify the handling of the various aspects of symbols (tag, type +name, whether terminal, etc.), bison.exe defines one macro per (token, +field), where field can `has_id`, `id`, etc.: see +`prepare_symbol_definitions()` in `src/output.c`. + +NUM can be: +- `empty` to denote the "empty" pseudo-symbol when it exists, +- `eof`, `error`, or `undef` +- a symbol number. + +FIELD can be: + +- `has_id`: 0 or 1 + Whether the symbol has an `id`. + +- `id`: string (e.g., `exp`, `NUM`, or `TOK_NUM` with api.token.prefix) + If `has_id`, the name of the token kind (prefixed by api.token.prefix if + defined), otherwise empty. Guaranteed to be usable as a C identifier. + This is used to define the token kind (i.e., the enum used by the return + value of yylex). Should be named `token_kind`. + +- `tag`: string + A human readable representation of the symbol. Can be `'foo'`, + `'foo.id'`, `'"foo"'` etc. + +- `code`: integer + The token code associated to the token kind `id`. + The external number as used by yylex. Can be ASCII code when a character, + some number chosen by bison, or some user number in the case of `%token + FOO `. Corresponds to `yychar` in `yacc.c`. + +- `is_token`: 0 or 1 + Whether this is a terminal symbol. + +- `kind_base`: string (e.g., `YYSYMBOL_exp`, `YYSYMBOL_NUM`) + The base of the symbol kind, i.e., the enumerator of this symbol (token or + nonterminal) which is mapped to its `number`. + +- `kind`: string + Same as `kind_base`, but possibly with a prefix in some languages. E.g., + EOF's `kind_base` and `kind` are `YYSYMBOL_YYEOF` in C, but are + `S_YYEMPTY` and `symbol_kind::S_YYEMPTY` in C++. + +- `number`: integer + The code associated to the `kind`. + The internal number (computed from the external number by yytranslate). + Corresponds to yytoken in yacc.c. This is the same number that serves as + key in b4_symbol(NUM, FIELD). + + In bison, symbols are first assigned increasing numbers in order of + appearance (but tokens first, then nterms). After grammar reduction, + unused nterms are then renumbered to appear last (i.e., first tokens, then + used nterms and finally unused nterms). This final number NUM is the one + contained in this field, and it is the one used as key in `b4_symbol(NUM, + FIELD)`. + + The code of the rule actions, however, is emitted before we know what + symbols are unused, so they use the original numbers. To avoid confusion, + they actually use "orig NUM" instead of just "NUM". bison also emits + definitions for `b4_symbol(orig NUM, number)` that map from original + numbers to the new ones. `b4_symbol` actually resolves `orig NUM` in the + other case, i.e., `b4_symbol(orig 42, tag)` would return the tag of the + symbols whose original number was 42. + +- `has_type`: 0, 1 + Whether has a semantic value. + +- `type_tag`: string + When api.value.type=union, the generated name for the union member. + yytype_INT etc. for symbols that has_id, otherwise yytype_1 etc. + +- `type`: string + If it has a semantic value, its type tag, or, if variant are used, + its type. + In the case of api.value.type=union, type is the real type (e.g. int). + +- `slot`: string + If it has a semantic value, the name of the union member (i.e., bounces to + either `type_tag` or `type`). It would be better to fix our mess and + always use `type` for the true type of the member, and `type_tag` for the + name of the union member. + +- `has_printer`: 0, 1 +- `printer`: string +- `printer_file`: string +- `printer_line`: integer +- `printer_loc`: location + If the symbol has a printer, everything about it. + +- `has_destructor`, `destructor`, `destructor_file`, `destructor_line`, `destructor_loc` + Likewise. + +### `b4_symbol_value(VAL, [SYMBOL-NUM], [TYPE-TAG])` +Expansion of $$, $1, $3, etc. + +The semantic value from a given VAL. +- `VAL`: some semantic value storage (typically a union). e.g., `yylval` +- `SYMBOL-NUM`: the symbol number from which we extract the type tag. +- `TYPE-TAG`, the user forced the ``. + +The result can be used safely, it is put in parens to avoid nasty precedence +issues. + +### `b4_lhs_value(SYMBOL-NUM, [TYPE])` +Expansion of `$$` or `$$`, for symbol `SYMBOL-NUM`. + +### `b4_rhs_data(RULE-LENGTH, POS)` +The data corresponding to the symbol `#POS`, where the current rule has +`RULE-LENGTH` symbols on RHS. + +### `b4_rhs_value(RULE-LENGTH, POS, SYMBOL-NUM, [TYPE])` +Expansion of `$POS`, where the current rule has `RULE-LENGTH` symbols +on RHS. + + diff --git a/Engine/bin/bison-flex/data/bison-default.css b/Engine/bin/bison-flex/data/bison-default.css new file mode 100644 index 000000000..aadaba178 --- /dev/null +++ b/Engine/bin/bison-flex/data/bison-default.css @@ -0,0 +1,61 @@ +/* Default styling rules for Bison when doing terminal output. + Copyright (C) 2019-2021 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 + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* This is an experimental feature. The class names may change in the + future. */ + +/* Diagnostics. */ +.warning { color: purple; } +.error { color: red; } +.note { color: cyan; } + +.fixit-insert { color: green; } + +/* Semantic values in Bison's own parser traces. */ +.value { color: green; } + +/* "Sections" in traces (--trace). */ +.trace0 { color: green; } + +/* Syntax error messages. */ +.expected { color: green; } +.unexpected { color: red; } + + +/* Counterexamples. */ + +/* Cex: point in rule. */ +.cex-dot { color: red; } + +/* Cex: coloring various rules. */ +.cex-0 { color: yellow; } +.cex-1 { color: green; } +.cex-2 { color: blue; } +.cex-3 { color: purple; } +.cex-4 { color: violet; } +.cex-5 { color: orange; } +.cex-6 { color: brown; } +.cex-7 { color: mauve; } +.cex-8 { color: #013220; } /* Dark green. */ +.cex-9 { color: #e75480; } /* Dark pink. */ +.cex-10 { color: cyan; } +.cex-11 { color: orange; } + +/* Cex: derivation rewriting steps. */ +.cex-step { font-style: italic; } + +/* Cex: leaves of a derivation. */ +.cex-leaf { font-weight: 600; } diff --git a/Engine/bin/bison-flex/data/local.mk b/Engine/bin/bison-flex/data/local.mk new file mode 100644 index 000000000..c51d287cc --- /dev/null +++ b/Engine/bin/bison-flex/data/local.mk @@ -0,0 +1,58 @@ +## Copyright (C) 2002, 2005-2015, 2018-2021 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 +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program. If not, see . + +dist_pkgdata_DATA = \ + data/README.md \ + data/bison-default.css + +skeletonsdir = $(pkgdatadir)/skeletons +dist_skeletons_DATA = \ + data/skeletons/bison.m4 \ + data/skeletons/c++-skel.m4 \ + data/skeletons/c++.m4 \ + data/skeletons/c-like.m4 \ + data/skeletons/c-skel.m4 \ + data/skeletons/c.m4 \ + data/skeletons/glr.c \ + data/skeletons/glr.cc \ + data/skeletons/glr2.cc \ + data/skeletons/java-skel.m4 \ + data/skeletons/java.m4 \ + data/skeletons/lalr1.cc \ + data/skeletons/lalr1.java \ + data/skeletons/location.cc \ + data/skeletons/stack.hh \ + data/skeletons/traceon.m4 \ + data/skeletons/variant.hh \ + data/skeletons/yacc.c + +# Experimental support for the D language. +dist_skeletons_DATA += \ + data/skeletons/d-skel.m4 \ + data/skeletons/d.m4 \ + data/skeletons/lalr1.d + +m4sugardir = $(pkgdatadir)/m4sugar +dist_m4sugar_DATA = \ + data/m4sugar/foreach.m4 \ + data/m4sugar/m4sugar.m4 + +xsltdir = $(pkgdatadir)/xslt +dist_xslt_DATA = \ + data/xslt/bison.xsl \ + data/xslt/xml2dot.xsl \ + data/xslt/xml2text.xsl \ + data/xslt/xml2xhtml.xsl diff --git a/Engine/bin/bison-flex/data/m4sugar/foreach.m4 b/Engine/bin/bison-flex/data/m4sugar/foreach.m4 new file mode 100644 index 000000000..2052d44c2 --- /dev/null +++ b/Engine/bin/bison-flex/data/m4sugar/foreach.m4 @@ -0,0 +1,362 @@ +# -*- Autoconf -*- +# This file is part of Autoconf. +# foreach-based replacements for recursive functions. +# Speeds up GNU M4 1.4.x by avoiding quadratic $@ recursion, but penalizes +# GNU M4 1.6 by requiring more memory and macro expansions. +# +# Copyright (C) 2008-2017, 2020 Free Software Foundation, Inc. + +# This file is part of Autoconf. 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 the +# Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# Under Section 7 of GPL version 3, you are granted additional +# permissions described in the Autoconf Configure Script Exception, +# version 3.0, as published by the Free Software Foundation. +# +# You should have received a copy of the GNU General Public License +# and a copy of the Autoconf Configure Script Exception along with +# this program; see the files COPYINGv3 and COPYING.EXCEPTION +# respectively. If not, see . + +# Written by Eric Blake. + +# In M4 1.4.x, every byte of $@ is rescanned. This means that an +# algorithm on n arguments that recurses with one less argument each +# iteration will scan n * (n + 1) / 2 arguments, for O(n^2) time. In +# M4 1.6, this was fixed so that $@ is only scanned once, then +# back-references are made to information stored about the scan. +# Thus, n iterations need only scan n arguments, for O(n) time. +# Additionally, in M4 1.4.x, recursive algorithms did not clean up +# memory very well, requiring O(n^2) memory rather than O(n) for n +# iterations. +# +# This file is designed to overcome the quadratic nature of $@ +# recursion by writing a variant of m4_foreach that uses m4_for rather +# than $@ recursion to operate on the list. This involves more macro +# expansions, but avoids the need to rescan a quadratic number of +# arguments, making these replacements very attractive for M4 1.4.x. +# On the other hand, in any version of M4, expanding additional macros +# costs additional time; therefore, in M4 1.6, where $@ recursion uses +# fewer macros, these replacements actually pessimize performance. +# Additionally, the use of $10 to mean the tenth argument violates +# POSIX; although all versions of m4 1.4.x support this meaning, a +# future m4 version may switch to take it as the first argument +# concatenated with a literal 0, so the implementations in this file +# are not future-proof. Thus, this file is conditionally included as +# part of m4_init(), only when it is detected that M4 probably has +# quadratic behavior (ie. it lacks the macro __m4_version__). +# +# Please keep this file in sync with m4sugar.m4. + +# _m4_foreach(PRE, POST, IGNORED, ARG...) +# --------------------------------------- +# Form the common basis of the m4_foreach and m4_map macros. For each +# ARG, expand PRE[ARG]POST[]. The IGNORED argument makes recursion +# easier, and must be supplied rather than implicit. +# +# This version minimizes the number of times that $@ is evaluated by +# using m4_for to generate a boilerplate into _m4_f then passing $@ to +# that temporary macro. Thus, the recursion is done in m4_for without +# reparsing any user input, and is not quadratic. For an idea of how +# this works, note that m4_foreach(i,[1,2],[i]) calls +# _m4_foreach([m4_define([i],],[)i],[],[1],[2]) +# which defines _m4_f: +# $1[$4]$2[]$1[$5]$2[]_m4_popdef([_m4_f]) +# then calls _m4_f([m4_define([i],],[)i],[],[1],[2]) for a net result: +# m4_define([i],[1])i[]m4_define([i],[2])i[]_m4_popdef([_m4_f]). +m4_define([_m4_foreach], +[m4_if([$#], [3], [], + [m4_pushdef([_m4_f], _m4_for([4], [$#], [1], + [$0_([1], [2],], [)])[_m4_popdef([_m4_f])])_m4_f($@)])]) + +m4_define([_m4_foreach_], +[[$$1[$$3]$$2[]]]) + +# m4_case(SWITCH, VAL1, IF-VAL1, VAL2, IF-VAL2, ..., DEFAULT) +# ----------------------------------------------------------- +# Find the first VAL that SWITCH matches, and expand the corresponding +# IF-VAL. If there are no matches, expand DEFAULT. +# +# Use m4_for to create a temporary macro in terms of a boilerplate +# m4_if with final cleanup. If $# is even, we have DEFAULT; if it is +# odd, then rounding the last $# up in the temporary macro is +# harmless. For example, both m4_case(1,2,3,4,5) and +# m4_case(1,2,3,4,5,6) result in the intermediate _m4_case being +# m4_if([$1],[$2],[$3],[$1],[$4],[$5],_m4_popdef([_m4_case])[$6]) +m4_define([m4_case], +[m4_if(m4_eval([$# <= 2]), [1], [$2], +[m4_pushdef([_$0], [m4_if(]_m4_for([2], m4_eval([($# - 1) / 2 * 2]), [2], + [_$0_(], [)])[_m4_popdef( + [_$0])]m4_dquote($m4_eval([($# + 1) & ~1]))[)])_$0($@)])]) + +m4_define([_m4_case_], +[$0_([1], [$1], m4_incr([$1]))]) + +m4_define([_m4_case__], +[[[$$1],[$$2],[$$3],]]) + +# m4_bmatch(SWITCH, RE1, VAL1, RE2, VAL2, ..., DEFAULT) +# ----------------------------------------------------- +# m4 equivalent of +# +# if (SWITCH =~ RE1) +# VAL1; +# elif (SWITCH =~ RE2) +# VAL2; +# elif ... +# ... +# else +# DEFAULT +# +# We build the temporary macro _m4_b: +# m4_define([_m4_b], _m4_defn([_m4_bmatch]))_m4_b([$1], [$2], [$3])... +# _m4_b([$1], [$m-1], [$m])_m4_b([], [], [$m+1]_m4_popdef([_m4_b])) +# then invoke m4_unquote(_m4_b($@)), for concatenation with later text. +m4_define([m4_bmatch], +[m4_if([$#], 0, [m4_fatal([$0: too few arguments: $#])], + [$#], 1, [m4_fatal([$0: too few arguments: $#: $1])], + [$#], 2, [$2], + [m4_pushdef([_m4_b], [m4_define([_m4_b], + _m4_defn([_$0]))]_m4_for([3], m4_eval([($# + 1) / 2 * 2 - 1]), + [2], [_$0_(], [)])[_m4_b([], [],]m4_dquote([$]m4_eval( + [($# + 1) / 2 * 2]))[_m4_popdef([_m4_b]))])m4_unquote(_m4_b($@))])]) + +m4_define([_m4_bmatch], +[m4_if(m4_bregexp([$1], [$2]), [-1], [], [[$3]m4_define([$0])])]) + +m4_define([_m4_bmatch_], +[$0_([1], m4_decr([$1]), [$1])]) + +m4_define([_m4_bmatch__], +[[_m4_b([$$1], [$$2], [$$3])]]) + + +# m4_cond(TEST1, VAL1, IF-VAL1, TEST2, VAL2, IF-VAL2, ..., [DEFAULT]) +# ------------------------------------------------------------------- +# Similar to m4_if, except that each TEST is expanded when encountered. +# If the expansion of TESTn matches the string VALn, the result is IF-VALn. +# The result is DEFAULT if no tests passed. This macro allows +# short-circuiting of expensive tests, where it pays to arrange quick +# filter tests to run first. +# +# m4_cond already guarantees either 3*n or 3*n + 1 arguments, 1 <= n. +# We only have to speed up _m4_cond, by building the temporary _m4_c: +# m4_define([_m4_c], _m4_defn([m4_unquote]))_m4_c([m4_if(($1), [($2)], +# [[$3]m4_define([_m4_c])])])_m4_c([m4_if(($4), [($5)], +# [[$6]m4_define([_m4_c])])])..._m4_c([m4_if(($m-2), [($m-1)], +# [[$m]m4_define([_m4_c])])])_m4_c([[$m+1]]_m4_popdef([_m4_c])) +# We invoke m4_unquote(_m4_c($@)), for concatenation with later text. +m4_define([_m4_cond], +[m4_pushdef([_m4_c], [m4_define([_m4_c], + _m4_defn([m4_unquote]))]_m4_for([2], m4_eval([$# / 3 * 3 - 1]), [3], + [$0_(], [)])[_m4_c(]m4_dquote(m4_dquote( + [$]m4_eval([$# / 3 * 3 + 1])))[_m4_popdef([_m4_c]))])m4_unquote(_m4_c($@))]) + +m4_define([_m4_cond_], +[$0_(m4_decr([$1]), [$1], m4_incr([$1]))]) + +m4_define([_m4_cond__], +[[_m4_c([m4_if(($$1), [($$2)], [[$$3]m4_define([_m4_c])])])]]) + +# m4_bpatsubsts(STRING, RE1, SUBST1, RE2, SUBST2, ...) +# ---------------------------------------------------- +# m4 equivalent of +# +# $_ = STRING; +# s/RE1/SUBST1/g; +# s/RE2/SUBST2/g; +# ... +# +# m4_bpatsubsts already validated an odd number of arguments; we only +# need to speed up _m4_bpatsubsts. To avoid nesting, we build the +# temporary _m4_p: +# m4_define([_m4_p], [$1])m4_define([_m4_p], +# m4_bpatsubst(m4_dquote(_m4_defn([_m4_p])), [$2], [$3]))m4_define([_m4_p], +# m4_bpatsubst(m4_dquote(_m4_defn([_m4_p])), [$4], [$5]))m4_define([_m4_p],... +# m4_bpatsubst(m4_dquote(_m4_defn([_m4_p])), [$m-1], [$m]))m4_unquote( +# _m4_defn([_m4_p])_m4_popdef([_m4_p])) +m4_define([_m4_bpatsubsts], +[m4_pushdef([_m4_p], [m4_define([_m4_p], + ]m4_dquote([$]1)[)]_m4_for([3], [$#], [2], [$0_(], + [)])[m4_unquote(_m4_defn([_m4_p])_m4_popdef([_m4_p]))])_m4_p($@)]) + +m4_define([_m4_bpatsubsts_], +[$0_(m4_decr([$1]), [$1])]) + +m4_define([_m4_bpatsubsts__], +[[m4_define([_m4_p], +m4_bpatsubst(m4_dquote(_m4_defn([_m4_p])), [$$1], [$$2]))]]) + +# m4_shiftn(N, ...) +# ----------------- +# Returns ... shifted N times. Useful for recursive "varargs" constructs. +# +# m4_shiftn already validated arguments; we only need to speed up +# _m4_shiftn. If N is 3, then we build the temporary _m4_s, defined as +# ,[$5],[$6],...,[$m]_m4_popdef([_m4_s]) +# before calling m4_shift(_m4_s($@)). +m4_define([_m4_shiftn], +[m4_if(m4_incr([$1]), [$#], [], [m4_pushdef([_m4_s], + _m4_for(m4_eval([$1 + 2]), [$#], [1], + [[,]m4_dquote($], [)])[_m4_popdef([_m4_s])])m4_shift(_m4_s($@))])]) + +# m4_do(STRING, ...) +# ------------------ +# This macro invokes all its arguments (in sequence, of course). It is +# useful for making your macros more structured and readable by dropping +# unnecessary dnl's and have the macros indented properly. +# +# Here, we use the temporary macro _m4_do, defined as +# $1[]$2[]...[]$n[]_m4_popdef([_m4_do]) +m4_define([m4_do], +[m4_if([$#], [0], [], + [m4_pushdef([_$0], _m4_for([1], [$#], [1], + [$], [[[]]])[_m4_popdef([_$0])])_$0($@)])]) + +# m4_dquote_elt(ARGS) +# ------------------- +# Return ARGS as an unquoted list of double-quoted arguments. +# +# _m4_foreach to the rescue. +m4_define([m4_dquote_elt], +[m4_if([$#], [0], [], [[[$1]]_m4_foreach([,m4_dquote(], [)], $@)])]) + +# m4_reverse(ARGS) +# ---------------- +# Output ARGS in reverse order. +# +# Invoke _m4_r($@) with the temporary _m4_r built as +# [$m], [$m-1], ..., [$2], [$1]_m4_popdef([_m4_r]) +m4_define([m4_reverse], +[m4_if([$#], [0], [], [$#], [1], [[$1]], +[m4_pushdef([_m4_r], [[$$#]]_m4_for(m4_decr([$#]), [1], [-1], + [[, ]m4_dquote($], [)])[_m4_popdef([_m4_r])])_m4_r($@)])]) + + +# m4_map_args_pair(EXPRESSION, [END-EXPR = EXPRESSION], ARG...) +# ------------------------------------------------------------- +# Perform a pairwise grouping of consecutive ARGs, by expanding +# EXPRESSION([ARG1], [ARG2]). If there are an odd number of ARGs, the +# final argument is expanded with END-EXPR([ARGn]). +# +# Build the temporary macro _m4_map_args_pair, with the $2([$m+1]) +# only output if $# is odd: +# $1([$3], [$4])[]$1([$5], [$6])[]...$1([$m-1], +# [$m])[]m4_default([$2], [$1])([$m+1])[]_m4_popdef([_m4_map_args_pair]) +m4_define([m4_map_args_pair], +[m4_if([$#], [0], [m4_fatal([$0: too few arguments: $#])], + [$#], [1], [m4_fatal([$0: too few arguments: $#: $1])], + [$#], [2], [], + [$#], [3], [m4_default([$2], [$1])([$3])[]], + [m4_pushdef([_$0], _m4_for([3], + m4_eval([$# / 2 * 2 - 1]), [2], [_$0_(], [)])_$0_end( + [1], [2], [$#])[_m4_popdef([_$0])])_$0($@)])]) + +m4_define([_m4_map_args_pair_], +[$0_([1], [$1], m4_incr([$1]))]) + +m4_define([_m4_map_args_pair__], +[[$$1([$$2], [$$3])[]]]) + +m4_define([_m4_map_args_pair_end], +[m4_if(m4_eval([$3 & 1]), [1], [[m4_default([$$2], [$$1])([$$3])[]]])]) + +# m4_join(SEP, ARG1, ARG2...) +# --------------------------- +# Produce ARG1SEPARG2...SEPARGn. Avoid back-to-back SEP when a given ARG +# is the empty string. No expansion is performed on SEP or ARGs. +# +# Use a self-modifying separator, since we don't know how many +# arguments might be skipped before a separator is first printed, but +# be careful if the separator contains $. _m4_foreach to the rescue. +m4_define([m4_join], +[m4_pushdef([_m4_sep], [m4_define([_m4_sep], _m4_defn([m4_echo]))])]dnl +[_m4_foreach([_$0([$1],], [)], $@)_m4_popdef([_m4_sep])]) + +m4_define([_m4_join], +[m4_if([$2], [], [], [_m4_sep([$1])[$2]])]) + +# m4_joinall(SEP, ARG1, ARG2...) +# ------------------------------ +# Produce ARG1SEPARG2...SEPARGn. An empty ARG results in back-to-back SEP. +# No expansion is performed on SEP or ARGs. +# +# A bit easier than m4_join. _m4_foreach to the rescue. +m4_define([m4_joinall], +[[$2]m4_if(m4_eval([$# <= 2]), [1], [], + [_m4_foreach([$1], [], m4_shift($@))])]) + +# m4_list_cmp(A, B) +# ----------------- +# Compare the two lists of integer expressions A and B. +# +# m4_list_cmp takes care of any side effects; we only override +# _m4_list_cmp_raw, where we can safely expand lists multiple times. +# First, insert padding so that both lists are the same length; the +# trailing +0 is necessary to handle a missing list. Next, create a +# temporary macro to perform pairwise comparisons until an inequality +# is found. For example, m4_list_cmp([1], [1,2]) creates _m4_cmp as +# m4_if(m4_eval([($1) != ($3)]), [1], [m4_cmp([$1], [$3])], +# m4_eval([($2) != ($4)]), [1], [m4_cmp([$2], [$4])], +# [0]_m4_popdef([_m4_cmp])) +# then calls _m4_cmp([1+0], [0*2], [1], [2+0]) +m4_define([_m4_list_cmp_raw], +[m4_if([$1], [$2], 0, + [_m4_list_cmp($1+0_m4_list_pad(m4_count($1), m4_count($2)), + $2+0_m4_list_pad(m4_count($2), m4_count($1)))])]) + +m4_define([_m4_list_pad], +[m4_if(m4_eval($1 < $2), [1], + [_m4_for(m4_incr([$1]), [$2], [1], [,0*])])]) + +m4_define([_m4_list_cmp], +[m4_pushdef([_m4_cmp], [m4_if(]_m4_for( + [1], m4_eval([$# >> 1]), [1], [$0_(], [,]m4_eval([$# >> 1])[)])[ + [0]_m4_popdef([_m4_cmp]))])_m4_cmp($@)]) + +m4_define([_m4_list_cmp_], +[$0_([$1], m4_eval([$1 + $2]))]) + +m4_define([_m4_list_cmp__], +[[m4_eval([($$1) != ($$2)]), [1], [m4_cmp([$$1], [$$2])], +]]) + +# m4_max(EXPR, ...) +# m4_min(EXPR, ...) +# ----------------- +# Return the decimal value of the maximum (or minimum) in a series of +# integer expressions. +# +# _m4_foreach to the rescue; we only need to replace _m4_minmax. Here, +# we need a temporary macro to track the best answer so far, so that +# the foreach expression is tractable. +m4_define([_m4_minmax], +[m4_pushdef([_m4_best], m4_eval([$2]))_m4_foreach( + [m4_define([_m4_best], $1(_m4_best,], [))], m4_shift($@))]dnl +[_m4_best[]_m4_popdef([_m4_best])]) + +# m4_set_add_all(SET, VALUE...) +# ----------------------------- +# Add each VALUE into SET. This is O(n) in the number of VALUEs, and +# can be faster than calling m4_set_add for each VALUE. +# +# _m4_foreach to the rescue. If no deletions have occurred, then +# avoid the speed penalty of m4_set_add. +m4_define([m4_set_add_all], +[m4_if([$#], [0], [], [$#], [1], [], + [m4_define([_m4_set_size($1)], m4_eval(m4_set_size([$1]) + + m4_len(_m4_foreach(m4_ifdef([_m4_set_cleanup($1)], + [[m4_set_add]], [[_$0]])[([$1],], [)], $@))))])]) + +m4_define([_m4_set_add_all], +[m4_ifdef([_m4_set([$1],$2)], [], + [m4_define([_m4_set([$1],$2)], + [1])m4_pushdef([_m4_set([$1])], [$2])-])]) diff --git a/Engine/bin/bison-flex/data/m4sugar/m4sugar.m4 b/Engine/bin/bison-flex/data/m4sugar/m4sugar.m4 new file mode 100644 index 000000000..b42fc1a6d --- /dev/null +++ b/Engine/bin/bison-flex/data/m4sugar/m4sugar.m4 @@ -0,0 +1,3329 @@ +divert(-1)# -*- Autoconf -*- +# This file is part of Autoconf. +# Base M4 layer. +# Requires GNU M4. +# +# Copyright (C) 1999-2017, 2020 Free Software Foundation, Inc. + +# This file is part of Autoconf. 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 the +# Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# Under Section 7 of GPL version 3, you are granted additional +# permissions described in the Autoconf Configure Script Exception, +# version 3.0, as published by the Free Software Foundation. +# +# You should have received a copy of the GNU General Public License +# and a copy of the Autoconf Configure Script Exception along with +# this program; see the files COPYINGv3 and COPYING.EXCEPTION +# respectively. If not, see . + +# Written by Akim Demaille. + +# Set the quotes, whatever the current quoting system. +changequote() +changequote([, ]) + +# Some old m4's don't support m4exit. But they provide +# equivalent functionality by core dumping because of the +# long macros we define. +ifdef([__gnu__], , +[errprint(M4sugar requires GNU M4. Install it before installing M4sugar or +set the M4 environment variable to its absolute file name.) +m4exit(2)]) + + +## ------------------------------- ## +## 1. Simulate --prefix-builtins. ## +## ------------------------------- ## + +# m4_define +# m4_defn +# m4_undefine +define([m4_define], defn([define])) +define([m4_defn], defn([defn])) +define([m4_undefine], defn([undefine])) + +m4_undefine([define]) +m4_undefine([defn]) +m4_undefine([undefine]) + + +# m4_copy(SRC, DST) +# ----------------- +# Define DST as the definition of SRC. +# What's the difference between: +# 1. m4_copy([from], [to]) +# 2. m4_define([to], [from($@)]) +# Well, obviously 1 is more expensive in space. Maybe 2 is more expensive +# in time, but because of the space cost of 1, it's not that obvious. +# Nevertheless, one huge difference is the handling of `$0'. If `from' +# uses `$0', then with 1, `to''s `$0' is `to', while it is `from' in 2. +# The user would certainly prefer to see `to'. +# +# This definition is in effect during m4sugar initialization, when +# there are no pushdef stacks; later on, we redefine it to something +# more powerful for all other clients to use. +m4_define([m4_copy], +[m4_define([$2], m4_defn([$1]))]) + + +# m4_rename(SRC, DST) +# ------------------- +# Rename the macro SRC to DST. +m4_define([m4_rename], +[m4_copy([$1], [$2])m4_undefine([$1])]) + + +# m4_rename_m4(MACRO-NAME) +# ------------------------ +# Rename MACRO-NAME to m4_MACRO-NAME. +m4_define([m4_rename_m4], +[m4_rename([$1], [m4_$1])]) + + +# m4_copy_unm4(m4_MACRO-NAME) +# --------------------------- +# Copy m4_MACRO-NAME to MACRO-NAME. +m4_define([m4_copy_unm4], +[m4_copy([$1], m4_bpatsubst([$1], [^m4_\(.*\)], [[\1]]))]) + + +# Some m4 internals have names colliding with tokens we might use. +# Rename them a` la `m4 --prefix-builtins'. Conditionals first, since +# some subsequent renames are conditional. +m4_rename_m4([ifdef]) +m4_rename([ifelse], [m4_if]) + +m4_rename_m4([builtin]) +m4_rename_m4([changecom]) +m4_rename_m4([changequote]) +m4_ifdef([changeword],dnl conditionally available in 1.4.x +[m4_undefine([changeword])]) +m4_rename_m4([debugfile]) +m4_rename_m4([debugmode]) +m4_rename_m4([decr]) +m4_rename_m4([divnum]) +m4_rename_m4([dumpdef]) +m4_rename_m4([errprint]) +m4_rename_m4([esyscmd]) +m4_rename_m4([eval]) +m4_rename_m4([format]) +m4_undefine([include]) +m4_rename_m4([incr]) +m4_rename_m4([index]) +m4_rename_m4([indir]) +m4_rename_m4([len]) +m4_rename([m4exit], [m4_exit]) +m4_undefine([m4wrap]) +m4_ifdef([mkstemp],dnl added in M4 1.4.8 +[m4_rename_m4([mkstemp]) +m4_copy([m4_mkstemp], [m4_maketemp]) +m4_undefine([maketemp])], +[m4_rename_m4([maketemp]) +m4_copy([m4_maketemp], [m4_mkstemp])]) +m4_rename([patsubst], [m4_bpatsubst]) +m4_rename_m4([popdef]) +m4_rename_m4([pushdef]) +m4_rename([regexp], [m4_bregexp]) +m4_rename_m4([shift]) +m4_undefine([sinclude]) +m4_rename_m4([substr]) +m4_ifdef([symbols],dnl present only in alpha-quality 1.4o +[m4_rename_m4([symbols])]) +m4_rename_m4([syscmd]) +m4_rename_m4([sysval]) +m4_rename_m4([traceoff]) +m4_rename_m4([traceon]) +m4_rename_m4([translit]) + +# _m4_defn(ARG) +# ------------- +# _m4_defn is for internal use only - it bypasses the wrapper, so it +# must only be used on one argument at a time, and only on macros +# known to be defined. Make sure this still works if the user renames +# m4_defn but not _m4_defn. +m4_copy([m4_defn], [_m4_defn]) + +# _m4_divert_raw(NUM) +# ------------------- +# _m4_divert_raw is for internal use only. Use this instead of +# m4_builtin([divert], NUM), so that tracing diversion flow is easier. +m4_rename([divert], [_m4_divert_raw]) + +# _m4_popdef(ARG...) +# ------------------ +# _m4_popdef is for internal use only - it bypasses the wrapper, so it +# must only be used on macros known to be defined. Make sure this +# still works if the user renames m4_popdef but not _m4_popdef. +m4_copy([m4_popdef], [_m4_popdef]) + +# _m4_undefine(ARG...) +# -------------------- +# _m4_undefine is for internal use only - it bypasses the wrapper, so +# it must only be used on macros known to be defined. Make sure this +# still works if the user renames m4_undefine but not _m4_undefine. +m4_copy([m4_undefine], [_m4_undefine]) + +# _m4_undivert(NUM...) +# -------------------- +# _m4_undivert is for internal use only, and should always be given +# arguments. Use this instead of m4_builtin([undivert], NUM...), so +# that tracing diversion flow is easier. +m4_rename([undivert], [_m4_undivert]) + + +## ------------------- ## +## 2. Error messages. ## +## ------------------- ## + + +# m4_location +# ----------- +# Output the current file, colon, and the current line number. +m4_define([m4_location], +[__file__:__line__]) + + +# m4_errprintn(MSG) +# ----------------- +# Same as `errprint', but with the missing end of line. +m4_define([m4_errprintn], +[m4_errprint([$1 +])]) + + +# m4_warning(MSG) +# --------------- +# Warn the user. +m4_define([m4_warning], +[m4_errprintn(m4_location[: warning: $1])]) + + +# m4_fatal(MSG, [EXIT-STATUS]) +# ---------------------------- +# Fatal the user. :) +m4_define([m4_fatal], +[m4_errprintn(m4_location[: error: $1] +m4_expansion_stack)m4_exit(m4_if([$2],, 1, [$2]))]) + + +# m4_assert(EXPRESSION, [EXIT-STATUS = 1]) +# ---------------------------------------- +# This macro ensures that EXPRESSION evaluates to true, and exits if +# EXPRESSION evaluates to false. +m4_define([m4_assert], +[m4_if(m4_eval([$1]), 0, + [m4_fatal([assert failed: $1], [$2])])]) + + + +## ------------- ## +## 3. Warnings. ## +## ------------- ## + + +# _m4_warn(CATEGORY, MESSAGE, [STACK-TRACE]) +# ------------------------------------------ +# Report a MESSAGE to the user if the CATEGORY of warnings is enabled. +# This is for traces only. +# If present, STACK-TRACE is a \n-separated list of "LOCATION: MESSAGE", +# where the last line (and no other) ends with "the top level". +# +# Within m4, the macro is a no-op. This macro really matters +# when autom4te post-processes the trace output. +m4_define([_m4_warn], []) + + +# m4_warn(CATEGORY, MESSAGE) +# -------------------------- +# Report a MESSAGE to the user if the CATEGORY of warnings is enabled. +m4_define([m4_warn], +[_m4_warn([$1], [$2], +m4_ifdef([_m4_expansion_stack], [m4_expansion_stack]))]) + + + +## ------------------- ## +## 4. File inclusion. ## +## ------------------- ## + + +# We also want to neutralize include (and sinclude for symmetry), +# but we want to extend them slightly: warn when a file is included +# several times. This is, in general, a dangerous operation, because +# too many people forget to quote the first argument of m4_define. +# +# For instance in the following case: +# m4_define(foo, [bar]) +# then a second reading will turn into +# m4_define(bar, [bar]) +# which is certainly not what was meant. + +# m4_include_unique(FILE) +# ----------------------- +# Declare that the FILE was loading; and warn if it has already +# been included. +m4_define([m4_include_unique], +[m4_ifdef([m4_include($1)], + [m4_warn([syntax], [file `$1' included several times])])dnl +m4_define([m4_include($1)])]) + + +# m4_include(FILE) +# ---------------- +# Like the builtin include, but warns against multiple inclusions. +m4_define([m4_include], +[m4_include_unique([$1])dnl +m4_builtin([include], [$1])]) + + +# m4_sinclude(FILE) +# ----------------- +# Like the builtin sinclude, but warns against multiple inclusions. +m4_define([m4_sinclude], +[m4_include_unique([$1])dnl +m4_builtin([sinclude], [$1])]) + + + +## ------------------------------------ ## +## 5. Additional branching constructs. ## +## ------------------------------------ ## + +# Both `m4_ifval' and `m4_ifset' tests against the empty string. The +# difference is that `m4_ifset' is specialized on macros. +# +# In case of arguments of macros, eg. $1, it makes little difference. +# In the case of a macro `FOO', you don't want to check `m4_ifval(FOO, +# TRUE)', because if `FOO' expands with commas, there is a shifting of +# the arguments. So you want to run `m4_ifval([FOO])', but then you just +# compare the *string* `FOO' against `', which, of course fails. +# +# So you want the variation `m4_ifset' that expects a macro name as $1. +# If this macro is both defined and defined to a non empty value, then +# it runs TRUE, etc. + + +# m4_ifblank(COND, [IF-BLANK], [IF-TEXT]) +# m4_ifnblank(COND, [IF-TEXT], [IF-BLANK]) +# ---------------------------------------- +# If COND is empty, or consists only of blanks (space, tab, newline), +# then expand IF-BLANK, otherwise expand IF-TEXT. This differs from +# m4_ifval only if COND has just whitespace, but it helps optimize in +# spite of users who mistakenly leave trailing space after what they +# thought was an empty argument: +# macro( +# [] +# ) +# +# Writing one macro in terms of the other causes extra overhead, so +# we inline both definitions. +m4_define([m4_ifblank], +[m4_if(m4_translit([[$1]], [ ][ ][ +]), [], [$2], [$3])]) + +m4_define([m4_ifnblank], +[m4_if(m4_translit([[$1]], [ ][ ][ +]), [], [$3], [$2])]) + + +# m4_ifval(COND, [IF-TRUE], [IF-FALSE]) +# ------------------------------------- +# If COND is not the empty string, expand IF-TRUE, otherwise IF-FALSE. +# Comparable to m4_ifdef. +m4_define([m4_ifval], +[m4_if([$1], [], [$3], [$2])]) + + +# m4_n(TEXT) +# ---------- +# If TEXT is not empty, return TEXT and a new line, otherwise nothing. +m4_define([m4_n], +[m4_if([$1], + [], [], + [$1 +])]) + + +# m4_ifvaln(COND, [IF-TRUE], [IF-FALSE]) +# -------------------------------------- +# Same as `m4_ifval', but add an extra newline to IF-TRUE or IF-FALSE +# unless that argument is empty. +m4_define([m4_ifvaln], +[m4_if([$1], + [], [m4_n([$3])], + [m4_n([$2])])]) + + +# m4_ifset(MACRO, [IF-TRUE], [IF-FALSE]) +# -------------------------------------- +# If MACRO has no definition, or of its definition is the empty string, +# expand IF-FALSE, otherwise IF-TRUE. +m4_define([m4_ifset], +[m4_ifdef([$1], + [m4_ifval(_m4_defn([$1]), [$2], [$3])], + [$3])]) + + +# m4_ifndef(NAME, [IF-NOT-DEFINED], [IF-DEFINED]) +# ----------------------------------------------- +m4_define([m4_ifndef], +[m4_ifdef([$1], [$3], [$2])]) + + +# m4_case(SWITCH, VAL1, IF-VAL1, VAL2, IF-VAL2, ..., DEFAULT) +# ----------------------------------------------------------- +# m4 equivalent of +# switch (SWITCH) +# { +# case VAL1: +# IF-VAL1; +# break; +# case VAL2: +# IF-VAL2; +# break; +# ... +# default: +# DEFAULT; +# break; +# }. +# All the values are optional, and the macro is robust to active +# symbols properly quoted. +# +# Please keep foreach.m4 in sync with any adjustments made here. +m4_define([m4_case], +[m4_if([$#], 0, [], + [$#], 1, [], + [$#], 2, [$2], + [$1], [$2], [$3], + [$0([$1], m4_shift3($@))])]) + + +# m4_bmatch(SWITCH, RE1, VAL1, RE2, VAL2, ..., DEFAULT) +# ----------------------------------------------------- +# m4 equivalent of +# +# if (SWITCH =~ RE1) +# VAL1; +# elif (SWITCH =~ RE2) +# VAL2; +# elif ... +# ... +# else +# DEFAULT +# +# All the values are optional, and the macro is robust to active symbols +# properly quoted. +# +# Please keep foreach.m4 in sync with any adjustments made here. +m4_define([m4_bmatch], +[m4_if([$#], 0, [m4_fatal([$0: too few arguments: $#])], + [$#], 1, [m4_fatal([$0: too few arguments: $#: $1])], + [$#], 2, [$2], + [m4_if(m4_bregexp([$1], [$2]), -1, [$0([$1], m4_shift3($@))], + [$3])])]) + +# m4_argn(N, ARGS...) +# ------------------- +# Extract argument N (greater than 0) from ARGS. Example: +# m4_define([b], [B]) +# m4_argn([2], [a], [b], [c]) => b +# +# Rather than using m4_car(m4_shiftn([$1], $@)), we exploit the fact that +# GNU m4 can directly reference any argument, through an indirect macro. +m4_define([m4_argn], +[m4_assert([0 < $1])]dnl +[m4_pushdef([_$0], [_m4_popdef([_$0])]m4_dquote([$]m4_incr([$1])))_$0($@)]) + + +# m4_car(ARGS...) +# m4_cdr(ARGS...) +# --------------- +# Manipulate m4 lists. m4_car returns the first argument. m4_cdr +# bundles all but the first argument into a quoted list. These two +# macros are generally used with list arguments, with quoting removed +# to break the list into multiple m4 ARGS. +m4_define([m4_car], [[$1]]) +m4_define([m4_cdr], +[m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])], + [$#], 1, [], + [m4_dquote(m4_shift($@))])]) + +# _m4_cdr(ARGS...) +# ---------------- +# Like m4_cdr, except include a leading comma unless only one argument +# remains. Why? Because comparing a large list against [] is more +# expensive in expansion time than comparing the number of arguments; so +# _m4_cdr can be used to reduce the number of arguments when it is time +# to end recursion. +m4_define([_m4_cdr], +[m4_if([$#], 1, [], + [, m4_dquote(m4_shift($@))])]) + + + +# m4_cond(TEST1, VAL1, IF-VAL1, TEST2, VAL2, IF-VAL2, ..., [DEFAULT]) +# ------------------------------------------------------------------- +# Similar to m4_if, except that each TEST is expanded when encountered. +# If the expansion of TESTn matches the string VALn, the result is IF-VALn. +# The result is DEFAULT if no tests passed. This macro allows +# short-circuiting of expensive tests, where it pays to arrange quick +# filter tests to run first. +# +# For an example, consider a previous implementation of _AS_QUOTE_IFELSE: +# +# m4_if(m4_index([$1], [\]), [-1], [$2], +# m4_eval(m4_index([$1], [\\]) >= 0), [1], [$2], +# m4_eval(m4_index([$1], [\$]) >= 0), [1], [$2], +# m4_eval(m4_index([$1], [\`]) >= 0), [1], [$3], +# m4_eval(m4_index([$1], [\"]) >= 0), [1], [$3], +# [$2]) +# +# Here, m4_index is computed 5 times, and m4_eval 4, even if $1 contains +# no backslash. It is more efficient to do: +# +# m4_cond([m4_index([$1], [\])], [-1], [$2], +# [m4_eval(m4_index([$1], [\\]) >= 0)], [1], [$2], +# [m4_eval(m4_index([$1], [\$]) >= 0)], [1], [$2], +# [m4_eval(m4_index([$1], [\`]) >= 0)], [1], [$3], +# [m4_eval(m4_index([$1], [\"]) >= 0)], [1], [$3], +# [$2]) +# +# In the common case of $1 with no backslash, only one m4_index expansion +# occurs, and m4_eval is avoided altogether. +# +# Please keep foreach.m4 in sync with any adjustments made here. +m4_define([m4_cond], +[m4_if([$#], [0], [m4_fatal([$0: cannot be called without arguments])], + [$#], [1], [$1], + m4_eval([$# % 3]), [2], [m4_fatal([$0: missing an argument])], + [_$0($@)])]) + +m4_define([_m4_cond], +[m4_if(($1), [($2)], [$3], + [$#], [3], [], + [$#], [4], [$4], + [$0(m4_shift3($@))])]) + + +## ---------------------------------------- ## +## 6. Enhanced version of some primitives. ## +## ---------------------------------------- ## + +# m4_bpatsubsts(STRING, RE1, SUBST1, RE2, SUBST2, ...) +# ---------------------------------------------------- +# m4 equivalent of +# +# $_ = STRING; +# s/RE1/SUBST1/g; +# s/RE2/SUBST2/g; +# ... +# +# All the values are optional, and the macro is robust to active symbols +# properly quoted. +# +# I would have liked to name this macro `m4_bpatsubst', unfortunately, +# due to quotation problems, I need to double quote $1 below, therefore +# the anchors are broken :( I can't let users be trapped by that. +# +# Recall that m4_shift3 always results in an argument. Hence, we need +# to distinguish between a final deletion vs. ending recursion. +# +# Please keep foreach.m4 in sync with any adjustments made here. +m4_define([m4_bpatsubsts], +[m4_if([$#], 0, [m4_fatal([$0: too few arguments: $#])], + [$#], 1, [m4_fatal([$0: too few arguments: $#: $1])], + [$#], 2, [m4_unquote(m4_builtin([patsubst], [[$1]], [$2]))], + [$#], 3, [m4_unquote(m4_builtin([patsubst], [[$1]], [$2], [$3]))], + [_$0($@m4_if(m4_eval($# & 1), 0, [,]))])]) +m4_define([_m4_bpatsubsts], +[m4_if([$#], 2, [$1], + [$0(m4_builtin([patsubst], [[$1]], [$2], [$3]), + m4_shift3($@))])]) + + +# m4_copy(SRC, DST) +# ----------------- +# Define the pushdef stack DST as a copy of the pushdef stack SRC; +# give an error if DST is already defined. This is particularly nice +# for copying self-modifying pushdef stacks, where the top definition +# includes one-shot initialization that is later popped to the normal +# definition. This version intentionally does nothing if SRC is +# undefined. +# +# Some macros simply can't be renamed with this method: namely, anything +# involved in the implementation of m4_stack_foreach_sep. +m4_define([m4_copy], +[m4_ifdef([$2], [m4_fatal([$0: won't overwrite defined macro: $2])], + [m4_stack_foreach_sep([$1], [m4_pushdef([$2],], [)])])]dnl +[m4_ifdef([m4_location($1)], [m4_define([m4_location($2)], m4_location)])]) + + +# m4_copy_force(SRC, DST) +# m4_rename_force(SRC, DST) +# ------------------------- +# Like m4_copy/m4_rename, except blindly overwrite any existing DST. +# Note that m4_copy_force tolerates undefined SRC, while m4_rename_force +# does not. +m4_define([m4_copy_force], +[m4_ifdef([$2], [_m4_undefine([$2])])m4_copy($@)]) + +m4_define([m4_rename_force], +[m4_ifdef([$2], [_m4_undefine([$2])])m4_rename($@)]) + + +# m4_define_default(MACRO, VALUE) +# ------------------------------- +# If MACRO is undefined, set it to VALUE. +m4_define([m4_define_default], +[m4_ifndef([$1], [m4_define($@)])]) + + +# m4_default(EXP1, EXP2) +# m4_default_nblank(EXP1, EXP2) +# ----------------------------- +# Returns EXP1 if not empty/blank, otherwise EXP2. Expand the result. +# +# m4_default is called on hot paths, so inline the contents of m4_ifval, +# for one less round of expansion. +m4_define([m4_default], +[m4_if([$1], [], [$2], [$1])]) + +m4_define([m4_default_nblank], +[m4_ifblank([$1], [$2], [$1])]) + + +# m4_default_quoted(EXP1, EXP2) +# m4_default_nblank_quoted(EXP1, EXP2) +# ------------------------------------ +# Returns EXP1 if non empty/blank, otherwise EXP2. Leave the result quoted. +# +# For comparison: +# m4_define([active], [ACTIVE]) +# m4_default([active], [default]) => ACTIVE +# m4_default([], [active]) => ACTIVE +# -m4_default([ ], [active])- => - - +# -m4_default_nblank([ ], [active])- => -ACTIVE- +# m4_default_quoted([active], [default]) => active +# m4_default_quoted([], [active]) => active +# -m4_default_quoted([ ], [active])- => - - +# -m4_default_nblank_quoted([ ], [active])- => -active- +# +# m4_default macro is called on hot paths, so inline the contents of m4_ifval, +# for one less round of expansion. +m4_define([m4_default_quoted], +[m4_if([$1], [], [[$2]], [[$1]])]) + +m4_define([m4_default_nblank_quoted], +[m4_ifblank([$1], [[$2]], [[$1]])]) + + +# m4_defn(NAME) +# ------------- +# Like the original, except guarantee a warning when using something which is +# undefined (unlike M4 1.4.x). This replacement is not a full-featured +# replacement: if any of the defined macros contain unbalanced quoting, but +# when pasted together result in a well-quoted string, then only native m4 +# support is able to get it correct. But that's where quadrigraphs come in +# handy, if you really need unbalanced quotes inside your macros. +# +# This macro is called frequently, so minimize the amount of additional +# expansions by skipping m4_ifndef. Better yet, if __m4_version__ exists, +# (added in M4 1.6), then let m4 do the job for us (see m4_init). +m4_define([m4_defn], +[m4_if([$#], [0], [[$0]], + [$#], [1], [m4_ifdef([$1], [_m4_defn([$1])], + [m4_fatal([$0: undefined macro: $1])])], + [m4_map_args([$0], $@)])]) + + +# m4_dumpdef(NAME...) +# ------------------- +# In m4 1.4.x, dumpdef writes to the current debugfile, rather than +# stderr. This in turn royally confuses autom4te; so we follow the +# lead of newer m4 and always dump to stderr. Unlike the original, +# this version requires an argument, since there is no convenient way +# in m4 1.4.x to grab the names of all defined macros. Newer m4 +# always dumps to stderr, regardless of the current debugfile; it also +# provides m4symbols as a way to grab all current macro names. But +# dumpdefs is not frequently called, so we don't need to worry about +# conditionally using these newer features. Also, this version +# doesn't sort multiple arguments. +# +# If we detect m4 1.6 or newer, then provide an alternate definition, +# installed during m4_init, that allows builtins through. +# Unfortunately, there is no nice way in m4 1.4.x to dump builtins. +m4_define([m4_dumpdef], +[m4_if([$#], [0], [m4_fatal([$0: missing argument])], + [$#], [1], [m4_ifdef([$1], [m4_errprintn( + [$1: ]m4_dquote(_m4_defn([$1])))], [m4_fatal([$0: undefined macro: $1])])], + [m4_map_args([$0], $@)])]) + +m4_define([_m4_dumpdef], +[m4_if([$#], [0], [m4_fatal([$0: missing argument])], + [$#], [1], [m4_builtin([dumpdef], [$1])], + [m4_map_args_sep([m4_builtin([dumpdef],], [)], [], $@)])]) + + +# m4_dumpdefs(NAME...) +# -------------------- +# Similar to `m4_dumpdef(NAME)', but if NAME was m4_pushdef'ed, display its +# value stack (most recent displayed first). Also, this version silently +# ignores undefined macros, rather than erroring out. +# +# This macro cheats, because it relies on the current definition of NAME +# while the second argument of m4_stack_foreach_lifo is evaluated (which +# would be undefined according to the API). +m4_define([m4_dumpdefs], +[m4_if([$#], [0], [m4_fatal([$0: missing argument])], + [$#], [1], [m4_stack_foreach_lifo([$1], [m4_dumpdef([$1])m4_ignore])], + [m4_map_args([$0], $@)])]) + +# m4_esyscmd_s(COMMAND) +# --------------------- +# Like m4_esyscmd, except strip any trailing newlines, thus behaving +# more like shell command substitution. +m4_define([m4_esyscmd_s], +[m4_chomp_all(m4_esyscmd([$1]))]) + + +# m4_popdef(NAME) +# --------------- +# Like the original, except guarantee a warning when using something which is +# undefined (unlike M4 1.4.x). +# +# This macro is called frequently, so minimize the amount of additional +# expansions by skipping m4_ifndef. Better yet, if __m4_version__ exists, +# (added in M4 1.6), then let m4 do the job for us (see m4_init). +m4_define([m4_popdef], +[m4_if([$#], [0], [[$0]], + [$#], [1], [m4_ifdef([$1], [_m4_popdef([$1])], + [m4_fatal([$0: undefined macro: $1])])], + [m4_map_args([$0], $@)])]) + + +# m4_shiftn(N, ...) +# ----------------- +# Returns ... shifted N times. Useful for recursive "varargs" constructs. +# +# Autoconf does not use this macro, because it is inherently slower than +# calling the common cases of m4_shift2 or m4_shift3 directly. But it +# might as well be fast for other clients, such as Libtool. One way to +# do this is to expand $@ only once in _m4_shiftn (otherwise, for long +# lists, the expansion of m4_if takes twice as much memory as what the +# list itself occupies, only to throw away the unused branch). The end +# result is strictly equivalent to +# m4_if([$1], 1, [m4_shift(,m4_shift(m4_shift($@)))], +# [_m4_shiftn(m4_decr([$1]), m4_shift(m4_shift($@)))]) +# but with the final `m4_shift(m4_shift($@)))' shared between the two +# paths. The first leg uses a no-op m4_shift(,$@) to balance out the (). +# +# Please keep foreach.m4 in sync with any adjustments made here. +m4_define([m4_shiftn], +[m4_assert(0 < $1 && $1 < $#)_$0($@)]) + +m4_define([_m4_shiftn], +[m4_if([$1], 1, [m4_shift(], + [$0(m4_decr([$1])]), m4_shift(m4_shift($@)))]) + +# m4_shift2(...) +# m4_shift3(...) +# -------------- +# Returns ... shifted twice, and three times. Faster than m4_shiftn. +m4_define([m4_shift2], [m4_shift(m4_shift($@))]) +m4_define([m4_shift3], [m4_shift(m4_shift(m4_shift($@)))]) + +# _m4_shift2(...) +# _m4_shift3(...) +# --------------- +# Like m4_shift2 or m4_shift3, except include a leading comma unless shifting +# consumes all arguments. Why? Because in recursion, it is nice to +# distinguish between 1 element left and 0 elements left, based on how many +# arguments this shift expands to. +m4_define([_m4_shift2], +[m4_if([$#], [2], [], + [, m4_shift(m4_shift($@))])]) +m4_define([_m4_shift3], +[m4_if([$#], [3], [], + [, m4_shift(m4_shift(m4_shift($@)))])]) + + +# m4_undefine(NAME) +# ----------------- +# Like the original, except guarantee a warning when using something which is +# undefined (unlike M4 1.4.x). +# +# This macro is called frequently, so minimize the amount of additional +# expansions by skipping m4_ifndef. Better yet, if __m4_version__ exists, +# (added in M4 1.6), then let m4 do the job for us (see m4_init). +m4_define([m4_undefine], +[m4_if([$#], [0], [[$0]], + [$#], [1], [m4_ifdef([$1], [_m4_undefine([$1])], + [m4_fatal([$0: undefined macro: $1])])], + [m4_map_args([$0], $@)])]) + +# _m4_wrap(PRE, POST) +# ------------------- +# Helper macro for m4_wrap and m4_wrap_lifo. Allows nested calls to +# m4_wrap within wrapped text. Use _m4_defn and _m4_popdef for speed. +m4_define([_m4_wrap], +[m4_ifdef([$0_text], + [m4_define([$0_text], [$1]_m4_defn([$0_text])[$2])], + [m4_builtin([m4wrap], [m4_unquote( + _m4_defn([$0_text])_m4_popdef([$0_text]))])m4_define([$0_text], [$1$2])])]) + +# m4_wrap(TEXT) +# ------------- +# Append TEXT to the list of hooks to be executed at the end of input. +# Whereas the order of the original may be LIFO in the underlying m4, +# this version is always FIFO. +m4_define([m4_wrap], +[_m4_wrap([], [$1[]])]) + +# m4_wrap_lifo(TEXT) +# ------------------ +# Prepend TEXT to the list of hooks to be executed at the end of input. +# Whereas the order of m4_wrap may be FIFO in the underlying m4, this +# version is always LIFO. +m4_define([m4_wrap_lifo], +[_m4_wrap([$1[]])]) + +## ------------------------- ## +## 7. Quoting manipulation. ## +## ------------------------- ## + + +# m4_apply(MACRO, LIST) +# --------------------- +# Invoke MACRO, with arguments provided from the quoted list of +# comma-separated quoted arguments. If LIST is empty, invoke MACRO +# without arguments. The expansion will not be concatenated with +# subsequent text. +m4_define([m4_apply], +[m4_if([$2], [], [$1], [$1($2)])[]]) + +# _m4_apply(MACRO, LIST) +# ---------------------- +# Like m4_apply, except do nothing if LIST is empty. +m4_define([_m4_apply], +[m4_if([$2], [], [], [$1($2)[]])]) + + +# m4_count(ARGS) +# -------------- +# Return a count of how many ARGS are present. +m4_define([m4_count], [$#]) + + +# m4_curry(MACRO, ARG...) +# ----------------------- +# Perform argument currying. The expansion of this macro is another +# macro that takes exactly one argument, appends it to the end of the +# original ARG list, then invokes MACRO. For example: +# m4_curry([m4_curry], [m4_reverse], [1])([2])([3]) => 3, 2, 1 +# Not quite as practical as m4_incr, but you could also do: +# m4_define([add], [m4_eval(([$1]) + ([$2]))]) +# m4_define([add_one], [m4_curry([add], [1])]) +# add_one()([2]) => 3 +m4_define([m4_curry], [$1(m4_shift($@,)_$0]) +m4_define([_m4_curry], [[$1])]) + + +# m4_do(STRING, ...) +# ------------------ +# This macro invokes all its arguments (in sequence, of course). It is +# useful for making your macros more structured and readable by dropping +# unnecessary dnl's and have the macros indented properly. No concatenation +# occurs after a STRING; use m4_unquote(m4_join(,STRING)) for that. +# +# Please keep foreach.m4 in sync with any adjustments made here. +m4_define([m4_do], +[m4_if([$#], 0, [], + [$#], 1, [$1[]], + [$1[]$0(m4_shift($@))])]) + + +# m4_dquote(ARGS) +# --------------- +# Return ARGS as a quoted list of quoted arguments. +m4_define([m4_dquote], [[$@]]) + + +# m4_dquote_elt(ARGS) +# ------------------- +# Return ARGS as an unquoted list of double-quoted arguments. +# +# Please keep foreach.m4 in sync with any adjustments made here. +m4_define([m4_dquote_elt], +[m4_if([$#], [0], [], + [$#], [1], [[[$1]]], + [[[$1]],$0(m4_shift($@))])]) + + +# m4_echo(ARGS) +# ------------- +# Return the ARGS, with the same level of quoting. Whitespace after +# unquoted commas are consumed. +m4_define([m4_echo], [$@]) + + +# m4_expand(ARG) +# _m4_expand(ARG) +# --------------- +# Return the expansion of ARG as a single string. Unlike +# m4_quote($1), this preserves whitespace following single-quoted +# commas that appear within ARG. It also deals with shell case +# statements. +# +# m4_define([active], [ACT, IVE]) +# m4_define([active2], [[ACT, IVE]]) +# m4_quote(active, active2) +# => ACT,IVE,ACT, IVE +# m4_expand([active, active2]) +# => ACT, IVE, ACT, IVE +# +# Unfortunately, due to limitations in m4, ARG must expand to +# something with balanced quotes (use quadrigraphs to get around +# this), and should not contain the unlikely delimiters -=<{( or +# )}>=-. It is possible to have unbalanced quoted `(' or `)', as well +# as unbalanced unquoted `)'. m4_expand can handle unterminated +# comments or dnl on the final line, at the expense of speed; it also +# aids in detecting attempts to incorrectly change the current +# diversion inside ARG. Meanwhile, _m4_expand is faster but must be +# given a terminated expansion, and has no safety checks for +# mis-diverted text. +# +# Exploit that extra unquoted () will group unquoted commas and the +# following whitespace. m4_bpatsubst can't handle newlines inside $1, +# and m4_substr strips quoting. So we (ab)use m4_changequote, using +# temporary quotes to remove the delimiters that conveniently included +# the unquoted () that were added prior to the changequote. +# +# Thanks to shell case statements, too many people are prone to pass +# underquoted `)', so we try to detect that by passing a marker as a +# fourth argument; if the marker is not present, then we assume that +# we encountered an early `)', and re-expand the first argument, but +# this time with one more `(' in the second argument and in the +# open-quote delimiter. We must also ignore the slop from the +# previous try. The final macro is thus half line-noise, half art. +m4_define([m4_expand], +[m4_pushdef([m4_divert], _m4_defn([_m4_divert_unsafe]))]dnl +[m4_pushdef([m4_divert_push], _m4_defn([_m4_divert_unsafe]))]dnl +[m4_chomp(_$0([$1 +]))_m4_popdef([m4_divert], [m4_divert_push])]) + +m4_define([_m4_expand], [$0_([$1], [(], -=<{($1)}>=-, [}>=-])]) + +m4_define([_m4_expand_], +[m4_if([$4], [}>=-], + [m4_changequote([-=<{$2], [)}>=-])$3m4_changequote([, ])], + [$0([$1], [($2], -=<{($2$1)}>=-, [}>=-])m4_ignore$2])]) + + +# m4_ignore(ARGS) +# --------------- +# Expands to nothing. Useful for conditionally ignoring an arbitrary +# number of arguments (see _m4_list_cmp for an example). +m4_define([m4_ignore]) + + +# m4_make_list(ARGS) +# ------------------ +# Similar to m4_dquote, this creates a quoted list of quoted ARGS. This +# version is less efficient than m4_dquote, but separates each argument +# with a comma and newline, rather than just comma, for readability. +# When developing an m4sugar algorithm, you could temporarily use +# m4_pushdef([m4_dquote],m4_defn([m4_make_list])) +# around your code to make debugging easier. +m4_define([m4_make_list], [m4_join([, +], m4_dquote_elt($@))]) + + +# m4_noquote(STRING) +# ------------------ +# Return the result of ignoring all quotes in STRING and invoking the +# macros it contains. Among other things, this is useful for enabling +# macro invocations inside strings with [] blocks (for instance regexps +# and help-strings). On the other hand, since all quotes are disabled, +# any macro expanded during this time that relies on nested [] quoting +# will likely crash and burn. This macro is seldom useful; consider +# m4_unquote or m4_expand instead. +m4_define([m4_noquote], +[m4_changequote([-=<{(],[)}>=-])$1-=<{()}>=-m4_changequote([,])]) + + +# m4_quote(ARGS) +# -------------- +# Return ARGS as a single argument. Any whitespace after unquoted commas +# is stripped. There is always output, even when there were no arguments. +# +# It is important to realize the difference between `m4_quote(exp)' and +# `[exp]': in the first case you obtain the quoted *result* of the +# expansion of EXP, while in the latter you just obtain the string +# `exp'. +m4_define([m4_quote], [[$*]]) + + +# _m4_quote(ARGS) +# --------------- +# Like m4_quote, except that when there are no arguments, there is no +# output. For conditional scenarios (such as passing _m4_quote as the +# macro name in m4_mapall), this feature can be used to distinguish between +# one argument of the empty string vs. no arguments. However, in the +# normal case with arguments present, this is less efficient than m4_quote. +m4_define([_m4_quote], +[m4_if([$#], [0], [], [[$*]])]) + + +# m4_reverse(ARGS) +# ---------------- +# Output ARGS in reverse order. +# +# Please keep foreach.m4 in sync with any adjustments made here. +m4_define([m4_reverse], +[m4_if([$#], [0], [], [$#], [1], [[$1]], + [$0(m4_shift($@)), [$1]])]) + + +# m4_unquote(ARGS) +# ---------------- +# Remove one layer of quotes from each ARG, performing one level of +# expansion. For one argument, m4_unquote([arg]) is more efficient than +# m4_do([arg]), but for multiple arguments, the difference is that +# m4_unquote separates arguments with commas while m4_do concatenates. +# Follow this macro with [] if concatenation with subsequent text is +# undesired. +m4_define([m4_unquote], [$*]) + + +## -------------------------- ## +## 8. Implementing m4 loops. ## +## -------------------------- ## + + +# m4_for(VARIABLE, FIRST, LAST, [STEP = +/-1], EXPRESSION) +# -------------------------------------------------------- +# Expand EXPRESSION defining VARIABLE to FROM, FROM + 1, ..., TO with +# increments of STEP. Both limits are included, and bounds are +# checked for consistency. The algorithm is robust to indirect +# VARIABLE names. Changing VARIABLE inside EXPRESSION will not impact +# the number of iterations. +# +# Uses _m4_defn for speed, and avoid dnl in the macro body. Factor +# the _m4_for call so that EXPRESSION is only parsed once. +m4_define([m4_for], +[m4_pushdef([$1], m4_eval([$2]))]dnl +[m4_cond([m4_eval(([$3]) > ([$2]))], 1, + [m4_pushdef([_m4_step], m4_eval(m4_default_quoted([$4], + 1)))m4_assert(_m4_step > 0)_$0(_m4_defn([$1]), + m4_eval((([$3]) - ([$2])) / _m4_step * _m4_step + ([$2])), _m4_step,], + [m4_eval(([$3]) < ([$2]))], 1, + [m4_pushdef([_m4_step], m4_eval(m4_default_quoted([$4], + -1)))m4_assert(_m4_step < 0)_$0(_m4_defn([$1]), + m4_eval((([$2]) - ([$3])) / -(_m4_step) * _m4_step + ([$2])), _m4_step,], + [m4_pushdef([_m4_step])_$0(_m4_defn([$1]), _m4_defn([$1]), 0,])]dnl +[[m4_define([$1],], [)$5])m4_popdef([_m4_step], [$1])]) + +# _m4_for(COUNT, LAST, STEP, PRE, POST) +# ------------------------------------- +# Core of the loop, no consistency checks, all arguments are plain +# numbers. Expand PRE[COUNT]POST, then alter COUNT by STEP and +# iterate if COUNT is not LAST. +m4_define([_m4_for], +[$4[$1]$5[]m4_if([$1], [$2], [], + [$0(m4_eval([$1 + $3]), [$2], [$3], [$4], [$5])])]) + + +# Implementing `foreach' loops in m4 is much more tricky than it may +# seem. For example, the old M4 1.4.4 manual had an incorrect example, +# which looked like this (when translated to m4sugar): +# +# | # foreach(VAR, (LIST), STMT) +# | m4_define([foreach], +# | [m4_pushdef([$1])_foreach([$1], [$2], [$3])m4_popdef([$1])]) +# | m4_define([_arg1], [$1]) +# | m4_define([_foreach], +# | [m4_if([$2], [()], , +# | [m4_define([$1], _arg1$2)$3[]_foreach([$1], (m4_shift$2), [$3])])]) +# +# But then if you run +# +# | m4_define(a, 1) +# | m4_define(b, 2) +# | m4_define(c, 3) +# | foreach([f], [([a], [(b], [c)])], [echo f +# | ]) +# +# it gives +# +# => echo 1 +# => echo (2,3) +# +# which is not what is expected. +# +# Of course the problem is that many quotes are missing. So you add +# plenty of quotes at random places, until you reach the expected +# result. Alternatively, if you are a quoting wizard, you directly +# reach the following implementation (but if you really did, then +# apply to the maintenance of m4sugar!). +# +# | # foreach(VAR, (LIST), STMT) +# | m4_define([foreach], [m4_pushdef([$1])_foreach($@)m4_popdef([$1])]) +# | m4_define([_arg1], [[$1]]) +# | m4_define([_foreach], +# | [m4_if($2, [()], , +# | [m4_define([$1], [_arg1$2])$3[]_foreach([$1], [(m4_shift$2)], [$3])])]) +# +# which this time answers +# +# => echo a +# => echo (b +# => echo c) +# +# Bingo! +# +# Well, not quite. +# +# With a better look, you realize that the parens are more a pain than +# a help: since anyway you need to quote properly the list, you end up +# with always using an outermost pair of parens and an outermost pair +# of quotes. Rejecting the parens both eases the implementation, and +# simplifies the use: +# +# | # foreach(VAR, (LIST), STMT) +# | m4_define([foreach], [m4_pushdef([$1])_foreach($@)m4_popdef([$1])]) +# | m4_define([_arg1], [$1]) +# | m4_define([_foreach], +# | [m4_if($2, [], , +# | [m4_define([$1], [_arg1($2)])$3[]_foreach([$1], [m4_shift($2)], [$3])])]) +# +# +# Now, just replace the `$2' with `m4_quote($2)' in the outer `m4_if' +# to improve robustness, and you come up with a nice implementation +# that doesn't require extra parentheses in the user's LIST. +# +# But wait - now the algorithm is quadratic, because every recursion of +# the algorithm keeps the entire LIST and merely adds another m4_shift to +# the quoted text. If the user has a lot of elements in LIST, you can +# bring the system to its knees with the memory m4 then requires, or trip +# the m4 --nesting-limit recursion factor. The only way to avoid +# quadratic growth is ensure m4_shift is expanded prior to the recursion. +# Hence the design below. +# +# The M4 manual now includes a chapter devoted to this issue, with +# the lessons learned from m4sugar. And still, this design is only +# optimal for M4 1.6; see foreach.m4 for yet more comments on why +# M4 1.4.x uses yet another implementation. + + +# m4_foreach(VARIABLE, LIST, EXPRESSION) +# -------------------------------------- +# +# Expand EXPRESSION assigning each value of the LIST to VARIABLE. +# LIST should have the form `item_1, item_2, ..., item_n', i.e. the +# whole list must *quoted*. Quote members too if you don't want them +# to be expanded. +# +# This macro is robust to active symbols: +# | m4_define(active, [ACT, IVE]) +# | m4_foreach(Var, [active, active], [-Var-]) +# => -ACT--IVE--ACT--IVE- +# +# | m4_foreach(Var, [[active], [active]], [-Var-]) +# => -ACT, IVE--ACT, IVE- +# +# | m4_foreach(Var, [[[active]], [[active]]], [-Var-]) +# => -active--active- +# +# This macro is called frequently, so avoid extra expansions such as +# m4_ifval and dnl. Also, since $2 might be quite large, try to use it +# as little as possible in _m4_foreach; each extra use requires that much +# more memory for expansion. So, rather than directly compare $2 against +# [] and use m4_car/m4_cdr for recursion, we instead unbox the list (which +# requires swapping the argument order in the helper), insert an ignored +# third argument, and use m4_shift3 to detect when recursion is complete, +# at which point this looks very much like m4_map_args. +m4_define([m4_foreach], +[m4_if([$2], [], [], + [m4_pushdef([$1])_$0([m4_define([$1],], [)$3], [], + $2)m4_popdef([$1])])]) + +# _m4_foreach(PRE, POST, IGNORED, ARG...) +# --------------------------------------- +# Form the common basis of the m4_foreach and m4_map macros. For each +# ARG, expand PRE[ARG]POST[]. The IGNORED argument makes recursion +# easier, and must be supplied rather than implicit. +# +# Please keep foreach.m4 in sync with any adjustments made here. +m4_define([_m4_foreach], +[m4_if([$#], [3], [], + [$1[$4]$2[]$0([$1], [$2], m4_shift3($@))])]) + + +# m4_foreach_w(VARIABLE, LIST, EXPRESSION) +# ---------------------------------------- +# Like m4_foreach, but the list is whitespace separated. Depending on +# EXPRESSION, it may be more efficient to use m4_map_args_w. +# +# This macro is robust to active symbols: +# m4_foreach_w([Var], [ active +# b act\ +# ive ], [-Var-])end +# => -active--b--active-end +# +# This used to use a slower implementation based on m4_foreach: +# m4_foreach([$1], m4_split(m4_normalize([$2]), [ ]), [$3]) +m4_define([m4_foreach_w], +[m4_pushdef([$1])m4_map_args_w([$2], + [m4_define([$1],], [)$3])m4_popdef([$1])]) + + +# m4_map(MACRO, LIST) +# m4_mapall(MACRO, LIST) +# ---------------------- +# Invoke MACRO($1), MACRO($2) etc. where $1, $2... are the elements of +# LIST. $1, $2... must in turn be lists, appropriate for m4_apply. +# If LIST contains an empty sublist, m4_map skips the expansion of +# MACRO, while m4_mapall expands MACRO with no arguments. +# +# Since LIST may be quite large, we want to minimize how often it +# appears in the expansion. Rather than use m4_car/m4_cdr iteration, +# we unbox the list, and use _m4_foreach for iteration. For m4_map, +# an empty list behaves like an empty sublist and gets ignored; for +# m4_mapall, we must special-case the empty list. +m4_define([m4_map], +[_m4_foreach([_m4_apply([$1],], [)], [], $2)]) + +m4_define([m4_mapall], +[m4_if([$2], [], [], + [_m4_foreach([m4_apply([$1],], [)], [], $2)])]) + + +# m4_map_sep(MACRO, [SEPARATOR], LIST) +# m4_mapall_sep(MACRO, [SEPARATOR], LIST) +# --------------------------------------- +# Invoke MACRO($1), SEPARATOR, MACRO($2), ..., MACRO($N) where $1, +# $2... $N are the elements of LIST, and are in turn lists appropriate +# for m4_apply. SEPARATOR is expanded, in order to allow the creation +# of a list of arguments by using a single-quoted comma as the +# separator. For each empty sublist, m4_map_sep skips the expansion +# of MACRO and SEPARATOR, while m4_mapall_sep expands MACRO with no +# arguments. +# +# For m4_mapall_sep, merely expand the first iteration without the +# separator, then include separator as part of subsequent recursion; +# but avoid extra expansion of LIST's side-effects via a helper macro. +# For m4_map_sep, things are trickier - we don't know if the first +# list element is an empty sublist, so we must define a self-modifying +# helper macro and use that as the separator instead. +m4_define([m4_map_sep], +[m4_pushdef([m4_Sep], [m4_define([m4_Sep], _m4_defn([m4_unquote]))])]dnl +[_m4_foreach([_m4_apply([m4_Sep([$2])[]$1],], [)], [], $3)m4_popdef([m4_Sep])]) + +m4_define([m4_mapall_sep], +[m4_if([$3], [], [], [_$0([$1], [$2], $3)])]) + +m4_define([_m4_mapall_sep], +[m4_apply([$1], [$3])_m4_foreach([m4_apply([$2[]$1],], [)], m4_shift2($@))]) + +# m4_map_args(EXPRESSION, ARG...) +# ------------------------------- +# Expand EXPRESSION([ARG]) for each argument. More efficient than +# m4_foreach([var], [ARG...], [EXPRESSION(m4_defn([var]))]) +# Shorthand for m4_map_args_sep([EXPRESSION(], [)], [], ARG...). +m4_define([m4_map_args], +[m4_if([$#], [0], [m4_fatal([$0: too few arguments: $#])], + [$#], [1], [], + [$#], [2], [$1([$2])[]], + [_m4_foreach([$1(], [)], $@)])]) + + +# m4_map_args_pair(EXPRESSION, [END-EXPR = EXPRESSION], ARG...) +# ------------------------------------------------------------- +# Perform a pairwise grouping of consecutive ARGs, by expanding +# EXPRESSION([ARG1], [ARG2]). If there are an odd number of ARGs, the +# final argument is expanded with END-EXPR([ARGn]). +# +# For example: +# m4_define([show], [($*)m4_newline])dnl +# m4_map_args_pair([show], [], [a], [b], [c], [d], [e])dnl +# => (a,b) +# => (c,d) +# => (e) +# +# Please keep foreach.m4 in sync with any adjustments made here. +m4_define([m4_map_args_pair], +[m4_if([$#], [0], [m4_fatal([$0: too few arguments: $#])], + [$#], [1], [m4_fatal([$0: too few arguments: $#: $1])], + [$#], [2], [], + [$#], [3], [m4_default([$2], [$1])([$3])[]], + [$#], [4], [$1([$3], [$4])[]], + [$1([$3], [$4])[]$0([$1], [$2], m4_shift(m4_shift3($@)))])]) + + +# m4_map_args_sep([PRE], [POST], [SEP], ARG...) +# --------------------------------------------- +# Expand PRE[ARG]POST for each argument, with SEP between arguments. +m4_define([m4_map_args_sep], +[m4_if([$#], [0], [m4_fatal([$0: too few arguments: $#])], + [$#], [1], [], + [$#], [2], [], + [$#], [3], [], + [$#], [4], [$1[$4]$2[]], + [$1[$4]$2[]_m4_foreach([$3[]$1], [$2], m4_shift3($@))])]) + + +# m4_map_args_w(STRING, [PRE], [POST], [SEP]) +# ------------------------------------------- +# Perform the expansion of PRE[word]POST[] for each word in STRING +# separated by whitespace. More efficient than: +# m4_foreach_w([var], [STRING], [PRE[]m4_defn([var])POST]) +# Additionally, expand SEP between words. +# +# As long as we have to use m4_bpatsubst to split the string, we might +# as well make it also apply PRE and POST; this avoids iteration +# altogether. But we must be careful of any \ in PRE or POST. +# _m4_strip returns a quoted string, but that's okay, since it also +# supplies an empty leading and trailing argument due to our +# intentional whitespace around STRING. We use m4_substr to strip the +# empty elements and remove the extra layer of quoting. +m4_define([m4_map_args_w], +[_$0(_m4_split([ ]m4_flatten([$1])[ ], [[ ]+], + m4_if(m4_index([$2$3$4], [\]), [-1], [[$3[]$4[]$2]], + [m4_bpatsubst([[$3[]$4[]$2]], [\\], [\\\\])])), + m4_len([[]$3[]$4]), m4_len([$4[]$2[]]))]) + +m4_define([_m4_map_args_w], +[m4_substr([$1], [$2], m4_eval(m4_len([$1]) - [$2] - [$3]))]) + + +# m4_stack_foreach(MACRO, FUNC) +# m4_stack_foreach_lifo(MACRO, FUNC) +# ---------------------------------- +# Pass each stacked definition of MACRO to the one-argument macro FUNC. +# m4_stack_foreach proceeds in FIFO order, while m4_stack_foreach_lifo +# processes the topmost definitions first. In addition, FUNC should +# not push or pop definitions of MACRO, and should not expect anything about +# the active definition of MACRO (it will not be the topmost, and may not +# be the one passed to FUNC either). +# +# Some macros simply can't be examined with this method: namely, +# anything involved in the implementation of _m4_stack_reverse. +m4_define([m4_stack_foreach], +[_m4_stack_reverse([$1], [m4_tmp-$1])]dnl +[_m4_stack_reverse([m4_tmp-$1], [$1], [$2(_m4_defn([m4_tmp-$1]))])]) + +m4_define([m4_stack_foreach_lifo], +[_m4_stack_reverse([$1], [m4_tmp-$1], [$2(_m4_defn([m4_tmp-$1]))])]dnl +[_m4_stack_reverse([m4_tmp-$1], [$1])]) + +# m4_stack_foreach_sep(MACRO, [PRE], [POST], [SEP]) +# m4_stack_foreach_sep_lifo(MACRO, [PRE], [POST], [SEP]) +# ------------------------------------------------------ +# Similar to m4_stack_foreach and m4_stack_foreach_lifo, in that every +# definition of a pushdef stack will be visited. But rather than +# passing the definition as a single argument to a macro, this variant +# expands the concatenation of PRE[]definition[]POST, and expands SEP +# between consecutive expansions. Note that m4_stack_foreach([a], [b]) +# is equivalent to m4_stack_foreach_sep([a], [b(], [)]). +m4_define([m4_stack_foreach_sep], +[_m4_stack_reverse([$1], [m4_tmp-$1])]dnl +[_m4_stack_reverse([m4_tmp-$1], [$1], [$2[]_m4_defn([m4_tmp-$1])$3], [$4[]])]) + +m4_define([m4_stack_foreach_sep_lifo], +[_m4_stack_reverse([$1], [m4_tmp-$1], [$2[]_m4_defn([m4_tmp-$1])$3], [$4[]])]dnl +[_m4_stack_reverse([m4_tmp-$1], [$1])]) + + +# _m4_stack_reverse(OLD, NEW, [ACTION], [SEP]) +# -------------------------------------------- +# A recursive worker for pushdef stack manipulation. Destructively +# copy the OLD stack into the NEW, and expanding ACTION for each +# iteration. After the first iteration, SEP is promoted to the front +# of ACTION (note that SEP should include a trailing [] if it is to +# avoid interfering with ACTION). The current definition is examined +# after the NEW has been pushed but before OLD has been popped; this +# order is important, as ACTION is permitted to operate on either +# _m4_defn([OLD]) or _m4_defn([NEW]). Since the operation is +# destructive, this macro is generally used twice, with a temporary +# macro name holding the swapped copy. +m4_define([_m4_stack_reverse], +[m4_ifdef([$1], [m4_pushdef([$2], + _m4_defn([$1]))$3[]_m4_popdef([$1])$0([$1], [$2], [$4$3])])]) + + + +## --------------------------- ## +## 9. More diversion support. ## +## --------------------------- ## + + +# m4_cleardivert(DIVERSION-NAME...) +# --------------------------------- +# Discard any text in DIVERSION-NAME. +# +# This works even inside m4_expand. +m4_define([m4_cleardivert], +[m4_if([$#], [0], [m4_fatal([$0: missing argument])], + [_m4_divert_raw([-1])m4_undivert($@)_m4_divert_raw( + _m4_divert(_m4_defn([_m4_divert_diversion]), [-]))])]) + + +# _m4_divert(DIVERSION-NAME or NUMBER, [NOWARN]) +# ---------------------------------------------- +# If DIVERSION-NAME is the name of a diversion, return its number, +# otherwise if it is a NUMBER return it. Issue a warning about +# the use of a number instead of a name, unless NOWARN is provided. +m4_define([_m4_divert], +[m4_ifdef([_m4_divert($1)], + [m4_indir([_m4_divert($1)])], + [m4_if([$2], [], [m4_warn([syntax], + [prefer named diversions])])$1])]) + +# KILL is only used to suppress output. +m4_define([_m4_divert(KILL)], -1) + +# The empty diversion name is a synonym for 0. +m4_define([_m4_divert()], 0) + + +# m4_divert_stack +# --------------- +# Print the diversion stack, if it's nonempty. The caller is +# responsible for any leading or trailing newline. +m4_define([m4_divert_stack], +[m4_stack_foreach_sep_lifo([_m4_divert_stack], [], [], [ +])]) + + +# m4_divert_stack_push(MACRO-NAME, DIVERSION-NAME) +# ------------------------------------------------ +# Form an entry of the diversion stack from caller MACRO-NAME and +# entering DIVERSION-NAME and push it. +m4_define([m4_divert_stack_push], +[m4_pushdef([_m4_divert_stack], m4_location[: $1: $2])]) + + +# m4_divert(DIVERSION-NAME) +# ------------------------- +# Change the diversion stream to DIVERSION-NAME. +m4_define([m4_divert], +[m4_popdef([_m4_divert_stack])]dnl +[m4_define([_m4_divert_diversion], [$1])]dnl +[m4_divert_stack_push([$0], [$1])]dnl +[_m4_divert_raw(_m4_divert([$1]))]) + + +# m4_divert_push(DIVERSION-NAME, [NOWARN]) +# ---------------------------------------- +# Change the diversion stream to DIVERSION-NAME, while stacking old values. +# For internal use only: if NOWARN is not empty, DIVERSION-NAME can be a +# number instead of a name. +m4_define([m4_divert_push], +[m4_divert_stack_push([$0], [$1])]dnl +[m4_pushdef([_m4_divert_diversion], [$1])]dnl +[_m4_divert_raw(_m4_divert([$1], [$2]))]) + + +# m4_divert_pop([DIVERSION-NAME]) +# ------------------------------- +# Change the diversion stream to its previous value, unstacking it. +# If specified, verify we left DIVERSION-NAME. +# When we pop the last value from the stack, we divert to -1. +m4_define([m4_divert_pop], +[m4_if([$1], [], [], + [$1], _m4_defn([_m4_divert_diversion]), [], + [m4_fatal([$0($1): diversion mismatch: +]m4_divert_stack)])]dnl +[_m4_popdef([_m4_divert_stack], [_m4_divert_diversion])]dnl +[m4_ifdef([_m4_divert_diversion], [], + [m4_fatal([too many m4_divert_pop])])]dnl +[_m4_divert_raw(_m4_divert(_m4_defn([_m4_divert_diversion]), [-]))]) + + +# m4_divert_text(DIVERSION-NAME, CONTENT) +# --------------------------------------- +# Output CONTENT into DIVERSION-NAME (which may be a number actually). +# An end of line is appended for free to CONTENT. +m4_define([m4_divert_text], +[m4_divert_push([$1])$2 +m4_divert_pop([$1])]) + + +# m4_divert_once(DIVERSION-NAME, CONTENT) +# --------------------------------------- +# Output CONTENT into DIVERSION-NAME once, if not already there. +# An end of line is appended for free to CONTENT. +m4_define([m4_divert_once], +[m4_expand_once([m4_divert_text([$1], [$2])])]) + + +# _m4_divert_unsafe(DIVERSION-NAME) +# --------------------------------- +# Issue a warning that the attempt to change the current diversion to +# DIVERSION-NAME is unsafe, because this macro is being expanded +# during argument collection of m4_expand. +m4_define([_m4_divert_unsafe], +[m4_fatal([$0: cannot change diversion to `$1' inside m4_expand])]) + + +# m4_undivert(DIVERSION-NAME...) +# ------------------------------ +# Undivert DIVERSION-NAME. Unlike the M4 version, this requires at +# least one DIVERSION-NAME; also, due to support for named diversions, +# this should not be used to undivert files. +m4_define([m4_undivert], +[m4_if([$#], [0], [m4_fatal([$0: missing argument])], + [$#], [1], [_m4_undivert(_m4_divert([$1]))], + [m4_map_args([$0], $@)])]) + + +## --------------------------------------------- ## +## 10. Defining macros with bells and whistles. ## +## --------------------------------------------- ## + +# `m4_defun' is basically `m4_define' but it equips the macro with the +# needed machinery for `m4_require'. A macro must be m4_defun'd if +# either it is m4_require'd, or it m4_require's. +# +# Two things deserve attention and are detailed below: +# 1. Implementation of m4_require +# 2. Keeping track of the expansion stack +# +# 1. Implementation of m4_require +# =============================== +# +# Of course m4_defun calls m4_provide, so that a macro which has +# been expanded is not expanded again when m4_require'd, but the +# difficult part is the proper expansion of macros when they are +# m4_require'd. +# +# The implementation is based on three ideas, (i) using diversions to +# prepare the expansion of the macro and its dependencies (by Franc,ois +# Pinard), (ii) expand the most recently m4_require'd macros _after_ +# the previous macros (by Axel Thimm), and (iii) track instances of +# provide before require (by Eric Blake). +# +# +# The first idea: why use diversions? +# ----------------------------------- +# +# When a macro requires another, the other macro is expanded in new +# diversion, GROW. When the outer macro is fully expanded, we first +# undivert the most nested diversions (GROW - 1...), and finally +# undivert GROW. To understand why we need several diversions, +# consider the following example: +# +# | m4_defun([TEST1], [Test...m4_require([TEST2])1]) +# | m4_defun([TEST2], [Test...m4_require([TEST3])2]) +# | m4_defun([TEST3], [Test...3]) +# +# Because m4_require is not required to be first in the outer macros, we +# must keep the expansions of the various levels of m4_require separated. +# Right before executing the epilogue of TEST1, we have: +# +# GROW - 2: Test...3 +# GROW - 1: Test...2 +# GROW: Test...1 +# BODY: +# +# Finally the epilogue of TEST1 undiverts GROW - 2, GROW - 1, and +# GROW into the regular flow, BODY. +# +# GROW - 2: +# GROW - 1: +# GROW: +# BODY: Test...3; Test...2; Test...1 +# +# (The semicolons are here for clarification, but of course are not +# emitted.) This is what Autoconf 2.0 (I think) to 2.13 (I'm sure) +# implement. +# +# +# The second idea: first required first out +# ----------------------------------------- +# +# The natural implementation of the idea above is buggy and produces +# very surprising results in some situations. Let's consider the +# following example to explain the bug: +# +# | m4_defun([TEST1], [m4_require([TEST2a])m4_require([TEST2b])]) +# | m4_defun([TEST2a], []) +# | m4_defun([TEST2b], [m4_require([TEST3])]) +# | m4_defun([TEST3], [m4_require([TEST2a])]) +# | +# | AC_INIT +# | TEST1 +# +# The dependencies between the macros are: +# +# 3 --- 2b +# / \ is m4_require'd by +# / \ left -------------------- right +# 2a ------------ 1 +# +# If you strictly apply the rules given in the previous section you get: +# +# GROW - 2: TEST3 +# GROW - 1: TEST2a; TEST2b +# GROW: TEST1 +# BODY: +# +# (TEST2a, although required by TEST3 is not expanded in GROW - 3 +# because is has already been expanded before in GROW - 1, so it has +# been AC_PROVIDE'd, so it is not expanded again) so when you undivert +# the stack of diversions, you get: +# +# GROW - 2: +# GROW - 1: +# GROW: +# BODY: TEST3; TEST2a; TEST2b; TEST1 +# +# i.e., TEST2a is expanded after TEST3 although the latter required the +# former. +# +# Starting from 2.50, we use an implementation provided by Axel Thimm. +# The idea is simple: the order in which macros are emitted must be the +# same as the one in which macros are expanded. (The bug above can +# indeed be described as: a macro has been m4_provide'd before its +# dependent, but it is emitted after: the lack of correlation between +# emission and expansion order is guilty). +# +# How to do that? You keep the stack of diversions to elaborate the +# macros, but each time a macro is fully expanded, emit it immediately. +# +# In the example above, when TEST2a is expanded, but it's epilogue is +# not run yet, you have: +# +# GROW - 2: +# GROW - 1: TEST2a +# GROW: Elaboration of TEST1 +# BODY: +# +# The epilogue of TEST2a emits it immediately: +# +# GROW - 2: +# GROW - 1: +# GROW: Elaboration of TEST1 +# BODY: TEST2a +# +# TEST2b then requires TEST3, so right before the epilogue of TEST3, you +# have: +# +# GROW - 2: TEST3 +# GROW - 1: Elaboration of TEST2b +# GROW: Elaboration of TEST1 +# BODY: TEST2a +# +# The epilogue of TEST3 emits it: +# +# GROW - 2: +# GROW - 1: Elaboration of TEST2b +# GROW: Elaboration of TEST1 +# BODY: TEST2a; TEST3 +# +# TEST2b is now completely expanded, and emitted: +# +# GROW - 2: +# GROW - 1: +# GROW: Elaboration of TEST1 +# BODY: TEST2a; TEST3; TEST2b +# +# and finally, TEST1 is finished and emitted: +# +# GROW - 2: +# GROW - 1: +# GROW: +# BODY: TEST2a; TEST3; TEST2b: TEST1 +# +# The idea is simple, but the implementation is a bit involved. If +# you are like me, you will want to see the actual functioning of this +# implementation to be convinced. The next section gives the full +# details. +# +# +# The Axel Thimm implementation at work +# ------------------------------------- +# +# We consider the macros above, and this configure.ac: +# +# AC_INIT +# TEST1 +# +# You should keep the definitions of _m4_defun_pro, _m4_defun_epi, and +# m4_require at hand to follow the steps. +# +# This implementation tries not to assume that the current diversion is +# BODY, so as soon as a macro (m4_defun'd) is expanded, we first +# record the current diversion under the name _m4_divert_dump (denoted +# DUMP below for short). This introduces an important difference with +# the previous versions of Autoconf: you cannot use m4_require if you +# are not inside an m4_defun'd macro, and especially, you cannot +# m4_require directly from the top level. +# +# We have not tried to simulate the old behavior (better yet, we +# diagnose it), because it is too dangerous: a macro m4_require'd from +# the top level is expanded before the body of `configure', i.e., before +# any other test was run. I let you imagine the result of requiring +# AC_STDC_HEADERS for instance, before AC_PROG_CC was actually run.... +# +# After AC_INIT was run, the current diversion is BODY. +# * AC_INIT was run +# DUMP: undefined +# diversion stack: BODY |- +# +# * TEST1 is expanded +# The prologue of TEST1 sets _m4_divert_dump, which is the diversion +# where the current elaboration will be dumped, to the current +# diversion. It also m4_divert_push to GROW, where the full +# expansion of TEST1 and its dependencies will be elaborated. +# DUMP: BODY +# BODY: empty +# diversions: GROW, BODY |- +# +# * TEST1 requires TEST2a +# _m4_require_call m4_divert_pushes another temporary diversion, +# GROW - 1, and expands TEST2a in there. +# DUMP: BODY +# BODY: empty +# GROW - 1: TEST2a +# diversions: GROW - 1, GROW, BODY |- +# Then the content of the temporary diversion is moved to DUMP and the +# temporary diversion is popped. +# DUMP: BODY +# BODY: TEST2a +# diversions: GROW, BODY |- +# +# * TEST1 requires TEST2b +# Again, _m4_require_call pushes GROW - 1 and heads to expand TEST2b. +# DUMP: BODY +# BODY: TEST2a +# diversions: GROW - 1, GROW, BODY |- +# +# * TEST2b requires TEST3 +# _m4_require_call pushes GROW - 2 and expands TEST3 here. +# (TEST3 requires TEST2a, but TEST2a has already been m4_provide'd, so +# nothing happens.) +# DUMP: BODY +# BODY: TEST2a +# GROW - 2: TEST3 +# diversions: GROW - 2, GROW - 1, GROW, BODY |- +# Then the diversion is appended to DUMP, and popped. +# DUMP: BODY +# BODY: TEST2a; TEST3 +# diversions: GROW - 1, GROW, BODY |- +# +# * TEST1 requires TEST2b (contd.) +# The content of TEST2b is expanded... +# DUMP: BODY +# BODY: TEST2a; TEST3 +# GROW - 1: TEST2b, +# diversions: GROW - 1, GROW, BODY |- +# ... and moved to DUMP. +# DUMP: BODY +# BODY: TEST2a; TEST3; TEST2b +# diversions: GROW, BODY |- +# +# * TEST1 is expanded: epilogue +# TEST1's own content is in GROW... +# DUMP: BODY +# BODY: TEST2a; TEST3; TEST2b +# GROW: TEST1 +# diversions: BODY |- +# ... and it's epilogue moves it to DUMP and then undefines DUMP. +# DUMP: undefined +# BODY: TEST2a; TEST3; TEST2b; TEST1 +# diversions: BODY |- +# +# +# The third idea: track macros provided before they were required +# --------------------------------------------------------------- +# +# Using just the first two ideas, Autoconf 2.50 through 2.63 still had +# a subtle bug for more than seven years. Let's consider the +# following example to explain the bug: +# +# | m4_defun([TEST1], [1]) +# | m4_defun([TEST2], [2[]m4_require([TEST1])]) +# | m4_defun([TEST3], [3 TEST1 m4_require([TEST2])]) +# | TEST3 +# +# After the prologue of TEST3, we are collecting text in GROW with the +# intent of dumping it in BODY during the epilogue. Next, we +# encounter the direct invocation of TEST1, which provides the macro +# in place in GROW. From there, we encounter a requirement for TEST2, +# which must be collected in a new diversion. While expanding TEST2, +# we encounter a requirement for TEST1, but since it has already been +# expanded, the Axel Thimm algorithm states that we can treat it as a +# no-op. But that would lead to an end result of `2 3 1', meaning +# that we have once again output a macro (TEST2) prior to its +# requirements (TEST1). +# +# The problem can only occur if a single defun'd macro first provides, +# then later indirectly requires, the same macro. Note that directly +# expanding then requiring a macro is okay: because the dependency was +# met, the require phase can be a no-op. For that matter, the outer +# macro can even require two helpers, where the first helper expands +# the macro, and the second helper indirectly requires the macro. +# Out-of-order expansion is only present if the inner macro is +# required by something that will be hoisted in front of where the +# direct expansion occurred. In other words, we must be careful not +# to warn on: +# +# | m4_defun([TEST4], [4]) +# | m4_defun([TEST5], [5 TEST4 m4_require([TEST4])]) +# | TEST5 => 5 4 +# +# or even the more complex: +# +# | m4_defun([TEST6], [6]) +# | m4_defun([TEST7], [7 TEST6]) +# | m4_defun([TEST8], [8 m4_require([TEST6])]) +# | m4_defun([TEST9], [9 m4_require([TEST8])]) +# | m4_defun([TEST10], [10 m4_require([TEST7]) m4_require([TEST9])]) +# | TEST10 => 7 6 8 9 10 +# +# So, to detect whether a require was direct or indirect, m4_defun and +# m4_require track the name of the macro that caused a diversion to be +# created (using the stack _m4_diverting, coupled with an O(1) lookup +# _m4_diverting([NAME])), and m4_provide stores the name associated +# with the diversion at which a macro was provided. A require call is +# direct if it occurs within the same diversion where the macro was +# provided, or if the diversion associated with the providing context +# has been collected. +# +# The implementation of the warning involves tracking the set of +# macros which have been provided since the start of the outermost +# defun'd macro (the set is named _m4_provide). When starting an +# outermost macro, the set is emptied; when a macro is provided, it is +# added to the set; when require expands the body of a macro, it is +# removed from the set; and when a macro is indirectly required, the +# set is checked. If a macro is in the set, then it has been provided +# before it was required, and we satisfy dependencies by expanding the +# macro as if it had never been provided; in the example given above, +# this means we now output `1 2 3 1'. Meanwhile, a warning is issued +# to inform the user that her macros trigger the bug in older autoconf +# versions, and that her output file now contains redundant contents +# (and possibly new problems, if the repeated macro was not +# idempotent). Meanwhile, macros defined by m4_defun_once instead of +# m4_defun are idempotent, avoiding any warning or duplicate output. +# +# +# 2. Keeping track of the expansion stack +# ======================================= +# +# When M4 expansion goes wrong it is often extremely hard to find the +# path amongst macros that drove to the failure. What is needed is +# the stack of macro `calls'. One could imagine that GNU M4 would +# maintain a stack of macro expansions, unfortunately it doesn't, so +# we do it by hand. This is of course extremely costly, but the help +# this stack provides is worth it. Nevertheless to limit the +# performance penalty this is implemented only for m4_defun'd macros, +# not for define'd macros. +# +# Each time we enter an m4_defun'd macros, we add a definition in +# _m4_expansion_stack, and when we exit the macro, we remove it (thanks +# to pushdef/popdef). m4_stack_foreach is used to print the expansion +# stack in the rare cases when it's needed. +# +# In addition, we want to detect circular m4_require dependencies. +# Each time we expand a macro FOO we define _m4_expanding(FOO); and +# m4_require(BAR) simply checks whether _m4_expanding(BAR) is defined. + + +# m4_expansion_stack +# ------------------ +# Expands to the entire contents of the expansion stack. The caller +# must supply a trailing newline. This macro always prints a +# location; check whether _m4_expansion_stack is defined to filter out +# the case when no defun'd macro is in force. +m4_define([m4_expansion_stack], +[m4_stack_foreach_sep_lifo([_$0], [_$0_entry(], [) +])m4_location[: the top level]]) + +# _m4_expansion_stack_entry(MACRO) +# -------------------------------- +# Format an entry for MACRO found on the expansion stack. +m4_define([_m4_expansion_stack_entry], +[_m4_defn([m4_location($1)])[: $1 is expanded from...]]) + +# m4_expansion_stack_push(MACRO) +# ------------------------------ +# Form an entry of the expansion stack on entry to MACRO and push it. +m4_define([m4_expansion_stack_push], +[m4_pushdef([_m4_expansion_stack], [$1])]) + + +# _m4_divert(GROW) +# ---------------- +# This diversion is used by the m4_defun/m4_require machinery. It is +# important to keep room before GROW because for each nested +# AC_REQUIRE we use an additional diversion (i.e., two m4_require's +# will use GROW - 2. More than 3 levels has never seemed to be +# needed.) +# +# ... +# - GROW - 2 +# m4_require'd code, 2 level deep +# - GROW - 1 +# m4_require'd code, 1 level deep +# - GROW +# m4_defun'd macros are elaborated here. + +m4_define([_m4_divert(GROW)], 10000) + + +# _m4_defun_pro(MACRO-NAME) +# ------------------------- +# The prologue for Autoconf macros. +# +# This is called frequently, so minimize the number of macro invocations +# by avoiding dnl and m4_defn overhead. +m4_define([_m4_defun_pro], +[m4_ifdef([_m4_expansion_stack], [], [_m4_defun_pro_outer([$1])])]dnl +[m4_expansion_stack_push([$1])m4_pushdef([_m4_expanding($1)])]) + +m4_define([_m4_defun_pro_outer], +[m4_set_delete([_m4_provide])]dnl +[m4_pushdef([_m4_diverting([$1])])m4_pushdef([_m4_diverting], [$1])]dnl +[m4_pushdef([_m4_divert_dump], m4_divnum)m4_divert_push([GROW])]) + +# _m4_defun_epi(MACRO-NAME) +# ------------------------- +# The Epilogue for Autoconf macros. MACRO-NAME only helps tracing +# the PRO/EPI pairs. +# +# This is called frequently, so minimize the number of macro invocations +# by avoiding dnl and m4_popdef overhead. +m4_define([_m4_defun_epi], +[_m4_popdef([_m4_expanding($1)], [_m4_expansion_stack])]dnl +[m4_ifdef([_m4_expansion_stack], [], [_m4_defun_epi_outer([$1])])]dnl +[m4_provide([$1])]) + +m4_define([_m4_defun_epi_outer], +[_m4_popdef([_m4_divert_dump], [_m4_diverting([$1])], [_m4_diverting])]dnl +[m4_divert_pop([GROW])m4_undivert([GROW])]) + + +# _m4_divert_dump +# --------------- +# If blank, we are outside of any defun'd macro. Otherwise, expands +# to the diversion number (not name) where require'd macros should be +# moved once completed. +m4_define([_m4_divert_dump]) + + +# m4_divert_require(DIVERSION, NAME-TO-CHECK, [BODY-TO-EXPAND]) +# ------------------------------------------------------------- +# Same as m4_require, but BODY-TO-EXPAND goes into the named DIVERSION; +# requirements still go in the current diversion though. +# +m4_define([m4_divert_require], +[m4_ifdef([_m4_expanding($2)], + [m4_fatal([$0: circular dependency of $2])])]dnl +[m4_if(_m4_divert_dump, [], + [m4_fatal([$0($2): cannot be used outside of an m4_defun'd macro])])]dnl +[m4_provide_if([$2], [], + [_m4_require_call([$2], [$3], _m4_divert([$1], [-]))])]) + + +# m4_defun(NAME, EXPANSION, [MACRO = m4_define]) +# ---------------------------------------------- +# Define a macro NAME which automatically provides itself. Add +# machinery so the macro automatically switches expansion to the +# diversion stack if it is not already using it, prior to EXPANSION. +# In this case, once finished, it will bring back all the code +# accumulated in the diversion stack. This, combined with m4_require, +# achieves the topological ordering of macros. We don't use this +# macro to define some frequently called macros that are not involved +# in ordering constraints, to save m4 processing. +# +# MACRO is an undocumented argument; when set to m4_pushdef, and NAME +# is already defined, the new definition is added to the pushdef +# stack, rather than overwriting the current definition. It can thus +# be used to write self-modifying macros, which pop themselves to a +# previously m4_define'd definition so that subsequent use of the +# macro is faster. +m4_define([m4_defun], +[m4_define([m4_location($1)], m4_location)]dnl +[m4_default([$3], [m4_define])([$1], + [_m4_defun_pro(]m4_dquote($[0])[)$2[]_m4_defun_epi(]m4_dquote($[0])[)])]) + + +# m4_defun_init(NAME, INIT, COMMON) +# --------------------------------- +# Like m4_defun, but split EXPANSION into two portions: INIT which is +# done only the first time NAME is invoked, and COMMON which is +# expanded every time. +# +# For now, the COMMON definition is always m4_define'd, giving an even +# lighter-weight definition. m4_defun allows self-providing, but once +# a macro is provided, m4_require no longer cares if it is m4_define'd +# or m4_defun'd. m4_defun also provides location tracking to identify +# dependency bugs, but once the INIT has been expanded, we know there +# are no dependency bugs. However, if a future use needs COMMON to be +# m4_defun'd, we can add a parameter, similar to the third parameter +# to m4_defun. +m4_define([m4_defun_init], +[m4_define([$1], [$3[]])m4_defun([$1], + [$2[]_m4_popdef(]m4_dquote($[0])[)m4_indir(]m4_dquote($[0])dnl +[m4_if(]m4_dquote($[#])[, [0], [], ]m4_dquote([,$]@)[))], [m4_pushdef])]) + + +# m4_defun_once(NAME, EXPANSION) +# ------------------------------ +# Like m4_defun, but guarantee that EXPANSION only happens once +# (thereafter, using NAME is a no-op). +# +# If _m4_divert_dump is empty, we are called at the top level; +# otherwise, we must ensure that we are required in front of the +# current defun'd macro. Use a helper macro so that EXPANSION need +# only occur once in the definition of NAME, since it might be large. +m4_define([m4_defun_once], +[m4_define([m4_location($1)], m4_location)]dnl +[m4_define([$1], [_m4_defun_once([$1], [$2], m4_if(_m4_divert_dump, [], + [[_m4_defun_pro([$1])m4_unquote(], [)_m4_defun_epi([$1])]], +m4_ifdef([_m4_diverting([$1])], [-]), [-], [[m4_unquote(], [)]], + [[_m4_require_call([$1],], [, _m4_divert_dump)]]))])]) + +m4_define([_m4_defun_once], +[m4_pushdef([$1])$3[$2[]m4_provide([$1])]$4]) + + +# m4_pattern_forbid(ERE, [WHY]) +# ----------------------------- +# Declare that no token matching the forbidden perl extended regular +# expression ERE should be seen in the output unless... +m4_define([m4_pattern_forbid], []) + + +# m4_pattern_allow(ERE) +# --------------------- +# ... that token also matches the allowed extended regular expression ERE. +# Both used via traces, by autom4te post-processing. +m4_define([m4_pattern_allow], []) + + +## --------------------------------- ## +## 11. Dependencies between macros. ## +## --------------------------------- ## + + +# m4_before(THIS-MACRO-NAME, CALLED-MACRO-NAME) +# --------------------------------------------- +# Issue a warning if CALLED-MACRO-NAME was called before THIS-MACRO-NAME. +m4_define([m4_before], +[m4_provide_if([$2], + [m4_warn([syntax], [$2 was called before $1])])]) + + +# m4_require(NAME-TO-CHECK, [BODY-TO-EXPAND = NAME-TO-CHECK]) +# ----------------------------------------------------------- +# If NAME-TO-CHECK has never been expanded (actually, if it is not +# m4_provide'd), expand BODY-TO-EXPAND *before* the current macro +# expansion; follow the expansion with a newline. Once expanded, emit +# it in _m4_divert_dump. Keep track of the m4_require chain in +# _m4_expansion_stack. +# +# The normal cases are: +# +# - NAME-TO-CHECK == BODY-TO-EXPAND +# Which you can use for regular macros with or without arguments, e.g., +# m4_require([AC_PROG_CC], [AC_PROG_CC]) +# m4_require([AC_CHECK_HEADERS(threads.h)], [AC_CHECK_HEADERS(threads.h)]) +# which is just the same as +# m4_require([AC_PROG_CC]) +# m4_require([AC_CHECK_HEADERS(threads.h)]) +# +# - BODY-TO-EXPAND == m4_indir([NAME-TO-CHECK]) +# In the case of macros with irregular names. For instance: +# m4_require([AC_LANG_COMPILER(C)], [indir([AC_LANG_COMPILER(C)])]) +# which means `if the macro named `AC_LANG_COMPILER(C)' (the parens are +# part of the name, it is not an argument) has not been run, then +# call it.' +# Had you used +# m4_require([AC_LANG_COMPILER(C)], [AC_LANG_COMPILER(C)]) +# then m4_require would have tried to expand `AC_LANG_COMPILER(C)', i.e., +# call the macro `AC_LANG_COMPILER' with `C' as argument. +# +# You could argue that `AC_LANG_COMPILER', when it receives an argument +# such as `C' should dispatch the call to `AC_LANG_COMPILER(C)'. But this +# `extension' prevents `AC_LANG_COMPILER' from having actual arguments that +# it passes to `AC_LANG_COMPILER(C)'. +# +# This is called frequently, so minimize the number of macro invocations +# by avoiding dnl and other overhead on the common path. +m4_define([m4_require], +[m4_ifdef([_m4_expanding($1)], + [m4_fatal([$0: circular dependency of $1])])]dnl +[m4_if(_m4_divert_dump, [], + [m4_fatal([$0($1): cannot be used outside of an ]dnl +m4_if([$0], [m4_require], [[m4_defun]], [[AC_DEFUN]])['d macro])])]dnl +[m4_provide_if([$1], [m4_set_contains([_m4_provide], [$1], + [_m4_require_check([$1], _m4_defn([m4_provide($1)]), [$0])], [m4_ignore])], + [_m4_require_call])([$1], [$2], _m4_divert_dump)]) + + +# _m4_require_call(NAME-TO-CHECK, [BODY-TO-EXPAND = NAME-TO-CHECK], +# DIVERSION-NUMBER) +# ----------------------------------------------------------------- +# If m4_require decides to expand the body, it calls this macro. The +# expansion is placed in DIVERSION-NUMBER. +# +# This is called frequently, so minimize the number of macro invocations +# by avoiding dnl and other overhead on the common path. +# The use of a witness macro protecting the warning allows aclocal +# to silence any warnings when probing for what macros are required +# and must therefore be located, when using the Autoconf-without-aclocal-m4 +# autom4te language. For more background, see: +# https://lists.gnu.org/archive/html/automake-patches/2012-11/msg00035.html +m4_define([_m4_require_call], +[m4_pushdef([_m4_divert_grow], m4_decr(_m4_divert_grow))]dnl +[m4_pushdef([_m4_diverting([$1])])m4_pushdef([_m4_diverting], [$1])]dnl +[m4_divert_push(_m4_divert_grow, [-])]dnl +[m4_if([$2], [], [$1], [$2]) +m4_provide_if([$1], [m4_set_remove([_m4_provide], [$1])], + [m4_ifndef([m4_require_silent_probe], + [m4_warn([syntax], [$1 is m4_require'd but not m4_defun'd])])])]dnl +[_m4_divert_raw($3)_m4_undivert(_m4_divert_grow)]dnl +[m4_divert_pop(_m4_divert_grow)_m4_popdef([_m4_divert_grow], +[_m4_diverting([$1])], [_m4_diverting])]) + + +# _m4_require_check(NAME-TO-CHECK, OWNER, CALLER) +# ----------------------------------------------- +# NAME-TO-CHECK has been identified as previously expanded in the +# diversion owned by OWNER. If this is a problem, warn on behalf of +# CALLER and return _m4_require_call; otherwise return m4_ignore. +m4_define([_m4_require_check], +[m4_if(_m4_defn([_m4_diverting]), [$2], [m4_ignore], + m4_ifdef([_m4_diverting([$2])], [-]), [-], [m4_warn([syntax], + [$3: `$1' was expanded before it was required +https://www.gnu.org/software/autoconf/manual/autoconf.html#Expanded-Before-Required])_m4_require_call], + [m4_ignore])]) + + +# _m4_divert_grow +# --------------- +# The counter for _m4_require_call. +m4_define([_m4_divert_grow], _m4_divert([GROW])) + + +# m4_expand_once(TEXT, [WITNESS = TEXT]) +# -------------------------------------- +# If TEXT has never been expanded, expand it *here*. Use WITNESS as +# as a memory that TEXT has already been expanded. +m4_define([m4_expand_once], +[m4_provide_if(m4_default_quoted([$2], [$1]), + [], + [m4_provide(m4_default_quoted([$2], [$1]))[]$1])]) + + +# m4_provide(MACRO-NAME) +# ---------------------- +m4_define([m4_provide], +[m4_ifdef([m4_provide($1)], [], +[m4_set_add([_m4_provide], [$1], [m4_define([m4_provide($1)], + m4_ifdef([_m4_diverting], [_m4_defn([_m4_diverting])]))])])]) + + +# m4_provide_if(MACRO-NAME, IF-PROVIDED, IF-NOT-PROVIDED) +# ------------------------------------------------------- +# If MACRO-NAME is provided do IF-PROVIDED, else IF-NOT-PROVIDED. +# The purpose of this macro is to provide the user with a means to +# check macros which are provided without letting her know how the +# information is coded. +m4_define([m4_provide_if], +[m4_ifdef([m4_provide($1)], + [$2], [$3])]) + + +## --------------------- ## +## 12. Text processing. ## +## --------------------- ## + + +# m4_cr_letters +# m4_cr_LETTERS +# m4_cr_Letters +# ------------- +m4_define([m4_cr_letters], [abcdefghijklmnopqrstuvwxyz]) +m4_define([m4_cr_LETTERS], [ABCDEFGHIJKLMNOPQRSTUVWXYZ]) +m4_define([m4_cr_Letters], +m4_defn([m4_cr_letters])dnl +m4_defn([m4_cr_LETTERS])dnl +) + + +# m4_cr_digits +# ------------ +m4_define([m4_cr_digits], [0123456789]) + + +# m4_cr_alnum +# ----------- +m4_define([m4_cr_alnum], +m4_defn([m4_cr_Letters])dnl +m4_defn([m4_cr_digits])dnl +) + + +# m4_cr_symbols1 +# m4_cr_symbols2 +# -------------- +m4_define([m4_cr_symbols1], +m4_defn([m4_cr_Letters])dnl +_) + +m4_define([m4_cr_symbols2], +m4_defn([m4_cr_symbols1])dnl +m4_defn([m4_cr_digits])dnl +) + +# m4_cr_all +# --------- +# The character range representing everything, with `-' as the last +# character, since it is special to m4_translit. Use with care, because +# it contains characters special to M4 (fortunately, both ASCII and EBCDIC +# have [] in order, so m4_defn([m4_cr_all]) remains a valid string). It +# also contains characters special to terminals, so it should never be +# displayed in an error message. Also, attempts to map [ and ] to other +# characters via m4_translit must deal with the fact that m4_translit does +# not add quotes to the output. +# +# In EBCDIC, $ is immediately followed by *, which leads to problems +# if m4_cr_all is inlined into a macro definition; so swap them. +# +# It is mainly useful in generating inverted character range maps, for use +# in places where m4_translit is faster than an equivalent m4_bpatsubst; +# the regex `[^a-z]' is equivalent to: +# m4_translit(m4_dquote(m4_defn([m4_cr_all])), [a-z]) +m4_define([m4_cr_all], +m4_translit(m4_dquote(m4_format(m4_dquote(m4_for( + ,1,255,,[[%c]]))m4_for([i],1,255,,[,i]))), [$*-], [*$])-) + + +# _m4_define_cr_not(CATEGORY) +# --------------------------- +# Define m4_cr_not_CATEGORY as the inverse of m4_cr_CATEGORY. +m4_define([_m4_define_cr_not], +[m4_define([m4_cr_not_$1], + m4_translit(m4_dquote(m4_defn([m4_cr_all])), + m4_defn([m4_cr_$1])))]) + + +# m4_cr_not_letters +# m4_cr_not_LETTERS +# m4_cr_not_Letters +# m4_cr_not_digits +# m4_cr_not_alnum +# m4_cr_not_symbols1 +# m4_cr_not_symbols2 +# ------------------ +# Inverse character sets +_m4_define_cr_not([letters]) +_m4_define_cr_not([LETTERS]) +_m4_define_cr_not([Letters]) +_m4_define_cr_not([digits]) +_m4_define_cr_not([alnum]) +_m4_define_cr_not([symbols1]) +_m4_define_cr_not([symbols2]) + + +# m4_newline([STRING]) +# -------------------- +# Expands to a newline, possibly followed by STRING. Exists mostly for +# formatting reasons. +m4_define([m4_newline], [ +$1]) + + +# m4_re_escape(STRING) +# -------------------- +# Escape RE active characters in STRING. +m4_define([m4_re_escape], +[m4_bpatsubst([$1], + [[][*+.?\^$]], [\\\&])]) + + +# m4_re_string +# ------------ +# Regexp for `[a-zA-Z_0-9]*' +# m4_dquote provides literal [] for the character class. +m4_define([m4_re_string], +m4_dquote(m4_defn([m4_cr_symbols2]))dnl +[*]dnl +) + + +# m4_re_word +# ---------- +# Regexp for `[a-zA-Z_][a-zA-Z_0-9]*' +m4_define([m4_re_word], +m4_dquote(m4_defn([m4_cr_symbols1]))dnl +m4_defn([m4_re_string])dnl +) + + +# m4_tolower(STRING) +# m4_toupper(STRING) +# ------------------ +# These macros convert STRING to lowercase or uppercase. +# +# Rather than expand the m4_defn each time, we inline them up front. +m4_define([m4_tolower], +[m4_translit([[$1]], ]m4_dquote(m4_defn([m4_cr_LETTERS]))[, + ]m4_dquote(m4_defn([m4_cr_letters]))[)]) +m4_define([m4_toupper], +[m4_translit([[$1]], ]m4_dquote(m4_defn([m4_cr_letters]))[, + ]m4_dquote(m4_defn([m4_cr_LETTERS]))[)]) + + +# m4_split(STRING, [REGEXP]) +# -------------------------- +# Split STRING into an m4 list of quoted elements. The elements are +# quoted with [ and ]. Beginning spaces and end spaces *are kept*. +# Use m4_strip to remove them. +# +# REGEXP specifies where to split. Default is [\t ]+. +# +# If STRING is empty, the result is an empty list. +# +# Pay attention to the m4_changequotes. When m4 reads the definition of +# m4_split, it still has quotes set to [ and ]. Luckily, these are matched +# in the macro body, so the definition is stored correctly. Use the same +# alternate quotes as m4_noquote; it must be unlikely to appear in $1. +# +# Also, notice that $1 is quoted twice, since we want the result to +# be quoted. Then you should understand that the argument of +# patsubst is -=<{(STRING)}>=- (i.e., with additional -=<{( and )}>=-). +# +# This macro is safe on active symbols, i.e.: +# m4_define(active, ACTIVE) +# m4_split([active active ])end +# => [active], [active], []end +# +# Optimize on regex of ` ' (space), since m4_foreach_w already guarantees +# that the list contains single space separators, and a common case is +# splitting a single-element list. This macro is called frequently, +# so avoid unnecessary dnl inside the definition. +m4_define([m4_split], +[m4_if([$1], [], [], + [$2], [ ], [m4_if(m4_index([$1], [ ]), [-1], [[[$1]]], + [_$0([$1], [$2], [, ])])], + [$2], [], [_$0([$1], [[ ]+], [, ])], + [_$0([$1], [$2], [, ])])]) + +m4_define([_m4_split], +[m4_changequote([-=<{(],[)}>=-])]dnl +[[m4_bpatsubst(-=<{(-=<{($1)}>=-)}>=-, -=<{($2)}>=-, + -=<{(]$3[)}>=-)]m4_changequote([, ])]) + + +# m4_chomp(STRING) +# m4_chomp_all(STRING) +# -------------------- +# Return STRING quoted, but without a trailing newline. m4_chomp +# removes at most one newline, while m4_chomp_all removes all +# consecutive trailing newlines. Embedded newlines are not touched, +# and a trailing backslash-newline leaves just a trailing backslash. +# +# m4_bregexp is slower than m4_index, and we don't always want to +# remove all newlines; hence the two variants. We massage characters +# to give a nicer pattern to match, particularly since m4_bregexp is +# line-oriented. Both versions must guarantee a match, to avoid bugs +# with precision -1 in m4_format in older m4. +m4_define([m4_chomp], +[m4_format([[%.*s]], m4_index(m4_translit([[$1]], [ +/.], [/ ])[./.], [/.]), [$1])]) + +m4_define([m4_chomp_all], +[m4_format([[%.*s]], m4_bregexp(m4_translit([[$1]], [ +/], [/ ]), [/*$]), [$1])]) + + +# m4_flatten(STRING) +# ------------------ +# If STRING contains end of lines, replace them with spaces. If there +# are backslashed end of lines, remove them. This macro is safe with +# active symbols. +# m4_define(active, ACTIVE) +# m4_flatten([active +# act\ +# ive])end +# => active activeend +# +# In m4, m4_bpatsubst is expensive, so first check for a newline. +m4_define([m4_flatten], +[m4_if(m4_index([$1], [ +]), [-1], [[$1]], + [m4_translit(m4_bpatsubst([[[$1]]], [\\ +]), [ +], [ ])])]) + + +# m4_strip(STRING) +# ---------------- +# Expands into STRING with tabs and spaces singled out into a single +# space, and removing leading and trailing spaces. +# +# This macro is robust to active symbols. +# m4_define(active, ACTIVE) +# m4_strip([ active active ])end +# => active activeend +# +# First, notice that we guarantee trailing space. Why? Because regular +# expressions are greedy, and `.* ?' would always group the space into the +# .* portion. The algorithm is simpler by avoiding `?' at the end. The +# algorithm correctly strips everything if STRING is just ` '. +# +# Then notice the second pattern: it is in charge of removing the +# leading/trailing spaces. Why not just `[^ ]'? Because they are +# applied to over-quoted strings, i.e. more or less [STRING], due +# to the limitations of m4_bpatsubsts. So the leading space in STRING +# is the *second* character; equally for the trailing space. +m4_define([m4_strip], +[m4_bpatsubsts([$1 ], + [[ ]+], [ ], + [^. ?\(.*\) .$], [[[\1]]])]) + + +# m4_normalize(STRING) +# -------------------- +# Apply m4_flatten and m4_strip to STRING. +# +# The argument is quoted, so that the macro is robust to active symbols: +# +# m4_define(active, ACTIVE) +# m4_normalize([ act\ +# ive +# active ])end +# => active activeend + +m4_define([m4_normalize], +[m4_strip(m4_flatten([$1]))]) + + +# m4_validate_w(STRING) +# --------------------- +# Expands into m4_normalize(m4_expand([STRING])), but if that is not +# the same as just m4_normalize([STRING]), issue a warning. +# +# This is used in several Autoconf macros that take a +# whitespace-separated list of symbols as an argument. Ideally that +# list would not be expanded before use, but several packages used +# `dnl' to put comments inside those lists, so they must be expanded +# for compatibility's sake. +m4_define([m4_validate_w], +[_m4_validate_w(m4_normalize([$1]), m4_normalize(m4_expand([$1])))]) + +m4_define([_m4_validate_w], +[m4_if([$1], [$2], [], + [m4_warn([obsolete], [whitespace-separated list contains macros; +in a future version of Autoconf they will not be expanded]dnl +m4_if(m4_bregexp([$1], [\bdn[l]\b]), -1, [], [ +note: `dn@&t@l' is a macro]))])dnl +[$2]]) + + +# m4_join(SEP, ARG1, ARG2...) +# --------------------------- +# Produce ARG1SEPARG2...SEPARGn. Avoid back-to-back SEP when a given ARG +# is the empty string. No expansion is performed on SEP or ARGs. +# +# Since the number of arguments to join can be arbitrarily long, we +# want to avoid having more than one $@ in the macro definition; +# otherwise, the expansion would require twice the memory of the already +# long list. Hence, m4_join merely looks for the first non-empty element, +# and outputs just that element; while _m4_join looks for all non-empty +# elements, and outputs them following a separator. The final trick to +# note is that we decide between recursing with $0 or _$0 based on the +# nested m4_if ending with `_'. +# +# Please keep foreach.m4 in sync with any adjustments made here. +m4_define([m4_join], +[m4_if([$#], [1], [], + [$#], [2], [[$2]], + [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift2($@))])]) +m4_define([_m4_join], +[m4_if([$#$2], [2], [], + [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift2($@))])]) + +# m4_joinall(SEP, ARG1, ARG2...) +# ------------------------------ +# Produce ARG1SEPARG2...SEPARGn. An empty ARG results in back-to-back SEP. +# No expansion is performed on SEP or ARGs. +# +# Please keep foreach.m4 in sync with any adjustments made here. +m4_define([m4_joinall], [[$2]_$0([$1], m4_shift($@))]) +m4_define([_m4_joinall], +[m4_if([$#], [2], [], [[$1$3]$0([$1], m4_shift2($@))])]) + +# m4_combine([SEPARATOR], PREFIX-LIST, [INFIX], SUFFIX...) +# -------------------------------------------------------- +# Produce the pairwise combination of every element in the quoted, +# comma-separated PREFIX-LIST with every element from the SUFFIX arguments. +# Each pair is joined with INFIX, and pairs are separated by SEPARATOR. +# No expansion occurs on SEPARATOR, INFIX, or elements of either list. +# +# For example: +# m4_combine([, ], [[a], [b], [c]], [-], [1], [2], [3]) +# => a-1, a-2, a-3, b-1, b-2, b-3, c-1, c-2, c-3 +# +# This definition is a bit hairy; the thing to realize is that we want +# to construct m4_map_args_sep([[prefix$3]], [], [[$1]], m4_shift3($@)) +# as the inner loop, using each prefix generated by the outer loop, +# and without recalculating m4_shift3 every outer iteration. +m4_define([m4_combine], +[m4_if([$2], [], [], m4_eval([$# > 3]), [1], +[m4_map_args_sep([m4_map_args_sep(m4_dquote(], [)[[$3]], [], [[$1]],]]]dnl +[m4_dquote(m4_dquote(m4_shift3($@)))[[)], [[$1]], $2)])]) + + +# m4_append(MACRO-NAME, STRING, [SEPARATOR]) +# ------------------------------------------ +# Redefine MACRO-NAME to hold its former content plus `SEPARATOR`'STRING' +# at the end. It is valid to use this macro with MACRO-NAME undefined, +# in which case no SEPARATOR is added. Be aware that the criterion is +# `not being defined', and not `not being empty'. +# +# Note that neither STRING nor SEPARATOR are expanded here; rather, when +# you expand MACRO-NAME, they will be expanded at that point in time. +# +# This macro is robust to active symbols. It can be used to grow +# strings. +# +# | m4_define(active, ACTIVE)dnl +# | m4_append([sentence], [This is an])dnl +# | m4_append([sentence], [ active ])dnl +# | m4_append([sentence], [symbol.])dnl +# | sentence +# | m4_undefine([active])dnl +# | sentence +# => This is an ACTIVE symbol. +# => This is an active symbol. +# +# It can be used to define hooks. +# +# | m4_define(active, ACTIVE)dnl +# | m4_append([hooks], [m4_define([act1], [act2])])dnl +# | m4_append([hooks], [m4_define([act2], [active])])dnl +# | m4_undefine([active])dnl +# | act1 +# | hooks +# | act1 +# => act1 +# => +# => active +# +# It can also be used to create lists, although this particular usage was +# broken prior to autoconf 2.62. +# | m4_append([list], [one], [, ])dnl +# | m4_append([list], [two], [, ])dnl +# | m4_append([list], [three], [, ])dnl +# | list +# | m4_dquote(list) +# => one, two, three +# => [one],[two],[three] +# +# Note that m4_append can benefit from amortized O(n) m4 behavior, if +# the underlying m4 implementation is smart enough to avoid copying existing +# contents when enlarging a macro's definition into any pre-allocated storage +# (m4 1.4.x unfortunately does not implement this optimization). We do +# not implement m4_prepend, since it is inherently O(n^2) (pre-allocated +# storage only occurs at the end of a macro, so the existing contents must +# always be moved). +# +# Use _m4_defn for speed. +m4_define([m4_append], +[m4_define([$1], m4_ifdef([$1], [_m4_defn([$1])[$3]])[$2])]) + + +# m4_append_uniq(MACRO-NAME, STRING, [SEPARATOR], [IF-UNIQ], [IF-DUP]) +# -------------------------------------------------------------------- +# Like `m4_append', but append only if not yet present. Additionally, +# expand IF-UNIQ if STRING was appended, or IF-DUP if STRING was already +# present. Also, warn if SEPARATOR is not empty and occurs within STRING, +# as the algorithm no longer guarantees uniqueness. +# +# Note that while m4_append can be O(n) (depending on the quality of the +# underlying M4 implementation), m4_append_uniq is inherently O(n^2) +# because each append operation searches the entire string. +m4_define([m4_append_uniq], +[m4_ifval([$3], [m4_if(m4_index([$2], [$3]), [-1], [], + [m4_warn([syntax], + [$0: `$2' contains `$3'])])])_$0($@)]) +m4_define([_m4_append_uniq], +[m4_ifdef([$1], + [m4_if(m4_index([$3]_m4_defn([$1])[$3], [$3$2$3]), [-1], + [m4_append([$1], [$2], [$3])$4], [$5])], + [m4_define([$1], [$2])$4])]) + +# m4_append_uniq_w(MACRO-NAME, STRINGS) +# ------------------------------------- +# For each of the words in the whitespace separated list STRINGS, append +# only the unique strings to the definition of MACRO-NAME. +# +# Use _m4_defn for speed. +m4_define([m4_append_uniq_w], +[m4_map_args_w([$2], [_m4_append_uniq([$1],], [, [ ])])]) + + +# m4_escape(STRING) +# ----------------- +# Output quoted STRING, but with embedded #, $, [ and ] turned into +# quadrigraphs. +# +# It is faster to check if STRING is already good using m4_translit +# than to blindly perform four m4_bpatsubst. +# +# Because the translit is stripping quotes, it must also neutralize +# anything that might be in a macro name, as well as comments, commas, +# and parentheses. All the problem characters are unified so that a +# single m4_index can scan the result. +# +# Rather than expand m4_defn every time m4_escape is expanded, we +# inline its expansion up front. +m4_define([m4_escape], +[m4_if(m4_index(m4_translit([$1], + [[]#,()]]m4_dquote(m4_defn([m4_cr_symbols2]))[, [$$$]), [$]), + [-1], [m4_echo], [_$0])([$1])]) + +m4_define([_m4_escape], +[m4_changequote([-=<{(],[)}>=-])]dnl +[m4_bpatsubst(m4_bpatsubst(m4_bpatsubst(m4_bpatsubst( + -=<{(-=<{(-=<{(-=<{(-=<{($1)}>=-)}>=-)}>=-)}>=-)}>=-, + -=<{(#)}>=-, -=<{(@%:@)}>=-), + -=<{(\[)}>=-, -=<{(@<:@)}>=-), + -=<{(\])}>=-, -=<{(@:>@)}>=-), + -=<{(\$)}>=-, -=<{(@S|@)}>=-)m4_changequote([,])]) + + +# m4_text_wrap(STRING, [PREFIX], [FIRST-PREFIX], [WIDTH]) +# ------------------------------------------------------- +# Expands into STRING wrapped to hold in WIDTH columns (default = 79). +# If PREFIX is given, each line is prefixed with it. If FIRST-PREFIX is +# specified, then the first line is prefixed with it. As a special case, +# if the length of FIRST-PREFIX is greater than that of PREFIX, then +# FIRST-PREFIX will be left alone on the first line. +# +# No expansion occurs on the contents STRING, PREFIX, or FIRST-PREFIX, +# although quadrigraphs are correctly recognized. More precisely, +# you may redefine m4_qlen to recognize whatever escape sequences that +# you will post-process. +# +# Typical outputs are: +# +# m4_text_wrap([Short string */], [ ], [/* ], 20) +# => /* Short string */ +# +# m4_text_wrap([Much longer string */], [ ], [/* ], 20) +# => /* Much longer +# => string */ +# +# m4_text_wrap([Short doc.], [ ], [ --short ], 30) +# => --short Short doc. +# +# m4_text_wrap([Short doc.], [ ], [ --too-wide ], 30) +# => --too-wide +# => Short doc. +# +# m4_text_wrap([Super long documentation.], [ ], [ --too-wide ], 30) +# => --too-wide +# => Super long +# => documentation. +# +# FIXME: there is no checking of a longer PREFIX than WIDTH, but do +# we really want to bother with people trying each single corner +# of a software? +# +# This macro does not leave a trailing space behind the last word of a line, +# which complicates it a bit. The algorithm is otherwise stupid and simple: +# all the words are preceded by m4_Separator which is defined to empty for +# the first word, and then ` ' (single space) for all the others. +# +# The algorithm uses a helper that uses $2 through $4 directly, rather than +# using local variables, to avoid m4_defn overhead, or expansion swallowing +# any $. It also bypasses m4_popdef overhead with _m4_popdef since no user +# macro expansion occurs in the meantime. Also, the definition is written +# with m4_do, to avoid time wasted on dnl during expansion (since this is +# already a time-consuming macro). +m4_define([m4_text_wrap], +[_$0(m4_escape([$1]), [$2], m4_default_quoted([$3], [$2]), + m4_default_quoted([$4], [79]))]) + +m4_define([_m4_text_wrap], +m4_do(dnl set up local variables, to avoid repeated calculations +[[m4_pushdef([m4_Indent], m4_qlen([$2]))]], +[[m4_pushdef([m4_Cursor], m4_qlen([$3]))]], +[[m4_pushdef([m4_Separator], [m4_define([m4_Separator], [ ])])]], +dnl expand the first prefix, then check its length vs. regular prefix +dnl same length: nothing special +dnl prefix1 longer: output on line by itself, and reset cursor +dnl prefix1 shorter: pad to length of prefix, and reset cursor +[[[$3]m4_cond([m4_Cursor], m4_Indent, [], + [m4_eval(m4_Cursor > m4_Indent)], [1], [ +[$2]m4_define([m4_Cursor], m4_Indent)], + [m4_format([%*s], m4_max([0], + m4_eval(m4_Indent - m4_Cursor)), [])m4_define([m4_Cursor], m4_Indent)])]], +dnl now, for each word, compute the cursor after the word is output, then +dnl check if the cursor would exceed the wrap column +dnl if so, reset cursor, and insert newline and prefix +dnl if not, insert the separator (usually a space) +dnl either way, insert the word +[[m4_map_args_w([$1], [$0_word(], [, [$2], [$4])])]], +dnl finally, clean up the local variables +[[_m4_popdef([m4_Separator], [m4_Cursor], [m4_Indent])]])) + +m4_define([_m4_text_wrap_word], +[m4_define([m4_Cursor], m4_eval(m4_Cursor + m4_qlen([$1]) + 1))]dnl +[m4_if(m4_eval(m4_Cursor > ([$3])), + [1], [m4_define([m4_Cursor], m4_eval(m4_Indent + m4_qlen([$1]) + 1)) +[$2]], + [m4_Separator[]])[$1]]) + +# m4_text_box(MESSAGE, [FRAME-CHARACTER = `-']) +# --------------------------------------------- +# Turn MESSAGE into: +# ## ------- ## +# ## MESSAGE ## +# ## ------- ## +# using FRAME-CHARACTER in the border. +# +# Quadrigraphs are correctly recognized. More precisely, you may +# redefine m4_qlen to recognize whatever escape sequences that you +# will post-process. +m4_define([m4_text_box], +[m4_pushdef([m4_Border], + m4_translit(m4_format([[[%*s]]], m4_decr(m4_qlen(_m4_expand([$1 +]))), []), [ ], m4_default_quoted([$2], [-])))]dnl +[[##] _m4_defn([m4_Border]) [##] +[##] $1 [##] +[##] _m4_defn([m4_Border]) [##]_m4_popdef([m4_Border])]) + + +# m4_qlen(STRING) +# --------------- +# Expands to the length of STRING after autom4te converts all quadrigraphs. +# +# If you use some other means of post-processing m4 output rather than +# autom4te, then you may redefine this macro to recognize whatever +# escape sequences your post-processor will handle. For that matter, +# m4_define([m4_qlen], m4_defn([m4_len])) is sufficient if you don't +# do any post-processing. +# +# Avoid bpatsubsts for the common case of no quadrigraphs. Cache +# results, as configure scripts tend to ask about lengths of common +# strings like `/*' and `*/' rather frequently. Minimize the number +# of times that $1 occurs in m4_qlen, so there is less text to parse +# on a cache hit. +m4_define([m4_qlen], +[m4_ifdef([$0-$1], [_m4_defn([$0-]], [_$0(])[$1])]) +m4_define([_m4_qlen], +[m4_define([m4_qlen-$1], +m4_if(m4_index([$1], [@]), [-1], [m4_len([$1])], + [m4_len(m4_bpatsubst([[$1]], + [@\(\(<:\|:>\|S|\|%:\|\{:\|:\}\)\(@\)\|&t@\)], + [\3]))]))_m4_defn([m4_qlen-$1])]) + +# m4_copyright_condense(TEXT) +# --------------------------- +# Condense the copyright notice in TEXT to only display the final +# year, wrapping the results to fit in 80 columns. +m4_define([m4_copyright_condense], +[m4_text_wrap(m4_bpatsubst(m4_flatten([[$1]]), +[(C)[- ,0-9]*\([1-9][0-9][0-9][0-9]\)], [(C) \1]))]) + +## ----------------------- ## +## 13. Number processing. ## +## ----------------------- ## + +# m4_cmp(A, B) +# ------------ +# Compare two integer expressions. +# A < B -> -1 +# A = B -> 0 +# A > B -> 1 +m4_define([m4_cmp], +[m4_eval((([$1]) > ([$2])) - (([$1]) < ([$2])))]) + + +# m4_list_cmp(A, B) +# ----------------- +# +# Compare the two lists of integer expressions A and B. For instance: +# m4_list_cmp([1, 0], [1]) -> 0 +# m4_list_cmp([1, 0], [1, 0]) -> 0 +# m4_list_cmp([1, 2], [1, 0]) -> 1 +# m4_list_cmp([1, 2, 3], [1, 2]) -> 1 +# m4_list_cmp([1, 2, -3], [1, 2]) -> -1 +# m4_list_cmp([1, 0], [1, 2]) -> -1 +# m4_list_cmp([1], [1, 2]) -> -1 +# m4_define([xa], [oops])dnl +# m4_list_cmp([[0xa]], [5+5]) -> 0 +# +# Rather than face the overhead of m4_case, we use a helper function whose +# expansion includes the name of the macro to invoke on the tail, either +# m4_ignore or m4_unquote. This is particularly useful when comparing +# long lists, since less text is being expanded for deciding when to end +# recursion. The recursion is between a pair of macros that alternate +# which list is trimmed by one element; this is more efficient than +# calling m4_cdr on both lists from a single macro. Guarantee exactly +# one expansion of both lists' side effects. +# +# Please keep foreach.m4 in sync with any adjustments made here. +m4_define([m4_list_cmp], +[_$0_raw(m4_dquote($1), m4_dquote($2))]) + +m4_define([_m4_list_cmp_raw], +[m4_if([$1], [$2], [0], [_m4_list_cmp_1([$1], $2)])]) + +m4_define([_m4_list_cmp], +[m4_if([$1], [], [0m4_ignore], [$2], [0], [m4_unquote], [$2m4_ignore])]) + +m4_define([_m4_list_cmp_1], +[_m4_list_cmp_2([$2], [m4_shift2($@)], $1)]) + +m4_define([_m4_list_cmp_2], +[_m4_list_cmp([$1$3], m4_cmp([$3+0], [$1+0]))( + [_m4_list_cmp_1(m4_dquote(m4_shift3($@)), $2)])]) + +# m4_max(EXPR, ...) +# m4_min(EXPR, ...) +# ----------------- +# Return the decimal value of the maximum (or minimum) in a series of +# integer expressions. +# +# M4 1.4.x doesn't provide ?:. Hence this huge m4_eval. Avoid m4_eval +# if both arguments are identical, but be aware of m4_max(0xa, 10) (hence +# the use of <=, not just <, in the second multiply). +# +# Please keep foreach.m4 in sync with any adjustments made here. +m4_define([m4_max], +[m4_if([$#], [0], [m4_fatal([too few arguments to $0])], + [$#], [1], [m4_eval([$1])], + [$#$1], [2$2], [m4_eval([$1])], + [$#], [2], [_$0($@)], + [_m4_minmax([_$0], $@)])]) + +m4_define([_m4_max], +[m4_eval((([$1]) > ([$2])) * ([$1]) + (([$1]) <= ([$2])) * ([$2]))]) + +m4_define([m4_min], +[m4_if([$#], [0], [m4_fatal([too few arguments to $0])], + [$#], [1], [m4_eval([$1])], + [$#$1], [2$2], [m4_eval([$1])], + [$#], [2], [_$0($@)], + [_m4_minmax([_$0], $@)])]) + +m4_define([_m4_min], +[m4_eval((([$1]) < ([$2])) * ([$1]) + (([$1]) >= ([$2])) * ([$2]))]) + +# _m4_minmax(METHOD, ARG1, ARG2...) +# --------------------------------- +# Common recursion code for m4_max and m4_min. METHOD must be _m4_max +# or _m4_min, and there must be at least two arguments to combine. +# +# Please keep foreach.m4 in sync with any adjustments made here. +m4_define([_m4_minmax], +[m4_if([$#], [3], [$1([$2], [$3])], + [$0([$1], $1([$2], [$3]), m4_shift3($@))])]) + + +# m4_sign(A) +# ---------- +# The sign of the integer expression A. +m4_define([m4_sign], +[m4_eval((([$1]) > 0) - (([$1]) < 0))]) + + + +## ------------------------ ## +## 14. Version processing. ## +## ------------------------ ## + + +# m4_version_unletter(VERSION) +# ---------------------------- +# Normalize beta version numbers with letters to numeric expressions, which +# can then be handed to m4_eval for the purpose of comparison. +# +# Nl -> (N+1).-1.(l#) +# +# for example: +# [2.14a] -> [0,2,14+1,-1,[0r36:a]] -> 2.15.-1.10 +# [2.14b] -> [0,2,15+1,-1,[0r36:b]] -> 2.15.-1.11 +# [2.61aa.b] -> [0,2.61,1,-1,[0r36:aa],+1,-1,[0r36:b]] -> 2.62.-1.370.1.-1.11 +# [08] -> [0,[0r10:0]8] -> 8 +# +# This macro expects reasonable version numbers, but can handle double +# letters and does not expand any macros. Original version strings can +# use both `.' and `-' separators. +# +# Inline constant expansions, to avoid m4_defn overhead. +# _m4_version_unletter is the real workhorse used by m4_version_compare, +# but since [0r36:a] and commas are less readable than 10 and dots, we +# provide a wrapper for human use. +m4_define([m4_version_unletter], +[m4_substr(m4_map_args([.m4_eval], m4_unquote(_$0([$1]))), [3])]) +m4_define([_m4_version_unletter], +[m4_bpatsubst(m4_bpatsubst(m4_translit([[[[0,$1]]]], [.-], [,,]),]dnl +m4_dquote(m4_dquote(m4_defn([m4_cr_Letters])))[[+], + [+1,-1,[0r36:\&]]), [,0], [,[0r10:0]])]) + + +# m4_version_compare(VERSION-1, VERSION-2) +# ---------------------------------------- +# Compare the two version numbers and expand into +# -1 if VERSION-1 < VERSION-2 +# 0 if = +# 1 if > +# +# Since _m4_version_unletter does not output side effects, we can +# safely bypass the overhead of m4_version_cmp. +m4_define([m4_version_compare], +[_m4_list_cmp_raw(_m4_version_unletter([$1]), _m4_version_unletter([$2]))]) + + +# m4_PACKAGE_NAME +# m4_PACKAGE_TARNAME +# m4_PACKAGE_VERSION +# m4_PACKAGE_STRING +# m4_PACKAGE_BUGREPORT +# -------------------- +# If m4sugar/version.m4 is present, then define version strings. This +# file is optional, provided by Autoconf but absent in Bison. +m4_sinclude([m4sugar/version.m4]) + + +# m4_version_prereq(VERSION, [IF-OK], [IF-NOT = FAIL]) +# ---------------------------------------------------- +# Check this Autoconf version against VERSION. +m4_define([m4_version_prereq], +m4_ifdef([m4_PACKAGE_VERSION], +[[m4_if(m4_version_compare(]m4_dquote(m4_defn([m4_PACKAGE_VERSION]))[, [$1]), + [-1], + [m4_default([$3], + [m4_fatal([Autoconf version $1 or higher is required], + [63])])], + [$2])]], +[[m4_fatal([m4sugar/version.m4 not found])]])) + + +## ------------------ ## +## 15. Set handling. ## +## ------------------ ## + +# Autoconf likes to create arbitrarily large sets; for example, as of +# this writing, the configure.ac for coreutils tracks a set of more +# than 400 AC_SUBST. How do we track all of these set members, +# without introducing duplicates? We could use m4_append_uniq, with +# the set NAME residing in the contents of the macro NAME. +# Unfortunately, m4_append_uniq is quadratic for set creation, because +# it costs O(n) to search the string for each of O(n) insertions; not +# to mention that with m4 1.4.x, even using m4_append is slow, costing +# O(n) rather than O(1) per insertion. Other set operations, not used +# by Autoconf but still possible by manipulation of the definition +# tracked in macro NAME, include O(n) deletion of one element and O(n) +# computation of set size. Because the set is exposed to the user via +# the definition of a single macro, we cannot cache any data about the +# set without risking the cache being invalidated by the user +# redefining NAME. +# +# Can we do better? Yes, because m4 gives us an O(1) search function +# for free: ifdef. Additionally, even m4 1.4.x gives us an O(1) +# insert operation for free: pushdef. But to use these, we must +# represent the set via a group of macros; to keep the set consistent, +# we must hide the set so that the user can only manipulate it through +# accessor macros. The contents of the set are maintained through two +# access points; _m4_set([name]) is a pushdef stack of values in the +# set, useful for O(n) traversal of the set contents; while the +# existence of _m4_set([name],value) with no particular value is +# useful for O(1) querying of set membership. And since the user +# cannot externally manipulate the set, we are free to add additional +# caching macros for other performance improvements. Deletion can be +# O(1) per element rather than O(n), by reworking the definition of +# _m4_set([name],value) to be 0 or 1 based on current membership, and +# adding _m4_set_cleanup(name) to defer the O(n) cleanup of +# _m4_set([name]) until we have another reason to do an O(n) +# traversal. The existence of _m4_set_cleanup(name) can then be used +# elsewhere to determine if we must dereference _m4_set([name],value), +# or assume that definition implies set membership. Finally, size can +# be tracked in an O(1) fashion with _m4_set_size(name). +# +# The quoting in _m4_set([name],value) is chosen so that there is no +# ambiguity with a set whose name contains a comma, and so that we can +# supply the value via _m4_defn([_m4_set([name])]) without needing any +# quote manipulation. + +# m4_set_add(SET, VALUE, [IF-UNIQ], [IF-DUP]) +# ------------------------------------------- +# Add VALUE as an element of SET. Expand IF-UNIQ on the first +# addition, and IF-DUP if it is already in the set. Addition of one +# element is O(1), such that overall set creation is O(n). +# +# We do not want to add a duplicate for a previously deleted but +# unpruned element, but it is just as easy to check existence directly +# as it is to query _m4_set_cleanup($1). +m4_define([m4_set_add], +[m4_ifdef([_m4_set([$1],$2)], + [m4_if(m4_indir([_m4_set([$1],$2)]), [0], + [m4_define([_m4_set([$1],$2)], + [1])_m4_set_size([$1], [m4_incr])$3], [$4])], + [m4_define([_m4_set([$1],$2)], + [1])m4_pushdef([_m4_set([$1])], + [$2])_m4_set_size([$1], [m4_incr])$3])]) + +# m4_set_add_all(SET, VALUE...) +# ----------------------------- +# Add each VALUE into SET. This is O(n) in the number of VALUEs, and +# can be faster than calling m4_set_add for each VALUE. +# +# Implement two recursion helpers; the check variant is slower but +# handles the case where an element has previously been removed but +# not pruned. The recursion helpers ignore their second argument, so +# that we can use the faster m4_shift2 and 2 arguments, rather than +# _m4_shift2 and one argument, as the signal to end recursion. +# +# Please keep foreach.m4 in sync with any adjustments made here. +m4_define([m4_set_add_all], +[m4_define([_m4_set_size($1)], m4_eval(m4_set_size([$1]) + + m4_len(m4_ifdef([_m4_set_cleanup($1)], [_$0_check], [_$0])([$1], $@))))]) + +m4_define([_m4_set_add_all], +[m4_if([$#], [2], [], + [m4_ifdef([_m4_set([$1],$3)], [], + [m4_define([_m4_set([$1],$3)], [1])m4_pushdef([_m4_set([$1])], + [$3])-])$0([$1], m4_shift2($@))])]) + +m4_define([_m4_set_add_all_check], +[m4_if([$#], [2], [], + [m4_set_add([$1], [$3])$0([$1], m4_shift2($@))])]) + +# m4_set_contains(SET, VALUE, [IF-PRESENT], [IF-ABSENT]) +# ------------------------------------------------------ +# Expand IF-PRESENT if SET contains VALUE, otherwise expand IF-ABSENT. +# This is always O(1). +m4_define([m4_set_contains], +[m4_ifdef([_m4_set_cleanup($1)], + [m4_if(m4_ifdef([_m4_set([$1],$2)], + [m4_indir([_m4_set([$1],$2)])], [0]), [1], [$3], [$4])], + [m4_ifdef([_m4_set([$1],$2)], [$3], [$4])])]) + +# m4_set_contents(SET, [SEP]) +# --------------------------- +# Expand to a single string containing all the elements in SET, +# separated by SEP, without modifying SET. No provision is made for +# disambiguating set elements that contain non-empty SEP as a +# sub-string, or for recognizing a set that contains only the empty +# string. Order of the output is not guaranteed. If any elements +# have been previously removed from the set, this action will prune +# the unused memory. This is O(n) in the size of the set before +# pruning. +# +# Use _m4_popdef for speed. The existence of _m4_set_cleanup($1) +# determines which version of _1 helper we use. +m4_define([m4_set_contents], +[m4_set_map_sep([$1], [], [], [[$2]])]) + +# _m4_set_contents_1(SET) +# _m4_set_contents_1c(SET) +# _m4_set_contents_2(SET, [PRE], [POST], [SEP]) +# --------------------------------------------- +# Expand to a list of quoted elements currently in the set, each +# surrounded by PRE and POST, and moving SEP in front of PRE on +# recursion. To avoid nesting limit restrictions, the algorithm must +# be broken into two parts; _1 destructively copies the stack in +# reverse into _m4_set_($1), producing no output; then _2 +# destructively copies _m4_set_($1) back into the stack in reverse. +# If no elements were deleted, then this visits the set in the order +# that elements were inserted. Behavior is undefined if PRE/POST/SEP +# tries to recursively list or modify SET in any way other than +# calling m4_set_remove on the current element. Use _1 if all entries +# in the stack are guaranteed to be in the set, and _1c to prune +# removed entries. Uses _m4_defn and _m4_popdef for speed. +m4_define([_m4_set_contents_1], +[_m4_stack_reverse([_m4_set([$1])], [_m4_set_($1)])]) + +m4_define([_m4_set_contents_1c], +[m4_ifdef([_m4_set([$1])], + [m4_set_contains([$1], _m4_defn([_m4_set([$1])]), + [m4_pushdef([_m4_set_($1)], _m4_defn([_m4_set([$1])]))], + [_m4_popdef([_m4_set([$1],]_m4_defn( + [_m4_set([$1])])[)])])_m4_popdef([_m4_set([$1])])$0([$1])], + [_m4_popdef([_m4_set_cleanup($1)])])]) + +m4_define([_m4_set_contents_2], +[_m4_stack_reverse([_m4_set_($1)], [_m4_set([$1])], + [$2[]_m4_defn([_m4_set_($1)])$3], [$4[]])]) + +# m4_set_delete(SET) +# ------------------ +# Delete all elements in SET, and reclaim any memory occupied by the +# set. This is O(n) in the set size. +# +# Use _m4_defn and _m4_popdef for speed. +m4_define([m4_set_delete], +[m4_ifdef([_m4_set([$1])], + [_m4_popdef([_m4_set([$1],]_m4_defn([_m4_set([$1])])[)], + [_m4_set([$1])])$0([$1])], + [m4_ifdef([_m4_set_cleanup($1)], + [_m4_popdef([_m4_set_cleanup($1)])])m4_ifdef( + [_m4_set_size($1)], + [_m4_popdef([_m4_set_size($1)])])])]) + +# m4_set_difference(SET1, SET2) +# ----------------------------- +# Produce a LIST of quoted elements that occur in SET1 but not SET2. +# Output a comma prior to any elements, to distinguish the empty +# string from no elements. This can be directly used as a series of +# arguments, such as for m4_join, or wrapped inside quotes for use in +# m4_foreach. Order of the output is not guaranteed. +# +# Short-circuit the idempotence relation. +m4_define([m4_set_difference], +[m4_if([$1], [$2], [], [m4_set_map_sep([$1], [_$0([$2],], [)])])]) + +m4_define([_m4_set_difference], +[m4_set_contains([$1], [$2], [], [,[$2]])]) + +# m4_set_dump(SET, [SEP]) +# ----------------------- +# Expand to a single string containing all the elements in SET, +# separated by SEP, then delete SET. In general, if you only need to +# list the contents once, this is faster than m4_set_contents. No +# provision is made for disambiguating set elements that contain +# non-empty SEP as a sub-string. Order of the output is not +# guaranteed. This is O(n) in the size of the set before pruning. +# +# Use _m4_popdef for speed. Use existence of _m4_set_cleanup($1) to +# decide if more expensive recursion is needed. +m4_define([m4_set_dump], +[m4_ifdef([_m4_set_size($1)], + [_m4_popdef([_m4_set_size($1)])])m4_ifdef([_m4_set_cleanup($1)], + [_$0_check], [_$0])([$1], [], [$2])]) + +# _m4_set_dump(SET, [SEP], [PREP]) +# _m4_set_dump_check(SET, [SEP], [PREP]) +# -------------------------------------- +# Print SEP and the current element, then delete the element and +# recurse with empty SEP changed to PREP. The check variant checks +# whether the element has been previously removed. Use _m4_defn and +# _m4_popdef for speed. +m4_define([_m4_set_dump], +[m4_ifdef([_m4_set([$1])], + [[$2]_m4_defn([_m4_set([$1])])_m4_popdef([_m4_set([$1],]_m4_defn( + [_m4_set([$1])])[)], [_m4_set([$1])])$0([$1], [$2$3])])]) + +m4_define([_m4_set_dump_check], +[m4_ifdef([_m4_set([$1])], + [m4_set_contains([$1], _m4_defn([_m4_set([$1])]), + [[$2]_m4_defn([_m4_set([$1])])])_m4_popdef( + [_m4_set([$1],]_m4_defn([_m4_set([$1])])[)], + [_m4_set([$1])])$0([$1], [$2$3])], + [_m4_popdef([_m4_set_cleanup($1)])])]) + +# m4_set_empty(SET, [IF-EMPTY], [IF-ELEMENTS]) +# -------------------------------------------- +# Expand IF-EMPTY if SET has no elements, otherwise IF-ELEMENTS. +m4_define([m4_set_empty], +[m4_ifdef([_m4_set_size($1)], + [m4_if(m4_indir([_m4_set_size($1)]), [0], [$2], [$3])], [$2])]) + +# m4_set_foreach(SET, VAR, ACTION) +# -------------------------------- +# For each element of SET, define VAR to the element and expand +# ACTION. ACTION should not recursively list SET's contents, add +# elements to SET, nor delete any element from SET except the one +# currently in VAR. The order that the elements are visited in is not +# guaranteed. This is faster than the corresponding m4_foreach([VAR], +# m4_indir([m4_dquote]m4_set_listc([SET])), [ACTION]) +m4_define([m4_set_foreach], +[m4_pushdef([$2])m4_set_map_sep([$1], +[m4_define([$2],], [)$3])m4_popdef([$2])]) + +# m4_set_intersection(SET1, SET2) +# ------------------------------- +# Produce a LIST of quoted elements that occur in both SET1 or SET2. +# Output a comma prior to any elements, to distinguish the empty +# string from no elements. This can be directly used as a series of +# arguments, such as for m4_join, or wrapped inside quotes for use in +# m4_foreach. Order of the output is not guaranteed. +# +# Iterate over the smaller set, and short-circuit the idempotence +# relation. +m4_define([m4_set_intersection], +[m4_if([$1], [$2], [m4_set_listc([$1])], + m4_eval(m4_set_size([$2]) < m4_set_size([$1])), [1], [$0([$2], [$1])], + [m4_set_map_sep([$1], [_$0([$2],], [)])])]) + +m4_define([_m4_set_intersection], +[m4_set_contains([$1], [$2], [,[$2]])]) + +# m4_set_list(SET) +# m4_set_listc(SET) +# ----------------- +# Produce a LIST of quoted elements of SET. This can be directly used +# as a series of arguments, such as for m4_join or m4_set_add_all, or +# wrapped inside quotes for use in m4_foreach or m4_map. With +# m4_set_list, there is no way to distinguish an empty set from a set +# containing only the empty string; with m4_set_listc, a leading comma +# is output if there are any elements. +m4_define([m4_set_list], +[m4_set_map_sep([$1], [], [], [,])]) + +m4_define([m4_set_listc], +[m4_set_map_sep([$1], [,])]) + +# m4_set_map(SET, ACTION) +# ----------------------- +# For each element of SET, expand ACTION with a single argument of the +# current element. ACTION should not recursively list SET's contents, +# add elements to SET, nor delete any element from SET except the one +# passed as an argument. The order that the elements are visited in +# is not guaranteed. This is faster than either of the corresponding +# m4_map_args([ACTION]m4_set_listc([SET])) +# m4_set_foreach([SET], [VAR], [ACTION(m4_defn([VAR]))]) +m4_define([m4_set_map], +[m4_set_map_sep([$1], [$2(], [)])]) + +# m4_set_map_sep(SET, [PRE], [POST], [SEP]) +# ----------------------------------------- +# For each element of SET, expand PRE[value]POST[], and expand SEP +# between elements. +m4_define([m4_set_map_sep], +[m4_ifdef([_m4_set_cleanup($1)], [_m4_set_contents_1c], + [_m4_set_contents_1])([$1])_m4_set_contents_2($@)]) + +# m4_set_remove(SET, VALUE, [IF-PRESENT], [IF-ABSENT]) +# ---------------------------------------------------- +# If VALUE is an element of SET, delete it and expand IF-PRESENT. +# Otherwise expand IF-ABSENT. Deleting a single value is O(1), +# although it leaves memory occupied until the next O(n) traversal of +# the set which will compact the set. +# +# Optimize if the element being removed is the most recently added, +# since defining _m4_set_cleanup($1) slows down so many other macros. +# In particular, this plays well with m4_set_foreach and m4_set_map. +m4_define([m4_set_remove], +[m4_set_contains([$1], [$2], [_m4_set_size([$1], + [m4_decr])m4_if(_m4_defn([_m4_set([$1])]), [$2], + [_m4_popdef([_m4_set([$1],$2)], [_m4_set([$1])])], + [m4_define([_m4_set_cleanup($1)])m4_define( + [_m4_set([$1],$2)], [0])])$3], [$4])]) + +# m4_set_size(SET) +# ---------------- +# Expand to the number of elements currently in SET. This operation +# is O(1), and thus more efficient than m4_count(m4_set_list([SET])). +m4_define([m4_set_size], +[m4_ifdef([_m4_set_size($1)], [m4_indir([_m4_set_size($1)])], [0])]) + +# _m4_set_size(SET, ACTION) +# ------------------------- +# ACTION must be either m4_incr or m4_decr, and the size of SET is +# changed accordingly. If the set is empty, ACTION must not be +# m4_decr. +m4_define([_m4_set_size], +[m4_define([_m4_set_size($1)], + m4_ifdef([_m4_set_size($1)], [$2(m4_indir([_m4_set_size($1)]))], + [1]))]) + +# m4_set_union(SET1, SET2) +# ------------------------ +# Produce a LIST of double quoted elements that occur in either SET1 +# or SET2, without duplicates. Output a comma prior to any elements, +# to distinguish the empty string from no elements. This can be +# directly used as a series of arguments, such as for m4_join, or +# wrapped inside quotes for use in m4_foreach. Order of the output is +# not guaranteed. +# +# We can rely on the fact that m4_set_listc prunes SET1, so we don't +# need to check _m4_set([$1],element) for 0. Short-circuit the +# idempotence relation. +m4_define([m4_set_union], +[m4_set_listc([$1])m4_if([$1], [$2], [], + [m4_set_map_sep([$2], [_$0([$1],], [)])])]) + +m4_define([_m4_set_union], +[m4_ifdef([_m4_set([$1],$2)], [], [,[$2]])]) + + +## ------------------- ## +## 16. File handling. ## +## ------------------- ## + + +# It is a real pity that M4 comes with no macros to bind a diversion +# to a file. So we have to deal without, which makes us a lot more +# fragile than we should. + + +# m4_file_append(FILE-NAME, CONTENT) +# ---------------------------------- +m4_define([m4_file_append], +[m4_syscmd([cat >>$1 <<_m4eof +$2 +_m4eof +]) +m4_if(m4_sysval, [0], [], + [m4_fatal([$0: cannot write: $1])])]) + + + +## ------------------------ ## +## 17. Setting M4sugar up. ## +## ------------------------ ## + +# _m4_divert_diversion should be defined. +m4_divert_push([KILL]) + +# m4_init +# ------- +# Initialize the m4sugar language. +m4_define([m4_init], +[# All the M4sugar macros start with `m4_', except `dnl' kept as is +# for sake of simplicity. +m4_pattern_forbid([^_?m4_]) +m4_pattern_forbid([^dnl$]) + +# If __m4_version__ is defined, we assume that we are being run by M4 +# 1.6 or newer, thus $@ recursion is linear, and debugmode(+do) +# is available for faster checks of dereferencing undefined macros +# and forcing dumpdef to print to stderr regardless of debugfile. +# But if it is missing, we assume we are being run by M4 1.4.x, that +# $@ recursion is quadratic, and that we need foreach-based +# replacement macros. Also, m4 prior to 1.4.8 loses track of location +# during m4wrap text; __line__ should never be 0. +# +# Use the raw builtin to avoid tripping up include tracing. +# Meanwhile, avoid m4_copy, since it temporarily undefines m4_defn. +m4_ifdef([__m4_version__], +[m4_debugmode([+do]) +m4_define([m4_defn], _m4_defn([_m4_defn])) +m4_define([m4_dumpdef], _m4_defn([_m4_dumpdef])) +m4_define([m4_popdef], _m4_defn([_m4_popdef])) +m4_define([m4_undefine], _m4_defn([_m4_undefine]))], +[m4_builtin([include], [m4sugar/foreach.m4]) +m4_wrap_lifo([m4_if(__line__, [0], [m4_pushdef([m4_location], +]]m4_dquote(m4_dquote(m4_dquote(__file__:__line__)))[[)])])]) + +# Rewrite the first entry of the diversion stack. +m4_divert([KILL]) + +# Check the divert push/pop perfect balance. +# Some users are prone to also use m4_wrap to register last-minute +# m4_divert_text; so after our diversion cleanups, we restore +# KILL as the bottom of the diversion stack. +m4_wrap([m4_popdef([_m4_divert_diversion])m4_ifdef( + [_m4_divert_diversion], [m4_fatal([$0: unbalanced m4_divert_push: +]m4_divert_stack)])_m4_popdef([_m4_divert_stack])m4_divert_push([KILL])]) +]) diff --git a/Engine/bin/bison-flex/data/skeletons/bison.m4 b/Engine/bin/bison-flex/data/skeletons/bison.m4 new file mode 100644 index 000000000..b7bf5c5c7 --- /dev/null +++ b/Engine/bin/bison-flex/data/skeletons/bison.m4 @@ -0,0 +1,1241 @@ + -*- Autoconf -*- + +# Language-independent M4 Macros for Bison. + +# Copyright (C) 2002, 2004-2015, 2018-2021 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + + +# m4_gsub(STRING, RE1, SUBST1, RE2, SUBST2, ...) +# ---------------------------------------------- +# m4 equivalent of +# +# $_ = STRING; +# s/RE1/SUBST1/g; +# s/RE2/SUBST2/g; +# ... +# +# Really similar to m4_bpatsubsts, but behaves properly with quotes. +# See m4.at's "Generating Comments". Super inelegant, but so far, I +# did not find any better solution. +m4_define([b4_gsub], +[m4_bpatsubst(m4_bpatsubst(m4_bpatsubst([[[[$1]]]], + [$2], [$3]), + [$4], [$5]), + [$6], [$7])]) + +# m4_shift2 and m4_shift3 are provided by m4sugar. +m4_define([m4_shift4], [m4_shift(m4_shift(m4_shift(m4_shift($@))))]) + + +## ---------------- ## +## Identification. ## +## ---------------- ## + +# b4_generated_by +# --------------- +m4_define([b4_generated_by], +[b4_comment([A Bison parser, made by GNU Bison b4_version_string.]) +]) + +# b4_copyright(TITLE, [YEARS]) +# ---------------------------- +# If YEARS are not defined, use b4_copyright_years. +m4_define([b4_copyright], +[b4_generated_by +b4_comment([$1 + +]m4_dquote(m4_text_wrap([Copyright (C) +]m4_ifval([$2], [[$2]], [m4_defn([b4_copyright_years])])[ +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 +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see .]) + +b4_comment([As a special exception, you may create a larger work that contains +part or all of the Bison parser skeleton and distribute that work +under terms of your choice, so long as that work isn't itself a +parser generator using the skeleton or a modified version thereof +as a parser skeleton. Alternatively, if you modify or redistribute +the parser skeleton itself, you may (at your option) remove this +special exception, which will cause the skeleton and the resulting +Bison output files to be licensed under the GNU General Public +License without this special exception. + +This special exception was added by the Free Software Foundation in +version 2.2 of Bison.]) +]) + + +# b4_disclaimer +# ------------- +# Issue a warning about private implementation details. +m4_define([b4_disclaimer], +[b4_comment([DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, +especially those whose name start with YY_ or yy_. They are +private implementation details that can be changed or removed.]) +]) + + + +# b4_required_version_if(VERSION, IF_NEWER, IF_OLDER) +# --------------------------------------------------- +# If the version %require'd by the user is VERSION (or newer) expand +# IF_NEWER, otherwise IF_OLDER. VERSION should be an integer, e.g., +# 302 for 3.2. +m4_define([b4_required_version_if], +[m4_if(m4_eval($1 <= b4_required_version), + [1], [$2], [$3])]) + + +## -------- ## +## Output. ## +## -------- ## + +# b4_output_begin(FILE1, FILE2) +# ----------------------------- +# Enable output, i.e., send to diversion 0, expand after "#", and +# generate the tag to output into FILE. Must be followed by EOL. +# FILE is FILE1 concatenated to FILE2. FILE2 can be empty, or be +# absolute: do the right thing. +m4_define([b4_output_begin], +[m4_changecom() +m4_divert_push(0)dnl +@output(m4_unquote([$1])@,m4_unquote([$2])@)@dnl +]) + + +# b4_output_end +# ------------- +# Output nothing, restore # as comment character (no expansions after #). +m4_define([b4_output_end], +[m4_divert_pop(0) +m4_changecom([#]) +]) + + +# b4_divert_kill(CODE) +# -------------------- +# Expand CODE for its side effects, discard its output. +m4_define([b4_divert_kill], +[m4_divert_text([KILL], [$1])]) + + +# b4_define_silent(MACRO, CODE) +# ----------------------------- +# Same as m4_define, but throw away the expansion of CODE. +m4_define([b4_define_silent], +[m4_define([$1], [b4_divert_kill([$2])])]) + + +## ---------------- ## +## Error handling. ## +## ---------------- ## + +# The following error handling macros print error directives that should not +# become arguments of other macro invocations since they would likely then be +# mangled. Thus, they print to stdout directly. + +# b4_cat(TEXT) +# ------------ +# Write TEXT to stdout. Precede the final newline with an @ so that it's +# escaped. For example: +# +# b4_cat([[@complain(invalid input@)]]) +m4_define([b4_cat], +[m4_syscmd([cat <<'_m4eof' +]m4_bpatsubst(m4_dquote($1), [_m4eof], [_m4@`eof])[@ +_m4eof +])dnl +m4_if(m4_sysval, [0], [], [m4_fatal([$0: cannot write to stdout])])]) + +# b4_error(KIND, START, END, FORMAT, [ARG1], [ARG2], ...) +# ------------------------------------------------------- +# Write @KIND(START@,END@,FORMAT@,ARG1@,ARG2@,...@) to stdout. +# +# For example: +# +# b4_error([[complain]], [[input.y:2.3]], [[input.y:5.4]], +# [[invalid %s]], [[foo]]) +m4_define([b4_error], +[b4_cat([[@complain][(]$1[@,]$2[@,]$3[@,]$4[]]dnl +[m4_if([$#], [4], [], + [m4_foreach([b4_arg], + m4_dquote(m4_shift4($@)), + [[@,]b4_arg])])[@)]])]) + +# b4_warn(FORMAT, [ARG1], [ARG2], ...) +# ------------------------------------ +# Write @warn(FORMAT@,ARG1@,ARG2@,...@) to stdout. +# +# For example: +# +# b4_warn([[invalid value for '%s': %s]], [[foo]], [[3]]) +# +# As a simple test suite, this: +# +# m4_divert(-1) +# m4_define([asdf], [ASDF]) +# m4_define([fsa], [FSA]) +# m4_define([fdsa], [FDSA]) +# b4_warn_at([[[asdf), asdf]]], [[[fsa), fsa]]], [[[fdsa), fdsa]]]) +# b4_warn_at([[asdf), asdf]], [[fsa), fsa]], [[fdsa), fdsa]]) +# b4_warn_at() +# b4_warn_at(1) +# b4_warn_at(1, 2) +# +# Should produce this without newlines: +# +# @warn_at([asdf), asdf]@,@,@,[fsa), fsa]@,[fdsa), fdsa]@) +# @warn(asdf), asdf@,@,@,fsa), fsa@,fdsa), fdsa@) +# @warn(@) +# @warn(1@) +# @warn(1@,2@) +m4_define([b4_warn], +[b4_warn_at([], [], $@)]) + +# b4_warn_at(START, END, FORMAT, [ARG1], [ARG2], ...) +# --------------------------------------------------- +# Write @warn(START@,END@,FORMAT@,ARG1@,ARG2@,...@) to stdout. +# +# For example: +# +# b4_warn_at([[input.y:2.3]], [[input.y:5.4]], [[invalid %s]], [[foo]]) +m4_define([b4_warn_at], +[b4_error([[warn]], $@)]) + +# b4_complain(FORMAT, [ARG1], [ARG2], ...) +# ---------------------------------------- +# Bounce to b4_complain_at. +# +# See b4_warn example. +m4_define([b4_complain], +[b4_complain_at([], [], $@)]) + +# b4_complain_at(START, END, FORMAT, [ARG1], [ARG2], ...) +# ------------------------------------------------------- +# Write @complain(START@,END@,FORMAT@,ARG1@,ARG2@,...@) to stdout. +# +# See b4_warn_at example. +m4_define([b4_complain_at], +[b4_error([[complain]], $@)]) + +# b4_fatal(FORMAT, [ARG1], [ARG2], ...) +# ------------------------------------- +# Bounce to b4_fatal_at. +# +# See b4_warn example. +m4_define([b4_fatal], +[b4_fatal_at([], [], $@)]) + +# b4_fatal_at(START, END, FORMAT, [ARG1], [ARG2], ...) +# ---------------------------------------------------- +# Write @fatal(START@,END@,FORMAT@,ARG1@,ARG2@,...@) to stdout and exit. +# +# See b4_warn_at example. +m4_define([b4_fatal_at], +[b4_error([[fatal]], $@)dnl +m4_exit(1)]) + +# b4_canary(MSG) +# -------------- +# Issue a warning on stderr and in the output. Used in the test suite +# to catch spurious m4 evaluations. +m4_define([b4_canary], +[m4_errprintn([dead canary: $1])DEAD CANARY($1)]) + + +## ------------ ## +## Data Types. ## +## ------------ ## + +# b4_ints_in(INT1, INT2, LOW, HIGH) +# --------------------------------- +# Return 1 iff both INT1 and INT2 are in [LOW, HIGH], 0 otherwise. +m4_define([b4_ints_in], +[m4_eval([$3 <= $1 && $1 <= $4 && $3 <= $2 && $2 <= $4])]) + + +# b4_subtract(LHS, RHS) +# --------------------- +# Evaluate LHS - RHS if they are integer literals, otherwise expand +# to (LHS) - (RHS). +m4_define([b4_subtract], +[m4_bmatch([$1$2], [^[0123456789]*$], + [m4_eval([$1 - $2])], + [($1) - ($2)])]) + +# b4_join(ARG1, ...) +# _b4_join(ARG1, ...) +# ------------------- +# Join with comma, skipping empty arguments. +# b4_join calls itself recursively until it sees the first non-empty +# argument, then calls _b4_join (i.e., `_$0`) which prepends each +# non-empty argument with a comma. +m4_define([b4_join], +[m4_if([$#$1], + [1], [], + [m4_ifval([$1], + [$1[]_$0(m4_shift($@))], + [$0(m4_shift($@))])])]) + +# _b4_join(ARGS1, ...) +# -------------------- +m4_define([_b4_join], +[m4_if([$#$1], + [1], [], + [m4_ifval([$1], [, $1])[]$0(m4_shift($@))])]) + + + + +# b4_integral_parser_tables_map(MACRO) +# ------------------------------------- +# Map MACRO on all the integral tables. MACRO is expected to have +# the signature MACRO(TABLE-NAME, CONTENT, COMMENT). +m4_define([b4_integral_parser_tables_map], +[$1([pact], [b4_pact], + [[YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing +STATE-NUM.]]) + +$1([defact], [b4_defact], + [[YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. +Performed when YYTABLE does not specify something else to do. Zero +means the default is an error.]]) + +$1([pgoto], [b4_pgoto], [[YYPGOTO[NTERM-NUM].]]) + +$1([defgoto], [b4_defgoto], [[YYDEFGOTO[NTERM-NUM].]]) + +$1([table], [b4_table], + [[YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If +positive, shift that token. If negative, reduce the rule whose +number is the opposite. If YYTABLE_NINF, syntax error.]]) + +$1([check], [b4_check]) + +$1([stos], [b4_stos], + [[YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of +state STATE-NUM.]]) + +$1([r1], [b4_r1], + [[YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM.]]) + +$1([r2], [b4_r2], + [[YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM.]]) +]) + + +# b4_parser_tables_declare +# b4_parser_tables_define +# ------------------------ +# Define/declare the (deterministic) parser tables. +m4_define([b4_parser_tables_declare], +[b4_integral_parser_tables_map([b4_integral_parser_table_declare])]) + +m4_define([b4_parser_tables_define], +[b4_integral_parser_tables_map([b4_integral_parser_table_define])]) + + + +## ------------------ ## +## Decoding options. ## +## ------------------ ## + +# b4_flag_if(FLAG, IF-TRUE, IF-FALSE) +# ----------------------------------- +# Run IF-TRUE if b4_FLAG_flag is 1, IF-FALSE if FLAG is 0, otherwise fail. +m4_define([b4_flag_if], +[m4_case(b4_$1_flag, + [0], [$3], + [1], [$2], + [m4_fatal([invalid $1 value: ]b4_$1_flag)])]) + + +# b4_define_flag_if(FLAG) +# ----------------------- +# Define "b4_FLAG_if(IF-TRUE, IF-FALSE)" that depends on the +# value of the Boolean FLAG. +m4_define([b4_define_flag_if], +[_b4_define_flag_if($[1], $[2], [$1])]) + +# _b4_define_flag_if($1, $2, FLAG) +# -------------------------------- +# Work around the impossibility to define macros inside macros, +# because issuing '[$1]' is not possible in M4. GNU M4 should provide +# $$1 a la M5/TeX. +m4_define([_b4_define_flag_if], +[m4_if([$1$2], $[1]$[2], [], + [m4_fatal([$0: Invalid arguments: $@])])dnl +m4_define([b4_$3_if], + [b4_flag_if([$3], [$1], [$2])])]) + + +# b4_FLAG_if(IF-TRUE, IF-FALSE) +# ----------------------------- +# Expand IF-TRUE, if FLAG is true, IF-FALSE otherwise. +b4_define_flag_if([glr]) # Whether a GLR parser is requested. +b4_define_flag_if([has_translations]) # Whether some tokens are internationalized. +b4_define_flag_if([header]) # Whether a header is requested. +b4_define_flag_if([nondeterministic]) # Whether conflicts should be handled. +b4_define_flag_if([token_table]) # Whether yytoken_table is demanded. +b4_define_flag_if([yacc]) # Whether POSIX Yacc is emulated. + + +# b4_glr_cc_if([IF-TRUE], [IF-FALSE]) +# ----------------------------------- +m4_define([b4_glr_cc_if], + [m4_if(b4_skeleton, ["glr.cc"], $@)]) + +# b4_glr2_cc_if([IF-TRUE], [IF-FALSE]) +# ------------------------------------ +m4_define([b4_glr2_cc_if], + [m4_if(b4_skeleton, ["glr2.cc"], $@)]) + +## --------- ## +## Symbols. ## +## --------- ## + +# For a description of the Symbol handling, see README.md. +# +# The following macros provide access to symbol related values. + +# __b4_symbol(NUM, FIELD) +# ----------------------- +# Fetch FIELD of symbol #NUM. Fail if undefined. +m4_define([__b4_symbol], +[m4_indir([b4_symbol($1, $2)])]) + + +# _b4_symbol(NUM, FIELD) +# ---------------------- +# Fetch FIELD of symbol #NUM (or "orig NUM", see README.md). +# Fail if undefined. +m4_define([_b4_symbol], +[m4_ifdef([b4_symbol($1, number)], + [__b4_symbol(m4_indir([b4_symbol($1, number)]), $2)], + [__b4_symbol([$1], [$2])])]) + + +# b4_symbol_token_kind(NUM) +# ------------------------- +# The token kind of this symbol. +m4_define([b4_symbol_token_kind], +[b4_percent_define_get([api.token.prefix])dnl +_b4_symbol([$1], [id])]) + + +# b4_symbol_kind_base(NUM) +# ------------------------ +# Build the name of the kind of this symbol. It must always exist, +# otherwise some symbols might not be represented in the enum, which +# might be compiled into too small a type to contain all the symbol +# numbers. +m4_define([b4_symbol_prefix], [b4_percent_define_get([api.symbol.prefix])]) +m4_define([b4_symbol_kind_base], +[b4_percent_define_get([api.symbol.prefix])dnl +m4_case([$1], + [-2], [[YYEMPTY]], + [0], [[YYEOF]], + [1], [[YYerror]], + [2], [[YYUNDEF]], + [m4_case(b4_symbol([$1], [tag]), + [$accept], [[YYACCEPT]], + [b4_symbol_if([$1], [has_id], _b4_symbol([$1], [id]), + [m4_bpatsubst([$1-][]_b4_symbol([$1], [tag]), [[^a-zA-Z_0-9]+], [_])])])])]) + + +# b4_symbol_kind(NUM) +# ------------------- +# Same as b4_symbol_kind, but possibly with a prefix in some +# languages. E.g., EOF's kind_base and kind are YYSYMBOL_YYEOF in C, +# but are S_YYEMPTY and symbol_kind::S_YYEMPTY in C++. +m4_copy([b4_symbol_kind_base], [b4_symbol_kind]) + + +# b4_symbol_slot(NUM) +# ------------------- +# The name of union member that contains the value of these symbols. +# Currently, we are messy, this should actually be type_tag, but type_tag +# has several meanings. +m4_define([b4_symbol_slot], +[m4_case(b4_percent_define_get([[api.value.type]]), + [union], [b4_symbol([$1], [type_tag])], + [variant], [b4_symbol([$1], [type_tag])], + [b4_symbol([$1], [type])])]) + + +# b4_symbol(NUM, FIELD) +# --------------------- +# Fetch FIELD of symbol #NUM (or "orig NUM", or "empty"). Fail if undefined. +# +# If FIELD = id, prepend the token prefix. +m4_define([b4_symbol], +[m4_if([$1], [empty], [b4_symbol([-2], [$2])], + [$1], [eof], [b4_symbol([0], [$2])], + [$1], [error], [b4_symbol([1], [$2])], + [$1], [undef], [b4_symbol([2], [$2])], + [m4_case([$2], + [id], [b4_symbol_token_kind([$1])], + [kind_base], [b4_symbol_kind_base([$1])], + [kind], [b4_symbol_kind([$1])], + [slot], [b4_symbol_slot([$1])], + [_b4_symbol($@)])])]) + + +# b4_symbol_if(NUM, FIELD, IF-TRUE, IF-FALSE) +# ------------------------------------------- +# If FIELD about symbol #NUM is 1 expand IF-TRUE, if is 0, expand IF-FALSE. +# Otherwise an error. +m4_define([b4_symbol_if], +[m4_case(b4_symbol([$1], [$2]), + [1], [$3], + [0], [$4], + [m4_fatal([$0: field $2 of $1 is not a Boolean:] b4_symbol([$1], [$2]))])]) + + +# b4_symbol_tag_comment(SYMBOL-NUM) +# --------------------------------- +# Issue a comment giving the tag of symbol NUM. +m4_define([b4_symbol_tag_comment], +[b4_comment([b4_symbol([$1], [tag])]) +]) + + +# b4_symbol_action(SYMBOL-NUM, ACTION) +# ------------------------------------ +# Run the action ACTION ("destructor" or "printer") for SYMBOL-NUM. +m4_define([b4_symbol_action], +[b4_symbol_if([$1], [has_$2], +[b4_dollar_pushdef([(*yyvaluep)], + [$1], + [], + [(*yylocationp)])dnl + _b4_symbol_case([$1])[]dnl +b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl +b4_symbol([$1], [$2]) +b4_syncline([@oline@], [@ofile@])dnl + break; + +b4_dollar_popdef[]dnl +])]) + + +# b4_symbol_destructor(SYMBOL-NUM) +# b4_symbol_printer(SYMBOL-NUM) +# -------------------------------- +m4_define([b4_symbol_destructor], [b4_symbol_action([$1], [destructor])]) +m4_define([b4_symbol_printer], [b4_symbol_action([$1], [printer])]) + + +# b4_symbol_actions(ACTION, [KIND = yykind]) +# ------------------------------------------ +# Emit the symbol actions for ACTION ("destructor" or "printer"). +# Dispatch on KIND. +m4_define([b4_symbol_actions], +[m4_pushdef([b4_actions_], m4_expand([b4_symbol_foreach([b4_symbol_$1])]))dnl +m4_ifval(m4_defn([b4_actions_]), +[switch (m4_default([$2], [yykind])) + { +m4_defn([b4_actions_])[]dnl + default: + break; + }dnl +], +[b4_use(m4_default([$2], [yykind]));])dnl +m4_popdef([b4_actions_])dnl +]) + +# _b4_symbol_case(SYMBOL-NUM) +# --------------------------- +# Issue a "case NUM" for SYMBOL-NUM. Ends with its EOL to make it +# easier to use with m4_map, but then, use []dnl to suppress the last +# one. +m4_define([_b4_symbol_case], +[case b4_symbol([$1], [kind]): b4_symbol_tag_comment([$1])]) +]) + + +# b4_symbol_foreach(MACRO) +# ------------------------ +# Invoke MACRO(SYMBOL-NUM) for each SYMBOL-NUM. +m4_define([b4_symbol_foreach], + [m4_map([$1], m4_defn([b4_symbol_numbers]))]) + +# b4_symbol_map(MACRO) +# -------------------- +# Return a list (possibly empty elements) of MACRO invoked for each +# SYMBOL-NUM. +m4_define([b4_symbol_map], +[m4_map_args_sep([$1(], [)], [,], b4_symbol_numbers)]) + + +# b4_token_visible_if(NUM, IF-TRUE, IF-FALSE) +# ------------------------------------------- +# Whether NUM denotes a token kind that has an exported definition +# (i.e., shows in enum yytokentype). +m4_define([b4_token_visible_if], +[b4_symbol_if([$1], [is_token], + [b4_symbol_if([$1], [has_id], [$2], [$3])], + [$3])]) + + +# b4_token_has_definition(NUM) +# ---------------------------- +# 1 if NUM is visible, nothing otherwise. +m4_define([b4_token_has_definition], +[b4_token_visible_if([$1], [1])]) + +# b4_any_token_visible_if([IF-TRUE], [IF-FALSE]) +# ---------------------------------------------- +# Whether there is a token that needs to be defined. +m4_define([b4_any_token_visible_if], +[m4_ifval(b4_symbol_foreach([b4_token_has_definition]), + [$1], [$2])]) + + +# b4_token_format(FORMAT, NUM) +# ---------------------------- +# If token NUM has a visible ID, format FORMAT with ID, USER_NUMBER. +m4_define([b4_token_format], +[b4_token_visible_if([$2], +[m4_format([[$1]], + b4_symbol([$2], [id]), + b4_symbol([$2], b4_api_token_raw_if([[number]], [[code]])))])]) + + +# b4_last_enum_token +# ------------------ +# The code of the last token visible token. +m4_define([_b4_last_enum_token], +[b4_token_visible_if([$1], + [m4_define([b4_last_enum_token], [$1])])]) +b4_symbol_foreach([_b4_last_enum_token]) + +# b4_last_symbol +# -------------- +# The code of the last symbol. +m4_define([b4_last_symbol], m4_eval(b4_tokens_number + b4_nterms_number - 1)) + +## ------- ## +## Types. ## +## ------- ## + +# _b4_type_action(NUMS) +# --------------------- +# Run actions for the symbol NUMS that all have the same type-name. +# Skip NUMS that have no type-name. +# +# To specify the action to run, define b4_dollar_dollar(SYMBOL-NUM, +# TAG, TYPE). +m4_define([_b4_type_action], +[b4_symbol_if([$1], [has_type], +[m4_map([ _b4_symbol_case], [$@])[]dnl + b4_dollar_dollar([b4_symbol([$1], [number])], + [b4_symbol([$1], [tag])], + [b4_symbol([$1], [type])]); + break; + +])]) + +# b4_type_foreach(MACRO, [SEP]) +# ----------------------------- +# Invoke MACRO(SYMBOL-NUMS) for each set of SYMBOL-NUMS for each type set. +m4_define([b4_type_foreach], + [m4_map_sep([$1], [$2], m4_defn([b4_type_names]))]) + + + +## ----------- ## +## Synclines. ## +## ----------- ## + +# b4_basename(NAME) +# ----------------- +# Similar to POSIX basename; the differences don't matter here. +# Beware that NAME is not evaluated. +m4_define([b4_basename], +[m4_bpatsubst([$1], [^.*/\([^/]+\)/*$], [\1])]) + + +# b4_syncline(LINE, FILE)dnl +# -------------------------- +# Should always be following by a dnl. +# +# Emit "#line LINE FILE /* __LINE__ __FILE__ */". +m4_define([b4_syncline], +[b4_flag_if([synclines], +[b4_sync_start([$1], [$2])[]dnl +b4_sync_end([__line__], [b4_basename(m4_quote(__file__))]) +])]) + +# b4_sync_start(LINE, FILE) +# ----------------------- +# Syncline for the new place. Typically a directive for the compiler. +m4_define([b4_sync_start], [b4_comment([$2:$1])]) + +# b4_sync_end(LINE, FILE) +# ----------------------- +# Syncline for the current place, which ends. Typically a comment +# left for the reader. +m4_define([b4_sync_end], [ b4_comment([$2:$1])] +) +# This generates dependencies on the Bison skeletons hence lots of +# useless 'git diff'. This location is useless for the regular +# user (who does not care about the skeletons) and is actually not +# useful for Bison developers too (I, Akim, never used this to locate +# the code in skeletons that generated output). So disable it +# completely. If someone thinks this was actually useful, a %define +# variable should be provided to control the level of verbosity of +# '#line', in replacement of --no-lines. +m4_define([b4_sync_end]) + + +# b4_user_code(USER-CODE) +# ----------------------- +# Emit code from the user, ending it with synclines. +m4_define([b4_user_code], +[$1 +b4_syncline([@oline@], [@ofile@])]) + + +# b4_define_user_code(MACRO, COMMENT) +# ----------------------------------- +# From b4_MACRO, if defined, build b4_user_MACRO that includes the synclines. +m4_define([b4_define_user_code], +[m4_define([b4_user_$1], + [m4_ifdef([b4_$1], + [m4_ifval([$2], + [b4_comment([$2]) +])b4_user_code([b4_$1])])])]) + +# b4_user_actions +# b4_user_initial_action +# b4_user_post_prologue +# b4_user_pre_prologue +# b4_user_union_members +# ---------------------- +# Macros that issue user code, ending with synclines. +b4_define_user_code([actions]) +b4_define_user_code([initial_action], [User initialization code.]) +b4_define_user_code([post_prologue], [Second part of user prologue.]) +b4_define_user_code([pre_prologue], [First part of user prologue.]) +b4_define_user_code([union_members]) + + +# b4_check_user_names(WHAT, USER-LIST, BISON-NAMESPACE) +# ----------------------------------------------------- +# Complain if any name of type WHAT is used by the user (as recorded in +# USER-LIST) but is not used by Bison (as recorded by macros in the +# namespace BISON-NAMESPACE). +# +# USER-LIST must expand to a list specifying all user occurrences of all names +# of type WHAT. Each item in the list must be a triplet specifying one +# occurrence: name, start boundary, and end boundary. Empty string names are +# fine. An empty list is fine. +# +# For example, to define b4_foo_user_names to be used for USER-LIST with three +# name occurrences and with correct quoting: +# +# m4_define([b4_foo_user_names], +# [[[[[[bar]], [[parser.y:1.7]], [[parser.y:1.16]]]], +# [[[[bar]], [[parser.y:5.7]], [[parser.y:5.16]]]], +# [[[[baz]], [[parser.y:8.7]], [[parser.y:8.16]]]]]]) +# +# The macro BISON-NAMESPACE(bar) must be defined iff the name bar of type WHAT +# is used by Bison (in the front-end or in the skeleton). Empty string names +# are fine, but it would be ugly for Bison to actually use one. +# +# For example, to use b4_foo_bison_names for BISON-NAMESPACE and define that +# the names bar and baz are used by Bison: +# +# m4_define([b4_foo_bison_names(bar)]) +# m4_define([b4_foo_bison_names(baz)]) +# +# To invoke b4_check_user_names with TYPE foo, with USER-LIST +# b4_foo_user_names, with BISON-NAMESPACE b4_foo_bison_names, and with correct +# quoting: +# +# b4_check_user_names([[foo]], [b4_foo_user_names], +# [[b4_foo_bison_names]]) +m4_define([b4_check_user_names], +[m4_foreach([b4_occurrence], $2, +[m4_pushdef([b4_occurrence], b4_occurrence)dnl +m4_pushdef([b4_user_name], m4_car(b4_occurrence))dnl +m4_pushdef([b4_start], m4_car(m4_shift(b4_occurrence)))dnl +m4_pushdef([b4_end], m4_shift2(b4_occurrence))dnl +m4_ifndef($3[(]m4_quote(b4_user_name)[)], + [b4_complain_at([b4_start], [b4_end], + [[%s '%s' is not used]], + [$1], [b4_user_name])])[]dnl +m4_popdef([b4_occurrence])dnl +m4_popdef([b4_user_name])dnl +m4_popdef([b4_start])dnl +m4_popdef([b4_end])dnl +])]) + + + +## --------------------- ## +## b4_percent_define_*. ## +## --------------------- ## + + +# b4_percent_define_use(VARIABLE) +# ------------------------------- +# Declare that VARIABLE was used. +m4_define([b4_percent_define_use], +[m4_define([b4_percent_define_bison_variables(]$1[)])dnl +]) + +# b4_percent_define_get(VARIABLE, [DEFAULT]) +# ------------------------------------------ +# Mimic muscle_percent_define_get in ../src/muscle-tab.h. That is, if +# the %define variable VARIABLE is defined, emit its value. Contrary +# to its C counterpart, return DEFAULT otherwise. Also, record +# Bison's usage of VARIABLE by defining +# b4_percent_define_bison_variables(VARIABLE). +# +# For example: +# +# b4_percent_define_get([[foo]]) +m4_define([b4_percent_define_get], +[b4_percent_define_use([$1])dnl +_b4_percent_define_ifdef([$1], + [m4_indir([b4_percent_define(]$1[)])], + [$2])]) + +# b4_percent_define_get_loc(VARIABLE) +# ----------------------------------- +# Mimic muscle_percent_define_get_loc in ../src/muscle-tab.h exactly. That is, +# if the %define variable VARIABLE is undefined, complain fatally since that's +# a Bison or skeleton error. Otherwise, return its definition location in a +# form appropriate for the first two arguments of b4_warn_at, b4_complain_at, or +# b4_fatal_at. Don't record this as a Bison usage of VARIABLE as there's no +# reason to suspect that the user-supplied value has yet influenced the output. +# +# For example: +# +# b4_complain_at(b4_percent_define_get_loc([[foo]]), [[invalid foo]]) +m4_define([b4_percent_define_get_loc], +[m4_ifdef([b4_percent_define_loc(]$1[)], + [m4_pushdef([b4_loc], m4_indir([b4_percent_define_loc(]$1[)]))dnl +b4_loc[]dnl +m4_popdef([b4_loc])], + [b4_fatal([[$0: undefined %%define variable '%s']], [$1])])]) + +# b4_percent_define_get_kind(VARIABLE) +# ------------------------------------ +# Get the kind (code, keyword, string) of VARIABLE, i.e., how its +# value was defined (braces, not delimiters, quotes). +# +# If the %define variable VARIABLE is undefined, complain fatally +# since that's a Bison or skeleton error. Don't record this as a +# Bison usage of VARIABLE as there's no reason to suspect that the +# user-supplied value has yet influenced the output. +m4_define([b4_percent_define_get_kind], +[m4_ifdef([b4_percent_define_kind(]$1[)], + [m4_indir([b4_percent_define_kind(]$1[)])], + [b4_fatal([[$0: undefined %%define variable '%s']], [$1])])]) + +# b4_percent_define_get_syncline(VARIABLE)dnl +# ------------------------------------------- +# Should always be following by a dnl. +# +# Mimic muscle_percent_define_get_syncline in ../src/muscle-tab.h exactly. +# That is, if the %define variable VARIABLE is undefined, complain fatally +# since that's a Bison or skeleton error. Otherwise, return its definition +# location as a b4_syncline invocation. Don't record this as a Bison usage of +# VARIABLE as there's no reason to suspect that the user-supplied value has yet +# influenced the output. +# +# For example: +# +# b4_percent_define_get_syncline([[foo]]) +m4_define([b4_percent_define_get_syncline], +[m4_ifdef([b4_percent_define_syncline(]$1[)], + [m4_indir([b4_percent_define_syncline(]$1[)])], + [b4_fatal([[$0: undefined %%define variable '%s']], [$1])])]) + +# _b4_percent_define_ifdef(VARIABLE, IF-TRUE, [IF-FALSE]) +# ------------------------------------------------------ +# If the %define variable VARIABLE is defined, expand IF-TRUE, else expand +# IF-FALSE. Don't record usage of VARIABLE. +# +# For example: +# +# _b4_percent_define_ifdef([[foo]], [[it's defined]], [[it's undefined]]) +m4_define([_b4_percent_define_ifdef], +[m4_ifdef([b4_percent_define(]$1[)], + [$2], + [$3])]) + +# b4_percent_define_ifdef(VARIABLE, IF-TRUE, [IF-FALSE]) +# ------------------------------------------------------ +# Mimic muscle_percent_define_ifdef in ../src/muscle-tab.h exactly. That is, +# if the %define variable VARIABLE is defined, expand IF-TRUE, else expand +# IF-FALSE. Also, record Bison's usage of VARIABLE by defining +# b4_percent_define_bison_variables(VARIABLE). +# +# For example: +# +# b4_percent_define_ifdef([[foo]], [[it's defined]], [[it's undefined]]) +m4_define([b4_percent_define_ifdef], +[_b4_percent_define_ifdef([$1], + [b4_percent_define_use([$1])$2], + [$3])]) + + +# b4_percent_define_check_file_complain(VARIABLE) +# ----------------------------------------------- +# Warn about %define variable VARIABLE having an incorrect +# value. +m4_define([b4_percent_define_check_file_complain], +[b4_complain_at(b4_percent_define_get_loc([$1]), + [[%%define variable '%s' requires 'none' or '"..."' values]], + [$1])]) + + +# b4_percent_define_check_file(MACRO, VARIABLE, DEFAULT) +# ------------------------------------------------------ +# If the %define variable VARIABLE: +# - is undefined, then if DEFAULT is non-empty, define MACRO to DEFAULT +# - is a string, define MACRO to its value +# - is the keyword 'none', do nothing +# - otherwise, warn about the incorrect value. +m4_define([b4_percent_define_check_file], +[b4_percent_define_ifdef([$2], + [m4_case(b4_percent_define_get_kind([$2]), + [string], + [m4_define([$1], b4_percent_define_get([$2]))], + [keyword], + [m4_if(b4_percent_define_get([$2]), [none], [], + [b4_percent_define_check_file_complain([$2])])], + [b4_percent_define_check_file_complain([$2])]) + ], + [m4_ifval([$3], + [m4_define([$1], [$3])])]) +]) + + + +## --------- ## +## Options. ## +## --------- ## + + +# b4_percent_define_flag_if(VARIABLE, IF-TRUE, [IF-FALSE]) +# -------------------------------------------------------- +# Mimic muscle_percent_define_flag_if in ../src/muscle-tab.h exactly. That is, +# if the %define variable VARIABLE is defined to "" or "true", expand IF-TRUE. +# If it is defined to "false", expand IF-FALSE. Complain if it is undefined +# (a Bison or skeleton error since the default value should have been set +# already) or defined to any other value (possibly a user error). Also, record +# Bison's usage of VARIABLE by defining +# b4_percent_define_bison_variables(VARIABLE). +# +# For example: +# +# b4_percent_define_flag_if([[foo]], [[it's true]], [[it's false]]) +m4_define([b4_percent_define_flag_if], +[b4_percent_define_ifdef([$1], + [m4_case(b4_percent_define_get([$1]), + [], [$2], [true], [$2], [false], [$3], + [m4_expand_once([b4_complain_at(b4_percent_define_get_loc([$1]), + [[invalid value for %%define Boolean variable '%s']], + [$1])], + [[b4_percent_define_flag_if($1)]])])], + [b4_fatal([[$0: undefined %%define variable '%s']], [$1])])]) + + +# b4_percent_define_default(VARIABLE, DEFAULT, [KIND = keyword]) +# -------------------------------------------------------------- +# Mimic muscle_percent_define_default in ../src/muscle-tab.h exactly. That is, +# if the %define variable VARIABLE is undefined, set its value to DEFAULT. +# Don't record this as a Bison usage of VARIABLE as there's no reason to +# suspect that the value has yet influenced the output. +# +# For example: +# +# b4_percent_define_default([[foo]], [[default value]]) +m4_define([_b4_percent_define_define], +[m4_define([b4_percent_define(]$1[)], [$2])dnl +m4_define([b4_percent_define_kind(]$1[)], + [m4_default([$3], [keyword])])dnl +m4_define([b4_percent_define_loc(]$1[)], + [[[[:-1.-1]], + [[:-1.-1]]]])dnl +m4_define([b4_percent_define_syncline(]$1[)], [[]])]) + +m4_define([b4_percent_define_default], +[_b4_percent_define_ifdef([$1], [], + [_b4_percent_define_define($@)])]) + + +# b4_percent_define_if_define(NAME, [VARIABLE = NAME]) +# ---------------------------------------------------- +# Define b4_NAME_if that executes its $1 or $2 depending whether +# VARIABLE was %defined. The characters '.' and `-' in VARIABLE are mapped +# to '_'. +m4_define([_b4_percent_define_if_define], +[m4_define(m4_bpatsubst([b4_$1_if], [[-.]], [_]), + [b4_percent_define_default([m4_default([$2], [$1])], [[false]])dnl +b4_percent_define_flag_if(m4_default([$2], [$1]), + [$3], [$4])])]) + +m4_define([b4_percent_define_if_define], +[_b4_percent_define_if_define([$1], [$2], $[1], $[2])]) + + +# b4_percent_define_check_kind(VARIABLE, KIND, [DIAGNOSTIC = complain]) +# --------------------------------------------------------------------- +m4_define([b4_percent_define_check_kind], +[_b4_percent_define_ifdef([$1], + [m4_if(b4_percent_define_get_kind([$1]), [$2], [], + [b4_error([m4_default([$3], [complain])], + b4_percent_define_get_loc([$1]), + [m4_case([$2], + [code], [[%%define variable '%s' requires '{...}' values]], + [keyword], [[%%define variable '%s' requires keyword values]], + [string], [[%%define variable '%s' requires '"..."' values]])], + [$1])])])dnl +]) + + +# b4_percent_define_check_values(VALUES) +# -------------------------------------- +# Mimic muscle_percent_define_check_values in ../src/muscle-tab.h exactly +# except that the VALUES structure is more appropriate for M4. That is, VALUES +# is a list of sublists of strings. For each sublist, the first string is the +# name of a %define variable, and all remaining strings in that sublist are the +# valid values for that variable. Complain if such a variable is undefined (a +# Bison error since the default value should have been set already) or defined +# to any other value (possibly a user error). Don't record this as a Bison +# usage of the variable as there's no reason to suspect that the value has yet +# influenced the output. +# +# For example: +# +# b4_percent_define_check_values([[[[foo]], [[foo-value1]], [[foo-value2]]]], +# [[[[bar]], [[bar-value1]]]]) +m4_define([b4_percent_define_check_values], +[m4_foreach([b4_sublist], m4_quote($@), + [_b4_percent_define_check_values(b4_sublist)])]) + +m4_define([_b4_percent_define_check_values], +[_b4_percent_define_ifdef([$1], + [b4_percent_define_check_kind(]$1[, [keyword], [deprecated])dnl + m4_pushdef([b4_good_value], [0])dnl + m4_if($#, 1, [], + [m4_foreach([b4_value], m4_dquote(m4_shift($@)), + [m4_if(m4_indir([b4_percent_define(]$1[)]), b4_value, + [m4_define([b4_good_value], [1])])])])dnl + m4_if(b4_good_value, [0], + [b4_complain_at(b4_percent_define_get_loc([$1]), + [[invalid value for %%define variable '%s': '%s']], + [$1], + m4_dquote(m4_indir([b4_percent_define(]$1[)]))) + m4_foreach([b4_value], m4_dquote(m4_shift($@)), + [b4_error([[note]], b4_percent_define_get_loc([$1]), [] + [[accepted value: '%s']], + m4_dquote(b4_value))])])dnl + m4_popdef([b4_good_value])], + [b4_fatal([[$0: undefined %%define variable '%s']], [$1])])]) + +# b4_percent_code_get([QUALIFIER]) +# -------------------------------- +# If any %code blocks for QUALIFIER are defined, emit them beginning with a +# comment and ending with synclines and a newline. If QUALIFIER is not +# specified or empty, do this for the unqualified %code blocks. Also, record +# Bison's usage of QUALIFIER (if specified) by defining +# b4_percent_code_bison_qualifiers(QUALIFIER). +# +# For example, to emit any unqualified %code blocks followed by any %code +# blocks for the qualifier foo: +# +# b4_percent_code_get +# b4_percent_code_get([[foo]]) +m4_define([b4_percent_code_get], +[m4_pushdef([b4_macro_name], [[b4_percent_code(]$1[)]])dnl +m4_ifval([$1], [m4_define([b4_percent_code_bison_qualifiers(]$1[)])])dnl +m4_ifdef(b4_macro_name, +[b4_comment(m4_if([$#], [0], [[[Unqualified %code blocks.]]], + [[["%code ]$1[" blocks.]]])) +b4_user_code([m4_indir(b4_macro_name)])])dnl +m4_popdef([b4_macro_name])]) + +# b4_percent_code_ifdef(QUALIFIER, IF-TRUE, [IF-FALSE]) +# ----------------------------------------------------- +# If any %code blocks for QUALIFIER (or unqualified %code blocks if +# QUALIFIER is empty) are defined, expand IF-TRUE, else expand IF-FALSE. +# Also, record Bison's usage of QUALIFIER (if specified) by defining +# b4_percent_code_bison_qualifiers(QUALIFIER). +m4_define([b4_percent_code_ifdef], +[m4_ifdef([b4_percent_code(]$1[)], + [m4_ifval([$1], [m4_define([b4_percent_code_bison_qualifiers(]$1[)])])$2], + [$3])]) + + +## ------------------ ## +## Common variables. ## +## ------------------ ## + + +# b4_parse_assert_if([IF-ASSERTIONS-ARE-USED], [IF-NOT]) +# b4_parse_trace_if([IF-DEBUG-TRACES-ARE-ENABLED], [IF-NOT]) +# b4_token_ctor_if([IF-YYLEX-RETURNS-A-TOKEN], [IF-NOT]) +# ---------------------------------------------------------- +b4_percent_define_if_define([api.token.raw]) +b4_percent_define_if_define([token_ctor], [api.token.constructor]) +b4_percent_define_if_define([locations]) # Whether locations are tracked. +b4_percent_define_if_define([parse.assert]) +b4_percent_define_if_define([parse.trace]) +b4_percent_define_if_define([posix]) + + +# b4_bison_locations_if([IF-TRUE]) +# -------------------------------- +# Expand IF-TRUE if using locations, and using the default location +# type. +m4_define([b4_bison_locations_if], +[b4_locations_if([b4_percent_define_ifdef([[api.location.type]], [], [$1])])]) + + + +# %define parse.error "(custom|detailed|simple|verbose)" +# ------------------------------------------------------ +b4_percent_define_default([[parse.error]], [[simple]]) +b4_percent_define_check_values([[[[parse.error]], + [[custom]], [[detailed]], [[simple]], [[verbose]]]]) + +# b4_parse_error_case(CASE1, THEN1, CASE2, THEN2, ..., ELSE) +# ---------------------------------------------------------- +m4_define([b4_parse_error_case], +[m4_case(b4_percent_define_get([[parse.error]]), $@)]) + +# b4_parse_error_bmatch(PATTERN1, THEN1, PATTERN2, THEN2, ..., ELSE) +# ------------------------------------------------------------------ +m4_define([b4_parse_error_bmatch], +[m4_bmatch(b4_percent_define_get([[parse.error]]), $@)]) + + + +# b4_union_if([IF-UNION-ARE-USED], [IF-NOT]) +# b4_variant_if([IF-VARIANT-ARE-USED], [IF-NOT]) +# ---------------------------------------------- +# Depend on whether api.value.type is union, or variant. +m4_define([b4_union_flag], [[0]]) +m4_define([b4_variant_flag], [[0]]) +b4_percent_define_ifdef([[api.value.type]], + [m4_case(b4_percent_define_get_kind([[api.value.type]]), [keyword], + [m4_case(b4_percent_define_get([[api.value.type]]), + [union], [m4_define([b4_union_flag], [[1]])], + [variant], [m4_define([b4_variant_flag], [[1]])])])]) +b4_define_flag_if([union]) +b4_define_flag_if([variant]) + + +## ----------------------------------------------------------- ## +## After processing the skeletons, check that all the user's ## +## %define variables and %code qualifiers were used by Bison. ## +## ----------------------------------------------------------- ## + +m4_define([b4_check_user_names_wrap], +[m4_ifdef([b4_percent_]$1[_user_]$2[s], + [b4_check_user_names([[%]$1 $2], + [b4_percent_]$1[_user_]$2[s], + [[b4_percent_]$1[_bison_]$2[s]])])]) + +m4_wrap_lifo([ +b4_check_user_names_wrap([[define]], [[variable]]) +b4_check_user_names_wrap([[code]], [[qualifier]]) +]) + + +## ---------------- ## +## Default values. ## +## ---------------- ## + +# m4_define_default([b4_lex_param], []) dnl breaks other skeletons +m4_define_default([b4_epilogue], []) +m4_define_default([b4_parse_param], []) + +# The initial column and line. +m4_define_default([b4_location_initial_column], [1]) +m4_define_default([b4_location_initial_line], [1]) + + +## --------------- ## +## Sanity checks. ## +## --------------- ## + +# api.location.type={...} (C, C++ and Java). +b4_percent_define_check_kind([api.location.type], [code], [deprecated]) + +# api.position.type={...} (Java). +b4_percent_define_check_kind([api.position.type], [code], [deprecated]) + +# api.prefix >< %name-prefix. +b4_percent_define_check_kind([api.prefix], [code], [deprecated]) +b4_percent_define_ifdef([api.prefix], +[m4_ifdef([b4_prefix], +[b4_complain_at(b4_percent_define_get_loc([api.prefix]), + [['%s' and '%s' cannot be used together]], + [%name-prefix], + [%define api.prefix])])]) + +# api.token.prefix={...} +# Make it a warning for those who used betas of Bison 3.0. +b4_percent_define_check_kind([api.token.prefix], [code], [deprecated]) + +# api.value.type >< %union. +b4_percent_define_ifdef([api.value.type], +[m4_ifdef([b4_union_members], +[b4_complain_at(b4_percent_define_get_loc([api.value.type]), + [['%s' and '%s' cannot be used together]], + [%union], + [%define api.value.type])])]) + +# api.value.type=union >< %yacc. +b4_percent_define_ifdef([api.value.type], +[m4_if(b4_percent_define_get([api.value.type]), [union], +[b4_yacc_if(dnl +[b4_complain_at(b4_percent_define_get_loc([api.value.type]), + [['%s' and '%s' cannot be used together]], + [%yacc], + [%define api.value.type "union"])])])]) + +# api.value.union.name. +b4_percent_define_check_kind([api.value.union.name], [keyword]) + +# parse.error (custom|detailed) >< token-table. +b4_token_table_if( +[b4_parse_error_bmatch([custom\|detailed], +[b4_complain_at(b4_percent_define_get_loc([parse.error]), + [['%s' and '%s' cannot be used together]], + [%token-table], + [%define parse.error (custom|detailed)])])]) diff --git a/Engine/bin/bison-flex/data/skeletons/c++-skel.m4 b/Engine/bin/bison-flex/data/skeletons/c++-skel.m4 new file mode 100644 index 000000000..f22002b96 --- /dev/null +++ b/Engine/bin/bison-flex/data/skeletons/c++-skel.m4 @@ -0,0 +1,27 @@ + -*- Autoconf -*- + +# C++ skeleton dispatching for Bison. + +# Copyright (C) 2006-2007, 2009-2015, 2018-2021 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +b4_glr_if( [m4_define([b4_used_skeleton], [b4_skeletonsdir/[glr.cc]])]) +b4_nondeterministic_if([m4_define([b4_used_skeleton], [b4_skeletonsdir/[glr.cc]])]) + +m4_define_default([b4_used_skeleton], [b4_skeletonsdir/[lalr1.cc]]) +m4_define_default([b4_skeleton], ["b4_basename(b4_used_skeleton)"]) + +m4_include(b4_used_skeleton) diff --git a/Engine/bin/bison-flex/data/skeletons/c++.m4 b/Engine/bin/bison-flex/data/skeletons/c++.m4 new file mode 100644 index 000000000..2ae8423ab --- /dev/null +++ b/Engine/bin/bison-flex/data/skeletons/c++.m4 @@ -0,0 +1,778 @@ + -*- Autoconf -*- + +# C++ skeleton for Bison + +# Copyright (C) 2002-2021 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Sanity checks, before defaults installed by c.m4. +b4_percent_define_ifdef([[api.value.union.name]], + [b4_complain_at(b4_percent_define_get_loc([[api.value.union.name]]), + [named %union is invalid in C++])]) + +b4_percent_define_default([[api.symbol.prefix]], [[S_]]) + +m4_include(b4_skeletonsdir/[c.m4]) + +b4_percent_define_check_kind([api.namespace], [code], [deprecated]) +b4_percent_define_check_kind([api.parser.class], [code], [deprecated]) + + +## ----- ## +## C++. ## +## ----- ## + +# b4_comment(TEXT, [PREFIX]) +# -------------------------- +# Put TEXT in comment. Prefix all the output lines with PREFIX. +m4_define([b4_comment], +[_b4_comment([$1], [$2// ], [$2// ])]) + + +# b4_inline(hh|cc) +# ---------------- +# Expand to `inline\n ` if $1 is hh. +m4_define([b4_inline], +[m4_case([$1], + [cc], [], + [hh], [[inline + ]], + [m4_fatal([$0: invalid argument: $1])])]) + + +# b4_cxx_portability +# ------------------ +m4_define([b4_cxx_portability], +[#if defined __cplusplus +# define YY_CPLUSPLUS __cplusplus +#else +# define YY_CPLUSPLUS 199711L +#endif + +// Support move semantics when possible. +#if 201103L <= YY_CPLUSPLUS +# define YY_MOVE std::move +# define YY_MOVE_OR_COPY move +# define YY_MOVE_REF(Type) Type&& +# define YY_RVREF(Type) Type&& +# define YY_COPY(Type) Type +#else +# define YY_MOVE +# define YY_MOVE_OR_COPY copy +# define YY_MOVE_REF(Type) Type& +# define YY_RVREF(Type) const Type& +# define YY_COPY(Type) const Type& +#endif + +// Support noexcept when possible. +#if 201103L <= YY_CPLUSPLUS +# define YY_NOEXCEPT noexcept +# define YY_NOTHROW +#else +# define YY_NOEXCEPT +# define YY_NOTHROW throw () +#endif + +// Support constexpr when possible. +#if 201703 <= YY_CPLUSPLUS +# define YY_CONSTEXPR constexpr +#else +# define YY_CONSTEXPR +#endif[]dnl +]) + + +## ---------------- ## +## Default values. ## +## ---------------- ## + +b4_percent_define_default([[api.parser.class]], [[parser]]) + +# Don't do that so that we remember whether we're using a user +# request, or the default value. +# +# b4_percent_define_default([[api.location.type]], [[location]]) + +b4_percent_define_default([[api.filename.type]], [[const std::string]]) +# Make it a warning for those who used betas of Bison 3.0. +b4_percent_define_default([[api.namespace]], m4_defn([b4_prefix])) + +b4_percent_define_default([[define_location_comparison]], + [m4_if(b4_percent_define_get([[filename_type]]), + [std::string], [[true]], [[false]])]) + + + +## ----------- ## +## Namespace. ## +## ----------- ## + +m4_define([b4_namespace_ref], [b4_percent_define_get([[api.namespace]])]) + + +# Don't permit an empty b4_namespace_ref. Any '::parser::foo' appended to it +# would compile as an absolute reference with 'parser' in the global namespace. +# b4_namespace_open would open an anonymous namespace and thus establish +# internal linkage. This would compile. However, it's cryptic, and internal +# linkage for the parser would be specified in all translation units that +# include the header, which is always generated. If we ever need to permit +# internal linkage somehow, surely we can find a cleaner approach. +m4_if(m4_bregexp(b4_namespace_ref, [^[ ]*$]), [-1], [], +[b4_complain_at(b4_percent_define_get_loc([[api.namespace]]), + [[namespace reference is empty]])]) + +# Instead of assuming the C++ compiler will do it, Bison should reject any +# invalid b4_namespace_ref that would be converted to a valid +# b4_namespace_open. The problem is that Bison doesn't always output +# b4_namespace_ref to uncommented code but should reserve the ability to do so +# in future releases without risking breaking any existing user grammars. +# Specifically, don't allow empty names as b4_namespace_open would just convert +# those into anonymous namespaces, and that might tempt some users. +m4_if(m4_bregexp(b4_namespace_ref, [::[ ]*::]), [-1], [], +[b4_complain_at(b4_percent_define_get_loc([[api.namespace]]), + [[namespace reference has consecutive "::"]])]) +m4_if(m4_bregexp(b4_namespace_ref, [::[ ]*$]), [-1], [], +[b4_complain_at(b4_percent_define_get_loc([[api.namespace]]), + [[namespace reference has a trailing "::"]])]) + +m4_define([b4_namespace_open], +[b4_user_code([b4_percent_define_get_syncline([[api.namespace]])dnl +[namespace ]m4_bpatsubst(m4_dquote(m4_bpatsubst(m4_dquote(b4_namespace_ref), + [^\(.\)[ ]*::], [\1])), + [::], [ { namespace ])[ {]])]) + +m4_define([b4_namespace_close], +[b4_user_code([b4_percent_define_get_syncline([[api.namespace]])dnl +m4_bpatsubst(m4_dquote(m4_bpatsubst(m4_dquote(b4_namespace_ref[ ]), + [^\(.\)[ ]*\(::\)?\([^][:]\|:[^:]\)*], + [\1])), + [::\([^][:]\|:[^:]\)*], [} ])[} // ]b4_namespace_ref])]) + + +## ------------- ## +## Token kinds. ## +## ------------- ## + + +# b4_token_enums +# -------------- +# Output the definition of the token kinds. +m4_define([b4_token_enums], +[[enum token_kind_type + { + ]b4_symbol([-2], [id])[ = -2, +]b4_symbol_foreach([b4_token_enum])dnl +[ };]dnl +]) + + + +## -------------- ## +## Symbol kinds. ## +## -------------- ## + +# b4_declare_symbol_enum +# ---------------------- +# The definition of the symbol internal numbers as an enum. +# Defining YYEMPTY here is important: it forces the compiler +# to use a signed type, which matters for yytoken. +m4_define([b4_declare_symbol_enum], +[[enum symbol_kind_type + { + YYNTOKENS = ]b4_tokens_number[, ///< Number of tokens. + ]b4_symbol(empty, kind_base)[ = -2, +]b4_symbol_foreach([ b4_symbol_enum])dnl +[ };]]) + + + +## ----------------- ## +## Semantic Values. ## +## ----------------- ## + + + +# b4_value_type_declare +# --------------------- +# Declare value_type. +m4_define([b4_value_type_declare], +[b4_value_type_setup[]dnl +[ /// Symbol semantic values. +]m4_bmatch(b4_percent_define_get_kind([[api.value.type]]), +[code], +[[ typedef ]b4_percent_define_get([[api.value.type]])[ value_type;]], +[m4_bmatch(b4_percent_define_get([[api.value.type]]), +[union\|union-directive], +[[ union value_type + { +]b4_user_union_members[ + };]])])dnl +]) + + +# b4_public_types_declare +# ----------------------- +# Define the public types: token, semantic value, location, and so forth. +# Depending on %define token_lex, may be output in the header or source file. +m4_define([b4_public_types_declare], +[b4_glr2_cc_if( +[b4_value_type_declare], +[[#ifdef ]b4_api_PREFIX[STYPE +# ifdef __GNUC__ +# pragma GCC message "bison: do not #define ]b4_api_PREFIX[STYPE in C++, use %define api.value.type" +# endif + typedef ]b4_api_PREFIX[STYPE value_type; +#else +]b4_value_type_declare[ +#endif + /// Backward compatibility (Bison 3.8). + typedef value_type semantic_type; +]])[]b4_locations_if([ + /// Symbol locations. + typedef b4_percent_define_get([[api.location.type]], + [[location]]) location_type;])[ + + /// Syntax errors thrown from user actions. + struct syntax_error : std::runtime_error + { + syntax_error (]b4_locations_if([const location_type& l, ])[const std::string& m) + : std::runtime_error (m)]b4_locations_if([ + , location (l)])[ + {} + + syntax_error (const syntax_error& s) + : std::runtime_error (s.what ())]b4_locations_if([ + , location (s.location)])[ + {} + + ~syntax_error () YY_NOEXCEPT YY_NOTHROW;]b4_locations_if([ + + location_type location;])[ + }; + + /// Token kinds. + struct token + { + ]b4_token_enums[]b4_glr2_cc_if([], [[ + /// Backward compatibility alias (Bison 3.6). + typedef token_kind_type yytokentype;]])[ + }; + + /// Token kind, as returned by yylex. + typedef token::token_kind_type token_kind_type;]b4_glr2_cc_if([], [[ + + /// Backward compatibility alias (Bison 3.6). + typedef token_kind_type token_type;]])[ + + /// Symbol kinds. + struct symbol_kind + { + ]b4_declare_symbol_enum[ + }; + + /// (Internal) symbol kind. + typedef symbol_kind::symbol_kind_type symbol_kind_type; + + /// The number of tokens. + static const symbol_kind_type YYNTOKENS = symbol_kind::YYNTOKENS; +]]) + + +# b4_symbol_type_define +# --------------------- +# Define symbol_type, the external type for symbols used for symbol +# constructors. +m4_define([b4_symbol_type_define], +[[ /// A complete symbol. + /// + /// Expects its Base type to provide access to the symbol kind + /// via kind (). + /// + /// Provide access to semantic value]b4_locations_if([ and location])[. + template + struct basic_symbol : Base + { + /// Alias to Base. + typedef Base super_type; + + /// Default constructor. + basic_symbol () YY_NOEXCEPT + : value ()]b4_locations_if([ + , location ()])[ + {} + +#if 201103L <= YY_CPLUSPLUS + /// Move constructor. + basic_symbol (basic_symbol&& that) + : Base (std::move (that)) + , value (]b4_variant_if([], [std::move (that.value)]))b4_locations_if([ + , location (std::move (that.location))])[ + {]b4_variant_if([ + b4_symbol_variant([this->kind ()], [value], [move], + [std::move (that.value)]) + ])[} +#endif + + /// Copy constructor. + basic_symbol (const basic_symbol& that);]b4_variant_if([[ + + /// Constructors for typed symbols. +]b4_type_foreach([b4_basic_symbol_constructor_define], [ +])], [[ + /// Constructor for valueless symbols. + basic_symbol (typename Base::kind_type t]b4_locations_if([, + YY_MOVE_REF (location_type) l])[); + + /// Constructor for symbols with semantic value. + basic_symbol (typename Base::kind_type t, + YY_RVREF (value_type) v]b4_locations_if([, + YY_RVREF (location_type) l])[); +]])[ + /// Destroy the symbol. + ~basic_symbol () + { + clear (); + } + +]b4_glr2_cc_if([[ + /// Copy assignment. + basic_symbol& operator= (const basic_symbol& that) + { + Base::operator= (that);]b4_variant_if([[ + ]b4_symbol_variant([this->kind ()], [value], [copy], + [that.value])], [[ + value = that.value]])[;]b4_locations_if([[ + location = that.location;]])[ + return *this; + } + + /// Move assignment. + basic_symbol& operator= (basic_symbol&& that) + { + Base::operator= (std::move (that));]b4_variant_if([[ + ]b4_symbol_variant([this->kind ()], [value], [move], + [std::move (that.value)])], [[ + value = std::move (that.value)]])[;]b4_locations_if([[ + location = std::move (that.location);]])[ + return *this; + } +]])[ + + /// Destroy contents, and record that is empty. + void clear () YY_NOEXCEPT + {]b4_variant_if([[ + // User destructor. + symbol_kind_type yykind = this->kind (); + basic_symbol& yysym = *this; + (void) yysym; + switch (yykind) + { +]b4_symbol_foreach([b4_symbol_destructor])dnl +[ default: + break; + } + + // Value type destructor. +]b4_symbol_variant([[yykind]], [[value]], [[template destroy]])])[ + Base::clear (); + } + +]b4_parse_error_bmatch( +[custom\|detailed], +[[ /// The user-facing name of this symbol. + const char *name () const YY_NOEXCEPT + { + return ]b4_parser_class[::symbol_name (this->kind ()); + }]], +[simple], +[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ + /// The user-facing name of this symbol. + const char *name () const YY_NOEXCEPT + { + return ]b4_parser_class[::symbol_name (this->kind ()); + } +#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ +]], +[verbose], +[[ /// The user-facing name of this symbol. + std::string name () const YY_NOEXCEPT + { + return ]b4_parser_class[::symbol_name (this->kind ()); + }]])[]b4_glr2_cc_if([], [[ + + /// Backward compatibility (Bison 3.6). + symbol_kind_type type_get () const YY_NOEXCEPT;]])[ + + /// Whether empty. + bool empty () const YY_NOEXCEPT; + + /// Destructive move, \a s is emptied into this. + void move (basic_symbol& s); + + /// The semantic value. + value_type value;]b4_locations_if([ + + /// The location. + location_type location;])[ + + private: +#if YY_CPLUSPLUS < 201103L + /// Assignment operator. + basic_symbol& operator= (const basic_symbol& that); +#endif + }; + + /// Type access provider for token (enum) based symbols. + struct by_kind + { + /// The symbol kind as needed by the constructor. + typedef token_kind_type kind_type; + + /// Default constructor. + by_kind () YY_NOEXCEPT; + +#if 201103L <= YY_CPLUSPLUS + /// Move constructor. + by_kind (by_kind&& that) YY_NOEXCEPT; +#endif + + /// Copy constructor. + by_kind (const by_kind& that) YY_NOEXCEPT; + + /// Constructor from (external) token numbers. + by_kind (kind_type t) YY_NOEXCEPT; + +]b4_glr2_cc_if([[ + /// Copy assignment. + by_kind& operator= (const by_kind& that); + + /// Move assignment. + by_kind& operator= (by_kind&& that); +]])[ + + /// Record that this symbol is empty. + void clear () YY_NOEXCEPT; + + /// Steal the symbol kind from \a that. + void move (by_kind& that); + + /// The (internal) type number (corresponding to \a type). + /// \a empty when empty. + symbol_kind_type kind () const YY_NOEXCEPT;]b4_glr2_cc_if([], [[ + + /// Backward compatibility (Bison 3.6). + symbol_kind_type type_get () const YY_NOEXCEPT;]])[ + + /// The symbol kind. + /// \a ]b4_symbol_prefix[YYEMPTY when empty. + symbol_kind_type kind_; + };]b4_glr2_cc_if([], [[ + + /// Backward compatibility for a private implementation detail (Bison 3.6). + typedef by_kind by_type;]])[ + + /// "External" symbols: returned by the scanner. + struct symbol_type : basic_symbol + {]b4_variant_if([[ + /// Superclass. + typedef basic_symbol super_type; + + /// Empty symbol. + symbol_type () YY_NOEXCEPT {} + + /// Constructor for valueless symbols, and symbols from each type. +]b4_type_foreach([_b4_symbol_constructor_define])dnl + ])[}; +]]) + + +# b4_public_types_define(hh|cc) +# ----------------------------- +# Provide the implementation needed by the public types. +m4_define([b4_public_types_define], +[[ // basic_symbol. + template + ]b4_parser_class[::basic_symbol::basic_symbol (const basic_symbol& that) + : Base (that) + , value (]b4_variant_if([], [that.value]))b4_locations_if([ + , location (that.location)])[ + {]b4_variant_if([ + b4_symbol_variant([this->kind ()], [value], [copy], + [YY_MOVE (that.value)]) + ])[} + +]b4_variant_if([], [[ + /// Constructor for valueless symbols. + template + ]b4_parser_class[::basic_symbol::basic_symbol (]b4_join( + [typename Base::kind_type t], + b4_locations_if([YY_MOVE_REF (location_type) l]))[) + : Base (t) + , value ()]b4_locations_if([ + , location (l)])[ + {} + + template + ]b4_parser_class[::basic_symbol::basic_symbol (]b4_join( + [typename Base::kind_type t], + [YY_RVREF (value_type) v], + b4_locations_if([YY_RVREF (location_type) l]))[) + : Base (t) + , value (]b4_variant_if([], [YY_MOVE (v)])[)]b4_locations_if([ + , location (YY_MOVE (l))])[ + {]b4_variant_if([[ + (void) v; + ]b4_symbol_variant([this->kind ()], [value], [YY_MOVE_OR_COPY], [YY_MOVE (v)])])[}]])[ + +]b4_glr2_cc_if([], [[ + template + ]b4_parser_class[::symbol_kind_type + ]b4_parser_class[::basic_symbol::type_get () const YY_NOEXCEPT + { + return this->kind (); + } +]])[ + + template + bool + ]b4_parser_class[::basic_symbol::empty () const YY_NOEXCEPT + { + return this->kind () == ]b4_symbol(empty, kind)[; + } + + template + void + ]b4_parser_class[::basic_symbol::move (basic_symbol& s) + { + super_type::move (s); + ]b4_variant_if([b4_symbol_variant([this->kind ()], [value], [move], + [YY_MOVE (s.value)])], + [value = YY_MOVE (s.value);])[]b4_locations_if([ + location = YY_MOVE (s.location);])[ + } + + // by_kind. + ]b4_inline([$1])b4_parser_class[::by_kind::by_kind () YY_NOEXCEPT + : kind_ (]b4_symbol(empty, kind)[) + {} + +#if 201103L <= YY_CPLUSPLUS + ]b4_inline([$1])b4_parser_class[::by_kind::by_kind (by_kind&& that) YY_NOEXCEPT + : kind_ (that.kind_) + { + that.clear (); + } +#endif + + ]b4_inline([$1])b4_parser_class[::by_kind::by_kind (const by_kind& that) YY_NOEXCEPT + : kind_ (that.kind_) + {} + + ]b4_inline([$1])b4_parser_class[::by_kind::by_kind (token_kind_type t) YY_NOEXCEPT + : kind_ (yytranslate_ (t)) + {} + +]b4_glr2_cc_if([[ + ]b4_inline([$1])]b4_parser_class[::by_kind& + b4_parser_class[::by_kind::by_kind::operator= (const by_kind& that) + { + kind_ = that.kind_; + return *this; + } + + ]b4_inline([$1])]b4_parser_class[::by_kind& + b4_parser_class[::by_kind::by_kind::operator= (by_kind&& that) + { + kind_ = that.kind_; + that.clear (); + return *this; + } +]])[ + + ]b4_inline([$1])[void + ]b4_parser_class[::by_kind::clear () YY_NOEXCEPT + { + kind_ = ]b4_symbol(empty, kind)[; + } + + ]b4_inline([$1])[void + ]b4_parser_class[::by_kind::move (by_kind& that) + { + kind_ = that.kind_; + that.clear (); + } + + ]b4_inline([$1])[]b4_parser_class[::symbol_kind_type + ]b4_parser_class[::by_kind::kind () const YY_NOEXCEPT + { + return kind_; + } + +]b4_glr2_cc_if([], [[ + ]b4_inline([$1])[]b4_parser_class[::symbol_kind_type + ]b4_parser_class[::by_kind::type_get () const YY_NOEXCEPT + { + return this->kind (); + } +]])[ +]]) + + +# b4_token_constructor_define +# ---------------------------- +# Define make_FOO for all the token kinds. +# Use at class-level. Redefined in variant.hh. +m4_define([b4_token_constructor_define], []) + + +# b4_yytranslate_define(cc|hh) +# ---------------------------- +# Define yytranslate_. Sometimes used in the header file ($1=hh), +# sometimes in the cc file. +m4_define([b4_yytranslate_define], +[ b4_inline([$1])b4_parser_class[::symbol_kind_type + ]b4_parser_class[::yytranslate_ (int t) YY_NOEXCEPT + { +]b4_api_token_raw_if( +[[ return static_cast (t);]], +[[ // YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to + // TOKEN-NUM as returned by yylex. + static + const ]b4_int_type_for([b4_translate])[ + translate_table[] = + { + ]b4_translate[ + }; + // Last valid token kind. + const int code_max = ]b4_code_max[; + + if (t <= 0) + return symbol_kind::]b4_symbol_prefix[YYEOF; + else if (t <= code_max) + return static_cast (translate_table[t]); + else + return symbol_kind::]b4_symbol_prefix[YYUNDEF;]])[ + } +]]) + + +# b4_lhs_value([TYPE]) +# -------------------- +m4_define([b4_lhs_value], +[b4_symbol_value([yyval], [$1])]) + + +# b4_rhs_value(RULE-LENGTH, POS, [TYPE]) +# -------------------------------------- +# FIXME: Dead code. +m4_define([b4_rhs_value], +[b4_symbol_value([yysemantic_stack_@{($1) - ($2)@}], [$3])]) + + +# b4_lhs_location() +# ----------------- +# Expansion of @$. +m4_define([b4_lhs_location], +[(yyloc)]) + + +# b4_rhs_location(RULE-LENGTH, POS) +# --------------------------------- +# Expansion of @POS, where the current rule has RULE-LENGTH symbols +# on RHS. +m4_define([b4_rhs_location], +[(yylocation_stack_@{($1) - ($2)@})]) + + +# b4_parse_param_decl +# ------------------- +# Extra formal arguments of the constructor. +# Change the parameter names from "foo" into "foo_yyarg", so that +# there is no collision bw the user chosen attribute name, and the +# argument name in the constructor. +m4_define([b4_parse_param_decl], +[m4_ifset([b4_parse_param], + [m4_map_sep([b4_parse_param_decl_1], [, ], [b4_parse_param])])]) + +m4_define([b4_parse_param_decl_1], +[$1_yyarg]) + + + +# b4_parse_param_cons +# ------------------- +# Extra initialisations of the constructor. +m4_define([b4_parse_param_cons], + [m4_ifset([b4_parse_param], + [ + b4_cc_constructor_calls(b4_parse_param)])]) +m4_define([b4_cc_constructor_calls], + [m4_map_sep([b4_cc_constructor_call], [, + ], [$@])]) +m4_define([b4_cc_constructor_call], + [$2 ($2_yyarg)]) + +# b4_parse_param_vars +# ------------------- +# Extra instance variables. +m4_define([b4_parse_param_vars], + [m4_ifset([b4_parse_param], + [ + // User arguments. +b4_cc_var_decls(b4_parse_param)])]) +m4_define([b4_cc_var_decls], + [m4_map_sep([b4_cc_var_decl], [ +], [$@])]) +m4_define([b4_cc_var_decl], + [ $1;]) + + +## ---------## +## Values. ## +## ---------## + +# b4_yylloc_default_define +# ------------------------ +# Define YYLLOC_DEFAULT. +m4_define([b4_yylloc_default_define], +[[/* 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). */ + +# ifndef YYLLOC_DEFAULT +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (N) \ + { \ + (Current).begin = YYRHSLOC (Rhs, 1).begin; \ + (Current).end = YYRHSLOC (Rhs, N).end; \ + } \ + else \ + { \ + (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end; \ + } \ + while (false) +# endif +]]) + +## -------- ## +## Checks. ## +## -------- ## + +b4_token_ctor_if([b4_variant_if([], + [b4_fatal_at(b4_percent_define_get_loc(api.token.constructor), + [cannot use '%s' without '%s'], + [%define api.token.constructor], + [%define api.value.type variant]))])]) diff --git a/Engine/bin/bison-flex/data/skeletons/c-like.m4 b/Engine/bin/bison-flex/data/skeletons/c-like.m4 new file mode 100644 index 000000000..a9bbc2e86 --- /dev/null +++ b/Engine/bin/bison-flex/data/skeletons/c-like.m4 @@ -0,0 +1,72 @@ + -*- Autoconf -*- + +# Common code for C-like languages (C, C++, Java, etc.) + +# Copyright (C) 2012-2015, 2018-2021 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +# _b4_comment(TEXT, OPEN, CONTINUE, END) +# -------------------------------------- +# Put TEXT in comment. Avoid trailing spaces: don't indent empty lines. +# Avoid adding indentation to the first line, as the indentation comes +# from OPEN. That's why we don't patsubst([$1], [^\(.\)], [ \1]). +# Turn "*/" in TEXT into "* /" so that we don't unexpectedly close +# the comments before its end. +# +# Prefix all the output lines with PREFIX. +m4_define([_b4_comment], +[$2[]b4_gsub(m4_expand([$1]), + [[*]/], [*\\/], + [/[*]], [/\\*], + [ +\(.\)], [ +$3\1])$4]) + + +# b4_comment(TEXT, [PREFIX]) +# -------------------------- +# Put TEXT in comment. Prefix all the output lines with PREFIX. +m4_define([b4_comment], +[_b4_comment([$1], [$2/* ], [$2 ], [ */])]) + + + + +# _b4_dollar_dollar(VALUE, SYMBOL-NUM, FIELD, DEFAULT-FIELD) +# ---------------------------------------------------------- +# If FIELD (or DEFAULT-FIELD) is non-null, return "VALUE.FIELD", +# otherwise just VALUE. Be sure to pass "(VALUE)" if VALUE is a +# pointer. +m4_define([_b4_dollar_dollar], +[b4_symbol_value([$1], + [$2], + m4_if([$3], [[]], + [[$4]], [[$3]]))]) + +# b4_dollar_pushdef(VALUE-POINTER, SYMBOL-NUM, [TYPE_TAG], LOCATION) +# b4_dollar_popdef +# ------------------------------------------------------------------ +# Define b4_dollar_dollar for VALUE-POINTER and DEFAULT-FIELD, +# and b4_at_dollar for LOCATION. +m4_define([b4_dollar_pushdef], +[m4_pushdef([b4_dollar_dollar], + [_b4_dollar_dollar([$1], [$2], m4_dquote($][1), [$3])])dnl +m4_pushdef([b4_at_dollar], [$4])dnl +]) +m4_define([b4_dollar_popdef], +[m4_popdef([b4_at_dollar])dnl +m4_popdef([b4_dollar_dollar])dnl +]) diff --git a/Engine/bin/bison-flex/data/skeletons/c-skel.m4 b/Engine/bin/bison-flex/data/skeletons/c-skel.m4 new file mode 100644 index 000000000..ac6ddd687 --- /dev/null +++ b/Engine/bin/bison-flex/data/skeletons/c-skel.m4 @@ -0,0 +1,27 @@ + -*- Autoconf -*- + +# C skeleton dispatching for Bison. + +# Copyright (C) 2006-2007, 2009-2015, 2018-2021 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +b4_glr_if( [m4_define([b4_used_skeleton], [b4_skeletonsdir/[glr.c]])]) +b4_nondeterministic_if([m4_define([b4_used_skeleton], [b4_skeletonsdir/[glr.c]])]) + +m4_define_default([b4_used_skeleton], [b4_skeletonsdir/[yacc.c]]) +m4_define_default([b4_skeleton], ["b4_basename(b4_used_skeleton)"]) + +m4_include(b4_used_skeleton) diff --git a/Engine/bin/bison-flex/data/skeletons/c.m4 b/Engine/bin/bison-flex/data/skeletons/c.m4 new file mode 100644 index 000000000..2425b0715 --- /dev/null +++ b/Engine/bin/bison-flex/data/skeletons/c.m4 @@ -0,0 +1,1125 @@ + -*- Autoconf -*- + +# C M4 Macros for Bison. + +# Copyright (C) 2002, 2004-2015, 2018-2021 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +m4_include(b4_skeletonsdir/[c-like.m4]) + +# b4_tocpp(STRING) +# ---------------- +# Convert STRING into a valid C macro name. +m4_define([b4_tocpp], +[m4_toupper(m4_bpatsubst(m4_quote($1), [[^a-zA-Z0-9]+], [_]))]) + + +# b4_cpp_guard(FILE) +# ------------------ +# A valid C macro name to use as a CPP header guard for FILE. +m4_define([b4_cpp_guard], +[[YY_]b4_tocpp(m4_defn([b4_prefix])/[$1])[_INCLUDED]]) + + +# b4_cpp_guard_open(FILE) +# b4_cpp_guard_close(FILE) +# ------------------------ +# If FILE does not expand to nothing, open/close CPP inclusion guards for FILE. +m4_define([b4_cpp_guard_open], +[m4_ifval(m4_quote($1), +[#ifndef b4_cpp_guard([$1]) +# define b4_cpp_guard([$1])])]) + +m4_define([b4_cpp_guard_close], +[m4_ifval(m4_quote($1), +[#endif b4_comment([!b4_cpp_guard([$1])])])]) + + +## ---------------- ## +## Identification. ## +## ---------------- ## + +# b4_identification +# ----------------- +# Depends on individual skeletons to define b4_pure_flag, b4_push_flag, or +# b4_pull_flag if they use the values of the %define variables api.pure or +# api.push-pull. +m4_define([b4_identification], +[[/* Identify Bison output, and Bison version. */ +#define YYBISON ]b4_version[ + +/* Bison version string. */ +#define YYBISON_VERSION "]b4_version_string[" + +/* Skeleton name. */ +#define YYSKELETON_NAME ]b4_skeleton[]m4_ifdef([b4_pure_flag], [[ + +/* Pure parsers. */ +#define YYPURE ]b4_pure_flag])[]m4_ifdef([b4_push_flag], [[ + +/* Push parsers. */ +#define YYPUSH ]b4_push_flag])[]m4_ifdef([b4_pull_flag], [[ + +/* Pull parsers. */ +#define YYPULL ]b4_pull_flag])[ +]]) + + +## ---------------- ## +## Default values. ## +## ---------------- ## + +# b4_api_prefix, b4_api_PREFIX +# ---------------------------- +# Corresponds to %define api.prefix +b4_percent_define_default([[api.prefix]], [[yy]]) +m4_define([b4_api_prefix], +[b4_percent_define_get([[api.prefix]])]) +m4_define([b4_api_PREFIX], +[m4_toupper(b4_api_prefix)]) + + +# b4_prefix +# --------- +# If the %name-prefix is not given, it is api.prefix. +m4_define_default([b4_prefix], [b4_api_prefix]) + +# If the %union is not named, its name is YYSTYPE. +b4_percent_define_default([[api.value.union.name]], + [b4_api_PREFIX[][STYPE]]) + +b4_percent_define_default([[api.symbol.prefix]], [[YYSYMBOL_]]) + +## ------------------------ ## +## Pure/impure interfaces. ## +## ------------------------ ## + +# b4_yylex_formals +# ---------------- +# All the yylex formal arguments. +# b4_lex_param arrives quoted twice, but we want to keep only one level. +m4_define([b4_yylex_formals], +[b4_pure_if([[[b4_api_PREFIX[STYPE *yylvalp]], [[&yylval]]][]dnl +b4_locations_if([, [b4_api_PREFIX[LTYPE *yyllocp], [&yylloc]]])])dnl +m4_ifdef([b4_lex_param], [, ]b4_lex_param)]) + + +# b4_yylex +# -------- +# Call yylex. +m4_define([b4_yylex], +[b4_function_call([yylex], [int], b4_yylex_formals)]) + + +# b4_user_args +# ------------ +m4_define([b4_user_args], +[m4_ifset([b4_parse_param], [, b4_user_args_no_comma])]) + +# b4_user_args_no_comma +# --------------------- +m4_define([b4_user_args_no_comma], +[m4_ifset([b4_parse_param], [b4_args(b4_parse_param)])]) + + +# b4_user_formals +# --------------- +# The possible parse-params formal arguments preceded by a comma. +m4_define([b4_user_formals], +[m4_ifset([b4_parse_param], [, b4_formals(b4_parse_param)])]) + + +# b4_parse_param +# -------------- +# If defined, b4_parse_param arrives double quoted, but below we prefer +# it to be single quoted. +m4_define([b4_parse_param], +b4_parse_param) + + +# b4_parse_param_for(DECL, FORMAL, BODY) +# --------------------------------------- +# Iterate over the user parameters, binding the declaration to DECL, +# the formal name to FORMAL, and evaluating the BODY. +m4_define([b4_parse_param_for], +[m4_foreach([$1_$2], m4_defn([b4_parse_param]), +[m4_pushdef([$1], m4_unquote(m4_car($1_$2)))dnl +m4_pushdef([$2], m4_shift($1_$2))dnl +$3[]dnl +m4_popdef([$2])dnl +m4_popdef([$1])dnl +])]) + + +# b4_use(EXPR) +# ------------ +# Pacify the compiler about some maybe unused value. +m4_define([b4_use], +[YY_USE ($1)]) + +# b4_parse_param_use([VAL], [LOC]) +# -------------------------------- +# 'YY_USE' VAL, LOC if locations are enabled, and all the parse-params. +m4_define([b4_parse_param_use], +[m4_ifvaln([$1], [ b4_use([$1]);])dnl +b4_locations_if([m4_ifvaln([$2], [ b4_use([$2]);])])dnl +b4_parse_param_for([Decl], [Formal], [ b4_use(Formal); +])dnl +]) + + +## ------------ ## +## Data Types. ## +## ------------ ## + +# b4_int_type(MIN, MAX) +# --------------------- +# Return a narrow int type able to handle integers ranging from MIN +# to MAX (included) in portable C code. Assume MIN and MAX fall in +# 'int' range. +m4_define([b4_int_type], +[m4_if(b4_ints_in($@, [-127], [127]), [1], [signed char], + b4_ints_in($@, [0], [255]), [1], [unsigned char], + + b4_ints_in($@, [-32767], [32767]), [1], [short], + b4_ints_in($@, [0], [65535]), [1], [unsigned short], + + [int])]) + +# b4_c99_int_type(MIN, MAX) +# ------------------------- +# Like b4_int_type, but for C99. +# b4_c99_int_type_define replaces b4_int_type with this. +m4_define([b4_c99_int_type], +[m4_if(b4_ints_in($@, [-127], [127]), [1], [yytype_int8], + b4_ints_in($@, [0], [255]), [1], [yytype_uint8], + + b4_ints_in($@, [-32767], [32767]), [1], [yytype_int16], + b4_ints_in($@, [0], [65535]), [1], [yytype_uint16], + + [int])]) + +# b4_c99_int_type_define +# ---------------------- +# Define private types suitable for holding small integers in C99 or later. +m4_define([b4_c99_int_type_define], +[m4_copy_force([b4_c99_int_type], [b4_int_type])dnl +[#ifdef short +# undef short +#endif + +/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure + and (if available) are included + so that the code can choose integer types of a good width. */ + +#ifndef __PTRDIFF_MAX__ +# include /* INFRINGES ON USER NAME SPACE */ +# if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_STDINT_H +# endif +#endif + +/* Narrow types that promote to a signed type and that can represent a + signed or unsigned integer of at least N bits. In tables they can + save space and decrease cache pressure. Promoting to a signed type + helps avoid bugs in integer arithmetic. */ + +#ifdef __INT_LEAST8_MAX__ +typedef __INT_LEAST8_TYPE__ yytype_int8; +#elif defined YY_STDINT_H +typedef int_least8_t yytype_int8; +#else +typedef signed char yytype_int8; +#endif + +#ifdef __INT_LEAST16_MAX__ +typedef __INT_LEAST16_TYPE__ yytype_int16; +#elif defined YY_STDINT_H +typedef int_least16_t yytype_int16; +#else +typedef short yytype_int16; +#endif + +/* Work around bug in HP-UX 11.23, which defines these macros + incorrectly for preprocessor constants. This workaround can likely + be removed in 2023, as HPE has promised support for HP-UX 11.23 + (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of + . */ +#ifdef __hpux +# undef UINT_LEAST8_MAX +# undef UINT_LEAST16_MAX +# define UINT_LEAST8_MAX 255 +# define UINT_LEAST16_MAX 65535 +#endif + +#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST8_TYPE__ yytype_uint8; +#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \ + && UINT_LEAST8_MAX <= INT_MAX) +typedef uint_least8_t yytype_uint8; +#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX +typedef unsigned char yytype_uint8; +#else +typedef short yytype_uint8; +#endif + +#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST16_TYPE__ yytype_uint16; +#elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \ + && UINT_LEAST16_MAX <= INT_MAX) +typedef uint_least16_t yytype_uint16; +#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX +typedef unsigned short yytype_uint16; +#else +typedef int yytype_uint16; +#endif]]) + + +# b4_sizes_types_define +# --------------------- +# Define YYPTRDIFF_T/YYPTRDIFF_MAXIMUM, YYSIZE_T/YYSIZE_MAXIMUM, +# and YYSIZEOF. +m4_define([b4_sizes_types_define], +[[#ifndef YYPTRDIFF_T +# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__ +# define YYPTRDIFF_T __PTRDIFF_TYPE__ +# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__ +# elif defined PTRDIFF_MAX +# ifndef ptrdiff_t +# include /* INFRINGES ON USER NAME SPACE */ +# endif +# define YYPTRDIFF_T ptrdiff_t +# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX +# else +# define YYPTRDIFF_T long +# define YYPTRDIFF_MAXIMUM LONG_MAX +# endif +#endif + +#ifndef YYSIZE_T +# ifdef __SIZE_TYPE__ +# define YYSIZE_T __SIZE_TYPE__ +# elif defined size_t +# define YYSIZE_T size_t +# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ +# include /* INFRINGES ON USER NAME SPACE */ +# define YYSIZE_T size_t +# else +# define YYSIZE_T unsigned +# endif +#endif + +#define YYSIZE_MAXIMUM \ + YY_CAST (YYPTRDIFF_T, \ + (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \ + ? YYPTRDIFF_MAXIMUM \ + : YY_CAST (YYSIZE_T, -1))) + +#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X)) +]]) + + +# b4_int_type_for(NAME) +# --------------------- +# Return a narrow int type able to handle numbers ranging from +# 'NAME_min' to 'NAME_max' (included). +m4_define([b4_int_type_for], +[b4_int_type($1_min, $1_max)]) + + +# b4_table_value_equals(TABLE, VALUE, LITERAL, SYMBOL) +# ---------------------------------------------------- +# Without inducing a comparison warning from the compiler, check if the +# literal value LITERAL equals VALUE from table TABLE, which must have +# TABLE_min and TABLE_max defined. SYMBOL denotes +m4_define([b4_table_value_equals], +[m4_if(m4_eval($3 < m4_indir([b4_]$1[_min]) + || m4_indir([b4_]$1[_max]) < $3), [1], + [[0]], + [(($2) == $4)])]) + + +## ----------------- ## +## Compiler issues. ## +## ----------------- ## + +# b4_attribute_define([noreturn]) +# ------------------------------- +# Provide portable compiler "attributes". If "noreturn" is passed, define +# _Noreturn. +m4_define([b4_attribute_define], +[[#ifndef YY_ATTRIBUTE_PURE +# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_PURE __attribute__ ((__pure__)) +# else +# define YY_ATTRIBUTE_PURE +# endif +#endif + +#ifndef YY_ATTRIBUTE_UNUSED +# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__)) +# else +# define YY_ATTRIBUTE_UNUSED +# endif +#endif + +]m4_bmatch([$1], [\bnoreturn\b], [[/* The _Noreturn keyword of C11. */ +]dnl This is close to lib/_Noreturn.h, except that we do enable +dnl the use of [[noreturn]], because _Noreturn is used in places +dnl where [[noreturn]] works in C++. We need this in particular +dnl because of glr.cc which compiles code from glr.c in C++. +dnl And the C++ compiler chokes on _Noreturn. Also, we do not +dnl use C' _Noreturn in C++, to avoid -Wc11-extensions warnings. +[#ifndef _Noreturn +# if (defined __cplusplus \ + && ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \ + || (defined _MSC_VER && 1900 <= _MSC_VER))) +# define _Noreturn [[noreturn]] +# elif ((!defined __cplusplus || defined __clang__) \ + && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \ + || (!defined __STRICT_ANSI__ \ + && (4 < __GNUC__ + (7 <= __GNUC_MINOR__) \ + || (defined __apple_build_version__ \ + ? 6000000 <= __apple_build_version__ \ + : 3 < __clang_major__ + (5 <= __clang_minor__)))))) + /* _Noreturn works as-is. */ +# elif (2 < __GNUC__ + (8 <= __GNUC_MINOR__) || defined __clang__ \ + || 0x5110 <= __SUNPRO_C) +# define _Noreturn __attribute__ ((__noreturn__)) +# elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0) +# define _Noreturn __declspec (noreturn) +# else +# define _Noreturn +# endif +#endif + +]])[/* Suppress unused-variable warnings by "using" E. */ +#if ! defined lint || defined __GNUC__ +# define YY_USE(E) ((void) (E)) +#else +# define YY_USE(E) /* empty */ +#endif + +/* Suppress an incorrect diagnostic about yylval being uninitialized. */ +#if defined __GNUC__ && ! defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__ +# if __GNUC__ * 100 + __GNUC_MINOR__ < 407 +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") +# else +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \ + _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +# endif +# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ + _Pragma ("GCC diagnostic pop") +#else +# define YY_INITIAL_VALUE(Value) Value +#endif +#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 + +#if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__ +# define YY_IGNORE_USELESS_CAST_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"") +# define YY_IGNORE_USELESS_CAST_END \ + _Pragma ("GCC diagnostic pop") +#endif +#ifndef YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_END +#endif +]]) + + +# b4_cast_define +# -------------- +m4_define([b4_cast_define], +[# ifndef YY_CAST +# ifdef __cplusplus +# define YY_CAST(Type, Val) static_cast (Val) +# define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast (Val) +# else +# define YY_CAST(Type, Val) ((Type) (Val)) +# define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val)) +# endif +# endif[]dnl +]) + + +# b4_null_define +# -------------- +# Portability issues: define a YY_NULLPTR appropriate for the current +# language (C, C++98, or C++11). +# +# In C++ pre C++11 it is standard practice to use 0 (not NULL) for the +# null pointer. In C, prefer ((void*)0) to avoid having to include stdlib.h. +m4_define([b4_null_define], +[# ifndef YY_NULLPTR +# if defined __cplusplus +# if 201103L <= __cplusplus +# define YY_NULLPTR nullptr +# else +# define YY_NULLPTR 0 +# endif +# else +# define YY_NULLPTR ((void*)0) +# endif +# endif[]dnl +]) + + +# b4_null +# ------- +# Return a null pointer constant. +m4_define([b4_null], [YY_NULLPTR]) + + + +## ---------## +## Values. ## +## ---------## + +# b4_integral_parser_table_define(TABLE-NAME, CONTENT, COMMENT) +# ------------------------------------------------------------- +# Define "yy" whose contents is CONTENT. +m4_define([b4_integral_parser_table_define], +[m4_ifvaln([$3], [b4_comment([$3])])dnl +static const b4_int_type_for([$2]) yy$1[[]] = +{ + $2 +};dnl +]) + + +## ------------- ## +## Token kinds. ## +## ------------- ## + +# Because C enums are not scoped, because tokens are exposed in the +# header, and because these tokens are common to all the parsers, we +# need to make sure their names don't collide: use the api.prefix. +# YYEOF is special, since the user may give it a different name. +m4_define([b4_symbol(-2, id)], [b4_api_PREFIX[][EMPTY]]) +m4_define([b4_symbol(-2, tag)], [[No symbol.]]) + +m4_if(b4_symbol(eof, id), [YYEOF], + [m4_define([b4_symbol(0, id)], [b4_api_PREFIX[][EOF]])]) +m4_define([b4_symbol(1, id)], [b4_api_PREFIX[][error]]) +m4_define([b4_symbol(2, id)], [b4_api_PREFIX[][UNDEF]]) + + +# b4_token_define(TOKEN-NUM) +# -------------------------- +# Output the definition of this token as #define. +m4_define([b4_token_define], +[b4_token_format([#define %s %s], [$1])]) + +# b4_token_defines +# ---------------- +# Output the definition of the tokens. +m4_define([b4_token_defines], +[[/* Token kinds. */ +#define ]b4_symbol(empty, [id])[ -2 +]m4_join([ +], b4_symbol_map([b4_token_define])) +]) + + +# b4_token_enum(TOKEN-NUM) +# ------------------------ +# Output the definition of this token as an enum. +m4_define([b4_token_enum], +[b4_token_visible_if([$1], + [m4_format([ %-30s %s], + m4_format([[%s = %s%s%s]], + b4_symbol([$1], [id]), + b4_symbol([$1], b4_api_token_raw_if([[number]], [[code]])), + m4_if([$1], b4_last_enum_token, [], [[,]])), + [b4_symbol_tag_comment([$1])])])]) + + +# b4_token_enums +# -------------- +# The definition of the token kinds. +m4_define([b4_token_enums], +[b4_any_token_visible_if([[/* Token kinds. */ +#ifndef ]b4_api_PREFIX[TOKENTYPE +# define ]b4_api_PREFIX[TOKENTYPE + enum ]b4_api_prefix[tokentype + { + ]b4_symbol(empty, [id])[ = -2, +]b4_symbol_foreach([b4_token_enum])dnl +[ }; + typedef enum ]b4_api_prefix[tokentype ]b4_api_prefix[token_kind_t; +#endif +]])]) + + +# b4_token_enums_defines +# ---------------------- +# The definition of the tokens (if there are any) as enums and, +# if POSIX Yacc is enabled, as #defines. +m4_define([b4_token_enums_defines], +[b4_token_enums[]b4_yacc_if([b4_token_defines])]) + + +# b4_symbol_translate(STRING) +# --------------------------- +# Used by "bison" in the array of symbol names to mark those that +# require translation. +m4_define([b4_symbol_translate], +[[N_($1)]]) + + + +## -------------- ## +## Symbol kinds. ## +## -------------- ## + +# b4_symbol_enum(SYMBOL-NUM) +# -------------------------- +# Output the definition of this symbol as an enum. +m4_define([b4_symbol_enum], +[m4_format([ %-40s %s], + m4_format([[%s = %s%s%s]], + b4_symbol([$1], [kind_base]), + [$1], + m4_if([$1], b4_last_symbol, [], [[,]])), + [b4_symbol_tag_comment([$1])])]) + + +# b4_declare_symbol_enum +# ---------------------- +# The definition of the symbol internal numbers as an enum. +# Defining YYEMPTY here is important: it forces the compiler +# to use a signed type, which matters for yytoken. +m4_define([b4_declare_symbol_enum], +[[/* Symbol kind. */ +enum yysymbol_kind_t +{ + ]b4_symbol(empty, [kind_base])[ = -2, +]b4_symbol_foreach([b4_symbol_enum])dnl +[}; +typedef enum yysymbol_kind_t yysymbol_kind_t; +]])]) + + +## ----------------- ## +## Semantic Values. ## +## ----------------- ## + + +# b4_symbol_value(VAL, [SYMBOL-NUM], [TYPE-TAG]) +# ---------------------------------------------- +# See README. +m4_define([b4_symbol_value], +[m4_ifval([$3], + [($1.$3)], + [m4_ifval([$2], + [b4_symbol_if([$2], [has_type], + [($1.b4_symbol([$2], [type]))], + [$1])], + [$1])])]) + + +## ---------------------- ## +## Defining C functions. ## +## ---------------------- ## + + +# b4_formals([DECL1, NAME1], ...) +# ------------------------------- +# The formal arguments of a C function definition. +m4_define([b4_formals], +[m4_if([$#], [0], [void], + [$#$1], [1], [void], + [m4_map_sep([b4_formal], [, ], [$@])])]) + +m4_define([b4_formal], +[$1]) + + +# b4_function_declare(NAME, RETURN-VALUE, [DECL1, NAME1], ...) +# ------------------------------------------------------------ +# Declare the function NAME. +m4_define([b4_function_declare], +[$2 $1 (b4_formals(m4_shift2($@)));[]dnl +]) + + + +## --------------------- ## +## Calling C functions. ## +## --------------------- ## + + +# b4_function_call(NAME, RETURN-VALUE, [DECL1, NAME1], ...) +# ----------------------------------------------------------- +# Call the function NAME with arguments NAME1, NAME2 etc. +m4_define([b4_function_call], +[$1 (b4_args(m4_shift2($@)))[]dnl +]) + + +# b4_args([DECL1, NAME1], ...) +# ---------------------------- +# Output the arguments NAME1, NAME2... +m4_define([b4_args], +[m4_map_sep([b4_arg], [, ], [$@])]) + +m4_define([b4_arg], +[$2]) + + +## ----------- ## +## Synclines. ## +## ----------- ## + +# b4_sync_start(LINE, FILE) +# ------------------------- +m4_define([b4_sync_start], [[#]line $1 $2]) + + +## -------------- ## +## User actions. ## +## -------------- ## + +# b4_case(LABEL, STATEMENTS, [COMMENTS]) +# -------------------------------------- +m4_define([b4_case], +[ case $1:m4_ifval([$3], [ b4_comment([$3])]) +$2 +b4_syncline([@oline@], [@ofile@])dnl + break;]) + + +# b4_predicate_case(LABEL, CONDITIONS) +# ------------------------------------ +m4_define([b4_predicate_case], +[ case $1: + if (! ( +$2)) YYERROR; +b4_syncline([@oline@], [@ofile@])dnl + break;]) + + +# b4_yydestruct_define +# -------------------- +# Define the "yydestruct" function. +m4_define_default([b4_yydestruct_define], +[[/*-----------------------------------------------. +| Release the memory associated to this symbol. | +`-----------------------------------------------*/ + +static void +yydestruct (const char *yymsg, + yysymbol_kind_t yykind, YYSTYPE *yyvaluep]b4_locations_if(dnl +[[, YYLTYPE *yylocationp]])[]b4_user_formals[) +{ +]b4_parse_param_use([yyvaluep], [yylocationp])dnl +[ if (!yymsg) + yymsg = "Deleting"; + YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp); + + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + ]b4_symbol_actions([destructor])[ + YY_IGNORE_MAYBE_UNINITIALIZED_END +}]dnl +]) + + +# b4_yy_symbol_print_define +# ------------------------- +# Define the "yy_symbol_print" function. +m4_define_default([b4_yy_symbol_print_define], +[[ +/*-----------------------------------. +| Print this symbol's value on YYO. | +`-----------------------------------*/ + +static void +yy_symbol_value_print (FILE *yyo, + yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep]b4_locations_if(dnl +[[, YYLTYPE const * const yylocationp]])[]b4_user_formals[) +{ + FILE *yyoutput = yyo; +]b4_parse_param_use([yyoutput], [yylocationp])dnl +[ if (!yyvaluep) + return;] +b4_percent_code_get([[pre-printer]])dnl + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + b4_symbol_actions([printer]) + YY_IGNORE_MAYBE_UNINITIALIZED_END +b4_percent_code_get([[post-printer]])dnl +[} + + +/*---------------------------. +| Print this symbol on YYO. | +`---------------------------*/ + +static void +yy_symbol_print (FILE *yyo, + yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep]b4_locations_if(dnl +[[, YYLTYPE const * const yylocationp]])[]b4_user_formals[) +{ + YYFPRINTF (yyo, "%s %s (", + yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind)); + +]b4_locations_if([ YYLOCATION_PRINT (yyo, yylocationp); + YYFPRINTF (yyo, ": "); +])dnl +[ yy_symbol_value_print (yyo, yykind, yyvaluep]dnl +b4_locations_if([, yylocationp])[]b4_user_args[); + YYFPRINTF (yyo, ")"); +}]dnl +]) + + +## ---------------- ## +## api.value.type. ## +## ---------------- ## + + +# ---------------------- # +# api.value.type=union. # +# ---------------------- # + +# b4_symbol_type_register(SYMBOL-NUM) +# ----------------------------------- +# Symbol SYMBOL-NUM has a type (for variant) instead of a type-tag. +# Extend the definition of %union's body (b4_union_members) with a +# field of that type, and extend the symbol's "type" field to point to +# the field name, instead of the type name. +m4_define([b4_symbol_type_register], +[m4_define([b4_symbol($1, type_tag)], + [b4_symbol_if([$1], [has_id], + [b4_symbol([$1], [id])], + [yykind_[]b4_symbol([$1], [number])])])dnl +m4_append([b4_union_members], +m4_expand([m4_format([ %-40s %s], + m4_expand([b4_symbol([$1], [type]) b4_symbol([$1], [type_tag]);]), + [b4_symbol_tag_comment([$1])])])) +]) + + +# b4_type_define_tag(SYMBOL1-NUM, ...) +# ------------------------------------ +# For the batch of symbols SYMBOL1-NUM... (which all have the same +# type), enhance the %union definition for each of them, and set +# there "type" field to the field tag name, instead of the type name. +m4_define([b4_type_define_tag], +[b4_symbol_if([$1], [has_type], + [m4_map([b4_symbol_type_register], [$@])]) +]) + + +# b4_symbol_value_union(VAL, SYMBOL-NUM, [TYPE]) +# ---------------------------------------------- +# Same of b4_symbol_value, but when api.value.type=union. +m4_define([b4_symbol_value_union], +[m4_ifval([$3], + [(*($3*)(&$1))], + [m4_ifval([$2], + [b4_symbol_if([$2], [has_type], + [($1.b4_symbol([$2], [type_tag]))], + [$1])], + [$1])])]) + + +# b4_value_type_setup_union +# ------------------------- +# Setup support for api.value.type=union. Symbols are defined with a +# type instead of a union member name: build the corresponding union, +# and give the symbols their tag. +m4_define([b4_value_type_setup_union], +[m4_define([b4_union_members]) +b4_type_foreach([b4_type_define_tag]) +m4_copy_force([b4_symbol_value_union], [b4_symbol_value]) +]) + + +# -------------------------- # +# api.value.type = variant. # +# -------------------------- # + +# b4_value_type_setup_variant +# --------------------------- +# Setup support for api.value.type=variant. By default, fail, specialized +# by other skeletons. +m4_define([b4_value_type_setup_variant], +[b4_complain_at(b4_percent_define_get_loc([[api.value.type]]), + [['%s' does not support '%s']], + [b4_skeleton], + [%define api.value.type variant])]) + + +# _b4_value_type_setup_keyword +# ---------------------------- +# api.value.type is defined with a keyword/string syntax. Check if +# that is properly defined, and prepare its use. +m4_define([_b4_value_type_setup_keyword], +[b4_percent_define_check_values([[[[api.value.type]], + [[none]], + [[union]], + [[union-directive]], + [[variant]], + [[yystype]]]])dnl +m4_case(b4_percent_define_get([[api.value.type]]), + [union], [b4_value_type_setup_union], + [variant], [b4_value_type_setup_variant])]) + + +# b4_value_type_setup +# ------------------- +# Check if api.value.type is properly defined, and possibly prepare +# its use. +b4_define_silent([b4_value_type_setup], +[# Define default value. +b4_percent_define_ifdef([[api.value.type]], [], +[# %union => api.value.type=union-directive +m4_ifdef([b4_union_members], +[m4_define([b4_percent_define_kind(api.value.type)], [keyword]) +m4_define([b4_percent_define(api.value.type)], [union-directive])], +[# no tag seen => api.value.type={int} +m4_if(b4_tag_seen_flag, 0, +[m4_define([b4_percent_define_kind(api.value.type)], [code]) +m4_define([b4_percent_define(api.value.type)], [int])], +[# otherwise api.value.type=yystype +m4_define([b4_percent_define_kind(api.value.type)], [keyword]) +m4_define([b4_percent_define(api.value.type)], [yystype])])])]) + +# Set up. +m4_bmatch(b4_percent_define_get_kind([[api.value.type]]), + [keyword\|string], [_b4_value_type_setup_keyword]) +]) + + +## -------------- ## +## Declarations. ## +## -------------- ## + + +# b4_value_type_define +# -------------------- +m4_define([b4_value_type_define], +[b4_value_type_setup[]dnl +/* Value type. */ +m4_bmatch(b4_percent_define_get_kind([[api.value.type]]), +[code], +[[#if ! defined ]b4_api_PREFIX[STYPE && ! defined ]b4_api_PREFIX[STYPE_IS_DECLARED +typedef ]b4_percent_define_get([[api.value.type]])[ ]b4_api_PREFIX[STYPE; +# define ]b4_api_PREFIX[STYPE_IS_TRIVIAL 1 +# define ]b4_api_PREFIX[STYPE_IS_DECLARED 1 +#endif +]], +[m4_bmatch(b4_percent_define_get([[api.value.type]]), +[union\|union-directive], +[[#if ! defined ]b4_api_PREFIX[STYPE && ! defined ]b4_api_PREFIX[STYPE_IS_DECLARED +]b4_percent_define_get_syncline([[api.value.union.name]])dnl +[union ]b4_percent_define_get([[api.value.union.name]])[ +{ +]b4_user_union_members[ +}; +]b4_percent_define_get_syncline([[api.value.union.name]])dnl +[typedef union ]b4_percent_define_get([[api.value.union.name]])[ ]b4_api_PREFIX[STYPE; +# define ]b4_api_PREFIX[STYPE_IS_TRIVIAL 1 +# define ]b4_api_PREFIX[STYPE_IS_DECLARED 1 +#endif +]])])]) + + +# b4_location_type_define +# ----------------------- +m4_define([b4_location_type_define], +[[/* Location type. */ +]b4_percent_define_ifdef([[api.location.type]], +[[typedef ]b4_percent_define_get([[api.location.type]])[ ]b4_api_PREFIX[LTYPE; +]], +[[#if ! defined ]b4_api_PREFIX[LTYPE && ! defined ]b4_api_PREFIX[LTYPE_IS_DECLARED +typedef struct ]b4_api_PREFIX[LTYPE ]b4_api_PREFIX[LTYPE; +struct ]b4_api_PREFIX[LTYPE +{ + int first_line; + int first_column; + int last_line; + int last_column; +}; +# define ]b4_api_PREFIX[LTYPE_IS_DECLARED 1 +# define ]b4_api_PREFIX[LTYPE_IS_TRIVIAL 1 +#endif +]])]) + + +# b4_declare_yylstype +# ------------------- +# Declarations that might either go into the header (if --header) or +# in the parser body. Declare YYSTYPE/YYLTYPE, and yylval/yylloc. +m4_define([b4_declare_yylstype], +[b4_value_type_define[]b4_locations_if([ +b4_location_type_define]) + +b4_pure_if([], [[extern ]b4_api_PREFIX[STYPE ]b4_prefix[lval; +]b4_locations_if([[extern ]b4_api_PREFIX[LTYPE ]b4_prefix[lloc;]])])[]dnl +]) + + +# b4_YYDEBUG_define +# ----------------- +m4_define([b4_YYDEBUG_define], +[[/* Debug traces. */ +]m4_if(b4_api_prefix, [yy], +[[#ifndef YYDEBUG +# define YYDEBUG ]b4_parse_trace_if([1], [0])[ +#endif]], +[[#ifndef ]b4_api_PREFIX[DEBUG +# if defined YYDEBUG +#if YYDEBUG +# define ]b4_api_PREFIX[DEBUG 1 +# else +# define ]b4_api_PREFIX[DEBUG 0 +# endif +# else /* ! defined YYDEBUG */ +# define ]b4_api_PREFIX[DEBUG ]b4_parse_trace_if([1], [0])[ +# endif /* ! defined YYDEBUG */ +#endif /* ! defined ]b4_api_PREFIX[DEBUG */]])[]dnl +]) + +# b4_declare_yydebug +# ------------------ +m4_define([b4_declare_yydebug], +[b4_YYDEBUG_define[ +#if ]b4_api_PREFIX[DEBUG +extern int ]b4_prefix[debug; +#endif][]dnl +]) + +# b4_yylloc_default_define +# ------------------------ +# Define YYLLOC_DEFAULT. +m4_define([b4_yylloc_default_define], +[[/* 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). */ + +#ifndef YYLLOC_DEFAULT +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (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 (0) +#endif +]]) + +# b4_yylocation_print_define +# -------------------------- +# Define YYLOCATION_PRINT. +m4_define([b4_yylocation_print_define], +[b4_locations_if([[ +/* YYLOCATION_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. */ + +# ifndef YYLOCATION_PRINT + +# if defined YY_LOCATION_PRINT + + /* Temporary convenience wrapper in case some people defined the + undocumented and private YY_LOCATION_PRINT macros. */ +# define YYLOCATION_PRINT(File, Loc) YY_LOCATION_PRINT(File, *(Loc)) + +# elif defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL + +/* Print *YYLOCP on YYO. Private, do not rely on its existence. */ + +YY_ATTRIBUTE_UNUSED +static int +yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp) +{ + int res = 0; + int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0; + if (0 <= yylocp->first_line) + { + res += YYFPRINTF (yyo, "%d", yylocp->first_line); + if (0 <= yylocp->first_column) + res += YYFPRINTF (yyo, ".%d", yylocp->first_column); + } + if (0 <= yylocp->last_line) + { + if (yylocp->first_line < yylocp->last_line) + { + res += YYFPRINTF (yyo, "-%d", yylocp->last_line); + if (0 <= end_col) + res += YYFPRINTF (yyo, ".%d", end_col); + } + else if (0 <= end_col && yylocp->first_column < end_col) + res += YYFPRINTF (yyo, "-%d", end_col); + } + return res; +} + +# define YYLOCATION_PRINT yy_location_print_ + + /* Temporary convenience wrapper in case some people defined the + undocumented and private YY_LOCATION_PRINT macros. */ +# define YY_LOCATION_PRINT(File, Loc) YYLOCATION_PRINT(File, &(Loc)) + +# else + +# define YYLOCATION_PRINT(File, Loc) ((void) 0) + /* Temporary convenience wrapper in case some people defined the + undocumented and private YY_LOCATION_PRINT macros. */ +# define YY_LOCATION_PRINT YYLOCATION_PRINT + +# endif +# endif /* !defined YYLOCATION_PRINT */]]) +]) + +# b4_yyloc_default +# ---------------- +# Expand to a possible default value for yylloc. +m4_define([b4_yyloc_default], +[[ +# if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL + = { ]m4_join([, ], + m4_defn([b4_location_initial_line]), + m4_defn([b4_location_initial_column]), + m4_defn([b4_location_initial_line]), + m4_defn([b4_location_initial_column]))[ } +# endif +]]) diff --git a/Engine/bin/bison-flex/data/skeletons/d-skel.m4 b/Engine/bin/bison-flex/data/skeletons/d-skel.m4 new file mode 100644 index 000000000..2a38f02f2 --- /dev/null +++ b/Engine/bin/bison-flex/data/skeletons/d-skel.m4 @@ -0,0 +1,26 @@ + -*- Autoconf -*- + +# D skeleton dispatching for Bison. + +# Copyright (C) 2018-2021 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +b4_glr_if( [b4_complain([%%glr-parser not supported for D])]) +b4_nondeterministic_if([b4_complain([%%nondeterministic-parser not supported for D])]) + +m4_define_default([b4_used_skeleton], [b4_skeletonsdir/[lalr1.d]]) +m4_define_default([b4_skeleton], ["b4_basename(b4_used_skeleton)"]) + +m4_include(b4_used_skeleton) diff --git a/Engine/bin/bison-flex/data/skeletons/d.m4 b/Engine/bin/bison-flex/data/skeletons/d.m4 new file mode 100644 index 000000000..c0632e472 --- /dev/null +++ b/Engine/bin/bison-flex/data/skeletons/d.m4 @@ -0,0 +1,628 @@ + -*- Autoconf -*- + +# D language support for Bison + +# Copyright (C) 2018-2021 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +m4_include(b4_skeletonsdir/[c-like.m4]) + + +# b4_symbol_action(SYMBOL-NUM, ACTION) +# ------------------------------------ +# Run the action ACTION ("destructor" or "printer") for SYMBOL-NUM. +m4_define([b4_symbol_action], +[b4_symbol_if([$1], [has_$2], +[b4_dollar_pushdef([yyval], + [$1], + [], + [yyloc])dnl + _b4_symbol_case([$1])[]dnl +b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl +b4_symbol([$1], [$2]) +b4_syncline([@oline@], [@ofile@])dnl + break; + +b4_dollar_popdef[]dnl +])]) + + +# b4_use(EXPR) +# ------------ +# Pacify the compiler about some maybe unused value. +m4_define([b4_use], +[]) + + +# b4_sync_start(LINE, FILE) +# ------------------------- +m4_define([b4_sync_start], [[#]line $1 $2]) + + +# b4_list2(LIST1, LIST2) +# ---------------------- +# Join two lists with a comma if necessary. +m4_define([b4_list2], + [$1[]m4_ifval(m4_quote($1), [m4_ifval(m4_quote($2), [[, ]])])[]$2]) + + +# b4_percent_define_get3(DEF, PRE, POST, NOT) +# ------------------------------------------- +# Expand to the value of DEF surrounded by PRE and POST if it's %define'ed, +# otherwise NOT. +m4_define([b4_percent_define_get3], + [m4_ifval(m4_quote(b4_percent_define_get([$1])), + [$2[]b4_percent_define_get([$1])[]$3], [$4])]) + +# b4_percent_define_if_get2(ARG1, ARG2, DEF, NOT) +# ----------------------------------------------- +# Expand to the value of DEF if ARG1 or ARG2 are %define'ed, +# otherwise NOT. +m4_define([b4_percent_define_if_get2], + [m4_ifval(m4_quote(b4_percent_define_get([$1])), + [$3], [m4_ifval(m4_quote(b4_percent_define_get([$2])), + [$3], [$4])])]) + +# b4_percent_define_class_before_interface(CLASS, INTERFACE) +# ---------------------------------------------------------- +# Expand to a ', ' if both a class and an interface have been %define'ed +m4_define([b4_percent_define_class_before_interface], + [m4_ifval(m4_quote(b4_percent_define_get([$1])), + [m4_ifval(m4_quote(b4_percent_define_get([$2])), + [, ])])]) + + +# b4_flag_value(BOOLEAN-FLAG) +# --------------------------- +m4_define([b4_flag_value], [b4_flag_if([$1], [true], [false])]) + + +# b4_parser_class_declaration +# --------------------------- +# The declaration of the parser class ("class YYParser"), with all its +# qualifiers/annotations. +b4_percent_define_default([[api.parser.abstract]], [[false]]) +b4_percent_define_default([[api.parser.final]], [[false]]) +b4_percent_define_default([[api.parser.public]], [[false]]) + +m4_define([b4_parser_class_declaration], +[b4_percent_define_get3([api.parser.annotations], [], [ ])dnl +b4_percent_define_flag_if([api.parser.public], [public ])dnl +b4_percent_define_flag_if([api.parser.abstract], [abstract ])dnl +b4_percent_define_flag_if([api.parser.final], [final ])dnl +[class ]b4_parser_class[]dnl +b4_percent_define_if_get2([api.parser.extends], [api.parser.implements], [ : ])dnl +b4_percent_define_get([api.parser.extends])dnl +b4_percent_define_class_before_interface([api.parser.extends], [api.parser.implements])dnl +b4_percent_define_get([api.parser.implements])]) + + +# b4_lexer_if(TRUE, FALSE) +# ------------------------ +m4_define([b4_lexer_if], +[b4_percent_code_ifdef([[lexer]], [$1], [$2])]) + + +# b4_position_type_if(TRUE, FALSE) +# -------------------------------- +m4_define([b4_position_type_if], +[b4_percent_define_ifdef([[position_type]], [$1], [$2])]) + + +# b4_location_type_if(TRUE, FALSE) +# -------------------------------- +m4_define([b4_location_type_if], +[b4_percent_define_ifdef([[location_type]], [$1], [$2])]) + + +# b4_identification +# ----------------- +m4_define([b4_identification], +[[/** Version number for the Bison executable that generated this parser. */ + public static immutable string yy_bison_version = "]b4_version_string["; + + /** Name of the skeleton that generated this parser. */ + public static immutable string yy_bison_skeleton = ]b4_skeleton[; +]]) + + +## ------------ ## +## Data types. ## +## ------------ ## + +# b4_int_type(MIN, MAX) +# --------------------- +# Return the smallest int type able to handle numbers ranging from +# MIN to MAX (included). +m4_define([b4_int_type], +[m4_if(b4_ints_in($@, [-128], [127]), [1], [byte], + b4_ints_in($@, [-32768], [32767]), [1], [short], + [int])]) + +# b4_int_type_for(NAME) +# --------------------- +# Return the smallest int type able to handle numbers ranging from +# `NAME_min' to `NAME_max' (included). +m4_define([b4_int_type_for], +[b4_int_type($1_min, $1_max)]) + +# b4_null +# ------- +m4_define([b4_null], [null]) + + +# b4_integral_parser_table_define(NAME, DATA, COMMENT) +#----------------------------------------------------- +# Define "yy" whose contents is CONTENT. +m4_define([b4_integral_parser_table_define], +[m4_ifvaln([$3], [b4_comment([$3], [ ])])dnl +private static immutable b4_int_type_for([$2])[[]] yy$1_ = +@{ + $2 +@};dnl +]) + + +## ------------- ## +## Token kinds. ## +## ------------- ## + +m4_define([b4_symbol(-2, id)], [[YYEMPTY]]) +b4_percent_define_default([[api.token.raw]], [[true]]) + +# b4_token_enum(TOKEN-NAME, TOKEN-NUMBER) +# --------------------------------------- +# Output the definition of this token as an enum. +m4_define([b4_token_enum], +[b4_token_format([ %s = %s, +], [$1])]) + +# b4_token_enums +# -------------- +# Output the definition of the tokens as enums. +m4_define([b4_token_enums], +[/* Token kinds. */ +public enum TokenKind { + ]b4_symbol(empty, id)[ = -2, +b4_symbol_foreach([b4_token_enum])dnl +} +]) + +# b4_symbol_translate(STRING) +# --------------------------- +# Used by "bison" in the array of symbol names to mark those that +# require translation. +m4_define([b4_symbol_translate], +[[_($1)]]) + + +# _b4_token_constructor_define(SYMBOL-NUM) +# ---------------------------------------- +# Define Symbol.FOO for SYMBOL-NUM. +m4_define([_b4_token_constructor_define], +[b4_token_visible_if([$1], +[[ + static auto ]b4_symbol([$1], [id])[(]b4_symbol_if([$1], [has_type], +[b4_union_if([b4_symbol([$1], [type]], +[[typeof(YYSemanticType.]b4_symbol([$1], [type])[]])) [val]])dnl +[]b4_locations_if([b4_symbol_if([$1], [has_type], [[, ]])[Location l]])[) + { + return Symbol(TokenKind.]b4_symbol([$1], [id])[]b4_symbol_if([$1], [has_type], + [[, val]])[]b4_locations_if([[, l]])[); + }]])]) + +# b4_token_constructor_define +# --------------------------- +# Define Symbol.FOO for each token kind FOO. +m4_define([b4_token_constructor_define], +[[ + /* Implementation of token constructors for each symbol type visible to + * the user. The code generates static methods that have the same names + * as the TokenKinds. + */]b4_symbol_foreach([_b4_token_constructor_define])dnl +]) + +## -------------- ## +## Symbol kinds. ## +## -------------- ## + +# b4_symbol_kind(NUM) +# ------------------- +m4_define([b4_symbol_kind], +[SymbolKind.b4_symbol_kind_base($@)]) + + +# b4_symbol_enum(SYMBOL-NUM) +# -------------------------- +# Output the definition of this symbol as an enum. +m4_define([b4_symbol_enum], +[m4_format([ %-30s %s], + m4_format([[%s = %s,]], + b4_symbol([$1], [kind_base]), + [$1]), + [b4_symbol_tag_comment([$1])])]) + + +# b4_declare_symbol_enum +# ---------------------- +# The definition of the symbol internal numbers as an enum. +# Defining YYEMPTY here is important: it forces the compiler +# to use a signed type, which matters for yytoken. +m4_define([b4_declare_symbol_enum], +[[ /* Symbol kinds. */ + struct SymbolKind + { + enum + { + ]b4_symbol(empty, kind_base)[ = -2, /* No symbol. */ +]b4_symbol_foreach([b4_symbol_enum])dnl +[ } + + private int yycode_; + alias yycode_ this; + + this(int code) + { + yycode_ = code; + } + + /* Return YYSTR after stripping away unnecessary quotes and + backslashes, so that it's suitable for yyerror. The heuristic is + that double-quoting is unnecessary unless the string contains an + apostrophe, a comma, or backslash (other than backslash-backslash). + YYSTR is taken from yytname. */ + final void toString(W)(W sink) const + if (isOutputRange!(W, char)) + { + immutable string[] yy_sname = @{ + ]b4_symbol_names[ + @};]b4_has_translations_if([[ + /* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is + internationalizable. */ + immutable ]b4_int_type_for([b4_translatable])[[] yytranslatable = @{ + ]b4_translatable[ + @};]])[ + + put(sink, yy_sname[yycode_]); + } + } +]]) + + +# b4_case(ID, CODE, [COMMENTS]) +# ----------------------------- +m4_define([b4_case], [ case $1:m4_ifval([$3], [ b4_comment([$3])]) +$2 + break;]) + + +## ---------------- ## +## Default values. ## +## ---------------- ## + +m4_define([b4_yystype], [b4_percent_define_get([[stype]])]) +b4_percent_define_default([[stype]], [[YYSemanticType]])]) + +# %name-prefix +m4_define_default([b4_prefix], [[YY]]) + +b4_percent_define_default([[api.parser.class]], [b4_prefix[]Parser])]) +m4_define([b4_parser_class], [b4_percent_define_get([[api.parser.class]])]) + +#b4_percent_define_default([[location_type]], [Location])]) +m4_define([b4_location_type], b4_percent_define_ifdef([[location_type]],[b4_percent_define_get([[location_type]])],[YYLocation])) + +#b4_percent_define_default([[position_type]], [Position])]) +m4_define([b4_position_type], b4_percent_define_ifdef([[position_type]],[b4_percent_define_get([[position_type]])],[YYPosition])) + + +## ---------------- ## +## api.value.type. ## +## ---------------- ## + + +# ---------------------- # +# api.value.type=union. # +# ---------------------- # + +# b4_symbol_type_register(SYMBOL-NUM) +# ----------------------------------- +# Symbol SYMBOL-NUM has a type (for union) instead of a type-tag. +# Extend the definition of %union's body (b4_union_members) with a +# field of that type, and extend the symbol's "type" field to point to +# the field name, instead of the type name. +m4_define([b4_symbol_type_register], +[m4_define([b4_symbol($1, type_tag)], + [b4_symbol_if([$1], [has_id], + [b4_symbol([$1], [id])], + [yykind_[]b4_symbol([$1], [number])])])dnl +m4_append([b4_union_members], +m4_expand([m4_format([ %-40s %s], + m4_expand([b4_symbol([$1], [type]) b4_symbol([$1], [type_tag]);]), + [b4_symbol_tag_comment([$1])])])) +]) + + +# b4_type_define_tag(SYMBOL1-NUM, ...) +# ------------------------------------ +# For the batch of symbols SYMBOL1-NUM... (which all have the same +# type), enhance the %union definition for each of them, and set +# there "type" field to the field tag name, instead of the type name. +m4_define([b4_type_define_tag], +[b4_symbol_if([$1], [has_type], + [m4_map([b4_symbol_type_register], [$@])]) +]) + + +# b4_symbol_value_union(VAL, SYMBOL-NUM, [TYPE]) +# ---------------------------------------------- +# Same of b4_symbol_value, but when api.value.type=union. +m4_define([b4_symbol_value_union], +[m4_ifval([$3], + [(*($3*)(&$1))], + [m4_ifval([$2], + [b4_symbol_if([$2], [has_type], + [($1.b4_symbol([$2], [type_tag]))], + [$1])], + [$1])])]) + + +# b4_value_type_setup_union +# ------------------------- +# Setup support for api.value.type=union. Symbols are defined with a +# type instead of a union member name: build the corresponding union, +# and give the symbols their tag. +m4_define([b4_value_type_setup_union], +[m4_define([b4_union_members]) +b4_type_foreach([b4_type_define_tag]) +m4_copy_force([b4_symbol_value_union], [b4_symbol_value]) +]) + + +# _b4_value_type_setup_keyword +# ---------------------------- +# api.value.type is defined with a keyword/string syntax. Check if +# that is properly defined, and prepare its use. +m4_define([_b4_value_type_setup_keyword], +[b4_percent_define_check_values([[[[api.value.type]], + [[none]], + [[union]], + [[union-directive]], + [[yystype]]]])dnl +m4_case(b4_percent_define_get([[api.value.type]]), + [union], [b4_value_type_setup_union])]) + + +# b4_value_type_setup +# ------------------- +# Check if api.value.type is properly defined, and possibly prepare +# its use. +b4_define_silent([b4_value_type_setup], +[ +# Define default value. +b4_percent_define_ifdef([[api.value.type]], [], +[# %union => api.value.type=union-directive +m4_ifdef([b4_union_members], +[m4_define([b4_percent_define_kind(api.value.type)], [keyword]) +m4_define([b4_percent_define(api.value.type)], [union-directive])], +[# no tag seen => api.value.type={int} +m4_if(b4_tag_seen_flag, 0, +[m4_define([b4_percent_define_kind(api.value.type)], [code]) +m4_define([b4_percent_define(api.value.type)], [int])], +[# otherwise api.value.type=yystype +m4_define([b4_percent_define_kind(api.value.type)], [keyword]) +m4_define([b4_percent_define(api.value.type)], [yystype])])])]) + +# Set up. +m4_bmatch(b4_percent_define_get_kind([[api.value.type]]), + [keyword], [_b4_value_type_setup_keyword]) +]) + + +## ----------------- ## +## Semantic Values. ## +## ----------------- ## + + +# b4_symbol_value(VAL, [SYMBOL-NUM], [TYPE-TAG]) +# ---------------------------------------------- +# See README. FIXME: factor in c-like? +m4_define([b4_symbol_value], +[m4_ifval([$3], + [($1.$3)], + [m4_ifval([$2], + [b4_symbol_if([$2], [has_type], + [($1.b4_symbol([$2], [type]))], + [$1])], + [$1])])]) + +# b4_lhs_value(SYMBOL-NUM, [TYPE]) +# -------------------------------- +# See README. +m4_define([b4_lhs_value], +[b4_symbol_value([yyval], [$1], [$2])]) + + +# b4_rhs_value(RULE-LENGTH, POS, SYMBOL-NUM, [TYPE]) +# -------------------------------------------------- +# See README. +# +# In this simple implementation, %token and %type have class names +# between the angle brackets. +m4_define([b4_rhs_value], +[b4_symbol_value([(yystack.valueAt (b4_subtract([$1], [$2])))], [$3], [$4])]) + + +# b4_lhs_location() +# ----------------- +# Expansion of @$. +m4_define([b4_lhs_location], +[(yyloc)]) + + +# b4_rhs_location(RULE-LENGTH, POS) +# --------------------------------- +# Expansion of @POS, where the current rule has RULE-LENGTH symbols +# on RHS. +m4_define([b4_rhs_location], +[yystack.locationAt (b4_subtract($@))]) + + +# b4_lex_param +# b4_parse_param +# -------------- +# If defined, b4_lex_param arrives double quoted, but below we prefer +# it to be single quoted. Same for b4_parse_param. + +# TODO: should be in bison.m4 +m4_define_default([b4_lex_param], [[]])) +m4_define([b4_lex_param], b4_lex_param)) +m4_define([b4_parse_param], b4_parse_param)) + +# b4_lex_param_decl +# ------------------- +# Extra formal arguments of the constructor. +m4_define([b4_lex_param_decl], +[m4_ifset([b4_lex_param], + [b4_remove_comma([$1], + b4_param_decls(b4_lex_param))], + [$1])]) + +m4_define([b4_param_decls], + [m4_map([b4_param_decl], [$@])]) +m4_define([b4_param_decl], [, $1]) + +m4_define([b4_remove_comma], [m4_ifval(m4_quote($1), [$1, ], [])m4_shift2($@)]) + + + +# b4_parse_param_decl +# ------------------- +# Extra formal arguments of the constructor. +m4_define([b4_parse_param_decl], +[m4_ifset([b4_parse_param], + [b4_remove_comma([$1], + b4_param_decls(b4_parse_param))], + [$1])]) + + + +# b4_lex_param_call +# ------------------- +# Delegating the lexer parameters to the lexer constructor. +m4_define([b4_lex_param_call], + [m4_ifset([b4_lex_param], + [b4_remove_comma([$1], + b4_param_calls(b4_lex_param))], + [$1])]) +m4_define([b4_param_calls], + [m4_map([b4_param_call], [$@])]) +m4_define([b4_param_call], [, $2]) + + + +# b4_parse_param_cons +# ------------------- +# Extra initialisations of the constructor. +m4_define([b4_parse_param_cons], + [m4_ifset([b4_parse_param], + [b4_constructor_calls(b4_parse_param)])]) + +m4_define([b4_constructor_calls], + [m4_map([b4_constructor_call], [$@])]) +m4_define([b4_constructor_call], + [this.$2 = $2; + ]) + + + +# b4_parse_param_vars +# ------------------- +# Extra instance variables. +m4_define([b4_parse_param_vars], + [m4_ifset([b4_parse_param], + [ + /* User arguments. */ +b4_var_decls(b4_parse_param)])]) + +m4_define([b4_var_decls], + [m4_map_sep([b4_var_decl], [ +], [$@])]) +m4_define([b4_var_decl], + [ protected $1;]) + + +# b4_public_types_declare +# ----------------------- +# Define the public types: token, semantic value, location, and so forth. +# Depending on %define token_lex, may be output in the header or source file. +m4_define([b4_public_types_declare], +[[ +alias Symbol = ]b4_parser_class[.Symbol; +alias Value = ]b4_yystype[;]b4_locations_if([[ +alias Location = ]b4_location_type[; +alias Position = ]b4_position_type[;]b4_push_if([[ +alias PUSH_MORE = ]b4_parser_class[.YYPUSH_MORE; +alias ABORT = ]b4_parser_class[.YYABORT; +alias ACCEPT = ]b4_parser_class[.YYACCEPT;]])[]])[ +]]) + + +# b4_basic_symbol_constructor_define +# ---------------------------------- +# Create Symbol struct constructors for all the visible types. +m4_define([b4_basic_symbol_constructor_define], +[b4_token_visible_if([$1], +[[ this(TokenKind token]b4_symbol_if([$1], [has_type], +[[, ]b4_union_if([], [[typeof(YYSemanticType.]])b4_symbol([$1], [type])dnl +[]b4_union_if([], [[) ]])[ val]])[]b4_locations_if([[, Location loc]])[) + { + kind = yytranslate_(token);]b4_union_if([b4_symbol_if([$1], [has_type], [[ + static foreach (member; __traits(allMembers, YYSemanticType)) + { + static if (is(typeof(mixin("value_." ~ member)) == ]b4_symbol([$1], [type])[)) + { + mixin("value_." ~ member ~ " = val;"); + } + }]])], [b4_symbol_if([$1], [has_type], [[ + value_.]b4_symbol([$1], [type])[ = val;]])])[]b4_locations_if([ + location_ = loc;])[ + } +]])]) + + +# b4_symbol_type_define +# --------------------- +# Define symbol_type, the external type for symbols used for symbol +# constructors. +m4_define([b4_symbol_type_define], +[[ + /** + * A complete symbol + */ + struct Symbol + { + private SymbolKind kind; + private Value value_;]b4_locations_if([[ + private Location location_;]])[ + +]b4_type_foreach([b4_basic_symbol_constructor_define])[ + SymbolKind token() { return kind; } + Value value() { return value_; }]b4_locations_if([[ + Location location() { return location_; }]])[ +]b4_token_ctor_if([b4_token_constructor_define])[ + } +]]) diff --git a/Engine/bin/bison-flex/data/skeletons/glr.c b/Engine/bin/bison-flex/data/skeletons/glr.c new file mode 100644 index 000000000..fab3733f1 --- /dev/null +++ b/Engine/bin/bison-flex/data/skeletons/glr.c @@ -0,0 +1,2763 @@ +# -*- C -*- + +# GLR skeleton for Bison + +# Copyright (C) 2002-2015, 2018-2021 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +# If we are loaded by glr.cc, do not override c++.m4 definitions by +# those of c.m4. +m4_if(b4_skeleton, ["glr.c"], + [m4_include(b4_skeletonsdir/[c.m4])]) + + +## ---------------- ## +## Default values. ## +## ---------------- ## + +# Stack parameters. +m4_define_default([b4_stack_depth_max], [10000]) +m4_define_default([b4_stack_depth_init], [200]) + +# Included header. +b4_percent_define_default([[api.header.include]], + [["@basename(]b4_spec_header_file[@)"]]) + +## ------------------------ ## +## Pure/impure interfaces. ## +## ------------------------ ## + +b4_define_flag_if([pure]) +# If glr.cc is including this file and thus has already set b4_pure_flag, +# do not change the value of b4_pure_flag, and do not record a use of api.pure. +m4_ifndef([b4_pure_flag], +[b4_percent_define_default([[api.pure]], [[false]]) + m4_define([b4_pure_flag], + [b4_percent_define_flag_if([[api.pure]], [[1]], [[0]])])]) + +# b4_yyerror_args +# --------------- +# Optional effective arguments passed to yyerror: user args plus yylloc, and +# a trailing comma. +m4_define([b4_yyerror_args], +[b4_pure_if([b4_locations_if([yylocp, ])])dnl +m4_ifset([b4_parse_param], [b4_args(b4_parse_param), ])]) + + +# b4_lyyerror_args +# ---------------- +# Same as above, but on the lookahead, hence &yylloc instead of yylocp. +m4_define([b4_lyyerror_args], +[b4_pure_if([b4_locations_if([&yylloc, ])])dnl +m4_ifset([b4_parse_param], [b4_args(b4_parse_param), ])]) + + +# b4_pure_args +# ------------ +# Same as b4_yyerror_args, but with a leading comma. +m4_define([b4_pure_args], +[b4_pure_if([b4_locations_if([, yylocp])])[]b4_user_args]) + + +# b4_lpure_args +# ------------- +# Same as above, but on the lookahead, hence &yylloc instead of yylocp. +m4_define([b4_lpure_args], +[b4_pure_if([b4_locations_if([, &yylloc])])[]b4_user_args]) + + + +# b4_pure_formals +# --------------- +# Arguments passed to yyerror: user formals plus yylocp with leading comma. +m4_define([b4_pure_formals], +[b4_pure_if([b4_locations_if([, YYLTYPE *yylocp])])[]b4_user_formals]) + + +# b4_locuser_formals(LOC = yylocp) +# -------------------------------- +# User formal arguments, possibly preceded by location argument. +m4_define([b4_locuser_formals], +[b4_locations_if([, YYLTYPE *m4_default([$1], [yylocp])])[]b4_user_formals]) + + +# b4_locuser_args(LOC = yylocp) +# ----------------------------- +m4_define([b4_locuser_args], +[b4_locations_if([, m4_default([$1], [yylocp])])[]b4_user_args]) + + + +## ----------------- ## +## Semantic Values. ## +## ----------------- ## + + +# b4_lhs_value(SYMBOL-NUM, [TYPE]) +# -------------------------------- +# See README. +m4_define([b4_lhs_value], +[b4_symbol_value([(*yyvalp)], [$1], [$2])]) + + +# b4_rhs_data(RULE-LENGTH, POS) +# ----------------------------- +# See README. +m4_define([b4_rhs_data], +[YY_CAST (yyGLRStackItem const *, yyvsp)@{YYFILL (b4_subtract([$2], [$1]))@}.yystate]) + + +# b4_rhs_value(RULE-LENGTH, POS, SYMBOL-NUM, [TYPE]) +# -------------------------------------------------- +# Expansion of $$ or $$, for symbol SYMBOL-NUM. +m4_define([b4_rhs_value], +[b4_symbol_value([b4_rhs_data([$1], [$2]).yysemantics.yyval], [$3], [$4])]) + + + +## ----------- ## +## Locations. ## +## ----------- ## + +# b4_lhs_location() +# ----------------- +# Expansion of @$. +m4_define([b4_lhs_location], +[(*yylocp)]) + + +# b4_rhs_location(RULE-LENGTH, NUM) +# --------------------------------- +# Expansion of @NUM, where the current rule has RULE-LENGTH symbols +# on RHS. +m4_define([b4_rhs_location], +[(b4_rhs_data([$1], [$2]).yyloc)]) + + +# b4_call_merger(MERGER-NUM, MERGER-NAME, SYMBOL-SUM) +# --------------------------------------------------- +m4_define([b4_call_merger], +[b4_case([$1], + [ b4_symbol_if([$3], [has_type], + [yy0->b4_symbol($3, slot) = $2 (*yy0, *yy1);], + [*yy0 = $2 (*yy0, *yy1);])])]) + + +## -------------- ## +## Declarations. ## +## -------------- ## + +# b4_shared_declarations +# ---------------------- +# Declaration that might either go into the header (if --header) +# or open coded in the parser body. glr.cc has its own definition. +m4_if(b4_skeleton, ["glr.c"], +[m4_define([b4_shared_declarations], +[b4_declare_yydebug[ +]b4_percent_code_get([[requires]])[ +]b4_token_enums[ +]b4_declare_yylstype[ +int ]b4_prefix[parse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[); +]b4_percent_code_get([[provides]])[]dnl +]) +]) + +## -------------- ## +## Output files. ## +## -------------- ## + +# Unfortunately the order of generation between the header and the +# implementation file matters (for glr.c) because of the current +# implementation of api.value.type=union. In that case we still use a +# union for YYSTYPE, but we generate the contents of this union when +# setting up YYSTYPE. This is needed for other aspects, such as +# defining yy_symbol_value_print, since we need to now the name of the +# members of this union. +# +# To avoid this issue, just generate the header before the +# implementation file. But we should also make them more independent. + +# ----------------- # +# The header file. # +# ----------------- # + +# glr.cc produces its own header. +b4_glr_cc_if([], +[b4_header_if( +[b4_output_begin([b4_spec_header_file]) +b4_copyright([Skeleton interface for Bison GLR parsers in C], + [2002-2015, 2018-2021])[ +]b4_cpp_guard_open([b4_spec_mapped_header_file])[ +]b4_shared_declarations[ +]b4_cpp_guard_close([b4_spec_mapped_header_file])[ +]b4_output_end[ +]])]) + + +# ------------------------- # +# The implementation file. # +# ------------------------- # + +b4_output_begin([b4_parser_file_name]) +b4_copyright([Skeleton implementation for Bison GLR parsers in C], + [2002-2015, 2018-2021])[ +/* C GLR parser skeleton written by Paul Hilfinger. */ + +]b4_disclaimer[ +]b4_identification[ + +]b4_percent_code_get([[top]])[ +]m4_if(b4_api_prefix, [yy], [], +[[/* Substitute the type names. */ +#define YYSTYPE ]b4_api_PREFIX[STYPE]b4_locations_if([[ +#define YYLTYPE ]b4_api_PREFIX[LTYPE]])])[ +]m4_if(b4_prefix, [yy], [], +[[/* Substitute the variable and function names. */ +#define ]b4_glr_cc_if([yy_parse_impl], [yyparse])[ ]b4_prefix[]b4_glr_cc_if([_parse_impl], [parse])[ +#define yylex ]b4_prefix[lex +#define yyerror ]b4_prefix[error +#define yydebug ]b4_prefix[debug]]b4_pure_if([], [[ +#define yylval ]b4_prefix[lval +#define yychar ]b4_prefix[char +#define yynerrs ]b4_prefix[nerrs]b4_locations_if([[ +#define yylloc ]b4_prefix[lloc]])]))[ + +]b4_user_pre_prologue[ +]b4_cast_define[ +]b4_null_define[ + +]b4_header_if([[#include ]b4_percent_define_get([[api.header.include]])], + [b4_shared_declarations])[ + +]b4_glr_cc_if([b4_glr_cc_setup], + [b4_declare_symbol_enum])[ + +/* Default (constant) value used for initialization for null + right-hand sides. Unlike the standard yacc.c template, here we set + the default value of $$ to a zeroed-out value. Since the default + value is undefined, this behavior is technically correct. */ +static YYSTYPE yyval_default;]b4_locations_if([[ +static YYLTYPE yyloc_default][]b4_yyloc_default;])[ + +]b4_user_post_prologue[ +]b4_percent_code_get[]dnl + +[#include +#include +#include +#include +#include + +]b4_c99_int_type_define[ +]b4_sizes_types_define[ + +#ifndef YY_ +# if defined YYENABLE_NLS && YYENABLE_NLS +# if ENABLE_NLS +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_(Msgid) dgettext ("bison-runtime", Msgid) +# endif +# endif +# ifndef YY_ +# define YY_(Msgid) Msgid +# endif +#endif +]b4_has_translations_if([ +#ifndef N_ +# define N_(Msgid) Msgid +#endif +])[ + +#ifndef YYFREE +# define YYFREE free +#endif +#ifndef YYMALLOC +# define YYMALLOC malloc +#endif +#ifndef YYREALLOC +# define YYREALLOC realloc +#endif + +#ifdef __cplusplus + typedef bool yybool; +# define yytrue true +# define yyfalse false +#else + /* When we move to stdbool, get rid of the various casts to yybool. */ + typedef signed char yybool; +# define yytrue 1 +# define yyfalse 0 +#endif + +#ifndef YYSETJMP +# include +# define YYJMP_BUF jmp_buf +# define YYSETJMP(Env) setjmp (Env) +/* Pacify Clang and ICC. */ +# define YYLONGJMP(Env, Val) \ + do { \ + longjmp (Env, Val); \ + YY_ASSERT (0); \ + } while (yyfalse) +#endif + +]b4_attribute_define([noreturn])[ + +]b4_parse_assert_if([[#ifdef NDEBUG +# define YY_ASSERT(E) ((void) (0 && (E))) +#else +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_ASSERT(E) assert (E) +#endif +]], +[[#define YY_ASSERT(E) ((void) (0 && (E)))]])[ + +/* YYFINAL -- State number of the termination state. */ +#define YYFINAL ]b4_final_state_number[ +/* YYLAST -- Last index in YYTABLE. */ +#define YYLAST ]b4_last[ + +/* YYNTOKENS -- Number of terminals. */ +#define YYNTOKENS ]b4_tokens_number[ +/* YYNNTS -- Number of nonterminals. */ +#define YYNNTS ]b4_nterms_number[ +/* YYNRULES -- Number of rules. */ +#define YYNRULES ]b4_rules_number[ +/* YYNSTATES -- Number of states. */ +#define YYNSTATES ]b4_states_number[ +/* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */ +#define YYMAXRHS ]b4_r2_max[ +/* YYMAXLEFT -- Maximum number of symbols to the left of a handle + accessed by $0, $-1, etc., in any rule. */ +#define YYMAXLEFT ]b4_max_left_semantic_context[ + +/* YYMAXUTOK -- Last valid token kind. */ +#define YYMAXUTOK ]b4_code_max[ + +/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM + as returned by yylex, with out-of-bounds checking. */ +]b4_api_token_raw_if(dnl +[[#define YYTRANSLATE(YYX) YY_CAST (yysymbol_kind_t, YYX)]], +[[#define YYTRANSLATE(YYX) \ + (0 <= (YYX) && (YYX) <= YYMAXUTOK \ + ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \ + : ]b4_symbol_prefix[YYUNDEF) + +/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM + as returned by yylex. */ +static const ]b4_int_type_for([b4_translate])[ yytranslate[] = +{ + ]b4_translate[ +};]])[ + +#if ]b4_api_PREFIX[DEBUG +/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ +static const ]b4_int_type_for([b4_rline])[ yyrline[] = +{ + ]b4_rline[ +}; +#endif + +#define YYPACT_NINF (]b4_pact_ninf[) +#define YYTABLE_NINF (]b4_table_ninf[) + +]b4_parser_tables_define[ + +/* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */ +static const ]b4_int_type_for([b4_dprec])[ yydprec[] = +{ + ]b4_dprec[ +}; + +/* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */ +static const ]b4_int_type_for([b4_merger])[ yymerger[] = +{ + ]b4_merger[ +}; + +/* YYIMMEDIATE[RULE-NUM] -- True iff rule #RULE-NUM is not to be deferred, as + in the case of predicates. */ +static const yybool yyimmediate[] = +{ + ]b4_immediate[ +}; + +/* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of + list of conflicting reductions corresponding to action entry for + state STATE-NUM in yytable. 0 means no conflicts. The list in + yyconfl is terminated by a rule number of 0. */ +static const ]b4_int_type_for([b4_conflict_list_heads])[ yyconflp[] = +{ + ]b4_conflict_list_heads[ +}; + +/* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by + 0, pointed into by YYCONFLP. */ +]dnl Do not use b4_int_type_for here, since there are places where +dnl pointers onto yyconfl are taken, whose type is "short*". +dnl We probably ought to introduce a type for confl. +[static const short yyconfl[] = +{ + ]b4_conflicting_rules[ +}; + +]b4_locations_if([[ +]b4_yylloc_default_define[ +# define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc) +]])[ + +]b4_pure_if( +[ +#undef yynerrs +#define yynerrs (yystackp->yyerrcnt) +#undef yychar +#define yychar (yystackp->yyrawchar) +#undef yylval +#define yylval (yystackp->yyval) +#undef yylloc +#define yylloc (yystackp->yyloc) +m4_if(b4_prefix[], [yy], [], +[#define b4_prefix[]nerrs yynerrs +#define b4_prefix[]char yychar +#define b4_prefix[]lval yylval +#define b4_prefix[]lloc yylloc])], +[YYSTYPE yylval;]b4_locations_if([[ +YYLTYPE yylloc;]])[ + +int yynerrs; +int yychar;])[ + +enum { YYENOMEM = -2 }; + +typedef enum { yyok, yyaccept, yyabort, yyerr, yynomem } YYRESULTTAG; + +#define YYCHK(YYE) \ + do { \ + YYRESULTTAG yychk_flag = YYE; \ + if (yychk_flag != yyok) \ + return yychk_flag; \ + } while (0) + +/* YYINITDEPTH -- initial size of the parser's stacks. */ +#ifndef YYINITDEPTH +# define YYINITDEPTH ]b4_stack_depth_init[ +#endif + +/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only + if the built-in stack extension method is used). + + Do not make this value too large; the results are undefined if + SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem) + evaluated with infinite-precision integer arithmetic. */ + +#ifndef YYMAXDEPTH +# define YYMAXDEPTH ]b4_stack_depth_max[ +#endif + +/* Minimum number of free items on the stack allowed after an + allocation. This is to allow allocation and initialization + to be completed by functions that call yyexpandGLRStack before the + stack is expanded, thus insuring that all necessary pointers get + properly redirected to new data. */ +#define YYHEADROOM 2 + +#ifndef YYSTACKEXPANDABLE +# define YYSTACKEXPANDABLE 1 +#endif + +#if YYSTACKEXPANDABLE +# define YY_RESERVE_GLRSTACK(Yystack) \ + do { \ + if (Yystack->yyspaceLeft < YYHEADROOM) \ + yyexpandGLRStack (Yystack); \ + } while (0) +#else +# define YY_RESERVE_GLRSTACK(Yystack) \ + do { \ + if (Yystack->yyspaceLeft < YYHEADROOM) \ + yyMemoryExhausted (Yystack); \ + } while (0) +#endif + +/** State numbers. */ +typedef int yy_state_t; + +/** Rule numbers. */ +typedef int yyRuleNum; + +/** Item references. */ +typedef short yyItemNum; + +typedef struct yyGLRState yyGLRState; +typedef struct yyGLRStateSet yyGLRStateSet; +typedef struct yySemanticOption yySemanticOption; +typedef union yyGLRStackItem yyGLRStackItem; +typedef struct yyGLRStack yyGLRStack; + +struct yyGLRState +{ + /** Type tag: always true. */ + yybool yyisState; + /** Type tag for yysemantics. If true, yyval applies, otherwise + * yyfirstVal applies. */ + yybool yyresolved; + /** Number of corresponding LALR(1) machine state. */ + yy_state_t yylrState; + /** Preceding state in this stack */ + yyGLRState* yypred; + /** Source position of the last token produced by my symbol */ + YYPTRDIFF_T yyposn; + union { + /** First in a chain of alternative reductions producing the + * nonterminal corresponding to this state, threaded through + * yynext. */ + yySemanticOption* yyfirstVal; + /** Semantic value for this state. */ + YYSTYPE yyval; + } yysemantics;]b4_locations_if([[ + /** Source location for this state. */ + YYLTYPE yyloc;]])[ +}; + +struct yyGLRStateSet +{ + yyGLRState** yystates; + /** During nondeterministic operation, yylookaheadNeeds tracks which + * stacks have actually needed the current lookahead. During deterministic + * operation, yylookaheadNeeds[0] is not maintained since it would merely + * duplicate yychar != ]b4_symbol(empty, id)[. */ + yybool* yylookaheadNeeds; + YYPTRDIFF_T yysize; + YYPTRDIFF_T yycapacity; +}; + +struct yySemanticOption +{ + /** Type tag: always false. */ + yybool yyisState; + /** Rule number for this reduction */ + yyRuleNum yyrule; + /** The last RHS state in the list of states to be reduced. */ + yyGLRState* yystate; + /** The lookahead for this reduction. */ + int yyrawchar; + YYSTYPE yyval;]b4_locations_if([[ + YYLTYPE yyloc;]])[ + /** Next sibling in chain of options. To facilitate merging, + * options are chained in decreasing order by address. */ + yySemanticOption* yynext; +}; + +/** Type of the items in the GLR stack. The yyisState field + * indicates which item of the union is valid. */ +union yyGLRStackItem { + yyGLRState yystate; + yySemanticOption yyoption; +}; + +struct yyGLRStack { + int yyerrState; +]b4_locations_if([[ /* To compute the location of the error token. */ + yyGLRStackItem yyerror_range[3];]])[ +]b4_pure_if( +[ + int yyerrcnt; + int yyrawchar; + YYSTYPE yyval;]b4_locations_if([[ + YYLTYPE yyloc;]])[ +])[ + YYJMP_BUF yyexception_buffer; + yyGLRStackItem* yyitems; + yyGLRStackItem* yynextFree; + YYPTRDIFF_T yyspaceLeft; + yyGLRState* yysplitPoint; + yyGLRState* yylastDeleted; + yyGLRStateSet yytops; +}; + +#if YYSTACKEXPANDABLE +static void yyexpandGLRStack (yyGLRStack* yystackp); +#endif + +_Noreturn static void +yyFail (yyGLRStack* yystackp]b4_pure_formals[, const char* yymsg) +{ + if (yymsg != YY_NULLPTR) + yyerror (]b4_yyerror_args[yymsg); + YYLONGJMP (yystackp->yyexception_buffer, 1); +} + +_Noreturn static void +yyMemoryExhausted (yyGLRStack* yystackp) +{ + YYLONGJMP (yystackp->yyexception_buffer, 2); +} + +/** Accessing symbol of state YYSTATE. */ +static inline yysymbol_kind_t +yy_accessing_symbol (yy_state_t yystate) +{ + return YY_CAST (yysymbol_kind_t, yystos[yystate]); +} + +#if ]b4_parse_error_case([simple], [b4_api_PREFIX[DEBUG || ]b4_token_table_flag], [[1]])[ +/* The user-facing name of the symbol whose (internal) number is + YYSYMBOL. No bounds checking. */ +static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED; + +]b4_parse_error_bmatch([simple\|verbose], +[[/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at YYNTOKENS, nonterminals. */ +static const char *const yytname[] = +{ + ]b4_tname[ +}; + +static const char * +yysymbol_name (yysymbol_kind_t yysymbol) +{ + return yytname[yysymbol]; +}]], +[[static const char * +yysymbol_name (yysymbol_kind_t yysymbol) +{ + static const char *const yy_sname[] = + { + ]b4_symbol_names[ + };]b4_has_translations_if([[ + /* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is + internationalizable. */ + static ]b4_int_type_for([b4_translatable])[ yytranslatable[] = + { + ]b4_translatable[ + }; + return (yysymbol < YYNTOKENS && yytranslatable[yysymbol] + ? _(yy_sname[yysymbol]) + : yy_sname[yysymbol]);]], [[ + return yy_sname[yysymbol];]])[ +}]])[ +#endif + +/** Left-hand-side symbol for rule #YYRULE. */ +static inline yysymbol_kind_t +yylhsNonterm (yyRuleNum yyrule) +{ + return YY_CAST (yysymbol_kind_t, yyr1[yyrule]); +} + +#if ]b4_api_PREFIX[DEBUG + +# ifndef YYFPRINTF +# define YYFPRINTF fprintf +# endif + +# define YY_FPRINTF \ + YY_IGNORE_USELESS_CAST_BEGIN YY_FPRINTF_ + +# define YY_FPRINTF_(Args) \ + do { \ + YYFPRINTF Args; \ + YY_IGNORE_USELESS_CAST_END \ + } while (0) + +# define YY_DPRINTF \ + YY_IGNORE_USELESS_CAST_BEGIN YY_DPRINTF_ + +# define YY_DPRINTF_(Args) \ + do { \ + if (yydebug) \ + YYFPRINTF Args; \ + YY_IGNORE_USELESS_CAST_END \ + } while (0) + +]b4_yylocation_print_define[ + +]b4_yy_symbol_print_define[ + +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ + do { \ + if (yydebug) \ + { \ + YY_FPRINTF ((stderr, "%s ", Title)); \ + yy_symbol_print (stderr, Kind, Value]b4_locuser_args([Location])[); \ + YY_FPRINTF ((stderr, "\n")); \ + } \ + } while (0) + +static inline void +yy_reduce_print (yybool yynormal, yyGLRStackItem* yyvsp, YYPTRDIFF_T yyk, + yyRuleNum yyrule]b4_user_formals[); + +# define YY_REDUCE_PRINT(Args) \ + do { \ + if (yydebug) \ + yy_reduce_print Args; \ + } while (0) + +/* Nonzero means print parse trace. It is left uninitialized so that + multiple parsers can coexist. */ +int yydebug; + +static void yypstack (yyGLRStack* yystackp, YYPTRDIFF_T yyk) + YY_ATTRIBUTE_UNUSED; +static void yypdumpstack (yyGLRStack* yystackp) + YY_ATTRIBUTE_UNUSED; + +#else /* !]b4_api_PREFIX[DEBUG */ + +# define YY_DPRINTF(Args) do {} while (yyfalse) +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) +# define YY_REDUCE_PRINT(Args) + +#endif /* !]b4_api_PREFIX[DEBUG */ + +]b4_parse_error_case( + [simple], +[[]], +[[#ifndef yystrlen +# define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S))) +#endif + +]b4_parse_error_bmatch( + [detailed\|verbose], +[[#ifndef yystpcpy +# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE +# define yystpcpy stpcpy +# else +/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in + YYDEST. */ +static char * +yystpcpy (char *yydest, const char *yysrc) +{ + char *yyd = yydest; + const char *yys = yysrc; + + while ((*yyd++ = *yys++) != '\0') + continue; + + return yyd - 1; +} +# endif +#endif]])[ + +]b4_parse_error_case( + [verbose], +[[#ifndef yytnamerr +/* Copy to YYRES the contents of YYSTR after stripping away unnecessary + quotes and backslashes, so that it's suitable for yyerror. The + heuristic is that double-quoting is unnecessary unless the string + contains an apostrophe, a comma, or backslash (other than + backslash-backslash). YYSTR is taken from yytname. If YYRES is + null, do not copy; instead, return the length of what the result + would have been. */ +static YYPTRDIFF_T +yytnamerr (char *yyres, const char *yystr) +{ + if (*yystr == '"') + { + YYPTRDIFF_T yyn = 0; + char const *yyp = yystr; + + for (;;) + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + else + goto append; + + append: + default: + if (yyres) + yyres[yyn] = *yyp; + yyn++; + break; + + case '"': + if (yyres) + yyres[yyn] = '\0'; + return yyn; + } + do_not_strip_quotes: ; + } + + if (yyres) + return yystpcpy (yyres, yystr) - yyres; + else + return yystrlen (yystr); +} +#endif +]])])[ + +/** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting + * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred + * containing the pointer to the next state in the chain. */ +static void yyfillin (yyGLRStackItem *, int, int) YY_ATTRIBUTE_UNUSED; +static void +yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1) +{ + int i; + yyGLRState *s = yyvsp[yylow0].yystate.yypred; + for (i = yylow0-1; i >= yylow1; i -= 1) + { +#if ]b4_api_PREFIX[DEBUG + yyvsp[i].yystate.yylrState = s->yylrState; +#endif + yyvsp[i].yystate.yyresolved = s->yyresolved; + if (s->yyresolved) + yyvsp[i].yystate.yysemantics.yyval = s->yysemantics.yyval; + else + /* The effect of using yyval or yyloc (in an immediate rule) is + * undefined. */ + yyvsp[i].yystate.yysemantics.yyfirstVal = YY_NULLPTR;]b4_locations_if([[ + yyvsp[i].yystate.yyloc = s->yyloc;]])[ + s = yyvsp[i].yystate.yypred = s->yypred; + } +} + +]m4_define([b4_yygetToken_call], + [[yygetToken (&yychar][]b4_pure_if([, yystackp])[]b4_user_args[)]])[ +/** If yychar is empty, fetch the next token. */ +static inline yysymbol_kind_t +yygetToken (int *yycharp][]b4_pure_if([, yyGLRStack* yystackp])[]b4_user_formals[) +{ + yysymbol_kind_t yytoken; +]b4_parse_param_use()dnl +[ if (*yycharp == ]b4_symbol(empty, id)[) + { + YY_DPRINTF ((stderr, "Reading a token\n"));]b4_glr_cc_if([[ +#if YY_EXCEPTIONS + try + { +#endif // YY_EXCEPTIONS + *yycharp = ]b4_yylex[; +#if YY_EXCEPTIONS + } + catch (const ]b4_namespace_ref[::]b4_parser_class[::syntax_error& yyexc) + { + YY_DPRINTF ((stderr, "Caught exception: %s\n", yyexc.what()));]b4_locations_if([ + yylloc = yyexc.location;])[ + yyerror (]b4_lyyerror_args[yyexc.what ()); + // Map errors caught in the scanner to the undefined token, + // so that error handling is started. However, record this + // with this special value of yychar. + *yycharp = ]b4_symbol(error, id)[; + } +#endif // YY_EXCEPTIONS]], [[ + *yycharp = ]b4_yylex[;]])[ + } + if (*yycharp <= ]b4_symbol(eof, [id])[) + { + *yycharp = ]b4_symbol(eof, [id])[; + yytoken = ]b4_symbol_prefix[YYEOF; + YY_DPRINTF ((stderr, "Now at end of input.\n")); + } + else + { + yytoken = YYTRANSLATE (*yycharp); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); + } + return yytoken; +} + +/* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in + * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1. + * For convenience, always return YYLOW1. */ +static inline int yyfill (yyGLRStackItem *, int *, int, yybool) + YY_ATTRIBUTE_UNUSED; +static inline int +yyfill (yyGLRStackItem *yyvsp, int *yylow, int yylow1, yybool yynormal) +{ + if (!yynormal && yylow1 < *yylow) + { + yyfillin (yyvsp, *yylow, yylow1); + *yylow = yylow1; + } + return yylow1; +} + +/** Perform user action for rule number YYN, with RHS length YYRHSLEN, + * and top stack item YYVSP. YYLVALP points to place to put semantic + * value ($$), and yylocp points to place for location information + * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT, + * yyerr for YYERROR, yyabort for YYABORT, yynomem for YYNOMEM. */ +static YYRESULTTAG +yyuserAction (yyRuleNum yyrule, int yyrhslen, yyGLRStackItem* yyvsp, + yyGLRStack* yystackp, YYPTRDIFF_T yyk, + YYSTYPE* yyvalp]b4_locuser_formals[) +{ + const yybool yynormal YY_ATTRIBUTE_UNUSED = yystackp->yysplitPoint == YY_NULLPTR; + int yylow = 1; +]b4_parse_param_use([yyvalp], [yylocp])dnl +[ YY_USE (yyk); + YY_USE (yyrhslen); +# undef yyerrok +# define yyerrok (yystackp->yyerrState = 0) +# undef YYACCEPT +# define YYACCEPT return yyaccept +# undef YYABORT +# define YYABORT return yyabort +# undef YYNOMEM +# define YYNOMEM return yynomem +# undef YYERROR +# define YYERROR return yyerrok, yyerr +# undef YYRECOVERING +# define YYRECOVERING() (yystackp->yyerrState != 0) +# undef yyclearin +# define yyclearin (yychar = ]b4_symbol(empty, id)[) +# undef YYFILL +# define YYFILL(N) yyfill (yyvsp, &yylow, (N), yynormal) +# undef YYBACKUP +# define YYBACKUP(Token, Value) \ + return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \ + yyerrok, yyerr + + if (yyrhslen == 0) + *yyvalp = yyval_default; + else + *yyvalp = yyvsp[YYFILL (1-yyrhslen)].yystate.yysemantics.yyval;]b4_locations_if([[ + /* Default location. */ + YYLLOC_DEFAULT ((*yylocp), (yyvsp - yyrhslen), yyrhslen); + yystackp->yyerror_range[1].yystate.yyloc = *yylocp;]])[ + /* If yyk == -1, we are running a deferred action on a temporary + stack. In that case, YY_REDUCE_PRINT must not play with YYFILL, + so pretend the stack is "normal". */ + YY_REDUCE_PRINT ((yynormal || yyk == -1, yyvsp, yyk, yyrule]b4_user_args[));]b4_glr_cc_if([[ +#if YY_EXCEPTIONS + typedef ]b4_namespace_ref[::]b4_parser_class[::syntax_error syntax_error; + try + { +#endif // YY_EXCEPTIONS]])[ + switch (yyrule) + { +]b4_user_actions[ + default: break; + }]b4_glr_cc_if([[ +#if YY_EXCEPTIONS + } + catch (const syntax_error& yyexc) + { + YY_DPRINTF ((stderr, "Caught exception: %s\n", yyexc.what()));]b4_locations_if([ + *yylocp = yyexc.location;])[ + yyerror (]b4_yyerror_args[yyexc.what ()); + YYERROR; + } +#endif // YY_EXCEPTIONS]])[ + YY_SYMBOL_PRINT ("-> $$ =", yylhsNonterm (yyrule), yyvalp, yylocp); + + return yyok; +# undef yyerrok +# undef YYABORT +# undef YYACCEPT +# undef YYNOMEM +# undef YYERROR +# undef YYBACKUP +# undef yyclearin +# undef YYRECOVERING +} + + +static void +yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1) +{ + YY_USE (yy0); + YY_USE (yy1); + + switch (yyn) + { +]b4_mergers[ + default: break; + } +} + + /* Bison grammar-table manipulation. */ + +]b4_yydestruct_define[ + +/** Number of symbols composing the right hand side of rule #RULE. */ +static inline int +yyrhsLength (yyRuleNum yyrule) +{ + return yyr2[yyrule]; +} + +static void +yydestroyGLRState (char const *yymsg, yyGLRState *yys]b4_user_formals[) +{ + if (yys->yyresolved) + yydestruct (yymsg, yy_accessing_symbol (yys->yylrState), + &yys->yysemantics.yyval]b4_locuser_args([&yys->yyloc])[); + else + { +#if ]b4_api_PREFIX[DEBUG + if (yydebug) + { + if (yys->yysemantics.yyfirstVal) + YY_FPRINTF ((stderr, "%s unresolved", yymsg)); + else + YY_FPRINTF ((stderr, "%s incomplete", yymsg)); + YY_SYMBOL_PRINT ("", yy_accessing_symbol (yys->yylrState), YY_NULLPTR, &yys->yyloc); + } +#endif + + if (yys->yysemantics.yyfirstVal) + { + yySemanticOption *yyoption = yys->yysemantics.yyfirstVal; + yyGLRState *yyrh; + int yyn; + for (yyrh = yyoption->yystate, yyn = yyrhsLength (yyoption->yyrule); + yyn > 0; + yyrh = yyrh->yypred, yyn -= 1) + yydestroyGLRState (yymsg, yyrh]b4_user_args[); + } + } +} + +#define yypact_value_is_default(Yyn) \ + ]b4_table_value_equals([[pact]], [[Yyn]], [b4_pact_ninf], [YYPACT_NINF])[ + +/** True iff LR state YYSTATE has only a default reduction (regardless + * of token). */ +static inline yybool +yyisDefaultedState (yy_state_t yystate) +{ + return yypact_value_is_default (yypact[yystate]); +} + +/** The default reduction for YYSTATE, assuming it has one. */ +static inline yyRuleNum +yydefaultAction (yy_state_t yystate) +{ + return yydefact[yystate]; +} + +#define yytable_value_is_error(Yyn) \ + ]b4_table_value_equals([[table]], [[Yyn]], [b4_table_ninf], [YYTABLE_NINF])[ + +/** The action to take in YYSTATE on seeing YYTOKEN. + * Result R means + * R < 0: Reduce on rule -R. + * R = 0: Error. + * R > 0: Shift to state R. + * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list + * of conflicting reductions. + */ +static inline int +yygetLRActions (yy_state_t yystate, yysymbol_kind_t yytoken, const short** yyconflicts) +{ + int yyindex = yypact[yystate] + yytoken; + if (yytoken == ]b4_symbol(error, kind)[) + { + // This is the error token. + *yyconflicts = yyconfl; + return 0; + } + else if (yyisDefaultedState (yystate) + || yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken) + { + *yyconflicts = yyconfl; + return -yydefact[yystate]; + } + else if (! yytable_value_is_error (yytable[yyindex])) + { + *yyconflicts = yyconfl + yyconflp[yyindex]; + return yytable[yyindex]; + } + else + { + *yyconflicts = yyconfl + yyconflp[yyindex]; + return 0; + } +} + +/** Compute post-reduction state. + * \param yystate the current state + * \param yysym the nonterminal to push on the stack + */ +static inline yy_state_t +yyLRgotoState (yy_state_t yystate, yysymbol_kind_t yysym) +{ + int yyr = yypgoto[yysym - YYNTOKENS] + yystate; + if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate) + return yytable[yyr]; + else + return yydefgoto[yysym - YYNTOKENS]; +} + +static inline yybool +yyisShiftAction (int yyaction) +{ + return 0 < yyaction; +} + +static inline yybool +yyisErrorAction (int yyaction) +{ + return yyaction == 0; +} + + /* GLRStates */ + +/** Return a fresh GLRStackItem in YYSTACKP. The item is an LR state + * if YYISSTATE, and otherwise a semantic option. Callers should call + * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient + * headroom. */ + +static inline yyGLRStackItem* +yynewGLRStackItem (yyGLRStack* yystackp, yybool yyisState) +{ + yyGLRStackItem* yynewItem = yystackp->yynextFree; + yystackp->yyspaceLeft -= 1; + yystackp->yynextFree += 1; + yynewItem->yystate.yyisState = yyisState; + return yynewItem; +} + +/** Add a new semantic action that will execute the action for rule + * YYRULE on the semantic values in YYRHS to the list of + * alternative actions for YYSTATE. Assumes that YYRHS comes from + * stack #YYK of *YYSTACKP. */ +static void +yyaddDeferredAction (yyGLRStack* yystackp, YYPTRDIFF_T yyk, yyGLRState* yystate, + yyGLRState* yyrhs, yyRuleNum yyrule) +{ + yySemanticOption* yynewOption = + &yynewGLRStackItem (yystackp, yyfalse)->yyoption; + YY_ASSERT (!yynewOption->yyisState); + yynewOption->yystate = yyrhs; + yynewOption->yyrule = yyrule; + if (yystackp->yytops.yylookaheadNeeds[yyk]) + { + yynewOption->yyrawchar = yychar; + yynewOption->yyval = yylval;]b4_locations_if([ + yynewOption->yyloc = yylloc;])[ + } + else + yynewOption->yyrawchar = ]b4_symbol(empty, id)[; + yynewOption->yynext = yystate->yysemantics.yyfirstVal; + yystate->yysemantics.yyfirstVal = yynewOption; + + YY_RESERVE_GLRSTACK (yystackp); +} + + /* GLRStacks */ + +/** Initialize YYSET to a singleton set containing an empty stack. */ +static yybool +yyinitStateSet (yyGLRStateSet* yyset) +{ + yyset->yysize = 1; + yyset->yycapacity = 16; + yyset->yystates + = YY_CAST (yyGLRState**, + YYMALLOC (YY_CAST (YYSIZE_T, yyset->yycapacity) + * sizeof yyset->yystates[0])); + if (! yyset->yystates) + return yyfalse; + yyset->yystates[0] = YY_NULLPTR; + yyset->yylookaheadNeeds + = YY_CAST (yybool*, + YYMALLOC (YY_CAST (YYSIZE_T, yyset->yycapacity) + * sizeof yyset->yylookaheadNeeds[0])); + if (! yyset->yylookaheadNeeds) + { + YYFREE (yyset->yystates); + return yyfalse; + } + memset (yyset->yylookaheadNeeds, + 0, + YY_CAST (YYSIZE_T, yyset->yycapacity) * sizeof yyset->yylookaheadNeeds[0]); + return yytrue; +} + +static void yyfreeStateSet (yyGLRStateSet* yyset) +{ + YYFREE (yyset->yystates); + YYFREE (yyset->yylookaheadNeeds); +} + +/** Initialize *YYSTACKP to a single empty stack, with total maximum + * capacity for all stacks of YYSIZE. */ +static yybool +yyinitGLRStack (yyGLRStack* yystackp, YYPTRDIFF_T yysize) +{ + yystackp->yyerrState = 0; + yynerrs = 0; + yystackp->yyspaceLeft = yysize; + yystackp->yyitems + = YY_CAST (yyGLRStackItem*, + YYMALLOC (YY_CAST (YYSIZE_T, yysize) + * sizeof yystackp->yynextFree[0])); + if (!yystackp->yyitems) + return yyfalse; + yystackp->yynextFree = yystackp->yyitems; + yystackp->yysplitPoint = YY_NULLPTR; + yystackp->yylastDeleted = YY_NULLPTR; + return yyinitStateSet (&yystackp->yytops); +} + + +#if YYSTACKEXPANDABLE +# define YYRELOC(YYFROMITEMS, YYTOITEMS, YYX, YYTYPE) \ + &((YYTOITEMS) \ + - ((YYFROMITEMS) - YY_REINTERPRET_CAST (yyGLRStackItem*, (YYX))))->YYTYPE + +/** If *YYSTACKP is expandable, extend it. WARNING: Pointers into the + stack from outside should be considered invalid after this call. + We always expand when there are 1 or fewer items left AFTER an + allocation, so that we can avoid having external pointers exist + across an allocation. */ +static void +yyexpandGLRStack (yyGLRStack* yystackp) +{ + yyGLRStackItem* yynewItems; + yyGLRStackItem* yyp0, *yyp1; + YYPTRDIFF_T yynewSize; + YYPTRDIFF_T yyn; + YYPTRDIFF_T yysize = yystackp->yynextFree - yystackp->yyitems; + if (YYMAXDEPTH - YYHEADROOM < yysize) + yyMemoryExhausted (yystackp); + yynewSize = 2*yysize; + if (YYMAXDEPTH < yynewSize) + yynewSize = YYMAXDEPTH; + yynewItems + = YY_CAST (yyGLRStackItem*, + YYMALLOC (YY_CAST (YYSIZE_T, yynewSize) + * sizeof yynewItems[0])); + if (! yynewItems) + yyMemoryExhausted (yystackp); + for (yyp0 = yystackp->yyitems, yyp1 = yynewItems, yyn = yysize; + 0 < yyn; + yyn -= 1, yyp0 += 1, yyp1 += 1) + { + *yyp1 = *yyp0; + if (*YY_REINTERPRET_CAST (yybool *, yyp0)) + { + yyGLRState* yys0 = &yyp0->yystate; + yyGLRState* yys1 = &yyp1->yystate; + if (yys0->yypred != YY_NULLPTR) + yys1->yypred = + YYRELOC (yyp0, yyp1, yys0->yypred, yystate); + if (! yys0->yyresolved && yys0->yysemantics.yyfirstVal != YY_NULLPTR) + yys1->yysemantics.yyfirstVal = + YYRELOC (yyp0, yyp1, yys0->yysemantics.yyfirstVal, yyoption); + } + else + { + yySemanticOption* yyv0 = &yyp0->yyoption; + yySemanticOption* yyv1 = &yyp1->yyoption; + if (yyv0->yystate != YY_NULLPTR) + yyv1->yystate = YYRELOC (yyp0, yyp1, yyv0->yystate, yystate); + if (yyv0->yynext != YY_NULLPTR) + yyv1->yynext = YYRELOC (yyp0, yyp1, yyv0->yynext, yyoption); + } + } + if (yystackp->yysplitPoint != YY_NULLPTR) + yystackp->yysplitPoint = YYRELOC (yystackp->yyitems, yynewItems, + yystackp->yysplitPoint, yystate); + + for (yyn = 0; yyn < yystackp->yytops.yysize; yyn += 1) + if (yystackp->yytops.yystates[yyn] != YY_NULLPTR) + yystackp->yytops.yystates[yyn] = + YYRELOC (yystackp->yyitems, yynewItems, + yystackp->yytops.yystates[yyn], yystate); + YYFREE (yystackp->yyitems); + yystackp->yyitems = yynewItems; + yystackp->yynextFree = yynewItems + yysize; + yystackp->yyspaceLeft = yynewSize - yysize; +} +#endif + +static void +yyfreeGLRStack (yyGLRStack* yystackp) +{ + YYFREE (yystackp->yyitems); + yyfreeStateSet (&yystackp->yytops); +} + +/** Assuming that YYS is a GLRState somewhere on *YYSTACKP, update the + * splitpoint of *YYSTACKP, if needed, so that it is at least as deep as + * YYS. */ +static inline void +yyupdateSplit (yyGLRStack* yystackp, yyGLRState* yys) +{ + if (yystackp->yysplitPoint != YY_NULLPTR && yystackp->yysplitPoint > yys) + yystackp->yysplitPoint = yys; +} + +/** Invalidate stack #YYK in *YYSTACKP. */ +static inline void +yymarkStackDeleted (yyGLRStack* yystackp, YYPTRDIFF_T yyk) +{ + if (yystackp->yytops.yystates[yyk] != YY_NULLPTR) + yystackp->yylastDeleted = yystackp->yytops.yystates[yyk]; + yystackp->yytops.yystates[yyk] = YY_NULLPTR; +} + +/** Undelete the last stack in *YYSTACKP that was marked as deleted. Can + only be done once after a deletion, and only when all other stacks have + been deleted. */ +static void +yyundeleteLastStack (yyGLRStack* yystackp) +{ + if (yystackp->yylastDeleted == YY_NULLPTR || yystackp->yytops.yysize != 0) + return; + yystackp->yytops.yystates[0] = yystackp->yylastDeleted; + yystackp->yytops.yysize = 1; + YY_DPRINTF ((stderr, "Restoring last deleted stack as stack #0.\n")); + yystackp->yylastDeleted = YY_NULLPTR; +} + +static inline void +yyremoveDeletes (yyGLRStack* yystackp) +{ + YYPTRDIFF_T yyi, yyj; + yyi = yyj = 0; + while (yyj < yystackp->yytops.yysize) + { + if (yystackp->yytops.yystates[yyi] == YY_NULLPTR) + { + if (yyi == yyj) + YY_DPRINTF ((stderr, "Removing dead stacks.\n")); + yystackp->yytops.yysize -= 1; + } + else + { + yystackp->yytops.yystates[yyj] = yystackp->yytops.yystates[yyi]; + /* In the current implementation, it's unnecessary to copy + yystackp->yytops.yylookaheadNeeds[yyi] since, after + yyremoveDeletes returns, the parser immediately either enters + deterministic operation or shifts a token. However, it doesn't + hurt, and the code might evolve to need it. */ + yystackp->yytops.yylookaheadNeeds[yyj] = + yystackp->yytops.yylookaheadNeeds[yyi]; + if (yyj != yyi) + YY_DPRINTF ((stderr, "Rename stack %ld -> %ld.\n", + YY_CAST (long, yyi), YY_CAST (long, yyj))); + yyj += 1; + } + yyi += 1; + } +} + +/** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR + * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic + * value *YYVALP and source location *YYLOCP. */ +static inline void +yyglrShift (yyGLRStack* yystackp, YYPTRDIFF_T yyk, yy_state_t yylrState, + YYPTRDIFF_T yyposn, + YYSTYPE* yyvalp]b4_locations_if([, YYLTYPE* yylocp])[) +{ + yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate; + + yynewState->yylrState = yylrState; + yynewState->yyposn = yyposn; + yynewState->yyresolved = yytrue; + yynewState->yypred = yystackp->yytops.yystates[yyk]; + yynewState->yysemantics.yyval = *yyvalp;]b4_locations_if([ + yynewState->yyloc = *yylocp;])[ + yystackp->yytops.yystates[yyk] = yynewState; + + YY_RESERVE_GLRSTACK (yystackp); +} + +/** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR + * state YYLRSTATE, at input position YYPOSN, with the (unresolved) + * semantic value of YYRHS under the action for YYRULE. */ +static inline void +yyglrShiftDefer (yyGLRStack* yystackp, YYPTRDIFF_T yyk, yy_state_t yylrState, + YYPTRDIFF_T yyposn, yyGLRState* yyrhs, yyRuleNum yyrule) +{ + yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate; + YY_ASSERT (yynewState->yyisState); + + yynewState->yylrState = yylrState; + yynewState->yyposn = yyposn; + yynewState->yyresolved = yyfalse; + yynewState->yypred = yystackp->yytops.yystates[yyk]; + yynewState->yysemantics.yyfirstVal = YY_NULLPTR; + yystackp->yytops.yystates[yyk] = yynewState; + + /* Invokes YY_RESERVE_GLRSTACK. */ + yyaddDeferredAction (yystackp, yyk, yynewState, yyrhs, yyrule); +} + +#if ]b4_api_PREFIX[DEBUG + +/*----------------------------------------------------------------------. +| Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. | +`----------------------------------------------------------------------*/ + +static inline void +yy_reduce_print (yybool yynormal, yyGLRStackItem* yyvsp, YYPTRDIFF_T yyk, + yyRuleNum yyrule]b4_user_formals[) +{ + int yynrhs = yyrhsLength (yyrule);]b4_locations_if([ + int yylow = 1;])[ + int yyi; + YY_FPRINTF ((stderr, "Reducing stack %ld by rule %d (line %d):\n", + YY_CAST (long, yyk), yyrule - 1, yyrline[yyrule])); + if (! yynormal) + yyfillin (yyvsp, 1, -yynrhs); + /* The symbols being reduced. */ + for (yyi = 0; yyi < yynrhs; yyi++) + { + YY_FPRINTF ((stderr, " $%d = ", yyi + 1)); + yy_symbol_print (stderr, + yy_accessing_symbol (yyvsp[yyi - yynrhs + 1].yystate.yylrState), + &yyvsp[yyi - yynrhs + 1].yystate.yysemantics.yyval]b4_locations_if([, + &]b4_rhs_location(yynrhs, yyi + 1))[]dnl + b4_user_args[); + if (!yyvsp[yyi - yynrhs + 1].yystate.yyresolved) + YY_FPRINTF ((stderr, " (unresolved)")); + YY_FPRINTF ((stderr, "\n")); + } +} +#endif + +/** Pop the symbols consumed by reduction #YYRULE from the top of stack + * #YYK of *YYSTACKP, and perform the appropriate semantic action on their + * semantic values. Assumes that all ambiguities in semantic values + * have been previously resolved. Set *YYVALP to the resulting value, + * and *YYLOCP to the computed location (if any). Return value is as + * for userAction. */ +static inline YYRESULTTAG +yydoAction (yyGLRStack* yystackp, YYPTRDIFF_T yyk, yyRuleNum yyrule, + YYSTYPE* yyvalp]b4_locuser_formals[) +{ + int yynrhs = yyrhsLength (yyrule); + + if (yystackp->yysplitPoint == YY_NULLPTR) + { + /* Standard special case: single stack. */ + yyGLRStackItem* yyrhs + = YY_REINTERPRET_CAST (yyGLRStackItem*, yystackp->yytops.yystates[yyk]); + YY_ASSERT (yyk == 0); + yystackp->yynextFree -= yynrhs; + yystackp->yyspaceLeft += yynrhs; + yystackp->yytops.yystates[0] = & yystackp->yynextFree[-1].yystate; + return yyuserAction (yyrule, yynrhs, yyrhs, yystackp, yyk, + yyvalp]b4_locuser_args[); + } + else + { + yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1]; + yyGLRState* yys = yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred + = yystackp->yytops.yystates[yyk]; + int yyi;]b4_locations_if([[ + if (yynrhs == 0) + /* Set default location. */ + yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yys->yyloc;]])[ + for (yyi = 0; yyi < yynrhs; yyi += 1) + { + yys = yys->yypred; + YY_ASSERT (yys); + } + yyupdateSplit (yystackp, yys); + yystackp->yytops.yystates[yyk] = yys; + return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, + yystackp, yyk, yyvalp]b4_locuser_args[); + } +} + +/** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE, + * and push back on the resulting nonterminal symbol. Perform the + * semantic action associated with YYRULE and store its value with the + * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently + * unambiguous. Otherwise, store the deferred semantic action with + * the new state. If the new state would have an identical input + * position, LR state, and predecessor to an existing state on the stack, + * it is identified with that existing state, eliminating stack #YYK from + * *YYSTACKP. In this case, the semantic value is + * added to the options for the existing state's semantic value. + */ +static inline YYRESULTTAG +yyglrReduce (yyGLRStack* yystackp, YYPTRDIFF_T yyk, yyRuleNum yyrule, + yybool yyforceEval]b4_user_formals[) +{ + YYPTRDIFF_T yyposn = yystackp->yytops.yystates[yyk]->yyposn; + + if (yyforceEval || yystackp->yysplitPoint == YY_NULLPTR) + { + YYSTYPE yyval;]b4_locations_if([[ + YYLTYPE yyloc;]])[ + + YYRESULTTAG yyflag = yydoAction (yystackp, yyk, yyrule, &yyval]b4_locuser_args([&yyloc])[); + if (yyflag == yyerr && yystackp->yysplitPoint != YY_NULLPTR) + YY_DPRINTF ((stderr, + "Parse on stack %ld rejected by rule %d (line %d).\n", + YY_CAST (long, yyk), yyrule - 1, yyrline[yyrule])); + if (yyflag != yyok) + return yyflag; + yyglrShift (yystackp, yyk, + yyLRgotoState (yystackp->yytops.yystates[yyk]->yylrState, + yylhsNonterm (yyrule)), + yyposn, &yyval]b4_locations_if([, &yyloc])[); + } + else + { + YYPTRDIFF_T yyi; + int yyn; + yyGLRState* yys, *yys0 = yystackp->yytops.yystates[yyk]; + yy_state_t yynewLRState; + + for (yys = yystackp->yytops.yystates[yyk], yyn = yyrhsLength (yyrule); + 0 < yyn; yyn -= 1) + { + yys = yys->yypred; + YY_ASSERT (yys); + } + yyupdateSplit (yystackp, yys); + yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule)); + YY_DPRINTF ((stderr, + "Reduced stack %ld by rule %d (line %d); action deferred. " + "Now in state %d.\n", + YY_CAST (long, yyk), yyrule - 1, yyrline[yyrule], + yynewLRState)); + for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1) + if (yyi != yyk && yystackp->yytops.yystates[yyi] != YY_NULLPTR) + { + yyGLRState *yysplit = yystackp->yysplitPoint; + yyGLRState *yyp = yystackp->yytops.yystates[yyi]; + while (yyp != yys && yyp != yysplit && yyp->yyposn >= yyposn) + { + if (yyp->yylrState == yynewLRState && yyp->yypred == yys) + { + yyaddDeferredAction (yystackp, yyk, yyp, yys0, yyrule); + yymarkStackDeleted (yystackp, yyk); + YY_DPRINTF ((stderr, "Merging stack %ld into stack %ld.\n", + YY_CAST (long, yyk), YY_CAST (long, yyi))); + return yyok; + } + yyp = yyp->yypred; + } + } + yystackp->yytops.yystates[yyk] = yys; + yyglrShiftDefer (yystackp, yyk, yynewLRState, yyposn, yys0, yyrule); + } + return yyok; +} + +static YYPTRDIFF_T +yysplitStack (yyGLRStack* yystackp, YYPTRDIFF_T yyk) +{ + if (yystackp->yysplitPoint == YY_NULLPTR) + { + YY_ASSERT (yyk == 0); + yystackp->yysplitPoint = yystackp->yytops.yystates[yyk]; + } + if (yystackp->yytops.yycapacity <= yystackp->yytops.yysize) + { + YYPTRDIFF_T state_size = YYSIZEOF (yystackp->yytops.yystates[0]); + YYPTRDIFF_T half_max_capacity = YYSIZE_MAXIMUM / 2 / state_size; + if (half_max_capacity < yystackp->yytops.yycapacity) + yyMemoryExhausted (yystackp); + yystackp->yytops.yycapacity *= 2; + + { + yyGLRState** yynewStates + = YY_CAST (yyGLRState**, + YYREALLOC (yystackp->yytops.yystates, + (YY_CAST (YYSIZE_T, yystackp->yytops.yycapacity) + * sizeof yynewStates[0]))); + if (yynewStates == YY_NULLPTR) + yyMemoryExhausted (yystackp); + yystackp->yytops.yystates = yynewStates; + } + + { + yybool* yynewLookaheadNeeds + = YY_CAST (yybool*, + YYREALLOC (yystackp->yytops.yylookaheadNeeds, + (YY_CAST (YYSIZE_T, yystackp->yytops.yycapacity) + * sizeof yynewLookaheadNeeds[0]))); + if (yynewLookaheadNeeds == YY_NULLPTR) + yyMemoryExhausted (yystackp); + yystackp->yytops.yylookaheadNeeds = yynewLookaheadNeeds; + } + } + yystackp->yytops.yystates[yystackp->yytops.yysize] + = yystackp->yytops.yystates[yyk]; + yystackp->yytops.yylookaheadNeeds[yystackp->yytops.yysize] + = yystackp->yytops.yylookaheadNeeds[yyk]; + yystackp->yytops.yysize += 1; + return yystackp->yytops.yysize - 1; +} + +/** True iff YYY0 and YYY1 represent identical options at the top level. + * That is, they represent the same rule applied to RHS symbols + * that produce the same terminal symbols. */ +static yybool +yyidenticalOptions (yySemanticOption* yyy0, yySemanticOption* yyy1) +{ + if (yyy0->yyrule == yyy1->yyrule) + { + yyGLRState *yys0, *yys1; + int yyn; + for (yys0 = yyy0->yystate, yys1 = yyy1->yystate, + yyn = yyrhsLength (yyy0->yyrule); + yyn > 0; + yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1) + if (yys0->yyposn != yys1->yyposn) + return yyfalse; + return yytrue; + } + else + return yyfalse; +} + +/** Assuming identicalOptions (YYY0,YYY1), destructively merge the + * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */ +static void +yymergeOptionSets (yySemanticOption* yyy0, yySemanticOption* yyy1) +{ + yyGLRState *yys0, *yys1; + int yyn; + for (yys0 = yyy0->yystate, yys1 = yyy1->yystate, + yyn = yyrhsLength (yyy0->yyrule); + 0 < yyn; + yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1) + { + if (yys0 == yys1) + break; + else if (yys0->yyresolved) + { + yys1->yyresolved = yytrue; + yys1->yysemantics.yyval = yys0->yysemantics.yyval; + } + else if (yys1->yyresolved) + { + yys0->yyresolved = yytrue; + yys0->yysemantics.yyval = yys1->yysemantics.yyval; + } + else + { + yySemanticOption** yyz0p = &yys0->yysemantics.yyfirstVal; + yySemanticOption* yyz1 = yys1->yysemantics.yyfirstVal; + while (yytrue) + { + if (yyz1 == *yyz0p || yyz1 == YY_NULLPTR) + break; + else if (*yyz0p == YY_NULLPTR) + { + *yyz0p = yyz1; + break; + } + else if (*yyz0p < yyz1) + { + yySemanticOption* yyz = *yyz0p; + *yyz0p = yyz1; + yyz1 = yyz1->yynext; + (*yyz0p)->yynext = yyz; + } + yyz0p = &(*yyz0p)->yynext; + } + yys1->yysemantics.yyfirstVal = yys0->yysemantics.yyfirstVal; + } + } +} + +/** Y0 and Y1 represent two possible actions to take in a given + * parsing state; return 0 if no combination is possible, + * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */ +static int +yypreference (yySemanticOption* y0, yySemanticOption* y1) +{ + yyRuleNum r0 = y0->yyrule, r1 = y1->yyrule; + int p0 = yydprec[r0], p1 = yydprec[r1]; + + if (p0 == p1) + { + if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1]) + return 0; + else + return 1; + } + if (p0 == 0 || p1 == 0) + return 0; + if (p0 < p1) + return 3; + if (p1 < p0) + return 2; + return 0; +} + +static YYRESULTTAG +yyresolveValue (yyGLRState* yys, yyGLRStack* yystackp]b4_user_formals[); + + +/** Resolve the previous YYN states starting at and including state YYS + * on *YYSTACKP. If result != yyok, some states may have been left + * unresolved possibly with empty semantic option chains. Regardless + * of whether result = yyok, each state has been left with consistent + * data so that yydestroyGLRState can be invoked if necessary. */ +static YYRESULTTAG +yyresolveStates (yyGLRState* yys, int yyn, + yyGLRStack* yystackp]b4_user_formals[) +{ + if (0 < yyn) + { + YY_ASSERT (yys->yypred); + YYCHK (yyresolveStates (yys->yypred, yyn-1, yystackp]b4_user_args[)); + if (! yys->yyresolved) + YYCHK (yyresolveValue (yys, yystackp]b4_user_args[)); + } + return yyok; +} + +/** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its + * user action, and return the semantic value and location in *YYVALP + * and *YYLOCP. Regardless of whether result = yyok, all RHS states + * have been destroyed (assuming the user action destroys all RHS + * semantic values if invoked). */ +static YYRESULTTAG +yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystackp, + YYSTYPE* yyvalp]b4_locuser_formals[) +{ + yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1]; + int yynrhs = yyrhsLength (yyopt->yyrule); + YYRESULTTAG yyflag = + yyresolveStates (yyopt->yystate, yynrhs, yystackp]b4_user_args[); + if (yyflag != yyok) + { + yyGLRState *yys; + for (yys = yyopt->yystate; yynrhs > 0; yys = yys->yypred, yynrhs -= 1) + yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[); + return yyflag; + } + + yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred = yyopt->yystate;]b4_locations_if([[ + if (yynrhs == 0) + /* Set default location. */ + yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yyopt->yystate->yyloc;]])[ + { + int yychar_current = yychar; + YYSTYPE yylval_current = yylval;]b4_locations_if([ + YYLTYPE yylloc_current = yylloc;])[ + yychar = yyopt->yyrawchar; + yylval = yyopt->yyval;]b4_locations_if([ + yylloc = yyopt->yyloc;])[ + yyflag = yyuserAction (yyopt->yyrule, yynrhs, + yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, + yystackp, -1, yyvalp]b4_locuser_args[); + yychar = yychar_current; + yylval = yylval_current;]b4_locations_if([ + yylloc = yylloc_current;])[ + } + return yyflag; +} + +#if ]b4_api_PREFIX[DEBUG +static void +yyreportTree (yySemanticOption* yyx, int yyindent) +{ + int yynrhs = yyrhsLength (yyx->yyrule); + int yyi; + yyGLRState* yys; + yyGLRState* yystates[1 + YYMAXRHS]; + yyGLRState yyleftmost_state; + + for (yyi = yynrhs, yys = yyx->yystate; 0 < yyi; yyi -= 1, yys = yys->yypred) + yystates[yyi] = yys; + if (yys == YY_NULLPTR) + { + yyleftmost_state.yyposn = 0; + yystates[0] = &yyleftmost_state; + } + else + yystates[0] = yys; + + if (yyx->yystate->yyposn < yys->yyposn + 1) + YY_FPRINTF ((stderr, "%*s%s -> \n", + yyindent, "", yysymbol_name (yylhsNonterm (yyx->yyrule)), + yyx->yyrule - 1)); + else + YY_FPRINTF ((stderr, "%*s%s -> \n", + yyindent, "", yysymbol_name (yylhsNonterm (yyx->yyrule)), + yyx->yyrule - 1, YY_CAST (long, yys->yyposn + 1), + YY_CAST (long, yyx->yystate->yyposn))); + for (yyi = 1; yyi <= yynrhs; yyi += 1) + { + if (yystates[yyi]->yyresolved) + { + if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn) + YY_FPRINTF ((stderr, "%*s%s \n", yyindent+2, "", + yysymbol_name (yy_accessing_symbol (yystates[yyi]->yylrState)))); + else + YY_FPRINTF ((stderr, "%*s%s \n", yyindent+2, "", + yysymbol_name (yy_accessing_symbol (yystates[yyi]->yylrState)), + YY_CAST (long, yystates[yyi-1]->yyposn + 1), + YY_CAST (long, yystates[yyi]->yyposn))); + } + else + yyreportTree (yystates[yyi]->yysemantics.yyfirstVal, yyindent+2); + } +} +#endif + +static YYRESULTTAG +yyreportAmbiguity (yySemanticOption* yyx0, + yySemanticOption* yyx1]b4_pure_formals[) +{ + YY_USE (yyx0); + YY_USE (yyx1); + +#if ]b4_api_PREFIX[DEBUG + YY_FPRINTF ((stderr, "Ambiguity detected.\n")); + YY_FPRINTF ((stderr, "Option 1,\n")); + yyreportTree (yyx0, 2); + YY_FPRINTF ((stderr, "\nOption 2,\n")); + yyreportTree (yyx1, 2); + YY_FPRINTF ((stderr, "\n")); +#endif + + yyerror (]b4_yyerror_args[YY_("syntax is ambiguous")); + return yyabort; +}]b4_locations_if([[ + +/** Resolve the locations for each of the YYN1 states in *YYSTACKP, + * ending at YYS1. Has no effect on previously resolved states. + * The first semantic option of a state is always chosen. */ +static void +yyresolveLocations (yyGLRState *yys1, int yyn1, + yyGLRStack *yystackp]b4_user_formals[) +{ + if (0 < yyn1) + { + yyresolveLocations (yys1->yypred, yyn1 - 1, yystackp]b4_user_args[); + if (!yys1->yyresolved) + { + yyGLRStackItem yyrhsloc[1 + YYMAXRHS]; + int yynrhs; + yySemanticOption *yyoption = yys1->yysemantics.yyfirstVal; + YY_ASSERT (yyoption); + yynrhs = yyrhsLength (yyoption->yyrule); + if (0 < yynrhs) + { + yyGLRState *yys; + int yyn; + yyresolveLocations (yyoption->yystate, yynrhs, + yystackp]b4_user_args[); + for (yys = yyoption->yystate, yyn = yynrhs; + yyn > 0; + yys = yys->yypred, yyn -= 1) + yyrhsloc[yyn].yystate.yyloc = yys->yyloc; + } + else + { + /* Both yyresolveAction and yyresolveLocations traverse the GSS + in reverse rightmost order. It is only necessary to invoke + yyresolveLocations on a subforest for which yyresolveAction + would have been invoked next had an ambiguity not been + detected. Thus the location of the previous state (but not + necessarily the previous state itself) is guaranteed to be + resolved already. */ + yyGLRState *yyprevious = yyoption->yystate; + yyrhsloc[0].yystate.yyloc = yyprevious->yyloc; + } + YYLLOC_DEFAULT ((yys1->yyloc), yyrhsloc, yynrhs); + } + } +}]])[ + +/** Resolve the ambiguity represented in state YYS in *YYSTACKP, + * perform the indicated actions, and set the semantic value of YYS. + * If result != yyok, the chain of semantic options in YYS has been + * cleared instead or it has been left unmodified except that + * redundant options may have been removed. Regardless of whether + * result = yyok, YYS has been left with consistent data so that + * yydestroyGLRState can be invoked if necessary. */ +static YYRESULTTAG +yyresolveValue (yyGLRState* yys, yyGLRStack* yystackp]b4_user_formals[) +{ + yySemanticOption* yyoptionList = yys->yysemantics.yyfirstVal; + yySemanticOption* yybest = yyoptionList; + yySemanticOption** yypp; + yybool yymerge = yyfalse; + YYSTYPE yyval; + YYRESULTTAG yyflag;]b4_locations_if([ + YYLTYPE *yylocp = &yys->yyloc;])[ + + for (yypp = &yyoptionList->yynext; *yypp != YY_NULLPTR; ) + { + yySemanticOption* yyp = *yypp; + + if (yyidenticalOptions (yybest, yyp)) + { + yymergeOptionSets (yybest, yyp); + *yypp = yyp->yynext; + } + else + { + switch (yypreference (yybest, yyp)) + { + case 0:]b4_locations_if([[ + yyresolveLocations (yys, 1, yystackp]b4_user_args[);]])[ + return yyreportAmbiguity (yybest, yyp]b4_pure_args[); + break; + case 1: + yymerge = yytrue; + break; + case 2: + break; + case 3: + yybest = yyp; + yymerge = yyfalse; + break; + default: + /* This cannot happen so it is not worth a YY_ASSERT (yyfalse), + but some compilers complain if the default case is + omitted. */ + break; + } + yypp = &yyp->yynext; + } + } + + if (yymerge) + { + yySemanticOption* yyp; + int yyprec = yydprec[yybest->yyrule]; + yyflag = yyresolveAction (yybest, yystackp, &yyval]b4_locuser_args[); + if (yyflag == yyok) + for (yyp = yybest->yynext; yyp != YY_NULLPTR; yyp = yyp->yynext) + { + if (yyprec == yydprec[yyp->yyrule]) + { + YYSTYPE yyval_other;]b4_locations_if([ + YYLTYPE yydummy;])[ + yyflag = yyresolveAction (yyp, yystackp, &yyval_other]b4_locuser_args([&yydummy])[); + if (yyflag != yyok) + { + yydestruct ("Cleanup: discarding incompletely merged value for", + yy_accessing_symbol (yys->yylrState), + &yyval]b4_locuser_args[); + break; + } + yyuserMerge (yymerger[yyp->yyrule], &yyval, &yyval_other); + } + } + } + else + yyflag = yyresolveAction (yybest, yystackp, &yyval]b4_locuser_args([yylocp])[); + + if (yyflag == yyok) + { + yys->yyresolved = yytrue; + yys->yysemantics.yyval = yyval; + } + else + yys->yysemantics.yyfirstVal = YY_NULLPTR; + return yyflag; +} + +static YYRESULTTAG +yyresolveStack (yyGLRStack* yystackp]b4_user_formals[) +{ + if (yystackp->yysplitPoint != YY_NULLPTR) + { + yyGLRState* yys; + int yyn; + + for (yyn = 0, yys = yystackp->yytops.yystates[0]; + yys != yystackp->yysplitPoint; + yys = yys->yypred, yyn += 1) + continue; + YYCHK (yyresolveStates (yystackp->yytops.yystates[0], yyn, yystackp + ]b4_user_args[)); + } + return yyok; +} + +/** Called when returning to deterministic operation to clean up the extra + * stacks. */ +static void +yycompressStack (yyGLRStack* yystackp) +{ + /* yyr is the state after the split point. */ + yyGLRState *yyr; + + if (yystackp->yytops.yysize != 1 || yystackp->yysplitPoint == YY_NULLPTR) + return; + + { + yyGLRState *yyp, *yyq; + for (yyp = yystackp->yytops.yystates[0], yyq = yyp->yypred, yyr = YY_NULLPTR; + yyp != yystackp->yysplitPoint; + yyr = yyp, yyp = yyq, yyq = yyp->yypred) + yyp->yypred = yyr; + } + + yystackp->yyspaceLeft += yystackp->yynextFree - yystackp->yyitems; + yystackp->yynextFree = YY_REINTERPRET_CAST (yyGLRStackItem*, yystackp->yysplitPoint) + 1; + yystackp->yyspaceLeft -= yystackp->yynextFree - yystackp->yyitems; + yystackp->yysplitPoint = YY_NULLPTR; + yystackp->yylastDeleted = YY_NULLPTR; + + while (yyr != YY_NULLPTR) + { + yystackp->yynextFree->yystate = *yyr; + yyr = yyr->yypred; + yystackp->yynextFree->yystate.yypred = &yystackp->yynextFree[-1].yystate; + yystackp->yytops.yystates[0] = &yystackp->yynextFree->yystate; + yystackp->yynextFree += 1; + yystackp->yyspaceLeft -= 1; + } +} + +static YYRESULTTAG +yyprocessOneStack (yyGLRStack* yystackp, YYPTRDIFF_T yyk, + YYPTRDIFF_T yyposn]b4_pure_formals[) +{ + while (yystackp->yytops.yystates[yyk] != YY_NULLPTR) + { + yy_state_t yystate = yystackp->yytops.yystates[yyk]->yylrState; + YY_DPRINTF ((stderr, "Stack %ld Entering state %d\n", + YY_CAST (long, yyk), yystate)); + + YY_ASSERT (yystate != YYFINAL); + + if (yyisDefaultedState (yystate)) + { + YYRESULTTAG yyflag; + yyRuleNum yyrule = yydefaultAction (yystate); + if (yyrule == 0) + { + YY_DPRINTF ((stderr, "Stack %ld dies.\n", YY_CAST (long, yyk))); + yymarkStackDeleted (yystackp, yyk); + return yyok; + } + yyflag = yyglrReduce (yystackp, yyk, yyrule, yyimmediate[yyrule]]b4_user_args[); + if (yyflag == yyerr) + { + YY_DPRINTF ((stderr, + "Stack %ld dies " + "(predicate failure or explicit user error).\n", + YY_CAST (long, yyk))); + yymarkStackDeleted (yystackp, yyk); + return yyok; + } + if (yyflag != yyok) + return yyflag; + } + else + { + yysymbol_kind_t yytoken = ]b4_yygetToken_call[; + const short* yyconflicts; + const int yyaction = yygetLRActions (yystate, yytoken, &yyconflicts); + yystackp->yytops.yylookaheadNeeds[yyk] = yytrue; + + for (/* nothing */; *yyconflicts; yyconflicts += 1) + { + YYRESULTTAG yyflag; + YYPTRDIFF_T yynewStack = yysplitStack (yystackp, yyk); + YY_DPRINTF ((stderr, "Splitting off stack %ld from %ld.\n", + YY_CAST (long, yynewStack), YY_CAST (long, yyk))); + yyflag = yyglrReduce (yystackp, yynewStack, + *yyconflicts, + yyimmediate[*yyconflicts]]b4_user_args[); + if (yyflag == yyok) + YYCHK (yyprocessOneStack (yystackp, yynewStack, + yyposn]b4_pure_args[)); + else if (yyflag == yyerr) + { + YY_DPRINTF ((stderr, "Stack %ld dies.\n", YY_CAST (long, yynewStack))); + yymarkStackDeleted (yystackp, yynewStack); + } + else + return yyflag; + } + + if (yyisShiftAction (yyaction)) + break; + else if (yyisErrorAction (yyaction)) + { + YY_DPRINTF ((stderr, "Stack %ld dies.\n", YY_CAST (long, yyk))); + yymarkStackDeleted (yystackp, yyk); + break; + } + else + { + YYRESULTTAG yyflag = yyglrReduce (yystackp, yyk, -yyaction, + yyimmediate[-yyaction]]b4_user_args[); + if (yyflag == yyerr) + { + YY_DPRINTF ((stderr, + "Stack %ld dies " + "(predicate failure or explicit user error).\n", + YY_CAST (long, yyk))); + yymarkStackDeleted (yystackp, yyk); + break; + } + else if (yyflag != yyok) + return yyflag; + } + } + } + return yyok; +} + +]b4_parse_error_case([simple], [], +[[/* Put in YYARG at most YYARGN of the expected tokens given the + current YYSTACKP, and return the number of tokens stored in YYARG. If + YYARG is null, return the number of expected tokens (guaranteed to + be less than YYNTOKENS). */ +static int +yypcontext_expected_tokens (const yyGLRStack* yystackp, + yysymbol_kind_t yyarg[], int yyargn) +{ + /* Actual size of YYARG. */ + int yycount = 0; + int yyn = yypact[yystackp->yytops.yystates[0]->yylrState]; + 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; + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != ]b4_symbol(error, kind)[ + && !yytable_value_is_error (yytable[yyx + yyn])) + { + if (!yyarg) + ++yycount; + else if (yycount == yyargn) + return 0; + else + yyarg[yycount++] = YY_CAST (yysymbol_kind_t, yyx); + } + } + if (yyarg && yycount == 0 && 0 < yyargn) + yyarg[0] = ]b4_symbol(empty, kind)[; + return yycount; +}]])[ + +]b4_parse_error_bmatch( + [custom], +[[/* User defined function to report a syntax error. */ +typedef yyGLRStack yypcontext_t; +static int +yyreport_syntax_error (const yyGLRStack* yystackp]b4_user_formals[); + +/* The kind of the lookahead of this context. */ +static yysymbol_kind_t +yypcontext_token (const yyGLRStack *yystackp) YY_ATTRIBUTE_UNUSED; + +static yysymbol_kind_t +yypcontext_token (const yyGLRStack *yystackp) +{ + YY_USE (yystackp); + yysymbol_kind_t yytoken = yychar == ]b4_symbol(empty, id)[ ? ]b4_symbol(empty, kind)[ : YYTRANSLATE (yychar); + return yytoken; +} + +]b4_locations_if([[/* The location of the lookahead of this context. */ +static const YYLTYPE * +yypcontext_location (const yyGLRStack *yystackp) YY_ATTRIBUTE_UNUSED; + +static const YYLTYPE * +yypcontext_location (const yyGLRStack *yystackp) +{ + YY_USE (yystackp); + return &yylloc; +}]])], + [detailed\|verbose], +[[static int +yy_syntax_error_arguments (const yyGLRStack* yystackp, + yysymbol_kind_t yyarg[], int yyargn) +{ + yysymbol_kind_t yytoken = yychar == ]b4_symbol(empty, id)[ ? ]b4_symbol(empty, kind)[ : YYTRANSLATE (yychar); + /* Actual size of YYARG. */ + int yycount = 0; + /* There are many possibilities here to consider: + - 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 != ]b4_symbol(empty, kind)[) + { + int yyn; + if (yyarg) + yyarg[yycount] = yytoken; + ++yycount; + yyn = yypcontext_expected_tokens (yystackp, + yyarg ? yyarg + 1 : yyarg, yyargn - 1); + if (yyn == YYENOMEM) + return YYENOMEM; + else + yycount += yyn; + } + return yycount; +} +]])[ + + +static void +yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[) +{ + if (yystackp->yyerrState != 0) + return; +]b4_parse_error_case( + [custom], +[[ if (yyreport_syntax_error (yystackp]b4_user_args[)) + yyMemoryExhausted (yystackp);]], + [simple], +[[ yyerror (]b4_lyyerror_args[YY_("syntax error"));]], +[[ { + yybool yysize_overflow = yyfalse; + char* yymsg = YY_NULLPTR; + enum { YYARGS_MAX = 5 }; + /* Internationalized format string. */ + const char *yyformat = YY_NULLPTR; + /* Arguments of yyformat: reported tokens (one for the "unexpected", + one per "expected"). */ + yysymbol_kind_t yyarg[YYARGS_MAX]; + /* Cumulated lengths of YYARG. */ + YYPTRDIFF_T yysize = 0; + + /* Actual size of YYARG. */ + int yycount + = yy_syntax_error_arguments (yystackp, yyarg, YYARGS_MAX); + if (yycount == YYENOMEM) + yyMemoryExhausted (yystackp); + + switch (yycount) + { +#define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + default: /* Avoid compiler warnings. */ + 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_ + } + + /* Compute error message size. Don't count the "%s"s, but reserve + room for the terminator. */ + yysize = yystrlen (yyformat) - 2 * yycount + 1; + { + int yyi; + for (yyi = 0; yyi < yycount; ++yyi) + { + YYPTRDIFF_T yysz + = ]b4_parse_error_case( + [verbose], [[yytnamerr (YY_NULLPTR, yytname[yyarg[yyi]])]], + [[yystrlen (yysymbol_name (yyarg[yyi]))]]);[ + if (YYSIZE_MAXIMUM - yysize < yysz) + yysize_overflow = yytrue; + else + yysize += yysz; + } + } + + if (!yysize_overflow) + yymsg = YY_CAST (char *, YYMALLOC (YY_CAST (YYSIZE_T, yysize))); + + if (yymsg) + { + char *yyp = yymsg; + int yyi = 0; + while ((*yyp = *yyformat)) + { + if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) + {]b4_parse_error_case([verbose], [[ + yyp += yytnamerr (yyp, yytname[yyarg[yyi++]]);]], [[ + yyp = yystpcpy (yyp, yysymbol_name (yyarg[yyi++]));]])[ + yyformat += 2; + } + else + { + ++yyp; + ++yyformat; + } + } + yyerror (]b4_lyyerror_args[yymsg); + YYFREE (yymsg); + } + else + { + yyerror (]b4_lyyerror_args[YY_("syntax error")); + yyMemoryExhausted (yystackp); + } + }]])[ + yynerrs += 1; +} + +/* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP, + yylval, and yylloc are the syntactic category, semantic value, and location + of the lookahead. */ +static void +yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[) +{ + if (yystackp->yyerrState == 3) + /* We just shifted the error token and (perhaps) took some + reductions. Skip tokens until we can proceed. */ + while (yytrue) + { + yysymbol_kind_t yytoken; + int yyj; + if (yychar == ]b4_symbol(eof, [id])[) + yyFail (yystackp][]b4_lpure_args[, YY_NULLPTR); + if (yychar != ]b4_symbol(empty, id)[) + {]b4_locations_if([[ + /* We throw away the lookahead, but the error range + of the shifted error token must take it into account. */ + yyGLRState *yys = yystackp->yytops.yystates[0]; + yyGLRStackItem yyerror_range[3]; + yyerror_range[1].yystate.yyloc = yys->yyloc; + yyerror_range[2].yystate.yyloc = yylloc; + YYLLOC_DEFAULT ((yys->yyloc), yyerror_range, 2);]])[ + yytoken = YYTRANSLATE (yychar); + yydestruct ("Error: discarding", + yytoken, &yylval]b4_locuser_args([&yylloc])[); + yychar = ]b4_symbol(empty, id)[; + } + yytoken = ]b4_yygetToken_call[; + yyj = yypact[yystackp->yytops.yystates[0]->yylrState]; + if (yypact_value_is_default (yyj)) + return; + yyj += yytoken; + if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != yytoken) + { + if (yydefact[yystackp->yytops.yystates[0]->yylrState] != 0) + return; + } + else if (! yytable_value_is_error (yytable[yyj])) + return; + } + + /* Reduce to one stack. */ + { + YYPTRDIFF_T yyk; + for (yyk = 0; yyk < yystackp->yytops.yysize; yyk += 1) + if (yystackp->yytops.yystates[yyk] != YY_NULLPTR) + break; + if (yyk >= yystackp->yytops.yysize) + yyFail (yystackp][]b4_lpure_args[, YY_NULLPTR); + for (yyk += 1; yyk < yystackp->yytops.yysize; yyk += 1) + yymarkStackDeleted (yystackp, yyk); + yyremoveDeletes (yystackp); + yycompressStack (yystackp); + } + + /* Pop stack until we find a state that shifts the error token. */ + yystackp->yyerrState = 3; + while (yystackp->yytops.yystates[0] != YY_NULLPTR) + { + yyGLRState *yys = yystackp->yytops.yystates[0]; + int yyj = yypact[yys->yylrState]; + if (! yypact_value_is_default (yyj)) + { + yyj += ]b4_symbol(error, kind)[; + if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == ]b4_symbol(error, kind)[ + && yyisShiftAction (yytable[yyj])) + { + /* Shift the error token. */ + int yyaction = yytable[yyj];]b4_locations_if([[ + /* First adjust its location.*/ + YYLTYPE yyerrloc; + yystackp->yyerror_range[2].yystate.yyloc = yylloc; + YYLLOC_DEFAULT (yyerrloc, (yystackp->yyerror_range), 2);]])[ + YY_SYMBOL_PRINT ("Shifting", yy_accessing_symbol (yyaction), + &yylval, &yyerrloc); + yyglrShift (yystackp, 0, yyaction, + yys->yyposn, &yylval]b4_locations_if([, &yyerrloc])[); + yys = yystackp->yytops.yystates[0]; + break; + } + }]b4_locations_if([[ + yystackp->yyerror_range[1].yystate.yyloc = yys->yyloc;]])[ + if (yys->yypred != YY_NULLPTR) + yydestroyGLRState ("Error: popping", yys]b4_user_args[); + yystackp->yytops.yystates[0] = yys->yypred; + yystackp->yynextFree -= 1; + yystackp->yyspaceLeft += 1; + } + if (yystackp->yytops.yystates[0] == YY_NULLPTR) + yyFail (yystackp][]b4_lpure_args[, YY_NULLPTR); +} + +#define YYCHK1(YYE) \ + do { \ + switch (YYE) { \ + case yyok: break; \ + case yyabort: goto yyabortlab; \ + case yyaccept: goto yyacceptlab; \ + case yyerr: goto yyuser_error; \ + case yynomem: goto yyexhaustedlab; \ + default: goto yybuglab; \ + } \ + } while (0) + +/*----------. +| yyparse. | +`----------*/ + +int +]b4_glr_cc_if([yy_parse_impl], [yyparse])[ (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[) +{ + int yyresult; + yyGLRStack yystack; + yyGLRStack* const yystackp = &yystack; + YYPTRDIFF_T yyposn; + + YY_DPRINTF ((stderr, "Starting parse\n")); + + yychar = ]b4_symbol(empty, id)[; + yylval = yyval_default;]b4_locations_if([ + yylloc = yyloc_default;])[ +]m4_ifdef([b4_initial_action], [ +b4_dollar_pushdef([yylval], [], [], [yylloc])dnl + b4_user_initial_action +b4_dollar_popdef])[]dnl +[ + if (! yyinitGLRStack (yystackp, YYINITDEPTH)) + goto yyexhaustedlab; + switch (YYSETJMP (yystack.yyexception_buffer)) + { + case 0: break; + case 1: goto yyabortlab; + case 2: goto yyexhaustedlab; + default: goto yybuglab; + } + yyglrShift (&yystack, 0, 0, 0, &yylval]b4_locations_if([, &yylloc])[); + yyposn = 0; + + while (yytrue) + { + /* For efficiency, we have two loops, the first of which is + specialized to deterministic operation (single stack, no + potential ambiguity). */ + /* Standard mode. */ + while (yytrue) + { + yy_state_t yystate = yystack.yytops.yystates[0]->yylrState; + YY_DPRINTF ((stderr, "Entering state %d\n", yystate)); + if (yystate == YYFINAL) + goto yyacceptlab; + if (yyisDefaultedState (yystate)) + { + yyRuleNum yyrule = yydefaultAction (yystate); + if (yyrule == 0) + {]b4_locations_if([[ + yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[ + yyreportSyntaxError (&yystack]b4_user_args[); + goto yyuser_error; + } + YYCHK1 (yyglrReduce (&yystack, 0, yyrule, yytrue]b4_user_args[)); + } + else + { + yysymbol_kind_t yytoken = ]b4_yygetToken_call;[ + const short* yyconflicts; + int yyaction = yygetLRActions (yystate, yytoken, &yyconflicts); + if (*yyconflicts) + /* Enter nondeterministic mode. */ + break; + if (yyisShiftAction (yyaction)) + { + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); + yychar = ]b4_symbol(empty, id)[; + yyposn += 1; + yyglrShift (&yystack, 0, yyaction, yyposn, &yylval]b4_locations_if([, &yylloc])[); + if (0 < yystack.yyerrState) + yystack.yyerrState -= 1; + } + else if (yyisErrorAction (yyaction)) + {]b4_locations_if([[ + yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[ + /* Issue an error message unless the scanner already + did. */ + if (yychar != ]b4_symbol(error, id)[) + yyreportSyntaxError (&yystack]b4_user_args[); + goto yyuser_error; + } + else + YYCHK1 (yyglrReduce (&yystack, 0, -yyaction, yytrue]b4_user_args[)); + } + } + + /* Nondeterministic mode. */ + while (yytrue) + { + yysymbol_kind_t yytoken_to_shift; + YYPTRDIFF_T yys; + + for (yys = 0; yys < yystack.yytops.yysize; yys += 1) + yystackp->yytops.yylookaheadNeeds[yys] = yychar != ]b4_symbol(empty, id)[; + + /* yyprocessOneStack returns one of three things: + + - An error flag. If the caller is yyprocessOneStack, it + immediately returns as well. When the caller is finally + yyparse, it jumps to an error label via YYCHK1. + + - yyok, but yyprocessOneStack has invoked yymarkStackDeleted + (&yystack, yys), which sets the top state of yys to NULL. Thus, + yyparse's following invocation of yyremoveDeletes will remove + the stack. + + - yyok, when ready to shift a token. + + Except in the first case, yyparse will invoke yyremoveDeletes and + then shift the next token onto all remaining stacks. This + synchronization of the shift (that is, after all preceding + reductions on all stacks) helps prevent double destructor calls + on yylval in the event of memory exhaustion. */ + + for (yys = 0; yys < yystack.yytops.yysize; yys += 1) + YYCHK1 (yyprocessOneStack (&yystack, yys, yyposn]b4_lpure_args[)); + yyremoveDeletes (&yystack); + if (yystack.yytops.yysize == 0) + { + yyundeleteLastStack (&yystack); + if (yystack.yytops.yysize == 0) + yyFail (&yystack][]b4_lpure_args[, YY_("syntax error")); + YYCHK1 (yyresolveStack (&yystack]b4_user_args[)); + YY_DPRINTF ((stderr, "Returning to deterministic operation.\n"));]b4_locations_if([[ + yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[ + yyreportSyntaxError (&yystack]b4_user_args[); + goto yyuser_error; + } + + /* If any yyglrShift call fails, it will fail after shifting. Thus, + a copy of yylval will already be on stack 0 in the event of a + failure in the following loop. Thus, yychar is set to ]b4_symbol(empty, id)[ + before the loop to make sure the user destructor for yylval isn't + called twice. */ + yytoken_to_shift = YYTRANSLATE (yychar); + yychar = ]b4_symbol(empty, id)[; + yyposn += 1; + for (yys = 0; yys < yystack.yytops.yysize; yys += 1) + { + yy_state_t yystate = yystack.yytops.yystates[yys]->yylrState; + const short* yyconflicts; + int yyaction = yygetLRActions (yystate, yytoken_to_shift, + &yyconflicts); + /* Note that yyconflicts were handled by yyprocessOneStack. */ + YY_DPRINTF ((stderr, "On stack %ld, ", YY_CAST (long, yys))); + YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, &yylval, &yylloc); + yyglrShift (&yystack, yys, yyaction, yyposn, + &yylval]b4_locations_if([, &yylloc])[); + YY_DPRINTF ((stderr, "Stack %ld now in state %d\n", + YY_CAST (long, yys), + yystack.yytops.yystates[yys]->yylrState)); + } + + if (yystack.yytops.yysize == 1) + { + YYCHK1 (yyresolveStack (&yystack]b4_user_args[)); + YY_DPRINTF ((stderr, "Returning to deterministic operation.\n")); + yycompressStack (&yystack); + break; + } + } + continue; + yyuser_error: + yyrecoverSyntaxError (&yystack]b4_user_args[); + yyposn = yystack.yytops.yystates[0]->yyposn; + } + + yyacceptlab: + yyresult = 0; + goto yyreturnlab; + + yybuglab: + YY_ASSERT (yyfalse); + goto yyabortlab; + + yyabortlab: + yyresult = 1; + goto yyreturnlab; + + yyexhaustedlab: + yyerror (]b4_lyyerror_args[YY_("memory exhausted")); + yyresult = 2; + goto yyreturnlab; + + yyreturnlab: + if (yychar != ]b4_symbol(empty, id)[) + yydestruct ("Cleanup: discarding lookahead", + YYTRANSLATE (yychar), &yylval]b4_locuser_args([&yylloc])[); + + /* If the stack is well-formed, pop the stack until it is empty, + destroying its entries as we go. But free the stack regardless + of whether it is well-formed. */ + if (yystack.yyitems) + { + yyGLRState** yystates = yystack.yytops.yystates; + if (yystates) + { + YYPTRDIFF_T yysize = yystack.yytops.yysize; + YYPTRDIFF_T yyk; + for (yyk = 0; yyk < yysize; yyk += 1) + if (yystates[yyk]) + { + while (yystates[yyk]) + { + yyGLRState *yys = yystates[yyk];]b4_locations_if([[ + yystack.yyerror_range[1].yystate.yyloc = yys->yyloc;]])[ + if (yys->yypred != YY_NULLPTR) + yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[); + yystates[yyk] = yys->yypred; + yystack.yynextFree -= 1; + yystack.yyspaceLeft += 1; + } + break; + } + } + yyfreeGLRStack (&yystack); + } + + return yyresult; +} + +/* DEBUGGING ONLY */ +#if ]b4_api_PREFIX[DEBUG +/* Print *YYS and its predecessors. */ +static void +yy_yypstack (yyGLRState* yys) +{ + if (yys->yypred) + { + yy_yypstack (yys->yypred); + YY_FPRINTF ((stderr, " -> ")); + } + YY_FPRINTF ((stderr, "%d@@%ld", yys->yylrState, YY_CAST (long, yys->yyposn))); +} + +/* Print YYS (possibly NULL) and its predecessors. */ +static void +yypstates (yyGLRState* yys) +{ + if (yys == YY_NULLPTR) + YY_FPRINTF ((stderr, "")); + else + yy_yypstack (yys); + YY_FPRINTF ((stderr, "\n")); +} + +/* Print the stack #YYK. */ +static void +yypstack (yyGLRStack* yystackp, YYPTRDIFF_T yyk) +{ + yypstates (yystackp->yytops.yystates[yyk]); +} + +/* Print all the stacks. */ +static void +yypdumpstack (yyGLRStack* yystackp) +{ +#define YYINDEX(YYX) \ + YY_CAST (long, \ + ((YYX) \ + ? YY_REINTERPRET_CAST (yyGLRStackItem*, (YYX)) - yystackp->yyitems \ + : -1)) + + yyGLRStackItem* yyp; + for (yyp = yystackp->yyitems; yyp < yystackp->yynextFree; yyp += 1) + { + YY_FPRINTF ((stderr, "%3ld. ", + YY_CAST (long, yyp - yystackp->yyitems))); + if (*YY_REINTERPRET_CAST (yybool *, yyp)) + { + YY_ASSERT (yyp->yystate.yyisState); + YY_ASSERT (yyp->yyoption.yyisState); + YY_FPRINTF ((stderr, "Res: %d, LR State: %d, posn: %ld, pred: %ld", + yyp->yystate.yyresolved, yyp->yystate.yylrState, + YY_CAST (long, yyp->yystate.yyposn), + YYINDEX (yyp->yystate.yypred))); + if (! yyp->yystate.yyresolved) + YY_FPRINTF ((stderr, ", firstVal: %ld", + YYINDEX (yyp->yystate.yysemantics.yyfirstVal))); + } + else + { + YY_ASSERT (!yyp->yystate.yyisState); + YY_ASSERT (!yyp->yyoption.yyisState); + YY_FPRINTF ((stderr, "Option. rule: %d, state: %ld, next: %ld", + yyp->yyoption.yyrule - 1, + YYINDEX (yyp->yyoption.yystate), + YYINDEX (yyp->yyoption.yynext))); + } + YY_FPRINTF ((stderr, "\n")); + } + + YY_FPRINTF ((stderr, "Tops:")); + { + YYPTRDIFF_T yyi; + for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1) + YY_FPRINTF ((stderr, "%ld: %ld; ", YY_CAST (long, yyi), + YYINDEX (yystackp->yytops.yystates[yyi]))); + YY_FPRINTF ((stderr, "\n")); + } +#undef YYINDEX +} +#endif + +#undef yylval +#undef yychar +#undef yynerrs]b4_locations_if([ +#undef yylloc]) + +m4_if(b4_prefix, [yy], [], +[[/* Substitute the variable and function names. */ +#define yyparse ]b4_prefix[parse +#define yylex ]b4_prefix[lex +#define yyerror ]b4_prefix[error +#define yylval ]b4_prefix[lval +#define yychar ]b4_prefix[char +#define yydebug ]b4_prefix[debug +#define yynerrs ]b4_prefix[nerrs]b4_locations_if([[ +#define yylloc ]b4_prefix[lloc]])])[ + +]b4_glr_cc_if([b4_glr_cc_pre_epilogue +b4_glr_cc_cleanup])[ +]b4_percent_code_get([[epilogue]])[]dnl +b4_epilogue[]dnl +b4_output_end diff --git a/Engine/bin/bison-flex/data/skeletons/glr.cc b/Engine/bin/bison-flex/data/skeletons/glr.cc new file mode 100644 index 000000000..7181402f3 --- /dev/null +++ b/Engine/bin/bison-flex/data/skeletons/glr.cc @@ -0,0 +1,397 @@ +# C++ GLR skeleton for Bison + +# Copyright (C) 2002-2015, 2018-2021 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +# This skeleton produces a C++ class that encapsulates a C glr parser. +# This is in order to reduce the maintenance burden. The glr.c +# skeleton is clean and pure enough so that there are no real +# problems. The C++ interface is the same as that of lalr1.cc. In +# fact, glr.c can replace yacc.c without the user noticing any +# difference, and similarly for glr.cc replacing lalr1.cc. +# +# The passing of parse-params +# +# The additional arguments are stored as members of the parser +# object, yyparser. The C routines need to carry yyparser +# throughout the C parser; that's easy: make yyparser an +# additional parse-param. But because the C++ skeleton needs to +# know the "real" original parse-param, we save them +# (b4_parse_param_orig). Note that b4_parse_param is overquoted +# (and c.m4 strips one level of quotes). This is a PITA, and +# explains why there are so many levels of quotes. +# +# The locations +# +# We use location.cc just like lalr1.cc, but because glr.c stores +# the locations in a union, the position and location classes +# must not have a constructor. Therefore, contrary to lalr1.cc, we +# must not define "b4_location_constructors". As a consequence the +# user must initialize the first positions (in particular the +# filename member). + +# We require a pure interface. +m4_define([b4_pure_flag], [1]) + +m4_include(b4_skeletonsdir/[c++.m4]) +b4_bison_locations_if([m4_include(b4_skeletonsdir/[location.cc])]) + +m4_define([b4_parser_class], + [b4_percent_define_get([[api.parser.class]])]) + +# Save the parse parameters. +m4_define([b4_parse_param_orig], m4_defn([b4_parse_param])) + +# b4_parse_param_wrap +# ------------------- +# New ones. +m4_ifset([b4_parse_param], +[m4_define([b4_parse_param_wrap], + [[b4_namespace_ref::b4_parser_class[& yyparser], [[yyparser]]],] +m4_defn([b4_parse_param]))], +[m4_define([b4_parse_param_wrap], + [[b4_namespace_ref::b4_parser_class[& yyparser], [[yyparser]]]]) +]) + + +# b4_yy_symbol_print_define +# ------------------------- +# Bypass the default implementation to generate the "yy_symbol_print" +# and "yy_symbol_value_print" functions. +m4_define([b4_yy_symbol_print_define], +[[/*--------------------. +| Print this symbol. | +`--------------------*/ + +static void +yy_symbol_print (FILE *, ]b4_namespace_ref::b4_parser_class[::symbol_kind_type yytoken, + const ]b4_namespace_ref::b4_parser_class[::value_type *yyvaluep]b4_locations_if([[, + const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp]])[]b4_user_formals[) +{ +]b4_parse_param_use[]dnl +[ yyparser.yy_symbol_print_ (yytoken, yyvaluep]b4_locations_if([, yylocationp])[); +} +]])[ + +# Hijack the initial action to initialize the locations. +]b4_bison_locations_if([m4_define([b4_initial_action], +[yylloc.initialize ();]m4_ifdef([b4_initial_action], [ +m4_defn([b4_initial_action])]))])[ + +# Hijack the post prologue to declare yyerror. +]m4_append([b4_post_prologue], +[b4_syncline([@oline@], [@ofile@])dnl +[static void +yyerror (]b4_locations_if([[const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp, + ]])[]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param), + ])[const char* msg);]])[ + +# Inserted before the epilogue to define implementations (yyerror, parser member +# functions etc.). +]m4_define([b4_glr_cc_pre_epilogue], +[b4_syncline([@oline@], [@ofile@])dnl +[ +/*------------------. +| Report an error. | +`------------------*/ + +static void +yyerror (]b4_locations_if([[const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp, + ]])[]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param), + ])[const char* msg) +{ +]b4_parse_param_use[]dnl +[ yyparser.error (]b4_locations_if([[*yylocationp, ]])[msg); +} + + +]b4_namespace_open[ +]dnl In this section, the parse params are the original parse_params. +m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl +[ /// Build a parser object. + ]b4_parser_class::b4_parser_class[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [ + :])[ +#if ]b4_api_PREFIX[DEBUG + ]m4_ifset([b4_parse_param], [ ], [ :])[yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[ +#endif]b4_parse_param_cons[ + {} + + ]b4_parser_class::~b4_parser_class[ () + {} + + ]b4_parser_class[::syntax_error::~syntax_error () YY_NOEXCEPT YY_NOTHROW + {} + + int + ]b4_parser_class[::operator() () + { + return parse (); + } + + int + ]b4_parser_class[::parse () + { + return ::yy_parse_impl (*this]b4_user_args[); + } + +#if ]b4_api_PREFIX[DEBUG + /*--------------------. + | Print this symbol. | + `--------------------*/ + + void + ]b4_parser_class[::yy_symbol_value_print_ (symbol_kind_type yykind, + const value_type* yyvaluep]b4_locations_if([[, + const location_type* yylocationp]])[) const + {]b4_locations_if([[ + YY_USE (yylocationp);]])[ + YY_USE (yyvaluep); + std::ostream& yyo = debug_stream (); + std::ostream& yyoutput = yyo; + YY_USE (yyoutput); + ]b4_symbol_actions([printer])[ + } + + + void + ]b4_parser_class[::yy_symbol_print_ (symbol_kind_type yykind, + const value_type* yyvaluep]b4_locations_if([[, + const location_type* yylocationp]])[) const + { + *yycdebug_ << (yykind < YYNTOKENS ? "token" : "nterm") + << ' ' << yysymbol_name (yykind) << " ("]b4_locations_if([[ + << *yylocationp << ": "]])[; + yy_symbol_value_print_ (yykind, yyvaluep]b4_locations_if([[, yylocationp]])[); + *yycdebug_ << ')'; + } + + std::ostream& + ]b4_parser_class[::debug_stream () const + { + return *yycdebug_; + } + + void + ]b4_parser_class[::set_debug_stream (std::ostream& o) + { + yycdebug_ = &o; + } + + + ]b4_parser_class[::debug_level_type + ]b4_parser_class[::debug_level () const + { + return yydebug; + } + + void + ]b4_parser_class[::set_debug_level (debug_level_type l) + { + // Actually, it is yydebug which is really used. + yydebug = l; + } + +#endif +]m4_popdef([b4_parse_param])dnl +b4_namespace_close[]dnl +]) + + +m4_define([b4_define_symbol_kind], +[m4_format([#define %-15s %s], + b4_symbol($][1, kind_base), + b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol($1, kind_base)) +]) + +# b4_glr_cc_setup +# --------------- +# Setup redirections for glr.c: Map the names used in c.m4 to the ones used +# in c++.m4. +m4_define([b4_glr_cc_setup], +[[]b4_attribute_define[ +]b4_null_define[ + +// This skeleton is based on C, yet compiles it as C++. +// So expect warnings about C style casts. +#if defined __clang__ && 306 <= __clang_major__ * 100 + __clang_minor__ +# pragma clang diagnostic ignored "-Wold-style-cast" +#elif defined __GNUC__ && 406 <= __GNUC__ * 100 + __GNUC_MINOR__ +# pragma GCC diagnostic ignored "-Wold-style-cast" +#endif + +// On MacOS, PTRDIFF_MAX is defined as long long, which Clang's +// -pedantic reports as being a C++11 extension. +#if defined __APPLE__ && YY_CPLUSPLUS < 201103L \ + && defined __clang__ && 4 <= __clang_major__ +# pragma clang diagnostic ignored "-Wc++11-long-long" +#endif + +#undef ]b4_symbol(empty, [id])[ +#define ]b4_symbol(empty, [id])[ ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(empty, [id])[ +#undef ]b4_symbol(eof, [id])[ +#define ]b4_symbol(eof, [id])[ ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(eof, [id])[ +#undef ]b4_symbol(error, [id])[ +#define ]b4_symbol(error, [id])[ ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(error, [id])[ + +#ifndef ]b4_api_PREFIX[STYPE +# define ]b4_api_PREFIX[STYPE ]b4_namespace_ref[::]b4_parser_class[::value_type +#endif +#ifndef ]b4_api_PREFIX[LTYPE +# define ]b4_api_PREFIX[LTYPE ]b4_namespace_ref[::]b4_parser_class[::location_type +#endif + +typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind_type yysymbol_kind_t; + +// Expose C++ symbol kinds to C. +]b4_define_symbol_kind(-2)dnl +b4_symbol_foreach([b4_define_symbol_kind])])[ +]]) + + +m4_define([b4_undef_symbol_kind], +[[#undef ]b4_symbol($1, kind_base)[ +]]) + + +# b4_glr_cc_cleanup +# ----------------- +# Remove redirections for glr.c. +m4_define([b4_glr_cc_cleanup], +[[#undef ]b4_symbol(empty, [id])[ +#undef ]b4_symbol(eof, [id])[ +#undef ]b4_symbol(error, [id])[ + +]b4_undef_symbol_kind(-2)dnl +b4_symbol_foreach([b4_undef_symbol_kind])dnl +]) + + +# b4_shared_declarations(hh|cc) +# ----------------------------- +# Declaration that might either go into the header (if --header, $1 = hh) +# or in the implementation file. +m4_define([b4_shared_declarations], +[m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl +b4_percent_code_get([[requires]])[ +#include +#include +#include + +]b4_cxx_portability[ +]m4_ifdef([b4_location_include], + [[# include ]b4_location_include])[ +]b4_variant_if([b4_variant_includes])[ + +// Whether we are compiled with exception support. +#ifndef YY_EXCEPTIONS +# if defined __GNUC__ && !defined __EXCEPTIONS +# define YY_EXCEPTIONS 0 +# else +# define YY_EXCEPTIONS 1 +# endif +#endif + +]b4_YYDEBUG_define[ + +]b4_namespace_open[ + +]b4_bison_locations_if([m4_ifndef([b4_location_file], + [b4_location_define])])[ + + /// A Bison parser. + class ]b4_parser_class[ + { + public: +]b4_public_types_declare[ + + /// Build a parser object. + ]b4_parser_class[ (]b4_parse_param_decl[); + virtual ~]b4_parser_class[ (); + + /// Parse. An alias for parse (). + /// \returns 0 iff parsing succeeded. + int operator() (); + + /// Parse. + /// \returns 0 iff parsing succeeded. + virtual int parse (); + +#if ]b4_api_PREFIX[DEBUG + /// The current debugging stream. + std::ostream& debug_stream () const; + /// Set the current debugging stream. + void set_debug_stream (std::ostream &); + + /// Type for debugging levels. + typedef int debug_level_type; + /// The current debugging level. + debug_level_type debug_level () const; + /// Set the current debugging level. + void set_debug_level (debug_level_type l); +#endif + + /// Report a syntax error.]b4_locations_if([[ + /// \param loc where the syntax error is found.]])[ + /// \param msg a description of the syntax error. + virtual void error (]b4_locations_if([[const location_type& loc, ]])[const std::string& msg); + +# if ]b4_api_PREFIX[DEBUG + public: + /// \brief Report a symbol value on the debug stream. + /// \param yykind The symbol kind. + /// \param yyvaluep Its semantic value.]b4_locations_if([[ + /// \param yylocationp Its location.]])[ + virtual void yy_symbol_value_print_ (symbol_kind_type yykind, + const value_type* yyvaluep]b4_locations_if([[, + const location_type* yylocationp]])[) const; + /// \brief Report a symbol on the debug stream. + /// \param yykind The symbol kind. + /// \param yyvaluep Its semantic value.]b4_locations_if([[ + /// \param yylocationp Its location.]])[ + virtual void yy_symbol_print_ (symbol_kind_type yykind, + const value_type* yyvaluep]b4_locations_if([[, + const location_type* yylocationp]])[) const; + private: + /// Debug stream. + std::ostream* yycdebug_; +#endif + +]b4_parse_param_vars[ + }; + +]b4_namespace_close[ + +]b4_percent_code_get([[provides]])[ +]m4_popdef([b4_parse_param])dnl +])[ + +]b4_header_if( +[b4_output_begin([b4_spec_header_file]) +b4_copyright([Skeleton interface for Bison GLR parsers in C++], + [2002-2015, 2018-2021])[ +// C++ GLR parser skeleton written by Akim Demaille. + +]b4_disclaimer[ +]b4_cpp_guard_open([b4_spec_mapped_header_file])[ +]b4_shared_declarations[ +]b4_cpp_guard_close([b4_spec_mapped_header_file])[ +]b4_output_end]) + +# Let glr.c (and b4_shared_declarations) believe that the user +# arguments include the parser itself. +m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_wrap])) +m4_include(b4_skeletonsdir/[glr.c]) +m4_popdef([b4_parse_param]) diff --git a/Engine/bin/bison-flex/data/skeletons/glr2.cc b/Engine/bin/bison-flex/data/skeletons/glr2.cc new file mode 100644 index 000000000..757d68d49 --- /dev/null +++ b/Engine/bin/bison-flex/data/skeletons/glr2.cc @@ -0,0 +1,3533 @@ +# C++ GLR skeleton for Bison + +# Copyright (C) 2002-2015, 2018-2021 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +m4_include(b4_skeletonsdir/[c++.m4]) + +# api.value.type=variant is valid. +m4_define([b4_value_type_setup_variant]) + +# b4_tname_if(TNAME-NEEDED, TNAME-NOT-NEEDED) +# ------------------------------------------- +m4_define([b4_tname_if], +[m4_case(b4_percent_define_get([[parse.error]]), + [verbose], [$1], + [b4_token_table_if([$1], + [$2])])]) + +b4_bison_locations_if([ + m4_define([b4_location_constructors]) + m4_include(b4_skeletonsdir/[location.cc])]) +b4_variant_if([m4_include(b4_skeletonsdir/[variant.hh])]) + +m4_define([b4_parser_class], + [b4_percent_define_get([[api.parser.class]])]) + +]m4_define([b4_define_symbol_kind], +[m4_format([#define %-15s %s], + b4_symbol($][1, kind_base), + b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol($1, kind_base)) +]) + + +# b4_integral_parser_table_define(TABLE-NAME, CONTENT, COMMENT) +# ------------------------------------------------------------- +# Define "yy" whose contents is CONTENT. Does not use "static", +# should be in unnamed namespace. +m4_define([b4_integral_parser_table_define], +[m4_ifvaln([$3], [ b4_comment([$3])])dnl + const b4_int_type_for([$2]) yy$1[[]] = + { + $2 + };dnl +]) + + +## ---------------- ## +## Default values. ## +## ---------------- ## + +# Stack parameters. +m4_define_default([b4_stack_depth_max], [10000]) +m4_define_default([b4_stack_depth_init], [200]) + + + +## ------------ ## +## Interfaces. ## +## ------------ ## + +# b4_user_formals +# --------------- +# The possible parse-params formal arguments preceded by a comma. +# +# This is not shared with yacc.c in c.m4 because GLR relies on ISO C +# formal argument declarations. +m4_define([b4_user_formals], +[m4_ifset([b4_parse_param], [, b4_formals(b4_parse_param)])]) + + +# b4_symbol_kind(NUM) +# ------------------- +m4_define([b4_symbol_kind], +[symbol_kind::b4_symbol_kind_base($@)]) + + +## ----------------- ## +## Semantic Values. ## +## ----------------- ## + + +# b4_lhs_value(SYMBOL-NUM, [TYPE]) +# -------------------------------- +# See README. +m4_define([b4_lhs_value], +[b4_symbol_value([(*yyvalp)], [$1], [$2])]) + + +# b4_rhs_data(RULE-LENGTH, POS) +# ----------------------------- +# See README. +m4_define([b4_rhs_data], +[(static_cast(yyvsp))@{YYFILL (b4_subtract([$2], [$1]))@}.getState()]) + + +# b4_rhs_value(RULE-LENGTH, POS, SYMBOL-NUM, [TYPE]) +# -------------------------------------------------- +# Expansion of $$ or $$, for symbol SYMBOL-NUM. +m4_define([b4_rhs_value], +[b4_symbol_value([b4_rhs_data([$1], [$2]).value ()], [$3], [$4])]) + + + +## ----------- ## +## Locations. ## +## ----------- ## + +# b4_lhs_location() +# ----------------- +# Expansion of @$. +m4_define([b4_lhs_location], +[(*yylocp)]) + + +# b4_rhs_location(RULE-LENGTH, NUM) +# --------------------------------- +# Expansion of @NUM, where the current rule has RULE-LENGTH symbols +# on RHS. +m4_define([b4_rhs_location], +[(b4_rhs_data([$1], [$2]).yyloc)]) + + +# b4_symbol_action(SYMBOL-NUM, KIND) +# ---------------------------------- +# Run the action KIND (destructor or printer) for SYMBOL-NUM. +# Same as in C, but using references instead of pointers. +# +# Currently we need two different b4_symbol_action: once for the +# self-contained symbols, and another time for yy_destroy_ and +# yy_symbol_value_print_, which don't use genuine symbols yet. +m4_define([b4_symbol_action], +[b4_symbol_if([$1], [has_$2], +[m4_pushdef([b4_symbol_value], m4_defn([b4_symbol_value_template]))[]dnl +b4_dollar_pushdef([yysym.value], + [$1], + [], + [yysym.location])dnl + _b4_symbol_case([$1])[]dnl +b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl + b4_symbol([$1], [$2]) +b4_syncline([@oline@], [@ofile@])dnl + break; + +m4_popdef([b4_symbol_value])[]dnl +b4_dollar_popdef[]dnl +])]) + + +# b4_symbol_action_for_yyval(SYMBOL-NUM, KIND) +# -------------------------------------------- +# Run the action KIND (destructor or printer) for SYMBOL-NUM. +# Same as in C, but using references instead of pointers. +m4_define([b4_symbol_action_for_yyval], +[b4_symbol_if([$1], [has_$2], +[b4_dollar_pushdef([yyval], + [$1], + [], + [yyloc])dnl + _b4_symbol_case([$1])[]dnl +b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl + b4_symbol([$1], [$2]) +b4_syncline([@oline@], [@ofile@])dnl + break; + +b4_dollar_popdef[]dnl +])]) + + +# b4_call_merger(MERGER-NUM, MERGER-NAME, SYMBOL-SUM) +# --------------------------------------------------- +m4_define([b4_call_merger], +[b4_case([$1], + [ b4_symbol_if([$3], [has_type], + [b4_variant_if([yy0.as< b4_symbol($3, type) > () = $2 (yy0.as< b4_symbol($3, type) >(), yy1.as< b4_symbol($3, type) >());], + [yy0.b4_symbol($3, slot) = $2 (yy0, yy1);])], + [yy0 = $2 (yy0, yy1);])])]) + +# b4_yylex +# -------- +# Call yylex. +m4_define([b4_yylex], +[b4_token_ctor_if( +[b4_function_call([yylex], + [symbol_type], m4_ifdef([b4_lex_param], b4_lex_param))], +[b4_function_call([yylex], [int], + [[value_type *], [&this->yyla.value]][]dnl +b4_locations_if([, [[location_type *], [&this->yyla.location]]])dnl +m4_ifdef([b4_lex_param], [, ]b4_lex_param))])]) + + +# b4_shared_declarations(hh|cc) +# ----------------------------- +# Declaration that might either go into the header (if --header, $1 = hh) +# or in the implementation file. +m4_define([b4_shared_declarations], +[b4_percent_code_get([[requires]])[ +#include +#include // ptrdiff_t +#include // memcpy +#include +#include +#include +#include +#include +#include +#include + +]b4_cxx_portability[ +]m4_ifdef([b4_location_include], + [[# include ]b4_location_include])[ +]b4_variant_if([b4_variant_includes])[ + +]b4_YYDEBUG_define[ + +]b4_namespace_open[ + +]b4_bison_locations_if([m4_ifndef([b4_location_file], + [b4_location_define])])[ + + /// A Bison parser. + class ]b4_parser_class[ + { + public: +]b4_public_types_declare[ +]b4_symbol_type_define[ + + // FIXME: should be private eventually. + class glr_stack; + class glr_state; + + /// Build a parser object. + ]b4_parser_class[ (]b4_parse_param_decl[); + ~]b4_parser_class[ (); + + /// Parse. An alias for parse (). + /// \returns 0 iff parsing succeeded. + int operator() (); + + /// Parse. + /// \returns 0 iff parsing succeeded. + int parse (); + +#if ]b4_api_PREFIX[DEBUG + /// The current debugging stream. + std::ostream& debug_stream () const; + /// Set the current debugging stream. + void set_debug_stream (std::ostream &); + + /// Type for debugging levels. + using debug_level_type = int; + /// The current debugging level. + debug_level_type debug_level () const; + /// Set the current debugging level. + void set_debug_level (debug_level_type l); +#endif + + /// Report a syntax error.]b4_locations_if([[ + /// \param loc where the syntax error is found.]])[ + /// \param msg a description of the syntax error. + void error (]b4_locations_if([[const location_type& loc, ]])[const std::string& msg); + +]b4_parse_error_bmatch( +[custom\|detailed], +[[ /// The user-facing name of the symbol whose (internal) number is + /// YYSYMBOL. No bounds checking. + static const char *symbol_name (symbol_kind_type yysymbol);]], +[simple], +[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ + /// The user-facing name of the symbol whose (internal) number is + /// YYSYMBOL. No bounds checking. + static const char *symbol_name (symbol_kind_type yysymbol); +#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ +]], +[verbose], +[[ /// The user-facing name of the symbol whose (internal) number is + /// YYSYMBOL. No bounds checking. + static std::string symbol_name (symbol_kind_type yysymbol);]])[ + +]b4_token_constructor_define[ +]b4_parse_error_bmatch([custom\|detailed\|verbose], [[ + class context + { + public: + context (glr_stack& yystack, const symbol_type& yyla); + const symbol_type& lookahead () const YY_NOEXCEPT { return yyla_; } + symbol_kind_type token () const YY_NOEXCEPT { return yyla_.kind (); }]b4_locations_if([[ + const location_type& location () const YY_NOEXCEPT { return yyla_.location; } +]])[ + /// Put in YYARG at most YYARGN of the expected tokens, and return the + /// number of tokens stored in YYARG. If YYARG is null, return the + /// number of expected tokens (guaranteed to be less than YYNTOKENS). + int expected_tokens (symbol_kind_type yyarg[], int yyargn) const; + + private: + glr_stack& yystack_; + const symbol_type& yyla_; + }; +]])[ +# if ]b4_api_PREFIX[DEBUG + public: + /// \brief Report a symbol value on the debug stream. + /// \param yykind The symbol kind. + /// \param yyval Its semantic value.]b4_locations_if([[ + /// \param yyloc Its location.]])[ + void yy_symbol_value_print_ (symbol_kind_type yykind, + const value_type& yyval]b4_locations_if([[, + const location_type& yyloc]])[) const; + /// \brief Report a symbol on the debug stream. + /// \param yykind The symbol kind. + /// \param yyval Its semantic value.]b4_locations_if([[ + /// \param yyloc Its location.]])[ + void yy_symbol_print_ (symbol_kind_type yykind, + const value_type& yyval]b4_locations_if([[, + const location_type& yyloc]])[) const; + private: + /// Debug stream. + std::ostream* yycdebug_; +#endif + +]b4_parse_error_bmatch( +[custom], [[ + private: + /// Report a syntax error + /// \param yyctx the context in which the error occurred. + void report_syntax_error (const context& yyctx) const;]], +[detailed\|verbose], [[ + private: + /// The arguments of the error message. + int yy_syntax_error_arguments_ (const context& yyctx, + symbol_kind_type yyarg[], int yyargn) const; + + /// Generate an error message. + /// \param yyctx the context in which the error occurred. + virtual std::string yysyntax_error_ (const context& yyctx) const;]])[ + + /// Convert a scanner token kind \a t to a symbol kind. + /// In theory \a t should be a token_kind_type, but character literals + /// are valid, yet not members of the token_kind_type enum. + static symbol_kind_type yytranslate_ (int t) YY_NOEXCEPT; + +]b4_parse_error_bmatch( +[simple], +[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ + /// For a symbol, its name in clear. + static const char* const yytname_[]; +#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ +]], +[verbose], +[[ /// Convert the symbol name \a n to a form suitable for a diagnostic. + static std::string yytnamerr_ (const char *yystr); + + /// For a symbol, its name in clear. + static const char* const yytname_[]; +]])[ + + /// \brief Reclaim the memory associated to a symbol. + /// \param yymsg Why this token is reclaimed. + /// If null, print nothing. + /// \param yykind The symbol kind. + void yy_destroy_ (const char* yymsg, symbol_kind_type yykind, + value_type& yyval]b4_locations_if([[, + location_type& yyloc]])[); + +]b4_parse_param_vars[ + // Needs access to yy_destroy_, report_syntax_error, etc. + friend glr_stack; + }; + +]b4_token_ctor_if([b4_yytranslate_define([$1])[ +]b4_public_types_define([$1])])[ +]b4_namespace_close[ + +]b4_percent_code_get([[provides]])[ +]])[ + + +## -------------- ## +## Output files. ## +## -------------- ## + + +# ------------- # +# Header file. # +# ------------- # + +]b4_header_if([[ +]b4_output_begin([b4_spec_header_file])[ +]b4_copyright([Skeleton interface for Bison GLR parsers in C++], + [2002-2015, 2018-2021])[ +// C++ GLR parser skeleton written by Valentin Tolmer. + +]b4_disclaimer[ +]b4_cpp_guard_open([b4_spec_mapped_header_file])[ +]b4_shared_declarations([hh])[ +]b4_cpp_guard_close([b4_spec_mapped_header_file])[ +]b4_output_end])[ + + +# --------------------- # +# Implementation file. # +# --------------------- # + +]b4_output_begin([b4_parser_file_name])[ +]b4_copyright([Skeleton implementation for Bison GLR parsers in C], + [2002-2015, 2018-2021])[ +// C++ GLR parser skeleton written by Valentin Tolmer. + +]b4_disclaimer[ +]b4_identification[ + +]b4_percent_code_get([[top]])[ +]m4_if(b4_prefix, [yy], [], +[[/* Substitute the variable and function names. */ +#define yyparse ]b4_prefix[parse +#define yylex ]b4_prefix[lex +#define yyerror ]b4_prefix[error +#define yydebug ]b4_prefix[debug]])[ + +]b4_user_pre_prologue[ + +]b4_null_define[ + +]b4_header_if([[#include "@basename(]b4_spec_header_file[@)"]], + [b4_shared_declarations([cc])])[ + +namespace +{ + /* Default (constant) value used for initialization for null + right-hand sides. Unlike the standard yacc.c template, here we set + the default value of $$ to a zeroed-out value. Since the default + value is undefined, this behavior is technically correct. */ + ]b4_namespace_ref[::]b4_parser_class[::value_type yyval_default; +} + +]b4_user_post_prologue[ +]b4_percent_code_get[ + +#include +#include + +#ifndef YY_ +# if defined YYENABLE_NLS && YYENABLE_NLS +# if ENABLE_NLS +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_(Msgid) dgettext ("bison-runtime", Msgid) +# endif +# endif +# ifndef YY_ +# define YY_(Msgid) Msgid +# endif +#endif + +// Whether we are compiled with exception support. +#ifndef YY_EXCEPTIONS +# if defined __GNUC__ && !defined __EXCEPTIONS +# define YY_EXCEPTIONS 0 +# else +# define YY_EXCEPTIONS 1 +# endif +#endif + +#ifndef YYFREE +# define YYFREE free +#endif +#ifndef YYMALLOC +# define YYMALLOC malloc +#endif + +#ifndef YYSETJMP +# include +# define YYJMP_BUF jmp_buf +# define YYSETJMP(Env) setjmp (Env) +/* Pacify Clang and ICC. */ +# define YYLONGJMP(Env, Val) \ + do { \ + longjmp (Env, Val); \ + YYASSERT (0); \ + } while (false) +#endif + +]b4_attribute_define([noreturn])[ + +#if defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__ +# define YY_IGNORE_NULL_DEREFERENCE_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wnull-dereference\"") +# define YY_IGNORE_NULL_DEREFERENCE_END \ + _Pragma ("GCC diagnostic pop") +#else +# define YY_IGNORE_NULL_DEREFERENCE_BEGIN +# define YY_IGNORE_NULL_DEREFERENCE_END +#endif + +]b4_null_define[ +]b4_cast_define[ + +// FIXME: Use the same conventions as lalr1.cc. +]b4_parse_assert_if[ +#ifndef YYASSERT +# define YYASSERT(Condition) ((void) ((Condition) || (abort (), 0))) +#endif + +#ifdef YYDEBUG +# define YYDASSERT(Condition) YYASSERT(Condition) +#else +# define YYDASSERT(Condition) +#endif + +/* YYFINAL -- State number of the termination state. */ +#define YYFINAL ]b4_final_state_number[ +/* YYLAST -- Last index in YYTABLE. */ +#define YYLAST ]b4_last[ + +/* YYNTOKENS -- Number of terminals. */ +#define YYNTOKENS ]b4_tokens_number[ +/* YYNNTS -- Number of nonterminals. */ +#define YYNNTS ]b4_nterms_number[ +/* YYNRULES -- Number of rules. */ +#define YYNRULES ]b4_rules_number[ +/* YYNSTATES -- Number of states. */ +#define YYNSTATES ]b4_states_number[ +/* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */ +#define YYMAXRHS ]b4_r2_max[ +/* YYMAXLEFT -- Maximum number of symbols to the left of a handle + accessed by $0, $-1, etc., in any rule. */ +#define YYMAXLEFT ]b4_max_left_semantic_context[ + +namespace +{ +#if ]b4_api_PREFIX[DEBUG + /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ + const ]b4_int_type_for([b4_rline])[ yyrline[] = + { + ]b4_rline[ + }; +#endif + +#define YYPACT_NINF ]b4_pact_ninf[ +#define YYTABLE_NINF ]b4_table_ninf[ + +]b4_parser_tables_define[ + + /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */ + const ]b4_int_type_for([b4_dprec])[ yydprec[] = + { + ]b4_dprec[ + }; + + /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */ + const ]b4_int_type_for([b4_merger])[ yymerger[] = + { + ]b4_merger[ + }; + + /* YYIMMEDIATE[RULE-NUM] -- True iff rule #RULE-NUM is not to be deferred, as + in the case of predicates. */ + const bool yyimmediate[] = + { + ]b4_immediate[ + }; + + /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of + list of conflicting reductions corresponding to action entry for + state STATE-NUM in yytable. 0 means no conflicts. The list in + yyconfl is terminated by a rule number of 0. */ + const ]b4_int_type_for([b4_conflict_list_heads])[ yyconflp[] = + { + ]b4_conflict_list_heads[ + }; + + /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by + 0, pointed into by YYCONFLP. */ + ]dnl Do not use b4_int_type_for here, since there are places where + dnl pointers onto yyconfl are taken, whose type is "short*". + dnl We probably ought to introduce a type for confl. + [const short yyconfl[] = + { + ]b4_conflicting_rules[ + }; +} // namespace + + +/* Error token number */ +#define YYTERROR 1 + +]b4_locations_if([[ +]b4_yylloc_default_define[ +# define YYRHSLOC(Rhs, K) ((Rhs)[K].getState().yyloc) +]])[ + +enum YYRESULTTAG { yyok, yyaccept, yyabort, yyerr }; + +#define YYCHK(YYE) \ + do { \ + YYRESULTTAG yychk_flag = YYE; \ + if (yychk_flag != yyok) \ + return yychk_flag; \ + } while (false) + +#if ]b4_api_PREFIX[DEBUG + +#define YYCDEBUG if (!yydebug) {} else std::cerr + +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ + do { \ + if (yydebug) \ + { \ + std::cerr << Title << ' '; \ + yyparser.yy_symbol_print_ (Kind, Value]b4_locations_if([, Location])[); \ + std::cerr << '\n'; \ + } \ + } while (false) + +# define YY_REDUCE_PRINT(Args) \ + do { \ + if (yydebug) \ + yystateStack.yy_reduce_print Args; \ + } while (false) + +/* Nonzero means print parse trace. It is left uninitialized so that + multiple parsers can coexist. */ +int yydebug; + +namespace +{ + using glr_stack = ]b4_namespace_ref[::]b4_parser_class[::glr_stack; + using glr_state = ]b4_namespace_ref[::]b4_parser_class[::glr_state; + + void yypstack (const glr_stack& yystack, size_t yyk) + YY_ATTRIBUTE_UNUSED; + void yypdumpstack (const glr_stack& yystack) + YY_ATTRIBUTE_UNUSED; +} + +#else /* !]b4_api_PREFIX[DEBUG */ + +# define YYCDEBUG if (true) {} else std::cerr +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) {} +# define YY_REDUCE_PRINT(Args) {} + +#endif /* !]b4_api_PREFIX[DEBUG */ + +/* YYINITDEPTH -- initial size of the parser's stacks. */ +#ifndef YYINITDEPTH +# define YYINITDEPTH ]b4_stack_depth_init[ +#endif + +/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only + if the built-in stack extension method is used). + + Do not make this value too large; the results are undefined if + SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem) + evaluated with infinite-precision integer arithmetic. */ + +#ifndef YYMAXDEPTH +# define YYMAXDEPTH ]b4_stack_depth_max[ +#endif + +/* Minimum number of free items on the stack allowed after an + allocation. This is to allow allocation and initialization + to be completed by functions that call yyexpandGLRStack before the + stack is expanded, thus insuring that all necessary pointers get + properly redirected to new data. */ +#define YYHEADROOM 2 + +#ifndef YYSTACKEXPANDABLE +# define YYSTACKEXPANDABLE 1 +#endif + +namespace +{ + template + class strong_index_alias + { + public: + static strong_index_alias create (std::ptrdiff_t value) + { + strong_index_alias result; + result.value_ = value; + return result; + } + + std::ptrdiff_t const& get () const { return value_; } + + size_t uget () const { return static_cast (value_); } + + strong_index_alias operator+ (std::ptrdiff_t other) const + { + return strong_index_alias (get () + other); + } + + void operator+= (std::ptrdiff_t other) + { + value_ += other; + } + + strong_index_alias operator- (std::ptrdiff_t other) + { + return strong_index_alias (get () - other); + } + + void operator-= (std::ptrdiff_t other) + { + value_ -= other; + } + + size_t operator- (strong_index_alias other) + { + return strong_index_alias (get () - other.get ()); + } + + strong_index_alias& operator++ () + { + ++value_; + return *this; + } + + bool isValid () const + { + return value_ != INVALID_INDEX; + } + + void setInvalid() + { + value_ = INVALID_INDEX; + } + + bool operator== (strong_index_alias other) + { + return get () == other.get (); + } + + bool operator!= (strong_index_alias other) + { + return get () != other.get (); + } + + bool operator< (strong_index_alias other) + { + return get () < other.get (); + } + + private: + static const std::ptrdiff_t INVALID_INDEX; + + // WARNING: 0-initialized. + std::ptrdiff_t value_; + }; // class strong_index_alias + + template + const std::ptrdiff_t strong_index_alias::INVALID_INDEX = + std::numeric_limits::max (); + + using state_set_index = strong_index_alias; + + state_set_index create_state_set_index (std::ptrdiff_t value) + { + return state_set_index::create (value); + } + + /** State numbers, as in LALR(1) machine */ + using state_num = int; + + /** Rule numbers, as in LALR(1) machine */ + using rule_num = int; + + using parser_type = ]b4_namespace_ref[::]b4_parser_class[; + using glr_state = parser_type::glr_state; + using symbol_kind = parser_type::symbol_kind; + using symbol_kind_type = parser_type::symbol_kind_type; + using symbol_type = parser_type::symbol_type; + using value_type = parser_type::value_type;]b4_locations_if([[ + using location_type = parser_type::location_type;]])[ + + // Forward declarations. + class glr_stack_item; + class semantic_option; +} // namespace + +namespace +{ + /** Accessing symbol of state YYSTATE. */ + inline symbol_kind_type + yy_accessing_symbol (state_num yystate) + { + return YY_CAST (symbol_kind_type, yystos[yystate]); + } + + /** Left-hand-side symbol for rule #YYRULE. */ + inline symbol_kind_type + yylhsNonterm (rule_num yyrule) + { + return static_cast(yyr1[yyrule]); + } + + /** Number of symbols composing the right hand side of rule #RULE. */ + inline int + yyrhsLength (rule_num yyrule) + { + return yyr2[yyrule]; + } +} + +namespace ]b4_namespace_ref[ +{ + class ]b4_parser_class[::glr_state + { + public: + glr_state () + : yyresolved (false) + , yylrState (0) + , yyposn (0) + , yypred (0) + , yyfirstVal (0)]b4_locations_if([[ + , yyloc ()]])[]b4_parse_assert_if([[ + , magic_ (MAGIC)]])[ + {} + + /// Build with a semantic value. + glr_state (state_num lrState, size_t posn, const value_type& val]b4_locations_if([[, const location_type& loc]])[) + : yyresolved (true) + , yylrState (lrState) + , yyposn (posn) + , yypred (0) + , yyval (]b4_variant_if([], [[val]])[)]b4_locations_if([[ + , yyloc (loc)]])[]b4_parse_assert_if([[ + , magic_ (MAGIC)]])[ + {]b4_variant_if([[ + ]b4_symbol_variant([yy_accessing_symbol (lrState)], + [yyval], [copy], [val])])[} + + /// Build with a semantic option. + glr_state (state_num lrState, size_t posn) + : yyresolved (false) + , yylrState (lrState) + , yyposn (posn) + , yypred (0) + , yyfirstVal (0)]b4_locations_if([[ + , yyloc ()]])[]b4_parse_assert_if([[ + , magic_ (MAGIC)]])[ + {} + + glr_state (const glr_state& other) + : yyresolved (other.yyresolved) + , yylrState (other.yylrState) + , yyposn (other.yyposn) + , yypred (0)]b4_locations_if([[ + , yyloc (other.yyloc)]])[]b4_parse_assert_if([[ + , magic_ (MAGIC)]])[ + { + setPred (other.pred ()); + if (other.yyresolved)]b4_variant_if([[ + { + new (&yyval) value_type (); + ]b4_symbol_variant([yy_accessing_symbol (other.yylrState)], + [yyval], [copy], [other.value ()])[ + }]], [[ + new (&yyval) value_type (other.value ());]])[ + else + { + yyfirstVal = 0; + setFirstVal (other.firstVal ()); + }]b4_parse_assert_if([[ + check_();]])[ + } + + ~glr_state () + {]b4_parse_assert_if([[ + check_ ();]])[ + if (yyresolved) + {]b4_variant_if([[ + symbol_kind_type yykind = yy_accessing_symbol (yylrState); + // FIXME: User destructors. + // Value type destructor. + ]b4_symbol_variant([[yykind]], [[yyval]], [[template destroy]])])[ + yyval.~value_type (); + }]b4_parse_assert_if([[ + magic_ = 0;]])[ + } + + glr_state& operator= (const glr_state& other) + {]b4_parse_assert_if([[ + check_ (); + other.check_ ();]])[ + if (!yyresolved && other.yyresolved) + new (&yyval) value_type; + yyresolved = other.yyresolved; + yylrState = other.yylrState; + yyposn = other.yyposn; + setPred (other.pred ()); + if (other.yyresolved)]b4_variant_if([[ + ]b4_symbol_variant([yy_accessing_symbol (other.yylrState)], + [yyval], [copy], [other.value ()])], [[ + value () = other.value ();]])[ + else + setFirstVal (other.firstVal ());]b4_locations_if([[ + yyloc = other.yyloc;]])[ + return *this; + } + + /** Type tag for the semantic value. If true, yyval applies, otherwise + * yyfirstVal applies. */ + bool yyresolved; + /** Number of corresponding LALR(1) machine state. */ + state_num yylrState; + /** Source position of the last token produced by my symbol */ + size_t yyposn; + + /// Only call pred() and setPred() on objects in yyitems, not temporaries. + glr_state* pred (); + const glr_state* pred () const; + void setPred (const glr_state* state); + + /// Only call firstVal() and setFirstVal() on objects in yyitems, not + /// temporaries. + semantic_option* firstVal (); + const semantic_option* firstVal () const; + void setFirstVal (const semantic_option* option); + + value_type& value () + {]b4_parse_assert_if([[ + check_ ();]])[ + return yyval; + } + + const value_type& value () const + {]b4_parse_assert_if([[ + check_ ();]])[ + return yyval; + } + + void + destroy (char const *yymsg, ]b4_namespace_ref[::]b4_parser_class[& yyparser); + + /* DEBUGGING ONLY */ + #if ]b4_api_PREFIX[DEBUG + void yy_yypstack () const + {]b4_parse_assert_if([[ + check_ ();]])[ + if (pred () != YY_NULLPTR) + { + pred ()->yy_yypstack (); + std::cerr << " -> "; + } + std::cerr << yylrState << "@@" << yyposn; + } + #endif + + std::ptrdiff_t indexIn (const glr_stack_item* array) const YY_ATTRIBUTE_UNUSED; + + glr_stack_item* asItem () + {]b4_parse_assert_if([[ + check_ ();]])[ + return asItem(this); + } + + const glr_stack_item* asItem () const + {]b4_parse_assert_if([[ + check_ ();]])[ + return asItem (this); + } + + private: + template + static const glr_stack_item* asItem (const T* state) + { + return reinterpret_cast(state); + } + template + static glr_stack_item* asItem (T* state) + { + return reinterpret_cast (state); + } + static const char *as_pointer_ (const glr_state *state) + { + return reinterpret_cast (state); + } + static char *as_pointer_ (glr_state *state) + { + return reinterpret_cast (state); + } + /** Preceding state in this stack */ + std::ptrdiff_t yypred; + union { + /** First in a chain of alternative reductions producing the + * nonterminal corresponding to this state, threaded through + * yyfirstVal. Value "0" means empty. */ + std::ptrdiff_t yyfirstVal; + /** Semantic value for this state. */ + value_type yyval; + };]b4_locations_if([[ + // FIXME: Why public? + public: + /** Source location for this state. */ + location_type yyloc;]])[ + +]b4_parse_assert_if([[ + public: + // Check invariants. + void check_ () const + { + YY_IGNORE_NULL_DEREFERENCE_BEGIN + YYASSERT (this->magic_ == MAGIC); + YY_IGNORE_NULL_DEREFERENCE_END + } + + // A magic number to check our pointer arithmetic is sane. + enum { MAGIC = 713705 }; + unsigned int magic_;]])[ + }; // class ]b4_parser_class[::glr_state +} // namespace ]b4_namespace_ref[ + + +namespace +{ + /** A stack of GLRState representing the different heads during + * nondeterministic evaluation. */ + class glr_state_set + { + public: + /** Initialize YYSET to a singleton set containing an empty stack. */ + glr_state_set () + : yylastDeleted (YY_NULLPTR) + { + yystates.push_back (YY_NULLPTR); + yylookaheadNeeds.push_back (false); + } + + // Behave like a vector of states. + glr_state*& operator[] (state_set_index index) + { + return yystates[index.uget()]; + } + + glr_state* operator[] (state_set_index index) const + { + return yystates[index.uget()]; + } + + size_t size () const + { + return yystates.size (); + } + + std::vector::iterator begin () + { + return yystates.begin (); + } + + std::vector::iterator end () + { + return yystates.end (); + } + + bool lookaheadNeeds (state_set_index index) const + { + return yylookaheadNeeds[index.uget ()]; + } + + bool setLookaheadNeeds (state_set_index index, bool value) + { + return yylookaheadNeeds[index.uget ()] = value; + } + + /** Invalidate stack #YYK. */ + void + yymarkStackDeleted (state_set_index yyk) + { + size_t k = yyk.uget (); + if (yystates[k] != YY_NULLPTR) + yylastDeleted = yystates[k]; + yystates[k] = YY_NULLPTR; + } + + /** Undelete the last stack in *this that was marked as deleted. Can + only be done once after a deletion, and only when all other stacks have + been deleted. */ + void + yyundeleteLastStack () + { + if (yylastDeleted == YY_NULLPTR || !yystates.empty ()) + return; + yystates.push_back (yylastDeleted); + YYCDEBUG << "Restoring last deleted stack as stack #0.\n"; + clearLastDeleted (); + } + + /** Remove the dead stacks (yystates[i] == YY_NULLPTR) and shift the later + * ones. */ + void + yyremoveDeletes () + { + size_t newsize = yystates.size (); + /* j is the number of live stacks we have seen. */ + for (size_t i = 0, j = 0; j < newsize; ++i) + { + if (yystates[i] == YY_NULLPTR) + { + if (i == j) + { + YYCDEBUG << "Removing dead stacks.\n"; + } + newsize -= 1; + } + else + { + yystates[j] = yystates[i]; + /* In the current implementation, it's unnecessary to copy + yylookaheadNeeds[i] since, after + yyremoveDeletes returns, the parser immediately either enters + deterministic operation or shifts a token. However, it doesn't + hurt, and the code might evolve to need it. */ + yylookaheadNeeds[j] = yylookaheadNeeds[i]; + if (j != i) + { + YYCDEBUG << "Rename stack " << i << " -> " << j << ".\n"; + } + j += 1; + } + } + yystates.resize (newsize); + yylookaheadNeeds.resize (newsize); + } + + + state_set_index + yysplitStack (state_set_index yyk) + { + const size_t k = yyk.uget (); + yystates.push_back (yystates[k]); + yylookaheadNeeds.push_back (yylookaheadNeeds[k]); + return create_state_set_index (static_cast (yystates.size () - 1)); + } + + void clearLastDeleted () + { + yylastDeleted = YY_NULLPTR; + } + + private: + + std::vector yystates; + /** During nondeterministic operation, yylookaheadNeeds tracks which + * stacks have actually needed the current lookahead. During deterministic + * operation, yylookaheadNeeds[0] is not maintained since it would merely + * duplicate !yyla.empty (). */ + std::vector yylookaheadNeeds; + + /** The last stack we invalidated. */ + glr_state* yylastDeleted; + }; // class glr_state_set +} // namespace + +namespace +{ + class semantic_option + { + public: + semantic_option () + : yyrule (0) + , yystate (0) + , yynext (0) + , yyla ()]b4_parse_assert_if([[ + , magic_ (MAGIC)]])[ + {} + + semantic_option (rule_num rule) + : yyrule (rule) + , yystate (0) + , yynext (0) + , yyla ()]b4_parse_assert_if([[ + , magic_ (MAGIC)]])[ + {} + + semantic_option (const semantic_option& that) + : yyrule (that.yyrule) + , yystate (that.yystate) + , yynext (that.yynext) + , yyla (that.yyla)]b4_parse_assert_if([[ + , magic_ (MAGIC)]])[ + {]b4_parse_assert_if([[ + that.check_ ();]])[ + } + + // Needed for the assignment in yynewSemanticOption. + semantic_option& operator= (const semantic_option& that) + {]b4_parse_assert_if([[ + check_ (); + that.check_ ();]])[ + yyrule = that.yyrule; + yystate = that.yystate; + yynext = that.yynext; + yyla = that.yyla; + return *this; + } + + /// Only call state() and setState() on objects in yyitems, not temporaries. + glr_state* state(); + const glr_state* state() const; + void setState(const glr_state* s); + + const semantic_option* next () const YY_ATTRIBUTE_UNUSED; + semantic_option* next (); + void setNext (const semantic_option* s); + + std::ptrdiff_t indexIn (const glr_stack_item* array) const YY_ATTRIBUTE_UNUSED; + + /** True iff YYY0 and YYY1 represent identical options at the top level. + * That is, they represent the same rule applied to RHS symbols + * that produce the same terminal symbols. */ + bool + isIdenticalTo (const semantic_option& yyy1) const + {]b4_parse_assert_if([[ + check_ (); + yyy1.check_ ();]])[ + if (this->yyrule == yyy1.yyrule) + { + const glr_state *yys0, *yys1; + int yyn; + for (yys0 = this->state(), + yys1 = yyy1.state(), + yyn = yyrhsLength (this->yyrule); + yyn > 0; + yys0 = yys0->pred(), + yys1 = yys1->pred(), yyn -= 1) + if (yys0->yyposn != yys1->yyposn) + return false; + return true; + } + else + return false; + } + + /** Assuming identicalOptions (YYY0,YYY1), destructively merge the + * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */ + void + mergeWith (semantic_option& yyy1) + {]b4_parse_assert_if([[ + check_ (); + yyy1.check_ ();]])[ + glr_state *yys0 = this->state (); + glr_state *yys1 = yyy1.state (); + for (int yyn = yyrhsLength (this->yyrule); + yyn > 0; + yyn -= 1, yys0 = yys0->pred (), yys1 = yys1->pred ()) + { + if (yys0 == yys1) + break; + else if (yys0->yyresolved) + { + yys1->yyresolved = true;]b4_variant_if([[ + YYASSERT (yys1->yylrState == yys0->yylrState); + ]b4_symbol_variant([yy_accessing_symbol (yys0->yylrState)], + [yys1->value ()], [copy], [yys0->value ()])], [[ + yys1->value () = yys0->value ();]])[ + } + else if (yys1->yyresolved) + { + yys0->yyresolved = true;]b4_variant_if([[ + YYASSERT (yys0->yylrState == yys1->yylrState); + ]b4_symbol_variant([yy_accessing_symbol (yys1->yylrState)], + [yys0->value ()], [copy], [yys1->value ()])], [[ + yys0->value () = yys1->value ();]])[ + } + else + { + semantic_option* yyz0prev = YY_NULLPTR; + semantic_option* yyz0 = yys0->firstVal(); + semantic_option* yyz1 = yys1->firstVal(); + while (true) + { + if (yyz1 == yyz0 || yyz1 == YY_NULLPTR) + break; + else if (yyz0 == YY_NULLPTR) + { + if (yyz0prev != YY_NULLPTR) + yyz0prev->setNext (yyz1); + else + yys0->setFirstVal (yyz1); + break; + } + else if (yyz0 < yyz1) + { + semantic_option* yyz = yyz0; + if (yyz0prev != YY_NULLPTR) + yyz0prev->setNext(yyz1); + else + yys0->setFirstVal(yyz1); + yyz1 = yyz1->next(); + yyz0->setNext(yyz); + } + yyz0prev = yyz0; + yyz0 = yyz0->next(); + } + yys1->setFirstVal(yys0->firstVal()); + } + } + } + +#if ]b4_api_PREFIX[DEBUG + void yyreportTree (size_t yyindent = 2) const + {]b4_parse_assert_if([[ + check_ ();]])[ + int yynrhs = yyrhsLength (this->yyrule); + const glr_state* yystates[1 + YYMAXRHS]; + glr_state yyleftmost_state; + + { + const glr_state* yys = this->state(); + for (int yyi = yynrhs; 0 < yyi; yyi -= 1) + { + yystates[yyi] = yys; + yys = yys->pred(); + } + if (yys == YY_NULLPTR) + { + yyleftmost_state.yyposn = 0; + yystates[0] = &yyleftmost_state; + } + else + yystates[0] = yys; + } + + std::string yylhs = ]b4_namespace_ref[::]b4_parser_class[::symbol_name (yylhsNonterm (this->yyrule)); + YYASSERT(this->state()); + if (this->state()->yyposn < yystates[0]->yyposn + 1) + std::cerr << std::string(yyindent, ' ') << yylhs << " -> yyrule - 1 << ", empty>\n"; + else + std::cerr << std::string(yyindent, ' ') << yylhs << " -> yyrule - 1 << ", tokens " + << yystates[0]->yyposn + 1 << " .. " + << this->state()->yyposn << ">\n"; + for (int yyi = 1; yyi <= yynrhs; yyi += 1) + { + if (yystates[yyi]->yyresolved) + { + std::string yysym = ]b4_namespace_ref[::]b4_parser_class[::symbol_name (yy_accessing_symbol (yystates[yyi]->yylrState)); + if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn) + std::cerr << std::string(yyindent + 2, ' ') << yysym + << " \n"; + else + std::cerr << std::string(yyindent + 2, ' ') << yysym + << " yyposn + 1 + << " .. " << yystates[yyi]->yyposn << ">\n"; + } + else + yystates[yyi]->firstVal ()->yyreportTree (yyindent+2); + } + } +#endif + + /** Rule number for this reduction */ + rule_num yyrule; + + private: + template + static const glr_stack_item* asItem(const T* state) + { + return reinterpret_cast(state); + } + template + static glr_stack_item* asItem(T* state) + { + return reinterpret_cast(state); + } + /** The last RHS state in the list of states to be reduced. */ + std::ptrdiff_t yystate; + /** Next sibling in chain of options. To facilitate merging, + * options are chained in decreasing order by address. */ + std::ptrdiff_t yynext; + + public: + /** The lookahead for this reduction. */ + symbol_type yyla; + +]b4_parse_assert_if([[ + public: + // Check invariants. + void check_ () const + { + YY_IGNORE_NULL_DEREFERENCE_BEGIN + YYASSERT (this->magic_ == MAGIC); + YY_IGNORE_NULL_DEREFERENCE_END + } + + // A magic number to check our pointer arithmetic is sane. + enum { MAGIC = 0xeff1cace }; + unsigned int magic_;]])[ + }; // class semantic_option +} // namespace + +namespace +{ + /** Type of the items in the GLR stack. + * It can be either a glr_state or a semantic_option. The is_state_ field + * indicates which item of the union is valid. */ + class glr_stack_item + { + public: + glr_stack_item (bool state = true) + : is_state_ (state)]b4_parse_assert_if([[ + , magic_ (MAGIC)]])[ + { + if (is_state_) + new (&raw_) glr_state; + else + new (&raw_) semantic_option; + } + + glr_stack_item (const glr_stack_item& other) YY_NOEXCEPT YY_NOTHROW + : is_state_ (other.is_state_)]b4_parse_assert_if([[ + , magic_ (MAGIC)]])[ + {]b4_parse_assert_if([[ + other.check_ ();]])[ + std::memcpy (raw_, other.raw_, union_size); + } + + glr_stack_item& operator= (glr_stack_item other) + {]b4_parse_assert_if([[ + check_ (); + other.check_ ();]])[ + std::swap (is_state_, other.is_state_); + std::swap (raw_, other.raw_); + return *this; + } + + ~glr_stack_item () + {]b4_parse_assert_if([[ + check_ ();]])[ + if (is_state ()) + getState ().~glr_state (); + else + getOption ().~semantic_option (); + } + + void setState (const glr_state &state) + {]b4_parse_assert_if([[ + check_ (); + state.check_ ();]])[ + if (this != state.asItem ()) + { + if (is_state_) + getState ().~glr_state (); + else + getOption ().~semantic_option (); + new (&raw_) glr_state (state); + is_state_ = true; + } + } + + glr_state& getState () + {]b4_parse_assert_if([[ + check_ ();]])[ + YYDASSERT (is_state ()); + void *yyp = raw_; + glr_state& res = *static_cast (yyp);]b4_parse_assert_if([[ + res.check_ ();]])[ + return res; + } + + const glr_state& getState () const + {]b4_parse_assert_if([[ + check_ ();]])[ + YYDASSERT (is_state ()); + const void *yyp = raw_; + const glr_state& res = *static_cast (yyp);]b4_parse_assert_if([[ + res.check_ ();]])[ + return res; + } + + semantic_option& getOption () + {]b4_parse_assert_if([[ + check_ ();]])[ + YYDASSERT (!is_state ()); + void *yyp = raw_; + return *static_cast (yyp); + } + const semantic_option& getOption () const + {]b4_parse_assert_if([[ + check_ ();]])[ + YYDASSERT (!is_state ()); + const void *yyp = raw_; + return *static_cast (yyp); + } + bool is_state () const + {]b4_parse_assert_if([[ + check_ ();]])[ + return is_state_; + } + + private: + /// The possible contents of raw_. Since they have constructors, they cannot + /// be directly included in the union. + union contents + { + char yystate[sizeof (glr_state)]; + char yyoption[sizeof (semantic_option)]; + }; + enum { union_size = sizeof (contents) }; + union { + /// Strongest alignment constraints. + long double yyalign_me; + /// A buffer large enough to store the contents. + char raw_[union_size]; + }; + /** Type tag for the union. */ + bool is_state_; +]b4_parse_assert_if([[ + public: + // Check invariants. + void check_ () const + { + YYASSERT (this->magic_ == MAGIC); + YYASSERT (this->is_state_ == false || this->is_state_ == true); + } + // A magic number to check our pointer arithmetic is sane. + enum { MAGIC = 0xDEAD1ACC }; // 3735886540. + const unsigned int magic_;]])[ + }; // class glr_stack_item +} // namespace + +glr_state* glr_state::pred () +{]b4_parse_assert_if([[ + check_ ();]])[ + YY_IGNORE_NULL_DEREFERENCE_BEGIN + return yypred ? &asItem (as_pointer_ (this) - yypred)->getState () : YY_NULLPTR; + YY_IGNORE_NULL_DEREFERENCE_END +} + +const glr_state* glr_state::pred () const +{]b4_parse_assert_if([[ + check_ ();]])[ + YY_IGNORE_NULL_DEREFERENCE_BEGIN + return yypred ? &asItem (as_pointer_ (this) - yypred)->getState () : YY_NULLPTR; + YY_IGNORE_NULL_DEREFERENCE_END +} + +void glr_state::setPred (const glr_state* state) +{]b4_parse_assert_if([[ + check_ (); + if (state) + state->check_ ();]])[ + yypred = state ? as_pointer_ (this) - as_pointer_ (state) : 0; +} + +semantic_option* glr_state::firstVal () +{]b4_parse_assert_if([[ + check_ ();]])[ + return yyfirstVal ? &(asItem(this) - yyfirstVal)->getOption() : YY_NULLPTR; +} + +const semantic_option* glr_state::firstVal () const +{]b4_parse_assert_if([[ + check_ ();]])[ + return yyfirstVal ? &(asItem(this) - yyfirstVal)->getOption() : YY_NULLPTR; +} + +void glr_state::setFirstVal (const semantic_option* option) +{]b4_parse_assert_if([[ + check_ ();]])[ + yyfirstVal = option ? asItem(this) - asItem(option) : 0; +} + +std::ptrdiff_t glr_state::indexIn (const glr_stack_item* array) const +{]b4_parse_assert_if([[ + check_ ();]])[ + return asItem(this) - array; +} + +std::ptrdiff_t semantic_option::indexIn (const glr_stack_item* array) const +{ + return asItem(this) - array; +} + +glr_state* semantic_option::state () +{ + YY_IGNORE_NULL_DEREFERENCE_BEGIN + return yystate ? &(asItem(this) - yystate)->getState() : YY_NULLPTR; + YY_IGNORE_NULL_DEREFERENCE_END +} + +const glr_state* semantic_option::state () const +{ + return yystate ? &(asItem(this) - yystate)->getState() : YY_NULLPTR; +} + +void semantic_option::setState (const glr_state* s) +{ + yystate = s ? asItem(this) - asItem(s) : 0; +} + +const semantic_option* semantic_option::next () const +{ + return yynext ? &(asItem(this) - yynext)->getOption() : YY_NULLPTR; +} + +semantic_option* semantic_option::next () +{ + return yynext ? &(asItem(this) - yynext)->getOption() : YY_NULLPTR; +} + +void semantic_option::setNext (const semantic_option* s) +{ + yynext = s ? asItem(this) - asItem(s) : 0; +} + +void glr_state::destroy (char const* yymsg, ]b4_namespace_ref[::]b4_parser_class[& yyparser) +{]b4_parse_assert_if([[ + check_ ();]])[ + if (yyresolved) + yyparser.yy_destroy_ (yymsg, yy_accessing_symbol(yylrState), + value ()]b4_locations_if([, yyloc])[); + else + { +#if ]b4_api_PREFIX[DEBUG + YYCDEBUG << yymsg + << (firstVal() ? " unresolved " : " incomplete ") + << (yy_accessing_symbol (yylrState) < YYNTOKENS ? "token" : "nterm") + << ' ' << yyparser.symbol_name (yy_accessing_symbol (yylrState)) + << " ("]b4_locations_if([[ + << yyloc << ": "]])[ + << ")\n"; +#endif + if (firstVal() != YY_NULLPTR) + { + semantic_option& yyoption = *firstVal (); + glr_state *yyrh = yyoption.state (); + for (int yyn = yyrhsLength (yyoption.yyrule); yyn > 0; yyn -= 1) + { + yyrh->destroy (yymsg, yyparser); + yyrh = yyrh->pred(); + } + } + } +} + + +#undef YYFILL +#define YYFILL(N) yyfill (yyvsp, yylow, (N), yynormal) + +namespace +{ + class state_stack + { + public: + using parser_type = ]b4_namespace_ref[::]b4_parser_class[; + using symbol_kind = parser_type::symbol_kind; + using value_type = parser_type::value_type;]b4_locations_if([[ + using location_type = parser_type::location_type;]])[ + + /** Initialize to a single empty stack, with total maximum + * capacity for all stacks of YYSIZE. */ + state_stack (size_t yysize) + : yysplitPoint (YY_NULLPTR) + { + yyitems.reserve (yysize); + } + +#if YYSTACKEXPANDABLE + /** Returns false if it tried to expand but could not. */ + bool + yyexpandGLRStackIfNeeded () + { + return YYHEADROOM <= spaceLeft () || yyexpandGLRStack (); + } + + private: + /** If *this is expandable, extend it. WARNING: Pointers into the + stack from outside should be considered invalid after this call. + We always expand when there are 1 or fewer items left AFTER an + allocation, so that we can avoid having external pointers exist + across an allocation. */ + bool + yyexpandGLRStack () + { + const size_t oldsize = yyitems.size(); + if (YYMAXDEPTH - YYHEADROOM < oldsize) + return false; + const size_t yynewSize = YYMAXDEPTH < 2 * oldsize ? YYMAXDEPTH : 2 * oldsize; + const glr_stack_item *oldbase = &yyitems[0]; + + yyitems.reserve (yynewSize); + const glr_stack_item *newbase = &yyitems[0]; + + // Adjust the pointers. Perform raw pointer arithmetic, as there + // is no reason for objects to be aligned on their size. + const ptrdiff_t disp + = reinterpret_cast (newbase) - reinterpret_cast (oldbase); + if (yysplitPoint) + const_cast (yysplitPoint) + = reinterpret_cast (reinterpret_cast (const_cast (yysplitPoint)) + disp); + + for (std::vector::iterator + i = yytops.begin (), + yyend = yytops.end (); + i != yyend; ++i) + if (glr_state_not_null (*i)) + *i = reinterpret_cast(reinterpret_cast(*i) + disp); + + return true; + } + + public: +#else + bool yyexpandGLRStackIfNeeded () + { + return YYHEADROOM <= spaceLeft (); + } +#endif +#undef YYSTACKEXPANDABLE + + static bool glr_state_not_null (glr_state* s) + { + return s != YY_NULLPTR; + } + + bool + reduceToOneStack () + { + using iterator = std::vector::iterator; + const iterator yybegin = yytops.begin(); + const iterator yyend = yytops.end(); + const iterator yyit = std::find_if(yybegin, yyend, glr_state_not_null); + if (yyit == yyend) + return false; + for (state_set_index yyk = create_state_set_index(yyit + 1 - yybegin); + yyk.uget() != numTops(); ++yyk) + yytops.yymarkStackDeleted (yyk); + yytops.yyremoveDeletes (); + yycompressStack (); + return true; + } + + /** Called when returning to deterministic operation to clean up the extra + * stacks. */ + void + yycompressStack () + { + if (yytops.size() != 1 || !isSplit()) + return; + + // yyr is the state after the split point. + glr_state* yyr = YY_NULLPTR; + for (glr_state *yyp = firstTop(), *yyq = yyp->pred(); + yyp != yysplitPoint; + yyr = yyp, yyp = yyq, yyq = yyp->pred()) + yyp->setPred(yyr); + + // This const_cast is okay, since anyway we have access to the mutable + // yyitems into which yysplitPoint points. + glr_stack_item* nextFreeItem + = const_cast (yysplitPoint)->asItem () + 1; + yysplitPoint = YY_NULLPTR; + yytops.clearLastDeleted (); + + while (yyr != YY_NULLPTR) + { + nextFreeItem->setState (*yyr); + glr_state& nextFreeState = nextFreeItem->getState(); + yyr = yyr->pred(); + nextFreeState.setPred(&(nextFreeItem - 1)->getState()); + setFirstTop (&nextFreeState); + ++nextFreeItem; + } + yyitems.resize(static_cast(nextFreeItem - yyitems.data())); + } + + bool isSplit() const { + return yysplitPoint != YY_NULLPTR; + } + + // Present the interface of a vector of glr_stack_item. + std::vector::const_iterator begin () const + { + return yyitems.begin (); + } + + std::vector::const_iterator end () const + { + return yyitems.end (); + } + + size_t size() const + { + return yyitems.size (); + } + + glr_stack_item& operator[] (size_t i) + { + return yyitems[i]; + } + + glr_stack_item& stackItemAt (size_t index) + { + return yyitems[index]; + } + + size_t numTops () const + { + return yytops.size (); + } + + glr_state* firstTop () const + { + return yytops[create_state_set_index (0)]; + } + + glr_state* topAt (state_set_index i) const + { + return yytops[i]; + } + + void setFirstTop (glr_state* value) + { + yytops[create_state_set_index (0)] = value; + } + + void setTopAt (state_set_index i, glr_state* value) + { + yytops[i] = value; + } + + void pop_back () + { + yyitems.pop_back (); + } + + void pop_back (size_t n) + { + yyitems.resize (yyitems.size () - n); + } + + state_set_index + yysplitStack (state_set_index yyk) + { + if (!isSplit ()) + { + YYASSERT (yyk.get () == 0); + yysplitPoint = topAt (yyk); + } + return yytops.yysplitStack (yyk); + } + + /** Assuming that YYS is a GLRState somewhere on *this, update the + * splitpoint of *this, if needed, so that it is at least as deep as + * YYS. */ + void + yyupdateSplit (glr_state& yys) + { + if (isSplit() && &yys < yysplitPoint) + yysplitPoint = &yys; + } + + /** Return a fresh GLRState. + * Callers should call yyreserveStack afterwards to make sure there is + * sufficient headroom. */ + glr_state& yynewGLRState (const glr_state& newState) + { + glr_state& state = yyitems[yynewGLRStackItem (true)].getState (); +#if false && 201103L <= YY_CPLUSPLUS + state = std::move (newState); +#else + state = newState; +#endif + return state; + } + + /** Return a fresh SemanticOption. + * Callers should call yyreserveStack afterwards to make sure there is + * sufficient headroom. */ + semantic_option& yynewSemanticOption (semantic_option newOption) + { + semantic_option& option = yyitems[yynewGLRStackItem (false)].getOption (); + option = std::move (newOption); + return option; + } + + /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in + * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1. + * For convenience, always return YYLOW1. */ + int + yyfill (glr_stack_item *yyvsp, int &yylow, int yylow1, bool yynormal) + { + if (!yynormal && yylow1 < yylow) + { + yyfillin (yyvsp, yylow, yylow1); + yylow = yylow1; + } + return yylow1; + } + + /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting + * at YYVSP[YYLOW0].getState().pred(). Leaves YYVSP[YYLOW1].getState().pred() + * containing the pointer to the next state in the chain. */ + void + yyfillin (glr_stack_item *yyvsp, int yylow0, int yylow1) + { + glr_state* s = yyvsp[yylow0].getState().pred(); + YYASSERT(s != YY_NULLPTR); + for (int i = yylow0-1; i >= yylow1; i -= 1, s = s->pred()) + { + glr_state& yys = yyvsp[i].getState(); +#if ]b4_api_PREFIX[DEBUG + yys.yylrState = s->yylrState; +#endif + yys.yyresolved = s->yyresolved; + if (s->yyresolved) + {]b4_variant_if([[ + new (&yys.value ()) value_type (); + ]b4_symbol_variant([yy_accessing_symbol (s->yylrState)], + [yys.value ()], [copy], [s->value ()])], [[ + new (&yys.value ()) value_type (s->value ());]])[ + } + else + /* The effect of using yyval or yyloc (in an immediate + * rule) is undefined. */ + yys.setFirstVal (YY_NULLPTR);]b4_locations_if([[ + yys.yyloc = s->yyloc;]])[ + yys.setPred(s->pred()); + } + } + +#if ]b4_api_PREFIX[DEBUG + + /*----------------------------------------------------------------------. + | Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. | + `----------------------------------------------------------------------*/ + + void + yy_reduce_print (bool yynormal, glr_stack_item* yyvsp, state_set_index yyk, + rule_num yyrule, parser_type& yyparser) + { + int yynrhs = yyrhsLength (yyrule);]b4_locations_if([ + int yylow = 1;])[ + int yyi; + std::cerr << "Reducing stack " << yyk.get() << " by rule " << yyrule - 1 + << " (line " << int (yyrline[yyrule]) << "):\n"; + if (! yynormal) + yyfillin (yyvsp, 1, -yynrhs); + /* The symbols being reduced. */ + for (yyi = 0; yyi < yynrhs; yyi++) + { + std::cerr << " $" << yyi + 1 << " = "; + yyparser.yy_symbol_print_ + (yy_accessing_symbol (yyvsp[yyi - yynrhs + 1].getState().yylrState), + yyvsp[yyi - yynrhs + 1].getState().value ()]b4_locations_if([[, + ]b4_rhs_location(yynrhs, yyi + 1)])[); + if (!yyvsp[yyi - yynrhs + 1].getState().yyresolved) + std::cerr << " (unresolved)"; + std::cerr << '\n'; + } + } + + +#define YYINDEX(YYX) \ + ((YYX) == YY_NULLPTR ? -1 : (YYX)->indexIn (yyitems.data ())) + + void + dumpStack () const + { + for (size_t yyi = 0; yyi < size(); ++yyi) + { + const glr_stack_item& item = yyitems[yyi]; + std::cerr << std::setw(3) << yyi << ". "; + if (item.is_state()) + { + std::cerr << "Res: " << item.getState().yyresolved + << ", LR State: " << item.getState().yylrState + << ", posn: " << item.getState().yyposn + << ", pred: " << YYINDEX(item.getState().pred()); + if (! item.getState().yyresolved) + std::cerr << ", firstVal: " + << YYINDEX(item.getState().firstVal()); + } + else + { + std::cerr << "Option. rule: " << item.getOption().yyrule - 1 + << ", state: " << YYINDEX(item.getOption().state()) + << ", next: " << YYINDEX(item.getOption().next()); + } + std::cerr << '\n'; + } + std::cerr << "Tops:"; + for (state_set_index yyi = create_state_set_index(0); yyi.uget() < numTops(); ++yyi) { + std::cerr << yyi.get() << ": " << YYINDEX(topAt(yyi)) << "; "; + } + std::cerr << '\n'; + } + +#undef YYINDEX +#endif + + YYRESULTTAG + yyreportAmbiguity (const semantic_option& yyx0, + const semantic_option& yyx1, parser_type& yyparser]b4_locations_if([, const location_type& yyloc])[) + { + YY_USE (yyx0); + YY_USE (yyx1); + +#if ]b4_api_PREFIX[DEBUG + std::cerr << "Ambiguity detected.\n" + "Option 1,\n"; + yyx0.yyreportTree (); + std::cerr << "\nOption 2,\n"; + yyx1.yyreportTree (); + std::cerr << '\n'; +#endif + + yyparser.error (]b4_locations_if([yyloc, ])[YY_("syntax is ambiguous")); + return yyabort; + } + +#if ]b4_api_PREFIX[DEBUG + /* Print YYS (possibly NULL) and its predecessors. */ + void + yypstates (const glr_state* yys) const + { + if (yys != YY_NULLPTR) + yys->yy_yypstack(); + else + std::cerr << ""; + std::cerr << '\n'; + } +#endif + + private: + size_t spaceLeft() const + { + return yyitems.capacity() - yyitems.size(); + } + + /** Return a fresh GLRStackItem in this. The item is an LR state + * if YYIS_STATE, and otherwise a semantic option. Callers should call + * yyreserveStack afterwards to make sure there is sufficient + * headroom. */ + size_t + yynewGLRStackItem (bool yyis_state) + { + YYDASSERT(yyitems.size() < yyitems.capacity()); + yyitems.push_back(glr_stack_item(yyis_state)); + return yyitems.size() - 1; + } + + + public: + std::vector yyitems; + // Where the stack splits. Anything below this address is deterministic. + const glr_state* yysplitPoint; + glr_state_set yytops; + }; // class state_stack +} // namespace + +#undef YYFILL +#define YYFILL(N) yystateStack.yyfill (yyvsp, yylow, (N), yynormal) + +namespace ]b4_namespace_ref[ +{ + class ]b4_parser_class[::glr_stack + { + public: +]b4_parse_error_bmatch([custom\|detailed\|verbose], [[ + // Needs access to yypact_value_is_default, etc. + friend context; +]])[ + + glr_stack (size_t yysize, parser_type& yyparser_yyarg]m4_ifset([b4_parse_param], [, b4_parse_param_decl])[) + : yyerrState (0) + , yystateStack (yysize) + , yyerrcnt (0) + , yyla () + , yyparser (yyparser_yyarg)]m4_ifset([b4_parse_param], [,b4_parse_param_cons])[ + {} + + ~glr_stack () + { + if (!this->yyla.empty ()) + yyparser.yy_destroy_ ("Cleanup: discarding lookahead", + this->yyla.kind (), this->yyla.value]b4_locations_if([, this->yyla.location])[); + popall_ (); + } + + int yyerrState; +]b4_locations_if([[ /* To compute the location of the error token. */ + glr_stack_item yyerror_range[3];]])[ + state_stack yystateStack; + int yyerrcnt; + symbol_type yyla; + YYJMP_BUF yyexception_buffer; + parser_type& yyparser; + + #define YYCHK1(YYE) \ + do { \ + switch (YYE) { \ + case yyok: \ + break; \ + case yyabort: \ + goto yyabortlab; \ + case yyaccept: \ + goto yyacceptlab; \ + case yyerr: \ + goto yyuser_error; \ + default: \ + goto yybuglab; \ + } \ + } while (false) + + int + parse () + { + int yyresult; + size_t yyposn; + + YYCDEBUG << "Starting parse\n"; + + this->yyla.clear (); +]m4_ifdef([b4_initial_action], [ +b4_dollar_pushdef([yyla.value], [], [], [yyla.location])dnl + b4_user_initial_action +b4_dollar_popdef])[]dnl +[ + switch (YYSETJMP (this->yyexception_buffer)) + { + case 0: break; + case 1: goto yyabortlab; + case 2: goto yyexhaustedlab; + default: goto yybuglab; + } + this->yyglrShift (create_state_set_index(0), 0, 0, this->yyla.value]b4_locations_if([, this->yyla.location])[); + yyposn = 0; + + while (true) + { + /* For efficiency, we have two loops, the first of which is + specialized to deterministic operation (single stack, no + potential ambiguity). */ + /* Standard mode */ + while (true) + { + const state_num yystate = this->firstTopState()->yylrState; + YYCDEBUG << "Entering state " << yystate << '\n'; + if (yystate == YYFINAL) + goto yyacceptlab; + if (yy_is_defaulted_state (yystate)) + { + const rule_num yyrule = yy_default_action (yystate); + if (yyrule == 0) + {]b4_locations_if([[ + this->yyerror_range[1].getState().yyloc = this->yyla.location;]])[ + this->yyreportSyntaxError (); + goto yyuser_error; + } + YYCHK1 (this->yyglrReduce (create_state_set_index(0), yyrule, true)); + } + else + { + yyget_token (); + const short* yyconflicts; + const int yyaction = yygetLRActions (yystate, this->yyla.kind (), yyconflicts); + if (*yyconflicts != 0) + break; + if (yy_is_shift_action (yyaction)) + { + YY_SYMBOL_PRINT ("Shifting", this->yyla.kind (), this->yyla.value, this->yyla.location); + yyposn += 1; + // FIXME: we should move yylval. + this->yyglrShift (create_state_set_index(0), yyaction, yyposn, this->yyla.value]b4_locations_if([, this->yyla.location])[); + yyla.clear (); + if (0 < this->yyerrState) + this->yyerrState -= 1; + } + else if (yy_is_error_action (yyaction)) + {]b4_locations_if([[ + this->yyerror_range[1].getState().yyloc = this->yyla.location;]])[ + /* Don't issue an error message again for exceptions + thrown from the scanner. */ + if (this->yyla.kind () != ]b4_symbol(error, kind)[) + this->yyreportSyntaxError (); + goto yyuser_error; + } + else + YYCHK1 (this->yyglrReduce (create_state_set_index(0), -yyaction, true)); + } + } + + while (true) + { + for (state_set_index yys = create_state_set_index(0); yys.uget() < this->yystateStack.numTops(); ++yys) + this->yystateStack.yytops.setLookaheadNeeds(yys, !this->yyla.empty ()); + + /* yyprocessOneStack returns one of three things: + + - An error flag. If the caller is yyprocessOneStack, it + immediately returns as well. When the caller is finally + yyparse, it jumps to an error label via YYCHK1. + + - yyok, but yyprocessOneStack has invoked yymarkStackDeleted + (yys), which sets the top state of yys to NULL. Thus, + yyparse's following invocation of yyremoveDeletes will remove + the stack. + + - yyok, when ready to shift a token. + + Except in the first case, yyparse will invoke yyremoveDeletes and + then shift the next token onto all remaining stacks. This + synchronization of the shift (that is, after all preceding + reductions on all stacks) helps prevent double destructor calls + on yylval in the event of memory exhaustion. */ + + for (state_set_index yys = create_state_set_index (0); yys.uget () < this->yystateStack.numTops (); ++yys) + YYCHK1 (this->yyprocessOneStack (yys, yyposn]b4_locations_if([, &this->yyla.location])[)); + this->yystateStack.yytops.yyremoveDeletes (); + if (this->yystateStack.yytops.size() == 0) + { + this->yystateStack.yytops.yyundeleteLastStack (); + if (this->yystateStack.yytops.size() == 0) + this->yyFail (]b4_locations_if([&this->yyla.location, ])[YY_("syntax error")); + YYCHK1 (this->yyresolveStack ()); + YYCDEBUG << "Returning to deterministic operation.\n";]b4_locations_if([[ + this->yyerror_range[1].getState ().yyloc = this->yyla.location;]])[ + this->yyreportSyntaxError (); + goto yyuser_error; + } + + /* If any yyglrShift call fails, it will fail after shifting. Thus, + a copy of yylval will already be on stack 0 in the event of a + failure in the following loop. Thus, yyla is emptied + before the loop to make sure the user destructor for yylval isn't + called twice. */ + symbol_kind_type yytoken_to_shift = this->yyla.kind (); + this->yyla.kind_ = ]b4_symbol(empty, kind)[; + yyposn += 1; + for (state_set_index yys = create_state_set_index (0); yys.uget () < this->yystateStack.numTops (); ++yys) + { + const state_num yystate = this->topState (yys)->yylrState; + const short* yyconflicts; + const int yyaction = yygetLRActions (yystate, yytoken_to_shift, yyconflicts); + /* Note that yyconflicts were handled by yyprocessOneStack. */ + YYCDEBUG << "On stack " << yys.get() << ", "; + YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, this->yyla.value, this->yyla.location); + this->yyglrShift (yys, yyaction, yyposn, this->yyla.value]b4_locations_if([, this->yyla.location])[); + YYCDEBUG << "Stack " << yys.get() << " now in state " + << this->topState(yys)->yylrState << '\n'; + } +]b4_variant_if([[ + // FIXME: User destructors. + // Value type destructor. + ]b4_symbol_variant([[yytoken_to_shift]], [[this->yyla.value]], [[template destroy]])])[ + + if (this->yystateStack.yytops.size () == 1) + { + YYCHK1 (this->yyresolveStack ()); + YYCDEBUG << "Returning to deterministic operation.\n"; + this->yystateStack.yycompressStack (); + break; + } + } + continue; + yyuser_error: + this->yyrecoverSyntaxError (]b4_locations_if([&this->yyla.location])[); + yyposn = this->firstTopState()->yyposn; + } + + yyacceptlab: + yyresult = 0; + goto yyreturn; + + yybuglab: + YYASSERT (false); + goto yyabortlab; + + yyabortlab: + yyresult = 1; + goto yyreturn; + + yyexhaustedlab: + yyparser.error (]b4_locations_if([this->yyla.location, ])[YY_("memory exhausted")); + yyresult = 2; + goto yyreturn; + + yyreturn: + return yyresult; + } + #undef YYCHK1 + + void yyreserveGlrStack () + { + if (!yystateStack.yyexpandGLRStackIfNeeded ()) + yyMemoryExhausted (); + } + + _Noreturn void + yyMemoryExhausted () + { + YYLONGJMP (yyexception_buffer, 2); + } + + _Noreturn void + yyFail (]b4_locations_if([location_type* yylocp, ])[const char* yymsg) + { + if (yymsg != YY_NULLPTR) + yyparser.error (]b4_locations_if([*yylocp, ])[yymsg); + YYLONGJMP (yyexception_buffer, 1); + } + + /* GLRStates */ + + + /** Add a new semantic action that will execute the action for rule + * YYRULE on the semantic values in YYRHS to the list of + * alternative actions for YYSTATE. Assumes that YYRHS comes from + * stack #YYK of *this. */ + void + yyaddDeferredAction (state_set_index yyk, glr_state* yystate, + glr_state* yyrhs, rule_num yyrule) + { + semantic_option& yyopt = yystateStack.yynewSemanticOption (semantic_option (yyrule)); + yyopt.setState (yyrhs); + yyopt.setNext (yystate->firstVal ()); + if (yystateStack.yytops.lookaheadNeeds (yyk)) + yyopt.yyla = this->yyla; + yystate->setFirstVal (&yyopt); + + yyreserveGlrStack (); + } + + #if ]b4_api_PREFIX[DEBUG + void yypdumpstack () const + { + yystateStack.dumpStack(); + } + #endif + + void + yyreportSyntaxError () + { + if (yyerrState != 0) + return; +]b4_parse_error_case( +[simple], [[ + std::string msg = YY_("syntax error"); + yyparser.error (]b4_join(b4_locations_if([yyla.location]), [[YY_MOVE (msg)]])[);]], +[custom], [[ + context yyctx (*this, yyla); + yyparser.report_syntax_error (yyctx);]], +[[ + context yyctx (*this, yyla); + std::string msg = yyparser.yysyntax_error_ (yyctx); + yyparser.error (]b4_join(b4_locations_if([yyla.location]), [[YY_MOVE (msg)]])[);]])[ + yyerrcnt += 1; + } + + /* Recover from a syntax error on this, assuming that yytoken, + yylval, and yylloc are the syntactic category, semantic value, and location + of the lookahead. */ + void + yyrecoverSyntaxError (]b4_locations_if([location_type* yylocp])[) + { + if (yyerrState == 3) + /* We just shifted the error token and (perhaps) took some + reductions. Skip tokens until we can proceed. */ + while (true) + { + if (this->yyla.kind () == ]b4_symbol(eof, kind)[) + yyFail (]b4_locations_if([yylocp, ])[YY_NULLPTR); + if (this->yyla.kind () != ]b4_symbol(empty, kind)[) + {]b4_locations_if([[ + /* We throw away the lookahead, but the error range + of the shifted error token must take it into account. */ + glr_state *yys = firstTopState(); + yyerror_range[1].getState().yyloc = yys->yyloc; + yyerror_range[2].getState().yyloc = this->yyla.location; + YYLLOC_DEFAULT ((yys->yyloc), yyerror_range, 2);]])[ + yyparser.yy_destroy_ ("Error: discarding", + this->yyla.kind (), this->yyla.value]b4_locations_if([, this->yyla.location])[);]b4_variant_if([[ + // Value type destructor. + ]b4_symbol_variant([[this->yyla.kind ()]], [[this->yyla.value]], [[template destroy]])])[ + this->yyla.kind_ = ]b4_symbol(empty, kind)[; + } + yyget_token (); + int yyj = yypact[firstTopState()->yylrState]; + if (yypact_value_is_default (yyj)) + return; + yyj += this->yyla.kind (); + if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != this->yyla.kind ()) + { + if (yydefact[firstTopState()->yylrState] != 0) + return; + } + else if (! yytable_value_is_error (yytable[yyj])) + return; + } + + if (!yystateStack.reduceToOneStack()) + yyFail (]b4_locations_if([yylocp, ])[YY_NULLPTR); + + /* Now pop stack until we find a state that shifts the error token. */ + yyerrState = 3; + while (firstTopState () != YY_NULLPTR) + { + glr_state *yys = firstTopState (); + int yyj = yypact[yys->yylrState]; + if (! yypact_value_is_default (yyj)) + { + yyj += YYTERROR; + if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR + && yy_is_shift_action (yytable[yyj])) + { + /* Shift the error token. */]b4_locations_if([[ + /* First adjust its location.*/ + location_type yyerrloc; + yyerror_range[2].getState().yyloc = this->yyla.location; + YYLLOC_DEFAULT (yyerrloc, (yyerror_range), 2);]])[ + YY_SYMBOL_PRINT ("Shifting", yy_accessing_symbol (yytable[yyj]), + this->yyla.value, yyerrloc); + yyglrShift (create_state_set_index(0), yytable[yyj], + yys->yyposn, yyla.value]b4_locations_if([, yyerrloc])[); + yys = firstTopState(); + break; + } + }]b4_locations_if([[ + yyerror_range[1].getState().yyloc = yys->yyloc;]])[ + if (yys->pred() != YY_NULLPTR) + yys->destroy ("Error: popping", yyparser); + yystateStack.setFirstTop(yys->pred()); + yystateStack.pop_back(); + } + if (firstTopState() == YY_NULLPTR) + yyFail (]b4_locations_if([yylocp, ])[YY_NULLPTR); + } + + YYRESULTTAG + yyprocessOneStack (state_set_index yyk, + size_t yyposn]b4_locations_if([, location_type* yylocp])[) + { + while (yystateStack.topAt(yyk) != YY_NULLPTR) + { + const state_num yystate = topState(yyk)->yylrState; + YYCDEBUG << "Stack " << yyk.get() + << " Entering state " << yystate << '\n'; + + YYASSERT (yystate != YYFINAL); + + if (yy_is_defaulted_state (yystate)) + { + const rule_num yyrule = yy_default_action (yystate); + if (yyrule == 0) + { + YYCDEBUG << "Stack " << yyk.get() << " dies.\n"; + yystateStack.yytops.yymarkStackDeleted (yyk); + return yyok; + } + const YYRESULTTAG yyflag + = yyglrReduce (yyk, yyrule, yyimmediate[yyrule]); + if (yyflag == yyerr) + { + YYCDEBUG << "Stack " << yyk.get() << " dies" + " (predicate failure or explicit user error).\n"; + yystateStack.yytops.yymarkStackDeleted (yyk); + return yyok; + } + if (yyflag != yyok) + return yyflag; + } + else + { + yystateStack.yytops.setLookaheadNeeds(yyk, true); + yyget_token (); + const short* yyconflicts; + const int yyaction = yygetLRActions (yystate, this->yyla.kind (), yyconflicts); + + for (; *yyconflicts != 0; ++yyconflicts) + { + state_set_index yynewStack = yystateStack.yysplitStack (yyk); + YYCDEBUG << "Splitting off stack " << yynewStack.get() + << " from " << yyk.get() << ".\n"; + YYRESULTTAG yyflag = + yyglrReduce (yynewStack, *yyconflicts, yyimmediate[*yyconflicts]); + if (yyflag == yyok) + YYCHK (yyprocessOneStack (yynewStack, + yyposn]b4_locations_if([, yylocp])[)); + else if (yyflag == yyerr) + { + YYCDEBUG << "Stack " << yynewStack.get() << " dies.\n"; + yystateStack.yytops.yymarkStackDeleted (yynewStack); + } + else + return yyflag; + } + + if (yy_is_shift_action (yyaction)) + break; + else if (yy_is_error_action (yyaction)) + { + YYCDEBUG << "Stack " << yyk.get() << " dies.\n"; + yystateStack.yytops.yymarkStackDeleted (yyk); + break; + } + else + { + YYRESULTTAG yyflag + = yyglrReduce (yyk, -yyaction, yyimmediate[-yyaction]); + if (yyflag == yyerr) + { + YYCDEBUG << "Stack " << yyk.get() << " dies" + " (predicate failure or explicit user error).\n"; + yystateStack.yytops.yymarkStackDeleted (yyk); + break; + } + else if (yyflag != yyok) + return yyflag; + } + } + } + return yyok; + } + + /** Perform user action for rule number YYN, with RHS length YYRHSLEN, + * and top stack item YYVSP. YYVALP points to place to put semantic + * value ($$), and yylocp points to place for location information + * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT, + * yyerr for YYERROR, yyabort for YYABORT. */ + YYRESULTTAG + yyuserAction (rule_num yyrule, int yyrhslen, glr_stack_item* yyvsp, state_set_index yyk, + value_type* yyvalp]b4_locations_if([, location_type* yylocp])[) + { + bool yynormal YY_ATTRIBUTE_UNUSED = !yystateStack.isSplit(); + int yylow = 1; +]b4_parse_param_use([yyvalp], [yylocp])dnl +[ YY_USE (yyk); + YY_USE (yyrhslen); + # undef yyerrok + # define yyerrok (yyerrState = 0) + # undef YYACCEPT + # define YYACCEPT return yyaccept + # undef YYABORT + # define YYABORT return yyabort + # undef YYERROR + # define YYERROR return yyerrok, yyerr + # undef YYRECOVERING + # define YYRECOVERING() (yyerrState != 0) + # undef yytoken + # define yytoken this->yyla.kind_ + # undef yyclearin + # define yyclearin (yytoken = ]b4_symbol(empty, kind)[) + # undef YYBACKUP + # define YYBACKUP(Token, Value) \ + return yyparser.error (]b4_locations_if([*yylocp, ])[YY_("syntax error: cannot back up")), \ + yyerrok, yyerr + +]b4_variant_if([[ + /* Variants are always initialized to an empty instance of the + correct type. The default '$$ = $1' action is NOT applied + when using variants. */ + // However we really need to prepare yyvsp now if we want to get + // correct locations, so invoke YYFILL for $1 anyway. + (void) YYFILL (1-yyrhslen); + ]b4_symbol_variant([[yylhsNonterm (yyrule)]], [(*yyvalp)], [emplace])], [[ + if (yyrhslen == 0) + *yyvalp = yyval_default; + else + *yyvalp = yyvsp[YYFILL (1-yyrhslen)].getState().value ();]])[]b4_locations_if([[ + /* Default location. */ + YYLLOC_DEFAULT ((*yylocp), (yyvsp - yyrhslen), yyrhslen); + yyerror_range[1].getState().yyloc = *yylocp; +]])[ + /* If yyk == -1, we are running a deferred action on a temporary + stack. In that case, YY_REDUCE_PRINT must not play with YYFILL, + so pretend the stack is "normal". */ + YY_REDUCE_PRINT ((yynormal || yyk == create_state_set_index (-1), yyvsp, yyk, yyrule, yyparser)); + #if YY_EXCEPTIONS + try + { + #endif // YY_EXCEPTIONS + switch (yyrule) + { + ]b4_user_actions[ + default: break; + } + #if YY_EXCEPTIONS + } + catch (const syntax_error& yyexc) + { + YYCDEBUG << "Caught exception: " << yyexc.what() << '\n';]b4_locations_if([ + *yylocp = yyexc.location;])[ + yyparser.error (]b4_locations_if([*yylocp, ])[yyexc.what ()); + YYERROR; + } + #endif // YY_EXCEPTIONS + YY_SYMBOL_PRINT ("-> $$ =", yylhsNonterm (yyrule), *yyvalp, *yylocp); + + return yyok; + # undef yyerrok + # undef YYABORT + # undef YYACCEPT + # undef YYERROR + # undef YYBACKUP + # undef yytoken + # undef yyclearin + # undef YYRECOVERING + } + + YYRESULTTAG + yyresolveStack () + { + if (yystateStack.isSplit ()) + { + int yyn = 0; + for (glr_state* yys = firstTopState (); + yys != yystateStack.yysplitPoint; + yys = yys->pred ()) + yyn += 1; + YYCHK (yyresolveStates (*firstTopState (), yyn)); + } + return yyok; + } + + /** Pop the symbols consumed by reduction #YYRULE from the top of stack + * #YYK of *YYSTACKP, and perform the appropriate semantic action on their + * semantic values. Assumes that all ambiguities in semantic values + * have been previously resolved. Set *YYVALP to the resulting value, + * and *YYLOCP to the computed location (if any). Return value is as + * for userAction. */ + YYRESULTTAG + yydoAction (state_set_index yyk, rule_num yyrule, + value_type* yyvalp]b4_locations_if([, location_type* yylocp])[) + { + const int yynrhs = yyrhsLength (yyrule); + + if (!yystateStack.isSplit()) + { + /* Standard special case: single stack. */ + YYASSERT (yyk.get() == 0); + glr_stack_item* yyrhs = yystateStack.firstTop()->asItem(); + const YYRESULTTAG res + = yyuserAction (yyrule, yynrhs, yyrhs, yyk, yyvalp]b4_locations_if([, yylocp])[); + yystateStack.pop_back(static_cast(yynrhs)); + yystateStack.setFirstTop(&yystateStack[yystateStack.size() - 1].getState()); + return res; + } + else + { + glr_stack_item yyrhsVals[YYMAXRHS + YYMAXLEFT + 1]; + glr_state* yys = yystateStack.topAt(yyk); + yyrhsVals[YYMAXRHS + YYMAXLEFT].getState().setPred(yys);]b4_locations_if([[ + if (yynrhs == 0) + /* Set default location. */ + yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].getState().yyloc = yys->yyloc;]])[ + for (int yyi = 0; yyi < yynrhs; yyi += 1) + { + yys = yys->pred(); + YYASSERT (yys != YY_NULLPTR); + } + yystateStack.yyupdateSplit (*yys); + yystateStack.setTopAt(yyk, yys); + return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, + yyk, + yyvalp]b4_locations_if([, yylocp])[); + } + } + + /** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE, + * and push back on the resulting nonterminal symbol. Perform the + * semantic action associated with YYRULE and store its value with the + * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently + * unambiguous. Otherwise, store the deferred semantic action with + * the new state. If the new state would have an identical input + * position, LR state, and predecessor to an existing state on the stack, + * it is identified with that existing state, eliminating stack #YYK from + * *YYSTACKP. In this case, the semantic value is + * added to the options for the existing state's semantic value. + */ + YYRESULTTAG + yyglrReduce (state_set_index yyk, rule_num yyrule, bool yyforceEval) + { + size_t yyposn = topState(yyk)->yyposn; + + if (yyforceEval || !yystateStack.isSplit()) + { + value_type val;]b4_locations_if([[ + location_type loc;]])[ + + YYRESULTTAG yyflag = yydoAction (yyk, yyrule, &val]b4_locations_if([, &loc])[); + if (yyflag == yyerr && yystateStack.isSplit()) + {]b4_parse_trace_if([[ + YYCDEBUG << "Parse on stack " << yyk.get () + << " rejected by rule " << yyrule - 1 + << " (line " << int (yyrline[yyrule]) << ").\n"; + ]])[} + if (yyflag != yyok) + return yyflag; + yyglrShift (yyk, + yyLRgotoState (topState(yyk)->yylrState, + yylhsNonterm (yyrule)), + yyposn, val]b4_locations_if([, loc])[);]b4_variant_if([[ + // FIXME: User destructors. + // Value type destructor. + ]b4_symbol_variant([[yylhsNonterm (yyrule)]], [[val]], [[template destroy]])])[ + } + else + { + glr_state *yys = yystateStack.topAt(yyk); + glr_state *yys0 = yys; + for (int yyn = yyrhsLength (yyrule); 0 < yyn; yyn -= 1) + { + yys = yys->pred(); + YYASSERT (yys != YY_NULLPTR); + } + yystateStack.yyupdateSplit (*yys); + state_num yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule));]b4_parse_trace_if([[ + YYCDEBUG << "Reduced stack " << yyk.get () + << " by rule " << yyrule - 1 << " (line " << int (yyrline[yyrule]) + << "); action deferred. Now in state " << yynewLRState + << ".\n";]])[ + for (state_set_index yyi = create_state_set_index(0); yyi.uget() < yystateStack.numTops(); ++yyi) + if (yyi != yyk && yystateStack.topAt(yyi) != YY_NULLPTR) + { + const glr_state* yysplit = yystateStack.yysplitPoint; + glr_state* yyp = yystateStack.topAt(yyi); + while (yyp != yys && yyp != yysplit + && yyp->yyposn >= yyposn) + { + if (yyp->yylrState == yynewLRState + && yyp->pred() == yys) + { + yyaddDeferredAction (yyk, yyp, yys0, yyrule); + yystateStack.yytops.yymarkStackDeleted (yyk); + YYCDEBUG << "Merging stack " << yyk.get () + << " into stack " << yyi.get () << ".\n"; + return yyok; + } + yyp = yyp->pred(); + } + } + yystateStack.setTopAt(yyk, yys); + yyglrShiftDefer (yyk, yynewLRState, yyposn, yys0, yyrule); + } + return yyok; + } + + /** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR + * state YYLRSTATE, at input position YYPOSN, with the (unresolved) + * semantic value of YYRHS under the action for YYRULE. */ + void + yyglrShiftDefer (state_set_index yyk, state_num yylrState, + size_t yyposn, glr_state* yyrhs, rule_num yyrule) + { + glr_state& yynewState = yystateStack.yynewGLRState ( + glr_state (yylrState, yyposn)); + yynewState.setPred (yystateStack.topAt (yyk)); + yystateStack.setTopAt (yyk, &yynewState); + + /* Invokes yyreserveStack. */ + yyaddDeferredAction (yyk, &yynewState, yyrhs, yyrule); + } + + /** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR + * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic + * value YYVAL_ARG and source location YYLOC_ARG. */ + void + yyglrShift (state_set_index yyk, state_num yylrState, + size_t yyposn, + const value_type& yyval_arg]b4_locations_if([, const location_type& yyloc_arg])[) + { + glr_state& yynewState = yystateStack.yynewGLRState ( + glr_state (yylrState, yyposn, yyval_arg]b4_locations_if([, yyloc_arg])[)); + yynewState.setPred (yystateStack.topAt(yyk)); + yystateStack.setTopAt (yyk, &yynewState); + yyreserveGlrStack (); + } + +#if ]b4_api_PREFIX[DEBUG + void + yypstack (state_set_index yyk) const + { + yystateStack.yypstates (yystateStack.topAt (yyk)); + } +#endif + + glr_state* topState(state_set_index i) { + return yystateStack.topAt(i); + } + + glr_state* firstTopState() { + return yystateStack.firstTop(); + } + + private: + + void popall_ () + { + /* If the stack is well-formed, pop the stack until it is empty, + destroying its entries as we go. But free the stack regardless + of whether it is well-formed. */ + for (state_set_index k = create_state_set_index(0); k.uget() < yystateStack.numTops(); k += 1) + if (yystateStack.topAt(k) != YY_NULLPTR) + { + while (yystateStack.topAt(k) != YY_NULLPTR) + { + glr_state* state = topState(k);]b4_locations_if([[ + yyerror_range[1].getState().yyloc = state->yyloc;]])[ + if (state->pred() != YY_NULLPTR) + state->destroy ("Cleanup: popping", yyparser); + yystateStack.setTopAt(k, state->pred()); + yystateStack.pop_back(); + } + break; + } + } + + /** Resolve the previous YYN states starting at and including state YYS + * on *YYSTACKP. If result != yyok, some states may have been left + * unresolved possibly with empty semantic option chains. Regardless + * of whether result = yyok, each state has been left with consistent + * data so that destroy can be invoked if necessary. */ + YYRESULTTAG + yyresolveStates (glr_state& yys, int yyn) + { + if (0 < yyn) + { + YYASSERT (yys.pred() != YY_NULLPTR); + YYCHK (yyresolveStates (*yys.pred(), yyn-1)); + if (! yys.yyresolved) + YYCHK (yyresolveValue (yys)); + } + return yyok; + } + + static void + yyuserMerge (int yyn, value_type& yy0, value_type& yy1) + { + YY_USE (yy0); + YY_USE (yy1); + + switch (yyn) + { +]b4_mergers[ + default: break; + } + } + + /** Resolve the ambiguity represented in state YYS in *YYSTACKP, + * perform the indicated actions, and set the semantic value of YYS. + * If result != yyok, the chain of semantic options in YYS has been + * cleared instead or it has been left unmodified except that + * redundant options may have been removed. Regardless of whether + * result = yyok, YYS has been left with consistent data so that + * destroy can be invoked if necessary. */ + YYRESULTTAG + yyresolveValue (glr_state& yys) + { + semantic_option* yybest = yys.firstVal(); + YYASSERT(yybest != YY_NULLPTR); + bool yymerge = false; + YYRESULTTAG yyflag;]b4_locations_if([ + location_type *yylocp = &yys.yyloc;])[ + + semantic_option* yypPrev = yybest; + for (semantic_option* yyp = yybest->next(); + yyp != YY_NULLPTR; ) + { + if (yybest->isIdenticalTo (*yyp)) + { + yybest->mergeWith (*yyp); + yypPrev->setNext(yyp->next()); + yyp = yypPrev->next(); + } + else + { + switch (yypreference (*yybest, *yyp)) + { + case 0:]b4_locations_if([[ + yyresolveLocations (yys, 1);]])[ + return yystateStack.yyreportAmbiguity (*yybest, *yyp, yyparser]b4_locations_if([, *yylocp])[); + break; + case 1: + yymerge = true; + break; + case 2: + break; + case 3: + yybest = yyp; + yymerge = false; + break; + default: + /* This cannot happen so it is not worth a YYASSERT (false), + but some compilers complain if the default case is + omitted. */ + break; + } + yypPrev = yyp; + yyp = yyp->next(); + } + } + + value_type val; + if (yymerge) + { + int yyprec = yydprec[yybest->yyrule]; + yyflag = yyresolveAction (*yybest, &val]b4_locations_if([, yylocp])[); + if (yyflag == yyok) + for (semantic_option* yyp = yybest->next(); + yyp != YY_NULLPTR; + yyp = yyp->next()) + { + if (yyprec == yydprec[yyp->yyrule]) + { + value_type yyval_other;]b4_locations_if([ + location_type yydummy;])[ + yyflag = yyresolveAction (*yyp, &yyval_other]b4_locations_if([, &yydummy])[); + if (yyflag != yyok) + { + yyparser.yy_destroy_ ("Cleanup: discarding incompletely merged value for", + yy_accessing_symbol (yys.yylrState), + this->yyla.value]b4_locations_if([, *yylocp])[); + break; + } + yyuserMerge (yymerger[yyp->yyrule], val, yyval_other);]b4_variant_if([[ + // FIXME: User destructors. + // Value type destructor. + ]b4_symbol_variant([[yy_accessing_symbol (yys.yylrState)]], [[yyval_other]], [[template destroy]])])[ + } + } + } + else + yyflag = yyresolveAction (*yybest, &val]b4_locations_if([, yylocp])[); + + if (yyflag == yyok) + { + yys.yyresolved = true; + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN]b4_variant_if([[ + new (&yys.value ()) value_type (); + ]b4_symbol_variant([yy_accessing_symbol (yys.yylrState)], + [yys.value ()], [copy], [val])], [[ + new (&yys.value ()) value_type (val);]])[ + + YY_IGNORE_MAYBE_UNINITIALIZED_END + } + else + yys.setFirstVal(YY_NULLPTR); +]b4_variant_if([[ + // FIXME: User destructors. + // Value type destructor. + ]b4_symbol_variant([[yy_accessing_symbol (yys.yylrState)]], [[val]], [[template destroy]])])[ + return yyflag; + } + + /** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its + * user action, and return the semantic value and location in *YYVALP + * and *YYLOCP. Regardless of whether result = yyok, all RHS states + * have been destroyed (assuming the user action destroys all RHS + * semantic values if invoked). */ + YYRESULTTAG + yyresolveAction (semantic_option& yyopt, value_type* yyvalp]b4_locations_if([, location_type* yylocp])[) + { + glr_state* yyoptState = yyopt.state(); + YYASSERT(yyoptState != YY_NULLPTR); + int yynrhs = yyrhsLength (yyopt.yyrule); + YYRESULTTAG yyflag = yyresolveStates (*yyoptState, yynrhs); + if (yyflag != yyok) + { + for (glr_state *yys = yyoptState; yynrhs > 0; yys = yys->pred(), yynrhs -= 1) + yys->destroy ("Cleanup: popping", yyparser); + return yyflag; + } + + glr_stack_item yyrhsVals[YYMAXRHS + YYMAXLEFT + 1]; + yyrhsVals[YYMAXRHS + YYMAXLEFT].getState().setPred(yyopt.state());]b4_locations_if([[ + if (yynrhs == 0) + /* Set default location. */ + yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].getState().yyloc = yyoptState->yyloc;]])[ + { + symbol_type yyla_current = std::move (this->yyla); + this->yyla = std::move (yyopt.yyla); + yyflag = yyuserAction (yyopt.yyrule, yynrhs, + yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, + create_state_set_index (-1), + yyvalp]b4_locations_if([, yylocp])[); + this->yyla = std::move (yyla_current); + } + return yyflag; + }]b4_locations_if([[ + + /** Resolve the locations for each of the YYN1 states in *YYSTACKP, + * ending at YYS1. Has no effect on previously resolved states. + * The first semantic option of a state is always chosen. */ + void + yyresolveLocations (glr_state &yys1, int yyn1) + { + if (0 < yyn1) + { + yyresolveLocations (*yys1.pred(), yyn1 - 1); + if (!yys1.yyresolved) + { + glr_stack_item yyrhsloc[1 + YYMAXRHS]; + YYASSERT (yys1.firstVal() != YY_NULLPTR); + semantic_option& yyoption = *yys1.firstVal(); + const int yynrhs = yyrhsLength (yyoption.yyrule); + if (0 < yynrhs) + { + yyresolveLocations (*yyoption.state(), yynrhs); + const glr_state *yys = yyoption.state(); + for (int yyn = yynrhs; yyn > 0; yyn -= 1) + { + yyrhsloc[yyn].getState().yyloc = yys->yyloc; + yys = yys->pred(); + } + } + else + { + /* Both yyresolveAction and yyresolveLocations traverse the GSS + in reverse rightmost order. It is only necessary to invoke + yyresolveLocations on a subforest for which yyresolveAction + would have been invoked next had an ambiguity not been + detected. Thus the location of the previous state (but not + necessarily the previous state itself) is guaranteed to be + resolved already. */ + YY_IGNORE_NULL_DEREFERENCE_BEGIN + yyrhsloc[0].getState().yyloc = yyoption.state()->yyloc; + YY_IGNORE_NULL_DEREFERENCE_END + } + YYLLOC_DEFAULT ((yys1.yyloc), yyrhsloc, yynrhs); + } + } + }]])[ + + /** If yytoken is empty, fetch the next token. */ + void + yyget_token () + { +]b4_parse_param_use()dnl +[ if (this->yyla.empty ()) + { + YYCDEBUG << "Reading a token\n"; +#if YY_EXCEPTIONS + try +#endif // YY_EXCEPTIONS + {]b4_token_ctor_if([[ + symbol_type yylookahead (]b4_yylex[); + yyla.move (yylookahead);]], [[ + yyla.kind_ = yyparser.yytranslate_ (]b4_yylex[);]])[ + } +#if YY_EXCEPTIONS + catch (const parser_type::syntax_error& yyexc) + { + YYCDEBUG << "Caught exception: " << yyexc.what () << '\n';]b4_locations_if([ + this->yyla.location = yyexc.location;])[ + yyparser.error (]b4_locations_if([this->yyla.location, ])[yyexc.what ()); + // Map errors caught in the scanner to the error token, so that error + // handling is started. + this->yyla.kind_ = ]b4_symbol(error, kind)[; + } + } +#endif // YY_EXCEPTIONS + if (this->yyla.kind () == ]b4_symbol(eof, kind)[) + YYCDEBUG << "Now at end of input.\n"; + else + YY_SYMBOL_PRINT ("Next token is", this->yyla.kind (), this->yyla.value, this->yyla.location); + } + + + /* Bison grammar-table manipulation. */ + + /** The action to take in YYSTATE on seeing YYTOKEN. + * Result R means + * R < 0: Reduce on rule -R. + * R = 0: Error. + * R > 0: Shift to state R. + * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list + * of conflicting reductions. + */ + static int + yygetLRActions (state_num yystate, symbol_kind_type yytoken, const short*& yyconflicts) + { + int yyindex = yypact[yystate] + yytoken; + if (yytoken == ]b4_symbol(error, kind)[) + { + // This is the error token. + yyconflicts = yyconfl; + return 0; + } + else if (yy_is_defaulted_state (yystate) + || yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken) + { + yyconflicts = yyconfl; + return -yydefact[yystate]; + } + else if (! yytable_value_is_error (yytable[yyindex])) + { + yyconflicts = yyconfl + yyconflp[yyindex]; + return yytable[yyindex]; + } + else + { + yyconflicts = yyconfl + yyconflp[yyindex]; + return 0; + } + } + + /** Compute post-reduction state. + * \param yystate the current state + * \param yysym the nonterminal to push on the stack + */ + static state_num + yyLRgotoState (state_num yystate, symbol_kind_type yysym) + { + const int yyr = yypgoto[yysym - YYNTOKENS] + yystate; + if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate) + return yytable[yyr]; + else + return yydefgoto[yysym - YYNTOKENS]; + } + + static bool + yypact_value_is_default (state_num yystate) + { + return ]b4_table_value_equals([[pact]], [[yystate]], [b4_pact_ninf], [YYPACT_NINF])[; + } + + static bool + yytable_value_is_error (int yytable_value YY_ATTRIBUTE_UNUSED) + { + return ]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_ninf], [YYTABLE_NINF])[; + } + + static bool + yy_is_shift_action (int yyaction) YY_NOEXCEPT + { + return 0 < yyaction; + } + + static bool + yy_is_error_action (int yyaction) YY_NOEXCEPT + { + return yyaction == 0; + } + + /** Whether LR state YYSTATE has only a default reduction + * (regardless of token). */ + static bool + yy_is_defaulted_state (state_num yystate) + { + return yypact_value_is_default (yypact[yystate]); + } + + /** The default reduction for YYSTATE, assuming it has one. */ + static rule_num + yy_default_action (state_num yystate) + { + return yydefact[yystate]; + } + + /* GLRStacks */ + + /** Y0 and Y1 represent two possible actions to take in a given + * parsing state; return 0 if no combination is possible, + * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */ + static int + yypreference (const semantic_option& y0, const semantic_option& y1) + { + const rule_num r0 = y0.yyrule, r1 = y1.yyrule; + const int p0 = yydprec[r0], p1 = yydprec[r1]; + + if (p0 == p1) + { + if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1]) + return 0; + else + return 1; + } + else if (p0 == 0 || p1 == 0) + return 0; + else if (p0 < p1) + return 3; + else if (p1 < p0) + return 2; + else + return 0; + } + +]b4_parse_param_vars[ + }; // class ]b4_parser_class[::glr_stack +} // namespace ]b4_namespace_ref[ + + +#if ]b4_api_PREFIX[DEBUG +namespace +{ + void + yypstack (const glr_stack& yystack, size_t yyk) + { + yystack.yypstack (create_state_set_index (static_cast (yyk))); + } + + void + yypdumpstack (const glr_stack& yystack) + { + yystack.yypdumpstack (); + } +} +#endif + +]b4_namespace_open[ + /// Build a parser object. + ]b4_parser_class::b4_parser_class[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [ + :])[ +#if ]b4_api_PREFIX[DEBUG + ]m4_ifset([b4_parse_param], [ ], [ :])[yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[ +#endif]b4_parse_param_cons[ + {} + + ]b4_parser_class::~b4_parser_class[ () + {} + + ]b4_parser_class[::syntax_error::~syntax_error () YY_NOEXCEPT YY_NOTHROW + {} + + int + ]b4_parser_class[::operator() () + { + return parse (); + } + + int + ]b4_parser_class[::parse () + { + glr_stack yystack(YYINITDEPTH, *this]b4_user_args[); + return yystack.parse (); + } + +]b4_parse_error_bmatch([custom\|detailed], +[[ const char * + ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol) + { + static const char *const yy_sname[] = + { + ]b4_symbol_names[ + };]b4_has_translations_if([[ + /* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is + internationalizable. */ + static ]b4_int_type_for([b4_translatable])[ yytranslatable[] = + { + ]b4_translatable[ + }; + return (yysymbol < YYNTOKENS && yytranslatable[yysymbol] + ? _(yy_sname[yysymbol]) + : yy_sname[yysymbol]);]], [[ + return yy_sname[yysymbol];]])[ + } +]], +[simple], +[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ + const char * + ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol) + { + return yytname_[yysymbol]; + } +#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ +]], +[verbose], +[[ /* Return YYSTR after stripping away unnecessary quotes and + backslashes, so that it's suitable for yyerror. The heuristic is + that double-quoting is unnecessary unless the string contains an + apostrophe, a comma, or backslash (other than backslash-backslash). + YYSTR is taken from yytname. */ + std::string + ]b4_parser_class[::yytnamerr_ (const char *yystr) + { + if (*yystr == '"') + { + std::string yyr; + char const *yyp = yystr; + + for (;;) + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + else + goto append; + + append: + default: + yyr += *yyp; + break; + + case '"': + return yyr; + } + do_not_strip_quotes: ; + } + + return yystr; + } + + std::string + ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol) + { + return yytnamerr_ (yytname_[yysymbol]); + } +]])[ + +]b4_parse_error_bmatch([simple\|verbose], +[[#if ]b4_api_PREFIX[DEBUG]b4_tname_if([[ || 1]])[ + // YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + // First, the terminals, then, starting at \a YYNTOKENS, nonterminals. + const char* + const ]b4_parser_class[::yytname_[] = + { + ]b4_tname[ + }; +#endif +]])[ + +]b4_parse_error_bmatch([custom\|detailed\|verbose], [[ + // ]b4_parser_class[::context. + ]b4_parser_class[::context::context (glr_stack& yystack, const symbol_type& yyla) + : yystack_ (yystack) + , yyla_ (yyla) + {} + + int + ]b4_parser_class[::context::expected_tokens (symbol_kind_type yyarg[], int yyargn) const + { + // Actual number of expected tokens + int yycount = 0; + const int yyn = yypact[yystack_.firstTopState()->yylrState]; + if (!yystack_.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. */ + const int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + const int yychecklim = YYLAST - yyn + 1; + const int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + for (int yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != ]b4_symbol(error, kind)[ + && !yystack_.yytable_value_is_error (yytable[yyx + yyn])) + { + if (!yyarg) + ++yycount; + else if (yycount == yyargn) + return 0; + else + yyarg[yycount++] = YY_CAST (symbol_kind_type, yyx); + } + } + if (yyarg && yycount == 0 && 0 < yyargn) + yyarg[0] = ]b4_symbol(empty, kind)[; + return yycount; + } + +]])[ + +]b4_parse_error_bmatch([detailed\|verbose], [[ + int + ]b4_parser_class[::yy_syntax_error_arguments_ (const context& yyctx, + symbol_kind_type yyarg[], int yyargn) const + { + /* There are many possibilities here to consider: + - 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 yyla) 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 + yyla. (However, yyla is currently not documented for users.) + */ + + if (!yyctx.lookahead ().empty ()) + { + if (yyarg) + yyarg[0] = yyctx.token (); + int yyn = yyctx.expected_tokens (yyarg ? yyarg + 1 : yyarg, yyargn - 1); + return yyn + 1; + } + return 0; + } + + // Generate an error message. + std::string + ]b4_parser_class[::yysyntax_error_ (const context& yyctx) const + { + // Its maximum. + enum { YYARGS_MAX = 5 }; + // Arguments of yyformat. + symbol_kind_type yyarg[YYARGS_MAX]; + int yycount = yy_syntax_error_arguments_ (yyctx, yyarg, YYARGS_MAX); + + char const* yyformat = YY_NULLPTR; + switch (yycount) + { +#define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + default: // Avoid compiler warnings. + 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_ + } + + std::string yyres; + // Argument number. + std::ptrdiff_t yyi = 0; + for (char const* yyp = yyformat; *yyp; ++yyp) + if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount) + { + yyres += symbol_name (yyarg[yyi++]); + ++yyp; + } + else + yyres += *yyp; + return yyres; + }]])[ + + void + ]b4_parser_class[::yy_destroy_ (const char* yymsg, symbol_kind_type yykind, + value_type& yyval]b4_locations_if([[, + location_type& yyloc]])[) + { + YY_USE (yyval);]b4_locations_if([[ + YY_USE (yyloc);]])[ + if (!yymsg) + yymsg = "Deleting"; + ]b4_parser_class[& yyparser = *this; + YY_USE (yyparser); + YY_SYMBOL_PRINT (yymsg, yykind, yyval, yyloc); + + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + ]m4_do([m4_pushdef([b4_symbol_action], m4_defn([b4_symbol_action_for_yyval]))], + [b4_symbol_actions([destructor])], + [m4_popdef([b4_symbol_action])])[ + YY_IGNORE_MAYBE_UNINITIALIZED_END + } + +#if ]b4_api_PREFIX[DEBUG + /*--------------------. + | Print this symbol. | + `--------------------*/ + + void + ]b4_parser_class[::yy_symbol_value_print_ (symbol_kind_type yykind, + const value_type& yyval]b4_locations_if([[, + const location_type& yyloc]])[) const + {]b4_locations_if([[ + YY_USE (yyloc);]])[ + YY_USE (yyval); + std::ostream& yyo = debug_stream (); + YY_USE (yyo); + ]m4_do([m4_pushdef([b4_symbol_action], m4_defn([b4_symbol_action_for_yyval]))], + [b4_symbol_actions([printer])], + [m4_popdef([b4_symbol_action])])[ + } + + void + ]b4_parser_class[::yy_symbol_print_ (symbol_kind_type yykind, + const value_type& yyval]b4_locations_if([[, + const location_type& yyloc]])[) const + { + *yycdebug_ << (yykind < YYNTOKENS ? "token" : "nterm") + << ' ' << symbol_name (yykind) << " ("]b4_locations_if([[ + << yyloc << ": "]])[; + yy_symbol_value_print_ (yykind, yyval]b4_locations_if([[, yyloc]])[); + *yycdebug_ << ')'; + } + + std::ostream& + ]b4_parser_class[::debug_stream () const + { + return *yycdebug_; + } + + void + ]b4_parser_class[::set_debug_stream (std::ostream& o) + { + yycdebug_ = &o; + } + + + ]b4_parser_class[::debug_level_type + ]b4_parser_class[::debug_level () const + { + return yydebug; + } + + void + ]b4_parser_class[::set_debug_level (debug_level_type l) + { + // Actually, it is yydebug which is really used. + yydebug = l; + } +#endif // ]b4_api_PREFIX[DEBUG + +]b4_token_ctor_if([], [b4_yytranslate_define([cc])])[ + +]b4_token_ctor_if([], [[ + /*---------. + | symbol. | + `---------*/ +]b4_public_types_define([cc])])[ +]b4_namespace_close[]dnl +b4_epilogue[]dnl +b4_output_end diff --git a/Engine/bin/bison-flex/data/skeletons/java-skel.m4 b/Engine/bin/bison-flex/data/skeletons/java-skel.m4 new file mode 100644 index 000000000..11cbc4999 --- /dev/null +++ b/Engine/bin/bison-flex/data/skeletons/java-skel.m4 @@ -0,0 +1,27 @@ + -*- Autoconf -*- + +# Java skeleton dispatching for Bison. + +# Copyright (C) 2007, 2009-2015, 2018-2021 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +b4_glr_if( [b4_complain([%%glr-parser not supported for Java])]) +b4_nondeterministic_if([b4_complain([%%nondeterministic-parser not supported for Java])]) + +m4_define_default([b4_used_skeleton], [b4_skeletonsdir/[lalr1.java]]) +m4_define_default([b4_skeleton], ["b4_basename(b4_used_skeleton)"]) + +m4_include(b4_used_skeleton) diff --git a/Engine/bin/bison-flex/data/skeletons/java.m4 b/Engine/bin/bison-flex/data/skeletons/java.m4 new file mode 100644 index 000000000..8b0828b0b --- /dev/null +++ b/Engine/bin/bison-flex/data/skeletons/java.m4 @@ -0,0 +1,502 @@ + -*- Autoconf -*- + +# Java language support for Bison + +# Copyright (C) 2007-2015, 2018-2021 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +m4_include(b4_skeletonsdir/[c-like.m4]) + + +# b4_list2(LIST1, LIST2) +# ---------------------- +# Join two lists with a comma if necessary. +m4_define([b4_list2], + [$1[]m4_ifval(m4_quote($1), [m4_ifval(m4_quote($2), [[, ]])])[]$2]) + + +# b4_percent_define_get3(DEF, PRE, POST, NOT) +# ------------------------------------------- +# Expand to the value of DEF surrounded by PRE and POST if it's %define'ed, +# otherwise NOT. +m4_define([b4_percent_define_get3], + [m4_ifval(m4_quote(b4_percent_define_get([$1])), + [$2[]b4_percent_define_get([$1])[]$3], [$4])]) + + + +# b4_flag_value(BOOLEAN-FLAG) +# --------------------------- +m4_define([b4_flag_value], [b4_flag_if([$1], [true], [false])]) + + +# b4_parser_class_declaration +# --------------------------- +# The declaration of the parser class ("class YYParser"), with all its +# qualifiers/annotations. +b4_percent_define_default([[api.parser.abstract]], [[false]]) +b4_percent_define_default([[api.parser.final]], [[false]]) +b4_percent_define_default([[api.parser.public]], [[false]]) +b4_percent_define_default([[api.parser.strictfp]], [[false]]) + +m4_define([b4_parser_class_declaration], +[b4_percent_define_get3([api.parser.annotations], [], [ ])dnl +b4_percent_define_flag_if([api.parser.public], [public ])dnl +b4_percent_define_flag_if([api.parser.abstract], [abstract ])dnl +b4_percent_define_flag_if([api.parser.final], [final ])dnl +b4_percent_define_flag_if([api.parser.strictfp], [strictfp ])dnl +[class ]b4_parser_class[]dnl +b4_percent_define_get3([api.parser.extends], [ extends ])dnl +b4_percent_define_get3([api.parser.implements], [ implements ])]) + + +# b4_lexer_if(TRUE, FALSE) +# ------------------------ +m4_define([b4_lexer_if], +[b4_percent_code_ifdef([[lexer]], [$1], [$2])]) + + +# b4_identification +# ----------------- +m4_define([b4_identification], +[[ /** Version number for the Bison executable that generated this parser. */ + public static final String bisonVersion = "]b4_version_string["; + + /** Name of the skeleton that generated this parser. */ + public static final String bisonSkeleton = ]b4_skeleton[; +]]) + + +## ------------ ## +## Data types. ## +## ------------ ## + +# b4_int_type(MIN, MAX) +# --------------------- +# Return the smallest int type able to handle numbers ranging from +# MIN to MAX (included). +m4_define([b4_int_type], +[m4_if(b4_ints_in($@, [-128], [127]), [1], [byte], + b4_ints_in($@, [-32768], [32767]), [1], [short], + [int])]) + +# b4_int_type_for(NAME) +# --------------------- +# Return the smallest int type able to handle numbers ranging from +# 'NAME_min' to 'NAME_max' (included). +m4_define([b4_int_type_for], +[b4_int_type($1_min, $1_max)]) + +# b4_null +# ------- +m4_define([b4_null], [null]) + + +# b4_typed_parser_table_define(TYPE, NAME, DATA, COMMENT) +# ------------------------------------------------------- +# We use intermediate functions (e.g., yypact_init) to work around the +# 64KB limit for JVM methods. See +# https://lists.gnu.org/r/help-bison/2008-11/msg00004.html. +m4_define([b4_typed_parser_table_define], +[m4_ifval([$4], [b4_comment([$4]) + ])dnl +[private static final ]$1[[] yy$2_ = yy$2_init(); + private static final ]$1[[] yy$2_init() + { + return new ]$1[[] + { + ]$3[ + }; + }]]) + + +# b4_integral_parser_table_define(NAME, DATA, COMMENT) +#----------------------------------------------------- +m4_define([b4_integral_parser_table_define], +[b4_typed_parser_table_define([b4_int_type_for([$2])], [$1], [$2], [$3])]) + + +## ------------- ## +## Token kinds. ## +## ------------- ## + + +# b4_token_enum(TOKEN-NUM) +# ------------------------ +# Output the definition of this token as an enum. +m4_define([b4_token_enum], +[b4_token_visible_if([$1], + [m4_format([[ /** Token %s, to be returned by the scanner. */ + static final int %s = %s%s; +]], + b4_symbol([$1], [tag]), + b4_symbol([$1], [id]), + b4_symbol([$1], b4_api_token_raw_if([[number]], [[code]])))])]) + + +# b4_token_enums +# -------------- +# Output the definition of the tokens (if there are) as enums. +m4_define([b4_token_enums], +[b4_any_token_visible_if([ /* Token kinds. */ +b4_symbol_foreach([b4_token_enum])])]) + + + +## -------------- ## +## Symbol kinds. ## +## -------------- ## + + +# b4_symbol_kind(NUM) +# ------------------- +m4_define([b4_symbol_kind], +[SymbolKind.b4_symbol_kind_base($@)]) + + +# b4_symbol_enum(SYMBOL-NUM) +# -------------------------- +# Output the definition of this symbol as an enum. +m4_define([b4_symbol_enum], +[m4_format([ %-30s %s], + m4_format([[%s(%s)%s]], + b4_symbol([$1], [kind_base]), + [$1], + m4_if([$1], b4_last_symbol, [[;]], [[,]])), + [b4_symbol_tag_comment([$1])])]) + + +# b4_declare_symbol_enum +# ---------------------- +# The definition of the symbol internal numbers as an enum. +m4_define([b4_declare_symbol_enum], +[[ public enum SymbolKind + { +]b4_symbol_foreach([b4_symbol_enum])[ + + private final int yycode_; + + SymbolKind (int n) { + this.yycode_ = n; + } + + private static final SymbolKind[] values_ = { + ]m4_map_args_sep([b4_symbol_kind(], [)], [, + ], b4_symbol_numbers)[ + }; + + static final SymbolKind get(int code) { + return values_[code]; + } + + public final int getCode() { + return this.yycode_; + } + +]b4_parse_error_bmatch( +[simple\|verbose], +[[ /* Return YYSTR after stripping away unnecessary quotes and + backslashes, so that it's suitable for yyerror. The heuristic is + that double-quoting is unnecessary unless the string contains an + apostrophe, a comma, or backslash (other than backslash-backslash). + YYSTR is taken from yytname. */ + private static String yytnamerr_(String yystr) + { + if (yystr.charAt (0) == '"') + { + StringBuffer yyr = new StringBuffer(); + strip_quotes: for (int i = 1; i < yystr.length(); i++) + switch (yystr.charAt(i)) + { + case '\'': + case ',': + break strip_quotes; + + case '\\': + if (yystr.charAt(++i) != '\\') + break strip_quotes; + /* Fall through. */ + default: + yyr.append(yystr.charAt(i)); + break; + + case '"': + return yyr.toString(); + } + } + return yystr; + } + + /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at \a YYNTOKENS_, nonterminals. */ + ]b4_typed_parser_table_define([String], [tname], [b4_tname])[ + + /* The user-facing name of this symbol. */ + public final String getName() { + return yytnamerr_(yytname_[yycode_]); + } +]], +[custom\|detailed], +[[ /* YYNAMES_[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at \a YYNTOKENS_, nonterminals. */ + ]b4_typed_parser_table_define([String], [names], [b4_symbol_names])[ + + /* The user-facing name of this symbol. */ + public final String getName() { + return yynames_[yycode_]; + }]])[ + }; +]])]) + + + +# b4_case(ID, CODE, [COMMENTS]) +# ----------------------------- +# We need to fool Java's stupid unreachable code detection. +m4_define([b4_case], +[ case $1:m4_ifval([$3], [ b4_comment([$3])]) + if (yyn == $1) + $2; + break; +]) + + +# b4_predicate_case(LABEL, CONDITIONS) +# ------------------------------------ +m4_define([b4_predicate_case], +[ case $1: + if (! ($2)) YYERROR; + break; +]) + + +## -------- ## +## Checks. ## +## -------- ## + +b4_percent_define_check_kind([[api.value.type]], [code], [deprecated]) + +b4_percent_define_check_kind([[annotations]], [code], [deprecated]) +b4_percent_define_check_kind([[extends]], [code], [deprecated]) +b4_percent_define_check_kind([[implements]], [code], [deprecated]) +b4_percent_define_check_kind([[init_throws]], [code], [deprecated]) +b4_percent_define_check_kind([[lex_throws]], [code], [deprecated]) +b4_percent_define_check_kind([[api.parser.class]], [code], [deprecated]) +b4_percent_define_check_kind([[throws]], [code], [deprecated]) + + + +## ---------------- ## +## Default values. ## +## ---------------- ## + +m4_define([b4_yystype], [b4_percent_define_get([[api.value.type]])]) +b4_percent_define_default([[api.value.type]], [[Object]]) +b4_percent_define_default([[api.symbol.prefix]], [[S_]]) + +# b4_api_prefix, b4_api_PREFIX +# ---------------------------- +# Corresponds to %define api.prefix +b4_percent_define_default([[api.prefix]], [[YY]]) +m4_define([b4_api_prefix], +[b4_percent_define_get([[api.prefix]])]) +m4_define([b4_api_PREFIX], +[m4_toupper(b4_api_prefix)]) + +# b4_prefix +# --------- +# If the %name-prefix is not given, it is api.prefix. +m4_define_default([b4_prefix], [b4_api_prefix]) + +b4_percent_define_default([[api.parser.class]], [b4_prefix[]Parser]) +m4_define([b4_parser_class], [b4_percent_define_get([[api.parser.class]])]) + +b4_percent_define_default([[lex_throws]], [[java.io.IOException]]) +m4_define([b4_lex_throws], [b4_percent_define_get([[lex_throws]])]) + +b4_percent_define_default([[throws]], []) +m4_define([b4_throws], [b4_percent_define_get([[throws]])]) + +b4_percent_define_default([[init_throws]], []) +m4_define([b4_init_throws], [b4_percent_define_get([[init_throws]])]) + +b4_percent_define_default([[api.location.type]], [Location]) +m4_define([b4_location_type], [b4_percent_define_get([[api.location.type]])]) + +b4_percent_define_default([[api.position.type]], [Position]) +m4_define([b4_position_type], [b4_percent_define_get([[api.position.type]])]) + + +## ----------------- ## +## Semantic Values. ## +## ----------------- ## + + +# b4_symbol_translate(STRING) +# --------------------------- +# Used by "bison" in the array of symbol names to mark those that +# require translation. +m4_define([b4_symbol_translate], +[[i18n($1)]]) + + +# b4_trans(STRING) +# ---------------- +# Translate a string if i18n is enabled. Avoid collision with b4_translate. +m4_define([b4_trans], +[b4_has_translations_if([i18n($1)], [$1])]) + + + +# b4_symbol_value(VAL, [SYMBOL-NUM], [TYPE-TAG]) +# ---------------------------------------------- +# See README. +m4_define([b4_symbol_value], +[m4_ifval([$3], + [(($3)($1))], + [m4_ifval([$2], + [b4_symbol_if([$2], [has_type], + [((b4_symbol([$2], [type]))($1))], + [$1])], + [$1])])]) + + +# b4_lhs_value([SYMBOL-NUM], [TYPE]) +# ---------------------------------- +# See README. +m4_define([b4_lhs_value], [yyval]) + + +# b4_rhs_data(RULE-LENGTH, POS) +# ----------------------------- +# See README. +m4_define([b4_rhs_data], +[yystack.valueAt (b4_subtract($@))]) + +# b4_rhs_value(RULE-LENGTH, POS, SYMBOL-NUM, [TYPE]) +# -------------------------------------------------- +# See README. +# +# In this simple implementation, %token and %type have class names +# between the angle brackets. +m4_define([b4_rhs_value], +[b4_symbol_value([b4_rhs_data([$1], [$2])], [$3], [$4])]) + + +# b4_lhs_location() +# ----------------- +# Expansion of @$. +m4_define([b4_lhs_location], +[(yyloc)]) + + +# b4_rhs_location(RULE-LENGTH, POS) +# --------------------------------- +# Expansion of @POS, where the current rule has RULE-LENGTH symbols +# on RHS. +m4_define([b4_rhs_location], +[yystack.locationAt (b4_subtract($@))]) + + +# b4_lex_param +# b4_parse_param +# -------------- +# If defined, b4_lex_param arrives double quoted, but below we prefer +# it to be single quoted. Same for b4_parse_param. + +# TODO: should be in bison.m4 +m4_define_default([b4_lex_param], [[]]) +m4_define([b4_lex_param], b4_lex_param) +m4_define([b4_parse_param], b4_parse_param) + +# b4_lex_param_decl +# ----------------- +# Extra formal arguments of the constructor. +m4_define([b4_lex_param_decl], +[m4_ifset([b4_lex_param], + [b4_remove_comma([$1], + b4_param_decls(b4_lex_param))], + [$1])]) + +m4_define([b4_param_decls], + [m4_map([b4_param_decl], [$@])]) +m4_define([b4_param_decl], [, $1]) + +m4_define([b4_remove_comma], [m4_ifval(m4_quote($1), [$1, ], [])m4_shift2($@)]) + + + +# b4_parse_param_decl +# ------------------- +# Extra formal arguments of the constructor. +m4_define([b4_parse_param_decl], +[m4_ifset([b4_parse_param], + [b4_remove_comma([$1], + b4_param_decls(b4_parse_param))], + [$1])]) + + + +# b4_lex_param_call +# ----------------- +# Delegating the lexer parameters to the lexer constructor. +m4_define([b4_lex_param_call], + [m4_ifset([b4_lex_param], + [b4_remove_comma([$1], + b4_param_calls(b4_lex_param))], + [$1])]) +m4_define([b4_param_calls], + [m4_map([b4_param_call], [$@])]) +m4_define([b4_param_call], [, $2]) + + + +# b4_parse_param_cons +# ------------------- +# Extra initialisations of the constructor. +m4_define([b4_parse_param_cons], + [m4_ifset([b4_parse_param], + [b4_constructor_calls(b4_parse_param)])]) + +m4_define([b4_constructor_calls], + [m4_map([b4_constructor_call], [$@])]) +m4_define([b4_constructor_call], + [this.$2 = $2; + ]) + + + +# b4_parse_param_vars +# ------------------- +# Extra instance variables. +m4_define([b4_parse_param_vars], + [m4_ifset([b4_parse_param], + [ + /* User arguments. */ +b4_var_decls(b4_parse_param)])]) + +m4_define([b4_var_decls], + [m4_map_sep([b4_var_decl], [ +], [$@])]) +m4_define([b4_var_decl], + [ protected final $1;]) + + + +# b4_maybe_throws(THROWS) +# ----------------------- +# Expand to either an empty string or "throws THROWS". +m4_define([b4_maybe_throws], + [m4_ifval($1, [ throws $1])]) diff --git a/Engine/bin/bison-flex/data/skeletons/lalr1.cc b/Engine/bin/bison-flex/data/skeletons/lalr1.cc new file mode 100644 index 000000000..7cb69d3db --- /dev/null +++ b/Engine/bin/bison-flex/data/skeletons/lalr1.cc @@ -0,0 +1,1633 @@ +# C++ skeleton for Bison + +# Copyright (C) 2002-2015, 2018-2021 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +m4_include(b4_skeletonsdir/[c++.m4]) + +# api.value.type=variant is valid. +m4_define([b4_value_type_setup_variant]) + +# parse.lac +b4_percent_define_default([[parse.lac]], [[none]]) +b4_percent_define_check_values([[[[parse.lac]], [[full]], [[none]]]]) +b4_define_flag_if([lac]) +m4_define([b4_lac_flag], + [m4_if(b4_percent_define_get([[parse.lac]]), + [none], [[0]], [[1]])]) + + +# b4_tname_if(TNAME-NEEDED, TNAME-NOT-NEEDED) +# ------------------------------------------- +m4_define([b4_tname_if], +[m4_case(b4_percent_define_get([[parse.error]]), + [verbose], [$1], + [b4_token_table_if([$1], + [$2])])]) + + +# b4_integral_parser_table_declare(TABLE-NAME, CONTENT, COMMENT) +# -------------------------------------------------------------- +# Declare "parser::yy_" whose contents is CONTENT. +m4_define([b4_integral_parser_table_declare], +[m4_ifval([$3], [b4_comment([$3], [ ]) +])dnl + static const b4_int_type_for([$2]) yy$1_[[]];dnl +]) + +# b4_integral_parser_table_define(TABLE-NAME, CONTENT, COMMENT) +# ------------------------------------------------------------- +# Define "parser::yy_" whose contents is CONTENT. +m4_define([b4_integral_parser_table_define], +[ const b4_int_type_for([$2]) + b4_parser_class::yy$1_[[]] = + { + $2 + };dnl +]) + + +# b4_symbol_kind(NUM) +# ------------------- +m4_define([b4_symbol_kind], +[symbol_kind::b4_symbol_kind_base($@)]) + + +# b4_symbol_value_template(VAL, SYMBOL-NUM, [TYPE]) +# ------------------------------------------------- +# Same as b4_symbol_value, but used in a template method. It makes +# a difference when using variants. Note that b4_value_type_setup_union +# overrides b4_symbol_value, so we must override it again. +m4_copy([b4_symbol_value], [b4_symbol_value_template]) +m4_append([b4_value_type_setup_union], +[m4_copy_force([b4_symbol_value_union], [b4_symbol_value_template])]) + +# b4_lhs_value(SYMBOL-NUM, [TYPE]) +# -------------------------------- +# See README. +m4_define([b4_lhs_value], +[b4_symbol_value([yylhs.value], [$1], [$2])]) + + +# b4_lhs_location() +# ----------------- +# Expansion of @$. +m4_define([b4_lhs_location], +[yylhs.location]) + + +# b4_rhs_data(RULE-LENGTH, POS) +# ----------------------------- +# See README. +m4_define([b4_rhs_data], +[yystack_@{b4_subtract($@)@}]) + + +# b4_rhs_state(RULE-LENGTH, POS) +# ------------------------------ +# The state corresponding to the symbol #POS, where the current +# rule has RULE-LENGTH symbols on RHS. +m4_define([b4_rhs_state], +[b4_rhs_data([$1], [$2]).state]) + + +# b4_rhs_value(RULE-LENGTH, POS, SYMBOL-NUM, [TYPE]) +# -------------------------------------------------- +# See README. +m4_define([_b4_rhs_value], +[b4_symbol_value([b4_rhs_data([$1], [$2]).value], [$3], [$4])]) + +m4_define([b4_rhs_value], +[b4_percent_define_ifdef([api.value.automove], + [YY_MOVE (_b4_rhs_value($@))], + [_b4_rhs_value($@)])]) + + +# b4_rhs_location(RULE-LENGTH, POS) +# --------------------------------- +# Expansion of @POS, where the current rule has RULE-LENGTH symbols +# on RHS. +m4_define([b4_rhs_location], +[b4_rhs_data([$1], [$2]).location]) + + +# b4_symbol_action(SYMBOL-NUM, KIND) +# ---------------------------------- +# Run the action KIND (destructor or printer) for SYMBOL-NUM. +# Same as in C, but using references instead of pointers. +m4_define([b4_symbol_action], +[b4_symbol_if([$1], [has_$2], +[m4_pushdef([b4_symbol_value], m4_defn([b4_symbol_value_template]))[]dnl +b4_dollar_pushdef([yysym.value], + [$1], + [], + [yysym.location])dnl + _b4_symbol_case([$1])[]dnl +b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl + b4_symbol([$1], [$2]) +b4_syncline([@oline@], [@ofile@])dnl + break; + +m4_popdef([b4_symbol_value])[]dnl +b4_dollar_popdef[]dnl +])]) + + +# b4_yylex +# -------- +# Call yylex. +m4_define([b4_yylex], +[b4_token_ctor_if( +[b4_function_call([yylex], + [symbol_type], m4_ifdef([b4_lex_param], b4_lex_param))], +[b4_function_call([yylex], [int], + [[value_type *], [&yyla.value]][]dnl +b4_locations_if([, [[location_type *], [&yyla.location]]])dnl +m4_ifdef([b4_lex_param], [, ]b4_lex_param))])]) + + +m4_pushdef([b4_copyright_years], + [2002-2015, 2018-2021]) + +m4_define([b4_parser_class], + [b4_percent_define_get([[api.parser.class]])]) + +b4_bison_locations_if([# Backward compatibility. + m4_define([b4_location_constructors]) + m4_include(b4_skeletonsdir/[location.cc])]) +m4_include(b4_skeletonsdir/[stack.hh]) +b4_variant_if([m4_include(b4_skeletonsdir/[variant.hh])]) + + +# b4_shared_declarations(hh|cc) +# ----------------------------- +# Declaration that might either go into the header (if --header, $1 = hh) +# or in the implementation file. +m4_define([b4_shared_declarations], +[b4_percent_code_get([[requires]])[ +]b4_parse_assert_if([# include ])[ +# include // std::abort +# include +# include +# include +# include + +]b4_cxx_portability[ +]m4_ifdef([b4_location_include], + [[# include ]b4_location_include])[ +]b4_variant_if([b4_variant_includes])[ + +]b4_attribute_define[ +]b4_cast_define[ +]b4_null_define[ + +]b4_YYDEBUG_define[ + +]b4_namespace_open[ + +]b4_bison_locations_if([m4_ifndef([b4_location_file], + [b4_location_define])])[ + + /// A Bison parser. + class ]b4_parser_class[ + { + public: +]b4_public_types_declare[ +]b4_symbol_type_define[ + /// Build a parser object. + ]b4_parser_class[ (]b4_parse_param_decl[); + virtual ~]b4_parser_class[ (); + +#if 201103L <= YY_CPLUSPLUS + /// Non copyable. + ]b4_parser_class[ (const ]b4_parser_class[&) = delete; + /// Non copyable. + ]b4_parser_class[& operator= (const ]b4_parser_class[&) = delete; +#endif + + /// Parse. An alias for parse (). + /// \returns 0 iff parsing succeeded. + int operator() (); + + /// Parse. + /// \returns 0 iff parsing succeeded. + virtual int parse (); + +#if ]b4_api_PREFIX[DEBUG + /// The current debugging stream. + std::ostream& debug_stream () const YY_ATTRIBUTE_PURE; + /// Set the current debugging stream. + void set_debug_stream (std::ostream &); + + /// Type for debugging levels. + typedef int debug_level_type; + /// The current debugging level. + debug_level_type debug_level () const YY_ATTRIBUTE_PURE; + /// Set the current debugging level. + void set_debug_level (debug_level_type l); +#endif + + /// Report a syntax error.]b4_locations_if([[ + /// \param loc where the syntax error is found.]])[ + /// \param msg a description of the syntax error. + virtual void error (]b4_locations_if([[const location_type& loc, ]])[const std::string& msg); + + /// Report a syntax error. + void error (const syntax_error& err); + +]b4_parse_error_bmatch( +[custom\|detailed], +[[ /// The user-facing name of the symbol whose (internal) number is + /// YYSYMBOL. No bounds checking. + static const char *symbol_name (symbol_kind_type yysymbol);]], +[simple], +[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ + /// The user-facing name of the symbol whose (internal) number is + /// YYSYMBOL. No bounds checking. + static const char *symbol_name (symbol_kind_type yysymbol); +#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ +]], +[verbose], +[[ /// The user-facing name of the symbol whose (internal) number is + /// YYSYMBOL. No bounds checking. + static std::string symbol_name (symbol_kind_type yysymbol);]])[ + +]b4_token_constructor_define[ +]b4_parse_error_bmatch([custom\|detailed\|verbose], [[ + class context + { + public: + context (const ]b4_parser_class[& yyparser, const symbol_type& yyla); + const symbol_type& lookahead () const YY_NOEXCEPT { return yyla_; } + symbol_kind_type token () const YY_NOEXCEPT { return yyla_.kind (); }]b4_locations_if([[ + const location_type& location () const YY_NOEXCEPT { return yyla_.location; } +]])[ + /// Put in YYARG at most YYARGN of the expected tokens, and return the + /// number of tokens stored in YYARG. If YYARG is null, return the + /// number of expected tokens (guaranteed to be less than YYNTOKENS). + int expected_tokens (symbol_kind_type yyarg[], int yyargn) const; + + private: + const ]b4_parser_class[& yyparser_; + const symbol_type& yyla_; + }; +]])[ + private: +#if YY_CPLUSPLUS < 201103L + /// Non copyable. + ]b4_parser_class[ (const ]b4_parser_class[&); + /// Non copyable. + ]b4_parser_class[& operator= (const ]b4_parser_class[&); +#endif +]b4_lac_if([[ + /// Check the lookahead yytoken. + /// \returns true iff the token will be eventually shifted. + bool yy_lac_check_ (symbol_kind_type yytoken) const; + /// Establish the initial context if no initial context currently exists. + /// \returns true iff the token will be eventually shifted. + bool yy_lac_establish_ (symbol_kind_type yytoken); + /// Discard any previous initial lookahead context because of event. + /// \param event the event which caused the lookahead to be discarded. + /// Only used for debbuging output. + void yy_lac_discard_ (const char* event);]])[ + + /// Stored state numbers (used for stacks). + typedef ]b4_int_type(0, m4_eval(b4_states_number - 1))[ state_type; +]b4_parse_error_bmatch( +[custom], [[ + /// Report a syntax error + /// \param yyctx the context in which the error occurred. + void report_syntax_error (const context& yyctx) const;]], +[detailed\|verbose], [[ + /// The arguments of the error message. + int yy_syntax_error_arguments_ (const context& yyctx, + symbol_kind_type yyarg[], int yyargn) const; + + /// Generate an error message. + /// \param yyctx the context in which the error occurred. + virtual std::string yysyntax_error_ (const context& yyctx) const;]])[ + /// Compute post-reduction state. + /// \param yystate the current state + /// \param yysym the nonterminal to push on the stack + static state_type yy_lr_goto_state_ (state_type yystate, int yysym); + + /// Whether the given \c yypact_ value indicates a defaulted state. + /// \param yyvalue the value to check + static bool yy_pact_value_is_default_ (int yyvalue) YY_NOEXCEPT; + + /// Whether the given \c yytable_ value indicates a syntax error. + /// \param yyvalue the value to check + static bool yy_table_value_is_error_ (int yyvalue) YY_NOEXCEPT; + + static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_; + static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_; + + /// Convert a scanner token kind \a t to a symbol kind. + /// In theory \a t should be a token_kind_type, but character literals + /// are valid, yet not members of the token_kind_type enum. + static symbol_kind_type yytranslate_ (int t) YY_NOEXCEPT; + +]b4_parse_error_bmatch( +[simple], +[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ + /// For a symbol, its name in clear. + static const char* const yytname_[]; +#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ +]], +[verbose], +[[ /// Convert the symbol name \a n to a form suitable for a diagnostic. + static std::string yytnamerr_ (const char *yystr); + + /// For a symbol, its name in clear. + static const char* const yytname_[]; +]])[ + + // Tables. +]b4_parser_tables_declare[ + +#if ]b4_api_PREFIX[DEBUG +]b4_integral_parser_table_declare([rline], [b4_rline], + [[YYRLINE[YYN] -- Source line where rule number YYN was defined.]])[ + /// Report on the debug stream that the rule \a r is going to be reduced. + virtual void yy_reduce_print_ (int r) const; + /// Print the state stack on the debug stream. + virtual void yy_stack_print_ () const; + + /// Debugging level. + int yydebug_; + /// Debug stream. + std::ostream* yycdebug_; + + /// \brief Display a symbol kind, value and location. + /// \param yyo The output stream. + /// \param yysym The symbol. + template + void yy_print_ (std::ostream& yyo, const basic_symbol& yysym) const; +#endif + + /// \brief Reclaim the memory associated to a symbol. + /// \param yymsg Why this token is reclaimed. + /// If null, print nothing. + /// \param yysym The symbol. + template + void yy_destroy_ (const char* yymsg, basic_symbol& yysym) const; + + private: + /// Type access provider for state based symbols. + struct by_state + { + /// Default constructor. + by_state () YY_NOEXCEPT; + + /// The symbol kind as needed by the constructor. + typedef state_type kind_type; + + /// Constructor. + by_state (kind_type s) YY_NOEXCEPT; + + /// Copy constructor. + by_state (const by_state& that) YY_NOEXCEPT; + + /// Record that this symbol is empty. + void clear () YY_NOEXCEPT; + + /// Steal the symbol kind from \a that. + void move (by_state& that); + + /// The symbol kind (corresponding to \a state). + /// \a ]b4_symbol(empty, kind)[ when empty. + symbol_kind_type kind () const YY_NOEXCEPT; + + /// The state number used to denote an empty symbol. + /// We use the initial state, as it does not have a value. + enum { empty_state = 0 }; + + /// The state. + /// \a empty when empty. + state_type state; + }; + + /// "Internal" symbol: element of the stack. + struct stack_symbol_type : basic_symbol + { + /// Superclass. + typedef basic_symbol super_type; + /// Construct an empty symbol. + stack_symbol_type (); + /// Move or copy construction. + stack_symbol_type (YY_RVREF (stack_symbol_type) that); + /// Steal the contents from \a sym to build this. + stack_symbol_type (state_type s, YY_MOVE_REF (symbol_type) sym); +#if YY_CPLUSPLUS < 201103L + /// Assignment, needed by push_back by some old implementations. + /// Moves the contents of that. + stack_symbol_type& operator= (stack_symbol_type& that); + + /// Assignment, needed by push_back by other implementations. + /// Needed by some other old implementations. + stack_symbol_type& operator= (const stack_symbol_type& that); +#endif + }; + +]b4_stack_define[ + + /// Stack type. + typedef stack stack_type; + + /// The stack. + stack_type yystack_;]b4_lac_if([[ + /// The stack for LAC. + /// Logically, the yy_lac_stack's lifetime is confined to the function + /// yy_lac_check_. We just store it as a member of this class to hold + /// on to the memory and to avoid frequent reallocations. + /// Since yy_lac_check_ is const, this member must be mutable. + mutable std::vector yylac_stack_; + /// Whether an initial LAC context was established. + bool yy_lac_established_; +]])[ + + /// Push a new state on the stack. + /// \param m a debug message to display + /// if null, no trace is output. + /// \param sym the symbol + /// \warning the contents of \a s.value is stolen. + void yypush_ (const char* m, YY_MOVE_REF (stack_symbol_type) sym); + + /// Push a new look ahead token on the state on the stack. + /// \param m a debug message to display + /// if null, no trace is output. + /// \param s the state + /// \param sym the symbol (for its value and location). + /// \warning the contents of \a sym.value is stolen. + void yypush_ (const char* m, state_type s, YY_MOVE_REF (symbol_type) sym); + + /// Pop \a n symbols from the stack. + void yypop_ (int n = 1) YY_NOEXCEPT; + + /// Constants. + enum + { + yylast_ = ]b4_last[, ///< Last index in yytable_. + yynnts_ = ]b4_nterms_number[, ///< Number of nonterminal symbols. + yyfinal_ = ]b4_final_state_number[ ///< Termination state number. + }; + +]b4_parse_param_vars[ +]b4_percent_code_get([[yy_bison_internal_hook]])[ + }; + +]b4_token_ctor_if([b4_yytranslate_define([$1])[ +]b4_public_types_define([$1])])[ +]b4_namespace_close[ + +]b4_percent_code_get([[provides]])[ +]])[ + + +## -------------- ## +## Output files. ## +## -------------- ## + +# ------------- # +# Header file. # +# ------------- # + +]b4_header_if([[ +]b4_output_begin([b4_spec_header_file])[ +]b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++])[ + +/** + ** \file ]b4_spec_mapped_header_file[ + ** Define the ]b4_namespace_ref[::parser class. + */ + +// C++ LALR(1) parser skeleton written by Akim Demaille. + +]b4_disclaimer[ +]b4_cpp_guard_open([b4_spec_mapped_header_file])[ +]b4_shared_declarations(hh)[ +]b4_cpp_guard_close([b4_spec_mapped_header_file])[ +]b4_output_end[ +]])[ + + +# --------------------- # +# Implementation file. # +# --------------------- # + +]b4_output_begin([b4_parser_file_name])[ +]b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++])[ +]b4_disclaimer[ +]b4_percent_code_get([[top]])[]dnl +m4_if(b4_prefix, [yy], [], +[ +// Take the name prefix into account. +[#]define yylex b4_prefix[]lex])[ + +]b4_user_pre_prologue[ + +]b4_header_if([[#include "@basename(]b4_spec_header_file[@)"]], + [b4_shared_declarations([cc])])[ + +]b4_user_post_prologue[ +]b4_percent_code_get[ + +#ifndef YY_ +# if defined YYENABLE_NLS && YYENABLE_NLS +# if ENABLE_NLS +# include // FIXME: INFRINGES ON USER NAME SPACE. +# define YY_(msgid) dgettext ("bison-runtime", msgid) +# endif +# endif +# ifndef YY_ +# define YY_(msgid) msgid +# endif +#endif +]b4_has_translations_if([ +#ifndef N_ +# define N_(Msgid) Msgid +#endif +])[ + +// Whether we are compiled with exception support. +#ifndef YY_EXCEPTIONS +# if defined __GNUC__ && !defined __EXCEPTIONS +# define YY_EXCEPTIONS 0 +# else +# define YY_EXCEPTIONS 1 +# endif +#endif + +]b4_locations_if([dnl +[#define YYRHSLOC(Rhs, K) ((Rhs)[K].location) +]b4_yylloc_default_define])[ + +// Enable debugging if requested. +#if ]b4_api_PREFIX[DEBUG + +// A pseudo ostream that takes yydebug_ into account. +# define YYCDEBUG if (yydebug_) (*yycdebug_) + +# define YY_SYMBOL_PRINT(Title, Symbol) \ + do { \ + if (yydebug_) \ + { \ + *yycdebug_ << Title << ' '; \ + yy_print_ (*yycdebug_, Symbol); \ + *yycdebug_ << '\n'; \ + } \ + } while (false) + +# define YY_REDUCE_PRINT(Rule) \ + do { \ + if (yydebug_) \ + yy_reduce_print_ (Rule); \ + } while (false) + +# define YY_STACK_PRINT() \ + do { \ + if (yydebug_) \ + yy_stack_print_ (); \ + } while (false) + +#else // !]b4_api_PREFIX[DEBUG + +# define YYCDEBUG if (false) std::cerr +# define YY_SYMBOL_PRINT(Title, Symbol) YY_USE (Symbol) +# define YY_REDUCE_PRINT(Rule) static_cast (0) +# define YY_STACK_PRINT() static_cast (0) + +#endif // !]b4_api_PREFIX[DEBUG + +#define yyerrok (yyerrstatus_ = 0) +#define yyclearin (yyla.clear ()) + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab +#define YYRECOVERING() (!!yyerrstatus_) + +]b4_namespace_open[ + /// Build a parser object. + ]b4_parser_class::b4_parser_class[ (]b4_parse_param_decl[) +#if ]b4_api_PREFIX[DEBUG + : yydebug_ (false), + yycdebug_ (&std::cerr)]b4_lac_if([,], [m4_ifset([b4_parse_param], [,])])[ +#else +]b4_lac_if([ :], [m4_ifset([b4_parse_param], [ :])])[ +#endif]b4_lac_if([[ + yy_lac_established_ (false)]m4_ifset([b4_parse_param], [,])])[]b4_parse_param_cons[ + {} + + ]b4_parser_class::~b4_parser_class[ () + {} + + ]b4_parser_class[::syntax_error::~syntax_error () YY_NOEXCEPT YY_NOTHROW + {} + + /*---------. + | symbol. | + `---------*/ + +]b4_token_ctor_if([], [b4_public_types_define([cc])])[ + + // by_state. + ]b4_parser_class[::by_state::by_state () YY_NOEXCEPT + : state (empty_state) + {} + + ]b4_parser_class[::by_state::by_state (const by_state& that) YY_NOEXCEPT + : state (that.state) + {} + + void + ]b4_parser_class[::by_state::clear () YY_NOEXCEPT + { + state = empty_state; + } + + void + ]b4_parser_class[::by_state::move (by_state& that) + { + state = that.state; + that.clear (); + } + + ]b4_parser_class[::by_state::by_state (state_type s) YY_NOEXCEPT + : state (s) + {} + + ]b4_parser_class[::symbol_kind_type + ]b4_parser_class[::by_state::kind () const YY_NOEXCEPT + { + if (state == empty_state) + return ]b4_symbol(empty, kind)[; + else + return YY_CAST (symbol_kind_type, yystos_[+state]); + } + + ]b4_parser_class[::stack_symbol_type::stack_symbol_type () + {} + + ]b4_parser_class[::stack_symbol_type::stack_symbol_type (YY_RVREF (stack_symbol_type) that) + : super_type (YY_MOVE (that.state)]b4_variant_if([], [, YY_MOVE (that.value)])b4_locations_if([, YY_MOVE (that.location)])[) + {]b4_variant_if([ + b4_symbol_variant([that.kind ()], + [value], [YY_MOVE_OR_COPY], [YY_MOVE (that.value)])])[ +#if 201103L <= YY_CPLUSPLUS + // that is emptied. + that.state = empty_state; +#endif + } + + ]b4_parser_class[::stack_symbol_type::stack_symbol_type (state_type s, YY_MOVE_REF (symbol_type) that) + : super_type (s]b4_variant_if([], [, YY_MOVE (that.value)])[]b4_locations_if([, YY_MOVE (that.location)])[) + {]b4_variant_if([ + b4_symbol_variant([that.kind ()], + [value], [move], [YY_MOVE (that.value)])])[ + // that is emptied. + that.kind_ = ]b4_symbol(empty, kind)[; + } + +#if YY_CPLUSPLUS < 201103L + ]b4_parser_class[::stack_symbol_type& + ]b4_parser_class[::stack_symbol_type::operator= (const stack_symbol_type& that) + { + state = that.state; + ]b4_variant_if([b4_symbol_variant([that.kind ()], + [value], [copy], [that.value])], + [[value = that.value;]])[]b4_locations_if([ + location = that.location;])[ + return *this; + } + + ]b4_parser_class[::stack_symbol_type& + ]b4_parser_class[::stack_symbol_type::operator= (stack_symbol_type& that) + { + state = that.state; + ]b4_variant_if([b4_symbol_variant([that.kind ()], + [value], [move], [that.value])], + [[value = that.value;]])[]b4_locations_if([ + location = that.location;])[ + // that is emptied. + that.state = empty_state; + return *this; + } +#endif + + template + void + ]b4_parser_class[::yy_destroy_ (const char* yymsg, basic_symbol& yysym) const + { + if (yymsg) + YY_SYMBOL_PRINT (yymsg, yysym);]b4_variant_if([], [ + + // User destructor. + b4_symbol_actions([destructor], [yysym.kind ()])])[ + } + +#if ]b4_api_PREFIX[DEBUG + template + void + ]b4_parser_class[::yy_print_ (std::ostream& yyo, const basic_symbol& yysym) const + { + std::ostream& yyoutput = yyo; + YY_USE (yyoutput); + if (yysym.empty ()) + yyo << "empty symbol"; + else + { + symbol_kind_type yykind = yysym.kind (); + yyo << (yykind < YYNTOKENS ? "token" : "nterm") + << ' ' << yysym.name () << " ("]b4_locations_if([ + << yysym.location << ": "])[; + ]b4_symbol_actions([printer])[ + yyo << ')'; + } + } +#endif + + void + ]b4_parser_class[::yypush_ (const char* m, YY_MOVE_REF (stack_symbol_type) sym) + { + if (m) + YY_SYMBOL_PRINT (m, sym); + yystack_.push (YY_MOVE (sym)); + } + + void + ]b4_parser_class[::yypush_ (const char* m, state_type s, YY_MOVE_REF (symbol_type) sym) + { +#if 201103L <= YY_CPLUSPLUS + yypush_ (m, stack_symbol_type (s, std::move (sym))); +#else + stack_symbol_type ss (s, sym); + yypush_ (m, ss); +#endif + } + + void + ]b4_parser_class[::yypop_ (int n) YY_NOEXCEPT + { + yystack_.pop (n); + } + +#if ]b4_api_PREFIX[DEBUG + std::ostream& + ]b4_parser_class[::debug_stream () const + { + return *yycdebug_; + } + + void + ]b4_parser_class[::set_debug_stream (std::ostream& o) + { + yycdebug_ = &o; + } + + + ]b4_parser_class[::debug_level_type + ]b4_parser_class[::debug_level () const + { + return yydebug_; + } + + void + ]b4_parser_class[::set_debug_level (debug_level_type l) + { + yydebug_ = l; + } +#endif // ]b4_api_PREFIX[DEBUG + + ]b4_parser_class[::state_type + ]b4_parser_class[::yy_lr_goto_state_ (state_type yystate, int yysym) + { + int yyr = yypgoto_[yysym - YYNTOKENS] + yystate; + if (0 <= yyr && yyr <= yylast_ && yycheck_[yyr] == yystate) + return yytable_[yyr]; + else + return yydefgoto_[yysym - YYNTOKENS]; + } + + bool + ]b4_parser_class[::yy_pact_value_is_default_ (int yyvalue) YY_NOEXCEPT + { + return yyvalue == yypact_ninf_; + } + + bool + ]b4_parser_class[::yy_table_value_is_error_ (int yyvalue) YY_NOEXCEPT + { + return yyvalue == yytable_ninf_; + } + + int + ]b4_parser_class[::operator() () + { + return parse (); + } + + int + ]b4_parser_class[::parse () + { + int yyn; + /// Length of the RHS of the rule being reduced. + int yylen = 0; + + // Error handling. + int yynerrs_ = 0; + int yyerrstatus_ = 0; + + /// The lookahead symbol. + symbol_type yyla;]b4_locations_if([[ + + /// The locations where the error started and ended. + stack_symbol_type yyerror_range[3];]])[ + + /// The return value of parse (). + int yyresult;]b4_lac_if([[ + + // Discard the LAC context in case there still is one left from a + // previous invocation. + yy_lac_discard_ ("init");]])[ + +#if YY_EXCEPTIONS + try +#endif // YY_EXCEPTIONS + { + YYCDEBUG << "Starting parse\n"; + +]m4_ifdef([b4_initial_action], [ +b4_dollar_pushdef([yyla.value], [], [], [yyla.location])dnl + b4_user_initial_action +b4_dollar_popdef])[]dnl + + [ /* Initialize the stack. The initial state will be set in + yynewstate, since the latter expects the semantical and the + location values to have been already stored, initialize these + stacks with a primary value. */ + yystack_.clear (); + yypush_ (YY_NULLPTR, 0, YY_MOVE (yyla)); + + /*-----------------------------------------------. + | yynewstate -- push a new symbol on the stack. | + `-----------------------------------------------*/ + yynewstate: + YYCDEBUG << "Entering state " << int (yystack_[0].state) << '\n'; + YY_STACK_PRINT (); + + // Accept? + if (yystack_[0].state == yyfinal_) + YYACCEPT; + + goto yybackup; + + + /*-----------. + | yybackup. | + `-----------*/ + yybackup: + // Try to take a decision without lookahead. + yyn = yypact_[+yystack_[0].state]; + if (yy_pact_value_is_default_ (yyn)) + goto yydefault; + + // Read a lookahead token. + if (yyla.empty ()) + { + YYCDEBUG << "Reading a token\n"; +#if YY_EXCEPTIONS + try +#endif // YY_EXCEPTIONS + {]b4_token_ctor_if([[ + symbol_type yylookahead (]b4_yylex[); + yyla.move (yylookahead);]], [[ + yyla.kind_ = yytranslate_ (]b4_yylex[);]])[ + } +#if YY_EXCEPTIONS + catch (const syntax_error& yyexc) + { + YYCDEBUG << "Caught exception: " << yyexc.what() << '\n'; + error (yyexc); + goto yyerrlab1; + } +#endif // YY_EXCEPTIONS + } + YY_SYMBOL_PRINT ("Next token is", yyla); + + if (yyla.kind () == ]b4_symbol(error, kind)[) + { + // The scanner already issued an error message, process directly + // to error recovery. But do not keep the error token as + // lookahead, it is too special and may lead us to an endless + // loop in error recovery. */ + yyla.kind_ = ]b4_symbol(undef, kind)[; + goto yyerrlab1; + } + + /* If the proper action on seeing token YYLA.TYPE is to reduce or + to detect an error, take that action. */ + yyn += yyla.kind (); + if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.kind ()) + {]b4_lac_if([[ + if (!yy_lac_establish_ (yyla.kind ())) + goto yyerrlab;]])[ + goto yydefault; + } + + // Reduce or error. + yyn = yytable_[yyn]; + if (yyn <= 0) + { + if (yy_table_value_is_error_ (yyn)) + goto yyerrlab;]b4_lac_if([[ + if (!yy_lac_establish_ (yyla.kind ())) + goto yyerrlab; +]])[ + yyn = -yyn; + goto yyreduce; + } + + // Count tokens shifted since error; after three, turn off error status. + if (yyerrstatus_) + --yyerrstatus_; + + // Shift the lookahead token. + yypush_ ("Shifting", state_type (yyn), YY_MOVE (yyla));]b4_lac_if([[ + yy_lac_discard_ ("shift");]])[ + goto yynewstate; + + + /*-----------------------------------------------------------. + | yydefault -- do the default action for the current state. | + `-----------------------------------------------------------*/ + yydefault: + yyn = yydefact_[+yystack_[0].state]; + if (yyn == 0) + goto yyerrlab; + goto yyreduce; + + + /*-----------------------------. + | yyreduce -- do a reduction. | + `-----------------------------*/ + yyreduce: + yylen = yyr2_[yyn]; + { + stack_symbol_type yylhs; + yylhs.state = yy_lr_goto_state_ (yystack_[yylen].state, yyr1_[yyn]);]b4_variant_if([[ + /* Variants are always initialized to an empty instance of the + correct type. The default '$$ = $1' action is NOT applied + when using variants. */ + ]b4_symbol_variant([[yyr1_@{yyn@}]], [yylhs.value], [emplace])], [[ + /* If YYLEN is nonzero, implement the default value of the + action: '$$ = $1'. Otherwise, use the top of the stack. + + Otherwise, the following line sets YYLHS.VALUE to garbage. + This behavior is undocumented and Bison users should not rely + upon it. */ + if (yylen) + yylhs.value = yystack_@{yylen - 1@}.value; + else + yylhs.value = yystack_@{0@}.value;]])[ +]b4_locations_if([dnl +[ + // Default location. + { + stack_type::slice range (yystack_, yylen); + YYLLOC_DEFAULT (yylhs.location, range, yylen); + yyerror_range[1].location = yylhs.location; + }]])[ + + // Perform the reduction. + YY_REDUCE_PRINT (yyn); +#if YY_EXCEPTIONS + try +#endif // YY_EXCEPTIONS + { + switch (yyn) + { +]b4_user_actions[ + default: + break; + } + } +#if YY_EXCEPTIONS + catch (const syntax_error& yyexc) + { + YYCDEBUG << "Caught exception: " << yyexc.what() << '\n'; + error (yyexc); + YYERROR; + } +#endif // YY_EXCEPTIONS + YY_SYMBOL_PRINT ("-> $$ =", yylhs); + yypop_ (yylen); + yylen = 0; + + // Shift the result of the reduction. + yypush_ (YY_NULLPTR, YY_MOVE (yylhs)); + } + goto yynewstate; + + + /*--------------------------------------. + | yyerrlab -- here on detecting error. | + `--------------------------------------*/ + yyerrlab: + // If not already recovering from an error, report this error. + if (!yyerrstatus_) + { + ++yynerrs_;]b4_parse_error_case( + [simple], [[ + std::string msg = YY_("syntax error"); + error (]b4_join(b4_locations_if([yyla.location]), [[YY_MOVE (msg)]])[);]], + [custom], [[ + context yyctx (*this, yyla); + report_syntax_error (yyctx);]], + [[ + context yyctx (*this, yyla); + std::string msg = yysyntax_error_ (yyctx); + error (]b4_join(b4_locations_if([yyla.location]), [[YY_MOVE (msg)]])[);]])[ + } + +]b4_locations_if([[ + yyerror_range[1].location = yyla.location;]])[ + if (yyerrstatus_ == 3) + { + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ + + // Return failure if at end of input. + if (yyla.kind () == ]b4_symbol(eof, kind)[) + YYABORT; + else if (!yyla.empty ()) + { + yy_destroy_ ("Error: discarding", yyla); + yyla.clear (); + } + } + + // Else will try to reuse lookahead token after shifting the error token. + goto yyerrlab1; + + + /*---------------------------------------------------. + | yyerrorlab -- error raised explicitly by YYERROR. | + `---------------------------------------------------*/ + yyerrorlab: + /* Pacify compilers when the user code never invokes YYERROR and + the label yyerrorlab therefore never appears in user code. */ + if (false) + YYERROR; + + /* Do not reclaim the symbols of the rule whose action triggered + this YYERROR. */ + yypop_ (yylen); + yylen = 0; + YY_STACK_PRINT (); + goto yyerrlab1; + + + /*-------------------------------------------------------------. + | yyerrlab1 -- common code for both syntax error and YYERROR. | + `-------------------------------------------------------------*/ + yyerrlab1: + yyerrstatus_ = 3; // Each real token shifted decrements this. + // Pop stack until we find a state that shifts the error token. + for (;;) + { + yyn = yypact_[+yystack_[0].state]; + if (!yy_pact_value_is_default_ (yyn)) + { + yyn += ]b4_symbol(error, kind)[; + if (0 <= yyn && yyn <= yylast_ + && yycheck_[yyn] == ]b4_symbol(error, kind)[) + { + yyn = yytable_[yyn]; + if (0 < yyn) + break; + } + } + + // Pop the current state because it cannot handle the error token. + if (yystack_.size () == 1) + YYABORT; +]b4_locations_if([[ + yyerror_range[1].location = yystack_[0].location;]])[ + yy_destroy_ ("Error: popping", yystack_[0]); + yypop_ (); + YY_STACK_PRINT (); + } + { + stack_symbol_type error_token; +]b4_locations_if([[ + yyerror_range[2].location = yyla.location; + YYLLOC_DEFAULT (error_token.location, yyerror_range, 2);]])[ + + // Shift the error token.]b4_lac_if([[ + yy_lac_discard_ ("error recovery");]])[ + error_token.state = state_type (yyn); + yypush_ ("Shifting", YY_MOVE (error_token)); + } + goto yynewstate; + + + /*-------------------------------------. + | yyacceptlab -- YYACCEPT comes here. | + `-------------------------------------*/ + yyacceptlab: + yyresult = 0; + goto yyreturn; + + + /*-----------------------------------. + | yyabortlab -- YYABORT comes here. | + `-----------------------------------*/ + yyabortlab: + yyresult = 1; + goto yyreturn; + + + /*-----------------------------------------------------. + | yyreturn -- parsing is finished, return the result. | + `-----------------------------------------------------*/ + yyreturn: + if (!yyla.empty ()) + yy_destroy_ ("Cleanup: discarding lookahead", yyla); + + /* Do not reclaim the symbols of the rule whose action triggered + this YYABORT or YYACCEPT. */ + yypop_ (yylen); + YY_STACK_PRINT (); + while (1 < yystack_.size ()) + { + yy_destroy_ ("Cleanup: popping", yystack_[0]); + yypop_ (); + } + + return yyresult; + } +#if YY_EXCEPTIONS + catch (...) + { + YYCDEBUG << "Exception caught: cleaning lookahead and stack\n"; + // Do not try to display the values of the reclaimed symbols, + // as their printers might throw an exception. + if (!yyla.empty ()) + yy_destroy_ (YY_NULLPTR, yyla); + + while (1 < yystack_.size ()) + { + yy_destroy_ (YY_NULLPTR, yystack_[0]); + yypop_ (); + } + throw; + } +#endif // YY_EXCEPTIONS + } + + void + ]b4_parser_class[::error (const syntax_error& yyexc) + { + error (]b4_join(b4_locations_if([yyexc.location]), + [[yyexc.what ()]])[); + } + +]b4_parse_error_bmatch([custom\|detailed], +[[ const char * + ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol) + { + static const char *const yy_sname[] = + { + ]b4_symbol_names[ + };]b4_has_translations_if([[ + /* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is + internationalizable. */ + static ]b4_int_type_for([b4_translatable])[ yytranslatable[] = + { + ]b4_translatable[ + }; + return (yysymbol < YYNTOKENS && yytranslatable[yysymbol] + ? _(yy_sname[yysymbol]) + : yy_sname[yysymbol]);]], [[ + return yy_sname[yysymbol];]])[ + } +]], +[simple], +[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ + const char * + ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol) + { + return yytname_[yysymbol]; + } +#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ +]], +[verbose], +[[ /* Return YYSTR after stripping away unnecessary quotes and + backslashes, so that it's suitable for yyerror. The heuristic is + that double-quoting is unnecessary unless the string contains an + apostrophe, a comma, or backslash (other than backslash-backslash). + YYSTR is taken from yytname. */ + std::string + ]b4_parser_class[::yytnamerr_ (const char *yystr) + { + if (*yystr == '"') + { + std::string yyr; + char const *yyp = yystr; + + for (;;) + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + else + goto append; + + append: + default: + yyr += *yyp; + break; + + case '"': + return yyr; + } + do_not_strip_quotes: ; + } + + return yystr; + } + + std::string + ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol) + { + return yytnamerr_ (yytname_[yysymbol]); + } +]])[ + +]b4_parse_error_bmatch([custom\|detailed\|verbose], [[ + // ]b4_parser_class[::context. + ]b4_parser_class[::context::context (const ]b4_parser_class[& yyparser, const symbol_type& yyla) + : yyparser_ (yyparser) + , yyla_ (yyla) + {} + + int + ]b4_parser_class[::context::expected_tokens (symbol_kind_type yyarg[], int yyargn) const + { + // Actual number of expected tokens + int yycount = 0; +]b4_lac_if([[ +#if ]b4_api_PREFIX[DEBUG + // Execute LAC once. We don't care if it is successful, we + // only do it for the sake of debugging output. + if (!yyparser_.yy_lac_established_) + yyparser_.yy_lac_check_ (yyla_.kind ()); +#endif + + for (int yyx = 0; yyx < YYNTOKENS; ++yyx) + { + symbol_kind_type yysym = YY_CAST (symbol_kind_type, yyx); + if (yysym != ]b4_symbol(error, kind)[ + && yysym != ]b4_symbol(undef, kind)[ + && yyparser_.yy_lac_check_ (yysym)) + { + if (!yyarg) + ++yycount; + else if (yycount == yyargn) + return 0; + else + yyarg[yycount++] = yysym; + } + }]], [[ + const int yyn = yypact_[+yyparser_.yystack_[0].state]; + if (!yy_pact_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. */ + const int yyxbegin = yyn < 0 ? -yyn : 0; + // Stay within bounds of both yycheck and yytname. + const int yychecklim = yylast_ - yyn + 1; + const int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + for (int yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck_[yyx + yyn] == yyx && yyx != ]b4_symbol(error, kind)[ + && !yy_table_value_is_error_ (yytable_[yyx + yyn])) + { + if (!yyarg) + ++yycount; + else if (yycount == yyargn) + return 0; + else + yyarg[yycount++] = YY_CAST (symbol_kind_type, yyx); + } + } +]])[ + if (yyarg && yycount == 0 && 0 < yyargn) + yyarg[0] = ]b4_symbol(empty, kind)[; + return yycount; + } + +]])[ + +]b4_lac_if([[ + bool + ]b4_parser_class[::yy_lac_check_ (symbol_kind_type yytoken) const + { + // Logically, the yylac_stack's lifetime is confined to this function. + // Clear it, to get rid of potential left-overs from previous call. + yylac_stack_.clear (); + // Reduce until we encounter a shift and thereby accept the token. +#if ]b4_api_PREFIX[DEBUG + YYCDEBUG << "LAC: checking lookahead " << symbol_name (yytoken) << ':'; +#endif + std::ptrdiff_t lac_top = 0; + while (true) + { + state_type top_state = (yylac_stack_.empty () + ? yystack_[lac_top].state + : yylac_stack_.back ()); + int yyrule = yypact_[+top_state]; + if (yy_pact_value_is_default_ (yyrule) + || (yyrule += yytoken) < 0 || yylast_ < yyrule + || yycheck_[yyrule] != yytoken) + { + // Use the default action. + yyrule = yydefact_[+top_state]; + if (yyrule == 0) + { + YYCDEBUG << " Err\n"; + return false; + } + } + else + { + // Use the action from yytable. + yyrule = yytable_[yyrule]; + if (yy_table_value_is_error_ (yyrule)) + { + YYCDEBUG << " Err\n"; + return false; + } + if (0 < yyrule) + { + YYCDEBUG << " S" << yyrule << '\n'; + return true; + } + yyrule = -yyrule; + } + // By now we know we have to simulate a reduce. + YYCDEBUG << " R" << yyrule - 1; + // Pop the corresponding number of values from the stack. + { + std::ptrdiff_t yylen = yyr2_[yyrule]; + // First pop from the LAC stack as many tokens as possible. + std::ptrdiff_t lac_size = std::ptrdiff_t (yylac_stack_.size ()); + if (yylen < lac_size) + { + yylac_stack_.resize (std::size_t (lac_size - yylen)); + yylen = 0; + } + else if (lac_size) + { + yylac_stack_.clear (); + yylen -= lac_size; + } + // Only afterwards look at the main stack. + // We simulate popping elements by incrementing lac_top. + lac_top += yylen; + } + // Keep top_state in sync with the updated stack. + top_state = (yylac_stack_.empty () + ? yystack_[lac_top].state + : yylac_stack_.back ()); + // Push the resulting state of the reduction. + state_type state = yy_lr_goto_state_ (top_state, yyr1_[yyrule]); + YYCDEBUG << " G" << int (state); + yylac_stack_.push_back (state); + } + } + + // Establish the initial context if no initial context currently exists. + bool + ]b4_parser_class[::yy_lac_establish_ (symbol_kind_type yytoken) + { + /* Establish the initial context for the current lookahead if no initial + context is currently established. + + We define a context as a snapshot of the parser stacks. We define + the initial context for a lookahead as the context in which the + parser initially examines that lookahead in order to select a + syntactic action. Thus, if the lookahead eventually proves + syntactically unacceptable (possibly in a later context reached via a + series of reductions), the initial context can be used to determine + the exact set of tokens that would be syntactically acceptable in the + lookahead's place. Moreover, it is the context after which any + further semantic actions would be erroneous because they would be + determined by a syntactically unacceptable token. + + yy_lac_establish_ should be invoked when a reduction is about to be + performed in an inconsistent state (which, for the purposes of LAC, + includes consistent states that don't know they're consistent because + their default reductions have been disabled). + + For parse.lac=full, the implementation of yy_lac_establish_ is as + follows. If no initial context is currently established for the + current lookahead, then check if that lookahead can eventually be + shifted if syntactic actions continue from the current context. */ + if (yy_lac_established_) + return true; + else + { +#if ]b4_api_PREFIX[DEBUG + YYCDEBUG << "LAC: initial context established for " + << symbol_name (yytoken) << '\n'; +#endif + yy_lac_established_ = true; + return yy_lac_check_ (yytoken); + } + } + + // Discard any previous initial lookahead context. + void + ]b4_parser_class[::yy_lac_discard_ (const char* event) + { + /* Discard any previous initial lookahead context because of Event, + which may be a lookahead change or an invalidation of the currently + established initial context for the current lookahead. + + The most common example of a lookahead change is a shift. An example + of both cases is syntax error recovery. That is, a syntax error + occurs when the lookahead is syntactically erroneous for the + currently established initial context, so error recovery manipulates + the parser stacks to try to find a new initial context in which the + current lookahead is syntactically acceptable. If it fails to find + such a context, it discards the lookahead. */ + if (yy_lac_established_) + { + YYCDEBUG << "LAC: initial context discarded due to " + << event << '\n'; + yy_lac_established_ = false; + } + }]])[ + +]b4_parse_error_bmatch([detailed\|verbose], [[ + int + ]b4_parser_class[::yy_syntax_error_arguments_ (const context& yyctx, + symbol_kind_type yyarg[], int yyargn) const + { + /* There are many possibilities here to consider: + - 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 yyla) 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 + yyla. (However, yyla is currently not documented for users.)]b4_lac_if([[ + In the first two cases, it might appear that the current syntax + error should have been detected in the previous state when + yy_lac_check was invoked. However, at that time, there might + have been a different syntax error that discarded a different + initial context during error recovery, leaving behind the + current lookahead.]], [[ + - 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 (!yyctx.lookahead ().empty ()) + { + if (yyarg) + yyarg[0] = yyctx.token (); + int yyn = yyctx.expected_tokens (yyarg ? yyarg + 1 : yyarg, yyargn - 1); + return yyn + 1; + } + return 0; + } + + // Generate an error message. + std::string + ]b4_parser_class[::yysyntax_error_ (const context& yyctx) const + { + // Its maximum. + enum { YYARGS_MAX = 5 }; + // Arguments of yyformat. + symbol_kind_type yyarg[YYARGS_MAX]; + int yycount = yy_syntax_error_arguments_ (yyctx, yyarg, YYARGS_MAX); + + char const* yyformat = YY_NULLPTR; + switch (yycount) + { +#define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + default: // Avoid compiler warnings. + 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_ + } + + std::string yyres; + // Argument number. + std::ptrdiff_t yyi = 0; + for (char const* yyp = yyformat; *yyp; ++yyp) + if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount) + { + yyres += symbol_name (yyarg[yyi++]); + ++yyp; + } + else + yyres += *yyp; + return yyres; + }]])[ + + + const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) b4_parser_class::yypact_ninf_ = b4_pact_ninf[; + + const ]b4_int_type(b4_table_ninf, b4_table_ninf) b4_parser_class::yytable_ninf_ = b4_table_ninf[; + +]b4_parser_tables_define[ + +]b4_parse_error_bmatch([simple\|verbose], +[[#if ]b4_api_PREFIX[DEBUG]b4_tname_if([[ || 1]])[ + // YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + // First, the terminals, then, starting at \a YYNTOKENS, nonterminals. + const char* + const ]b4_parser_class[::yytname_[] = + { + ]b4_tname[ + }; +#endif +]])[ + +#if ]b4_api_PREFIX[DEBUG][ +]b4_integral_parser_table_define([rline], [b4_rline])[ + + void + ]b4_parser_class[::yy_stack_print_ () const + { + *yycdebug_ << "Stack now"; + for (stack_type::const_iterator + i = yystack_.begin (), + i_end = yystack_.end (); + i != i_end; ++i) + *yycdebug_ << ' ' << int (i->state); + *yycdebug_ << '\n'; + } + + void + ]b4_parser_class[::yy_reduce_print_ (int yyrule) const + { + int yylno = yyrline_[yyrule]; + int yynrhs = yyr2_[yyrule]; + // Print the symbols being reduced, and their result. + *yycdebug_ << "Reducing stack by rule " << yyrule - 1 + << " (line " << yylno << "):\n"; + // The symbols being reduced. + for (int yyi = 0; yyi < yynrhs; yyi++) + YY_SYMBOL_PRINT (" $" << yyi + 1 << " =", + ]b4_rhs_data(yynrhs, yyi + 1)[); + } +#endif // ]b4_api_PREFIX[DEBUG + +]b4_token_ctor_if([], [b4_yytranslate_define([cc])])[ +]b4_namespace_close[ +]b4_epilogue[]dnl +b4_output_end + + +m4_popdef([b4_copyright_years])dnl diff --git a/Engine/bin/bison-flex/data/skeletons/lalr1.d b/Engine/bin/bison-flex/data/skeletons/lalr1.d new file mode 100644 index 000000000..973037722 --- /dev/null +++ b/Engine/bin/bison-flex/data/skeletons/lalr1.d @@ -0,0 +1,1326 @@ +# D skeleton for Bison -*- autoconf -*- + +# Copyright (C) 2007-2012, 2019-2021 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +m4_include(b4_skeletonsdir/[d.m4]) + +b4_header_if([b4_complain([%header/%defines does not make sense in D])]) + +# parse.lac +b4_percent_define_default([[parse.lac]], [[none]]) +b4_percent_define_check_values([[[[parse.lac]], [[full]], [[none]]]]) +b4_define_flag_if([lac]) +m4_define([b4_lac_flag], + [m4_if(b4_percent_define_get([[parse.lac]]), + [none], [[0]], [[1]])]) + + +## --------------- ## +## api.push-pull. ## +## --------------- ## + +b4_percent_define_default([[api.push-pull]], [[pull]]) +b4_percent_define_check_values([[[[api.push-pull]], + [[pull]], [[push]], [[both]]]]) + +# Define m4 conditional macros that encode the value +# of the api.push-pull flag. +b4_define_flag_if([pull]) m4_define([b4_pull_flag], [[1]]) +b4_define_flag_if([push]) m4_define([b4_push_flag], [[1]]) +m4_case(b4_percent_define_get([[api.push-pull]]), + [pull], [m4_define([b4_push_flag], [[0]])], + [push], [m4_define([b4_pull_flag], [[0]])]) + +# Define a macro to be true when api.push-pull has the value "both". +m4_define([b4_both_if],[b4_push_if([b4_pull_if([$1],[$2])],[$2])]) + +# Handle BISON_USE_PUSH_FOR_PULL for the test suite. So that push parsing +# tests function as written, do not let BISON_USE_PUSH_FOR_PULL modify the +# behavior of Bison at all when push parsing is already requested. +b4_define_flag_if([use_push_for_pull]) +b4_use_push_for_pull_if([ + b4_push_if([m4_define([b4_use_push_for_pull_flag], [[0]])], + [m4_define([b4_push_flag], [[1]])])]) + + +# Define a macro to encapsulate the parse state variables. This +# allows them to be defined either in parse() when doing pull parsing, +# or as class instance variable when doing push parsing. +b4_output_begin([b4_parser_file_name]) +b4_copyright([Skeleton implementation for Bison LALR(1) parsers in D], + [2007-2012, 2019-2021])[ +]b4_disclaimer[ +]b4_percent_define_ifdef([package], [module b4_percent_define_get([package]); +])[ +version(D_Version2) { +} else { + static assert(false, "need compiler for D Version 2"); +} + +]b4_user_pre_prologue[ +]b4_user_post_prologue[ +]b4_percent_code_get([[imports]])[ +import std.format; +import std.conv; + +/** + * Handle error message internationalisation. + */ +static if (!is(typeof(YY_))) { + version(YYENABLE_NLS) + { + version(ENABLE_NLS) + { + extern(C) char* dgettext(const char*, const char*); + string YY_(const char* s) + { + return to!string(dgettext("bison-runtime", s)); + } + } + } + static if (!is(typeof(YY_))) + { + pragma(inline, true) + string YY_(string msg) { return msg; } + } +} + +/** + * A Bison parser, automatically generated from ]m4_bpatsubst(b4_file_name, [^"\(.*\)"$], [\1])[. + * + * @@author LALR (1) parser skeleton written by Paolo Bonzini. + * Port to D language was done by Oliver Mangold. + */ + +/** + * Communication interface between the scanner and the Bison-generated + * parser ]b4_parser_class[. + */ +public interface Lexer +{ + /** + * Entry point for the scanner. Returns the token identifier corresponding + * to the next token and prepares to return the semantic value + * ]b4_locations_if([and beginning/ending positions ])[of the token. + * @@return the token identifier corresponding to the next token. */ + Symbol yylex (); + + /** + * Entry point for error reporting. Emits an error + * ]b4_locations_if([referring to the given location ])[in a user-defined way. + *]b4_locations_if([[ + * @@param loc The location of the element to which the + * error message is related]])[ + * @@param s The string for the error message. */ + void yyerror (]b4_locations_if([[const Location loc, ]])[string s); +]b4_parse_error_bmatch([custom], [[ + /** + * Build and emit a "syntax error" message in a user-defined way. + * + * @@param ctx The context of the error. + */ + void reportSyntaxError(]b4_parser_class[.Context ctx); +]])[ +} + +]b4_public_types_declare[ + +]b4_locations_if([b4_position_type_if([[ +static assert(__traits(compiles, + (new Position[1])[0]=(new Position[1])[0]), + "struct/class Position must be default-constructible " + "and assignable"); +static assert(__traits(compiles, (new string[1])[0]=(new Position).toString()), + "error: struct/class Position must have toString method"); +]], [[ + /** + * A struct denoting a point in the input.*/ +public struct ]b4_position_type[ { + + /** The column index within the line of input. */ + public int column = 1; + /** The line number within an input file. */ + public int line = 1; + /** The name of the input file. */ + public string filename = null; + + /** + * A string representation of the position. */ + public string toString() const { + if (filename) + return format("%s:%d.%d", filename, line, column); + else + return format("%d.%d", line, column); + } +} +]])b4_location_type_if([[ +static assert(__traits(compiles, (new Location((new Position[1])[0]))) && + __traits(compiles, (new Location((new Position[1])[0], (new Position[1])[0]))), + "error: struct/class Location must have " + "default constructor and constructors this(Position) and this(Position, Position)."); +static assert(__traits(compiles, (new Location[1])[0].begin=(new Location[1])[0].begin) && + __traits(compiles, (new Location[1])[0].begin=(new Location[1])[0].end) && + __traits(compiles, (new Location[1])[0].end=(new Location[1])[0].begin) && + __traits(compiles, (new Location[1])[0].end=(new Location[1])[0].end), + "error: struct/class Location must have assignment-compatible " + "members/properties 'begin' and 'end'."); +static assert(__traits(compiles, (new string[1])[0]=(new Location[1])[0].toString()), + "error: struct/class Location must have toString method."); + +private immutable bool yy_location_is_class = !__traits(compiles, *(new Location((new Position[1])[0])));]], [[ +/** + * A struct defining a pair of positions. Positions, defined by the + * Position struct, denote a point in the input. + * Locations represent a part of the input through the beginning + * and ending positions. */ +public struct ]b4_location_type[ +{ + /** The first, inclusive, position in the range. */ + public Position begin; + + /** The first position beyond the range. */ + public Position end; + + /** + * Create a Location denoting an empty range located at + * a given point. + * @@param loc The position at which the range is anchored. */ + public this(Position loc) + { + this.begin = this.end = loc; + } + + /** + * Create a Location from the endpoints of the range. + * @@param begin The first position included in the range. + * @@param end The first position beyond the range. */ + public this(Position begin, Position end) + { + this.begin = begin; + this.end = end; + } + + /** + * Reset initial location to final location. + */ + public void step() + { + this.begin = this.end; + } + + /** + * A representation of the location. + */ + public string toString() const + { + auto end_col = 0 < end.column ? end.column - 1 : 0; + auto res = begin.toString (); + if (end.filename && begin.filename != end.filename) + res ~= "-" ~ format("%s:%d.%d", end.filename, end.line, end_col); + else if (begin.line < end.line) + res ~= "-" ~ format("%d.%d", end.line, end_col); + else if (begin.column < end_col) + res ~= "-" ~ format("%d", end_col); + return res; + } +} + +private immutable bool yy_location_is_class = false; + +]])])[]b4_value_type_setup[]m4_ifdef([b4_user_union_members], [private union YYSemanticType +{ +b4_user_union_members +};], +[m4_if(b4_tag_seen_flag, 0, +[[private alias int YYSemanticType;]])])[ +]b4_token_enums[ +]b4_parser_class_declaration[ +{ + ]b4_identification[ + +]b4_declare_symbol_enum[ + +]b4_locations_if([[ + private final Location yylloc_from_stack (ref YYStack rhs, int n) + { + static if (yy_location_is_class) { + if (n > 0) + return new Location (rhs.locationAt (n-1).begin, rhs.locationAt (0).end); + else + return new Location (rhs.locationAt (0).end); + } else { + if (n > 0) + return Location (rhs.locationAt (n-1).begin, rhs.locationAt (0).end); + else + return Location (rhs.locationAt (0).end); + } + }]])[ + +]b4_lexer_if([[ private class YYLexer implements Lexer { +]b4_percent_code_get([[lexer]])[ + } +]])[ + /** The object doing lexical analysis for us. */ + private Lexer yylexer; + +]b4_parse_param_vars[ + +]b4_lexer_if([[ + /** + * Instantiate the Bison-generated parser. + */ + public this] (b4_parse_param_decl([b4_lex_param_decl])[) { +]b4_percent_code_get([[init]])[]b4_lac_if([[ + this.yylacStack = new int[]; + this.yylacEstablished = false;]])[ + this (new YYLexer(]b4_lex_param_call[)); + } +]])[ + + /** + * Instantiate the Bison-generated parser. + * @@param yylexer The scanner that will supply tokens to the parser. + */ + ]b4_lexer_if([[protected]], [[public]]) [this (]b4_parse_param_decl([[Lexer yylexer]])[) { + this.yylexer = yylexer;]b4_parse_trace_if([[ + this.yyDebugStream = stderr;]])[ +]b4_parse_param_cons[ + } +]b4_parse_trace_if([[ + import std.stdio; + private File yyDebugStream; + + /** + * The File on which the debugging output is + * printed. + */ + public File getDebugStream () { return yyDebugStream; } + + /** + * Set the std.File on which the debug output is printed. + * @@param s The stream that is used for debugging output. + */ + public final void setDebugStream(File s) { yyDebugStream = s; } + + private int yydebug = 0; + + /** + * Answer the verbosity of the debugging output; 0 means that all kinds of + * output from the parser are suppressed. + */ + public final int getDebugLevel() { return yydebug; } + + /** + * Set the verbosity of the debugging output; 0 means that all kinds of + * output from the parser are suppressed. + * @@param level The verbosity level for debugging output. + */ + public final void setDebugLevel(int level) { yydebug = level; } + + protected final void yycdebug (string s) { + if (0 < yydebug) + yyDebugStream.write (s); + } + + protected final void yycdebugln (string s) { + if (0 < yydebug) + yyDebugStream.writeln (s); + } +]])[ + private final ]b4_parser_class[.Symbol yylex () { + return yylexer.yylex (); + } + + protected final void yyerror (]b4_locations_if([[const Location loc, ]])[string s) { + yylexer.yyerror (]b4_locations_if([loc, ])[s); + } + + /** + * The number of syntax errors so far. + */ + public int numberOfErrors() const { return yynerrs_; } + private int yynerrs_ = 0; + + /** + * Returned by a Bison action in order to stop the parsing process and + * return success (true). */ + public static immutable int YYACCEPT = 0; + + /** + * Returned by a Bison action in order to stop the parsing process and + * return failure (false). */ + public static immutable int YYABORT = 1; +]b4_push_if([ + /** + * Returned by a Bison action in order to request a new token. + */ + public static immutable int YYPUSH_MORE = 4;])[ + + /** + * Returned by a Bison action in order to start error recovery without + * printing an error message. */ + public static immutable int YYERROR = 2; + + // Internal return codes that are not supported for user semantic + // actions. + private static immutable int YYERRLAB = 3; + private static immutable int YYNEWSTATE = 4; + private static immutable int YYDEFAULT = 5; + private static immutable int YYREDUCE = 6; + private static immutable int YYERRLAB1 = 7; + private static immutable int YYRETURN = 8; +]b4_push_if([[ private static immutable int YYGETTOKEN = 9; /* Signify that a new token is expected when doing push-parsing. */]])[ + +]b4_locations_if([ + private static immutable YYSemanticType yy_semantic_null;])[ + private int yyerrstatus_ = 0; + + private void yyerrok() + { + yyerrstatus_ = 0; + } + + // Lookahead symbol kind. + SymbolKind yytoken = ]b4_symbol(empty, kind)[; + + /* State. */ + int yyn = 0; + int yylen = 0; + int yystate = 0; + + YYStack yystack; + + int label = YYNEWSTATE; + + /* Error handling. */ +]b4_locations_if([[ + /// The location where the error started. + Location yyerrloc; + + /// Location of the lookahead. + Location yylloc; + + /// @@$. + Location yyloc;]])[ + + /// Semantic value of the lookahead. + Value yylval; + + /** + * Whether error recovery is being done. In this state, the parser + * reads token until it reaches a known state, and then restarts normal + * operation. */ + public final bool recovering () + { + return yyerrstatus_ == 0; + } + + /** Compute post-reduction state. + * @@param yystate the current state + * @@param yysym the nonterminal to push on the stack + */ + private int yyLRGotoState(int yystate, int yysym) { + int yyr = yypgoto_[yysym - yyntokens_] + yystate; + if (0 <= yyr && yyr <= yylast_ && yycheck_[yyr] == yystate) + return yytable_[yyr]; + else + return yydefgoto_[yysym - yyntokens_]; + } + + private int yyaction (int yyn, ref YYStack yystack, int yylen) + { + Value yyval;]b4_locations_if([[ + Location yyloc = yylloc_from_stack (yystack, yylen);]])[ + + /* If YYLEN is nonzero, implement the default value of the action: + `$$ = $1'. Otherwise, use the top of the stack. + + Otherwise, the following line sets YYVAL to garbage. + This behavior is undocumented and Bison + users should not rely upon it. */ + if (yylen > 0) + yyval = yystack.valueAt (yylen - 1); + else + yyval = yystack.valueAt (0); + +]b4_parse_trace_if([[ + yy_reduce_print (yyn, yystack);]])[ + + switch (yyn) + { +]b4_user_actions[ + default: break; + } + +]b4_parse_trace_if([[ + yy_symbol_print ("-> $$ =", to!SymbolKind (yyr1_[yyn]), yyval]b4_locations_if([, yyloc])[);]])[ + + yystack.pop (yylen); + yylen = 0; + + /* Shift the result of the reduction. */ + int yystate = yyLRGotoState(yystack.stateAt(0), yyr1_[yyn]); + yystack.push (yystate, yyval]b4_locations_if([, yyloc])[); + return YYNEWSTATE; + } + +]b4_parse_trace_if([[ + /*--------------------------------. + | Print this symbol on YYOUTPUT. | + `--------------------------------*/ + + private final void yy_symbol_print (string s, SymbolKind yykind, + ref Value yyval]b4_locations_if([, ref Location yyloc])[) + { + if (0 < yydebug) + { + File yyo = yyDebugStream; + yyo.write(s); + yyo.write(yykind < yyntokens_ ? " token " : " nterm "); + yyo.write(format("%s", yykind)); + yyo.write(" ("]b4_locations_if([ ~ yyloc.toString() ~ ": "])[); + ]b4_symbol_actions([printer])[ + yyo.write(")\n"); + } + } +]])[ +]b4_symbol_type_define[ +]b4_push_if([[ + /** + * Push Parse input from external lexer + * + * @@param yyla current Symbol + * + * @@return YYACCEPT, YYABORT, YYPUSH_MORE + */ + public int pushParse(Symbol yyla)]], [[ + /** + * Parse input from the scanner that was specified at object construction + * time. Return whether the end of the input was reached successfully. + * + * @@return true if the parsing succeeds. Note that this does not + * imply that there were no syntax errors. + */ + public bool parse()]])[ + {]b4_push_if([[ + if (!this.pushParseInitialized) + { + pushParseInitialize(); + yyerrstatus_ = 0; + } + else + label = YYGETTOKEN; + + bool push_token_consumed = true; +]], [[ bool yyresult;]b4_lac_if([[ + // Discard the LAC context in case there still is one left from a + // previous invocation. + yylacDiscard("init");]])[]b4_parse_trace_if([[ + + yycdebugln ("Starting parse");]])[ + yyerrstatus_ = 0; + +]m4_ifdef([b4_initial_action], [ +m4_pushdef([b4_at_dollar], [yylloc])dnl +m4_pushdef([b4_dollar_dollar], [yylval])dnl + /* User initialization code. */ + b4_user_initial_action +m4_popdef([b4_dollar_dollar])dnl +m4_popdef([b4_at_dollar])])dnl + + [ /* Initialize the stack. */ + yystack.push (yystate, yylval]b4_locations_if([, yylloc])[); + + label = YYNEWSTATE;]])[ + for (;;) + final switch (label) + { + /* New state. Unlike in the C/C++ skeletons, the state is already + pushed when we come here. */ + case YYNEWSTATE:]b4_parse_trace_if([[ + yycdebugln (format("Entering state %d", yystate)); + if (0 < yydebug) + yystack.print (yyDebugStream);]])[ + + /* Accept? */ + if (yystate == yyfinal_)]b4_push_if([[ + { + label = YYACCEPT; + break; + }]], [[ + return true;]])[ + + /* Take a decision. First try without lookahead. */ + yyn = yypact_[yystate]; + if (yyPactValueIsDefault(yyn)) + { + label = YYDEFAULT; + break; + }]b4_push_if([[ + goto case; + + case YYGETTOKEN:]])[ + + /* Read a lookahead token. */ + if (yytoken == ]b4_symbol(empty, kind)[) + {]b4_push_if([[ + if (!push_token_consumed) + return YYPUSH_MORE;]])[]b4_parse_trace_if([[ + yycdebugln ("Reading a token");]])[]b4_push_if([[ + yytoken = yyla.token; + yylval = yyla.value;]b4_locations_if([[ + yylloc = yyla.location;]])[ + push_token_consumed = false;]], [[ + Symbol yysymbol = yylex(); + yytoken = yysymbol.token(); + yylval = yysymbol.value();]b4_locations_if([[ + yylloc = yysymbol.location();]])[]])[ + } + + /* Token already converted to internal form. */]b4_parse_trace_if([[ + yy_symbol_print ("Next token is", yytoken, yylval]b4_locations_if([, yylloc])[);]])[ + + if (yytoken == ]b4_symbol(error, kind)[) + { + // The scanner already issued an error message, process directly + // to error recovery. But do not keep the error token as + // lookahead, it is too special and may lead us to an endless + // loop in error recovery. */ + yytoken = ]b4_symbol(undef, kind)[;]b4_locations_if([[ + yyerrloc = yylloc;]])[ + label = YYERRLAB1; + } + else + { + /* If the proper action on seeing token YYTOKEN is to reduce or to + detect an error, take that action. */ + yyn += yytoken; + if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yytoken) {]b4_lac_if([[ + if (!yylacEstablish(yystack, yytoken)) + label = YYERRLAB; + else]])[ + label = YYDEFAULT; + } + /* <= 0 means reduce or error. */ + else if ((yyn = yytable_[yyn]) <= 0) + { + if (yyTableValueIsError(yyn)) + label = YYERRLAB;]b4_lac_if([[ + else if (!yylacEstablish(yystack, yytoken)) + label = YYERRLAB;]])[ + else + { + yyn = -yyn; + label = YYREDUCE; + } + } + else + { + /* Shift the lookahead token. */]b4_parse_trace_if([[ + yy_symbol_print ("Shifting", yytoken, yylval]b4_locations_if([, yylloc])[);]])[ + + /* Discard the token being shifted. */ + yytoken = ]b4_symbol(empty, kind)[; + + /* Count tokens shifted since error; after three, turn off error + * status. */ + if (yyerrstatus_ > 0) + --yyerrstatus_; + + yystate = yyn; + yystack.push (yystate, yylval]b4_locations_if([, yylloc])[);]b4_lac_if([[ + yylacDiscard("shift");]])[ + label = YYNEWSTATE; + } + } + break; + + /*-----------------------------------------------------------. + | yydefault -- do the default action for the current state. | + `-----------------------------------------------------------*/ + case YYDEFAULT: + yyn = yydefact_[yystate]; + if (yyn == 0) + label = YYERRLAB; + else + label = YYREDUCE; + break; + + /*-----------------------------. + | yyreduce -- Do a reduction. | + `-----------------------------*/ + case YYREDUCE: + yylen = yyr2_[yyn]; + label = yyaction (yyn, yystack, yylen); + yystate = yystack.stateAt (0); + break; + + /*--------------------------------------. + | yyerrlab -- here on detecting error. | + `--------------------------------------*/ + case YYERRLAB: + /* If not already recovering from an error, report this error. */ + if (yyerrstatus_ == 0) + { + ++yynerrs_; + yyreportSyntaxError(new Context(]b4_lac_if([[this, ]])[yystack, yytoken]b4_locations_if([[, yylloc]])[)); + } +]b4_locations_if([ + yyerrloc = yylloc;])[ + if (yyerrstatus_ == 3) + { + /* If just tried and failed to reuse lookahead token after an + * error, discard it. */ + + /* Return failure if at end of input. */ + if (yytoken == ]b4_symbol(eof, [kind])[)]b4_push_if([[ + { + label = YYABORT; + break; + }]], [[ + return false;]])[ + else + yytoken = ]b4_symbol(empty, kind)[; + } + + /* Else will try to reuse lookahead token after shifting the error + * token. */ + label = YYERRLAB1; + break; + + /*-------------------------------------------------. + | errorlab -- error raised explicitly by YYERROR. | + `-------------------------------------------------*/ + case YYERROR:]b4_locations_if([ + yyerrloc = yystack.locationAt (yylen - 1);])[ + /* Do not reclaim the symbols of the rule which action triggered + this YYERROR. */ + yystack.pop (yylen); + yylen = 0; + yystate = yystack.stateAt (0); + label = YYERRLAB1; + break; + + /*-------------------------------------------------------------. + | yyerrlab1 -- common code for both syntax error and YYERROR. | + `-------------------------------------------------------------*/ + case YYERRLAB1: + yyerrstatus_ = 3; /* Each real token shifted decrements this. */ + + // Pop stack until we find a state that shifts the error token. + for (;;) + { + yyn = yypact_[yystate]; + if (!yyPactValueIsDefault(yyn)) + { + yyn += ]b4_symbol(error, kind)[; + if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == ]b4_symbol(error, kind)[) + { + yyn = yytable_[yyn]; + if (0 < yyn) + break; + } + } + + /* Pop the current state because it cannot handle the error token. */ + if (yystack.height == 1)]b4_push_if([[ + { + label = YYABORT; + break; + }]],[[ + return false;]])[ + +]b4_locations_if([ yyerrloc = yystack.locationAt (0);])[ + yystack.pop (); + yystate = yystack.stateAt (0);]b4_parse_trace_if([[ + if (0 < yydebug) + yystack.print (yyDebugStream);]])[ + }]b4_push_if([[ + if (label == YYABORT) + /* Leave the switch. */ + break; +]])[ +]b4_locations_if([ + /* Muck with the stack to setup for yylloc. */ + yystack.push (0, yy_semantic_null, yylloc); + yystack.push (0, yy_semantic_null, yyerrloc); + yyloc = yylloc_from_stack (yystack, 2); + yystack.pop (2);])[ + + /* Shift the error token. */]b4_lac_if([[ + yylacDiscard("error recovery");]])[]b4_parse_trace_if([[ + yy_symbol_print ("Shifting", to!SymbolKind (yystos_[yyn]), yylval]b4_locations_if([, yyloc])[);]])[ + yystate = yyn; + yystack.push (yyn, yylval]b4_locations_if([, yyloc])[); + label = YYNEWSTATE; + break; + + /* Accept. */ + case YYACCEPT:]b4_push_if([[ + this.pushParseInitialized = false;]b4_parse_trace_if([[ + if (0 < yydebug) + yystack.print (yyDebugStream);]])[ + return YYACCEPT;]], [[ + yyresult = true; + label = YYRETURN; + break;]])[ + + /* Abort. */ + case YYABORT:]b4_push_if([[ + this.pushParseInitialized = false;]b4_parse_trace_if([[ + if (0 < yydebug) + yystack.print (yyDebugStream);]])[ + return YYABORT;]], [[ + yyresult = false; + label = YYRETURN; + break;]])[ +]b4_push_if([[]], [[ ][case YYRETURN:]b4_parse_trace_if([[ + if (0 < yydebug) + yystack.print (yyDebugStream);]])[ + return yyresult;]])[ + } + assert(0); + } + +]b4_push_if([[ + bool pushParseInitialized = false; + + /** + * (Re-)Initialize the state of the push parser. + */ + public void pushParseInitialize() + { + + /* Lookahead and lookahead in internal form. */ + this.yytoken = ]b4_symbol(empty, kind)[; + + /* State. */ + this.yyn = 0; + this.yylen = 0; + this.yystate = 0; + destroy(this.yystack); + this.label = YYNEWSTATE; +]b4_lac_if([[ + destroy(this.yylacStack); + this.yylacEstablished = false;]])[ + + /* Error handling. */ + this.yynerrs_ = 0; +]b4_locations_if([ + /* The location where the error started. */ + this.yyerrloc = Location(Position(), Position()); + this.yylloc = Location(Position(), Position());])[ + + /* Semantic value of the lookahead. */ + //destroy(this.yylval); + + /* Initialize the stack. */ + yystack.push(this.yystate, this.yylval]b4_locations_if([, this.yylloc])[); + + this.pushParseInitialized = true; + }]])[]b4_both_if([[ + /** + * Parse input from the scanner that was specified at object construction + * time. Return whether the end of the input was reached successfully. + * This version of parse() is defined only when api.push-push=both. + * + * @@return true if the parsing succeeds. Note that this does not + * imply that there were no syntax errors. + */ + bool parse() + { + int status = 0; + do { + status = this.pushParse(yylex()); + } while (status == YYPUSH_MORE); + return status == YYACCEPT; + }]])[ + + // Generate an error message. + private final void yyreportSyntaxError(Context yyctx) + {]b4_parse_error_bmatch( +[custom], [[ + yylexer.reportSyntaxError(yyctx);]], +[detailed], [[ + if (yyctx.getToken() != ]b4_symbol(empty, kind)[) + { + // FIXME: This method of building the message is not compatible + // with internationalization. + immutable int argmax = 5; + SymbolKind[] yyarg = new SymbolKind[argmax]; + int yycount = yysyntaxErrorArguments(yyctx, yyarg, argmax); + string res, yyformat; + switch (yycount) + { + case 1: + yyformat = YY_("syntax error, unexpected %s"); + res = format(yyformat, yyarg[0]); + break; + case 2: + yyformat = YY_("syntax error, unexpected %s, expecting %s"); + res = format(yyformat, yyarg[0], yyarg[1]); + break; + case 3: + yyformat = YY_("syntax error, unexpected %s, expecting %s or %s"); + res = format(yyformat, yyarg[0], yyarg[1], yyarg[2]); + break; + case 4: + yyformat = YY_("syntax error, unexpected %s, expecting %s or %s or %s"); + res = format(yyformat, yyarg[0], yyarg[1], yyarg[2], yyarg[3]); + break; + case 5: + yyformat = YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"); + res = format(yyformat, yyarg[0], yyarg[1], yyarg[2], yyarg[3], yyarg[4]); + break; + default: + res = YY_("syntax error"); + break; + } + yyerror(]b4_locations_if([yyctx.getLocation(), ])[res); + }]], +[[simple]], [[ + yyerror(]b4_locations_if([yyctx.getLocation(), ])[YY_("syntax error"));]])[ + } + +]b4_parse_error_bmatch( +[detailed], [[ + private int yysyntaxErrorArguments(Context yyctx, SymbolKind[] yyarg, int yyargn) { + /* There are many possibilities here to consider: + - 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 tok) 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. (However, yychar is currently out + of scope during semantic actions.) + - 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. + */ + int yycount = 0; + if (yyctx.getToken() != ]b4_symbol(empty, kind)[) + { + if (yyarg !is null) + yyarg[yycount] = yyctx.getToken(); + yycount += 1; + yycount += yyctx.getExpectedTokens(yyarg, 1, yyargn); + } + return yycount; + } +]])[ + + + /** + * Information needed to get the list of expected tokens and to forge + * a syntax error diagnostic. + */ + public static final class Context + {]b4_lac_if([[ + private ]b4_parser_class[ yyparser;]])[ + private const(YYStack) yystack; + private SymbolKind yytoken;]b4_locations_if([[ + private const(Location) yylocation;]])[ + + this(]b4_lac_if([[]b4_parser_class[ parser, ]])[YYStack stack, SymbolKind kind]b4_locations_if([[, Location loc]])[) + {]b4_lac_if([[ + yyparser = parser;]])[ + yystack = stack; + yytoken = kind;]b4_locations_if([[ + yylocation = loc;]])[ + } + + final SymbolKind getToken() const + { + return yytoken; + }]b4_locations_if([[ + + final const(Location) getLocation() const + { + return yylocation; + }]])[ + /** + * Put in YYARG at most YYARGN of the expected tokens given the + * current YYCTX, and return the number of tokens stored in YYARG. If + * YYARG is null, return the number of expected tokens (guaranteed to + * be less than YYNTOKENS). + */ + int getExpectedTokens(SymbolKind[] yyarg, int yyargn)]b4_lac_if([[]], [[ const]])[ + { + return getExpectedTokens(yyarg, 0, yyargn); + } + + int getExpectedTokens(SymbolKind[] yyarg, int yyoffset, int yyargn)]b4_lac_if([[]], [[ const]])[ + { + int yycount = yyoffset;]b4_lac_if([b4_parse_trace_if([[ + // Execute LAC once. We don't care if it is successful, we + // only do it for the sake of debugging output. + + if (!yyparser.yylacEstablished) + yyparser.yylacCheck(yystack, yytoken); +]])[ + for (int yyx = 0; yyx < yyntokens_; ++yyx) + { + SymbolKind yysym = SymbolKind(yyx); + if (yysym != ]b4_symbol(error, kind)[ + && yysym != ]b4_symbol(undef, kind)[ + && yyparser.yylacCheck(yystack, yysym)) + { + if (yyarg == null) + yycount += 1; + else if (yycount == yyargn) + return 0; + else + yyarg[yycount++] = yysym; + } + }]], [[ + int yyn = yypact_[this.yystack.stateAt(0)]; + if (!yyPactValueIsDefault(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_; + for (int yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck_[yyx + yyn] == yyx && yyx != ]b4_symbol(error, kind)[ + && !yyTableValueIsError(yytable_[yyx + yyn])) + { + if (yyarg is null) + ++yycount; + else if (yycount == yyargn) + return 0; + else + yyarg[yycount++] = SymbolKind(yyx); + } + }]])[ + if (yyarg !is null && yycount == yyoffset && yyoffset < yyargn) + yyarg[yyoffset] = ]b4_symbol(empty, kind)[; + return yycount - yyoffset; + } + } + +]b4_lac_if([[ + /** Check the lookahead yytoken. + * \returns true iff the token will be eventually shifted. + */ + bool yylacCheck(const YYStack yystack, SymbolKind yytoken) + { + // Logically, the yylacStack's lifetime is confined to this function. + // Clear it, to get rid of potential left-overs from previous call. + destroy(yylacStack); + // Reduce until we encounter a shift and thereby accept the token. +]b4_parse_trace_if([[ + yycdebug("LAC: checking lookahead " ~ format("%s", yytoken) ~ ":");]])[ + int lacTop = 0; + while (true) + { + int topState = (yylacStack.length == 0 + ? yystack.stateAt(lacTop) + : yylacStack[$ - 1]); + int yyrule = yypact_[topState]; + if (yyPactValueIsDefault(yyrule) + || (yyrule += yytoken) < 0 || yylast_ < yyrule + || yycheck_[yyrule] != yytoken) + { + // Use the default action. + yyrule = yydefact_[+topState]; + if (yyrule == 0) + {]b4_parse_trace_if([[ + yycdebugln(" Err");]])[ + return false; + } + } + else + { + // Use the action from yytable. + yyrule = yytable_[yyrule]; + if (yyTableValueIsError(yyrule)) + {]b4_parse_trace_if([[ + yycdebugln(" Err");]])[ + return false; + } + if (0 < yyrule) + {]b4_parse_trace_if([[ + yycdebugln(" S" ~ to!string(yyrule));]])[ + return true; + } + yyrule = -yyrule; + } + // By now we know we have to simulate a reduce. +]b4_parse_trace_if([[ + yycdebug(" R" ~ to!string(yyrule - 1));]])[ + // Pop the corresponding number of values from the stack. + { + int yylen = yyr2_[yyrule]; + // First pop from the LAC stack as many tokens as possible. + int lacSize = cast (int) yylacStack.length; + if (yylen < lacSize) + { + yylacStack.length -= yylen; + yylen = 0; + } + else if (lacSize != 0) + { + destroy(yylacStack); + yylen -= lacSize; + } + // Only afterwards look at the main stack. + // We simulate popping elements by incrementing lacTop. + lacTop += yylen; + } + // Keep topState in sync with the updated stack. + topState = (yylacStack.length == 0 + ? yystack.stateAt(lacTop) + : yylacStack[$ - 1]); + // Push the resulting state of the reduction. + int state = yyLRGotoState(topState, yyr1_[yyrule]);]b4_parse_trace_if([[ + yycdebug(" G" ~ to!string(state));]])[ + yylacStack.length++; + yylacStack[$ - 1] = state; + } + } + + /** Establish the initial context if no initial context currently exists. + * \returns true iff the token will be eventually shifted. + */ + bool yylacEstablish(YYStack yystack, SymbolKind yytoken) + { + /* Establish the initial context for the current lookahead if no initial + context is currently established. + + We define a context as a snapshot of the parser stacks. We define + the initial context for a lookahead as the context in which the + parser initially examines that lookahead in order to select a + syntactic action. Thus, if the lookahead eventually proves + syntactically unacceptable (possibly in a later context reached via a + series of reductions), the initial context can be used to determine + the exact set of tokens that would be syntactically acceptable in the + lookahead's place. Moreover, it is the context after which any + further semantic actions would be erroneous because they would be + determined by a syntactically unacceptable token. + + yylacEstablish should be invoked when a reduction is about to be + performed in an inconsistent state (which, for the purposes of LAC, + includes consistent states that don't know they're consistent because + their default reductions have been disabled). + + For parse.lac=full, the implementation of yylacEstablish is as + follows. If no initial context is currently established for the + current lookahead, then check if that lookahead can eventually be + shifted if syntactic actions continue from the current context. */ + if (yylacEstablished) + return true; + else + {]b4_parse_trace_if([[ + yycdebugln("LAC: initial context established for " ~ format("%s", yytoken));]])[ + yylacEstablished = true; + return yylacCheck(yystack, yytoken); + } + } + + /** Discard any previous initial lookahead context because of event. + * \param event the event which caused the lookahead to be discarded. + * Only used for debbuging output. */ + void yylacDiscard(string event) + { + /* Discard any previous initial lookahead context because of Event, + which may be a lookahead change or an invalidation of the currently + established initial context for the current lookahead. + + The most common example of a lookahead change is a shift. An example + of both cases is syntax error recovery. That is, a syntax error + occurs when the lookahead is syntactically erroneous for the + currently established initial context, so error recovery manipulates + the parser stacks to try to find a new initial context in which the + current lookahead is syntactically acceptable. If it fails to find + such a context, it discards the lookahead. */ + if (yylacEstablished) + {]b4_parse_trace_if([[ + yycdebugln("LAC: initial context discarded due to " ~ event);]])[ + yylacEstablished = false; + } + } + + /** The stack for LAC. + * Logically, the yylacStack's lifetime is confined to the function + * yylacCheck. We just store it as a member of this class to hold + * on to the memory and to avoid frequent reallocations. + */ + int[] yylacStack; + /** Whether an initial LAC context was established. */ + bool yylacEstablished; +]])[ + + /** + * Whether the given yypact_ value indicates a defaulted state. + * @@param yyvalue the value to check + */ + private static bool yyPactValueIsDefault(int yyvalue) + { + return yyvalue == yypact_ninf_; + } + + /** + * Whether the given yytable_ value indicates a syntax error. + * @@param yyvalue the value to check + */ + private static bool yyTableValueIsError(int yyvalue) + { + return yyvalue == yytable_ninf_; + } + + /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ + private static immutable ]b4_int_type_for([b4_pact])[ yypact_ninf_ = ]b4_pact_ninf[; + + /* 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 YYTABLE_NINF_, syntax error. */ + private static immutable ]b4_int_type_for([b4_table])[ yytable_ninf_ = ]b4_table_ninf[; + + ]b4_parser_tables_define[ + +]b4_parse_trace_if([[ + /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ + private static immutable ]b4_int_type_for([b4_rline])[[] yyrline_ = + @{ + ]b4_rline[ + @}; + + // Report on the debug stream that the rule yyrule is going to be reduced. + private final void yy_reduce_print (int yyrule, ref YYStack yystack) + { + if (yydebug == 0) + return; + + int yylno = yyrline_[yyrule]; + int yynrhs = yyr2_[yyrule]; + /* Print the symbols being reduced, and their result. */ + yycdebugln (format("Reducing stack by rule %d (line %d):", + yyrule - 1, yylno)); + + /* The symbols being reduced. */ + for (int yyi = 0; yyi < yynrhs; yyi++) + yy_symbol_print (format(" $%d =", yyi + 1), + to!SymbolKind (yystos_[yystack.stateAt(yynrhs - (yyi + 1))]), + ]b4_rhs_value(yynrhs, yyi + 1)b4_locations_if([, + b4_rhs_location(yynrhs, yyi + 1)])[); + } +]])[ + + private static auto yytranslate_ (int t) + { +]b4_api_token_raw_if( +[[ return SymbolKind(t);]], +[[ /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ + immutable ]b4_int_type_for([b4_translate])[[] translate_table = + @{ + ]b4_translate[ + @}; + + // Last valid token kind. + immutable int code_max = ]b4_code_max[; + + if (t <= 0) + return ]b4_symbol(eof, kind)[; + else if (t <= code_max) + return SymbolKind(translate_table[t]); + else + return ]b4_symbol(undef, kind)[;]])[ + } + + private static immutable int yylast_ = ]b4_last[; + private static immutable int yynnts_ = ]b4_nterms_number[; + private static immutable int yyfinal_ = ]b4_final_state_number[; + private static immutable int yyntokens_ = ]b4_tokens_number[; + + private final struct YYStackElement { + int state; + Value value;]b4_locations_if( + b4_location_type[[] location;])[ + } + + private final struct YYStack { + private YYStackElement[] stack = []; + + public final ulong height() + { + return stack.length; + } + + public final void push (int state, Value value]dnl + b4_locations_if([, ref Location loc])[) + { + stack ~= YYStackElement(state, value]b4_locations_if([, loc])[); + } + + public final void pop () + { + pop (1); + } + + public final void pop (int num) + { + stack.length -= num; + } + + public final int stateAt (int i) const + { + return stack[$-i-1].state; + } + +]b4_locations_if([[ + public final ref Location locationAt (int i) + { + return stack[$-i-1].location; + }]])[ + + public final ref Value valueAt (int i) + { + return stack[$-i-1].value; + } +]b4_parse_trace_if([[ + // Print the state stack on the debug stream. + public final void print (File stream) + { + stream.write ("Stack now"); + for (int i = 0; i < stack.length; i++) + stream.write (" ", stack[i].state); + stream.writeln (); + }]])[ + } +]b4_percent_code_get[ +} +]b4_percent_code_get([[epilogue]])[]dnl +b4_epilogue[]dnl +b4_output_end diff --git a/Engine/bin/bison-flex/data/skeletons/lalr1.java b/Engine/bin/bison-flex/data/skeletons/lalr1.java new file mode 100644 index 000000000..1bbecca13 --- /dev/null +++ b/Engine/bin/bison-flex/data/skeletons/lalr1.java @@ -0,0 +1,1303 @@ +# Java skeleton for Bison -*- java -*- + +# Copyright (C) 2007-2015, 2018-2021 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +m4_include(b4_skeletonsdir/[java.m4]) + +b4_header_if([b4_complain([%header/%defines does not make sense in Java])]) + +m4_define([b4_symbol_no_destructor_assert], +[b4_symbol_if([$1], [has_destructor], + [b4_complain_at(m4_unquote(b4_symbol([$1], [destructor_loc])), + [%destructor does not make sense in Java])])]) +b4_symbol_foreach([b4_symbol_no_destructor_assert]) + +## --------------- ## +## api.push-pull. ## +## --------------- ## + +b4_percent_define_default([[api.push-pull]], [[pull]]) +b4_percent_define_check_values([[[[api.push-pull]], + [[pull]], [[push]], [[both]]]]) + +# Define m4 conditional macros that encode the value +# of the api.push-pull flag. +b4_define_flag_if([pull]) m4_define([b4_pull_flag], [[1]]) +b4_define_flag_if([push]) m4_define([b4_push_flag], [[1]]) +m4_case(b4_percent_define_get([[api.push-pull]]), + [pull], [m4_define([b4_push_flag], [[0]])], + [push], [m4_define([b4_pull_flag], [[0]])]) + +# Define a macro to be true when api.push-pull has the value "both". +m4_define([b4_both_if],[b4_push_if([b4_pull_if([$1],[$2])],[$2])]) + +# Handle BISON_USE_PUSH_FOR_PULL for the test suite. So that push parsing +# tests function as written, do not let BISON_USE_PUSH_FOR_PULL modify the +# behavior of Bison at all when push parsing is already requested. +b4_define_flag_if([use_push_for_pull]) +b4_use_push_for_pull_if([ + b4_push_if([m4_define([b4_use_push_for_pull_flag], [[0]])], + [m4_define([b4_push_flag], [[1]])])]) + +# Define a macro to encapsulate the parse state variables. This +# allows them to be defined either in parse() when doing pull parsing, +# or as class instance variable when doing push parsing. +m4_define([b4_define_state], +[[ + /* Lookahead token kind. */ + int yychar = YYEMPTY_; + /* Lookahead symbol kind. */ + SymbolKind yytoken = null; + + /* State. */ + int yyn = 0; + int yylen = 0; + int yystate = 0; + YYStack yystack = new YYStack (); + int label = YYNEWSTATE; + +]b4_locations_if([[ + /* The location where the error started. */ + ]b4_location_type[ yyerrloc = null; + + /* Location. */ + ]b4_location_type[ yylloc = new ]b4_location_type[ (null, null);]])[ + + /* Semantic value of the lookahead. */ + ]b4_yystype[ yylval = null; +]]) + +# parse.lac +b4_percent_define_default([[parse.lac]], [[none]]) +b4_percent_define_check_values([[[[parse.lac]], [[full]], [[none]]]]) +b4_define_flag_if([lac]) +m4_define([b4_lac_flag], + [m4_if(b4_percent_define_get([[parse.lac]]), + [none], [[0]], [[1]])]) + + +## ------------- ## +## Parser File. ## +## ------------- ## + +b4_output_begin([b4_parser_file_name])[ +]b4_copyright([Skeleton implementation for Bison LALR(1) parsers in Java], + [2007-2015, 2018-2021])[ +]b4_disclaimer[ +]b4_percent_define_ifdef([api.package], [package b4_percent_define_get([api.package]);[ +]])[ +]b4_user_pre_prologue[ +]b4_user_post_prologue[ +import java.text.MessageFormat; +import java.util.ArrayList; +]b4_percent_code_get([[imports]])[ +/** + * A Bison parser, automatically generated from ]m4_bpatsubst(b4_file_name, [^"\(.*\)"$], [\1])[. + * + * @@author LALR (1) parser skeleton written by Paolo Bonzini. + */ +]b4_parser_class_declaration[ +{ +]b4_identification[ +][ +]b4_parse_error_bmatch( + [detailed\|verbose], [[ + /** + * True if verbose error messages are enabled. + */ + private boolean yyErrorVerbose = true; + + /** + * Whether verbose error messages are enabled. + */ + public final boolean getErrorVerbose() { return yyErrorVerbose; } + + /** + * Set the verbosity of error messages. + * @@param verbose True to request verbose error messages. + */ + public final void setErrorVerbose(boolean verbose) + { yyErrorVerbose = verbose; } +]])[ + +]b4_locations_if([[ + /** + * A class defining a pair of positions. Positions, defined by the + * ]b4_position_type[ class, denote a point in the input. + * Locations represent a part of the input through the beginning + * and ending positions. + */ + public static class ]b4_location_type[ { + /** + * The first, inclusive, position in the range. + */ + public ]b4_position_type[ begin; + + /** + * The first position beyond the range. + */ + public ]b4_position_type[ end; + + /** + * Create a ]b4_location_type[ denoting an empty range located at + * a given point. + * @@param loc The position at which the range is anchored. + */ + public ]b4_location_type[ (]b4_position_type[ loc) { + this.begin = this.end = loc; + } + + /** + * Create a ]b4_location_type[ from the endpoints of the range. + * @@param begin The first position included in the range. + * @@param end The first position beyond the range. + */ + public ]b4_location_type[ (]b4_position_type[ begin, ]b4_position_type[ end) { + this.begin = begin; + this.end = end; + } + + /** + * Print a representation of the location. For this to be correct, + * ]b4_position_type[ should override the equals + * method. + */ + public String toString() { + if (begin.equals (end)) + return begin.toString(); + else + return begin.toString() + "-" + end.toString(); + } + } + + private ]b4_location_type[ yylloc(YYStack rhs, int n) + { + if (0 < n) + return new ]b4_location_type[(rhs.locationAt(n-1).begin, rhs.locationAt(0).end); + else + return new ]b4_location_type[(rhs.locationAt(0).end); + }]])[ + +]b4_declare_symbol_enum[ + + /** + * Communication interface between the scanner and the Bison-generated + * parser ]b4_parser_class[. + */ + public interface Lexer { +]b4_token_enums[ + /** Deprecated, use ]b4_symbol(eof, id)[ instead. */ + public static final int EOF = ]b4_symbol(eof, id)[; +]b4_pull_if([b4_locations_if([[ + /** + * Method to retrieve the beginning position of the last scanned token. + * @@return the position at which the last scanned token starts. + */ + ]b4_position_type[ getStartPos(); + + /** + * Method to retrieve the ending position of the last scanned token. + * @@return the first position beyond the last scanned token. + */ + ]b4_position_type[ getEndPos();]])[ + + /** + * Method to retrieve the semantic value of the last scanned token. + * @@return the semantic value of the last scanned token. + */ + ]b4_yystype[ getLVal(); + + /** + * Entry point for the scanner. Returns the token identifier corresponding + * to the next token and prepares to return the semantic value + * ]b4_locations_if([and beginning/ending positions ])[of the token. + * @@return the token identifier corresponding to the next token. + */ + int yylex()]b4_maybe_throws([b4_lex_throws])[; +]])[ + /** + * Emit an error]b4_locations_if([ referring to the given location])[in a user-defined way. + * + *]b4_locations_if([[ @@param loc The location of the element to which the + * error message is related.]])[ + * @@param msg The string for the error message. + */ + void yyerror(]b4_locations_if([b4_location_type[ loc, ]])[String msg); + +]b4_parse_error_bmatch( + [custom], [[ + /** + * Build and emit a "syntax error" message in a user-defined way. + * + * @@param ctx The context of the error. + */ + void reportSyntaxError(Context ctx); +]])[ + } + +]b4_lexer_if([[ + private class YYLexer implements Lexer { +]b4_percent_code_get([[lexer]])[ + } + +]])[ + /** + * The object doing lexical analysis for us. + */ + private Lexer yylexer; + +]b4_parse_param_vars[ + +]b4_lexer_if([[ + /** + * Instantiates the Bison-generated parser. + */ + public ]b4_parser_class[(]b4_parse_param_decl([b4_lex_param_decl])[)]b4_maybe_throws([b4_init_throws])[ + { +]b4_percent_code_get([[init]])[]b4_lac_if([[ + this.yylacStack = new ArrayList(); + this.yylacEstablished = false;]])[ + this.yylexer = new YYLexer(]b4_lex_param_call[); +]b4_parse_param_cons[ + } +]])[ + + /** + * Instantiates the Bison-generated parser. + * @@param yylexer The scanner that will supply tokens to the parser. + */ + ]b4_lexer_if([[protected]], [[public]]) b4_parser_class[(]b4_parse_param_decl([[Lexer yylexer]])[)]b4_maybe_throws([b4_init_throws])[ + { +]b4_percent_code_get([[init]])[]b4_lac_if([[ + this.yylacStack = new ArrayList(); + this.yylacEstablished = false;]])[ + this.yylexer = yylexer; +]b4_parse_param_cons[ + } + +]b4_parse_trace_if([[ + private java.io.PrintStream yyDebugStream = System.err; + + /** + * The PrintStream on which the debugging output is printed. + */ + public final java.io.PrintStream getDebugStream() { return yyDebugStream; } + + /** + * Set the PrintStream on which the debug output is printed. + * @@param s The stream that is used for debugging output. + */ + public final void setDebugStream(java.io.PrintStream s) { yyDebugStream = s; } + + private int yydebug = 0; + + /** + * Answer the verbosity of the debugging output; 0 means that all kinds of + * output from the parser are suppressed. + */ + public final int getDebugLevel() { return yydebug; } + + /** + * Set the verbosity of the debugging output; 0 means that all kinds of + * output from the parser are suppressed. + * @@param level The verbosity level for debugging output. + */ + public final void setDebugLevel(int level) { yydebug = level; } +]])[ + + private int yynerrs = 0; + + /** + * The number of syntax errors so far. + */ + public final int getNumberOfErrors() { return yynerrs; } + + /** + * Print an error message via the lexer. + *]b4_locations_if([[ Use a null location.]])[ + * @@param msg The error message. + */ + public final void yyerror(String msg) { + yylexer.yyerror(]b4_locations_if([[(]b4_location_type[)null, ]])[msg); + } +]b4_locations_if([[ + /** + * Print an error message via the lexer. + * @@param loc The location associated with the message. + * @@param msg The error message. + */ + public final void yyerror(]b4_location_type[ loc, String msg) { + yylexer.yyerror(loc, msg); + } + + /** + * Print an error message via the lexer. + * @@param pos The position associated with the message. + * @@param msg The error message. + */ + public final void yyerror(]b4_position_type[ pos, String msg) { + yylexer.yyerror(new ]b4_location_type[ (pos), msg); + }]])[ +]b4_parse_trace_if([[ + protected final void yycdebugNnl(String s) { + if (0 < yydebug) + yyDebugStream.print(s); + } + + protected final void yycdebug(String s) { + if (0 < yydebug) + yyDebugStream.println(s); + }]])[ + + private final class YYStack { + private int[] stateStack = new int[16];]b4_locations_if([[ + private ]b4_location_type[[] locStack = new ]b4_location_type[[16];]])[ + private ]b4_yystype[[] valueStack = new ]b4_yystype[[16]; + + public int size = 16; + public int height = -1; + + public final void push(int state, ]b4_yystype[ value]b4_locations_if([, ]b4_location_type[ loc])[) { + height++; + if (size == height) { + int[] newStateStack = new int[size * 2]; + System.arraycopy(stateStack, 0, newStateStack, 0, height); + stateStack = newStateStack;]b4_locations_if([[ + ]b4_location_type[[] newLocStack = new ]b4_location_type[[size * 2]; + System.arraycopy(locStack, 0, newLocStack, 0, height); + locStack = newLocStack;]]) + + b4_yystype[[] newValueStack = new ]b4_yystype[[size * 2]; + System.arraycopy(valueStack, 0, newValueStack, 0, height); + valueStack = newValueStack; + + size *= 2; + } + + stateStack[height] = state;]b4_locations_if([[ + locStack[height] = loc;]])[ + valueStack[height] = value; + } + + public final void pop() { + pop(1); + } + + public final void pop(int num) { + // Avoid memory leaks... garbage collection is a white lie! + if (0 < num) { + java.util.Arrays.fill(valueStack, height - num + 1, height + 1, null);]b4_locations_if([[ + java.util.Arrays.fill(locStack, height - num + 1, height + 1, null);]])[ + } + height -= num; + } + + public final int stateAt(int i) { + return stateStack[height - i]; + } +]b4_locations_if([[ + + public final ]b4_location_type[ locationAt(int i) { + return locStack[height - i]; + } +]])[ + public final ]b4_yystype[ valueAt(int i) { + return valueStack[height - i]; + } + + // Print the state stack on the debug stream. + public void print(java.io.PrintStream out) { + out.print ("Stack now"); + + for (int i = 0; i <= height; i++) { + out.print(' '); + out.print(stateStack[i]); + } + out.println(); + } + } + + /** + * Returned by a Bison action in order to stop the parsing process and + * return success (true). + */ + public static final int YYACCEPT = 0; + + /** + * Returned by a Bison action in order to stop the parsing process and + * return failure (false). + */ + public static final int YYABORT = 1; + +]b4_push_if([ + /** + * Returned by a Bison action in order to request a new token. + */ + public static final int YYPUSH_MORE = 4;])[ + + /** + * Returned by a Bison action in order to start error recovery without + * printing an error message. + */ + public static final int YYERROR = 2; + + /** + * Internal return codes that are not supported for user semantic + * actions. + */ + private static final int YYERRLAB = 3; + private static final int YYNEWSTATE = 4; + private static final int YYDEFAULT = 5; + private static final int YYREDUCE = 6; + private static final int YYERRLAB1 = 7; + private static final int YYRETURN = 8; +]b4_push_if([[ private static final int YYGETTOKEN = 9; /* Signify that a new token is expected when doing push-parsing. */]])[ + + private int yyerrstatus_ = 0; + +]b4_push_if([b4_define_state])[ + /** + * Whether error recovery is being done. In this state, the parser + * reads token until it reaches a known state, and then restarts normal + * operation. + */ + public final boolean recovering () + { + return yyerrstatus_ == 0; + } + + /** Compute post-reduction state. + * @@param yystate the current state + * @@param yysym the nonterminal to push on the stack + */ + private int yyLRGotoState(int yystate, int yysym) { + int yyr = yypgoto_[yysym - YYNTOKENS_] + yystate; + if (0 <= yyr && yyr <= YYLAST_ && yycheck_[yyr] == yystate) + return yytable_[yyr]; + else + return yydefgoto_[yysym - YYNTOKENS_]; + } + + private int yyaction(int yyn, YYStack yystack, int yylen)]b4_maybe_throws([b4_throws])[ + { + /* If YYLEN is nonzero, implement the default value of the action: + '$$ = $1'. Otherwise, use the top of the stack. + + Otherwise, the following line sets YYVAL to garbage. + This behavior is undocumented and Bison + users should not rely upon it. */ + ]b4_yystype[ yyval = (0 < yylen) ? yystack.valueAt(yylen - 1) : yystack.valueAt(0);]b4_locations_if([[ + ]b4_location_type[ yyloc = yylloc(yystack, yylen);]])[]b4_parse_trace_if([[ + + yyReducePrint(yyn, yystack);]])[ + + switch (yyn) + { + ]b4_user_actions[ + default: break; + }]b4_parse_trace_if([[ + + yySymbolPrint("-> $$ =", SymbolKind.get(yyr1_[yyn]), yyval]b4_locations_if([, yyloc])[);]])[ + + yystack.pop(yylen); + yylen = 0; + /* Shift the result of the reduction. */ + int yystate = yyLRGotoState(yystack.stateAt(0), yyr1_[yyn]); + yystack.push(yystate, yyval]b4_locations_if([, yyloc])[); + return YYNEWSTATE; + } + +]b4_parse_trace_if([[ + /*--------------------------------. + | Print this symbol on YYOUTPUT. | + `--------------------------------*/ + + private void yySymbolPrint(String s, SymbolKind yykind, + ]b4_yystype[ yyvalue]b4_locations_if([, ]b4_location_type[ yylocation])[) { + if (0 < yydebug) { + yycdebug(s + + (yykind.getCode() < YYNTOKENS_ ? " token " : " nterm ") + + yykind.getName() + " ("]b4_locations_if([ + + yylocation + ": "])[ + + (yyvalue == null ? "(null)" : yyvalue.toString()) + ")"); + } + }]])[ + +]b4_push_if([],[[ + /** + * Parse input from the scanner that was specified at object construction + * time. Return whether the end of the input was reached successfully. + * + * @@return true if the parsing succeeds. Note that this does not + * imply that there were no syntax errors. + */ + public boolean parse()]b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])[]])[ +]b4_push_if([ + /** + * Push Parse input from external lexer + * + * @@param yylextoken current token + * @@param yylexval current lval]b4_locations_if([[ + * @@param yylexloc current position]])[ + * + * @@return YYACCEPT, YYABORT, YYPUSH_MORE + */ + public int push_parse(int yylextoken, b4_yystype yylexval[]b4_locations_if([, b4_location_type yylexloc]))b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])])[ + {]b4_locations_if([[ + /* @@$. */ + ]b4_location_type[ yyloc;]])[ +]b4_push_if([],[[ +]b4_define_state[ +]b4_lac_if([[ + // Discard the LAC context in case there still is one left from a + // previous invocation. + yylacDiscard("init");]])[ +]b4_parse_trace_if([[ + yycdebug ("Starting parse");]])[ + yyerrstatus_ = 0; + yynerrs = 0; + + /* Initialize the stack. */ + yystack.push (yystate, yylval]b4_locations_if([, yylloc])[); +]m4_ifdef([b4_initial_action], [ +b4_dollar_pushdef([yylval], [], [], [yylloc])dnl + b4_user_initial_action +b4_dollar_popdef[]dnl +])[ +]])[ +]b4_push_if([[ + if (!this.push_parse_initialized) + { + push_parse_initialize (); +]m4_ifdef([b4_initial_action], [ +b4_dollar_pushdef([yylval], [], [], [yylloc])dnl + b4_user_initial_action +b4_dollar_popdef[]dnl +])[]b4_parse_trace_if([[ + yycdebug ("Starting parse");]])[ + yyerrstatus_ = 0; + } else + label = YYGETTOKEN; + + boolean push_token_consumed = true; +]])[ + for (;;) + switch (label) + { + /* New state. Unlike in the C/C++ skeletons, the state is already + pushed when we come here. */ + case YYNEWSTATE:]b4_parse_trace_if([[ + yycdebug ("Entering state " + yystate); + if (0 < yydebug) + yystack.print (yyDebugStream);]])[ + + /* Accept? */ + if (yystate == YYFINAL_) + ]b4_push_if([{label = YYACCEPT; break;}], + [return true;])[ + + /* Take a decision. First try without lookahead. */ + yyn = yypact_[yystate]; + if (yyPactValueIsDefault (yyn)) + { + label = YYDEFAULT; + break; + } +]b4_push_if([ /* Fall Through */ + + case YYGETTOKEN:])[ + /* Read a lookahead token. */ + if (yychar == YYEMPTY_) + { +]b4_push_if([[ + if (!push_token_consumed) + return YYPUSH_MORE;]b4_parse_trace_if([[ + yycdebug ("Reading a token");]])[ + yychar = yylextoken; + yylval = yylexval;]b4_locations_if([ + yylloc = yylexloc;])[ + push_token_consumed = false;]], [b4_parse_trace_if([[ + yycdebug ("Reading a token");]])[ + yychar = yylexer.yylex (); + yylval = yylexer.getLVal();]b4_locations_if([[ + yylloc = new ]b4_location_type[(yylexer.getStartPos(), + yylexer.getEndPos());]])[ +]])[ + } + + /* Convert token to internal form. */ + yytoken = yytranslate_ (yychar);]b4_parse_trace_if([[ + yySymbolPrint("Next token is", yytoken, + yylval]b4_locations_if([, yylloc])[);]])[ + + if (yytoken == ]b4_symbol(error, kind)[) + { + // The scanner already issued an error message, process directly + // to error recovery. But do not keep the error token as + // lookahead, it is too special and may lead us to an endless + // loop in error recovery. */ + yychar = Lexer.]b4_symbol(undef, id)[; + yytoken = ]b4_symbol(undef, kind)[;]b4_locations_if([[ + yyerrloc = yylloc;]])[ + label = YYERRLAB1; + } + else + { + /* If the proper action on seeing token YYTOKEN is to reduce or to + detect an error, take that action. */ + yyn += yytoken.getCode(); + if (yyn < 0 || YYLAST_ < yyn || yycheck_[yyn] != yytoken.getCode()) {]b4_lac_if([[ + if (!yylacEstablish(yystack, yytoken)) { + label = YYERRLAB; + } else]])[ + label = YYDEFAULT; + } + + /* <= 0 means reduce or error. */ + else if ((yyn = yytable_[yyn]) <= 0) + { + if (yyTableValueIsError(yyn)) { + label = YYERRLAB; + }]b4_lac_if([[ else if (!yylacEstablish(yystack, yytoken)) { + label = YYERRLAB; + }]])[ else { + yyn = -yyn; + label = YYREDUCE; + } + } + + else + { + /* Shift the lookahead token. */]b4_parse_trace_if([[ + yySymbolPrint("Shifting", yytoken, + yylval]b4_locations_if([, yylloc])[); +]])[ + /* Discard the token being shifted. */ + yychar = YYEMPTY_; + + /* Count tokens shifted since error; after three, turn off error + status. */ + if (yyerrstatus_ > 0) + --yyerrstatus_; + + yystate = yyn; + yystack.push(yystate, yylval]b4_locations_if([, yylloc])[);]b4_lac_if([[ + yylacDiscard("shift");]])[ + label = YYNEWSTATE; + } + } + break; + + /*-----------------------------------------------------------. + | yydefault -- do the default action for the current state. | + `-----------------------------------------------------------*/ + case YYDEFAULT: + yyn = yydefact_[yystate]; + if (yyn == 0) + label = YYERRLAB; + else + label = YYREDUCE; + break; + + /*-----------------------------. + | yyreduce -- Do a reduction. | + `-----------------------------*/ + case YYREDUCE: + yylen = yyr2_[yyn]; + label = yyaction(yyn, yystack, yylen); + yystate = yystack.stateAt(0); + break; + + /*------------------------------------. + | yyerrlab -- here on detecting error | + `------------------------------------*/ + case YYERRLAB: + /* If not already recovering from an error, report this error. */ + if (yyerrstatus_ == 0) + { + ++yynerrs; + if (yychar == YYEMPTY_) + yytoken = null; + yyreportSyntaxError(new Context(this, yystack, yytoken]b4_locations_if([[, yylloc]])[)); + } +]b4_locations_if([[ + yyerrloc = yylloc;]])[ + if (yyerrstatus_ == 3) + { + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ + + if (yychar <= Lexer.]b4_symbol(eof, id)[) + { + /* Return failure if at end of input. */ + if (yychar == Lexer.]b4_symbol(eof, id)[) + ]b4_push_if([{label = YYABORT; break;}], [return false;])[ + } + else + yychar = YYEMPTY_; + } + + /* Else will try to reuse lookahead token after shifting the error + token. */ + label = YYERRLAB1; + break; + + /*-------------------------------------------------. + | errorlab -- error raised explicitly by YYERROR. | + `-------------------------------------------------*/ + case YYERROR:]b4_locations_if([[ + yyerrloc = yystack.locationAt (yylen - 1);]])[ + /* Do not reclaim the symbols of the rule which action triggered + this YYERROR. */ + yystack.pop (yylen); + yylen = 0; + yystate = yystack.stateAt(0); + label = YYERRLAB1; + break; + + /*-------------------------------------------------------------. + | yyerrlab1 -- common code for both syntax error and YYERROR. | + `-------------------------------------------------------------*/ + case YYERRLAB1: + yyerrstatus_ = 3; /* Each real token shifted decrements this. */ + + // Pop stack until we find a state that shifts the error token. + for (;;) + { + yyn = yypact_[yystate]; + if (!yyPactValueIsDefault (yyn)) + { + yyn += ]b4_symbol(error, kind)[.getCode(); + if (0 <= yyn && yyn <= YYLAST_ + && yycheck_[yyn] == ]b4_symbol(error, kind)[.getCode()) + { + yyn = yytable_[yyn]; + if (0 < yyn) + break; + } + } + + /* Pop the current state because it cannot handle the + * error token. */ + if (yystack.height == 0) + ]b4_push_if([{label = YYABORT; break;}],[return false;])[ + +]b4_locations_if([[ + yyerrloc = yystack.locationAt (0);]])[ + yystack.pop (); + yystate = yystack.stateAt(0);]b4_parse_trace_if([[ + if (0 < yydebug) + yystack.print (yyDebugStream);]])[ + } + + if (label == YYABORT) + /* Leave the switch. */ + break; + +]b4_locations_if([[ + /* Muck with the stack to setup for yylloc. */ + yystack.push (0, null, yylloc); + yystack.push (0, null, yyerrloc); + yyloc = yylloc (yystack, 2); + yystack.pop (2);]])[ + + /* Shift the error token. */]b4_lac_if([[ + yylacDiscard("error recovery");]])[]b4_parse_trace_if([[ + yySymbolPrint("Shifting", SymbolKind.get(yystos_[yyn]), + yylval]b4_locations_if([, yyloc])[);]])[ + + yystate = yyn; + yystack.push (yyn, yylval]b4_locations_if([, yyloc])[); + label = YYNEWSTATE; + break; + + /* Accept. */ + case YYACCEPT: + ]b4_push_if([this.push_parse_initialized = false; return YYACCEPT;], + [return true;])[ + + /* Abort. */ + case YYABORT: + ]b4_push_if([this.push_parse_initialized = false; return YYABORT;], + [return false;])[ + } +} +]b4_push_if([[ + boolean push_parse_initialized = false; + + /** + * (Re-)Initialize the state of the push parser. + */ + public void push_parse_initialize () + { + /* Lookahead and lookahead in internal form. */ + this.yychar = YYEMPTY_; + this.yytoken = null; + + /* State. */ + this.yyn = 0; + this.yylen = 0; + this.yystate = 0; + this.yystack = new YYStack();]b4_lac_if([[ + this.yylacStack = new ArrayList(); + this.yylacEstablished = false;]])[ + this.label = YYNEWSTATE; + + /* Error handling. */ + this.yynerrs = 0;]b4_locations_if([[ + /* The location where the error started. */ + this.yyerrloc = null; + this.yylloc = new ]b4_location_type[ (null, null);]])[ + + /* Semantic value of the lookahead. */ + this.yylval = null; + + yystack.push (this.yystate, this.yylval]b4_locations_if([, this.yylloc])[); + + this.push_parse_initialized = true; + + } +]b4_locations_if([[ + /** + * Push parse given input from an external lexer. + * + * @@param yylextoken current token + * @@param yylexval current lval + * @@param yyylexpos current position + * + * @@return YYACCEPT, YYABORT, YYPUSH_MORE + */ + public int push_parse(int yylextoken, ]b4_yystype[ yylexval, ]b4_position_type[ yylexpos)]b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])[ { + return push_parse(yylextoken, yylexval, new ]b4_location_type[(yylexpos)); + } +]])])[ + +]b4_both_if([[ + /** + * Parse input from the scanner that was specified at object construction + * time. Return whether the end of the input was reached successfully. + * This version of parse() is defined only when api.push-push=both. + * + * @@return true if the parsing succeeds. Note that this does not + * imply that there were no syntax errors. + */ + public boolean parse()]b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])[ { + if (yylexer == null) + throw new NullPointerException("Null Lexer"); + int status; + do { + int token = yylexer.yylex(); + ]b4_yystype[ lval = yylexer.getLVal();]b4_locations_if([[ + ]b4_location_type[ yyloc = new ]b4_location_type[(yylexer.getStartPos(), yylexer.getEndPos()); + status = push_parse(token, lval, yyloc);]], [[ + status = push_parse(token, lval);]])[ + } while (status == YYPUSH_MORE); + return status == YYACCEPT; + } +]])[ + + /** + * Information needed to get the list of expected tokens and to forge + * a syntax error diagnostic. + */ + public static final class Context { + Context(]b4_parser_class[ parser, YYStack stack, SymbolKind token]b4_locations_if([[, ]b4_location_type[ loc]])[) { + yyparser = parser; + yystack = stack; + yytoken = token;]b4_locations_if([[ + yylocation = loc;]])[ + } + + private ]b4_parser_class[ yyparser; + private YYStack yystack; + + + /** + * The symbol kind of the lookahead token. + */ + public final SymbolKind getToken() { + return yytoken; + } + + private SymbolKind yytoken;]b4_locations_if([[ + + /** + * The location of the lookahead. + */ + public final ]b4_location_type[ getLocation() { + return yylocation; + } + + private ]b4_location_type[ yylocation;]])[ + static final int NTOKENS = ]b4_parser_class[.YYNTOKENS_; + + /** + * Put in YYARG at most YYARGN of the expected tokens given the + * current YYCTX, and return the number of tokens stored in YYARG. If + * YYARG is null, return the number of expected tokens (guaranteed to + * be less than YYNTOKENS). + */ + int getExpectedTokens(SymbolKind yyarg[], int yyargn) { + return getExpectedTokens (yyarg, 0, yyargn); + } + + int getExpectedTokens(SymbolKind yyarg[], int yyoffset, int yyargn) { + int yycount = yyoffset;]b4_lac_if([b4_parse_trace_if([[ + // Execute LAC once. We don't care if it is successful, we + // only do it for the sake of debugging output. + if (!yyparser.yylacEstablished) + yyparser.yylacCheck(yystack, yytoken); +]])[ + for (int yyx = 0; yyx < YYNTOKENS_; ++yyx) + { + SymbolKind yysym = SymbolKind.get(yyx); + if (yysym != ]b4_symbol(error, kind)[ + && yysym != ]b4_symbol(undef, kind)[ + && yyparser.yylacCheck(yystack, yysym)) + { + if (yyarg == null) + yycount += 1; + else if (yycount == yyargn) + return 0; + else + yyarg[yycount++] = yysym; + } + }]], [[ + int yyn = yypact_[this.yystack.stateAt(0)]; + if (!yyPactValueIsDefault(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 < NTOKENS ? yychecklim : NTOKENS; + for (int yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck_[yyx + yyn] == yyx && yyx != ]b4_symbol(error, kind)[.getCode() + && !yyTableValueIsError(yytable_[yyx + yyn])) + { + if (yyarg == null) + yycount += 1; + else if (yycount == yyargn) + return 0; // FIXME: this is incorrect. + else + yyarg[yycount++] = SymbolKind.get(yyx); + } + }]])[ + if (yyarg != null && yycount == yyoffset && yyoffset < yyargn) + yyarg[yycount] = null; + return yycount - yyoffset; + } + } + +]b4_lac_if([[ + /** Check the lookahead yytoken. + * \returns true iff the token will be eventually shifted. + */ + boolean yylacCheck(YYStack yystack, SymbolKind yytoken) + { + // Logically, the yylacStack's lifetime is confined to this function. + // Clear it, to get rid of potential left-overs from previous call. + yylacStack.clear(); + // Reduce until we encounter a shift and thereby accept the token. + yycdebugNnl("LAC: checking lookahead " + yytoken.getName() + ":"); + int lacTop = 0; + while (true) + { + int topState = (yylacStack.isEmpty() + ? yystack.stateAt(lacTop) + : yylacStack.get(yylacStack.size() - 1)); + int yyrule = yypact_[topState]; + if (yyPactValueIsDefault(yyrule) + || (yyrule += yytoken.getCode()) < 0 || YYLAST_ < yyrule + || yycheck_[yyrule] != yytoken.getCode()) + { + // Use the default action. + yyrule = yydefact_[+topState]; + if (yyrule == 0) { + yycdebug(" Err"); + return false; + } + } + else + { + // Use the action from yytable. + yyrule = yytable_[yyrule]; + if (yyTableValueIsError(yyrule)) { + yycdebug(" Err"); + return false; + } + if (0 < yyrule) { + yycdebug(" S" + yyrule); + return true; + } + yyrule = -yyrule; + } + // By now we know we have to simulate a reduce. + yycdebugNnl(" R" + (yyrule - 1)); + // Pop the corresponding number of values from the stack. + { + int yylen = yyr2_[yyrule]; + // First pop from the LAC stack as many tokens as possible. + int lacSize = yylacStack.size(); + if (yylen < lacSize) { + // yylacStack.setSize(lacSize - yylen); + for (/* Nothing */; 0 < yylen; yylen -= 1) { + yylacStack.remove(yylacStack.size() - 1); + } + yylen = 0; + } else if (lacSize != 0) { + yylacStack.clear(); + yylen -= lacSize; + } + // Only afterwards look at the main stack. + // We simulate popping elements by incrementing lacTop. + lacTop += yylen; + } + // Keep topState in sync with the updated stack. + topState = (yylacStack.isEmpty() + ? yystack.stateAt(lacTop) + : yylacStack.get(yylacStack.size() - 1)); + // Push the resulting state of the reduction. + int state = yyLRGotoState(topState, yyr1_[yyrule]); + yycdebugNnl(" G" + state); + yylacStack.add(state); + } + } + + /** Establish the initial context if no initial context currently exists. + * \returns true iff the token will be eventually shifted. + */ + boolean yylacEstablish(YYStack yystack, SymbolKind yytoken) { + /* Establish the initial context for the current lookahead if no initial + context is currently established. + + We define a context as a snapshot of the parser stacks. We define + the initial context for a lookahead as the context in which the + parser initially examines that lookahead in order to select a + syntactic action. Thus, if the lookahead eventually proves + syntactically unacceptable (possibly in a later context reached via a + series of reductions), the initial context can be used to determine + the exact set of tokens that would be syntactically acceptable in the + lookahead's place. Moreover, it is the context after which any + further semantic actions would be erroneous because they would be + determined by a syntactically unacceptable token. + + yylacEstablish should be invoked when a reduction is about to be + performed in an inconsistent state (which, for the purposes of LAC, + includes consistent states that don't know they're consistent because + their default reductions have been disabled). + + For parse.lac=full, the implementation of yylacEstablish is as + follows. If no initial context is currently established for the + current lookahead, then check if that lookahead can eventually be + shifted if syntactic actions continue from the current context. */ + if (yylacEstablished) { + return true; + } else { + yycdebug("LAC: initial context established for " + yytoken.getName()); + yylacEstablished = true; + return yylacCheck(yystack, yytoken); + } + } + + /** Discard any previous initial lookahead context because of event. + * \param event the event which caused the lookahead to be discarded. + * Only used for debbuging output. */ + void yylacDiscard(String event) { + /* Discard any previous initial lookahead context because of Event, + which may be a lookahead change or an invalidation of the currently + established initial context for the current lookahead. + + The most common example of a lookahead change is a shift. An example + of both cases is syntax error recovery. That is, a syntax error + occurs when the lookahead is syntactically erroneous for the + currently established initial context, so error recovery manipulates + the parser stacks to try to find a new initial context in which the + current lookahead is syntactically acceptable. If it fails to find + such a context, it discards the lookahead. */ + if (yylacEstablished) { + yycdebug("LAC: initial context discarded due to " + event); + yylacEstablished = false; + } + } + + /** The stack for LAC. + * Logically, the yylacStack's lifetime is confined to the function + * yylacCheck. We just store it as a member of this class to hold + * on to the memory and to avoid frequent reallocations. + */ + ArrayList yylacStack; + /** Whether an initial LAC context was established. */ + boolean yylacEstablished; +]])[ + +]b4_parse_error_bmatch( +[detailed\|verbose], [[ + private int yysyntaxErrorArguments(Context yyctx, SymbolKind[] yyarg, int yyargn) { + /* There are many possibilities here to consider: + - 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 tok) 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. (However, yychar is currently out + of scope during semantic actions.) + - 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. + */ + int yycount = 0; + if (yyctx.getToken() != null) + { + if (yyarg != null) + yyarg[yycount] = yyctx.getToken(); + yycount += 1; + yycount += yyctx.getExpectedTokens(yyarg, 1, yyargn); + } + return yycount; + } +]])[ + + /** + * Build and emit a "syntax error" message in a user-defined way. + * + * @@param ctx The context of the error. + */ + private void yyreportSyntaxError(Context yyctx) {]b4_parse_error_bmatch( +[custom], [[ + yylexer.reportSyntaxError(yyctx);]], +[detailed\|verbose], [[ + if (yyErrorVerbose) { + final int argmax = 5; + SymbolKind[] yyarg = new SymbolKind[argmax]; + int yycount = yysyntaxErrorArguments(yyctx, yyarg, argmax); + String[] yystr = new String[yycount]; + for (int yyi = 0; yyi < yycount; ++yyi) { + yystr[yyi] = yyarg[yyi].getName(); + } + String yyformat; + switch (yycount) { + default: + case 0: yyformat = ]b4_trans(["syntax error"])[; break; + case 1: yyformat = ]b4_trans(["syntax error, unexpected {0}"])[; break; + case 2: yyformat = ]b4_trans(["syntax error, unexpected {0}, expecting {1}"])[; break; + case 3: yyformat = ]b4_trans(["syntax error, unexpected {0}, expecting {1} or {2}"])[; break; + case 4: yyformat = ]b4_trans(["syntax error, unexpected {0}, expecting {1} or {2} or {3}"])[; break; + case 5: yyformat = ]b4_trans(["syntax error, unexpected {0}, expecting {1} or {2} or {3} or {4}"])[; break; + } + yyerror(]b4_locations_if([[yyctx.yylocation, ]])[new MessageFormat(yyformat).format(yystr)); + } else { + yyerror(]b4_locations_if([[yyctx.yylocation, ]])[]b4_trans(["syntax error"])[); + }]], +[simple], [[ + yyerror(]b4_locations_if([[yyctx.yylocation, ]])[]b4_trans(["syntax error"])[);]])[ + } + + /** + * Whether the given yypact_ value indicates a defaulted state. + * @@param yyvalue the value to check + */ + private static boolean yyPactValueIsDefault(int yyvalue) { + return yyvalue == yypact_ninf_; + } + + /** + * Whether the given yytable_ + * value indicates a syntax error. + * @@param yyvalue the value to check + */ + private static boolean yyTableValueIsError(int yyvalue) { + return yyvalue == yytable_ninf_; + } + + private static final ]b4_int_type_for([b4_pact])[ yypact_ninf_ = ]b4_pact_ninf[; + private static final ]b4_int_type_for([b4_table])[ yytable_ninf_ = ]b4_table_ninf[; + +]b4_parser_tables_define[ + +]b4_parse_trace_if([[ + ]b4_integral_parser_table_define([rline], [b4_rline], + [[YYRLINE[YYN] -- Source line where rule number YYN was defined.]])[ + + + // Report on the debug stream that the rule yyrule is going to be reduced. + private void yyReducePrint (int yyrule, YYStack yystack) + { + if (yydebug == 0) + return; + + int yylno = yyrline_[yyrule]; + int yynrhs = yyr2_[yyrule]; + /* Print the symbols being reduced, and their result. */ + yycdebug ("Reducing stack by rule " + (yyrule - 1) + + " (line " + yylno + "):"); + + /* The symbols being reduced. */ + for (int yyi = 0; yyi < yynrhs; yyi++) + yySymbolPrint(" $" + (yyi + 1) + " =", + SymbolKind.get(yystos_[yystack.stateAt(yynrhs - (yyi + 1))]), + ]b4_rhs_data(yynrhs, yyi + 1)b4_locations_if([, + b4_rhs_location(yynrhs, yyi + 1)])[); + }]])[ + + /* YYTRANSLATE_(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM + as returned by yylex, with out-of-bounds checking. */ + private static final SymbolKind yytranslate_(int t) +]b4_api_token_raw_if(dnl +[[ { + return SymbolKind.get(t); + } +]], +[[ { + // Last valid token kind. + int code_max = ]b4_code_max[; + if (t <= 0) + return ]b4_symbol(eof, kind)[; + else if (t <= code_max) + return SymbolKind.get(yytranslate_table_[t]); + else + return ]b4_symbol(undef, kind)[; + } + ]b4_integral_parser_table_define([translate_table], [b4_translate])[ +]])[ + + private static final int YYLAST_ = ]b4_last[; + private static final int YYEMPTY_ = -2; + private static final int YYFINAL_ = ]b4_final_state_number[; + private static final int YYNTOKENS_ = ]b4_tokens_number[; + +]b4_percent_code_get[ +} +]b4_percent_code_get([[epilogue]])[]dnl +b4_epilogue[]dnl +b4_output_end diff --git a/Engine/bin/bison-flex/data/skeletons/location.cc b/Engine/bin/bison-flex/data/skeletons/location.cc new file mode 100644 index 000000000..3870b2bcc --- /dev/null +++ b/Engine/bin/bison-flex/data/skeletons/location.cc @@ -0,0 +1,380 @@ +# C++ skeleton for Bison + +# Copyright (C) 2002-2015, 2018-2021 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +m4_pushdef([b4_copyright_years], + [2002-2015, 2018-2021]) + + +# b4_location_file +# ---------------- +# Name of the file containing the position/location class, +# if we want this file. +b4_percent_define_check_file([b4_location_file], + [[api.location.file]], + b4_header_if([[location.hh]])) + +# b4_location_include +# ------------------- +# If location.hh is to be generated, the name under which should it be +# included. +# +# b4_location_path +# ---------------- +# The path to use for the CPP guard. +m4_ifdef([b4_location_file], +[m4_define([b4_location_include], + [b4_percent_define_get([[api.location.include]], + ["b4_location_file"])]) + m4_define([b4_location_path], + b4_percent_define_get([[api.location.include]], + ["b4_mapped_dir_prefix[]b4_location_file"])) + m4_define([b4_location_path], + m4_substr(m4_defn([b4_location_path]), 1, m4_eval(m4_len(m4_defn([b4_location_path])) - 2))) + ]) + + +# b4_position_file +# ---------------- +# Name of the file containing the position class, if we want this file. +b4_header_if( + [b4_required_version_if( + [30200], [], + [m4_ifdef([b4_location_file], + [m4_define([b4_position_file], [position.hh])])])]) + + + +# b4_location_define +# ------------------ +# Define the position and location classes. +m4_define([b4_location_define], +[[ /// A point in a source file. + class position + { + public: + /// Type for file name. + typedef ]b4_percent_define_get([[api.filename.type]])[ filename_type; + /// Type for line and column numbers. + typedef int counter_type; +]m4_ifdef([b4_location_constructors], [[ + /// Construct a position. + explicit position (filename_type* f = YY_NULLPTR, + counter_type l = ]b4_location_initial_line[, + counter_type c = ]b4_location_initial_column[) + : filename (f) + , line (l) + , column (c) + {} + +]])[ + /// Initialization. + void initialize (filename_type* fn = YY_NULLPTR, + counter_type l = ]b4_location_initial_line[, + counter_type c = ]b4_location_initial_column[) + { + filename = fn; + line = l; + column = c; + } + + /** \name Line and Column related manipulators + ** \{ */ + /// (line related) Advance to the COUNT next lines. + void lines (counter_type count = 1) + { + if (count) + { + column = ]b4_location_initial_column[; + line = add_ (line, count, ]b4_location_initial_line[); + } + } + + /// (column related) Advance to the COUNT next columns. + void columns (counter_type count = 1) + { + column = add_ (column, count, ]b4_location_initial_column[); + } + /** \} */ + + /// File name to which this position refers. + filename_type* filename; + /// Current line number. + counter_type line; + /// Current column number. + counter_type column; + + private: + /// Compute max (min, lhs+rhs). + static counter_type add_ (counter_type lhs, counter_type rhs, counter_type min) + { + return lhs + rhs < min ? min : lhs + rhs; + } + }; + + /// Add \a width columns, in place. + inline position& + operator+= (position& res, position::counter_type width) + { + res.columns (width); + return res; + } + + /// Add \a width columns. + inline position + operator+ (position res, position::counter_type width) + { + return res += width; + } + + /// Subtract \a width columns, in place. + inline position& + operator-= (position& res, position::counter_type width) + { + return res += -width; + } + + /// Subtract \a width columns. + inline position + operator- (position res, position::counter_type width) + { + return res -= width; + } +]b4_percent_define_flag_if([[define_location_comparison]], [[ + /// Compare two position objects. + inline bool + operator== (const position& pos1, const position& pos2) + { + return (pos1.line == pos2.line + && pos1.column == pos2.column + && (pos1.filename == pos2.filename + || (pos1.filename && pos2.filename + && *pos1.filename == *pos2.filename))); + } + + /// Compare two position objects. + inline bool + operator!= (const position& pos1, const position& pos2) + { + return !(pos1 == pos2); + } +]])[ + /** \brief Intercept output stream redirection. + ** \param ostr the destination output stream + ** \param pos a reference to the position to redirect + */ + template + std::basic_ostream& + operator<< (std::basic_ostream& ostr, const position& pos) + { + if (pos.filename) + ostr << *pos.filename << ':'; + return ostr << pos.line << '.' << pos.column; + } + + /// Two points in a source file. + class location + { + public: + /// Type for file name. + typedef position::filename_type filename_type; + /// Type for line and column numbers. + typedef position::counter_type counter_type; +]m4_ifdef([b4_location_constructors], [ + /// Construct a location from \a b to \a e. + location (const position& b, const position& e) + : begin (b) + , end (e) + {} + + /// Construct a 0-width location in \a p. + explicit location (const position& p = position ()) + : begin (p) + , end (p) + {} + + /// Construct a 0-width location in \a f, \a l, \a c. + explicit location (filename_type* f, + counter_type l = ]b4_location_initial_line[, + counter_type c = ]b4_location_initial_column[) + : begin (f, l, c) + , end (f, l, c) + {} + +])[ + /// Initialization. + void initialize (filename_type* f = YY_NULLPTR, + counter_type l = ]b4_location_initial_line[, + counter_type c = ]b4_location_initial_column[) + { + begin.initialize (f, l, c); + end = begin; + } + + /** \name Line and Column related manipulators + ** \{ */ + public: + /// Reset initial location to final location. + void step () + { + begin = end; + } + + /// Extend the current location to the COUNT next columns. + void columns (counter_type count = 1) + { + end += count; + } + + /// Extend the current location to the COUNT next lines. + void lines (counter_type count = 1) + { + end.lines (count); + } + /** \} */ + + + public: + /// Beginning of the located region. + position begin; + /// End of the located region. + position end; + }; + + /// Join two locations, in place. + inline location& + operator+= (location& res, const location& end) + { + res.end = end.end; + return res; + } + + /// Join two locations. + inline location + operator+ (location res, const location& end) + { + return res += end; + } + + /// Add \a width columns to the end position, in place. + inline location& + operator+= (location& res, location::counter_type width) + { + res.columns (width); + return res; + } + + /// Add \a width columns to the end position. + inline location + operator+ (location res, location::counter_type width) + { + return res += width; + } + + /// Subtract \a width columns to the end position, in place. + inline location& + operator-= (location& res, location::counter_type width) + { + return res += -width; + } + + /// Subtract \a width columns to the end position. + inline location + operator- (location res, location::counter_type width) + { + return res -= width; + } +]b4_percent_define_flag_if([[define_location_comparison]], [[ + /// Compare two location objects. + inline bool + operator== (const location& loc1, const location& loc2) + { + return loc1.begin == loc2.begin && loc1.end == loc2.end; + } + + /// Compare two location objects. + inline bool + operator!= (const location& loc1, const location& loc2) + { + return !(loc1 == loc2); + } +]])[ + /** \brief Intercept output stream redirection. + ** \param ostr the destination output stream + ** \param loc a reference to the location to redirect + ** + ** Avoid duplicate information. + */ + template + std::basic_ostream& + operator<< (std::basic_ostream& ostr, const location& loc) + { + location::counter_type end_col + = 0 < loc.end.column ? loc.end.column - 1 : 0; + ostr << loc.begin; + if (loc.end.filename + && (!loc.begin.filename + || *loc.begin.filename != *loc.end.filename)) + ostr << '-' << loc.end.filename << ':' << loc.end.line << '.' << end_col; + else if (loc.begin.line < loc.end.line) + ostr << '-' << loc.end.line << '.' << end_col; + else if (loc.begin.column < end_col) + ostr << '-' << end_col; + return ostr; + } +]]) + + +m4_ifdef([b4_position_file], [[ +]b4_output_begin([b4_dir_prefix], [b4_position_file])[ +]b4_generated_by[ +// Starting with Bison 3.2, this file is useless: the structure it +// used to define is now defined in "]b4_location_file[". +// +// To get rid of this file: +// 1. add '%require "3.2"' (or newer) to your grammar file +// 2. remove references to this file from your build system +// 3. if you used to include it, include "]b4_location_file[" instead. + +#include ]b4_location_include[ +]b4_output_end[ +]]) + + +m4_ifdef([b4_location_file], [[ +]b4_output_begin([b4_dir_prefix], [b4_location_file])[ +]b4_copyright([Locations for Bison parsers in C++])[ +/** + ** \file ]b4_location_path[ + ** Define the ]b4_namespace_ref[::location class. + */ + +]b4_cpp_guard_open([b4_location_path])[ + +# include +# include + +]b4_null_define[ + +]b4_namespace_open[ +]b4_location_define[ +]b4_namespace_close[ +]b4_cpp_guard_close([b4_location_path])[ +]b4_output_end[ +]]) + + +m4_popdef([b4_copyright_years]) diff --git a/Engine/bin/bison-flex/data/skeletons/stack.hh b/Engine/bin/bison-flex/data/skeletons/stack.hh new file mode 100644 index 000000000..98913258f --- /dev/null +++ b/Engine/bin/bison-flex/data/skeletons/stack.hh @@ -0,0 +1,157 @@ +# C++ skeleton for Bison + +# Copyright (C) 2002-2015, 2018-2021 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +# b4_stack_file +# ------------- +# Name of the file containing the stack class, if we want this file. +b4_header_if([b4_required_version_if([30200], [], + [m4_define([b4_stack_file], [stack.hh])])]) + + +# b4_stack_define +# --------------- +m4_define([b4_stack_define], +[[ /// A stack with random access from its top. + template > + class stack + { + public: + // Hide our reversed order. + typedef typename S::iterator iterator; + typedef typename S::const_iterator const_iterator; + typedef typename S::size_type size_type; + typedef typename std::ptrdiff_t index_type; + + stack (size_type n = 200) YY_NOEXCEPT + : seq_ (n) + {} + +#if 201103L <= YY_CPLUSPLUS + /// Non copyable. + stack (const stack&) = delete; + /// Non copyable. + stack& operator= (const stack&) = delete; +#endif + + /// Random access. + /// + /// Index 0 returns the topmost element. + const T& + operator[] (index_type i) const + { + return seq_[size_type (size () - 1 - i)]; + } + + /// Random access. + /// + /// Index 0 returns the topmost element. + T& + operator[] (index_type i) + { + return seq_[size_type (size () - 1 - i)]; + } + + /// Steal the contents of \a t. + /// + /// Close to move-semantics. + void + push (YY_MOVE_REF (T) t) + { + seq_.push_back (T ()); + operator[] (0).move (t); + } + + /// Pop elements from the stack. + void + pop (std::ptrdiff_t n = 1) YY_NOEXCEPT + { + for (; 0 < n; --n) + seq_.pop_back (); + } + + /// Pop all elements from the stack. + void + clear () YY_NOEXCEPT + { + seq_.clear (); + } + + /// Number of elements on the stack. + index_type + size () const YY_NOEXCEPT + { + return index_type (seq_.size ()); + } + + /// Iterator on top of the stack (going downwards). + const_iterator + begin () const YY_NOEXCEPT + { + return seq_.begin (); + } + + /// Bottom of the stack. + const_iterator + end () const YY_NOEXCEPT + { + return seq_.end (); + } + + /// Present a slice of the top of a stack. + class slice + { + public: + slice (const stack& stack, index_type range) YY_NOEXCEPT + : stack_ (stack) + , range_ (range) + {} + + const T& + operator[] (index_type i) const + { + return stack_[range_ - i]; + } + + private: + const stack& stack_; + index_type range_; + }; + + private: +#if YY_CPLUSPLUS < 201103L + /// Non copyable. + stack (const stack&); + /// Non copyable. + stack& operator= (const stack&); +#endif + /// The wrapped container. + S seq_; + }; +]]) + +m4_ifdef([b4_stack_file], +[b4_output_begin([b4_dir_prefix], [b4_stack_file])[ +]b4_generated_by[ +// Starting with Bison 3.2, this file is useless: the structure it +// used to define is now defined with the parser itself. +// +// To get rid of this file: +// 1. add '%require "3.2"' (or newer) to your grammar file +// 2. remove references to this file from your build system. +]b4_output_end[ +]]) diff --git a/Engine/bin/bison-flex/data/skeletons/traceon.m4 b/Engine/bin/bison-flex/data/skeletons/traceon.m4 new file mode 100644 index 000000000..344d7d1c5 --- /dev/null +++ b/Engine/bin/bison-flex/data/skeletons/traceon.m4 @@ -0,0 +1,2 @@ +dnl GNU M4 treats -dV in a position-independent manner. +m4_debugmode(V)m4_traceon()dnl diff --git a/Engine/bin/bison-flex/data/skeletons/variant.hh b/Engine/bin/bison-flex/data/skeletons/variant.hh new file mode 100644 index 000000000..2a490e8fa --- /dev/null +++ b/Engine/bin/bison-flex/data/skeletons/variant.hh @@ -0,0 +1,525 @@ +# C++ skeleton for Bison + +# Copyright (C) 2002-2015, 2018-2021 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +## --------- ## +## variant. ## +## --------- ## + +# b4_assert +# --------- +# The name of YY_ASSERT. +m4_define([b4_assert], + [b4_api_PREFIX[]_ASSERT]) + + +# b4_symbol_variant(YYTYPE, YYVAL, ACTION, [ARGS]) +# ------------------------------------------------ +# Run some ACTION ("build", or "destroy") on YYVAL of symbol type +# YYTYPE. +m4_define([b4_symbol_variant], +[m4_pushdef([b4_dollar_dollar], + [$2.$3< $][3 > (m4_shift3($@))])dnl +switch ($1) + { +b4_type_foreach([_b4_type_action])[]dnl + default: + break; + } +m4_popdef([b4_dollar_dollar])dnl +]) + + +# _b4_char_sizeof_counter +# ----------------------- +# A counter used by _b4_char_sizeof_dummy to create fresh symbols. +m4_define([_b4_char_sizeof_counter], +[0]) + +# _b4_char_sizeof_dummy +# --------------------- +# At each call return a new C++ identifier. +m4_define([_b4_char_sizeof_dummy], +[m4_define([_b4_char_sizeof_counter], m4_incr(_b4_char_sizeof_counter))dnl +dummy[]_b4_char_sizeof_counter]) + + +# b4_char_sizeof(SYMBOL-NUMS) +# --------------------------- +# To be mapped on the list of type names to produce: +# +# char dummy1[sizeof (type_name_1)]; +# char dummy2[sizeof (type_name_2)]; +# +# for defined type names. +m4_define([b4_char_sizeof], +[b4_symbol_if([$1], [has_type], +[ +m4_map([ b4_symbol_tag_comment], [$@])dnl + char _b4_char_sizeof_dummy@{sizeof (b4_symbol([$1], [type]))@}; +])]) + + +# b4_variant_includes +# ------------------- +# The needed includes for variants support. +m4_define([b4_variant_includes], +[b4_parse_assert_if([[#include +#ifndef ]b4_assert[ +# include +# define ]b4_assert[ assert +#endif +]])]) + + + +## -------------------------- ## +## Adjustments for variants. ## +## -------------------------- ## + + +# b4_value_type_declare +# --------------------- +# Define value_type. +m4_define([b4_value_type_declare], +[[ /// A buffer to store and retrieve objects. + /// + /// Sort of a variant, but does not keep track of the nature + /// of the stored data, since that knowledge is available + /// via the current parser state. + class value_type + { + public: + /// Type of *this. + typedef value_type self_type; + + /// Empty construction. + value_type () YY_NOEXCEPT + : yyraw_ ()]b4_parse_assert_if([ + , yytypeid_ (YY_NULLPTR)])[ + {} + + /// Construct and fill. + template + value_type (YY_RVREF (T) t)]b4_parse_assert_if([ + : yytypeid_ (&typeid (T))])[ + {]b4_parse_assert_if([[ + ]b4_assert[ (sizeof (T) <= size);]])[ + new (yyas_ ()) T (YY_MOVE (t)); + } + +#if 201103L <= YY_CPLUSPLUS + /// Non copyable. + value_type (const self_type&) = delete; + /// Non copyable. + self_type& operator= (const self_type&) = delete; +#endif + + /// Destruction, allowed only if empty. + ~value_type () YY_NOEXCEPT + {]b4_parse_assert_if([ + ]b4_assert[ (!yytypeid_); + ])[} + +# if 201103L <= YY_CPLUSPLUS + /// Instantiate a \a T in here from \a t. + template + T& + emplace (U&&... u) + {]b4_parse_assert_if([[ + ]b4_assert[ (!yytypeid_); + ]b4_assert[ (sizeof (T) <= size); + yytypeid_ = & typeid (T);]])[ + return *new (yyas_ ()) T (std::forward (u)...); + } +# else + /// Instantiate an empty \a T in here. + template + T& + emplace () + {]b4_parse_assert_if([[ + ]b4_assert[ (!yytypeid_); + ]b4_assert[ (sizeof (T) <= size); + yytypeid_ = & typeid (T);]])[ + return *new (yyas_ ()) T (); + } + + /// Instantiate a \a T in here from \a t. + template + T& + emplace (const T& t) + {]b4_parse_assert_if([[ + ]b4_assert[ (!yytypeid_); + ]b4_assert[ (sizeof (T) <= size); + yytypeid_ = & typeid (T);]])[ + return *new (yyas_ ()) T (t); + } +# endif + + /// Instantiate an empty \a T in here. + /// Obsolete, use emplace. + template + T& + build () + { + return emplace (); + } + + /// Instantiate a \a T in here from \a t. + /// Obsolete, use emplace. + template + T& + build (const T& t) + { + return emplace (t); + } + + /// Accessor to a built \a T. + template + T& + as () YY_NOEXCEPT + {]b4_parse_assert_if([[ + ]b4_assert[ (yytypeid_); + ]b4_assert[ (*yytypeid_ == typeid (T)); + ]b4_assert[ (sizeof (T) <= size);]])[ + return *yyas_ (); + } + + /// Const accessor to a built \a T (for %printer). + template + const T& + as () const YY_NOEXCEPT + {]b4_parse_assert_if([[ + ]b4_assert[ (yytypeid_); + ]b4_assert[ (*yytypeid_ == typeid (T)); + ]b4_assert[ (sizeof (T) <= size);]])[ + return *yyas_ (); + } + + /// Swap the content with \a that, of same type. + /// + /// Both variants must be built beforehand, because swapping the actual + /// data requires reading it (with as()), and this is not possible on + /// unconstructed variants: it would require some dynamic testing, which + /// should not be the variant's responsibility. + /// Swapping between built and (possibly) non-built is done with + /// self_type::move (). + template + void + swap (self_type& that) YY_NOEXCEPT + {]b4_parse_assert_if([[ + ]b4_assert[ (yytypeid_); + ]b4_assert[ (*yytypeid_ == *that.yytypeid_);]])[ + std::swap (as (), that.as ()); + } + + /// Move the content of \a that to this. + /// + /// Destroys \a that. + template + void + move (self_type& that) + { +# if 201103L <= YY_CPLUSPLUS + emplace (std::move (that.as ())); +# else + emplace (); + swap (that); +# endif + that.destroy (); + } + +# if 201103L <= YY_CPLUSPLUS + /// Move the content of \a that to this. + template + void + move (self_type&& that) + { + emplace (std::move (that.as ())); + that.destroy (); + } +#endif + + /// Copy the content of \a that to this. + template + void + copy (const self_type& that) + { + emplace (that.as ()); + } + + /// Destroy the stored \a T. + template + void + destroy () + { + as ().~T ();]b4_parse_assert_if([ + yytypeid_ = YY_NULLPTR;])[ + } + + private: +#if YY_CPLUSPLUS < 201103L + /// Non copyable. + value_type (const self_type&); + /// Non copyable. + self_type& operator= (const self_type&); +#endif + + /// Accessor to raw memory as \a T. + template + T* + yyas_ () YY_NOEXCEPT + { + void *yyp = yyraw_; + return static_cast (yyp); + } + + /// Const accessor to raw memory as \a T. + template + const T* + yyas_ () const YY_NOEXCEPT + { + const void *yyp = yyraw_; + return static_cast (yyp); + } + + /// An auxiliary type to compute the largest semantic type. + union union_type + {]b4_type_foreach([b4_char_sizeof])[ }; + + /// The size of the largest semantic type. + enum { size = sizeof (union_type) }; + + /// A buffer to store semantic values. + union + { + /// Strongest alignment constraints. + long double yyalign_me_; + /// A buffer large enough to store any of the semantic values. + char yyraw_[size]; + };]b4_parse_assert_if([ + + /// Whether the content is built: if defined, the name of the stored type. + const std::type_info *yytypeid_;])[ + }; +]]) + + +# How the semantic value is extracted when using variants. + +# b4_symbol_value(VAL, SYMBOL-NUM, [TYPE]) +# ---------------------------------------- +# See README. +m4_define([b4_symbol_value], +[m4_ifval([$3], + [$1.as< $3 > ()], + [m4_ifval([$2], + [b4_symbol_if([$2], [has_type], + [$1.as < b4_symbol([$2], [type]) > ()], + [$1])], + [$1])])]) + +# b4_symbol_value_template(VAL, SYMBOL-NUM, [TYPE]) +# ------------------------------------------------- +# Same as b4_symbol_value, but used in a template method. +m4_define([b4_symbol_value_template], +[m4_ifval([$3], + [$1.template as< $3 > ()], + [m4_ifval([$2], + [b4_symbol_if([$2], [has_type], + [$1.template as < b4_symbol([$2], [type]) > ()], + [$1])], + [$1])])]) + + + +## ------------- ## +## make_SYMBOL. ## +## ------------- ## + + +# _b4_includes_tokens(SYMBOL-NUM...) +# ---------------------------------- +# Expands to non-empty iff one of the SYMBOL-NUM denotes +# a token. +m4_define([_b4_is_token], + [b4_symbol_if([$1], [is_token], [1])]) +m4_define([_b4_includes_tokens], + [m4_map([_b4_is_token], [$@])]) + + +# _b4_token_maker_define(SYMBOL-NUM) +# ---------------------------------- +# Declare make_SYMBOL for SYMBOL-NUM. Use at class-level. +m4_define([_b4_token_maker_define], +[b4_token_visible_if([$1], +[#if 201103L <= YY_CPLUSPLUS + static + symbol_type + make_[]_b4_symbol([$1], [id]) (b4_join( + b4_symbol_if([$1], [has_type], + [b4_symbol([$1], [type]) v]), + b4_locations_if([location_type l]))) + { + return symbol_type (b4_join([token::b4_symbol([$1], [id])], + b4_symbol_if([$1], [has_type], [std::move (v)]), + b4_locations_if([std::move (l)]))); + } +#else + static + symbol_type + make_[]_b4_symbol([$1], [id]) (b4_join( + b4_symbol_if([$1], [has_type], + [const b4_symbol([$1], [type])& v]), + b4_locations_if([const location_type& l]))) + { + return symbol_type (b4_join([token::b4_symbol([$1], [id])], + b4_symbol_if([$1], [has_type], [v]), + b4_locations_if([l]))); + } +#endif +])]) + + +# b4_token_kind(SYMBOL-NUM) +# ------------------------- +# Some tokens don't have an ID. +m4_define([b4_token_kind], +[b4_symbol_if([$1], [has_id], + [token::b4_symbol([$1], [id])], + [b4_symbol([$1], [code])])]) + + +# _b4_tok_in(SYMBOL-NUM, ...) +# --------------------------- +# See b4_tok_in below. The SYMBOL-NUMs... are tokens only. +# +# We iterate over the tokens to group them by "range" of token numbers (not +# symbols numbers!). +# +# b4_fst is the start of that range. +# b4_prev is the previous value. +# b4_val is the current value. +# If b4_val is the successor of b4_prev in token numbers, update the latter, +# otherwise emit the code for range b4_fst .. b4_prev. +# $1 is also used as a terminator in the foreach, but it will not be printed. +# +m4_define([_b4_tok_in], +[m4_pushdef([b4_prev], [$1])dnl +m4_pushdef([b4_fst], [$1])dnl +m4_pushdef([b4_sep], [])dnl +m4_foreach([b4_val], m4_dquote(m4_shift($@, $1)), + [m4_if(b4_symbol(b4_val, [code]), m4_eval(b4_symbol(b4_prev, [code]) + 1), [], + [b4_sep[]m4_if(b4_fst, b4_prev, + [tok == b4_token_kind(b4_fst)], + [(b4_token_kind(b4_fst) <= tok && tok <= b4_token_kind(b4_prev))])[]dnl +m4_define([b4_fst], b4_val)dnl +m4_define([b4_sep], [ + || ])])dnl +m4_define([b4_prev], b4_val)])dnl +m4_popdef([b4_sep])dnl +m4_popdef([b4_fst])dnl +m4_popdef([b4_prev])dnl +]) + + +# _b4_filter_tokens(SYMBOL-NUM, ...) +# ---------------------------------- +# Expand as the list of tokens amongst SYMBOL-NUM. +m4_define([_b4_filter_tokens], +[m4_pushdef([b4_sep])dnl +m4_foreach([b4_val], [$@], + [b4_symbol_if(b4_val, [is_token], [b4_sep[]b4_val[]m4_define([b4_sep], [,])])])dnl +m4_popdef([b4_sep])dnl +]) + + +# b4_tok_in(SYMBOL-NUM, ...) +# --------------------------- +# A C++ conditional that checks that `tok` is a member of this list of symbol +# numbers. +m4_define([b4_tok_in], + [_$0(_b4_filter_tokens($@))]) + + + + +# _b4_symbol_constructor_define(SYMBOL-NUM...) +# -------------------------------------------- +# Define a symbol_type constructor common to all the SYMBOL-NUM (they +# have the same type). Use at class-level. +m4_define([_b4_symbol_constructor_define], +[m4_ifval(_b4_includes_tokens($@), +[[#if 201103L <= YY_CPLUSPLUS + symbol_type (]b4_join( + [int tok], + b4_symbol_if([$1], [has_type], + [b4_symbol([$1], [type]) v]), + b4_locations_if([location_type l]))[) + : super_type (]b4_join([token_kind_type (tok)], + b4_symbol_if([$1], [has_type], [std::move (v)]), + b4_locations_if([std::move (l)]))[) +#else + symbol_type (]b4_join( + [int tok], + b4_symbol_if([$1], [has_type], + [const b4_symbol([$1], [type])& v]), + b4_locations_if([const location_type& l]))[) + : super_type (]b4_join([token_kind_type (tok)], + b4_symbol_if([$1], [has_type], [v]), + b4_locations_if([l]))[) +#endif + {]b4_parse_assert_if([[ +#if !defined _MSC_VER || defined __clang__ + ]b4_assert[ (]b4_tok_in($@)[); +#endif + ]])[} +]])]) + + +# b4_basic_symbol_constructor_define(SYMBOL-NUM) +# ---------------------------------------------- +# Generate a constructor for basic_symbol from given type. +m4_define([b4_basic_symbol_constructor_define], +[[#if 201103L <= YY_CPLUSPLUS + basic_symbol (]b4_join( + [typename Base::kind_type t], + b4_symbol_if([$1], [has_type], [b4_symbol([$1], [type])&& v]), + b4_locations_if([location_type&& l]))[) + : Base (t)]b4_symbol_if([$1], [has_type], [ + , value (std::move (v))])[]b4_locations_if([ + , location (std::move (l))])[ + {} +#else + basic_symbol (]b4_join( + [typename Base::kind_type t], + b4_symbol_if([$1], [has_type], [const b4_symbol([$1], [type])& v]), + b4_locations_if([const location_type& l]))[) + : Base (t)]b4_symbol_if([$1], [has_type], [ + , value (v)])[]b4_locations_if([ + , location (l)])[ + {} +#endif +]]) + + +# b4_token_constructor_define +# --------------------------- +# Define the overloaded versions of make_FOO for all the token kinds. +m4_define([b4_token_constructor_define], +[ // Implementation of make_symbol for each token kind. +b4_symbol_foreach([_b4_token_maker_define])]) diff --git a/Engine/bin/bison-flex/data/skeletons/yacc.c b/Engine/bin/bison-flex/data/skeletons/yacc.c new file mode 100644 index 000000000..64b9ac625 --- /dev/null +++ b/Engine/bin/bison-flex/data/skeletons/yacc.c @@ -0,0 +1,2209 @@ +# -*- C -*- +# Yacc compatible skeleton for Bison + +# Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software +# Foundation, Inc. + +m4_pushdef([b4_copyright_years], + [1984, 1989-1990, 2000-2015, 2018-2021]) + +# 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +m4_include(b4_skeletonsdir/[c.m4]) + + +## ---------- ## +## api.pure. ## +## ---------- ## + +b4_percent_define_default([[api.pure]], [[false]]) +b4_percent_define_check_values([[[[api.pure]], + [[false]], [[true]], [[]], [[full]]]]) + +m4_define([b4_pure_flag], [[0]]) +m4_case(b4_percent_define_get([[api.pure]]), + [false], [m4_define([b4_pure_flag], [[0]])], + [true], [m4_define([b4_pure_flag], [[1]])], + [], [m4_define([b4_pure_flag], [[1]])], + [full], [m4_define([b4_pure_flag], [[2]])]) + +m4_define([b4_pure_if], +[m4_case(b4_pure_flag, + [0], [$2], + [1], [$1], + [2], [$1])]) + [m4_fatal([invalid api.pure value: ]$1)])]) + +## --------------- ## +## api.push-pull. ## +## --------------- ## + +# b4_pull_if, b4_push_if +# ---------------------- +# Whether the pull/push APIs are needed. Both can be enabled. + +b4_percent_define_default([[api.push-pull]], [[pull]]) +b4_percent_define_check_values([[[[api.push-pull]], + [[pull]], [[push]], [[both]]]]) +b4_define_flag_if([pull]) m4_define([b4_pull_flag], [[1]]) +b4_define_flag_if([push]) m4_define([b4_push_flag], [[1]]) +m4_case(b4_percent_define_get([[api.push-pull]]), + [pull], [m4_define([b4_push_flag], [[0]])], + [push], [m4_define([b4_pull_flag], [[0]])]) + +# Handle BISON_USE_PUSH_FOR_PULL for the test suite. So that push parsing +# tests function as written, do not let BISON_USE_PUSH_FOR_PULL modify the +# behavior of Bison at all when push parsing is already requested. +b4_define_flag_if([use_push_for_pull]) +b4_use_push_for_pull_if([ + b4_push_if([m4_define([b4_use_push_for_pull_flag], [[0]])], + [m4_define([b4_push_flag], [[1]])])]) + +## ----------- ## +## parse.lac. ## +## ----------- ## + +b4_percent_define_default([[parse.lac]], [[none]]) +b4_percent_define_default([[parse.lac.es-capacity-initial]], [[20]]) +b4_percent_define_default([[parse.lac.memory-trace]], [[failures]]) +b4_percent_define_check_values([[[[parse.lac]], [[full]], [[none]]]], + [[[[parse.lac.memory-trace]], + [[failures]], [[full]]]]) +b4_define_flag_if([lac]) +m4_define([b4_lac_flag], + [m4_if(b4_percent_define_get([[parse.lac]]), + [none], [[0]], [[1]])]) + +## ---------------- ## +## Default values. ## +## ---------------- ## + +# Stack parameters. +m4_define_default([b4_stack_depth_max], [10000]) +m4_define_default([b4_stack_depth_init], [200]) + + +# b4_yyerror_arg_loc_if(ARG) +# -------------------------- +# Expand ARG iff yyerror is to be given a location as argument. +m4_define([b4_yyerror_arg_loc_if], +[b4_locations_if([m4_case(b4_pure_flag, + [1], [m4_ifset([b4_parse_param], [$1])], + [2], [$1])])]) + +# b4_yyerror_formals +# ------------------ +m4_define([b4_yyerror_formals], +[b4_pure_if([b4_locations_if([, [[const ]b4_api_PREFIX[LTYPE *yyllocp], [&yylloc]]])[]dnl +m4_ifdef([b4_parse_param], [, b4_parse_param])[]dnl +,])dnl +[[const char *msg], [msg]]]) + + + +# b4_yyerror_args +# --------------- +# Arguments passed to yyerror: user args plus yylloc. +m4_define([b4_yyerror_args], +[b4_yyerror_arg_loc_if([&yylloc, ])dnl +m4_ifset([b4_parse_param], [b4_args(b4_parse_param), ])]) + + + +## ----------------- ## +## Semantic Values. ## +## ----------------- ## + + +# b4_accept([SYMBOL-NUM]) +# ----------------------- +# Used in actions of the rules of accept, the initial symbol, to call +# YYACCEPT. If SYMBOL-NUM is specified, run "yyvalue->SLOT = $2;" +# before, using the slot of SYMBOL-NUM. +m4_define([b4_accept], +[m4_ifval([$1], + [b4_symbol_value(yyimpl->yyvalue, [$1]) = b4_rhs_value(2, 1, [$1]); ]) YYACCEPT]) + + +# b4_lhs_value(SYMBOL-NUM, [TYPE]) +# -------------------------------- +# See README. +m4_define([b4_lhs_value], +[b4_symbol_value(yyval, [$1], [$2])]) + + +# b4_rhs_value(RULE-LENGTH, POS, [SYMBOL-NUM], [TYPE]) +# ---------------------------------------------------- +# See README. +m4_define([b4_rhs_value], +[b4_symbol_value([yyvsp@{b4_subtract([$2], [$1])@}], [$3], [$4])]) + + +## ----------- ## +## Locations. ## +## ----------- ## + +# b4_lhs_location() +# ----------------- +# Expansion of @$. +# Overparenthetized to avoid obscure problems with "foo$$bar = foo$1bar". +m4_define([b4_lhs_location], +[(yyloc)]) + + +# b4_rhs_location(RULE-LENGTH, POS) +# --------------------------------- +# Expansion of @POS, where the current rule has RULE-LENGTH symbols +# on RHS. +# Overparenthetized to avoid obscure problems with "foo$$bar = foo$1bar". +m4_define([b4_rhs_location], +[(yylsp@{b4_subtract([$2], [$1])@})]) + + +## -------------- ## +## Declarations. ## +## -------------- ## + +# _b4_declare_sub_yyparse(START-SYMBOL-NUM, SWITCHING-TOKEN-SYMBOL-NUM) +# --------------------------------------------------------------------- +# Define the return type of the parsing function for SYMBOL-NUM, and +# declare its parsing function. +m4_define([_b4_declare_sub_yyparse], +[[ +// Return type when parsing one ]_b4_symbol($1, tag)[. +typedef struct +{]b4_symbol_if([$1], [has_type], [[ + ]_b4_symbol($1, type)[ yyvalue;]])[ + int yystatus; + int yynerrs; +} ]b4_prefix[parse_]_b4_symbol($1, id)[_t; + +// Parse one ]_b4_symbol($1, tag)[. +]b4_prefix[parse_]_b4_symbol($1, id)[_t ]b4_prefix[parse_]_b4_symbol($1, id)[ (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[); +]]) + + +# _b4_first_switching_token +# ------------------------- +m4_define([b4_first], [$1]) +m4_define([b4_second], [$2]) +m4_define([_b4_first_switching_token], +[b4_second(b4_first(b4_start_symbols))]) + + +# _b4_define_sub_yyparse(START-SYMBOL-NUM, SWITCHING-TOKEN-SYMBOL-NUM) +# -------------------------------------------------------------------- +# Define the parsing function for START-SYMBOL-NUM. +m4_define([_b4_define_sub_yyparse], +[[ +]b4_prefix[parse_]_b4_symbol($1, id)[_t +]b4_prefix[parse_]_b4_symbol($1, id)[ (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[) +{ + ]b4_prefix[parse_]_b4_symbol($1, id)[_t yyres; + yy_parse_impl_t yyimpl; + yyres.yystatus = yy_parse_impl (]b4_symbol($2, id)[, &yyimpl]m4_ifset([b4_parse_param], + [[, ]b4_args(b4_parse_param)])[);]b4_symbol_if([$1], [has_type], [[ + yyres.yyvalue = yyimpl.yyvalue.]b4_symbol($1, slot)[;]])[ + yyres.yynerrs = yyimpl.yynerrs; + return yyres; +} +]]) + + +# b4_declare_scanner_communication_variables +# ------------------------------------------ +# Declare the variables that are global, or local to YYPARSE if +# pure-parser. +m4_define([b4_declare_scanner_communication_variables], [[ +]m4_ifdef([b4_start_symbols], [], +[[/* Lookahead token kind. */ +int yychar; +]])[ +]b4_pure_if([[ +/* The semantic value of the lookahead symbol. */ +/* Default value used for initialization, for pacifying older GCCs + or non-GCC compilers. */ +YY_INITIAL_VALUE (static YYSTYPE yyval_default;) +YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);]b4_locations_if([[ + +/* Location data for the lookahead symbol. */ +static YYLTYPE yyloc_default]b4_yyloc_default[; +YYLTYPE yylloc = yyloc_default;]])], +[[/* The semantic value of the lookahead symbol. */ +YYSTYPE yylval;]b4_locations_if([[ +/* Location data for the lookahead symbol. */ +YYLTYPE yylloc]b4_yyloc_default[;]])[ +/* Number of syntax errors so far. */ +int yynerrs;]])]) + + +# b4_declare_parser_state_variables([INIT]) +# ----------------------------------------- +# Declare all the variables that are needed to maintain the parser state +# between calls to yypush_parse. +# If INIT is non-null, initialize these variables. +m4_define([b4_declare_parser_state_variables], +[b4_pure_if([[ + /* Number of syntax errors so far. */ + int yynerrs]m4_ifval([$1], [ = 0])[; +]])[ + yy_state_fast_t yystate]m4_ifval([$1], [ = 0])[; + /* Number of tokens to shift before error messages enabled. */ + int yyerrstatus]m4_ifval([$1], [ = 0])[; + + /* Refer to the stacks through separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ + + /* Their size. */ + YYPTRDIFF_T yystacksize]m4_ifval([$1], [ = YYINITDEPTH])[; + + /* The state stack: array, bottom, top. */ + yy_state_t yyssa[YYINITDEPTH]; + yy_state_t *yyss]m4_ifval([$1], [ = yyssa])[; + yy_state_t *yyssp]m4_ifval([$1], [ = yyss])[; + + /* The semantic value stack: array, bottom, top. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE *yyvs]m4_ifval([$1], [ = yyvsa])[; + YYSTYPE *yyvsp]m4_ifval([$1], [ = yyvs])[;]b4_locations_if([[ + + /* The location stack: array, bottom, top. */ + YYLTYPE yylsa[YYINITDEPTH]; + YYLTYPE *yyls]m4_ifval([$1], [ = yylsa])[; + YYLTYPE *yylsp]m4_ifval([$1], [ = yyls])[;]])[]b4_lac_if([[ + + yy_state_t yyesa@{]b4_percent_define_get([[parse.lac.es-capacity-initial]])[@}; + yy_state_t *yyes]m4_ifval([$1], [ = yyesa])[; + YYPTRDIFF_T yyes_capacity][]m4_ifval([$1], + [m4_do([ = b4_percent_define_get([[parse.lac.es-capacity-initial]]) < YYMAXDEPTH], + [ ? b4_percent_define_get([[parse.lac.es-capacity-initial]])], + [ : YYMAXDEPTH])])[;]])]) + + +m4_define([b4_macro_define], +[[#]define $1 $2]) + +m4_define([b4_macro_undef], +[[#]undef $1]) + +m4_define([b4_pstate_macro_define], +[b4_macro_define([$1], [yyps->$1])]) + +# b4_parse_state_variable_macros(b4_macro_define|b4_macro_undef) +# -------------------------------------------------------------- +m4_define([b4_parse_state_variable_macros], +[b4_pure_if([$1([b4_prefix[]nerrs])]) +$1([yystate]) +$1([yyerrstatus]) +$1([yyssa]) +$1([yyss]) +$1([yyssp]) +$1([yyvsa]) +$1([yyvs]) +$1([yyvsp])[]b4_locations_if([ +$1([yylsa]) +$1([yyls]) +$1([yylsp])]) +$1([yystacksize])[]b4_lac_if([ +$1([yyesa]) +$1([yyes]) +$1([yyes_capacity])])]) + + + + +# _b4_declare_yyparse_push +# ------------------------ +# Declaration of yyparse (and dependencies) when using the push parser +# (including in pull mode). +m4_define([_b4_declare_yyparse_push], +[[#ifndef YYPUSH_MORE_DEFINED +# define YYPUSH_MORE_DEFINED +enum { YYPUSH_MORE = 4 }; +#endif + +typedef struct ]b4_prefix[pstate ]b4_prefix[pstate; + +]b4_pull_if([[ +int ]b4_prefix[parse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[);]])[ +int ]b4_prefix[push_parse (]b4_prefix[pstate *ps]b4_pure_if([[, + int pushed_char, ]b4_api_PREFIX[STYPE const *pushed_val]b4_locations_if([[, ]b4_api_PREFIX[LTYPE *pushed_loc]])])b4_user_formals[); +]b4_pull_if([[int ]b4_prefix[pull_parse (]b4_prefix[pstate *ps]b4_user_formals[);]])[ +]b4_prefix[pstate *]b4_prefix[pstate_new (void); +void ]b4_prefix[pstate_delete (]b4_prefix[pstate *ps); +]]) + + +# _b4_declare_yyparse +# ------------------- +# When not the push parser. +m4_define([_b4_declare_yyparse], +[[int ]b4_prefix[parse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[); +]m4_ifdef([b4_start_symbols], + [m4_map([_b4_declare_sub_yyparse], m4_defn([b4_start_symbols]))])]) + + +# b4_declare_yyparse +# ------------------ +m4_define([b4_declare_yyparse], +[b4_push_if([_b4_declare_yyparse_push], + [_b4_declare_yyparse])[]dnl +]) + + +# b4_declare_yyerror_and_yylex +# ---------------------------- +# Comply with POSIX Yacc. +# +m4_define([b4_declare_yyerror_and_yylex], +[b4_posix_if([[#if !defined ]b4_prefix[error && !defined ]b4_api_PREFIX[ERROR_IS_DECLARED +]b4_function_declare([b4_prefix[error]], void, b4_yyerror_formals)[ +#endif +#if !defined ]b4_prefix[lex && !defined ]b4_api_PREFIX[LEX_IS_DECLARED +]b4_function_declare([b4_prefix[lex]], int, b4_yylex_formals)[ +#endif +]])dnl +]) + + +# b4_shared_declarations +# ---------------------- +# Declarations that might either go into the header (if --header) +# or into the implementation file. +m4_define([b4_shared_declarations], +[b4_cpp_guard_open([b4_spec_mapped_header_file])[ +]b4_declare_yydebug[ +]b4_percent_code_get([[requires]])[ +]b4_token_enums_defines[ +]b4_declare_yylstype[ +]b4_declare_yyerror_and_yylex[ +]b4_declare_yyparse[ +]b4_percent_code_get([[provides]])[ +]b4_cpp_guard_close([b4_spec_mapped_header_file])[]dnl +]) + + +# b4_header_include_if(IF-TRUE, IF-FALSE) +# --------------------------------------- +# Run IF-TRUE if we generate an output file and api.header.include +# is defined. +m4_define([b4_header_include_if], +[m4_ifval(m4_quote(b4_spec_header_file), + [b4_percent_define_ifdef([[api.header.include]], + [$1], + [$2])], + [$2])]) + +m4_if(b4_spec_header_file, [y.tab.h], [], + [b4_percent_define_default([[api.header.include]], + [["@basename(]b4_spec_header_file[@)"]])]) + + + + +## -------------- ## +## Output files. ## +## -------------- ## + + +b4_header_if([[ +]b4_output_begin([b4_spec_header_file])[ +]b4_copyright([Bison interface for Yacc-like parsers in C])[ +]b4_disclaimer[ +]b4_shared_declarations[ +]b4_output_end[ +]])# b4_header_if + +b4_output_begin([b4_parser_file_name])[ +]b4_copyright([Bison implementation for Yacc-like parsers in C])[ +/* C LALR(1) parser skeleton written by Richard Stallman, by + simplifying the original so-called "semantic" parser. */ + +]b4_disclaimer[ +/* All symbols defined below should begin with yy or YY, to avoid + infringing on user name space. This should be done even for local + variables, as they might otherwise be expanded by user macros. + There are some unavoidable exceptions within include files to + define necessary library symbols; they are noted "INFRINGES ON + USER NAME SPACE" below. */ + +]b4_identification[ +]b4_percent_code_get([[top]])[]dnl +m4_if(b4_api_prefix, [yy], [], +[[/* Substitute the type names. */ +#define YYSTYPE ]b4_api_PREFIX[STYPE]b4_locations_if([[ +#define YYLTYPE ]b4_api_PREFIX[LTYPE]])])[ +]m4_if(b4_prefix, [yy], [], +[[/* Substitute the variable and function names. */]b4_pull_if([[ +#define yyparse ]b4_prefix[parse]])b4_push_if([[ +#define yypush_parse ]b4_prefix[push_parse]b4_pull_if([[ +#define yypull_parse ]b4_prefix[pull_parse]])[ +#define yypstate_new ]b4_prefix[pstate_new +#define yypstate_clear ]b4_prefix[pstate_clear +#define yypstate_delete ]b4_prefix[pstate_delete +#define yypstate ]b4_prefix[pstate]])[ +#define yylex ]b4_prefix[lex +#define yyerror ]b4_prefix[error +#define yydebug ]b4_prefix[debug +#define yynerrs ]b4_prefix[nerrs]]b4_pure_if([], [[ +#define yylval ]b4_prefix[lval +#define yychar ]b4_prefix[char]b4_locations_if([[ +#define yylloc ]b4_prefix[lloc]])]))[ + +]b4_user_pre_prologue[ +]b4_cast_define[ +]b4_null_define[ + +]b4_header_include_if([[#include ]b4_percent_define_get([[api.header.include]])], + [m4_ifval(m4_quote(b4_spec_header_file), + [/* Use api.header.include to #include this header + instead of duplicating it here. */ +])b4_shared_declarations])[ +]b4_declare_symbol_enum[ + +]b4_user_post_prologue[ +]b4_percent_code_get[ +]b4_c99_int_type_define[ + +]b4_sizes_types_define[ + +/* Stored state numbers (used for stacks). */ +typedef ]b4_int_type(0, m4_eval(b4_states_number - 1))[ yy_state_t; + +/* State numbers in computations. */ +typedef int yy_state_fast_t; + +#ifndef YY_ +# if defined YYENABLE_NLS && YYENABLE_NLS +# if ENABLE_NLS +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_(Msgid) dgettext ("bison-runtime", Msgid) +# endif +# endif +# ifndef YY_ +# define YY_(Msgid) Msgid +# endif +#endif +]b4_has_translations_if([ +#ifndef N_ +# define N_(Msgid) Msgid +#endif +])[ + +]b4_attribute_define[ + +]b4_parse_assert_if([[#ifdef NDEBUG +# define YY_ASSERT(E) ((void) (0 && (E))) +#else +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_ASSERT(E) assert (E) +#endif +]], +[[#define YY_ASSERT(E) ((void) (0 && (E)))]])[ + +#if ]b4_lac_if([[1]], [b4_parse_error_case([simple], [[!defined yyoverflow]], [[1]])])[ + +/* The parser invokes alloca or malloc; define the necessary symbols. */]dnl +b4_push_if([], [b4_lac_if([], [[ + +# ifdef YYSTACK_USE_ALLOCA +# if YYSTACK_USE_ALLOCA +# ifdef __GNUC__ +# define YYSTACK_ALLOC __builtin_alloca +# elif defined __BUILTIN_VA_ARG_INCR +# include /* INFRINGES ON USER NAME SPACE */ +# elif defined _AIX +# define YYSTACK_ALLOC __alloca +# elif defined _MSC_VER +# include /* INFRINGES ON USER NAME SPACE */ +# define alloca _alloca +# else +# define YYSTACK_ALLOC alloca +# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS +# include /* INFRINGES ON USER NAME SPACE */ + /* Use EXIT_SUCCESS as a witness for stdlib.h. */ +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 +# endif +# endif +# endif +# endif +# endif]])])[ + +# ifdef YYSTACK_ALLOC + /* Pacify GCC's 'empty if-body' warning. */ +# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) +# ifndef YYSTACK_ALLOC_MAXIMUM + /* The OS might guarantee only one guard page at the bottom of the stack, + and a page size can be as small as 4096 bytes. So we cannot safely + invoke alloca (N) if N exceeds 4096. Use a slightly smaller number + to allow for a few compiler-allocated temporary stack slots. */ +# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ +# endif +# else +# define YYSTACK_ALLOC YYMALLOC +# define YYSTACK_FREE YYFREE +# ifndef YYSTACK_ALLOC_MAXIMUM +# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM +# endif +# if (defined __cplusplus && ! defined EXIT_SUCCESS \ + && ! ((defined YYMALLOC || defined malloc) \ + && (defined YYFREE || defined free))) +# include /* INFRINGES ON USER NAME SPACE */ +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 +# endif +# endif +# ifndef YYMALLOC +# define YYMALLOC malloc +# if ! defined malloc && ! defined EXIT_SUCCESS +void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# ifndef YYFREE +# define YYFREE free +# if ! defined free && ! defined EXIT_SUCCESS +void free (void *); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# endif]b4_lac_if([[ +# define YYCOPY_NEEDED 1]])[ +#endif /* ]b4_lac_if([[1]], [b4_parse_error_case([simple], [[!defined yyoverflow]], [[1]])])[ */ + +#if (! defined yyoverflow \ + && (! defined __cplusplus \ + || (]b4_locations_if([[defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL \ + && ]])[defined ]b4_api_PREFIX[STYPE_IS_TRIVIAL && ]b4_api_PREFIX[STYPE_IS_TRIVIAL))) + +/* A type that is properly aligned for any stack member. */ +union yyalloc +{ + yy_state_t yyss_alloc; + YYSTYPE yyvs_alloc;]b4_locations_if([ + YYLTYPE yyls_alloc;])[ +}; + +/* The size of the maximum gap between one aligned stack and the next. */ +# define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1) + +/* The size of an array large to enough to hold all stacks, each with + N elements. */ +]b4_locations_if( +[# define YYSTACK_BYTES(N) \ + ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE) \ + + YYSIZEOF (YYLTYPE)) \ + + 2 * YYSTACK_GAP_MAXIMUM)], +[# define YYSTACK_BYTES(N) \ + ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \ + + YYSTACK_GAP_MAXIMUM)])[ + +# 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 + elements in the stack, and YYPTR gives the new location of the + stack. Advance YYPTR to a properly aligned location for the next + stack. */ +# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ + do \ + { \ + YYPTRDIFF_T yynewbytes; \ + YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ + Stack = &yyptr->Stack_alloc; \ + yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / YYSIZEOF (*yyptr); \ + } \ + while (0) + +#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, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src))) +# else +# define YYCOPY(Dst, Src, Count) \ + do \ + { \ + YYPTRDIFF_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (Dst)[yyi] = (Src)[yyi]; \ + } \ + while (0) +# endif +# endif +#endif /* !YYCOPY_NEEDED */ + +/* YYFINAL -- State number of the termination state. */ +#define YYFINAL ]b4_final_state_number[ +/* YYLAST -- Last index in YYTABLE. */ +#define YYLAST ]b4_last[ + +/* YYNTOKENS -- Number of terminals. */ +#define YYNTOKENS ]b4_tokens_number[ +/* YYNNTS -- Number of nonterminals. */ +#define YYNNTS ]b4_nterms_number[ +/* YYNRULES -- Number of rules. */ +#define YYNRULES ]b4_rules_number[ +/* YYNSTATES -- Number of states. */ +#define YYNSTATES ]b4_states_number[ + +/* YYMAXUTOK -- Last valid token kind. */ +#define YYMAXUTOK ]b4_code_max[ + + +/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM + as returned by yylex, with out-of-bounds checking. */ +]b4_api_token_raw_if(dnl +[[#define YYTRANSLATE(YYX) YY_CAST (yysymbol_kind_t, YYX)]], +[[#define YYTRANSLATE(YYX) \ + (0 <= (YYX) && (YYX) <= YYMAXUTOK \ + ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \ + : ]b4_symbol_prefix[YYUNDEF) + +/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM + as returned by yylex. */ +static const ]b4_int_type_for([b4_translate])[ yytranslate[] = +{ + ]b4_translate[ +};]])[ + +#if ]b4_api_PREFIX[DEBUG +]b4_integral_parser_table_define([rline], [b4_rline], + [[YYRLINE[YYN] -- Source line where rule number YYN was defined.]])[ +#endif + +/** Accessing symbol of state STATE. */ +#define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State]) + +#if ]b4_parse_error_case([simple], [b4_api_PREFIX[DEBUG || ]b4_token_table_flag], [[1]])[ +/* The user-facing name of the symbol whose (internal) number is + YYSYMBOL. No bounds checking. */ +static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED; + +]b4_parse_error_bmatch([simple\|verbose], +[[/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at YYNTOKENS, nonterminals. */ +static const char *const yytname[] = +{ + ]b4_tname[ +}; + +static const char * +yysymbol_name (yysymbol_kind_t yysymbol) +{ + return yytname[yysymbol]; +}]], +[[static const char * +yysymbol_name (yysymbol_kind_t yysymbol) +{ + static const char *const yy_sname[] = + { + ]b4_symbol_names[ + };]b4_has_translations_if([[ + /* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is + internationalizable. */ + static ]b4_int_type_for([b4_translatable])[ yytranslatable[] = + { + ]b4_translatable[ + }; + return (yysymbol < YYNTOKENS && yytranslatable[yysymbol] + ? _(yy_sname[yysymbol]) + : yy_sname[yysymbol]);]], [[ + return yy_sname[yysymbol];]])[ +}]])[ +#endif + +#define YYPACT_NINF (]b4_pact_ninf[) + +#define yypact_value_is_default(Yyn) \ + ]b4_table_value_equals([[pact]], [[Yyn]], [b4_pact_ninf], [YYPACT_NINF])[ + +#define YYTABLE_NINF (]b4_table_ninf[) + +#define yytable_value_is_error(Yyn) \ + ]b4_table_value_equals([[table]], [[Yyn]], [b4_table_ninf], [YYTABLE_NINF])[ + +]b4_parser_tables_define[ + +enum { YYENOMEM = -2 }; + +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = ]b4_symbol(empty, id)[) + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab +#define YYNOMEM goto yyexhaustedlab + + +#define YYRECOVERING() (!!yyerrstatus) + +#define YYBACKUP(Token, Value) \ + do \ + if (yychar == ]b4_symbol(empty, id)[) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + YYPOPSTACK (yylen); \ + yystate = *yyssp; \]b4_lac_if([[ + YY_LAC_DISCARD ("YYBACKUP"); \]])[ + goto yybackup; \ + } \ + else \ + { \ + yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")); \ + YYERROR; \ + } \ + while (0) + +/* Backward compatibility with an undocumented macro. + Use ]b4_symbol(error, id)[ or ]b4_symbol(undef, id)[. */ +#define YYERRCODE ]b4_symbol(undef, id)[ +]b4_locations_if([[ +]b4_yylloc_default_define[ +#define YYRHSLOC(Rhs, K) ((Rhs)[K]) +]])[ + +/* Enable debugging if requested. */ +#if ]b4_api_PREFIX[DEBUG + +# ifndef YYFPRINTF +# include /* INFRINGES ON USER NAME SPACE */ +# define YYFPRINTF fprintf +# endif + +# define YYDPRINTF(Args) \ +do { \ + if (yydebug) \ + YYFPRINTF Args; \ +} while (0) + +]b4_yylocation_print_define[ + +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ +do { \ + if (yydebug) \ + { \ + YYFPRINTF (stderr, "%s ", Title); \ + yy_symbol_print (stderr, \ + Kind, Value]b4_locations_if([, Location])[]b4_user_args[); \ + YYFPRINTF (stderr, "\n"); \ + } \ +} while (0) + +]b4_yy_symbol_print_define[ + +/*------------------------------------------------------------------. +| yy_stack_print -- Print the state stack from its BOTTOM up to its | +| TOP (included). | +`------------------------------------------------------------------*/ + +static void +yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop) +{ + YYFPRINTF (stderr, "Stack now"); + for (; yybottom <= yytop; yybottom++) + { + int yybot = *yybottom; + YYFPRINTF (stderr, " %d", yybot); + } + YYFPRINTF (stderr, "\n"); +} + +# define YY_STACK_PRINT(Bottom, Top) \ +do { \ + if (yydebug) \ + yy_stack_print ((Bottom), (Top)); \ +} while (0) + + +/*------------------------------------------------. +| Report that the YYRULE is going to be reduced. | +`------------------------------------------------*/ + +static void +yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp,]b4_locations_if([[ YYLTYPE *yylsp,]])[ + int yyrule]b4_user_formals[) +{ + int yylno = yyrline[yyrule]; + int yynrhs = yyr2[yyrule]; + int yyi; + YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n", + yyrule - 1, yylno); + /* The symbols being reduced. */ + for (yyi = 0; yyi < yynrhs; yyi++) + { + YYFPRINTF (stderr, " $%d = ", yyi + 1); + yy_symbol_print (stderr, + YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]), + &]b4_rhs_value(yynrhs, yyi + 1)[]b4_locations_if([, + &]b4_rhs_location(yynrhs, yyi + 1))[]b4_user_args[); + YYFPRINTF (stderr, "\n"); + } +} + +# define YY_REDUCE_PRINT(Rule) \ +do { \ + if (yydebug) \ + yy_reduce_print (yyssp, yyvsp, ]b4_locations_if([yylsp, ])[Rule]b4_user_args[); \ +} while (0) + +/* Nonzero means print parse trace. It is left uninitialized so that + multiple parsers can coexist. */ +int yydebug; +#else /* !]b4_api_PREFIX[DEBUG */ +# define YYDPRINTF(Args) ((void) 0) +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) +# define YY_STACK_PRINT(Bottom, Top) +# define YY_REDUCE_PRINT(Rule) +#endif /* !]b4_api_PREFIX[DEBUG */ + + +/* YYINITDEPTH -- initial size of the parser's stacks. */ +#ifndef YYINITDEPTH +# define YYINITDEPTH ]b4_stack_depth_init[ +#endif + +/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only + if the built-in stack extension method is used). + + Do not make this value too large; the results are undefined if + YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) + evaluated with infinite-precision integer arithmetic. */ + +#ifndef YYMAXDEPTH +# define YYMAXDEPTH ]b4_stack_depth_max[ +#endif]b4_push_if([[ +/* Parser data structure. */ +struct yypstate + {]b4_declare_parser_state_variables[ + /* Whether this instance has not started parsing yet. + * If 2, it corresponds to a finished parsing. */ + int yynew; + };]b4_pure_if([], [[ + +/* Whether the only allowed instance of yypstate is allocated. */ +static char yypstate_allocated = 0;]])])[ +]b4_lac_if([[ + +/* Given a state stack such that *YYBOTTOM is its bottom, such that + *YYTOP is either its top or is YYTOP_EMPTY to indicate an empty + stack, and such that *YYCAPACITY is the maximum number of elements it + can hold without a reallocation, make sure there is enough room to + store YYADD more elements. If not, allocate a new stack using + YYSTACK_ALLOC, copy the existing elements, and adjust *YYBOTTOM, + *YYTOP, and *YYCAPACITY to reflect the new capacity and memory + location. If *YYBOTTOM != YYBOTTOM_NO_FREE, then free the old stack + using YYSTACK_FREE. Return 0 if successful or if no reallocation is + required. Return YYENOMEM if memory is exhausted. */ +static int +yy_lac_stack_realloc (YYPTRDIFF_T *yycapacity, YYPTRDIFF_T yyadd, +#if ]b4_api_PREFIX[DEBUG + char const *yydebug_prefix, + char const *yydebug_suffix, +#endif + yy_state_t **yybottom, + yy_state_t *yybottom_no_free, + yy_state_t **yytop, yy_state_t *yytop_empty) +{ + YYPTRDIFF_T yysize_old = + *yytop == yytop_empty ? 0 : *yytop - *yybottom + 1; + YYPTRDIFF_T yysize_new = yysize_old + yyadd; + if (*yycapacity < yysize_new) + { + YYPTRDIFF_T yyalloc = 2 * yysize_new; + yy_state_t *yybottom_new; + /* Use YYMAXDEPTH for maximum stack size given that the stack + should never need to grow larger than the main state stack + needs to grow without LAC. */ + if (YYMAXDEPTH < yysize_new) + { + YYDPRINTF ((stderr, "%smax size exceeded%s", yydebug_prefix, + yydebug_suffix)); + return YYENOMEM; + } + if (YYMAXDEPTH < yyalloc) + yyalloc = YYMAXDEPTH; + yybottom_new = + YY_CAST (yy_state_t *, + YYSTACK_ALLOC (YY_CAST (YYSIZE_T, + yyalloc * YYSIZEOF (*yybottom_new)))); + if (!yybottom_new) + { + YYDPRINTF ((stderr, "%srealloc failed%s", yydebug_prefix, + yydebug_suffix)); + return YYENOMEM; + } + if (*yytop != yytop_empty) + { + YYCOPY (yybottom_new, *yybottom, yysize_old); + *yytop = yybottom_new + (yysize_old - 1); + } + if (*yybottom != yybottom_no_free) + YYSTACK_FREE (*yybottom); + *yybottom = yybottom_new; + *yycapacity = yyalloc;]m4_if(b4_percent_define_get([[parse.lac.memory-trace]]), + [full], [[ + YY_IGNORE_USELESS_CAST_BEGIN + YYDPRINTF ((stderr, "%srealloc to %ld%s", yydebug_prefix, + YY_CAST (long, yyalloc), yydebug_suffix)); + YY_IGNORE_USELESS_CAST_END]])[ + } + return 0; +} + +/* Establish the initial context for the current lookahead if no initial + context is currently established. + + We define a context as a snapshot of the parser stacks. We define + the initial context for a lookahead as the context in which the + parser initially examines that lookahead in order to select a + syntactic action. Thus, if the lookahead eventually proves + syntactically unacceptable (possibly in a later context reached via a + series of reductions), the initial context can be used to determine + the exact set of tokens that would be syntactically acceptable in the + lookahead's place. Moreover, it is the context after which any + further semantic actions would be erroneous because they would be + determined by a syntactically unacceptable token. + + YY_LAC_ESTABLISH should be invoked when a reduction is about to be + performed in an inconsistent state (which, for the purposes of LAC, + includes consistent states that don't know they're consistent because + their default reductions have been disabled). Iff there is a + lookahead token, it should also be invoked before reporting a syntax + error. This latter case is for the sake of the debugging output. + + For parse.lac=full, the implementation of YY_LAC_ESTABLISH is as + follows. If no initial context is currently established for the + current lookahead, then check if that lookahead can eventually be + shifted if syntactic actions continue from the current context. + Report a syntax error if it cannot. */ +#define YY_LAC_ESTABLISH \ +do { \ + if (!yy_lac_established) \ + { \ + YYDPRINTF ((stderr, \ + "LAC: initial context established for %s\n", \ + yysymbol_name (yytoken))); \ + yy_lac_established = 1; \ + switch (yy_lac (yyesa, &yyes, &yyes_capacity, yyssp, yytoken)) \ + { \ + case YYENOMEM: \ + YYNOMEM; \ + case 1: \ + goto yyerrlab; \ + } \ + } \ +} while (0) + +/* Discard any previous initial lookahead context because of Event, + which may be a lookahead change or an invalidation of the currently + established initial context for the current lookahead. + + The most common example of a lookahead change is a shift. An example + of both cases is syntax error recovery. That is, a syntax error + occurs when the lookahead is syntactically erroneous for the + currently established initial context, so error recovery manipulates + the parser stacks to try to find a new initial context in which the + current lookahead is syntactically acceptable. If it fails to find + such a context, it discards the lookahead. */ +#if ]b4_api_PREFIX[DEBUG +# define YY_LAC_DISCARD(Event) \ +do { \ + if (yy_lac_established) \ + { \ + YYDPRINTF ((stderr, "LAC: initial context discarded due to " \ + Event "\n")); \ + yy_lac_established = 0; \ + } \ +} while (0) +#else +# define YY_LAC_DISCARD(Event) yy_lac_established = 0 +#endif + +/* Given the stack whose top is *YYSSP, return 0 iff YYTOKEN can + eventually (after perhaps some reductions) be shifted, return 1 if + not, or return YYENOMEM if memory is exhausted. As preconditions and + postconditions: *YYES_CAPACITY is the allocated size of the array to + which *YYES points, and either *YYES = YYESA or *YYES points to an + array allocated with YYSTACK_ALLOC. yy_lac may overwrite the + contents of either array, alter *YYES and *YYES_CAPACITY, and free + any old *YYES other than YYESA. */ +static int +yy_lac (yy_state_t *yyesa, yy_state_t **yyes, + YYPTRDIFF_T *yyes_capacity, yy_state_t *yyssp, yysymbol_kind_t yytoken) +{ + yy_state_t *yyes_prev = yyssp; + yy_state_t *yyesp = yyes_prev; + /* Reduce until we encounter a shift and thereby accept the token. */ + YYDPRINTF ((stderr, "LAC: checking lookahead %s:", yysymbol_name (yytoken))); + if (yytoken == ]b4_symbol_prefix[YYUNDEF) + { + YYDPRINTF ((stderr, " Always Err\n")); + return 1; + } + while (1) + { + int yyrule = yypact[+*yyesp]; + if (yypact_value_is_default (yyrule) + || (yyrule += yytoken) < 0 || YYLAST < yyrule + || yycheck[yyrule] != yytoken) + { + /* Use the default action. */ + yyrule = yydefact[+*yyesp]; + if (yyrule == 0) + { + YYDPRINTF ((stderr, " Err\n")); + return 1; + } + } + else + { + /* Use the action from yytable. */ + yyrule = yytable[yyrule]; + if (yytable_value_is_error (yyrule)) + { + YYDPRINTF ((stderr, " Err\n")); + return 1; + } + if (0 < yyrule) + { + YYDPRINTF ((stderr, " S%d\n", yyrule)); + return 0; + } + yyrule = -yyrule; + } + /* By now we know we have to simulate a reduce. */ + YYDPRINTF ((stderr, " R%d", yyrule - 1)); + { + /* Pop the corresponding number of values from the stack. */ + YYPTRDIFF_T yylen = yyr2[yyrule]; + /* First pop from the LAC stack as many tokens as possible. */ + if (yyesp != yyes_prev) + { + YYPTRDIFF_T yysize = yyesp - *yyes + 1; + if (yylen < yysize) + { + yyesp -= yylen; + yylen = 0; + } + else + { + yyesp = yyes_prev; + yylen -= yysize; + } + } + /* Only afterwards look at the main stack. */ + if (yylen) + yyesp = yyes_prev -= yylen; + } + /* Push the resulting state of the reduction. */ + { + yy_state_fast_t yystate; + { + const int yylhs = yyr1[yyrule] - YYNTOKENS; + const int yyi = yypgoto[yylhs] + *yyesp; + yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyesp + ? yytable[yyi] + : yydefgoto[yylhs]); + } + if (yyesp == yyes_prev) + { + yyesp = *yyes; + YY_IGNORE_USELESS_CAST_BEGIN + *yyesp = YY_CAST (yy_state_t, yystate); + YY_IGNORE_USELESS_CAST_END + } + else + { + if (yy_lac_stack_realloc (yyes_capacity, 1, +#if ]b4_api_PREFIX[DEBUG + " (", ")", +#endif + yyes, yyesa, &yyesp, yyes_prev)) + { + YYDPRINTF ((stderr, "\n")); + return YYENOMEM; + } + YY_IGNORE_USELESS_CAST_BEGIN + *++yyesp = YY_CAST (yy_state_t, yystate); + YY_IGNORE_USELESS_CAST_END + } + YYDPRINTF ((stderr, " G%d", yystate)); + } + } +}]])[ + +]b4_parse_error_case([simple], [], +[[/* Context of a parse error. */ +typedef struct +{]b4_push_if([[ + yypstate* yyps;]], [[ + yy_state_t *yyssp;]b4_lac_if([[ + yy_state_t *yyesa; + yy_state_t **yyes; + YYPTRDIFF_T *yyes_capacity;]])])[ + yysymbol_kind_t yytoken;]b4_locations_if([[ + YYLTYPE *yylloc;]])[ +} yypcontext_t; + +/* Put in YYARG at most YYARGN of the expected tokens given the + current YYCTX, and return the number of tokens stored in YYARG. If + YYARG is null, return the number of expected tokens (guaranteed to + be less than YYNTOKENS). Return YYENOMEM on memory exhaustion. + Return 0 if there are more than YYARGN expected tokens, yet fill + YYARG up to YYARGN. */]b4_push_if([[ +static int +yypstate_expected_tokens (yypstate *yyps, + yysymbol_kind_t yyarg[], int yyargn)]], [[ +static int +yypcontext_expected_tokens (const yypcontext_t *yyctx, + yysymbol_kind_t yyarg[], int yyargn)]])[ +{ + /* Actual size of YYARG. */ + int yycount = 0; +]b4_lac_if([[ + int yyx; + for (yyx = 0; yyx < YYNTOKENS; ++yyx) + { + yysymbol_kind_t yysym = YY_CAST (yysymbol_kind_t, yyx); + if (yysym != ]b4_symbol(error, kind)[ && yysym != ]b4_symbol_prefix[YYUNDEF) + switch (yy_lac (]b4_push_if([[yyps->yyesa, &yyps->yyes, &yyps->yyes_capacity, yyps->yyssp, yysym]], + [[yyctx->yyesa, yyctx->yyes, yyctx->yyes_capacity, yyctx->yyssp, yysym]])[)) + { + case YYENOMEM: + return YYENOMEM; + case 1: + continue; + default: + if (!yyarg) + ++yycount; + else if (yycount == yyargn) + return 0; + else + yyarg[yycount++] = yysym; + } + }]], +[[ int yyn = yypact@{+*]b4_push_if([yyps], [yyctx])[->yyssp@}; + 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; + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != ]b4_symbol(error, kind)[ + && !yytable_value_is_error (yytable[yyx + yyn])) + { + if (!yyarg) + ++yycount; + else if (yycount == yyargn) + return 0; + else + yyarg[yycount++] = YY_CAST (yysymbol_kind_t, yyx); + } + }]])[ + if (yyarg && yycount == 0 && 0 < yyargn) + yyarg[0] = ]b4_symbol(empty, kind)[; + return yycount; +} + +]b4_push_if([[ +/* Similar to the previous function. */ +static int +yypcontext_expected_tokens (const yypcontext_t *yyctx, + yysymbol_kind_t yyarg[], int yyargn) +{ + return yypstate_expected_tokens (yyctx->yyps, yyarg, yyargn); +}]])[ +]])[ + +]b4_parse_error_bmatch( + [custom], +[[/* The kind of the lookahead of this context. */ +static yysymbol_kind_t +yypcontext_token (const yypcontext_t *yyctx) YY_ATTRIBUTE_UNUSED; + +static yysymbol_kind_t +yypcontext_token (const yypcontext_t *yyctx) +{ + return yyctx->yytoken; +} + +]b4_locations_if([[/* The location of the lookahead of this context. */ +static YYLTYPE * +yypcontext_location (const yypcontext_t *yyctx) YY_ATTRIBUTE_UNUSED; + +static YYLTYPE * +yypcontext_location (const yypcontext_t *yyctx) +{ + return yyctx->yylloc; +}]])[ + +/* User defined function to report a syntax error. */ +static int +yyreport_syntax_error (const yypcontext_t *yyctx]b4_user_formals[);]], + [detailed\|verbose], +[[#ifndef yystrlen +# if defined __GLIBC__ && defined _STRING_H +# define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S))) +# else +/* Return the length of YYSTR. */ +static YYPTRDIFF_T +yystrlen (const char *yystr) +{ + YYPTRDIFF_T yylen; + for (yylen = 0; yystr[yylen]; yylen++) + continue; + return yylen; +} +# endif +#endif + +#ifndef yystpcpy +# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE +# define yystpcpy stpcpy +# else +/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in + YYDEST. */ +static char * +yystpcpy (char *yydest, const char *yysrc) +{ + char *yyd = yydest; + const char *yys = yysrc; + + while ((*yyd++ = *yys++) != '\0') + continue; + + return yyd - 1; +} +# endif +#endif + +]b4_parse_error_case( + [verbose], +[[#ifndef yytnamerr +/* Copy to YYRES the contents of YYSTR after stripping away unnecessary + quotes and backslashes, so that it's suitable for yyerror. The + heuristic is that double-quoting is unnecessary unless the string + contains an apostrophe, a comma, or backslash (other than + backslash-backslash). YYSTR is taken from yytname. If YYRES is + null, do not copy; instead, return the length of what the result + would have been. */ +static YYPTRDIFF_T +yytnamerr (char *yyres, const char *yystr) +{ + if (*yystr == '"') + { + YYPTRDIFF_T yyn = 0; + char const *yyp = yystr; + for (;;) + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + else + goto append; + + append: + default: + if (yyres) + yyres[yyn] = *yyp; + yyn++; + break; + + case '"': + if (yyres) + yyres[yyn] = '\0'; + return yyn; + } + do_not_strip_quotes: ; + } + + if (yyres) + return yystpcpy (yyres, yystr) - yyres; + else + return yystrlen (yystr); +} +#endif +]])[ + +static int +yy_syntax_error_arguments (const yypcontext_t *yyctx, + yysymbol_kind_t yyarg[], int yyargn) +{ + /* Actual size of YYARG. */ + int yycount = 0; + /* There are many possibilities here to consider: + - 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.]b4_lac_if([[ + In the first two cases, it might appear that the current syntax + error should have been detected in the previous state when yy_lac + was invoked. However, at that time, there might have been a + different syntax error that discarded a different initial context + during error recovery, leaving behind the current lookahead.]], [[ + - 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 (yyctx->yytoken != ]b4_symbol(empty, kind)[) + { + int yyn;]b4_lac_if([[ + YYDPRINTF ((stderr, "Constructing syntax error message\n"));]])[ + if (yyarg) + yyarg[yycount] = yyctx->yytoken; + ++yycount; + yyn = yypcontext_expected_tokens (yyctx, + yyarg ? yyarg + 1 : yyarg, yyargn - 1); + if (yyn == YYENOMEM) + return YYENOMEM;]b4_lac_if([[ + else if (yyn == 0) + YYDPRINTF ((stderr, "No expected tokens.\n"));]])[ + else + yycount += yyn; + } + return yycount; +} + +/* 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.]b4_lac_if([[ In order to see if a particular token T is a + valid looakhead, invoke yy_lac (YYESA, YYES, YYES_CAPACITY, YYSSP, T).]])[ + + 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 YYENOMEM if the + required number of bytes is too large to store]b4_lac_if([[ or if + yy_lac returned YYENOMEM]])[. */ +static int +yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg, + const yypcontext_t *yyctx) +{ + enum { YYARGS_MAX = 5 }; + /* Internationalized format string. */ + const char *yyformat = YY_NULLPTR; + /* Arguments of yyformat: reported tokens (one for the "unexpected", + one per "expected"). */ + yysymbol_kind_t yyarg[YYARGS_MAX]; + /* Cumulated lengths of YYARG. */ + YYPTRDIFF_T yysize = 0; + + /* Actual size of YYARG. */ + int yycount = yy_syntax_error_arguments (yyctx, yyarg, YYARGS_MAX); + if (yycount == YYENOMEM) + return YYENOMEM; + + switch (yycount) + { +#define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + default: /* Avoid compiler warnings. */ + 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_ + } + + /* Compute error message size. Don't count the "%s"s, but reserve + room for the terminator. */ + yysize = yystrlen (yyformat) - 2 * yycount + 1; + { + int yyi; + for (yyi = 0; yyi < yycount; ++yyi) + { + YYPTRDIFF_T yysize1 + = yysize + ]b4_parse_error_case( + [verbose], [[yytnamerr (YY_NULLPTR, yytname[yyarg[yyi]])]], + [[yystrlen (yysymbol_name (yyarg[yyi]))]]);[ + if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) + yysize = yysize1; + else + return YYENOMEM; + } + } + + 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) + {]b4_parse_error_case([verbose], [[ + yyp += yytnamerr (yyp, yytname[yyarg[yyi++]]);]], [[ + yyp = yystpcpy (yyp, yysymbol_name (yyarg[yyi++]));]])[ + yyformat += 2; + } + else + { + ++yyp; + ++yyformat; + } + } + return 0; +} +]])[ + +]b4_yydestruct_define[ + +]b4_pure_if([], [b4_declare_scanner_communication_variables])[ + +]b4_push_if([b4_pull_if([[ + +int +yyparse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[) +{ + yypstate *yyps = yypstate_new (); + if (!yyps) + {]b4_pure_if([b4_locations_if([[ + static YYLTYPE yyloc_default][]b4_yyloc_default[; + YYLTYPE yylloc = yyloc_default;]])[ + yyerror (]b4_yyerror_args[YY_("memory exhausted"));]], [[ + if (!yypstate_allocated) + yyerror (]b4_yyerror_args[YY_("memory exhausted"));]])[ + return 2; + } + int yystatus = yypull_parse (yyps]b4_user_args[); + yypstate_delete (yyps); + return yystatus; +} + +int +yypull_parse (yypstate *yyps]b4_user_formals[) +{ + YY_ASSERT (yyps);]b4_pure_if([b4_locations_if([[ + static YYLTYPE yyloc_default][]b4_yyloc_default[; + YYLTYPE yylloc = yyloc_default;]])])[ + int yystatus; + do { +]b4_pure_if([[ YYSTYPE yylval; + int ]])[yychar = ]b4_yylex[; + yystatus = yypush_parse (yyps]b4_pure_if([[, yychar, &yylval]b4_locations_if([[, &yylloc]])])m4_ifset([b4_parse_param], [, b4_args(b4_parse_param)])[); + } while (yystatus == YYPUSH_MORE); + return yystatus; +}]])[ + +]b4_parse_state_variable_macros([b4_pstate_macro_define])[ + +/* Initialize the parser data structure. */ +static void +yypstate_clear (yypstate *yyps) +{ + yynerrs = 0; + yystate = 0; + yyerrstatus = 0; + + yyssp = yyss; + yyvsp = yyvs;]b4_locations_if([[ + yylsp = yyls;]])[ + + /* Initialize the state stack, in case yypcontext_expected_tokens is + called before the first call to yyparse. */ + *yyssp = 0; + yyps->yynew = 1; +} + +/* Initialize the parser data structure. */ +yypstate * +yypstate_new (void) +{ + yypstate *yyps;]b4_pure_if([], [[ + if (yypstate_allocated) + return YY_NULLPTR;]])[ + yyps = YY_CAST (yypstate *, YYMALLOC (sizeof *yyps)); + if (!yyps) + return YY_NULLPTR;]b4_pure_if([], [[ + yypstate_allocated = 1;]])[ + yystacksize = YYINITDEPTH; + yyss = yyssa; + yyvs = yyvsa;]b4_locations_if([[ + yyls = yylsa;]])[]b4_lac_if([[ + yyes = yyesa; + yyes_capacity = ]b4_percent_define_get([[parse.lac.es-capacity-initial]])[; + if (YYMAXDEPTH < yyes_capacity) + yyes_capacity = YYMAXDEPTH;]])[ + yypstate_clear (yyps); + return yyps; +} + +void +yypstate_delete (yypstate *yyps) +{ + if (yyps) + { +#ifndef yyoverflow + /* If the stack was reallocated but the parse did not complete, then the + stack still needs to be freed. */ + if (yyss != yyssa) + YYSTACK_FREE (yyss); +#endif]b4_lac_if([[ + if (yyes != yyesa) + YYSTACK_FREE (yyes);]])[ + YYFREE (yyps);]b4_pure_if([], [[ + yypstate_allocated = 0;]])[ + } +} +]])[ + +]b4_push_if([[ +/*---------------. +| yypush_parse. | +`---------------*/ + +int +yypush_parse (yypstate *yyps]b4_pure_if([[, + int yypushed_char, YYSTYPE const *yypushed_val]b4_locations_if([[, YYLTYPE *yypushed_loc]])])b4_user_formals[)]], +[[ +/*----------. +| yyparse. | +`----------*/ + +]m4_ifdef([b4_start_symbols], +[[// Extract data from the parser. +typedef struct +{ + YYSTYPE yyvalue; + int yynerrs; +} yy_parse_impl_t; + +// Run a full parse, using YYCHAR as switching token. +static int +yy_parse_impl (int yychar, yy_parse_impl_t *yyimpl]m4_ifset([b4_parse_param], [, b4_formals(b4_parse_param)])[); + +]m4_map([_b4_define_sub_yyparse], m4_defn([b4_start_symbols]))[ + +int +yyparse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[) +{ + return yy_parse_impl (]b4_symbol(_b4_first_switching_token, id)[, YY_NULLPTR]m4_ifset([b4_parse_param], + [[, ]b4_args(b4_parse_param)])[); +} + +static int +yy_parse_impl (int yychar, yy_parse_impl_t *yyimpl]m4_ifset([b4_parse_param], [, b4_formals(b4_parse_param)])[)]], +[[int +yyparse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[)]])])[ +{]b4_pure_if([b4_declare_scanner_communication_variables +])b4_push_if([b4_pure_if([], [[ + int yypushed_char = yychar; + YYSTYPE yypushed_val = yylval;]b4_locations_if([[ + YYLTYPE yypushed_loc = yylloc;]]) +])], + [b4_declare_parser_state_variables([init]) +])b4_lac_if([[ + /* Whether LAC context is established. A Boolean. */ + int yy_lac_established = 0;]])[ + int yyn; + /* The return value of yyparse. */ + int yyresult; + /* Lookahead symbol kind. */ + yysymbol_kind_t yytoken = ]b4_symbol(empty, kind)[; + /* The variables used to return semantic value and location from the + action routines. */ + YYSTYPE yyval;]b4_locations_if([[ + YYLTYPE yyloc; + + /* The locations where the error started and ended. */ + YYLTYPE yyerror_range[3];]])[ + +]b4_parse_error_bmatch([detailed\|verbose], +[[ /* Buffer for error messages, and its allocated size. */ + char yymsgbuf[128]; + char *yymsg = yymsgbuf; + YYPTRDIFF_T yymsg_alloc = sizeof yymsgbuf;]])[ + +#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)]b4_locations_if([, yylsp -= (N)])[) + + /* The number of symbols on the RHS of the reduced rule. + Keep to zero when no symbol should be popped. */ + int yylen = 0;]b4_push_if([[ + + switch (yyps->yynew) + { + case 0: + yyn = yypact[yystate]; + goto yyread_pushed_token; + + case 2: + yypstate_clear (yyps); + break; + + default: + break; + }]])[ + + YYDPRINTF ((stderr, "Starting parse\n")); + +]m4_ifdef([b4_start_symbols], [], +[[ yychar = ]b4_symbol(empty, id)[; /* Cause a token to be read. */ +]])[ +]m4_ifdef([b4_initial_action], [ +b4_dollar_pushdef([m4_define([b4_dollar_dollar_used])yylval], [], [], + [b4_push_if([b4_pure_if([*])yypushed_loc], [yylloc])])dnl +b4_user_initial_action +b4_dollar_popdef[]dnl +m4_ifdef([b4_dollar_dollar_used],[[ yyvsp[0] = yylval; +]])])dnl +b4_locations_if([[ yylsp[0] = ]b4_push_if([b4_pure_if([*])yypushed_loc], [yylloc])[; +]])dnl +[ goto yysetstate; + + +/*------------------------------------------------------------. +| yynewstate -- push a new state, which is found in yystate. | +`------------------------------------------------------------*/ +yynewstate: + /* In all cases, when you get here, the value and location stacks + have just been pushed. So pushing a state here evens the stacks. */ + yyssp++; + + +/*--------------------------------------------------------------------. +| yysetstate -- set current state (the top of the stack) to yystate. | +`--------------------------------------------------------------------*/ +yysetstate: + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + YY_ASSERT (0 <= yystate && yystate < YYNSTATES); + YY_IGNORE_USELESS_CAST_BEGIN + *yyssp = YY_CAST (yy_state_t, yystate); + YY_IGNORE_USELESS_CAST_END + YY_STACK_PRINT (yyss, yyssp); + + if (yyss + yystacksize - 1 <= yyssp) +#if !defined yyoverflow && !defined YYSTACK_RELOCATE + YYNOMEM; +#else + { + /* Get the current used size of the three stacks, in elements. */ + YYPTRDIFF_T yysize = yyssp - yyss + 1; + +# if defined yyoverflow + { + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + yy_state_t *yyss1 = yyss; + YYSTYPE *yyvs1 = yyvs;]b4_locations_if([ + YYLTYPE *yyls1 = yyls;])[ + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow (YY_("memory exhausted"), + &yyss1, yysize * YYSIZEOF (*yyssp), + &yyvs1, yysize * YYSIZEOF (*yyvsp),]b4_locations_if([ + &yyls1, yysize * YYSIZEOF (*yylsp),])[ + &yystacksize); + yyss = yyss1; + yyvs = yyvs1;]b4_locations_if([ + yyls = yyls1;])[ + } +# else /* defined YYSTACK_RELOCATE */ + /* Extend the stack our own way. */ + if (YYMAXDEPTH <= yystacksize) + YYNOMEM; + yystacksize *= 2; + if (YYMAXDEPTH < yystacksize) + yystacksize = YYMAXDEPTH; + + { + yy_state_t *yyss1 = yyss; + union yyalloc *yyptr = + YY_CAST (union yyalloc *, + YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); + if (! yyptr) + YYNOMEM; + YYSTACK_RELOCATE (yyss_alloc, yyss); + YYSTACK_RELOCATE (yyvs_alloc, yyvs);]b4_locations_if([ + YYSTACK_RELOCATE (yyls_alloc, yyls);])[ +# undef YYSTACK_RELOCATE + if (yyss1 != yyssa) + YYSTACK_FREE (yyss1); + } +# endif + + yyssp = yyss + yysize - 1; + yyvsp = yyvs + yysize - 1;]b4_locations_if([ + yylsp = yyls + yysize - 1;])[ + + YY_IGNORE_USELESS_CAST_BEGIN + YYDPRINTF ((stderr, "Stack size increased to %ld\n", + YY_CAST (long, yystacksize))); + YY_IGNORE_USELESS_CAST_END + + if (yyss + yystacksize - 1 <= yyssp) + YYABORT; + } +#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ + +]m4_ifdef([b4_start_symbols], [], [[ + if (yystate == YYFINAL) + YYACCEPT;]])[ + + goto yybackup; + + +/*-----------. +| yybackup. | +`-----------*/ +yybackup: + /* Do appropriate processing given the current state. Read a + lookahead token if we need one and don't already have one. */ + + /* First try to decide what to do without reference to lookahead token. */ + yyn = yypact[yystate]; + if (yypact_value_is_default (yyn)) + goto yydefault; + + /* Not known => get a lookahead token if don't already have one. */ + + /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */ + if (yychar == ]b4_symbol(empty, id)[) + {]b4_push_if([[ + if (!yyps->yynew) + {]b4_use_push_for_pull_if([], [[ + YYDPRINTF ((stderr, "Return for a new token:\n"));]])[ + yyresult = YYPUSH_MORE; + goto yypushreturn; + } + yyps->yynew = 0;]b4_pure_if([], [[ + /* Restoring the pushed token is only necessary for the first + yypush_parse invocation since subsequent invocations don't overwrite + it before jumping to yyread_pushed_token. */ + yychar = yypushed_char; + yylval = yypushed_val;]b4_locations_if([[ + yylloc = yypushed_loc;]])])[ +yyread_pushed_token:]])[ + YYDPRINTF ((stderr, "Reading a token\n"));]b4_push_if([b4_pure_if([[ + yychar = yypushed_char; + if (yypushed_val) + yylval = *yypushed_val;]b4_locations_if([[ + if (yypushed_loc) + yylloc = *yypushed_loc;]])])], [[ + yychar = ]b4_yylex[;]])[ + } + + if (yychar <= ]b4_symbol(eof, [id])[) + { + yychar = ]b4_symbol(eof, [id])[; + yytoken = ]b4_symbol(eof, [kind])[; + YYDPRINTF ((stderr, "Now at end of input.\n")); + } + else if (yychar == ]b4_symbol(error, [id])[) + { + /* The scanner already issued an error message, process directly + to error recovery. But do not keep the error token as + lookahead, it is too special and may lead us to an endless + loop in error recovery. */ + yychar = ]b4_symbol(undef, [id])[; + yytoken = ]b4_symbol(error, [kind])[;]b4_locations_if([[ + yyerror_range[1] = yylloc;]])[ + goto yyerrlab1; + } + else + { + yytoken = YYTRANSLATE (yychar); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); + } + + /* If the proper action on seeing token YYTOKEN is to reduce or to + detect an error, take that action. */ + yyn += yytoken; + if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)]b4_lac_if([[ + { + YY_LAC_ESTABLISH; + goto yydefault; + }]], [[ + goto yydefault;]])[ + yyn = yytable[yyn]; + if (yyn <= 0) + { + if (yytable_value_is_error (yyn)) + goto yyerrlab; + yyn = -yyn;]b4_lac_if([[ + YY_LAC_ESTABLISH;]])[ + goto yyreduce; + } + + /* Count tokens shifted since error; after three, turn off error + status. */ + if (yyerrstatus) + yyerrstatus--; + + /* Shift the lookahead token. */ + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); + yystate = yyn; + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END]b4_locations_if([ + *++yylsp = yylloc;])[ + + /* Discard the shifted token. */ + yychar = ]b4_symbol(empty, id)[;]b4_lac_if([[ + YY_LAC_DISCARD ("shift");]])[ + goto yynewstate; + + +/*-----------------------------------------------------------. +| yydefault -- do the default action for the current state. | +`-----------------------------------------------------------*/ +yydefault: + yyn = yydefact[yystate]; + if (yyn == 0) + goto yyerrlab; + goto yyreduce; + + +/*-----------------------------. +| yyreduce -- do a reduction. | +`-----------------------------*/ +yyreduce: + /* yyn is the number of a rule to reduce with. */ + yylen = yyr2[yyn]; + + /* If YYLEN is nonzero, implement the default value of the action: + '$$ = $1'. + + Otherwise, the following line sets YYVAL to garbage. + This behavior is undocumented and Bison + users should not rely upon it. Assigning to YYVAL + unconditionally makes the parser a bit smaller, and it avoids a + GCC warning that YYVAL may be used uninitialized. */ + yyval = yyvsp[1-yylen]; + +]b4_locations_if( +[[ /* Default location. */ + YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen); + yyerror_range[1] = yyloc;]])[ + YY_REDUCE_PRINT (yyn);]b4_lac_if([[ + { + int yychar_backup = yychar; + switch (yyn) + { +]b4_user_actions[ + default: break; + } + if (yychar_backup != yychar) + YY_LAC_DISCARD ("yychar change"); + }]], [[ + switch (yyn) + { +]b4_user_actions[ + 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 ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc); + + YYPOPSTACK (yylen); + yylen = 0; + + *++yyvsp = yyval;]b4_locations_if([ + *++yylsp = yyloc;])[ + + /* Now 'shift' the result of the reduction. Determine what state + that goes to, based on the state we popped back to and the rule + number reduced by. */ + { + const int yylhs = yyr1[yyn] - YYNTOKENS; + const int yyi = yypgoto[yylhs] + *yyssp; + yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp + ? yytable[yyi] + : yydefgoto[yylhs]); + } + + goto yynewstate; + + +/*--------------------------------------. +| 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 == ]b4_symbol(empty, id)[ ? ]b4_symbol(empty, kind)[ : YYTRANSLATE (yychar); + /* If not already recovering from an error, report this error. */ + if (!yyerrstatus) + { + ++yynerrs; +]b4_parse_error_case( + [custom], +[[ { + yypcontext_t yyctx + = {]b4_push_if([[yyps]], [[yyssp]b4_lac_if([[, yyesa, &yyes, &yyes_capacity]])])[, yytoken]b4_locations_if([[, &yylloc]])[};]b4_lac_if([[ + if (yychar != ]b4_symbol(empty, id)[) + YY_LAC_ESTABLISH;]])[ + if (yyreport_syntax_error (&yyctx]m4_ifset([b4_parse_param], + [[, ]b4_args(b4_parse_param)])[) == 2) + YYNOMEM; + }]], + [simple], +[[ yyerror (]b4_yyerror_args[YY_("syntax error"));]], +[[ { + yypcontext_t yyctx + = {]b4_push_if([[yyps]], [[yyssp]b4_lac_if([[, yyesa, &yyes, &yyes_capacity]])])[, yytoken]b4_locations_if([[, &yylloc]])[}; + char const *yymsgp = YY_("syntax error"); + int yysyntax_error_status;]b4_lac_if([[ + if (yychar != ]b4_symbol(empty, id)[) + YY_LAC_ESTABLISH;]])[ + yysyntax_error_status = yysyntax_error (&yymsg_alloc, &yymsg, &yyctx); + if (yysyntax_error_status == 0) + yymsgp = yymsg; + else if (yysyntax_error_status == -1) + { + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); + yymsg = YY_CAST (char *, + YYSTACK_ALLOC (YY_CAST (YYSIZE_T, yymsg_alloc))); + if (yymsg) + { + yysyntax_error_status + = yysyntax_error (&yymsg_alloc, &yymsg, &yyctx); + yymsgp = yymsg; + } + else + { + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + yysyntax_error_status = YYENOMEM; + } + } + yyerror (]b4_yyerror_args[yymsgp); + if (yysyntax_error_status == YYENOMEM) + YYNOMEM; + }]])[ + } +]b4_locations_if([[ + yyerror_range[1] = yylloc;]])[ + if (yyerrstatus == 3) + { + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ + + if (yychar <= ]b4_symbol(eof, [id])[) + { + /* Return failure if at end of input. */ + if (yychar == ]b4_symbol(eof, [id])[) + YYABORT; + } + else + { + yydestruct ("Error: discarding", + yytoken, &yylval]b4_locations_if([, &yylloc])[]b4_user_args[); + yychar = ]b4_symbol(empty, id)[; + } + } + + /* Else will try to reuse lookahead token after shifting the error + token. */ + goto yyerrlab1; + + +/*---------------------------------------------------. +| yyerrorlab -- error raised explicitly by YYERROR. | +`---------------------------------------------------*/ +yyerrorlab: + /* Pacify compilers when the user code never invokes YYERROR and the + label yyerrorlab therefore never appears in user code. */ + if (0) + YYERROR; + ++yynerrs; + + /* Do not reclaim the symbols of the rule whose action triggered + this YYERROR. */ + YYPOPSTACK (yylen); + yylen = 0; + YY_STACK_PRINT (yyss, yyssp); + yystate = *yyssp; + goto yyerrlab1; + + +/*-------------------------------------------------------------. +| yyerrlab1 -- common code for both syntax error and YYERROR. | +`-------------------------------------------------------------*/ +yyerrlab1: + yyerrstatus = 3; /* Each real token shifted decrements this. */ + + /* Pop stack until we find a state that shifts the error token. */ + for (;;) + { + yyn = yypact[yystate]; + if (!yypact_value_is_default (yyn)) + { + yyn += ]b4_symbol(error, kind)[; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == ]b4_symbol(error, kind)[) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } + + /* Pop the current state because it cannot handle the error token. */ + if (yyssp == yyss) + YYABORT; + +]b4_locations_if([[ yyerror_range[1] = *yylsp;]])[ + yydestruct ("Error: popping", + YY_ACCESSING_SYMBOL (yystate), yyvsp]b4_locations_if([, yylsp])[]b4_user_args[); + YYPOPSTACK (1); + yystate = *yyssp; + YY_STACK_PRINT (yyss, yyssp); + }]b4_lac_if([[ + + /* If the stack popping above didn't lose the initial context for the + current lookahead token, the shift below will for sure. */ + YY_LAC_DISCARD ("error recovery");]])[ + + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END +]b4_locations_if([[ + yyerror_range[2] = yylloc; + ++yylsp; + YYLLOC_DEFAULT (*yylsp, yyerror_range, 2);]])[ + + /* Shift the error token. */ + YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp); + + yystate = yyn; + goto yynewstate; + + +/*-------------------------------------. +| yyacceptlab -- YYACCEPT comes here. | +`-------------------------------------*/ +yyacceptlab: + yyresult = 0; + goto yyreturnlab; + + +/*-----------------------------------. +| yyabortlab -- YYABORT comes here. | +`-----------------------------------*/ +yyabortlab: + yyresult = 1; + goto yyreturnlab; + + +/*-----------------------------------------------------------. +| yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here. | +`-----------------------------------------------------------*/ +yyexhaustedlab: + yyerror (]b4_yyerror_args[YY_("memory exhausted")); + yyresult = 2; + goto yyreturnlab; + + +/*----------------------------------------------------------. +| yyreturnlab -- parsing is finished, clean up and return. | +`----------------------------------------------------------*/ +yyreturnlab: + if (yychar != ]b4_symbol(empty, id)[) + { + /* 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]b4_locations_if([, &yylloc])[]b4_user_args[); + } + /* Do not reclaim the symbols of the rule whose action triggered + this YYABORT or YYACCEPT. */ + YYPOPSTACK (yylen); + YY_STACK_PRINT (yyss, yyssp); + while (yyssp != yyss) + { + yydestruct ("Cleanup: popping", + YY_ACCESSING_SYMBOL (+*yyssp), yyvsp]b4_locations_if([, yylsp])[]b4_user_args[); + YYPOPSTACK (1); + }]b4_push_if([[ + yyps->yynew = 2; + goto yypushreturn; + + +/*-------------------------. +| yypushreturn -- return. | +`-------------------------*/ +yypushreturn:]], [[ +#ifndef yyoverflow + if (yyss != yyssa) + YYSTACK_FREE (yyss); +#endif]b4_lac_if([[ + if (yyes != yyesa) + YYSTACK_FREE (yyes);]])])[ +]b4_parse_error_bmatch([detailed\|verbose], +[[ if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg);]])[]m4_ifdef([b4_start_symbols], [[ + if (yyimpl) + yyimpl->yynerrs = yynerrs;]])[ + return yyresult; +} +]b4_push_if([b4_parse_state_variable_macros([b4_macro_undef])])[ +]b4_percent_code_get([[epilogue]])[]dnl +b4_epilogue[]dnl +b4_output_end diff --git a/Engine/bin/bison-flex/data/xslt/bison.xsl b/Engine/bin/bison-flex/data/xslt/bison.xsl new file mode 100644 index 000000000..989a3437f --- /dev/null +++ b/Engine/bin/bison-flex/data/xslt/bison.xsl @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + + + + + + + + + + s + + + r + + + + + + , + + + + + 0 + + + + + + + + + + + diff --git a/Engine/bin/bison-flex/data/xslt/xml2dot.xsl b/Engine/bin/bison-flex/data/xslt/xml2dot.xsl new file mode 100644 index 000000000..7715d1ac3 --- /dev/null +++ b/Engine/bin/bison-flex/data/xslt/xml2dot.xsl @@ -0,0 +1,401 @@ + + + + + + + + + + + + + + + // Generated by GNU Bison + + . + // Report bugs to < + + >. + // Home page: < + + >. + + + + + + + + digraph " + + + + " { + node [fontname = courier, shape = box, colorscheme = paired6] + edge [fontname = courier] + + + + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + label="[ + + + + + + , + + + ]", + + + + style=solid] + + + + + + + + + 3 + + + 5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + : + + + + . + + + + + + + . + + + + + + + + + + + %empty + + + + [ + + ] + + + + + + , + + + + + + + + + + + -> " + + R + + + d + + " [ + + + + + + + + " + + R + + + d + + " [label=" + + + Acc", fillcolor=1 + + + R + + ", fillcolor= + + + + , shape=diamond, style=filled] + + + + + + + + + + dotted + + + solid + + + dashed + + + + + + + + + + + + + + + + + [label=" + State + + \n + + + + \l"] + + + + + + + + + + -> + + [style= + + + label=" + + + + " + + ] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Engine/bin/bison-flex/data/xslt/xml2text.xsl b/Engine/bin/bison-flex/data/xslt/xml2text.xsl new file mode 100644 index 000000000..1fc5731a7 --- /dev/null +++ b/Engine/bin/bison-flex/data/xslt/xml2text.xsl @@ -0,0 +1,572 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Nonterminals useless in grammar + + + + + + + + + + + + Terminals unused in grammar + + + + + + + + + + + + + + Rules useless in grammar + + + + + + + + + + + Rules useless in parser due to conflicts + + + + + + + + + Grammar + + + + + + + + + + + + + + + + + + + + + + + + + Terminals, with rules where they appear + + + + + + Nonterminals, with rules where they appear + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + on@left: + + + + + + + + + on@right: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + State + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + : + + + + + + + + + + + + + + + + + + + + + + + + + + + %empty + + + + [ + + ] + + + + + + , + + + + + + + + + + + + + shift, and go to state + + + + go to state + + + + + + + + + + + + + + error + ( + + ) + + + + + + + + + + + + [ + + + + accept + + + reduce using rule + + ( + + ) + + + + ] + + + + + + + + + + + + + Conflict between rule + + and token + + resolved as + + an + + + ( + + ). + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Engine/bin/bison-flex/data/xslt/xml2xhtml.xsl b/Engine/bin/bison-flex/data/xslt/xml2xhtml.xsl new file mode 100644 index 000000000..aaa5dbaa2 --- /dev/null +++ b/Engine/bin/bison-flex/data/xslt/xml2xhtml.xsl @@ -0,0 +1,765 @@ + + + + + + + + + + + + + + + + <xsl:value-of select="bison-xml-report/filename"/> + <xsl:text> - GNU Bison XML Automaton Report</xsl:text> + + + + + + + + + + + + +

GNU Bison XML Automaton Report

+

+ input grammar: +

+ + +

Table of Contents

+ + + + + + +
+ + +

+ + Reductions +

+ + + +
+ + +

+ + Nonterminals useless in grammar +

+ + +

+ + + + + + +

+
+ + + +

+ + Terminals unused in grammar +

+ + +

+ + + + + + + +

+
+ + + +

+ + Rules useless in grammar +

+ + + +

+ + + + +

+
+ + + + + +

+ + Rules useless in parser due to conflicts +

+ +

+ + + +

+ + + + + +

+ + Grammar +

+ +

+ + + + +

+ + + + + + + + + + + + + + + + + + + + + + + +

+ + Conflicts +

+ + + + + +

+ + +

+
+ + + + + + + + + +
+ + + + + + conflicts: + + + + + + + + + + + + + + +

+ + Terminals, with rules where they appear +

+ +
    + + +
+ +
+ + +

+ + Nonterminals, with rules where they appear +

+ +
    + + +
+ + + + +
  • + + + + + + + + +
  • + +
    + + + +
  • + + + + + + +
      + + + +
    • + on left: + + + +
    • + +
      + + +
    • + on right: + + + +
    • + +
      + +
    + +
  • + +
    + + + +
    + + + + + + + + +

    + + Automaton +

    + + + +
    + + + + +

    + + + + + + State + +

    + +

    + + + + + + + + + + + + +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + %empty + + + + [ + + ] + + + + + + , + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + error + ( + + ) + + + + + + + + + + + + [ + + + + accept + + + + + + + + + ( + + ) + + + + ] + + + + + + + + + + + + + Conflict between + + + + + + + and token + + resolved as + + an + + + ( + + ). + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + +
    diff --git a/Engine/bin/bison/bison.exe b/Engine/bin/bison/bison.exe deleted file mode 100644 index 4881bf604..000000000 Binary files a/Engine/bin/bison/bison.exe and /dev/null differ diff --git a/Engine/bin/bison/bison.html b/Engine/bin/bison/bison.html deleted file mode 100644 index a89eaa329..000000000 --- a/Engine/bin/bison/bison.html +++ /dev/null @@ -1,4501 +0,0 @@ - - - -Bison 1.24 - - - -

    Bison -

    -

    The YACC-compatible Parser Generator -

    -

    May 1995, Bison Version 1.24 -

    -
    by Charles Donnelly and Richard Stallman -
    -

    -


    -

    Table of Contents

    - -


    -

      -

      Introduction

      -

      - -Bison is a general-purpose parser generator that converts a -grammar description for an LALR(1) context-free grammar into a C -program to parse that grammar. Once you are proficient with Bison, -you may use it to develop a wide range of language parsers, from those -used in simple desk calculators to complex programming languages. -

      -Bison is upward compatible with Yacc: all properly-written Yacc grammars -ought to work with Bison with no change. Anyone familiar with Yacc -should be able to use Bison with little trouble. You need to be fluent in -C programming in order to use Bison or to understand this manual. -

      -We begin with tutorial chapters that explain the basic concepts of using -Bison and show three explained examples, each building on the last. If you -don't know Bison or Yacc, start by reading these chapters. Reference -chapters follow which describe specific aspects of Bison in detail. -

      -Bison was written primarily by Robert Corbett; Richard Stallman made -it Yacc-compatible. This edition corresponds to version 1.24 of Bison. -

      -

      Conditions for Using Bison

      -

      -As of Bison version 1.24, we have changed the distribution terms for -yyparse to permit using Bison's output in non-free programs. -Formerly, Bison parsers could be used only in programs that were free -software. -

      -The other GNU programming tools, such as the GNU C compiler, have never -had such a requirement. They could always be used for non-free -software. The reason Bison was different was not due to a special -policy decision; it resulted from applying the usual General Public -License to all of the Bison source code. -

      -The output of the Bison utility--the Bison parser file--contains a -verbatim copy of a sizable piece of Bison, which is the code for the -yyparse function. (The actions from your grammar are inserted -into this function at one point, but the rest of the function is not -changed.) When we applied the GPL terms to the code for yyparse, -the effect was to restrict the use of Bison output to free software. -

      -We didn't change the terms because of sympathy for people who want to -make software proprietary. Software should be free. But we -concluded that limiting Bison's use to free software was doing little to -encourage people to make other software free. So we decided to make the -practical conditions for using Bison match the practical conditions for -using the other GNU tools. -

      -

      GNU GENERAL PUBLIC LICENSE

      -

      -Version 2, June 1991 -

      -Copyright (C) 1989, 1991 Free Software Foundation, Inc.
      -675 Mass Ave, Cambridge, MA 02139, USA
      -

      -Everyone is permitted to copy and distribute verbatim copies -of this license document, but changing it is not allowed. -

      -

      -

      Preamble

      -

      - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. -

      - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. -

      - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. -

      - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. -

      - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. -

      - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. -

      - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. -

      - The precise terms and conditions for copying, distribution and -modification follow. -

      -

      TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

      -

      -

        -
      1. -This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". -

        -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. -

        -

      2. -You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. -

        -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. -

        -

      3. -You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: -

        -

          -
        1. -You must cause the modified files to carry prominent notices -stating that you changed the files and the date of any change. -

          -

        2. -You must cause any work that you distribute or publish, that in -whole or in part contains or is derived from the Program or any -part thereof, to be licensed as a whole at no charge to all third -parties under the terms of this License. -

          -

        3. -If the modified program normally reads commands interactively -when run, you must cause it, when started running for such -interactive use in the most ordinary way, to print or display an -announcement including an appropriate copyright notice and a -notice that there is no warranty (or else, saying that you provide -a warranty) and that users may redistribute the program under -these conditions, and telling the user how to view a copy of this -License. (Exception: if the Program itself is interactive but -does not normally print such an announcement, your work based on -the Program is not required to print an announcement.) -

          -

        -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. -

        -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. -

        -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. -

        -

      4. -You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: -

        -

          -
        1. -Accompany it with the complete corresponding machine-readable -source code, which must be distributed under the terms of Sections -1 and 2 above on a medium customarily used for software interchange; or, -

          -

        2. -Accompany it with a written offer, valid for at least three -years, to give any third party, for a charge no more than your -cost of physically performing source distribution, a complete -machine-readable copy of the corresponding source code, to be -distributed under the terms of Sections 1 and 2 above on a medium -customarily used for software interchange; or, -

          -

        3. -Accompany it with the information you received as to the offer -to distribute corresponding source code. (This alternative is -allowed only for noncommercial distribution and only if you -received the program in object code or executable form with such -an offer, in accord with Subsection b above.) -

          -

        -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. -

        -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. -

        -

      5. -You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. -

        -

      6. -You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. -

        -

      7. -Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. -

        -

      8. -If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. -

        -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. -

        -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. -

        -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. -

        -

      9. -If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. -

        -

      10. -The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. -

        -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. -

        -

      11. -If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. -

        -

        NO WARRANTY

        -
      12. -BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. -

        -

      13. -IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. -

        -

      -

      -

      END OF TERMS AND CONDITIONS

      -

      -

      How to Apply These Terms to Your New Programs

      -

      - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. -

      - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. -

      -

        -one line to give the program's name and a brief idea of what it does.
        -Copyright (C) 19yy  name of author
        -

        -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 -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. -

        -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. -

        -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -

        -
      -

      -Also add information on how to contact you by electronic and paper mail. -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: -

        -
        -Gnomovision version 69, Copyright (C) 19yy name of author
        -Gnomovision comes with ABSOLUTELY NO WARRANTY; for details 
        -type `show w'.
        -This is free software, and you are welcome to redistribute it
        -under certain conditions; type `show c' for details.
        -
        -
      -

      -The hypothetical commands `show w' and `show c' should show -the appropriate parts of the General Public License. Of course, the -commands you use may be called something other than `show w' and -`show c'; they could even be mouse-clicks or menu items--whatever -suits your program. -

      -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: -

      -

        -
        -Yoyodyne, Inc., hereby disclaims all copyright interest in the program
        -`Gnomovision' (which makes passes at compilers) written by James Hacker.
        -

        -signature of Ty Coon, 1 April 1989 -Ty Coon, President of Vice -

        -
      -

      -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. -

      -

      The Concepts of Bison

      -

      -This chapter introduces many of the basic concepts without which the -details of Bison will not make sense. If you do not already know how to -use Bison or Yacc, we suggest you start by reading this chapter carefully. -

      Languages and Context-Free Grammars

      -

      - - -In order for Bison to parse a language, it must be described by a -context-free grammar. This means that you specify one or more -syntactic groupings and give rules for constructing them from their -parts. For example, in the C language, one kind of grouping is called an -`expression'. One rule for making an expression might be, "An expression -can be made of a minus sign and another expression". Another would be, -"An expression can be an integer". As you can see, rules are often -recursive, but there must be at least one rule which leads out of the -recursion. -

      - - -The most common formal system for presenting such rules for humans to read -is Backus-Naur Form or "BNF", which was developed in order to -specify the language Algol 60. Any grammar expressed in BNF is a -context-free grammar. The input to Bison is essentially machine-readable -BNF. -

      -Not all context-free languages can be handled by Bison, only those -that are LALR(1). In brief, this means that it must be possible to -tell how to parse any portion of an input string with just a single -token of look-ahead. Strictly speaking, that is a description of an -LR(1) grammar, and LALR(1) involves additional restrictions that are -hard to explain simply; but it is rare in actual practice to find an -LR(1) grammar that fails to be LALR(1). See section Mysterious Reduce/Reduce Conflicts, for more information on this. -

      - - - - -In the formal grammatical rules for a language, each kind of syntactic unit -or grouping is named by a symbol. Those which are built by grouping -smaller constructs according to grammatical rules are called -nonterminal symbols; those which can't be subdivided are called -terminal symbols or token types. We call a piece of input -corresponding to a single terminal symbol a token, and a piece -corresponding to a single nonterminal symbol a grouping. -We can use the C language as an example of what symbols, terminal and -nonterminal, mean. The tokens of C are identifiers, constants (numeric and -string), and the various keywords, arithmetic operators and punctuation -marks. So the terminal symbols of a grammar for C include `identifier', -`number', `string', plus one symbol for each keyword, operator or -punctuation mark: `if', `return', `const', `static', `int', `char', -`plus-sign', `open-brace', `close-brace', `comma' and many more. (These -tokens can be subdivided into characters, but that is a matter of -lexicography, not grammar.) -

      -Here is a simple C function subdivided into tokens: -

      -

      -
      -int             /* keyword `int' */
      -square (x)      /* identifier, open-paren, */
      -                /* identifier, close-paren */
      -     int x;     /* keyword `int', identifier, semicolon */
      -{               /* open-brace */
      -  return x * x; /* keyword `return', identifier, */
      -                /* asterisk, identifier, semicolon */
      -}               /* close-brace */
      -
      -
      -

      -The syntactic groupings of C include the expression, the statement, the -declaration, and the function definition. These are represented in the -grammar of C by nonterminal symbols `expression', `statement', -`declaration' and `function definition'. The full grammar uses dozens of -additional language constructs, each with its own nonterminal symbol, in -order to express the meanings of these four. The example above is a -function definition; it contains one declaration, and one statement. In -the statement, each `x' is an expression and so is `x * x'. -Each nonterminal symbol must have grammatical rules showing how it is made -out of simpler constructs. For example, one kind of C statement is the -return statement; this would be described with a grammar rule which -reads informally as follows: -

      -

      -A `statement' can be made of a `return' keyword, an `expression' and a -`semicolon'. -

      -

      -There would be many other rules for `statement', one for each kind of -statement in C. -

      - -One nonterminal symbol must be distinguished as the special one which -defines a complete utterance in the language. It is called the start -symbol. In a compiler, this means a complete input program. In the C -language, the nonterminal symbol `sequence of definitions and declarations' -plays this role. -

      -For example, `1 + 2' is a valid C expression--a valid part of a C -program--but it is not valid as an entire C program. In the -context-free grammar of C, this follows from the fact that `expression' is -not the start symbol. -

      -The Bison parser reads a sequence of tokens as its input, and groups the -tokens using the grammar rules. If the input is valid, the end result is -that the entire token sequence reduces to a single grouping whose symbol is -the grammar's start symbol. If we use a grammar for C, the entire input -must be a `sequence of definitions and declarations'. If not, the parser -reports a syntax error. -

      -

      From Formal Rules to Bison Input

      -

      - - - -A formal grammar is a mathematical construct. To define the language -for Bison, you must write a file expressing the grammar in Bison syntax: -a Bison grammar file. See section Bison Grammar Files. -A nonterminal symbol in the formal grammar is represented in Bison input -as an identifier, like an identifier in C. By convention, it should be -in lower case, such as expr, stmt or declaration. -The Bison representation for a terminal symbol is also called a token -type. Token types as well can be represented as C-like identifiers. By -convention, these identifiers should be upper case to distinguish them from -nonterminals: for example, INTEGER, IDENTIFIER, IF or -RETURN. A terminal symbol that stands for a particular keyword in -the language should be named after that keyword converted to upper case. -The terminal symbol error is reserved for error recovery. -

      -See section Symbols, Terminal and Nonterminal. -A terminal symbol can also be represented as a character literal, just like -a C character constant. You should do this whenever a token is just a -single character (parenthesis, plus-sign, etc.): use that same character in -a literal as the terminal symbol for that token. -

      -The grammar rules also have an expression in Bison syntax. For example, -here is the Bison rule for a C return statement. The semicolon in -quotes is a literal character token, representing part of the C syntax for -the statement; the naked semicolon, and the colon, are Bison punctuation -used in every rule. -

      -

      -
      -stmt:   RETURN expr ';'
      -        ;
      -
      -
      -

      -See section Syntax of Grammar Rules. -

      -

      Semantic Values

      -

      - - -A formal grammar selects tokens only by their classifications: for example, -if a rule mentions the terminal symbol `integer constant', it means that -any integer constant is grammatically valid in that position. The -precise value of the constant is irrelevant to how to parse the input: if -`x+4' is grammatical then `x+1' or `x+3989' is equally -grammatical. -

      -But the precise value is very important for what the input means once it is -parsed. A compiler is useless if it fails to distinguish between 4, 1 and -3989 as constants in the program! Therefore, each token in a Bison grammar -has both a token type and a semantic value. See section Defining Language Semantics, -for details. -

      -The token type is a terminal symbol defined in the grammar, such as -INTEGER, IDENTIFIER or ','. It tells everything -you need to know to decide where the token may validly appear and how to -group it with other tokens. The grammar rules know nothing about tokens -except their types. -

      -The semantic value has all the rest of the information about the -meaning of the token, such as the value of an integer, or the name of an -identifier. (A token such as ',' which is just punctuation doesn't -need to have any semantic value.) -

      -For example, an input token might be classified as token type -INTEGER and have the semantic value 4. Another input token might -have the same token type INTEGER but value 3989. When a grammar -rule says that INTEGER is allowed, either of these tokens is -acceptable because each is an INTEGER. When the parser accepts the -token, it keeps track of the token's semantic value. -

      -Each grouping can also have a semantic value as well as its nonterminal -symbol. For example, in a calculator, an expression typically has a -semantic value that is a number. In a compiler for a programming -language, an expression typically has a semantic value that is a tree -structure describing the meaning of the expression. -

      -

      Semantic Actions

      -

      - - -In order to be useful, a program must do more than parse input; it must -also produce some output based on the input. In a Bison grammar, a grammar -rule can have an action made up of C statements. Each time the -parser recognizes a match for that rule, the action is executed. -See section Actions. -

      -Most of the time, the purpose of an action is to compute the semantic value -of the whole construct from the semantic values of its parts. For example, -suppose we have a rule which says an expression can be the sum of two -expressions. When the parser recognizes such a sum, each of the -subexpressions has a semantic value which describes how it was built up. -The action for this rule should create a similar sort of value for the -newly recognized larger expression. -For example, here is a rule that says an expression can be the sum of -two subexpressions: -

      -

      -
      -expr: expr '+' expr   { $$ = $1 + $3; }
      -        ;
      -
      -
      -

      -The action says how to produce the semantic value of the sum expression -from the values of the two subexpressions. -

      Bison Output: the Parser File

      -

      - - - - -When you run Bison, you give it a Bison grammar file as input. The output -is a C source file that parses the language described by the grammar. -This file is called a Bison parser. Keep in mind that the Bison -utility and the Bison parser are two distinct programs: the Bison utility -is a program whose output is the Bison parser that becomes part of your -program. -

      -The job of the Bison parser is to group tokens into groupings according to -the grammar rules--for example, to build identifiers and operators into -expressions. As it does this, it runs the actions for the grammar rules it -uses. -

      -The tokens come from a function called the lexical analyzer that you -must supply in some fashion (such as by writing it in C). The Bison parser -calls the lexical analyzer each time it wants a new token. It doesn't know -what is "inside" the tokens (though their semantic values may reflect -this). Typically the lexical analyzer makes the tokens by parsing -characters of text, but Bison does not depend on this. See section The Lexical Analyzer Function yylex. -The Bison parser file is C code which defines a function named -yyparse which implements that grammar. This function does not make -a complete C program: you must supply some additional functions. One is -the lexical analyzer. Another is an error-reporting function which the -parser calls to report an error. In addition, a complete C program must -start with a function called main; you have to provide this, and -arrange for it to call yyparse or the parser will never run. -See section Parser C-Language Interface. -Aside from the token type names and the symbols in the actions you -write, all variable and function names used in the Bison parser file -begin with `yy' or `YY'. This includes interface functions -such as the lexical analyzer function yylex, the error reporting -function yyerror and the parser function yyparse itself. -This also includes numerous identifiers used for internal purposes. -Therefore, you should avoid using C identifiers starting with `yy' -or `YY' in the Bison grammar file except for the ones defined in -this manual. -

      Stages in Using Bison

      -

      - - -The actual language-design process using Bison, from grammar specification -to a working compiler or interpreter, has these parts: -

        -
      1. -Formally specify the grammar in a form recognized by Bison -(see section Bison Grammar Files). For each grammatical rule in the language, -describe the action that is to be taken when an instance of that rule -is recognized. The action is described by a sequence of C statements. -
      2. -Write a lexical analyzer to process input and pass tokens to the -parser. The lexical analyzer may be written by hand in C -(see section The Lexical Analyzer Function yylex). It could also be produced using Lex, but the use -of Lex is not discussed in this manual. -
      3. -Write a controlling function that calls the Bison-produced parser. -
      4. -Write error-reporting routines. -
      -

      -To turn this source code as written into a runnable program, you -must follow these steps: -

        -
      1. -Run Bison on the grammar to produce the parser. -
      2. -Compile the code output by Bison, as well as any other source files. -
      3. -Link the object files to produce the finished product. -
      -

      -

      The Overall Layout of a Bison Grammar

      -

      - - - - -The input file for the Bison utility is a Bison grammar file. The -general form of a Bison grammar file is as follows: -

      -%{
      -C declarations
      -%}
      -Bison declarations
      -%%
      -Grammar rules
      -%%
      -Additional C code
      -
      -

      -The `%%', `%{' and `%}' are punctuation that appears -in every Bison grammar file to separate the sections. -The C declarations may define types and variables used in the actions. -You can also use preprocessor commands to define macros used there, and use -#include to include header files that do any of these things. -The Bison declarations declare the names of the terminal and nonterminal -symbols, and may also describe operator precedence and the data types of -semantic values of various symbols. -

      -The grammar rules define how to construct each nonterminal symbol from its -parts. -

      -The additional C code can contain any C code you want to use. Often the -definition of the lexical analyzer yylex goes here, plus subroutines -called by the actions in the grammar rules. In a simple program, all the -rest of the program can go here. -

      -

      Examples

      -

      - - -Now we show and explain three sample programs written using Bison: a -reverse polish notation calculator, an algebraic (infix) notation -calculator, and a multi-function calculator. All three have been tested -under BSD Unix 4.3; each produces a usable, though limited, interactive -desk-top calculator. -

      -These examples are simple, but Bison grammars for real programming -languages are written the same way. -

      -

      Reverse Polish Notation Calculator

      -

      - - - - -The first example is that of a simple double-precision reverse polish -notation calculator (a calculator using postfix operators). This example -provides a good starting point, since operator precedence is not an issue. -

      -The second example will illustrate how operator precedence is handled. -The source code for this calculator is named `rpcalc.y'. The -`.y' extension is a convention used for Bison input files. -

      Declarations for rpcalc

      -

      -Here are the C and Bison declarations for the reverse polish notation -calculator. As in C, comments are placed between `/*...*/'. -

      -

      -/* Reverse polish notation calculator. */
      -%{
      -#define YYSTYPE double
      -#include <math.h>
      -%}
      -%token NUM
      -%% /* Grammar rules and actions follow */
      -
      -

      -The C declarations section (see section The C Declarations Section) contains two -preprocessor directives. -

      -The #define directive defines the macro YYSTYPE, thus -specifying the C data type for semantic values of both tokens and groupings -(see section Data Types of Semantic Values). The Bison parser will use whatever type -YYSTYPE is defined as; if you don't define it, int is the -default. Because we specify double, each token and each expression -has an associated value, which is a floating point number. -

      -The #include directive is used to declare the exponentiation -function pow. -

      -The second section, Bison declarations, provides information to Bison about -the token types (see section The Bison Declarations Section). Each terminal symbol that is -not a single-character literal must be declared here. (Single-character -literals normally don't need to be declared.) In this example, all the -arithmetic operators are designated by single-character literals, so the -only terminal symbol that needs to be declared is NUM, the token -type for numeric constants. -

      -

      Grammar Rules for rpcalc

      -

      -Here are the grammar rules for the reverse polish notation calculator. -

      -

      -
      -input:    /* empty */
      -        | input line
      -;
      -line:     '\n'
      -        | exp '\n'  { printf ("\t%.10g\n", $1); }
      -;
      -exp:      NUM             { $$ = $1;         }
      -        | exp exp '+'     { $$ = $1 + $2;    }
      -        | exp exp '-'     { $$ = $1 - $2;    }
      -        | exp exp '*'     { $$ = $1 * $2;    }
      -        | exp exp '/'     { $$ = $1 / $2;    }
      -      /* Exponentiation */
      -        | exp exp '^'     { $$ = pow ($1, $2); }
      -      /* Unary minus    */
      -        | exp 'n'         { $$ = -$1;        }
      -;
      -%%
      -
      -
      -

      -The groupings of the rpcalc "language" defined here are the expression -(given the name exp), the line of input (line), and the -complete input transcript (input). Each of these nonterminal -symbols has several alternate rules, joined by the `|' punctuator -which is read as "or". The following sections explain what these rules -mean. -

      -The semantics of the language is determined by the actions taken when a -grouping is recognized. The actions are the C code that appears inside -braces. See section Actions. -

      -You must specify these actions in C, but Bison provides the means for -passing semantic values between the rules. In each action, the -pseudo-variable $$ stands for the semantic value for the grouping -that the rule is going to construct. Assigning a value to $$ is the -main job of most actions. The semantic values of the components of the -rule are referred to as $1, $2, and so on. -

      -

      Explanation of input

      -

      -Consider the definition of input: -

      -

      -
      -input:    /* empty */
      -        | input line
      -;
      -
      -
      -

      -This definition reads as follows: "A complete input is either an empty -string, or a complete input followed by an input line". Notice that -"complete input" is defined in terms of itself. This definition is said -to be left recursive since input appears always as the -leftmost symbol in the sequence. See section Recursive Rules. -

      -The first alternative is empty because there are no symbols between the -colon and the first `|'; this means that input can match an -empty string of input (no tokens). We write the rules this way because it -is legitimate to type Ctrl-d right after you start the calculator. -

      -It's conventional to put an empty alternative first and write the comment -`/* empty */' in it. -

      -The second alternate rule (input line) handles all nontrivial input. -It means, "After reading any number of lines, read one more line if -possible." The left recursion makes this rule into a loop. Since the -first alternative matches empty input, the loop can be executed zero or -more times. -

      -The parser function yyparse continues to process input until a -grammatical error is seen or the lexical analyzer says there are no more -input tokens; we will arrange for the latter to happen at end of file. -

      Explanation of line

      -

      -Now consider the definition of line: -

      -
      -line: '\n' - | exp '\n' { printf ("\t%.10g\n", $1); } -; -
      - -

      -The first alternative is a token which is a newline character; this means -that rpcalc accepts a blank line (and ignores it, since there is no -action). The second alternative is an expression followed by a newline. -This is the alternative that makes rpcalc useful. The semantic value of -the exp grouping is the value of $1 because the exp in -question is the first symbol in the alternative. The action prints this -value, which is the result of the computation the user asked for. -This action is unusual because it does not assign a value to $$. As -a consequence, the semantic value associated with the line is -uninitialized (its value will be unpredictable). This would be a bug if -that value were ever used, but we don't use it: once rpcalc has printed the -value of the user's input line, that value is no longer needed. -

      Explanation of expr

      -

      -The exp grouping has several rules, one for each kind of expression. -The first rule handles the simplest expressions: those that are just numbers. -The second handles an addition-expression, which looks like two expressions -followed by a plus-sign. The third handles subtraction, and so on. -

      -
      -exp:      NUM
      -        | exp exp '+'     { $$ = $1 + $2;    }
      -        | exp exp '-'     { $$ = $1 - $2;    }
      -        ...
      -        ;
      -
      -
      -

      -We have used `|' to join all the rules for exp, but we could -equally well have written them separately: -

      -
      -exp:      NUM ;
      -exp:      exp exp '+'     { $$ = $1 + $2;    } ;
      -exp:      exp exp '-'     { $$ = $1 - $2;    } ;
      -        ...
      -
      -
      -

      -Most of the rules have actions that compute the value of the expression in -terms of the value of its parts. For example, in the rule for addition, -$1 refers to the first component exp and $2 refers to -the second one. The third component, '+', has no meaningful -associated semantic value, but if it had one you could refer to it as -$3. When yyparse recognizes a sum expression using this -rule, the sum of the two subexpressions' values is produced as the value of -the entire expression. See section Actions. -You don't have to give an action for every rule. When a rule has no -action, Bison by default copies the value of $1 into $$. -This is what happens in the first rule (the one that uses NUM). -The formatting shown here is the recommended convention, but Bison does -not require it. You can add or change whitespace as much as you wish. -For example, this: -

      -exp   : NUM | exp exp '+' {$$ = $1 + $2; } | ...
      -
      -

      -means the same thing as this: -

      -exp:      NUM
      -        | exp exp '+'    { $$ = $1 + $2; }
      -        | ...
      -
      -

      -The latter, however, is much more readable. -

      The rpcalc Lexical Analyzer

      -

      - - -The lexical analyzer's job is low-level parsing: converting characters or -sequences of characters into tokens. The Bison parser gets its tokens by -calling the lexical analyzer. See section The Lexical Analyzer Function yylex. -Only a simple lexical analyzer is needed for the RPN calculator. This -lexical analyzer skips blanks and tabs, then reads in numbers as -double and returns them as NUM tokens. Any other character -that isn't part of a number is a separate token. Note that the token-code -for such a single-character token is the character itself. -The return value of the lexical analyzer function is a numeric code which -represents a token type. The same text used in Bison rules to stand for -this token type is also a C expression for the numeric code for the type. -This works in two ways. If the token type is a character literal, then its -numeric code is the ASCII code for that character; you can use the same -character literal in the lexical analyzer to express the number. If the -token type is an identifier, that identifier is defined by Bison as a C -macro whose definition is the appropriate number. In this example, -therefore, NUM becomes a macro for yylex to use. -The semantic value of the token (if it has one) is stored into the global -variable yylval, which is where the Bison parser will look for it. -(The C data type of yylval is YYSTYPE, which was defined -at the beginning of the grammar; see section Declarations for rpcalc.) -A token type code of zero is returned if the end-of-file is encountered. -(Bison recognizes any nonpositive value as indicating the end of the -input.) -Here is the code for the lexical analyzer: -

      -/* Lexical analyzer returns a double floating point 
      -   number on the stack and the token NUM, or the ASCII
      -   character read if not a number.  Skips all blanks
      -   and tabs, returns 0 for EOF. */
      -#include <ctype.h>
      -yylex ()
      -{
      -  int c;
      -  /* skip white space  */
      -  while ((c = getchar ()) == ' ' || c == '\t')  
      -    ;
      -  /* process numbers   */
      -  if (c == '.' || isdigit (c))                
      -    {
      -      ungetc (c, stdin);
      -      scanf ("%lf", &yylval);
      -      return NUM;
      -    }
      -  /* return end-of-file  */
      -  if (c == EOF)                            
      -    return 0;
      -  /* return single chars */
      -  return c;                                
      -}
      -
      -

      -

      The Controlling Function

      -

      - - -In keeping with the spirit of this example, the controlling function is -kept to the bare minimum. The only requirement is that it call -yyparse to start the process of parsing. -

      -main ()
      -{
      -  yyparse ();
      -}
      -
      -

      -

      The Error Reporting Routine

      -

      - -When yyparse detects a syntax error, it calls the error reporting -function yyerror to print an error message (usually but not always -"parse error"). It is up to the programmer to supply yyerror -(see section Parser C-Language Interface), so here is the definition we will use: -

      -#include <stdio.h>
      -yyerror (s)  /* Called by yyparse on error */
      -     char *s;
      -{
      -  printf ("%s\n", s);
      -}
      -
      -

      -After yyerror returns, the Bison parser may recover from the error -and continue parsing if the grammar contains a suitable error rule -(see section Error Recovery). Otherwise, yyparse returns nonzero. We -have not written any error rules in this example, so any invalid input will -cause the calculator program to exit. This is not clean behavior for a -real calculator, but it is adequate in the first example. -

      Running Bison to Make the Parser

      -

      - -Before running Bison to produce a parser, we need to decide how to arrange -all the source code in one or more source files. For such a simple example, -the easiest thing is to put everything in one file. The definitions of -yylex, yyerror and main go at the end, in the -"additional C code" section of the file (see section The Overall Layout of a Bison Grammar). -For a large project, you would probably have several source files, and use -make to arrange to recompile them. -With all the source in a single file, you use the following command to -convert it into a parser file: -

      -bison file_name.y
      -
      -

      -In this example the file was called `rpcalc.y' (for "Reverse Polish -CALCulator"). Bison produces a file named `file_name.tab.c', -removing the `.y' from the original file name. The file output by -Bison contains the source code for yyparse. The additional -functions in the input file (yylex, yyerror and main) -are copied verbatim to the output. -

      Compiling the Parser File

      -

      - -Here is how to compile and run the parser file: -

      -# List files in current directory.
      -% ls
      -rpcalc.tab.c  rpcalc.y
      -# Compile the Bison parser.
      -# `-lm' tells compiler to search math library for pow.
      -% cc rpcalc.tab.c -lm -o rpcalc
      -# List files again.
      -% ls
      -rpcalc  rpcalc.tab.c  rpcalc.y
      -
      -

      -The file `rpcalc' now contains the executable code. Here is an -example session using rpcalc. -

      -% rpcalc
      -4 9 +
      -13
      -3 7 + 3 4 5 *+-
      --13
      -3 7 + 3 4 5 * + - n              Note the unary minus, `n'
      -13
      -5 6 / 4 n +
      --3.166666667
      -3 4 ^                            Exponentiation
      -81
      -^D                               End-of-file indicator
      -%
      -
      -

      -

      Infix Notation Calculator: calc

      -

      - - - -We now modify rpcalc to handle infix operators instead of postfix. Infix -notation involves the concept of operator precedence and the need for -parentheses nested to arbitrary depth. Here is the Bison code for -`calc.y', an infix desk-top calculator. -

      -/* Infix notation calculator--calc */
      -%{
      -#define YYSTYPE double
      -#include <math.h>
      -%}
      -/* BISON Declarations */
      -%token NUM
      -%left '-' '+'
      -%left '*' '/'
      -%left NEG     /* negation--unary minus */
      -%right '^'    /* exponentiation        */
      -/* Grammar follows */
      -%%
      -input:    /* empty string */
      -        | input line
      -;
      -line:     '\n'
      -        | exp '\n'  { printf ("\t%.10g\n", $1); }
      -;
      -exp:      NUM                { $$ = $1;         }
      -        | exp '+' exp        { $$ = $1 + $3;    }
      -        | exp '-' exp        { $$ = $1 - $3;    }
      -        | exp '*' exp        { $$ = $1 * $3;    }
      -        | exp '/' exp        { $$ = $1 / $3;    }
      -        | '-' exp  %prec NEG { $$ = -$2;        }
      -        | exp '^' exp        { $$ = pow ($1, $3); }
      -        | '(' exp ')'        { $$ = $2;         }
      -;
      -%%
      -
      -

      -The functions yylex, yyerror and main can be the same -as before. -There are two important new features shown in this code. -In the second section (Bison declarations), %left declares token -types and says they are left-associative operators. The declarations -%left and %right (right associativity) take the place of -%token which is used to declare a token type name without -associativity. (These tokens are single-character literals, which -ordinarily don't need to be declared. We declare them here to specify -the associativity.) -Operator precedence is determined by the line ordering of the -declarations; the higher the line number of the declaration (lower on -the page or screen), the higher the precedence. Hence, exponentiation -has the highest precedence, unary minus (NEG) is next, followed -by `*' and `/', and so on. See section Operator Precedence. -The other important new feature is the %prec in the grammar section -for the unary minus operator. The %prec simply instructs Bison that -the rule `| '-' exp' has the same precedence as NEG---in this -case the next-to-highest. See section Context-Dependent Precedence. -Here is a sample run of `calc.y': -

      -% calc
      -4 + 4.5 - (34/(8*3+-3))
      -6.880952381
      --56 + 2
      --54
      -3 ^ 2
      -9
      -
      -

      -

      Simple Error Recovery

      -

      - -Up to this point, this manual has not addressed the issue of error -recovery---how to continue parsing after the parser detects a syntax -error. All we have handled is error reporting with yyerror. Recall -that by default yyparse returns after calling yyerror. This -means that an erroneous input line causes the calculator program to exit. -Now we show how to rectify this deficiency. -The Bison language itself includes the reserved word error, which -may be included in the grammar rules. In the example below it has -been added to one of the alternatives for line: -

      -line:     '\n'
      -        | exp '\n'   { printf ("\t%.10g\n", $1); }
      -        | error '\n' { yyerrok;                  }
      -;
      -
      -

      -This addition to the grammar allows for simple error recovery in the event -of a parse error. If an expression that cannot be evaluated is read, the -error will be recognized by the third rule for line, and parsing -will continue. (The yyerror function is still called upon to print -its message as well.) The action executes the statement yyerrok, a -macro defined automatically by Bison; its meaning is that error recovery is -complete (see section Error Recovery). Note the difference between -yyerrok and yyerror; neither one is a misprint. -This form of error recovery deals with syntax errors. There are other -kinds of errors; for example, division by zero, which raises an exception -signal that is normally fatal. A real calculator program must handle this -signal and use longjmp to return to main and resume parsing -input lines; it would also have to discard the rest of the current line of -input. We won't discuss this issue further because it is not specific to -Bison programs. -

      Multi-Function Calculator: mfcalc

      -

      - - - -Now that the basics of Bison have been discussed, it is time to move on to -a more advanced problem. The above calculators provided only five -functions, `+', `-', `*', `/' and `^'. It would -be nice to have a calculator that provides other mathematical functions such -as sin, cos, etc. -It is easy to add new operators to the infix calculator as long as they are -only single-character literals. The lexical analyzer yylex passes -back all non-number characters as tokens, so new grammar rules suffice for -adding a new operator. But we want something more flexible: built-in -functions whose syntax has this form: -

      -function_name (argument)
      -
      -

      -At the same time, we will add memory to the calculator, by allowing you -to create named variables, store values in them, and use them later. -Here is a sample session with the multi-function calculator: -

      -% mfcalc
      -pi = 3.141592653589
      -3.1415926536
      -sin(pi)
      -0.0000000000
      -alpha = beta1 = 2.3
      -2.3000000000
      -alpha
      -2.3000000000
      -ln(alpha)
      -0.8329091229
      -exp(ln(beta1))
      -2.3000000000
      -%
      -
      -

      -Note that multiple assignment and nested function calls are permitted. -

      Declarations for mfcalc

      -

      -Here are the C and Bison declarations for the multi-function calculator. -

      -%{
      -#include <math.h>  /* For math functions, cos(), sin(), etc. */
      -#include "calc.h"  /* Contains definition of `symrec'        */
      -%}
      -%union {
      -double     val;  /* For returning numbers.                   */
      -symrec  *tptr;   /* For returning symbol-table pointers      */
      -}
      -%token <val>  NUM        /* Simple double precision number   */
      -%token <tptr> VAR FNCT   /* Variable and Function            */
      -%type  <val>  exp
      -%right '='
      -%left '-' '+'
      -%left '*' '/'
      -%left NEG     /* Negation--unary minus */
      -%right '^'    /* Exponentiation        */
      -/* Grammar follows */
      -%%
      -
      -

      -The above grammar introduces only two new features of the Bison language. -These features allow semantic values to have various data types -(see section More Than One Value Type). -The %union declaration specifies the entire list of possible types; -this is instead of defining YYSTYPE. The allowable types are now -double-floats (for exp and NUM) and pointers to entries in -the symbol table. See section The Collection of Value Types. -Since values can now have various types, it is necessary to associate a -type with each grammar symbol whose semantic value is used. These symbols -are NUM, VAR, FNCT, and exp. Their -declarations are augmented with information about their data type (placed -between angle brackets). -The Bison construct %type is used for declaring nonterminal symbols, -just as %token is used for declaring token types. We have not used -%type before because nonterminal symbols are normally declared -implicitly by the rules that define them. But exp must be declared -explicitly so we can specify its value type. See section Nonterminal Symbols. -

      Grammar Rules for mfcalc

      -

      -Here are the grammar rules for the multi-function calculator. -Most of them are copied directly from calc; three rules, -those which mention VAR or FNCT, are new. -

      -input:   /* empty */
      -        | input line
      -;
      -line:
      -          '\n'
      -        | exp '\n'   { printf ("\t%.10g\n", $1); }
      -        | error '\n' { yyerrok;                  }
      -;
      -exp:      NUM                { $$ = $1;                         }
      -        | VAR                { $$ = $1->value.var;              }
      -        | VAR '=' exp        { $$ = $3; $1->value.var = $3;     }
      -        | FNCT '(' exp ')'   { $$ = (*($1->value.fnctptr))($3); }
      -        | exp '+' exp        { $$ = $1 + $3;                    }
      -        | exp '-' exp        { $$ = $1 - $3;                    }
      -        | exp '*' exp        { $$ = $1 * $3;                    }
      -        | exp '/' exp        { $$ = $1 / $3;                    }
      -        | '-' exp  %prec NEG { $$ = -$2;                        }
      -        | exp '^' exp        { $$ = pow ($1, $3);               }
      -        | '(' exp ')'        { $$ = $2;                         }
      -;
      -/* End of grammar */
      -%%
      -
      -

      -

      The mfcalc Symbol Table

      -

      - -The multi-function calculator requires a symbol table to keep track of the -names and meanings of variables and functions. This doesn't affect the -grammar rules (except for the actions) or the Bison declarations, but it -requires some additional C functions for support. -The symbol table itself consists of a linked list of records. Its -definition, which is kept in the header `calc.h', is as follows. It -provides for either functions or variables to be placed in the table. -

      -/* Data type for links in the chain of symbols.      */
      -struct symrec
      -{
      -  char *name;  /* name of symbol                     */
      -  int type;    /* type of symbol: either VAR or FNCT */
      -  union {
      -    double var;           /* value of a VAR          */
      -    double (*fnctptr)();  /* value of a FNCT         */
      -  } value;
      -  struct symrec *next;    /* link field              */
      -};
      -typedef struct symrec symrec;
      -/* The symbol table: a chain of `struct symrec'.     */
      -extern symrec *sym_table;
      -symrec *putsym ();
      -symrec *getsym ();
      -
      -

      -The new version of main includes a call to init_table, a -function that initializes the symbol table. Here it is, and -init_table as well: -

      -#include <stdio.h>
      -main ()
      -{
      -  init_table ();
      -  yyparse ();
      -}
      -yyerror (s)  /* Called by yyparse on error */
      -     char *s;
      -{
      -  printf ("%s\n", s);
      -}
      -struct init
      -{
      -  char *fname;
      -  double (*fnct)();
      -};
      -struct init arith_fncts[]
      -  = {
      -      "sin", sin,
      -      "cos", cos,
      -      "atan", atan,
      -      "ln", log,
      -      "exp", exp,
      -      "sqrt", sqrt,
      -      0, 0
      -    };
      -/* The symbol table: a chain of `struct symrec'.  */
      -symrec *sym_table = (symrec *)0;
      -init_table ()  /* puts arithmetic functions in table. */
      -{
      -  int i;
      -  symrec *ptr;
      -  for (i = 0; arith_fncts[i].fname != 0; i++)
      -    {
      -      ptr = putsym (arith_fncts[i].fname, FNCT);
      -      ptr->value.fnctptr = arith_fncts[i].fnct;
      -    }
      -}
      -
      -

      -By simply editing the initialization list and adding the necessary include -files, you can add additional functions to the calculator. -Two important functions allow look-up and installation of symbols in the -symbol table. The function putsym is passed a name and the type -(VAR or FNCT) of the object to be installed. The object is -linked to the front of the list, and a pointer to the object is returned. -The function getsym is passed the name of the symbol to look up. If -found, a pointer to that symbol is returned; otherwise zero is returned. -

      -symrec *
      -putsym (sym_name,sym_type)
      -     char *sym_name;
      -     int sym_type;
      -{
      -  symrec *ptr;
      -  ptr = (symrec *) malloc (sizeof (symrec));
      -  ptr->name = (char *) malloc (strlen (sym_name) + 1);
      -  strcpy (ptr->name,sym_name);
      -  ptr->type = sym_type;
      -  ptr->value.var = 0; /* set value to 0 even if fctn.  */
      -  ptr->next = (struct symrec *)sym_table;
      -  sym_table = ptr;
      -  return ptr;
      -}
      -symrec *
      -getsym (sym_name)
      -     char *sym_name;
      -{
      -  symrec *ptr;
      -  for (ptr = sym_table; ptr != (symrec *) 0;
      -       ptr = (symrec *)ptr->next)
      -    if (strcmp (ptr->name,sym_name) == 0)
      -      return ptr;
      -  return 0;
      -}
      -
      -

      -The function yylex must now recognize variables, numeric values, and -the single-character arithmetic operators. Strings of alphanumeric -characters with a leading nondigit are recognized as either variables or -functions depending on what the symbol table says about them. -The string is passed to getsym for look up in the symbol table. If -the name appears in the table, a pointer to its location and its type -(VAR or FNCT) is returned to yyparse. If it is not -already in the table, then it is installed as a VAR using -putsym. Again, a pointer and its type (which must be VAR) is -returned to yyparse. -No change is needed in the handling of numeric values and arithmetic -operators in yylex. -

      -#include <ctype.h>
      -yylex ()
      -{
      -  int c;
      -  /* Ignore whitespace, get first nonwhite character.  */
      -  while ((c = getchar ()) == ' ' || c == '\t');
      -  if (c == EOF)
      -    return 0;
      -  /* Char starts a number => parse the number.         */
      -  if (c == '.' || isdigit (c))
      -    {
      -      ungetc (c, stdin);
      -      scanf ("%lf", &yylval.val);
      -      return NUM;
      -    }
      -  /* Char starts an identifier => read the name.       */
      -  if (isalpha (c))
      -    {
      -      symrec *s;
      -      static char *symbuf = 0;
      -      static int length = 0;
      -      int i;
      -      /* Initially make the buffer long enough
      -         for a 40-character symbol name.  */
      -      if (length == 0)
      -        length = 40, symbuf = (char *)malloc (length + 1);
      -      i = 0;
      -      do
      -        {
      -          /* If buffer is full, make it bigger.        */
      -          if (i == length)
      -            {
      -              length *= 2;
      -              symbuf = (char *)realloc (symbuf, length + 1);
      -            }
      -          /* Add this character to the buffer.         */
      -          symbuf[i++] = c;
      -          /* Get another character.                    */
      -          c = getchar ();
      -        }
      -      while (c != EOF && isalnum (c));
      -      ungetc (c, stdin);
      -      symbuf[i] = '\0';
      -      s = getsym (symbuf);
      -      if (s == 0)
      -        s = putsym (symbuf, VAR);
      -      yylval.tptr = s;
      -      return s->type;
      -    }
      -  /* Any other character is a token by itself.        */
      -  return c;
      -}
      -
      -

      -This program is both powerful and flexible. You may easily add new -functions, and it is a simple job to modify this code to install predefined -variables such as pi or e as well. -

      Exercises

      -

      - -

        -
      1. -Add some new functions from `math.h' to the initialization list. -
      2. -Add another array that contains constants and their values. Then -modify init_table to add these constants to the symbol table. -It will be easiest to give the constants type VAR. -
      3. -Make the program report an error if the user refers to an -uninitialized variable in any way except to store a value in it. -
      -

      -

      Bison Grammar Files

      -

      -Bison takes as input a context-free grammar specification and produces a -C-language function that recognizes correct instances of the grammar. -The Bison grammar input file conventionally has a name ending in `.y'. -

      Outline of a Bison Grammar

      -

      -A Bison grammar file has four main sections, shown here with the -appropriate delimiters: -

      -%{
      -C declarations
      -%}
      -Bison declarations
      -%%
      -Grammar rules
      -%%
      -Additional C code
      -
      -

      -Comments enclosed in `/* ... */' may appear in any of the sections. -

      The C Declarations Section

      -

      - - -The C declarations section contains macro definitions and -declarations of functions and variables that are used in the actions in the -grammar rules. These are copied to the beginning of the parser file so -that they precede the definition of yyparse. You can use -`#include' to get the declarations from a header file. If you don't -need any C declarations, you may omit the `%{' and `%}' -delimiters that bracket this section. -

      The Bison Declarations Section

      -

      - - -The Bison declarations section contains declarations that define -terminal and nonterminal symbols, specify precedence, and so on. -In some simple grammars you may not need any declarations. -See section Bison Declarations. -

      The Grammar Rules Section

      -

      - - -The grammar rules section contains one or more Bison grammar -rules, and nothing else. See section Syntax of Grammar Rules. -There must always be at least one grammar rule, and the first -`%%' (which precedes the grammar rules) may never be omitted even -if it is the first thing in the file. -

      The Additional C Code Section

      -

      - - -The additional C code section is copied verbatim to the end of -the parser file, just as the C declarations section is copied to -the beginning. This is the most convenient place to put anything -that you want to have in the parser file but which need not come before -the definition of yyparse. For example, the definitions of -yylex and yyerror often go here. See section Parser C-Language Interface. -If the last section is empty, you may omit the `%%' that separates it -from the grammar rules. -The Bison parser itself contains many static variables whose names start -with `yy' and many macros whose names start with `YY'. It is a -good idea to avoid using any such names (except those documented in this -manual) in the additional C code section of the grammar file. -

      Symbols, Terminal and Nonterminal

      -

      - - - - -Symbols in Bison grammars represent the grammatical classifications -of the language. -A terminal symbol (also known as a token type) represents a -class of syntactically equivalent tokens. You use the symbol in grammar -rules to mean that a token in that class is allowed. The symbol is -represented in the Bison parser by a numeric code, and the yylex -function returns a token type code to indicate what kind of token has been -read. You don't need to know what the code value is; you can use the -symbol to stand for it. -A nonterminal symbol stands for a class of syntactically equivalent -groupings. The symbol name is used in writing grammar rules. By convention, -it should be all lower case. -Symbol names can contain letters, digits (not at the beginning), -underscores and periods. Periods make sense only in nonterminals. -There are two ways of writing terminal symbols in the grammar: -

        -
      • -A named token type is written with an identifier, like an -identifier in C. By convention, it should be all upper case. Each -such name must be defined with a Bison declaration such as -%token. See section Token Type Names. -
      • - - - -A character token type (or literal token) is written in -the grammar using the same syntax used in C for character constants; -for example, '+' is a character token type. A character token -type doesn't need to be declared unless you need to specify its -semantic value data type (see section Data Types of Semantic Values), associativity, or -precedence (see section Operator Precedence). -By convention, a character token type is used only to represent a -token that consists of that particular character. Thus, the token -type '+' is used to represent the character `+' as a -token. Nothing enforces this convention, but if you depart from it, -your program will confuse other readers. -All the usual escape sequences used in character literals in C can be -used in Bison as well, but you must not use the null character as a -character literal because its ASCII code, zero, is the code -yylex returns for end-of-input (see section Calling Convention for yylex). -
      -

      -How you choose to write a terminal symbol has no effect on its -grammatical meaning. That depends only on where it appears in rules and -on when the parser function returns that symbol. -The value returned by yylex is always one of the terminal symbols -(or 0 for end-of-input). Whichever way you write the token type in the -grammar rules, you write it the same way in the definition of yylex. -The numeric code for a character token type is simply the ASCII code for -the character, so yylex can use the identical character constant to -generate the requisite code. Each named token type becomes a C macro in -the parser file, so yylex can use the name to stand for the code. -(This is why periods don't make sense in terminal symbols.) -See section Calling Convention for yylex. -If yylex is defined in a separate file, you need to arrange for the -token-type macro definitions to be available there. Use the `-d' -option when you run Bison, so that it will write these macro definitions -into a separate header file `name.tab.h' which you can include -in the other source files that need it. See section Invoking Bison. -The symbol error is a terminal symbol reserved for error recovery -(see section Error Recovery); you shouldn't use it for any other purpose. -In particular, yylex should never return this value. -

      Syntax of Grammar Rules

      -

      - - - -A Bison grammar rule has the following general form: -

      -result: components...
      -        ;
      -
      -

      -where result is the nonterminal symbol that this rule describes -and components are various terminal and nonterminal symbols that -are put together by this rule (see section Symbols, Terminal and Nonterminal). -For example, -

      -exp:      exp '+' exp
      -        ;
      -
      -

      -says that two groupings of type exp, with a `+' token in between, -can be combined into a larger grouping of type exp. -Whitespace in rules is significant only to separate symbols. You can add -extra whitespace as you wish. -Scattered among the components can be actions that determine -the semantics of the rule. An action looks like this: -

      -{C statements}
      -
      -

      -Usually there is only one action and it follows the components. -See section Actions. - -Multiple rules for the same result can be written separately or can -be joined with the vertical-bar character `|' as follows: -

      -result:    rule1-components...
      -        | rule2-components...
      -        ...
      -        ;
      -
      -

      -They are still considered distinct rules even when joined in this way. -If components in a rule is empty, it means that result can -match the empty string. For example, here is how to define a -comma-separated sequence of zero or more exp groupings: -

      -expseq:   /* empty */
      -        | expseq1
      -        ;
      -expseq1:  exp
      -        | expseq1 ',' exp
      -        ;
      -
      -

      -It is customary to write a comment `/* empty */' in each rule -with no components. -

      Recursive Rules

      -

      - -A rule is called recursive when its result nonterminal appears -also on its right hand side. Nearly all Bison grammars need to use -recursion, because that is the only way to define a sequence of any number -of somethings. Consider this recursive definition of a comma-separated -sequence of one or more expressions: -

      -expseq1:  exp
      -        | expseq1 ',' exp
      -        ;
      -
      -

      - - -Since the recursive use of expseq1 is the leftmost symbol in the -right hand side, we call this left recursion. By contrast, here -the same construct is defined using right recursion: -

      -expseq1:  exp
      -        | exp ',' expseq1
      -        ;
      -
      -

      -Any kind of sequence can be defined using either left recursion or -right recursion, but you should always use left recursion, because it -can parse a sequence of any number of elements with bounded stack -space. Right recursion uses up space on the Bison stack in proportion -to the number of elements in the sequence, because all the elements -must be shifted onto the stack before the rule can be applied even -once. See section The Bison Parser Algorithm, for -further explanation of this. - -Indirect or mutual recursion occurs when the result of the -rule does not appear directly on its right hand side, but does appear -in rules for other nonterminals which do appear on its right hand -side. -For example: -

      -expr:     primary
      -        | primary '+' primary
      -        ;
      -primary:  constant
      -        | '(' expr ')'
      -        ;
      -
      -

      -defines two mutually-recursive nonterminals, since each refers to the -other. -

      Defining Language Semantics

      -

      - - -The grammar rules for a language determine only the syntax. The semantics -are determined by the semantic values associated with various tokens and -groupings, and by the actions taken when various groupings are recognized. -For example, the calculator calculates properly because the value -associated with each expression is the proper number; it adds properly -because the action for the grouping `x + y' is to add -the numbers associated with x and y. -

      Data Types of Semantic Values

      -

      - - - - -In a simple program it may be sufficient to use the same data type for -the semantic values of all language constructs. This was true in the -RPN and infix calculator examples (see section Reverse Polish Notation Calculator). -Bison's default is to use type int for all semantic values. To -specify some other type, define YYSTYPE as a macro, like this: -

      -#define YYSTYPE double
      -
      -

      -This macro definition must go in the C declarations section of the grammar -file (see section Outline of a Bison Grammar). -

      More Than One Value Type

      -

      -In most programs, you will need different data types for different kinds -of tokens and groupings. For example, a numeric constant may need type -int or long, while a string constant needs type char *, -and an identifier might need a pointer to an entry in the symbol table. -To use more than one data type for semantic values in one parser, Bison -requires you to do two things: -

        -
      • -Specify the entire collection of possible data types, with the -%union Bison declaration (see section The Collection of Value Types). -
      • -Choose one of those types for each symbol (terminal or nonterminal) -for which semantic values are used. This is done for tokens with the -%token Bison declaration (see section Token Type Names) and for groupings -with the %type Bison declaration (see section Nonterminal Symbols). -
      -

      -

      Actions

      -

      - - - -An action accompanies a syntactic rule and contains C code to be executed -each time an instance of that rule is recognized. The task of most actions -is to compute a semantic value for the grouping built by the rule from the -semantic values associated with tokens or smaller groupings. -An action consists of C statements surrounded by braces, much like a -compound statement in C. It can be placed at any position in the rule; it -is executed at that position. Most rules have just one action at the end -of the rule, following all the components. Actions in the middle of a rule -are tricky and used only for special purposes (see section Actions in Mid-Rule). -The C code in an action can refer to the semantic values of the components -matched by the rule with the construct $n, which stands for -the value of the nth component. The semantic value for the grouping -being constructed is $$. (Bison translates both of these constructs -into array element references when it copies the actions into the parser -file.) -Here is a typical example: -

      -exp:    ...
      -        | exp '+' exp
      -            { $$ = $1 + $3; }
      -
      -

      -This rule constructs an exp from two smaller exp groupings -connected by a plus-sign token. In the action, $1 and $3 -refer to the semantic values of the two component exp groupings, -which are the first and third symbols on the right hand side of the rule. -The sum is stored into $$ so that it becomes the semantic value of -the addition-expression just recognized by the rule. If there were a -useful semantic value associated with the `+' token, it could be -referred to as $2. - -If you don't specify an action for a rule, Bison supplies a default: -$$ = $1. Thus, the value of the first symbol in the rule becomes -the value of the whole rule. Of course, the default rule is valid only -if the two data types match. There is no meaningful default action for -an empty rule; every empty rule must have an explicit action unless the -rule's value does not matter. -$n with n zero or negative is allowed for reference -to tokens and groupings on the stack before those that match the -current rule. This is a very risky practice, and to use it reliably -you must be certain of the context in which the rule is applied. Here -is a case in which you can use this reliably: -

      -foo:      expr bar '+' expr  { ... }
      -        | expr bar '-' expr  { ... }
      -        ;
      -bar:      /* empty */
      -        { previous_expr = $0; }
      -        ;
      -
      -

      -As long as bar is used only in the fashion shown here, $0 -always refers to the expr which precedes bar in the -definition of foo. -

      Data Types of Values in Actions

      -

      - - -If you have chosen a single data type for semantic values, the $$ -and $n constructs always have that data type. -If you have used %union to specify a variety of data types, then you -must declare a choice among these types for each terminal or nonterminal -symbol that can have a semantic value. Then each time you use $$ or -$n, its data type is determined by which symbol it refers to -in the rule. In this example, -

      -exp:    ...
      -        | exp '+' exp
      -            { $$ = $1 + $3; }
      -
      -

      -$1 and $3 refer to instances of exp, so they all -have the data type declared for the nonterminal symbol exp. If -$2 were used, it would have the data type declared for the -terminal symbol '+', whatever that might be. -Alternatively, you can specify the data type when you refer to the value, -by inserting `<type>' after the `$' at the beginning of the -reference. For example, if you have defined types as shown here: -

      -%union {
      -  int itype;
      -  double dtype;
      -}
      -
      -

      -then you can write $<itype>1 to refer to the first subunit of the -rule as an integer, or $<dtype>1 to refer to it as a double. -

      Actions in Mid-Rule

      -

      - - -Occasionally it is useful to put an action in the middle of a rule. -These actions are written just like usual end-of-rule actions, but they -are executed before the parser even recognizes the following components. -A mid-rule action may refer to the components preceding it using -$n, but it may not refer to subsequent components because -it is run before they are parsed. -The mid-rule action itself counts as one of the components of the rule. -This makes a difference when there is another action later in the same rule -(and usually there is another at the end): you have to count the actions -along with the symbols when working out which number n to use in -$n. -The mid-rule action can also have a semantic value. The action can set -its value with an assignment to $$, and actions later in the rule -can refer to the value using $n. Since there is no symbol -to name the action, there is no way to declare a data type for the value -in advance, so you must use the `$<...>' construct to specify a -data type each time you refer to this value. -There is no way to set the value of the entire rule with a mid-rule -action, because assignments to $$ do not have that effect. The -only way to set the value for the entire rule is with an ordinary action -at the end of the rule. -Here is an example from a hypothetical compiler, handling a let -statement that looks like `let (variable) statement' and -serves to create a variable named variable temporarily for the -duration of statement. To parse this construct, we must put -variable into the symbol table while statement is parsed, then -remove it afterward. Here is how it is done: -

      -stmt:   LET '(' var ')'
      -                { $<context>$ = push_context ();
      -                  declare_variable ($3); }
      -        stmt    { $$ = $6;
      -                  pop_context ($<context>5); }
      -
      -

      -As soon as `let (variable)' has been recognized, the first -action is run. It saves a copy of the current semantic context (the -list of accessible variables) as its semantic value, using alternative -context in the data-type union. Then it calls -declare_variable to add the new variable to that list. Once the -first action is finished, the embedded statement stmt can be -parsed. Note that the mid-rule action is component number 5, so the -`stmt' is component number 6. -After the embedded statement is parsed, its semantic value becomes the -value of the entire let-statement. Then the semantic value from the -earlier action is used to restore the prior list of variables. This -removes the temporary let-variable from the list so that it won't -appear to exist while the rest of the program is parsed. -Taking action before a rule is completely recognized often leads to -conflicts since the parser must commit to a parse in order to execute the -action. For example, the following two rules, without mid-rule actions, -can coexist in a working parser because the parser can shift the open-brace -token and look at what follows before deciding whether there is a -declaration or not: -

      -compound: '{' declarations statements '}'
      -        | '{' statements '}'
      -        ;
      -
      -

      -But when we add a mid-rule action as follows, the rules become nonfunctional: -

      -compound: { prepare_for_local_variables (); }
      -          '{' declarations statements '}'
      -        | '{' statements '}'
      -        ;
      -
      -

      -Now the parser is forced to decide whether to run the mid-rule action -when it has read no farther than the open-brace. In other words, it -must commit to using one rule or the other, without sufficient -information to do it correctly. (The open-brace token is what is called -the look-ahead token at this time, since the parser is still -deciding what to do about it. See section Look-Ahead Tokens.) -You might think that you could correct the problem by putting identical -actions into the two rules, like this: -

      -compound: { prepare_for_local_variables (); }
      -          '{' declarations statements '}'
      -        | { prepare_for_local_variables (); }
      -          '{' statements '}'
      -        ;
      -
      -

      -But this does not help, because Bison does not realize that the two actions -are identical. (Bison never tries to understand the C code in an action.) -If the grammar is such that a declaration can be distinguished from a -statement by the first token (which is true in C), then one solution which -does work is to put the action after the open-brace, like this: -

      -compound: '{' { prepare_for_local_variables (); }
      -          declarations statements '}'
      -        | '{' statements '}'
      -        ;
      -
      -

      -Now the first token of the following declaration or statement, -which would in any case tell Bison which rule to use, can still do so. -Another solution is to bury the action inside a nonterminal symbol which -serves as a subroutine: -

      -subroutine: /* empty */
      -          { prepare_for_local_variables (); }
      -        ;
      -compound: subroutine
      -          '{' declarations statements '}'
      -        | subroutine
      -          '{' statements '}'
      -        ;
      -
      -

      -Now Bison can execute the action in the rule for subroutine without -deciding which rule for compound it will eventually use. Note that -the action is now at the end of its rule. Any mid-rule action can be -converted to an end-of-rule action in this way, and this is what Bison -actually does to implement mid-rule actions. -

      Bison Declarations

      -

      - - -The Bison declarations section of a Bison grammar defines the symbols -used in formulating the grammar and the data types of semantic values. -See section Symbols, Terminal and Nonterminal. -All token type names (but not single-character literal tokens such as -'+' and '*') must be declared. Nonterminal symbols must be -declared if you need to specify which data type to use for the semantic -value (see section More Than One Value Type). -The first rule in the file also specifies the start symbol, by default. -If you want some other symbol to be the start symbol, you must declare -it explicitly (see section Languages and Context-Free Grammars). -

      Token Type Names

      -

      - - - -The basic way to declare a token type name (terminal symbol) is as follows: -

      -%token name
      -
      -

      -Bison will convert this into a #define directive in -the parser, so that the function yylex (if it is in this file) -can use the name name to stand for this token type's code. -Alternatively, you can use %left, %right, or %nonassoc -instead of %token, if you wish to specify precedence. -See section Operator Precedence. -You can explicitly specify the numeric code for a token type by appending -an integer value in the field immediately following the token name: -

      -%token NUM 300
      -
      -

      -It is generally best, however, to let Bison choose the numeric codes for -all token types. Bison will automatically select codes that don't conflict -with each other or with ASCII characters. -In the event that the stack type is a union, you must augment the -%token or other token declaration to include the data type -alternative delimited by angle-brackets (see section More Than One Value Type). -For example: -

      -%union {              /* define stack type */
      -  double val;
      -  symrec *tptr;
      -}
      -%token <val> NUM      /* define token NUM and its type */
      -
      -

      -

      Operator Precedence

      -

      - - - -Use the %left, %right or %nonassoc declaration to -declare a token and specify its precedence and associativity, all at -once. These are called precedence declarations. -See section Operator Precedence, for general information on operator precedence. -The syntax of a precedence declaration is the same as that of -%token: either -

      -%left symbols...
      -
      -

      -or -

      -%left <type> symbols...
      -
      -

      -And indeed any of these declarations serves the purposes of %token. -But in addition, they specify the associativity and relative precedence for -all the symbols: -

        -
      • -The associativity of an operator op determines how repeated uses -of the operator nest: whether `x op y op -z' is parsed by grouping x with y first or by -grouping y with z first. %left specifies -left-associativity (grouping x with y first) and -%right specifies right-associativity (grouping y with -z first). %nonassoc specifies no associativity, which -means that `x op y op z' is -considered a syntax error. -
      • -The precedence of an operator determines how it nests with other operators. -All the tokens declared in a single precedence declaration have equal -precedence and nest together according to their associativity. -When two tokens declared in different precedence declarations associate, -the one declared later has the higher precedence and is grouped first. -
      -

      -

      The Collection of Value Types

      -

      - - - -The %union declaration specifies the entire collection of possible -data types for semantic values. The keyword %union is followed by a -pair of braces containing the same thing that goes inside a union in -C. -For example: -

      -%union {
      -  double val;
      -  symrec *tptr;
      -}
      -
      -

      -This says that the two alternative types are double and symrec -*. They are given names val and tptr; these names are used -in the %token and %type declarations to pick one of the types -for a terminal or nonterminal symbol (see section Nonterminal Symbols). -Note that, unlike making a union declaration in C, you do not write -a semicolon after the closing brace. -

      Nonterminal Symbols

      -

      - - - -When you use %union to specify multiple value types, you must -declare the value type of each nonterminal symbol for which values are -used. This is done with a %type declaration, like this: -

      -%type <type> nonterminal...
      -
      -

      -Here nonterminal is the name of a nonterminal symbol, and type -is the name given in the %union to the alternative that you want -(see section The Collection of Value Types). You can give any number of nonterminal symbols in -the same %type declaration, if they have the same value type. Use -spaces to separate the symbol names. -

      Suppressing Conflict Warnings

      -

      - - - - - -Bison normally warns if there are any conflicts in the grammar -(see section Shift/Reduce Conflicts), but most real grammars have harmless shift/reduce -conflicts which are resolved in a predictable way and would be difficult to -eliminate. It is desirable to suppress the warning about these conflicts -unless the number of conflicts changes. You can do this with the -%expect declaration. -The declaration looks like this: -

      -%expect n
      -
      -

      -Here n is a decimal integer. The declaration says there should be no -warning if there are n shift/reduce conflicts and no reduce/reduce -conflicts. The usual warning is given if there are either more or fewer -conflicts, or if there are any reduce/reduce conflicts. -In general, using %expect involves these steps: -

        -
      • -Compile your grammar without %expect. Use the `-v' option -to get a verbose list of where the conflicts occur. Bison will also -print the number of conflicts. -
      • -Check each of the conflicts to make sure that Bison's default -resolution is what you really want. If not, rewrite the grammar and -go back to the beginning. -
      • -Add an %expect declaration, copying the number n from the -number which Bison printed. -
      -

      -Now Bison will stop annoying you about the conflicts you have checked, but -it will warn you again if changes in the grammar result in additional -conflicts. -

      The Start-Symbol

      -

      - - - - -Bison assumes by default that the start symbol for the grammar is the first -nonterminal specified in the grammar specification section. The programmer -may override this restriction with the %start declaration as follows: -

      -%start symbol
      -
      -

      -

      A Pure (Reentrant) Parser

      -

      - - - -A reentrant program is one which does not alter in the course of -execution; in other words, it consists entirely of pure (read-only) -code. Reentrancy is important whenever asynchronous execution is possible; -for example, a nonreentrant program may not be safe to call from a signal -handler. In systems with multiple threads of control, a nonreentrant -program must be called only within interlocks. -The Bison parser is not normally a reentrant program, because it uses -statically allocated variables for communication with yylex. These -variables include yylval and yylloc. -The Bison declaration %pure_parser says that you want the parser -to be reentrant. It looks like this: -

      -%pure_parser
      -
      -

      -The effect is that the two communication variables become local -variables in yyparse, and a different calling convention is used -for the lexical analyzer function yylex. See section Calling Conventions for Pure Parsers, for the details of this. The -variable yynerrs also becomes local in yyparse -(see section The Error Reporting Function yyerror). -The convention for calling yyparse itself is unchanged. -

      Bison Declaration Summary

      -

      - - - -Here is a summary of all Bison declarations: -

      -
      %union -
      -Declare the collection of data types that semantic values may have -(see section The Collection of Value Types). -
      %token -
      -Declare a terminal symbol (token type name) with no precedence -or associativity specified (see section Token Type Names). -
      %right -
      -Declare a terminal symbol (token type name) that is right-associative -(see section Operator Precedence). -
      %left -
      -Declare a terminal symbol (token type name) that is left-associative -(see section Operator Precedence). -
      %nonassoc -
      -Declare a terminal symbol (token type name) that is nonassociative -(using it in a way that would be associative is a syntax error) -(see section Operator Precedence). -
      %type -
      -Declare the type of semantic values for a nonterminal symbol -(see section Nonterminal Symbols). -
      %start -
      -Specify the grammar's start symbol (see section The Start-Symbol). -
      %expect -
      -Declare the expected number of shift-reduce conflicts -(see section Suppressing Conflict Warnings). -
      %pure_parser -
      -Request a pure (reentrant) parser program (see section A Pure (Reentrant) Parser). -
      -

      -

      Multiple Parsers in the Same Program

      -

      -Most programs that use Bison parse only one language and therefore contain -only one Bison parser. But what if you want to parse more than one -language with the same program? Then you need to avoid a name conflict -between different definitions of yyparse, yylval, and so on. -The easy way to do this is to use the option `-p prefix' -(see section Invoking Bison). This renames the interface functions and -variables of the Bison parser to start with prefix instead of -`yy'. You can use this to give each parser distinct names that do -not conflict. -The precise list of symbols renamed is yyparse, yylex, -yyerror, yynerrs, yylval, yychar and -yydebug. For example, if you use `-p c', the names become -cparse, clex, and so on. -All the other variables and macros associated with Bison are not -renamed. These others are not global; there is no conflict if the same -name is used in different parsers. For example, YYSTYPE is not -renamed, but defining this in different ways in different parsers causes -no trouble (see section Data Types of Semantic Values). -The `-p' option works by adding macro definitions to the beginning -of the parser source file, defining yyparse as -prefixparse, and so on. This effectively substitutes one -name for the other in the entire parser file. -

      Parser C-Language Interface

      -

      - - -The Bison parser is actually a C function named yyparse. Here we -describe the interface conventions of yyparse and the other -functions that it needs to use. -Keep in mind that the parser uses many C identifiers starting with -`yy' and `YY' for internal purposes. If you use such an -identifier (aside from those in this manual) in an action or in additional -C code in the grammar file, you are likely to run into trouble. -

      The Parser Function yyparse

      -

      - -You call the function yyparse to cause parsing to occur. This -function reads tokens, executes actions, and ultimately returns when it -encounters end-of-input or an unrecoverable syntax error. You can also -write an action which directs yyparse to return immediately without -reading further. -The value returned by yyparse is 0 if parsing was successful (return -is due to end-of-input). -The value is 1 if parsing failed (return is due to a syntax error). -In an action, you can cause immediate return from yyparse by using -these macros: -

      -
      YYACCEPT -
      - -Return immediately with value 0 (to report success). -
      YYABORT -
      - -Return immediately with value 1 (to report failure). -
      -

      -

      The Lexical Analyzer Function yylex

      -

      - - -The lexical analyzer function, yylex, recognizes tokens from -the input stream and returns them to the parser. Bison does not create -this function automatically; you must write it so that yyparse can -call it. The function is sometimes referred to as a lexical scanner. -In simple programs, yylex is often defined at the end of the Bison -grammar file. If yylex is defined in a separate source file, you -need to arrange for the token-type macro definitions to be available there. -To do this, use the `-d' option when you run Bison, so that it will -write these macro definitions into a separate header file -`name.tab.h' which you can include in the other source files -that need it. See section Invoking Bison. -

      Calling Convention for yylex

      -

      -The value that yylex returns must be the numeric code for the type -of token it has just found, or 0 for end-of-input. -When a token is referred to in the grammar rules by a name, that name -in the parser file becomes a C macro whose definition is the proper -numeric code for that token type. So yylex can use the name -to indicate that type. See section Symbols, Terminal and Nonterminal. -When a token is referred to in the grammar rules by a character literal, -the numeric code for that character is also the code for the token type. -So yylex can simply return that character code. The null character -must not be used this way, because its code is zero and that is what -signifies end-of-input. -Here is an example showing these things: -

      -yylex ()
      -{
      -  ...
      -  if (c == EOF)     /* Detect end of file. */
      -    return 0;
      -  ...
      -  if (c == '+' || c == '-')
      -    return c;      /* Assume token type for `+' is '+'. */
      -  ...
      -  return INT;      /* Return the type of the token. */
      -  ...
      -}
      -
      -

      -This interface has been designed so that the output from the lex -utility can be used without change as the definition of yylex. -

      Semantic Values of Tokens

      -

      - -In an ordinary (nonreentrant) parser, the semantic value of the token must -be stored into the global variable yylval. When you are using -just one data type for semantic values, yylval has that type. -Thus, if the type is int (the default), you might write this in -yylex: -

      -  ...
      -  yylval = value;  /* Put value onto Bison stack. */
      -  return INT;      /* Return the type of the token. */
      -  ...
      -
      -

      -When you are using multiple data types, yylval's type is a union -made from the %union declaration (see section The Collection of Value Types). So when -you store a token's value, you must use the proper member of the union. -If the %union declaration looks like this: -

      -%union {
      -  int intval;
      -  double val;
      -  symrec *tptr;
      -}
      -
      -

      -then the code in yylex might look like this: -

      -  ...
      -  yylval.intval = value; /* Put value onto Bison stack. */
      -  return INT;          /* Return the type of the token. */
      -  ...
      -
      -

      -

      Textual Positions of Tokens

      -

      - -If you are using the `@n'-feature (see section Special Features for Use in Actions) in -actions to keep track of the textual locations of tokens and groupings, -then you must provide this information in yylex. The function -yyparse expects to find the textual location of a token just parsed -in the global variable yylloc. So yylex must store the -proper data in that variable. The value of yylloc is a structure -and you need only initialize the members that are going to be used by the -actions. The four members are called first_line, -first_column, last_line and last_column. Note that -the use of this feature makes the parser noticeably slower. - -The data type of yylloc has the name YYLTYPE. -

      Calling Conventions for Pure Parsers

      -

      -When you use the Bison declaration %pure_parser to request a -pure, reentrant parser, the global communication variables yylval -and yylloc cannot be used. (See section A Pure (Reentrant) Parser.) In such parsers the two global variables are replaced by -pointers passed as arguments to yylex. You must declare them as -shown here, and pass the information back by storing it through those -pointers. -

      -yylex (lvalp, llocp)
      -     YYSTYPE *lvalp;
      -     YYLTYPE *llocp;
      -{
      -  ...
      -  *lvalp = value;  /* Put value onto Bison stack.  */
      -  return INT;      /* Return the type of the token.  */
      -  ...
      -}
      -
      -

      -If the grammar file does not use the `@' constructs to refer to -textual positions, then the type YYLTYPE will not be defined. In -this case, omit the second argument; yylex will be called with -only one argument. - -You can pass parameter information to a reentrant parser in a reentrant -way. Define the macro YYPARSE_PARAM as a variable name. The -resulting yyparse function then accepts one argument, of type -void *, with that name. -When you call yyparse, pass the address of an object, casting the -address to void *. The grammar actions can refer to the contents -of the object by casting the pointer value back to its proper type and -then dereferencing it. Here's an example. Write this in the parser: -

      -%{
      -struct parser_control
      -{
      -  int nastiness;
      -  int randomness;
      -};
      -#define YYPARSE_PARAM parm
      -%}
      -
      -

      -Then call the parser like this: -

      -struct parser_control
      -{
      -  int nastiness;
      -  int randomness;
      -};
      -...
      -{
      -  struct parser_control foo;
      -  ...  /* Store proper data in foo.  */
      -  value = yyparse ((void *) &foo);
      -  ...
      -}
      -
      -

      -In the grammar actions, use expressions like this to refer to the data: -

      -((struct parser_control *) parm)->randomness
      -
      -

      - -If you wish to pass the additional parameter data to yylex, -define the macro YYLEX_PARAM just like YYPARSE_PARAM, as -shown here: -

      -%{
      -struct parser_control
      -{
      -  int nastiness;
      -  int randomness;
      -};
      -#define YYPARSE_PARAM parm
      -#define YYLEX_PARAM parm
      -%}
      -
      -

      -You should then define yylex to accept one additional -argument--the value of parm. (This makes either two or three -arguments in total, depending on whether an argument of type -YYLTYPE is passed.) You can declare the argument as a pointer to -the proper object type, or you can declare it as void * and -access the contents as shown above. -

      The Error Reporting Function yyerror

      -

      - - - - -The Bison parser detects a parse error or syntax error -whenever it reads a token which cannot satisfy any syntax rule. A -action in the grammar can also explicitly proclaim an error, using the -macro YYERROR (see section Special Features for Use in Actions). -The Bison parser expects to report the error by calling an error -reporting function named yyerror, which you must supply. It is -called by yyparse whenever a syntax error is found, and it -receives one argument. For a parse error, the string is normally -"parse error". - -If you define the macro YYERROR_VERBOSE in the Bison declarations -section (see section The Bison Declarations Section), then Bison provides a more verbose -and specific error message string instead of just plain "parse -error". It doesn't matter what definition you use for -YYERROR_VERBOSE, just whether you define it. -The parser can detect one other kind of error: stack overflow. This -happens when the input contains constructions that are very deeply -nested. It isn't likely you will encounter this, since the Bison -parser extends its stack automatically up to a very large limit. But -if overflow happens, yyparse calls yyerror in the usual -fashion, except that the argument string is "parser stack -overflow". -The following definition suffices in simple programs: -

      -yyerror (s)
      -     char *s;
      -{
      -  fprintf (stderr, "%s\n", s);
      -}
      -
      -

      -After yyerror returns to yyparse, the latter will attempt -error recovery if you have written suitable error recovery grammar rules -(see section Error Recovery). If recovery is impossible, yyparse will -immediately return 1. - -The variable yynerrs contains the number of syntax errors -encountered so far. Normally this variable is global; but if you -request a pure parser (see section A Pure (Reentrant) Parser) then it is a local variable -which only the actions can access. -

      Special Features for Use in Actions

      -

      - - -Here is a table of Bison constructs, variables and macros that -are useful in actions. -

      -
      `$$' -
      -Acts like a variable that contains the semantic value for the -grouping made by the current rule. See section Actions. -
      `$n' -
      -Acts like a variable that contains the semantic value for the -nth component of the current rule. See section Actions. -
      `$<typealt>$' -
      -Like $$ but specifies alternative typealt in the union -specified by the %union declaration. See section Data Types of Values in Actions. -
      `$<typealt>n' -
      -Like $n but specifies alternative typealt in the -union specified by the %union declaration. -See section Data Types of Values in Actions. -
      `YYABORT;' -
      -Return immediately from yyparse, indicating failure. -See section The Parser Function yyparse. -
      `YYACCEPT;' -
      -Return immediately from yyparse, indicating success. -See section The Parser Function yyparse. -
      `YYBACKUP (token, value);' -
      - -Unshift a token. This macro is allowed only for rules that reduce -a single value, and only when there is no look-ahead token. -It installs a look-ahead token with token type token and -semantic value value; then it discards the value that was -going to be reduced by this rule. -If the macro is used when it is not valid, such as when there is -a look-ahead token already, then it reports a syntax error with -a message `cannot back up' and performs ordinary error -recovery. -In either case, the rest of the action is not executed. -
      `YYEMPTY' -
      - -Value stored in yychar when there is no look-ahead token. -
      `YYERROR;' -
      - -Cause an immediate syntax error. This statement initiates error -recovery just as if the parser itself had detected an error; however, it -does not call yyerror, and does not print any message. If you -want to print an error message, call yyerror explicitly before -the `YYERROR;' statement. See section Error Recovery. -
      `YYRECOVERING' -
      -This macro stands for an expression that has the value 1 when the parser -is recovering from a syntax error, and 0 the rest of the time. -See section Error Recovery. -
      `yychar' -
      -Variable containing the current look-ahead token. (In a pure parser, -this is actually a local variable within yyparse.) When there is -no look-ahead token, the value YYEMPTY is stored in the variable. -See section Look-Ahead Tokens. -
      `yyclearin;' -
      -Discard the current look-ahead token. This is useful primarily in -error rules. See section Error Recovery. -
      `yyerrok;' -
      -Resume generating error messages immediately for subsequent syntax -errors. This is useful primarily in error rules. -See section Error Recovery. -
      `@n' -
      - -Acts like a structure variable containing information on the line -numbers and column numbers of the nth component of the current -rule. The structure has four members, like this: -
      -struct {
      -  int first_line, last_line;
      -  int first_column, last_column;
      -};
      -
      -Thus, to get the starting line number of the third component, use -`@3.first_line'. -In order for the members of this structure to contain valid information, -you must make yylex supply this information about each token. -If you need only certain members, then yylex need only fill in -those members. -The use of this feature makes the parser noticeably slower. -
      -

      -

      The Bison Parser Algorithm

      -

      - - - - - - -As Bison reads tokens, it pushes them onto a stack along with their -semantic values. The stack is called the parser stack. Pushing a -token is traditionally called shifting. -For example, suppose the infix calculator has read `1 + 5 *', with a -`3' to come. The stack will have four elements, one for each token -that was shifted. -But the stack does not always have an element for each token read. When -the last n tokens and groupings shifted match the components of a -grammar rule, they can be combined according to that rule. This is called -reduction. Those tokens and groupings are replaced on the stack by a -single grouping whose symbol is the result (left hand side) of that rule. -Running the rule's action is part of the process of reduction, because this -is what computes the semantic value of the resulting grouping. -For example, if the infix calculator's parser stack contains this: -

      -1 + 5 * 3
      -
      -

      -and the next input token is a newline character, then the last three -elements can be reduced to 15 via the rule: -

      -expr: expr '*' expr;
      -
      -

      -Then the stack contains just these three elements: -

      -1 + 15
      -
      -

      -At this point, another reduction can be made, resulting in the single value -16. Then the newline token can be shifted. -The parser tries, by shifts and reductions, to reduce the entire input down -to a single grouping whose symbol is the grammar's start-symbol -(see section Languages and Context-Free Grammars). -This kind of parser is known in the literature as a bottom-up parser. -

      Look-Ahead Tokens

      -

      - -The Bison parser does not always reduce immediately as soon as the -last n tokens and groupings match a rule. This is because such a -simple strategy is inadequate to handle most languages. Instead, when a -reduction is possible, the parser sometimes "looks ahead" at the next -token in order to decide what to do. -When a token is read, it is not immediately shifted; first it becomes the -look-ahead token, which is not on the stack. Now the parser can -perform one or more reductions of tokens and groupings on the stack, while -the look-ahead token remains off to the side. When no more reductions -should take place, the look-ahead token is shifted onto the stack. This -does not mean that all possible reductions have been done; depending on the -token type of the look-ahead token, some rules may choose to delay their -application. -Here is a simple case where look-ahead is needed. These three rules define -expressions which contain binary addition operators and postfix unary -factorial operators (`!'), and allow parentheses for grouping. -

      -expr:     term '+' expr
      -        | term
      -        ;
      -term:     '(' expr ')'
      -        | term '!'
      -        | NUMBER
      -        ;
      -
      -

      -Suppose that the tokens `1 + 2' have been read and shifted; what -should be done? If the following token is `)', then the first three -tokens must be reduced to form an expr. This is the only valid -course, because shifting the `)' would produce a sequence of symbols -term ')', and no rule allows this. -If the following token is `!', then it must be shifted immediately so -that `2 !' can be reduced to make a term. If instead the -parser were to reduce before shifting, `1 + 2' would become an -expr. It would then be impossible to shift the `!' because -doing so would produce on the stack the sequence of symbols expr -'!'. No rule allows that sequence. - -The current look-ahead token is stored in the variable yychar. -See section Special Features for Use in Actions. -

      Shift/Reduce Conflicts

      -

      - - - - -Suppose we are parsing a language which has if-then and if-then-else -statements, with a pair of rules like this: -

      -if_stmt:
      -          IF expr THEN stmt
      -        | IF expr THEN stmt ELSE stmt
      -        ;
      -
      -

      -Here we assume that IF, THEN and ELSE are -terminal symbols for specific keyword tokens. -When the ELSE token is read and becomes the look-ahead token, the -contents of the stack (assuming the input is valid) are just right for -reduction by the first rule. But it is also legitimate to shift the -ELSE, because that would lead to eventual reduction by the second -rule. -This situation, where either a shift or a reduction would be valid, is -called a shift/reduce conflict. Bison is designed to resolve -these conflicts by choosing to shift, unless otherwise directed by -operator precedence declarations. To see the reason for this, let's -contrast it with the other alternative. -Since the parser prefers to shift the ELSE, the result is to attach -the else-clause to the innermost if-statement, making these two inputs -equivalent: -

      -if x then if y then win (); else lose;
      -if x then do; if y then win (); else lose; end;
      -
      -

      -But if the parser chose to reduce when possible rather than shift, the -result would be to attach the else-clause to the outermost if-statement, -making these two inputs equivalent: -

      -if x then if y then win (); else lose;
      -if x then do; if y then win (); end; else lose;
      -
      -

      -The conflict exists because the grammar as written is ambiguous: either -parsing of the simple nested if-statement is legitimate. The established -convention is that these ambiguities are resolved by attaching the -else-clause to the innermost if-statement; this is what Bison accomplishes -by choosing to shift rather than reduce. (It would ideally be cleaner to -write an unambiguous grammar, but that is very hard to do in this case.) -This particular ambiguity was first encountered in the specifications of -Algol 60 and is called the "dangling else" ambiguity. -To avoid warnings from Bison about predictable, legitimate shift/reduce -conflicts, use the %expect n declaration. There will be no -warning as long as the number of shift/reduce conflicts is exactly n. -See section Suppressing Conflict Warnings. -The definition of if_stmt above is solely to blame for the -conflict, but the conflict does not actually appear without additional -rules. Here is a complete Bison input file that actually manifests the -conflict: -

      -%token IF THEN ELSE variable
      -%%
      -stmt:     expr
      -        | if_stmt
      -        ;
      -if_stmt:
      -          IF expr THEN stmt
      -        | IF expr THEN stmt ELSE stmt
      -        ;
      -expr:     variable
      -        ;
      -
      -

      -

      Operator Precedence

      -

      - - -Another situation where shift/reduce conflicts appear is in arithmetic -expressions. Here shifting is not always the preferred resolution; the -Bison declarations for operator precedence allow you to specify when to -shift and when to reduce. -

      When Precedence is Needed

      -

      -Consider the following ambiguous grammar fragment (ambiguous because the -input `1 - 2 * 3' can be parsed in two different ways): -

      -expr:     expr '-' expr
      -        | expr '*' expr
      -        | expr '<' expr
      -        | '(' expr ')'
      -        ...
      -        ;
      -
      -

      -Suppose the parser has seen the tokens `1', `-' and `2'; -should it reduce them via the rule for the addition operator? It depends -on the next token. Of course, if the next token is `)', we must -reduce; shifting is invalid because no single rule can reduce the token -sequence `- 2 )' or anything starting with that. But if the next -token is `*' or `<', we have a choice: either shifting or -reduction would allow the parse to complete, but with different -results. -To decide which one Bison should do, we must consider the -results. If the next operator token op is shifted, then it -must be reduced first in order to permit another opportunity to -reduce the sum. The result is (in effect) `1 - (2 -op 3)'. On the other hand, if the subtraction is reduced -before shifting op, the result is `(1 - 2) op -3'. Clearly, then, the choice of shift or reduce should depend -on the relative precedence of the operators `-' and -op: `*' should be shifted first, but not `<'. - -What about input such as `1 - 2 - 5'; should this be -`(1 - 2) - 5' or should it be `1 - (2 - 5)'? For -most operators we prefer the former, which is called left -association. The latter alternative, right association, is -desirable for assignment operators. The choice of left or right -association is a matter of whether the parser chooses to shift or -reduce when the stack contains `1 - 2' and the look-ahead -token is `-': shifting makes right-associativity. -

      Specifying Operator Precedence

      -

      - - - -Bison allows you to specify these choices with the operator precedence -declarations %left and %right. Each such declaration -contains a list of tokens, which are operators whose precedence and -associativity is being declared. The %left declaration makes all -those operators left-associative and the %right declaration makes -them right-associative. A third alternative is %nonassoc, which -declares that it is a syntax error to find the same operator twice "in a -row". -The relative precedence of different operators is controlled by the -order in which they are declared. The first %left or -%right declaration in the file declares the operators whose -precedence is lowest, the next such declaration declares the operators -whose precedence is a little higher, and so on. -

      Precedence Examples

      -

      -In our example, we would want the following declarations: -

      -%left '<'
      -%left '-'
      -%left '*'
      -
      -

      -In a more complete example, which supports other operators as well, we -would declare them in groups of equal precedence. For example, '+' is -declared with '-': -

      -%left '<' '>' '=' NE LE GE
      -%left '+' '-'
      -%left '*' '/'
      -
      -

      -(Here NE and so on stand for the operators for "not equal" -and so on. We assume that these tokens are more than one character long -and therefore are represented by names, not character literals.) -

      How Precedence Works

      -

      -The first effect of the precedence declarations is to assign precedence -levels to the terminal symbols declared. The second effect is to assign -precedence levels to certain rules: each rule gets its precedence from the -last terminal symbol mentioned in the components. (You can also specify -explicitly the precedence of a rule. See section Context-Dependent Precedence.) -Finally, the resolution of conflicts works by comparing the -precedence of the rule being considered with that of the -look-ahead token. If the token's precedence is higher, the -choice is to shift. If the rule's precedence is higher, the -choice is to reduce. If they have equal precedence, the choice -is made based on the associativity of that precedence level. The -verbose output file made by `-v' (see section Invoking Bison) says -how each conflict was resolved. -Not all rules and not all tokens have precedence. If either the rule or -the look-ahead token has no precedence, then the default is to shift. -

      Context-Dependent Precedence

      -

      - - - - - -Often the precedence of an operator depends on the context. This sounds -outlandish at first, but it is really very common. For example, a minus -sign typically has a very high precedence as a unary operator, and a -somewhat lower precedence (lower than multiplication) as a binary operator. -The Bison precedence declarations, %left, %right and -%nonassoc, can only be used once for a given token; so a token has -only one precedence declared in this way. For context-dependent -precedence, you need to use an additional mechanism: the %prec -modifier for rules. -The %prec modifier declares the precedence of a particular rule by -specifying a terminal symbol whose precedence should be used for that rule. -It's not necessary for that symbol to appear otherwise in the rule. The -modifier's syntax is: -

      -%prec terminal-symbol
      -
      -

      -and it is written after the components of the rule. Its effect is to -assign the rule the precedence of terminal-symbol, overriding -the precedence that would be deduced for it in the ordinary way. The -altered rule precedence then affects how conflicts involving that rule -are resolved (see section Operator Precedence). -Here is how %prec solves the problem of unary minus. First, declare -a precedence for a fictitious terminal symbol named UMINUS. There -are no tokens of this type, but the symbol serves to stand for its -precedence: -

      -...
      -%left '+' '-'
      -%left '*'
      -%left UMINUS
      -
      -

      -Now the precedence of UMINUS can be used in specific rules: -

      -exp:    ...
      -        | exp '-' exp
      -        ...
      -        | '-' exp %prec UMINUS
      -
      -

      -

      Parser States

      -

      - - - -The function yyparse is implemented using a finite-state machine. -The values pushed on the parser stack are not simply token type codes; they -represent the entire sequence of terminal and nonterminal symbols at or -near the top of the stack. The current state collects all the information -about previous input which is relevant to deciding what to do next. -Each time a look-ahead token is read, the current parser state together -with the type of look-ahead token are looked up in a table. This table -entry can say, "Shift the look-ahead token." In this case, it also -specifies the new parser state, which is pushed onto the top of the -parser stack. Or it can say, "Reduce using rule number n." -This means that a certain number of tokens or groupings are taken off -the top of the stack, and replaced by one grouping. In other words, -that number of states are popped from the stack, and one new state is -pushed. -There is one other alternative: the table can say that the look-ahead token -is erroneous in the current state. This causes error processing to begin -(see section Error Recovery). -

      Reduce/Reduce Conflicts

      -

      - - -A reduce/reduce conflict occurs if there are two or more rules that apply -to the same sequence of input. This usually indicates a serious error -in the grammar. -For example, here is an erroneous attempt to define a sequence -of zero or more word groupings. -

      -sequence: /* empty */
      -                { printf ("empty sequence\n"); }
      -        | maybeword
      -        | sequence word
      -                { printf ("added word %s\n", $2); }
      -        ;
      -maybeword: /* empty */
      -                { printf ("empty maybeword\n"); }
      -        | word
      -                { printf ("single word %s\n", $1); }
      -        ;
      -
      -

      -The error is an ambiguity: there is more than one way to parse a single -word into a sequence. It could be reduced to a -maybeword and then into a sequence via the second rule. -Alternatively, nothing-at-all could be reduced into a sequence -via the first rule, and this could be combined with the word -using the third rule for sequence. -There is also more than one way to reduce nothing-at-all into a -sequence. This can be done directly via the first rule, -or indirectly via maybeword and then the second rule. -You might think that this is a distinction without a difference, because it -does not change whether any particular input is valid or not. But it does -affect which actions are run. One parsing order runs the second rule's -action; the other runs the first rule's action and the third rule's action. -In this example, the output of the program changes. -Bison resolves a reduce/reduce conflict by choosing to use the rule that -appears first in the grammar, but it is very risky to rely on this. Every -reduce/reduce conflict must be studied and usually eliminated. Here is the -proper way to define sequence: -

      -sequence: /* empty */
      -                { printf ("empty sequence\n"); }
      -        | sequence word
      -                { printf ("added word %s\n", $2); }
      -        ;
      -
      -

      -Here is another common error that yields a reduce/reduce conflict: -

      -sequence: /* empty */
      -        | sequence words
      -        | sequence redirects
      -        ;
      -words:    /* empty */
      -        | words word
      -        ;
      -redirects:/* empty */
      -        | redirects redirect
      -        ;
      -
      -

      -The intention here is to define a sequence which can contain either -word or redirect groupings. The individual definitions of -sequence, words and redirects are error-free, but the -three together make a subtle ambiguity: even an empty input can be parsed -in infinitely many ways! -Consider: nothing-at-all could be a words. Or it could be two -words in a row, or three, or any number. It could equally well be a -redirects, or two, or any number. Or it could be a words -followed by three redirects and another words. And so on. -Here are two ways to correct these rules. First, to make it a single level -of sequence: -

      -sequence: /* empty */
      -        | sequence word
      -        | sequence redirect
      -        ;
      -
      -

      -Second, to prevent either a words or a redirects -from being empty: -

      -sequence: /* empty */
      -        | sequence words
      -        | sequence redirects
      -        ;
      -words:    word
      -        | words word
      -        ;
      -redirects:redirect
      -        | redirects redirect
      -        ;
      -
      -

      -

      Mysterious Reduce/Reduce Conflicts

      -

      -Sometimes reduce/reduce conflicts can occur that don't look warranted. -Here is an example: -

      -%token ID
      -%%
      -def:    param_spec return_spec ','
      -        ;
      -param_spec:
      -             type
      -        |    name_list ':' type
      -        ;
      -return_spec:
      -             type
      -        |    name ':' type
      -        ;
      -type:        ID
      -        ;
      -name:        ID
      -        ;
      -name_list:
      -             name
      -        |    name ',' name_list
      -        ;
      -
      -

      -It would seem that this grammar can be parsed with only a single token -of look-ahead: when a param_spec is being read, an ID is -a name if a comma or colon follows, or a type if another -ID follows. In other words, this grammar is LR(1). - - -However, Bison, like most parser generators, cannot actually handle all -LR(1) grammars. In this grammar, two contexts, that after an ID -at the beginning of a param_spec and likewise at the beginning of -a return_spec, are similar enough that Bison assumes they are the -same. They appear similar because the same set of rules would be -active--the rule for reducing to a name and that for reducing to -a type. Bison is unable to determine at that stage of processing -that the rules would require different look-ahead tokens in the two -contexts, so it makes a single parser state for them both. Combining -the two contexts causes a conflict later. In parser terminology, this -occurrence means that the grammar is not LALR(1). -In general, it is better to fix deficiencies than to document them. But -this particular deficiency is intrinsically hard to fix; parser -generators that can handle LR(1) grammars are hard to write and tend to -produce parsers that are very large. In practice, Bison is more useful -as it is now. -When the problem arises, you can often fix it by identifying the two -parser states that are being confused, and adding something to make them -look distinct. In the above example, adding one rule to -return_spec as follows makes the problem go away: -

      -%token BOGUS
      -...
      -%%
      -...
      -return_spec:
      -             type
      -        |    name ':' type
      -        /* This rule is never used.  */
      -        |    ID BOGUS
      -        ;
      -
      -

      -This corrects the problem because it introduces the possibility of an -additional active rule in the context after the ID at the beginning of -return_spec. This rule is not active in the corresponding context -in a param_spec, so the two contexts receive distinct parser states. -As long as the token BOGUS is never generated by yylex, -the added rule cannot alter the way actual input is parsed. -In this particular example, there is another way to solve the problem: -rewrite the rule for return_spec to use ID directly -instead of via name. This also causes the two confusing -contexts to have different sets of active rules, because the one for -return_spec activates the altered rule for return_spec -rather than the one for name. -

      -param_spec:
      -             type
      -        |    name_list ':' type
      -        ;
      -return_spec:
      -             type
      -        |    ID ':' type
      -        ;
      -
      -

      -

      Stack Overflow, and How to Avoid It

      -

      - - - -The Bison parser stack can overflow if too many tokens are shifted and -not reduced. When this happens, the parser function yyparse -returns a nonzero value, pausing only to call yyerror to report -the overflow. - -By defining the macro YYMAXDEPTH, you can control how deep the -parser stack can become before a stack overflow occurs. Define the -macro with a value that is an integer. This value is the maximum number -of tokens that can be shifted (and not reduced) before overflow. -It must be a constant expression whose value is known at compile time. -The stack space allowed is not necessarily allocated. If you specify a -large value for YYMAXDEPTH, the parser actually allocates a small -stack at first, and then makes it bigger by stages as needed. This -increasing allocation happens automatically and silently. Therefore, -you do not need to make YYMAXDEPTH painfully small merely to save -space for ordinary inputs that do not need much stack. - -The default value of YYMAXDEPTH, if you do not define it, is -10000. - -You can control how much stack is allocated initially by defining the -macro YYINITDEPTH. This value too must be a compile-time -constant integer. The default is 200. -

      Error Recovery

      -

      - - -It is not usually acceptable to have a program terminate on a parse -error. For example, a compiler should recover sufficiently to parse the -rest of the input file and check it for errors; a calculator should accept -another expression. -In a simple interactive command parser where each input is one line, it may -be sufficient to allow yyparse to return 1 on error and have the -caller ignore the rest of the input line when that happens (and then call -yyparse again). But this is inadequate for a compiler, because it -forgets all the syntactic context leading up to the error. A syntax error -deep within a function in the compiler input should not cause the compiler -to treat the following line like the beginning of a source file. - -You can define how to recover from a syntax error by writing rules to -recognize the special token error. This is a terminal symbol that -is always defined (you need not declare it) and reserved for error -handling. The Bison parser generates an error token whenever a -syntax error happens; if you have provided a rule to recognize this token -in the current context, the parse can continue. -For example: -

      -stmnts:  /* empty string */
      -        | stmnts '\n'
      -        | stmnts exp '\n'
      -        | stmnts error '\n'
      -
      -

      -The fourth rule in this example says that an error followed by a newline -makes a valid addition to any stmnts. -What happens if a syntax error occurs in the middle of an exp? The -error recovery rule, interpreted strictly, applies to the precise sequence -of a stmnts, an error and a newline. If an error occurs in -the middle of an exp, there will probably be some additional tokens -and subexpressions on the stack after the last stmnts, and there -will be tokens to read before the next newline. So the rule is not -applicable in the ordinary way. -But Bison can force the situation to fit the rule, by discarding part of -the semantic context and part of the input. First it discards states and -objects from the stack until it gets back to a state in which the -error token is acceptable. (This means that the subexpressions -already parsed are discarded, back to the last complete stmnts.) At -this point the error token can be shifted. Then, if the old -look-ahead token is not acceptable to be shifted next, the parser reads -tokens and discards them until it finds a token which is acceptable. In -this example, Bison reads and discards input until the next newline -so that the fourth rule can apply. -The choice of error rules in the grammar is a choice of strategies for -error recovery. A simple and useful strategy is simply to skip the rest of -the current input line or current statement if an error is detected: -

      -stmnt: error ';'  /* on error, skip until ';' is read */
      -
      -

      -It is also useful to recover to the matching close-delimiter of an -opening-delimiter that has already been parsed. Otherwise the -close-delimiter will probably appear to be unmatched, and generate another, -spurious error message: -

      -primary:  '(' expr ')'
      -        | '(' error ')'
      -        ...
      -        ;
      -
      -

      -Error recovery strategies are necessarily guesses. When they guess wrong, -one syntax error often leads to another. In the above example, the error -recovery rule guesses that an error is due to bad input within one -stmnt. Suppose that instead a spurious semicolon is inserted in the -middle of a valid stmnt. After the error recovery rule recovers -from the first error, another syntax error will be found straightaway, -since the text following the spurious semicolon is also an invalid -stmnt. -To prevent an outpouring of error messages, the parser will output no error -message for another syntax error that happens shortly after the first; only -after three consecutive input tokens have been successfully shifted will -error messages resume. -Note that rules which accept the error token may have actions, just -as any other rules can. - -You can make error messages resume immediately by using the macro -yyerrok in an action. If you do this in the error rule's action, no -error messages will be suppressed. This macro requires no arguments; -`yyerrok;' is a valid C statement. - -The previous look-ahead token is reanalyzed immediately after an error. If -this is unacceptable, then the macro yyclearin may be used to clear -this token. Write the statement `yyclearin;' in the error rule's -action. -For example, suppose that on a parse error, an error handling routine is -called that advances the input stream to some point where parsing should -once again commence. The next symbol returned by the lexical scanner is -probably correct. The previous look-ahead token ought to be discarded -with `yyclearin;'. - -The macro YYRECOVERING stands for an expression that has the -value 1 when the parser is recovering from a syntax error, and 0 the -rest of the time. A value of 1 indicates that error messages are -currently suppressed for new syntax errors. -

      Handling Context Dependencies

      -

      -The Bison paradigm is to parse tokens first, then group them into larger -syntactic units. In many languages, the meaning of a token is affected by -its context. Although this violates the Bison paradigm, certain techniques -(known as kludges) may enable you to write Bison parsers for such -languages. -(Actually, "kludge" means any technique that gets its job done but is -neither clean nor robust.) -

      Semantic Info in Token Types

      -

      -The C language has a context dependency: the way an identifier is used -depends on what its current meaning is. For example, consider this: -

      -foo (x);
      -
      -

      -This looks like a function call statement, but if foo is a typedef -name, then this is actually a declaration of x. How can a Bison -parser for C decide how to parse this input? -The method used in GNU C is to have two different token types, -IDENTIFIER and TYPENAME. When yylex finds an -identifier, it looks up the current declaration of the identifier in order -to decide which token type to return: TYPENAME if the identifier is -declared as a typedef, IDENTIFIER otherwise. -The grammar rules can then express the context dependency by the choice of -token type to recognize. IDENTIFIER is accepted as an expression, -but TYPENAME is not. TYPENAME can start a declaration, but -IDENTIFIER cannot. In contexts where the meaning of the identifier -is not significant, such as in declarations that can shadow a -typedef name, either TYPENAME or IDENTIFIER is -accepted--there is one rule for each of the two token types. -This technique is simple to use if the decision of which kinds of -identifiers to allow is made at a place close to where the identifier is -parsed. But in C this is not always so: C allows a declaration to -redeclare a typedef name provided an explicit type has been specified -earlier: -

      -typedef int foo, bar, lose;
      -static foo (bar);        /* redeclare bar as static variable */
      -static int foo (lose);   /* redeclare foo as function */
      -
      -

      -Unfortunately, the name being declared is separated from the declaration -construct itself by a complicated syntactic structure--the "declarator". -As a result, the part of Bison parser for C needs to be duplicated, with -all the nonterminal names changed: once for parsing a declaration in which -a typedef name can be redefined, and once for parsing a declaration in -which that can't be done. Here is a part of the duplication, with actions -omitted for brevity: -

      -initdcl:
      -          declarator maybeasm '='
      -          init
      -        | declarator maybeasm
      -        ;
      -notype_initdcl:
      -          notype_declarator maybeasm '='
      -          init
      -        | notype_declarator maybeasm
      -        ;
      -
      -

      -Here initdcl can redeclare a typedef name, but notype_initdcl -cannot. The distinction between declarator and -notype_declarator is the same sort of thing. -There is some similarity between this technique and a lexical tie-in -(described next), in that information which alters the lexical analysis is -changed during parsing by other parts of the program. The difference is -here the information is global, and is used for other purposes in the -program. A true lexical tie-in has a special-purpose flag controlled by -the syntactic context. -

      Lexical Tie-ins

      -

      - -One way to handle context-dependency is the lexical tie-in: a flag -which is set by Bison actions, whose purpose is to alter the way tokens are -parsed. -For example, suppose we have a language vaguely like C, but with a special -construct `hex (hex-expr)'. After the keyword hex comes -an expression in parentheses in which all integers are hexadecimal. In -particular, the token `a1b' must be treated as an integer rather than -as an identifier if it appears in that context. Here is how you can do it: -

      -%{
      -int hexflag;
      -%}
      -%%
      -...
      -expr:   IDENTIFIER
      -        | constant
      -        | HEX '('
      -                { hexflag = 1; }
      -          expr ')'
      -                { hexflag = 0;
      -                   $$ = $4; }
      -        | expr '+' expr
      -                { $$ = make_sum ($1, $3); }
      -        ...
      -        ;
      -constant:
      -          INTEGER
      -        | STRING
      -        ;
      -
      -

      -Here we assume that yylex looks at the value of hexflag; when -it is nonzero, all integers are parsed in hexadecimal, and tokens starting -with letters are parsed as integers if possible. -The declaration of hexflag shown in the C declarations section of -the parser file is needed to make it accessible to the actions -(see section The C Declarations Section). You must also write the code in yylex -to obey the flag. -

      Lexical Tie-ins and Error Recovery

      -

      -Lexical tie-ins make strict demands on any error recovery rules you have. -See section Error Recovery. -The reason for this is that the purpose of an error recovery rule is to -abort the parsing of one construct and resume in some larger construct. -For example, in C-like languages, a typical error recovery rule is to skip -tokens until the next semicolon, and then start a new statement, like this: -

      -stmt:   expr ';'
      -        | IF '(' expr ')' stmt { ... }
      -        ...
      -        error ';'
      -                { hexflag = 0; }
      -        ;
      -
      -

      -If there is a syntax error in the middle of a `hex (expr)' -construct, this error rule will apply, and then the action for the -completed `hex (expr)' will never run. So hexflag would -remain set for the entire rest of the input, or until the next hex -keyword, causing identifiers to be misinterpreted as integers. -To avoid this problem the error recovery rule itself clears hexflag. -There may also be an error recovery rule that works within expressions. -For example, there could be a rule which applies within parentheses -and skips to the close-parenthesis: -

      -expr:   ...
      -        | '(' expr ')'
      -                { $$ = $2; }
      -        | '(' error ')'
      -        ...
      -
      -

      -If this rule acts within the hex construct, it is not going to abort -that construct (since it applies to an inner level of parentheses within -the construct). Therefore, it should not clear the flag: the rest of -the hex construct should be parsed with the flag still in effect. -What if there is an error recovery rule which might abort out of the -hex construct or might not, depending on circumstances? There is no -way you can write the action to determine whether a hex construct is -being aborted or not. So if you are using a lexical tie-in, you had better -make sure your error recovery rules are not of this kind. Each rule must -be such that you can be sure that it always will, or always won't, have to -clear the flag. -

      Debugging Your Parser

      -

      - - - - -If a Bison grammar compiles properly but doesn't do what you want when it -runs, the yydebug parser-trace feature can help you figure out why. -To enable compilation of trace facilities, you must define the macro -YYDEBUG when you compile the parser. You could use -`-DYYDEBUG=1' as a compiler option or you could put `#define -YYDEBUG 1' in the C declarations section of the grammar file -(see section The C Declarations Section). Alternatively, use the `-t' option when -you run Bison (see section Invoking Bison). We always define YYDEBUG so that -debugging is always possible. -The trace facility uses stderr, so you must add #include -<stdio.h> to the C declarations section unless it is already there. -Once you have compiled the program with trace facilities, the way to -request a trace is to store a nonzero value in the variable yydebug. -You can do this by making the C code do it (in main, perhaps), or -you can alter the value with a C debugger. -Each step taken by the parser when yydebug is nonzero produces a -line or two of trace information, written on stderr. The trace -messages tell you these things: -

        -
      • -Each time the parser calls yylex, what kind of token was read. -
      • -Each time a token is shifted, the depth and complete contents of the -state stack (see section Parser States). -
      • -Each time a rule is reduced, which rule it is, and the complete contents -of the state stack afterward. -
      -

      -To make sense of this information, it helps to refer to the listing file -produced by the Bison `-v' option (see section Invoking Bison). This file -shows the meaning of each state in terms of positions in various rules, and -also what each state will do with each possible input token. As you read -the successive trace messages, you can see that the parser is functioning -according to its specification in the listing file. Eventually you will -arrive at the place where something undesirable happens, and you will see -which parts of the grammar are to blame. -The parser file is a C program and you can use C debuggers on it, but it's -not easy to interpret what it is doing. The parser function is a -finite-state machine interpreter, and aside from the actions it executes -the same code over and over. Only the values of variables show where in -the grammar it is working. - -The debugging information normally gives the token type of each token -read, but not its semantic value. You can optionally define a macro -named YYPRINT to provide a way to print the value. If you define -YYPRINT, it should take three arguments. The parser will pass a -standard I/O stream, the numeric code for the token type, and the token -value (from yylval). -Here is an example of YYPRINT suitable for the multi-function -calculator (see section Declarations for mfcalc): -

      -#define YYPRINT(file, type, value)   yyprint (file, type, value)
      -static void
      -yyprint (file, type, value)
      -     FILE *file;
      -     int type;
      -     YYSTYPE value;
      -{
      -  if (type == VAR)
      -    fprintf (file, " %s", value.tptr->name);
      -  else if (type == NUM)
      -    fprintf (file, " %d", value.val);
      -}
      -
      -

      -

      Invoking Bison

      -

      - - - -The usual way to invoke Bison is as follows: -

      -bison infile
      -
      -

      -Here infile is the grammar file name, which usually ends in -`.y'. The parser file's name is made by replacing the `.y' -with `.tab.c'. Thus, the `bison foo.y' filename yields -`foo.tab.c', and the `bison hack/foo.y' filename yields -`hack/foo.tab.c'. -

      Bison Options

      -

      -Bison supports both traditional single-letter options and mnemonic long -option names. Long option names are indicated with `--' instead of -`-'. Abbreviations for option names are allowed as long as they -are unique. When a long option takes an argument, like -`--file-prefix', connect the option name and the argument with -`='. -Here is a list of options that can be used with Bison, alphabetized by -short option. It is followed by a cross key alphabetized by long -option. -

      -
      `-b file-prefix' -
      -
      `--file-prefix=prefix' -
      -Specify a prefix to use for all Bison output file names. The names are -chosen as if the input file were named `prefix.c'. -
      `-d' -
      -
      `--defines' -
      -Write an extra output file containing macro definitions for the token -type names defined in the grammar and the semantic value type -YYSTYPE, as well as a few extern variable declarations. -If the parser output file is named `name.c' then this file -is named `name.h'. -This output file is essential if you wish to put the definition of -yylex in a separate source file, because yylex needs to -be able to refer to token type codes and the variable -yylval. See section Semantic Values of Tokens. -
      `-l' -
      -
      `--no-lines' -
      -Don't put any #line preprocessor commands in the parser file. -Ordinarily Bison puts them in the parser file so that the C compiler -and debuggers will associate errors with your source file, the -grammar file. This option causes them to associate errors with the -parser file, treating it an independent source file in its own right. -
      `-o outfile' -
      -
      `--output-file=outfile' -
      -Specify the name outfile for the parser file. -The other output files' names are constructed from outfile -as described under the `-v' and `-d' switches. -
      `-p prefix' -
      -
      `--name-prefix=prefix' -
      -Rename the external symbols used in the parser so that they start with -prefix instead of `yy'. The precise list of symbols renamed -is yyparse, yylex, yyerror, yynerrs, -yylval, yychar and yydebug. -For example, if you use `-p c', the names become cparse, -clex, and so on. -See section Multiple Parsers in the Same Program. -
      `-t' -
      -
      `--debug' -
      -Output a definition of the macro YYDEBUG into the parser file, -so that the debugging facilities are compiled. See section Debugging Your Parser. -
      `-v' -
      -
      `--verbose' -
      -Write an extra output file containing verbose descriptions of the -parser states and what is done for each type of look-ahead token in -that state. -This file also describes all the conflicts, both those resolved by -operator precedence and the unresolved ones. -The file's name is made by removing `.tab.c' or `.c' from -the parser output file name, and adding `.output' instead. -Therefore, if the input file is `foo.y', then the parser file is -called `foo.tab.c' by default. As a consequence, the verbose -output file is called `foo.output'. -
      `-V' -
      -
      `--version' -
      -Print the version number of Bison and exit. -
      `-h' -
      -
      `--help' -
      -Print a summary of the command-line options to Bison and exit. -
      `-y' -
      -
      `--yacc' -
      -
      `--fixed-output-files' -
      -Equivalent to `-o y.tab.c'; the parser output file is called -`y.tab.c', and the other outputs are called `y.output' and -`y.tab.h'. The purpose of this switch is to imitate Yacc's output -file name conventions. Thus, the following shell script can substitute -for Yacc: -
      -bison -y $*
      -
      -
      -

      -

      Option Cross Key

      -

      -Here is a list of options, alphabetized by long option, to help you find -the corresponding short option. -

      Invoking Bison under VMS

      -

      - - -The command line syntax for Bison on VMS is a variant of the usual -Bison command syntax--adapted to fit VMS conventions. -To find the VMS equivalent for any Bison option, start with the long -option, and substitute a `/' for the leading `--', and -substitute a `_' for each `-' in the name of the long option. -For example, the following invocation under VMS: -

      -bison /debug/name_prefix=bar foo.y
      -
      -

      -is equivalent to the following command under POSIX. -

      -bison --debug --name-prefix=bar foo.y
      -
      -

      -The VMS file system does not permit filenames such as -`foo.tab.c'. In the above example, the output file -would instead be named `foo_tab.c'. -

      Bison Symbols

      -

      - - -

      -
      error -
      -A token name reserved for error recovery. This token may be used in -grammar rules so as to allow the Bison parser to recognize an error in -the grammar without halting the process. In effect, a sentence -containing an error may be recognized as valid. On a parse error, the -token error becomes the current look-ahead token. Actions -corresponding to error are then executed, and the look-ahead -token is reset to the token that originally caused the violation. -See section Error Recovery. -
      YYABORT -
      -Macro to pretend that an unrecoverable syntax error has occurred, by -making yyparse return 1 immediately. The error reporting -function yyerror is not called. See section The Parser Function yyparse. -
      YYACCEPT -
      -Macro to pretend that a complete utterance of the language has been -read, by making yyparse return 0 immediately. -See section The Parser Function yyparse. -
      YYBACKUP -
      -Macro to discard a value from the parser stack and fake a look-ahead -token. See section Special Features for Use in Actions. -
      YYERROR -
      -Macro to pretend that a syntax error has just been detected: call -yyerror and then perform normal error recovery if possible -(see section Error Recovery), or (if recovery is impossible) make -yyparse return 1. See section Error Recovery. -
      YYERROR_VERBOSE -
      -Macro that you define with #define in the Bison declarations -section to request verbose, specific error message strings when -yyerror is called. -
      YYINITDEPTH -
      -Macro for specifying the initial size of the parser stack. -See section Stack Overflow, and How to Avoid It. -
      YYLEX_PARAM -
      -Macro for specifying an extra argument (or list of extra arguments) for -yyparse to pass to yylex. See section Calling Conventions for Pure Parsers. -
      YYLTYPE -
      -Macro for the data type of yylloc; a structure with four -members. See section Textual Positions of Tokens. -
      YYMAXDEPTH -
      -Macro for specifying the maximum size of the parser stack. -See section Stack Overflow, and How to Avoid It. -
      YYPARSE_PARAM -
      -Macro for specifying the name of a parameter that yyparse should -accept. See section Calling Conventions for Pure Parsers. -
      YYRECOVERING -
      -Macro whose value indicates whether the parser is recovering from a -syntax error. See section Special Features for Use in Actions. -
      YYSTYPE -
      -Macro for the data type of semantic values; int by default. -See section Data Types of Semantic Values. -
      yychar -
      -External integer variable that contains the integer value of the -current look-ahead token. (In a pure parser, it is a local variable -within yyparse.) Error-recovery rule actions may examine this -variable. See section Special Features for Use in Actions. -
      yyclearin -
      -Macro used in error-recovery rule actions. It clears the previous -look-ahead token. See section Error Recovery. -
      yydebug -
      -External integer variable set to zero by default. If yydebug -is given a nonzero value, the parser will output information on input -symbols and parser action. See section Debugging Your Parser. -
      yyerrok -
      -Macro to cause parser to recover immediately to its normal mode -after a parse error. See section Error Recovery. -
      yyerror -
      -User-supplied function to be called by yyparse on error. The -function receives one argument, a pointer to a character string -containing an error message. See section The Error Reporting Function yyerror. -
      yylex -
      -User-supplied lexical analyzer function, called with no arguments -to get the next token. See section The Lexical Analyzer Function yylex. -
      yylval -
      -External variable in which yylex should place the semantic -value associated with a token. (In a pure parser, it is a local -variable within yyparse, and its address is passed to -yylex.) See section Semantic Values of Tokens. -
      yylloc -
      -External variable in which yylex should place the line and -column numbers associated with a token. (In a pure parser, it is a -local variable within yyparse, and its address is passed to -yylex.) You can ignore this variable if you don't use the -`@' feature in the grammar actions. See section Textual Positions of Tokens. -
      yynerrs -
      -Global variable which Bison increments each time there is a parse -error. (In a pure parser, it is a local variable within -yyparse.) See section The Error Reporting Function yyerror. -
      yyparse -
      -The parser function produced by Bison; call this function to start -parsing. See section The Parser Function yyparse. -
      %left -
      -Bison declaration to assign left associativity to token(s). -See section Operator Precedence. -
      %nonassoc -
      -Bison declaration to assign nonassociativity to token(s). -See section Operator Precedence. -
      %prec -
      -Bison declaration to assign a precedence to a specific rule. -See section Context-Dependent Precedence. -
      %pure_parser -
      -Bison declaration to request a pure (reentrant) parser. -See section A Pure (Reentrant) Parser. -
      %right -
      -Bison declaration to assign right associativity to token(s). -See section Operator Precedence. -
      %start -
      -Bison declaration to specify the start symbol. See section The Start-Symbol. -
      %token -
      -Bison declaration to declare token(s) without specifying precedence. -See section Token Type Names. -
      %type -
      -Bison declaration to declare nonterminals. See section Nonterminal Symbols. -
      %union -
      -Bison declaration to specify several possible data types for semantic -values. See section The Collection of Value Types. -
      -

      -These are the punctuation and delimiters used in Bison input: -

      -
      `%%' -
      -Delimiter used to separate the grammar rule section from the -Bison declarations section or the additional C code section. -See section The Overall Layout of a Bison Grammar. -
      `%{ %}' -
      -All code listed between `%{' and `%}' is copied directly -to the output file uninterpreted. Such code forms the "C -declarations" section of the input file. See section Outline of a Bison Grammar. -
      `/*...*/' -
      -Comment delimiters, as in C. -
      `:' -
      -Separates a rule's result from its components. See section Syntax of Grammar Rules. -
      `;' -
      -Terminates a rule. See section Syntax of Grammar Rules. -
      `|' -
      -Separates alternate rules for the same result nonterminal. -See section Syntax of Grammar Rules. -
      -

      -

      Glossary

      -

      - -

      -
      Backus-Naur Form (BNF) -
      -Formal method of specifying context-free grammars. BNF was first used -in the ALGOL-60 report, 1963. See section Languages and Context-Free Grammars. -
      Context-free grammars -
      -Grammars specified as rules that can be applied regardless of context. -Thus, if there is a rule which says that an integer can be used as an -expression, integers are allowed anywhere an expression is -permitted. See section Languages and Context-Free Grammars. -
      Dynamic allocation -
      -Allocation of memory that occurs during execution, rather than at -compile time or on entry to a function. -
      Empty string -
      -Analogous to the empty set in set theory, the empty string is a -character string of length zero. -
      Finite-state stack machine -
      -A "machine" that has discrete states in which it is said to exist at -each instant in time. As input to the machine is processed, the -machine moves from state to state as specified by the logic of the -machine. In the case of the parser, the input is the language being -parsed, and the states correspond to various stages in the grammar -rules. See section The Bison Parser Algorithm. -
      Grouping -
      -A language construct that is (in general) grammatically divisible; -for example, `expression' or `declaration' in C. -See section Languages and Context-Free Grammars. -
      Infix operator -
      -An arithmetic operator that is placed between the operands on which it -performs some operation. -
      Input stream -
      -A continuous flow of data between devices or programs. -
      Language construct -
      -One of the typical usage schemas of the language. For example, one of -the constructs of the C language is the if statement. -See section Languages and Context-Free Grammars. -
      Left associativity -
      -Operators having left associativity are analyzed from left to right: -`a+b+c' first computes `a+b' and then combines with -`c'. See section Operator Precedence. -
      Left recursion -
      -A rule whose result symbol is also its first component symbol; -for example, `expseq1 : expseq1 ',' exp;'. See section Recursive Rules. -
      Left-to-right parsing -
      -Parsing a sentence of a language by analyzing it token by token from -left to right. See section The Bison Parser Algorithm. -
      Lexical analyzer (scanner) -
      -A function that reads an input stream and returns tokens one by one. -See section The Lexical Analyzer Function yylex. -
      Lexical tie-in -
      -A flag, set by actions in the grammar rules, which alters the way -tokens are parsed. See section Lexical Tie-ins. -
      Look-ahead token -
      -A token already read but not yet shifted. See section Look-Ahead Tokens. -
      LALR(1) -
      -The class of context-free grammars that Bison (like most other parser -generators) can handle; a subset of LR(1). See section Mysterious Reduce/Reduce Conflicts. -
      LR(1) -
      -The class of context-free grammars in which at most one token of -look-ahead is needed to disambiguate the parsing of any piece of input. -
      Nonterminal symbol -
      -A grammar symbol standing for a grammatical construct that can -be expressed through rules in terms of smaller constructs; in other -words, a construct that is not a token. See section Symbols, Terminal and Nonterminal. -
      Parse error -
      -An error encountered during parsing of an input stream due to invalid -syntax. See section Error Recovery. -
      Parser -
      -A function that recognizes valid sentences of a language by analyzing -the syntax structure of a set of tokens passed to it from a lexical -analyzer. -
      Postfix operator -
      -An arithmetic operator that is placed after the operands upon which it -performs some operation. -
      Reduction -
      -Replacing a string of nonterminals and/or terminals with a single -nonterminal, according to a grammar rule. See section The Bison Parser Algorithm. -
      Reentrant -
      -A reentrant subprogram is a subprogram which can be in invoked any -number of times in parallel, without interference between the various -invocations. See section A Pure (Reentrant) Parser. -
      Reverse polish notation -
      -A language in which all operators are postfix operators. -
      Right recursion -
      -A rule whose result symbol is also its last component symbol; -for example, `expseq1: exp ',' expseq1;'. See section Recursive Rules. -
      Semantics -
      -In computer languages, the semantics are specified by the actions -taken for each instance of the language, i.e., the meaning of -each statement. See section Defining Language Semantics. -
      Shift -
      -A parser is said to shift when it makes the choice of analyzing -further input from the stream rather than reducing immediately some -already-recognized rule. See section The Bison Parser Algorithm. -
      Single-character literal -
      -A single character that is recognized and interpreted as is. -See section From Formal Rules to Bison Input. -
      Start symbol -
      -The nonterminal symbol that stands for a complete valid utterance in -the language being parsed. The start symbol is usually listed as the -first nonterminal symbol in a language specification. -See section The Start-Symbol. -
      Symbol table -
      -A data structure where symbol names and associated data are stored -during parsing to allow for recognition and use of existing -information in repeated uses of a symbol. See section Multi-Function Calculator: mfcalc. -
      Token -
      -A basic, grammatically indivisible unit of a language. The symbol -that describes a token in the grammar is a terminal symbol. -The input of the Bison parser is a stream of tokens which comes from -the lexical analyzer. See section Symbols, Terminal and Nonterminal. -
      Terminal symbol -
      -A grammar symbol that has no rules in the grammar and therefore -is grammatically indivisible. The piece of text it represents -is a token. See section Languages and Context-Free Grammars. -
      -

      -

      Index

      -

      -Jump to: -$ -- -% -- -@ -- -a -- -b -- -c -- -d -- -e -- -f -- -g -- -i -- -l -- -m -- -n -- -o -- -p -- -r -- -s -- -t -- -u -- -v -- -w -- -y -- -| -

      -

      $

      - -
    • $$ -
    • $n -
    • -

      %

      - -
    • %expect -
    • %left -
    • %nonassoc -
    • %prec -
    • %pure_parser -
    • %right -
    • %start -
    • %token -
    • %type -
    • %union -
    • -

      @

      - -
    • @n -
    • -

      a

      - -
    • action -
    • action data types -
    • action features summary -
    • actions in mid-rule -
    • actions, semantic -
    • additional C code section -
    • algorithm of parser -
    • associativity -
    • -

      b

      - -
    • Backus-Naur form -
    • Bison declaration summary -
    • Bison declarations -
    • Bison declarations (introduction) -
    • Bison grammar -
    • Bison invocation -
    • Bison parser -
    • Bison parser algorithm -
    • Bison symbols, table of -
    • Bison utility -
    • BNF -
    • -

      c

      - -
    • C code, section for additional -
    • C declarations section -
    • C-language interface -
    • calc -
    • calculator, infix notation -
    • calculator, multi-function -
    • calculator, simple -
    • character token -
    • compiling the parser -
    • conflicts -
    • conflicts, reduce/reduce -
    • conflicts, suppressing warnings of -
    • context-dependent precedence -
    • context-free grammar -
    • controlling function -
    • -

      d

      - -
    • dangling else -
    • data types in actions -
    • data types of semantic values -
    • debugging -
    • declaration summary -
    • declarations, Bison -
    • declarations, Bison (introduction) -
    • declarations, C -
    • declaring operator precedence -
    • declaring the start symbol -
    • declaring token type names -
    • declaring value types -
    • declaring value types, nonterminals -
    • default action -
    • default data type -
    • default stack limit -
    • default start symbol -
    • defining language semantics -
    • -

      e

      - -
    • else, dangling -
    • error -
    • error recovery -
    • error recovery, simple -
    • error reporting function -
    • error reporting routine -
    • examples, simple -
    • exercises -
    • -

      f

      - -
    • file format -
    • finite-state machine -
    • formal grammar -
    • format of grammar file -
    • -

      g

      - -
    • glossary -
    • grammar file -
    • grammar rule syntax -
    • grammar rules section -
    • grammar, Bison -
    • grammar, context-free -
    • grouping, syntactic -
    • -

      i

      - -
    • infix notation calculator -
    • interface -
    • introduction -
    • invoking Bison -
    • invoking Bison under VMS -
    • -

      l

      - -
    • LALR(1) -
    • language semantics, defining -
    • layout of Bison grammar -
    • left recursion -
    • lexical analyzer -
    • lexical analyzer, purpose -
    • lexical analyzer, writing -
    • lexical tie-in -
    • literal token -
    • look-ahead token -
    • LR(1) -
    • -

      m

      - -
    • main function in simple example -
    • mfcalc -
    • mid-rule actions -
    • multi-function calculator -
    • mutual recursion -
    • -

      n

      - -
    • nonterminal symbol -
    • -

      o

      - -
    • operator precedence -
    • operator precedence, declaring -
    • options for invoking Bison -
    • overflow of parser stack -
    • -

      p

      - -
    • parse error -
    • parser -
    • parser stack -
    • parser stack overflow -
    • parser state -
    • polish notation calculator -
    • precedence declarations -
    • precedence of operators -
    • precedence, context-dependent -
    • precedence, unary operator -
    • preventing warnings about conflicts -
    • pure parser -
    • -

      r

      - -
    • recovery from errors -
    • recursive rule -
    • reduce/reduce conflict -
    • reduction -
    • reentrant parser -
    • reverse polish notation -
    • right recursion -
    • rpcalc -
    • rule syntax -
    • rules section for grammar -
    • running Bison (introduction) -
    • -

      s

      - -
    • semantic actions -
    • semantic value -
    • semantic value type -
    • shift/reduce conflicts -
    • shifting -
    • simple examples -
    • single-character literal -
    • stack overflow -
    • stack, parser -
    • stages in using Bison -
    • start symbol -
    • start symbol, declaring -
    • state (of parser) -
    • summary, action features -
    • summary, Bison declaration -
    • suppressing conflict warnings -
    • symbol -
    • symbol table example -
    • symbols (abstract) -
    • symbols in Bison, table of -
    • syntactic grouping -
    • syntax error -
    • syntax of grammar rules -
    • -

      t

      - -
    • terminal symbol -
    • token -
    • token type -
    • token type names, declaring -
    • tracing the parser -
    • -

      u

      - -
    • unary operator precedence -
    • using Bison -
    • -

      v

      - -
    • value type, semantic -
    • value types, declaring -
    • value types, nonterminals, declaring -
    • value, semantic -
    • VMS -
    • -

      w

      - -
    • warnings, preventing -
    • writing a lexical analyzer -
    • -

      y

      - -
    • YYABORT -
    • YYACCEPT -
    • YYBACKUP -
    • yychar -
    • yyclearin -
    • YYDEBUG -
    • yydebug -
    • YYEMPTY -
    • yyerrok -
    • yyerror -
    • YYERROR -
    • YYERROR_VERBOSE -
    • YYINITDEPTH -
    • yylex -
    • YYLEX_PARAM -
    • yylloc -
    • YYLTYPE -
    • yylval -
    • YYMAXDEPTH -
    • yynerrs -
    • yyparse -
    • YYPARSE_PARAM -
    • YYPRINT -
    • YYRECOVERING -
    • -

      |

      - -
    • | -
    • -


      -This document was generated on 2 October 1998 using the -texi2html -translator version 1.52.

      - - diff --git a/Engine/bin/flex/flex.exe b/Engine/bin/flex/flex.exe deleted file mode 100644 index 30bfa2916..000000000 Binary files a/Engine/bin/flex/flex.exe and /dev/null differ diff --git a/Engine/bin/flex/flex_1.html b/Engine/bin/flex/flex_1.html deleted file mode 100644 index 2f0080a89..000000000 --- a/Engine/bin/flex/flex_1.html +++ /dev/null @@ -1,4079 +0,0 @@ -flex -
        -

      NAME

        - -flex - fast lexical analyzer generator - -

      SYNOPSIS

        - -flex -[-bcdfhilnpstvwBFILTV78+? -C[aefFmr] -ooutput -Pprefix -Sskeleton] -[--help --version] -[filename ...] - -

      OVERVIEW

        - -This manual describes -flex, -a tool for generating programs that perform pattern-matching on text. The -manual includes both tutorial and reference sections: -
        -
        -


        Description -
        a brief overview of the tool -
        -


        Some Simple Examples -
        -


        Format Of The Input File -
        -


        Patterns -
        the extended regular expressions used by flex -
        -


        How The Input Is Matched -
        the rules for determining what has been matched -
        -


        Actions -
        how to specify what to do when a pattern is matched -
        -


        The Generated Scanner -
        details regarding the scanner that flex produces; -
        how to control the input source -
        -


        Start Conditions -
        introducing context into your scanners, and -
        managing "mini-scanners" -
        -


        Multiple Input Buffers -
        how to manipulate multiple input sources; how to -
        scan from strings instead of files -
        -


        End-of-file Rules -
        special rules for matching the end of the input -
        -


        Miscellaneous Macros -
        a summary of macros available to the actions -
        -


        Values Available To The User -
        a summary of values available to the actions -
        -


        Interfacing With Yacc -
        connecting flex scanners together with yacc parsers -
        -


        Options -
        flex command-line options, and the "%option" -
        directive -
        -


        Performance Considerations -
        how to make your scanner go as fast as possible -
        -


        Generating C++ Scanners -
        the (experimental) facility for generating C++ -
        scanner classes -
        -


        Incompatibilities With Lex And POSIX -
        how flex differs from AT&T lex and the POSIX lex -
        standard -
        -


        Diagnostics -
        those error messages produced by flex (or scanners -
        it generates) whose meanings might not be apparent -
        -


        Files -
        files used by flex -
        -


        Deficiencies / Bugs -
        known problems with flex -
        -


        See Also -
        other documentation, related tools -
        -


        Author -
        includes contact information -
        -


        - -

      DESCRIPTION

        - -flex -is a tool for generating -scanners: -programs which recognized lexical patterns in text. -flex -reads -the given input files, or its standard input if no file names are given, -for a description of a scanner to generate. The description is in -the form of pairs -of regular expressions and C code, called -rules. flex -generates as output a C source file, -lex.yy.c, -which defines a routine -yylex(). -This file is compiled and linked with the --lfl -library to produce an executable. When the executable is run, -it analyzes its input for occurrences -of the regular expressions. Whenever it finds one, it executes -the corresponding C code. - -

      SOME SIMPLE EXAMPLES

        - - -

        -First some simple examples to get the flavor of how one uses -flex. -The following -flex -input specifies a scanner which whenever it encounters the string -"username" will replace it with the user's login name: -

        -
        -


        %% -
        username printf( "%s", getlogin() ); -
        -


        -By default, any text not matched by a -flex -scanner -is copied to the output, so the net effect of this scanner is -to copy its input file to its output with each occurrence -of "username" expanded. -In this input, there is just one rule. "username" is the -pattern -and the "printf" is the -action. -The "%%" marks the beginning of the rules. - -

        -Here's another simple example: -

        -
        -


        int num_lines = 0, num_chars = 0; -
        -


        %% -
        \n ++num_lines; ++num_chars; -
        . ++num_chars; -
        -


        %% -
        main() -
        { -
        yylex(); -
        printf( "# of lines = %d, # of chars = %d\n", -
        num_lines, num_chars ); -
        } -
        -


        -This scanner counts the number of characters and the number -of lines in its input (it produces no output other than the -final report on the counts). The first line -declares two globals, "num_lines" and "num_chars", which are accessible -both inside -yylex() -and in the -main() -routine declared after the second "%%". There are two rules, one -which matches a newline ("\n") and increments both the line count and -the character count, and one which matches any character other than -a newline (indicated by the "." regular expression). - -

        -A somewhat more complicated example: -

        -
        -


        /* scanner for a toy Pascal-like language */ -
        -


        %{ -
        /* need this for the call to atof() below */ -
        #include <math.h> -
        %} -
        -


        DIGIT [0-9] -
        ID [a-z][a-z0-9]* -
        -


        %% -
        -


        {DIGIT}+ { -
        printf( "An integer: %s (%d)\n", yytext, -
        atoi( yytext ) ); -
        } -
        -


        {DIGIT}+"."{DIGIT}* { -
        printf( "A float: %s (%g)\n", yytext, -
        atof( yytext ) ); -
        } -
        -


        if|then|begin|end|procedure|function { -
        printf( "A keyword: %s\n", yytext ); -
        } -
        -


        {ID} printf( "An identifier: %s\n", yytext ); -
        -


        "+"|"-"|"*"|"/" printf( "An operator: %s\n", yytext ); -
        -


        "{"[^}\n]*"}" /* eat up one-line comments */ -
        -


        [ \t\n]+ /* eat up whitespace */ -
        -


        . printf( "Unrecognized character: %s\n", yytext ); -
        -


        %% -
        -


        main( argc, argv ) -
        int argc; -
        char **argv; -
        { -
        ++argv, --argc; /* skip over program name */ -
        if ( argc > 0 ) -
        yyin = fopen( argv[0], "r" ); -
        else -
        yyin = stdin; -
        -
        yylex(); -
        } -
        -


        -This is the beginnings of a simple scanner for a language like -Pascal. It identifies different types of -tokens -and reports on what it has seen. - -

        -The details of this example will be explained in the following -sections. - -

      FORMAT OF THE INPUT FILE

        - -The -flex -input file consists of three sections, separated by a line with just -%% -in it: -
        -
        -


        definitions -
        %% -
        rules -
        %% -
        user code -
        -


        -The -definitions -section contains declarations of simple -name -definitions to simplify the scanner specification, and declarations of -start conditions, -which are explained in a later section. - -

        -Name definitions have the form: -

        -
        -


        name definition -
        -


        -The "name" is a word beginning with a letter or an underscore ('_') -followed by zero or more letters, digits, '_', or '-' (dash). -The definition is taken to begin at the first non-white-space character -following the name and continuing to the end of the line. -The definition can subsequently be referred to using "{name}", which -will expand to "(definition)". For example, -
        -
        -


        DIGIT [0-9] -
        ID [a-z][a-z0-9]* -
        -


        -defines "DIGIT" to be a regular expression which matches a -single digit, and -"ID" to be a regular expression which matches a letter -followed by zero-or-more letters-or-digits. -A subsequent reference to -
        -
        -


        {DIGIT}+"."{DIGIT}* -
        -


        -is identical to -
        -
        -


        ([0-9])+"."([0-9])* -
        -


        -and matches one-or-more digits followed by a '.' followed -by zero-or-more digits. - -

        -The -rules -section of the -flex -input contains a series of rules of the form: -

        -
        -


        pattern action -
        -


        -where the pattern must be unindented and the action must begin -on the same line. - -

        -See below for a further description of patterns and actions. - -

        -Finally, the user code section is simply copied to -lex.yy.c -verbatim. -It is used for companion routines which call or are called -by the scanner. The presence of this section is optional; -if it is missing, the second -%% -in the input file may be skipped, too. - -

        -In the definitions and rules sections, any -indented -text or text enclosed in -%{ -and -%} -is copied verbatim to the output (with the %{}'s removed). -The %{}'s must appear unindented on lines by themselves. - -

        -In the rules section, -any indented or %{} text appearing before the -first rule may be used to declare variables -which are local to the scanning routine and (after the declarations) -code which is to be executed whenever the scanning routine is entered. -Other indented or %{} text in the rule section is still copied to the output, -but its meaning is not well-defined and it may well cause compile-time -errors (this feature is present for -POSIX -compliance; see below for other such features). - -

        -In the definitions section (but not in the rules section), -an unindented comment (i.e., a line -beginning with "/*") is also copied verbatim to the output up -to the next "*/". - -

      PATTERNS

        - -The patterns in the input are written using an extended set of regular -expressions. These are: -
        -
        -


        x match the character 'x' -
        . any character (byte) except newline -
        [xyz] a "character class"; in this case, the pattern -
        matches either an 'x', a 'y', or a 'z' -
        [abj-oZ] a "character class" with a range in it; matches -
        an 'a', a 'b', any letter from 'j' through 'o', -
        or a 'Z' -
        [^A-Z] a "negated character class", i.e., any character -
        but those in the class. In this case, any -
        character EXCEPT an uppercase letter. -
        [^A-Z\n] any character EXCEPT an uppercase letter or -
        a newline -
        r* zero or more r's, where r is any regular expression -
        r+ one or more r's -
        r? zero or one r's (that is, "an optional r") -
        r{2,5} anywhere from two to five r's -
        r{2,} two or more r's -
        r{4} exactly 4 r's -
        {name} the expansion of the "name" definition -
        (see above) -
        "[xyz]\"foo" -
        the literal string: [xyz]"foo -
        \X if X is an 'a', 'b', 'f', 'n', 'r', 't', or 'v', -
        then the ANSI-C interpretation of \x. -
        Otherwise, a literal 'X' (used to escape -
        operators such as '*') -
        \0 a NUL character (ASCII code 0) -
        \123 the character with octal value 123 -
        \x2a the character with hexadecimal value 2a -
        (r) match an r; parentheses are used to override -
        precedence (see below) -
        -


        -


        rs the regular expression r followed by the -
        regular expression s; called "concatenation" -
        -


        -


        r|s either an r or an s -
        -


        -


        r/s an r but only if it is followed by an s. The -
        text matched by s is included when determining -
        whether this rule is the "longest match", -
        but is then returned to the input before -
        the action is executed. So the action only -
        sees the text matched by r. This type -
        of pattern is called trailing context". -
        (There are some combinations of r/s that flex -
        cannot match correctly; see notes in the -
        Deficiencies / Bugs section below regarding -
        "dangerous trailing context".) -
        ^r an r, but only at the beginning of a line (i.e., -
        which just starting to scan, or right after a -
        newline has been scanned). -
        r$ an r, but only at the end of a line (i.e., just -
        before a newline). Equivalent to "r/\n". -
        -


        Note that flex's notion of "newline" is exactly -
        whatever the C compiler used to compile flex -
        interprets '\n' as; in particular, on some DOS -
        systems you must either filter out \r's in the -
        input yourself, or explicitly use r/\r\n for "r$". -
        -


        -


        <s>r an r, but only in start condition s (see -
        below for discussion of start conditions) -
        <s1,s2,s3>r -
        same, but in any of start conditions s1, -
        s2, or s3 -
        <*>r an r in any start condition, even an exclusive one. -
        -


        -


        <<EOF>> an end-of-file -
        <s1,s2><<EOF>> -
        an end-of-file when in start condition s1 or s2 -
        -


        -Note that inside of a character class, all regular expression operators -lose their special meaning except escape ('\') and the character class -operators, '-', ']', and, at the beginning of the class, '^'. - -

        -The regular expressions listed above are grouped according to -precedence, from highest precedence at the top to lowest at the bottom. -Those grouped together have equal precedence. For example, -

        -
        -


        foo|bar* -
        -


        -is the same as -
        -
        -


        (foo)|(ba(r*)) -
        -


        -since the '*' operator has higher precedence than concatenation, -and concatenation higher than alternation ('|'). This pattern -therefore matches -either -the string "foo" -or -the string "ba" followed by zero-or-more r's. -To match "foo" or zero-or-more "bar"'s, use: -
        -
        -


        foo|(bar)* -
        -


        -and to match zero-or-more "foo"'s-or-"bar"'s: -
        -
        -


        (foo|bar)* -
        -


        - -

        -In addition to characters and ranges of characters, character classes -can also contain character class -expressions. -These are expressions enclosed inside -[: -and -:] -delimiters (which themselves must appear between the '[' and ']' of the -character class; other elements may occur inside the character class, too). -The valid expressions are: -

        -
        -


        [:alnum:] [:alpha:] [:blank:] -
        [:cntrl:] [:digit:] [:graph:] -
        [:lower:] [:print:] [:punct:] -
        [:space:] [:upper:] [:xdigit:] -
        -


        -These expressions all designate a set of characters equivalent to -the corresponding standard C -isXXX -function. For example, -[:alnum:] -designates those characters for which -isalnum() -returns true - i.e., any alphabetic or numeric. -Some systems don't provide -isblank(), -so flex defines -[:blank:] -as a blank or a tab. - -

        -For example, the following character classes are all equivalent: -

        -
        -


        [[:alnum:]] -
        [[:alpha:][:digit:] -
        [[:alpha:]0-9] -
        [a-zA-Z0-9] -
        -


        -If your scanner is case-insensitive (the --i -flag), then -[:upper:] -and -[:lower:] -are equivalent to -[:alpha:]. - -

        -Some notes on patterns: -

        -
        A negated character class such as the example "[^A-Z]" -above -will match a newline -unless "\n" (or an equivalent escape sequence) is one of the -characters explicitly present in the negated character class -(e.g., "[^A-Z\n]"). This is unlike how many other regular -expression tools treat negated character classes, but unfortunately -the inconsistency is historically entrenched. -Matching newlines means that a pattern like [^"]* can match the entire -input unless there's another quote in the input. -
        -
        A rule can have at most one instance of trailing context (the '/' operator -or the '$' operator). The start condition, '^', and "<<EOF>>" patterns -can only occur at the beginning of a pattern, and, as well as with '/' and '$', -cannot be grouped inside parentheses. A '^' which does not occur at -the beginning of a rule or a '$' which does not occur at the end of -a rule loses its special properties and is treated as a normal character. -
        The following are illegal: -
        -
        -


        foo/bar$ -
        <sc1>foo<sc2>bar -
        -


        -Note that the first of these, can be written "foo/bar\n". -
        The following will result in '$' or '^' being treated as a normal character: -
        -
        -


        foo|(bar$) -
        foo|^bar -
        -


        -If what's wanted is a "foo" or a bar-followed-by-a-newline, the following -could be used (the special '|' action is explained below): -
        -
        -


        foo | -
        bar$ /* action goes here */ -
        -


        -A similar trick will work for matching a foo or a -bar-at-the-beginning-of-a-line. -
        -

      HOW THE INPUT IS MATCHED

        - -When the generated scanner is run, it analyzes its input looking -for strings which match any of its patterns. If it finds more than -one match, it takes the one matching the most text (for trailing -context rules, this includes the length of the trailing part, even -though it will then be returned to the input). If it finds two -or more matches of the same length, the -rule listed first in the -flex -input file is chosen. - -

        -Once the match is determined, the text corresponding to the match -(called the -token) -is made available in the global character pointer -yytext, -and its length in the global integer -yyleng. -The -action -corresponding to the matched pattern is then executed (a more -detailed description of actions follows), and then the remaining -input is scanned for another match. - -

        -If no match is found, then the -default rule -is executed: the next character in the input is considered matched and -copied to the standard output. Thus, the simplest legal -flex -input is: -

        -
        -


        %% -
        -


        -which generates a scanner that simply copies its input (one character -at a time) to its output. - -

        -Note that -yytext -can be defined in two different ways: either as a character -pointer -or as a character -array. -You can control which definition -flex -uses by including one of the special directives -%pointer -or -%array -in the first (definitions) section of your flex input. The default is -%pointer, -unless you use the --l -lex compatibility option, in which case -yytext -will be an array. -The advantage of using -%pointer -is substantially faster scanning and no buffer overflow when matching -very large tokens (unless you run out of dynamic memory). The disadvantage -is that you are restricted in how your actions can modify -yytext -(see the next section), and calls to the -unput() -function destroys the present contents of -yytext, -which can be a considerable porting headache when moving between different -lex -versions. - -

        -The advantage of -%array -is that you can then modify -yytext -to your heart's content, and calls to -unput() -do not destroy -yytext -(see below). Furthermore, existing -lex -programs sometimes access -yytext -externally using declarations of the form: -

        -    extern char yytext[];
        -
        -This definition is erroneous when used with -%pointer, -but correct for -%array. - -

        -%array -defines -yytext -to be an array of -YYLMAX -characters, which defaults to a fairly large value. You can change -the size by simply #define'ing -YYLMAX -to a different value in the first section of your -flex -input. As mentioned above, with -%pointer -yytext grows dynamically to accommodate large tokens. While this means your -%pointer -scanner can accommodate very large tokens (such as matching entire blocks -of comments), bear in mind that each time the scanner must resize -yytext -it also must rescan the entire token from the beginning, so matching such -tokens can prove slow. -yytext -presently does -not -dynamically grow if a call to -unput() -results in too much text being pushed back; instead, a run-time error results. - -

        -Also note that you cannot use -%array -with C++ scanner classes -(the -c++ -option; see below). - -

      ACTIONS

        - -Each pattern in a rule has a corresponding action, which can be any -arbitrary C statement. The pattern ends at the first non-escaped -whitespace character; the remainder of the line is its action. If the -action is empty, then when the pattern is matched the input token -is simply discarded. For example, here is the specification for a program -which deletes all occurrences of "zap me" from its input: -
        -
        -


        %% -
        "zap me" -
        -


        -(It will copy all other characters in the input to the output since -they will be matched by the default rule.) - -

        -Here is a program which compresses multiple blanks and tabs down to -a single blank, and throws away whitespace found at the end of a line: -

        -
        -


        %% -
        [ \t]+ putchar( ' ' ); -
        [ \t]+$ /* ignore this token */ -
        -


        - -

        -If the action contains a '{', then the action spans till the balancing '}' -is found, and the action may cross multiple lines. -flex -knows about C strings and comments and won't be fooled by braces found -within them, but also allows actions to begin with -%{ -and will consider the action to be all the text up to the next -%} -(regardless of ordinary braces inside the action). - -

        -An action consisting solely of a vertical bar ('|') means "same as -the action for the next rule." See below for an illustration. - -

        -Actions can include arbitrary C code, including -return -statements to return a value to whatever routine called -yylex(). -Each time -yylex() -is called it continues processing tokens from where it last left -off until it either reaches -the end of the file or executes a return. - -

        -Actions are free to modify -yytext -except for lengthening it (adding -characters to its end--these will overwrite later characters in the -input stream). This however does not apply when using -%array -(see above); in that case, -yytext -may be freely modified in any way. - -

        -Actions are free to modify -yyleng -except they should not do so if the action also includes use of -yymore() -(see below). - -

        -There are a number of special directives which can be included within -an action: -

        -
        ECHO -copies yytext to the scanner's output. -
        -
        BEGIN -followed by the name of a start condition places the scanner in the -corresponding start condition (see below). -
        -
        REJECT -directs the scanner to proceed on to the "second best" rule which matched the -input (or a prefix of the input). The rule is chosen as described -above in "How the Input is Matched", and -yytext -and -yyleng -set up appropriately. -It may either be one which matched as much text -as the originally chosen rule but came later in the -flex -input file, or one which matched less text. -For example, the following will both count the -words in the input and call the routine special() whenever "frob" is seen: -
        -
        -


        int word_count = 0; -
        %% -
        -


        frob special(); REJECT; -
        [^ \t\n]+ ++word_count; -
        -


        -Without the -REJECT, -any "frob"'s in the input would not be counted as words, since the -scanner normally executes only one action per token. -Multiple -REJECT's -are allowed, each one finding the next best choice to the currently -active rule. For example, when the following scanner scans the token -"abcd", it will write "abcdabcaba" to the output: -
        -
        -


        %% -
        a | -
        ab | -
        abc | -
        abcd ECHO; REJECT; -
        .|\n /* eat up any unmatched character */ -
        -


        -(The first three rules share the fourth's action since they use -the special '|' action.) -REJECT -is a particularly expensive feature in terms of scanner performance; -if it is used in -any -of the scanner's actions it will slow down -all -of the scanner's matching. Furthermore, -REJECT -cannot be used with the --Cf -or --CF -options (see below). -
        Note also that unlike the other special actions, -REJECT -is a -branch; -code immediately following it in the action will -not -be executed. -
        -
        yymore() -tells the scanner that the next time it matches a rule, the corresponding -token should be -appended -onto the current value of -yytext -rather than replacing it. For example, given the input "mega-kludge" -the following will write "mega-mega-kludge" to the output: -
        -
        -


        %% -
        mega- ECHO; yymore(); -
        kludge ECHO; -
        -


        -First "mega-" is matched and echoed to the output. Then "kludge" -is matched, but the previous "mega-" is still hanging around at the -beginning of -yytext -so the -ECHO -for the "kludge" rule will actually write "mega-kludge". -
        -

        -Two notes regarding use of -yymore(). -First, -yymore() -depends on the value of -yyleng -correctly reflecting the size of the current token, so you must not -modify -yyleng -if you are using -yymore(). -Second, the presence of -yymore() -in the scanner's action entails a minor performance penalty in the -scanner's matching speed. -

        -
        yyless(n) -returns all but the first -n -characters of the current token back to the input stream, where they -will be rescanned when the scanner looks for the next match. -yytext -and -yyleng -are adjusted appropriately (e.g., -yyleng -will now be equal to -n -). For example, on the input "foobar" the following will write out -"foobarbar": -
        -
        -


        %% -
        foobar ECHO; yyless(3); -
        [a-z]+ ECHO; -
        -


        -An argument of 0 to -yyless -will cause the entire current input string to be scanned again. Unless you've -changed how the scanner will subsequently process its input (using -BEGIN, -for example), this will result in an endless loop. -
        -

        -Note that -yyless -is a macro and can only be used in the flex input file, not from -other source files. -

        -
        unput(c) -puts the character -c -back onto the input stream. It will be the next character scanned. -The following action will take the current token and cause it -to be rescanned enclosed in parentheses. -
        -
        -


        { -
        int i; -
        /* Copy yytext because unput() trashes yytext */ -
        char *yycopy = strdup( yytext ); -
        unput( ')' ); -
        for ( i = yyleng - 1; i >= 0; --i ) -
        unput( yycopy[i] ); -
        unput( '(' ); -
        free( yycopy ); -
        } -
        -


        -Note that since each -unput() -puts the given character back at the -beginning -of the input stream, pushing back strings must be done back-to-front. -
        -

        -An important potential problem when using -unput() -is that if you are using -%pointer -(the default), a call to -unput() -destroys -the contents of -yytext, -starting with its rightmost character and devouring one character to -the left with each call. If you need the value of yytext preserved -after a call to -unput() -(as in the above example), -you must either first copy it elsewhere, or build your scanner using -%array -instead (see How The Input Is Matched). - -

        -Finally, note that you cannot put back -EOF -to attempt to mark the input stream with an end-of-file. -

        -
        input() -reads the next character from the input stream. For example, -the following is one way to eat up C comments: -
        -
        -


        %% -
        "/*" { -
        register int c; -
        -


        for ( ; ; ) -
        { -
        while ( (c = input()) != '*' && -
        c != EOF ) -
        ; /* eat up text of comment */ -
        -


        if ( c == '*' ) -
        { -
        while ( (c = input()) == '*' ) -
        ; -
        if ( c == '/' ) -
        break; /* found the end */ -
        } -
        -


        if ( c == EOF ) -
        { -
        error( "EOF in comment" ); -
        break; -
        } -
        } -
        } -
        -


        -(Note that if the scanner is compiled using -C++, -then -input() -is instead referred to as -yyinput(), -in order to avoid a name clash with the -C++ -stream by the name of -input.) -
        -
        YY_FLUSH_BUFFER -flushes the scanner's internal buffer -so that the next time the scanner attempts to match a token, it will -first refill the buffer using -YY_INPUT -(see The Generated Scanner, below). This action is a special case -of the more general -yy_flush_buffer() -function, described below in the section Multiple Input Buffers. -
        -
        yyterminate() -can be used in lieu of a return statement in an action. It terminates -the scanner and returns a 0 to the scanner's caller, indicating "all done". -By default, -yyterminate() -is also called when an end-of-file is encountered. It is a macro and -may be redefined. -
        -

      THE GENERATED SCANNER

        - -The output of -flex -is the file -lex.yy.c, -which contains the scanning routine -yylex(), -a number of tables used by it for matching tokens, and a number -of auxiliary routines and macros. By default, -yylex() -is declared as follows: -
        -
        -


        int yylex() -
        { -
        ... various definitions and the actions in here ... -
        } -
        -


        -(If your environment supports function prototypes, then it will -be "int yylex( void )".) This definition may be changed by defining -the "YY_DECL" macro. For example, you could use: -
        -
        -


        #define YY_DECL float lexscan( a, b ) float a, b; -
        -


        -to give the scanning routine the name -lexscan, -returning a float, and taking two floats as arguments. Note that -if you give arguments to the scanning routine using a -K&R-style/non-prototyped function declaration, you must terminate -the definition with a semi-colon (;). - -

        -Whenever -yylex() -is called, it scans tokens from the global input file -yyin -(which defaults to stdin). It continues until it either reaches -an end-of-file (at which point it returns the value 0) or -one of its actions executes a -return -statement. - -

        -If the scanner reaches an end-of-file, subsequent calls are undefined -unless either -yyin -is pointed at a new input file (in which case scanning continues from -that file), or -yyrestart() -is called. -yyrestart() -takes one argument, a -FILE * -pointer (which can be nil, if you've set up -YY_INPUT -to scan from a source other than -yyin), -and initializes -yyin -for scanning from that file. Essentially there is no difference between -just assigning -yyin -to a new input file or using -yyrestart() -to do so; the latter is available for compatibility with previous versions -of -flex, -and because it can be used to switch input files in the middle of scanning. -It can also be used to throw away the current input buffer, by calling -it with an argument of -yyin; -but better is to use -YY_FLUSH_BUFFER -(see above). -Note that -yyrestart() -does -not -reset the start condition to -INITIAL -(see Start Conditions, below). - -

        -If -yylex() -stops scanning due to executing a -return -statement in one of the actions, the scanner may then be called again and it -will resume scanning where it left off. - -

        -By default (and for purposes of efficiency), the scanner uses -block-reads rather than simple -getc() -calls to read characters from -yyin. -The nature of how it gets its input can be controlled by defining the -YY_INPUT -macro. -YY_INPUT's calling sequence is "YY_INPUT(buf,result,max_size)". Its -action is to place up to -max_size -characters in the character array -buf -and return in the integer variable -result -either the -number of characters read or the constant YY_NULL (0 on Unix systems) -to indicate EOF. The default YY_INPUT reads from the -global file-pointer "yyin". - -

        -A sample definition of YY_INPUT (in the definitions -section of the input file): -

        -
        -


        %{ -
        #define YY_INPUT(buf,result,max_size) \ -
        { \ -
        int c = getchar(); \ -
        result = (c == EOF) ? YY_NULL : (buf[0] = c, 1); \ -
        } -
        %} -
        -


        -This definition will change the input processing to occur -one character at a time. - -

        -When the scanner receives an end-of-file indication from YY_INPUT, -it then checks the -yywrap() -function. If -yywrap() -returns false (zero), then it is assumed that the -function has gone ahead and set up -yyin -to point to another input file, and scanning continues. If it returns -true (non-zero), then the scanner terminates, returning 0 to its -caller. Note that in either case, the start condition remains unchanged; -it does -not -revert to -INITIAL. - -

        -If you do not supply your own version of -yywrap(), -then you must either use -%option noyywrap -(in which case the scanner behaves as though -yywrap() -returned 1), or you must link with --lfl -to obtain the default version of the routine, which always returns 1. - -

        -Three routines are available for scanning from in-memory buffers rather -than files: -yy_scan_string(), yy_scan_bytes(), -and -yy_scan_buffer(). -See the discussion of them below in the section Multiple Input Buffers. - -

        -The scanner writes its -ECHO -output to the -yyout -global (default, stdout), which may be redefined by the user simply -by assigning it to some other -FILE -pointer. - -

      START CONDITIONS

        - -flex -provides a mechanism for conditionally activating rules. Any rule -whose pattern is prefixed with "<sc>" will only be active when -the scanner is in the start condition named "sc". For example, -
        -
        -


        <STRING>[^"]* { /* eat up the string body ... */ -
        ... -
        } -
        -


        -will be active only when the scanner is in the "STRING" start -condition, and -
        -
        -


        <INITIAL,STRING,QUOTE>\. { /* handle an escape ... */ -
        ... -
        } -
        -


        -will be active only when the current start condition is -either "INITIAL", "STRING", or "QUOTE". - -

        -Start conditions -are declared in the definitions (first) section of the input -using unindented lines beginning with either -%s -or -%x -followed by a list of names. -The former declares -inclusive -start conditions, the latter -exclusive -start conditions. A start condition is activated using the -BEGIN -action. Until the next -BEGIN -action is executed, rules with the given start -condition will be active and -rules with other start conditions will be inactive. -If the start condition is -inclusive, -then rules with no start conditions at all will also be active. -If it is -exclusive, -then -only -rules qualified with the start condition will be active. -A set of rules contingent on the same exclusive start condition -describe a scanner which is independent of any of the other rules in the -flex -input. Because of this, -exclusive start conditions make it easy to specify "mini-scanners" -which scan portions of the input that are syntactically different -from the rest (e.g., comments). - -

        -If the distinction between inclusive and exclusive start conditions -is still a little vague, here's a simple example illustrating the -connection between the two. The set of rules: -

        -
        -


        %s example -
        %% -
        -


        <example>foo do_something(); -
        -


        bar something_else(); -
        -


        -is equivalent to -
        -
        -


        %x example -
        %% -
        -


        <example>foo do_something(); -
        -


        <INITIAL,example>bar something_else(); -
        -


        -Without the -<INITIAL,example> -qualifier, the -bar -pattern in the second example wouldn't be active (i.e., couldn't match) -when in start condition -example. -If we just used -<example> -to qualify -bar, -though, then it would only be active in -example -and not in -INITIAL, -while in the first example it's active in both, because in the first -example the -example -startion condition is an -inclusive -(%s) -start condition. - -

        -Also note that the special start-condition specifier -<*> -matches every start condition. Thus, the above example could also -have been written; -

        -
        -


        %x example -
        %% -
        -


        <example>foo do_something(); -
        -


        <*>bar something_else(); -
        -


        - -

        -The default rule (to -ECHO -any unmatched character) remains active in start conditions. It -is equivalent to: -

        -
        -


        <*>.|\n ECHO; -
        -


        - -

        -BEGIN(0) -returns to the original state where only the rules with -no start conditions are active. This state can also be -referred to as the start-condition "INITIAL", so -BEGIN(INITIAL) -is equivalent to -BEGIN(0). -(The parentheses around the start condition name are not required but -are considered good style.) - -

        -BEGIN -actions can also be given as indented code at the beginning -of the rules section. For example, the following will cause -the scanner to enter the "SPECIAL" start condition whenever -yylex() -is called and the global variable -enter_special -is true: -

        -
        -


        int enter_special; -
        -


        %x SPECIAL -
        %% -
        if ( enter_special ) -
        BEGIN(SPECIAL); -
        -


        <SPECIAL>blahblahblah -
        ...more rules follow... -
        -


        - -

        -To illustrate the uses of start conditions, -here is a scanner which provides two different interpretations -of a string like "123.456". By default it will treat it as -as three tokens, the integer "123", a dot ('.'), and the integer "456". -But if the string is preceded earlier in the line by the string -"expect-floats" -it will treat it as a single token, the floating-point number -123.456: -

        -
        -


        %{ -
        #include <math.h> -
        %} -
        %s expect -
        -


        %% -
        expect-floats BEGIN(expect); -
        -


        <expect>[0-9]+"."[0-9]+ { -
        printf( "found a float, = %f\n", -
        atof( yytext ) ); -
        } -
        <expect>\n { -
        /* that's the end of the line, so -
        * we need another "expect-number" -
        * before we'll recognize any more -
        * numbers -
        */ -
        BEGIN(INITIAL); -
        } -
        -


        [0-9]+ { -
        printf( "found an integer, = %d\n", -
        atoi( yytext ) ); -
        } -
        -


        "." printf( "found a dot\n" ); -
        -


        -Here is a scanner which recognizes (and discards) C comments while -maintaining a count of the current input line. -
        -
        -


        %x comment -
        %% -
        int line_num = 1; -
        -


        "/*" BEGIN(comment); -
        -


        <comment>[^*\n]* /* eat anything that's not a '*' */ -
        <comment>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */ -
        <comment>\n ++line_num; -
        <comment>"*"+"/" BEGIN(INITIAL); -
        -


        -This scanner goes to a bit of trouble to match as much -text as possible with each rule. In general, when attempting to write -a high-speed scanner try to match as much possible in each rule, as -it's a big win. - -

        -Note that start-conditions names are really integer values and -can be stored as such. Thus, the above could be extended in the -following fashion: -

        -
        -


        %x comment foo -
        %% -
        int line_num = 1; -
        int comment_caller; -
        -


        "/*" { -
        comment_caller = INITIAL; -
        BEGIN(comment); -
        } -
        -


        ... -
        -


        <foo>"/*" { -
        comment_caller = foo; -
        BEGIN(comment); -
        } -
        -


        <comment>[^*\n]* /* eat anything that's not a '*' */ -
        <comment>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */ -
        <comment>\n ++line_num; -
        <comment>"*"+"/" BEGIN(comment_caller); -
        -


        -Furthermore, you can access the current start condition using -the integer-valued -YY_START -macro. For example, the above assignments to -comment_caller -could instead be written -
        -
        -


        comment_caller = YY_START; -
        -


        -Flex provides -YYSTATE -as an alias for -YY_START -(since that is what's used by AT&T -lex). - -

        -Note that start conditions do not have their own name-space; %s's and %x's -declare names in the same fashion as #define's. - -

        -Finally, here's an example of how to match C-style quoted strings using -exclusive start conditions, including expanded escape sequences (but -not including checking for a string that's too long): -

        -
        -


        %x str -
        -


        %% -
        char string_buf[MAX_STR_CONST]; -
        char *string_buf_ptr; -
        -


        -


        \" string_buf_ptr = string_buf; BEGIN(str); -
        -


        <str>\" { /* saw closing quote - all done */ -
        BEGIN(INITIAL); -
        *string_buf_ptr = '\0'; -
        /* return string constant token type and -
        * value to parser -
        */ -
        } -
        -


        <str>\n { -
        /* error - unterminated string constant */ -
        /* generate error message */ -
        } -
        -


        <str>\\[0-7]{1,3} { -
        /* octal escape sequence */ -
        int result; -
        -


        (void) sscanf( yytext + 1, "%o", &result ); -
        -


        if ( result > 0xff ) -
        /* error, constant is out-of-bounds */ -
        -


        *string_buf_ptr++ = result; -
        } -
        -


        <str>\\[0-9]+ { -
        /* generate error - bad escape sequence; something -
        * like '\48' or '\0777777' -
        */ -
        } -
        -


        <str>\\n *string_buf_ptr++ = '\n'; -
        <str>\\t *string_buf_ptr++ = '\t'; -
        <str>\\r *string_buf_ptr++ = '\r'; -
        <str>\\b *string_buf_ptr++ = '\b'; -
        <str>\\f *string_buf_ptr++ = '\f'; -
        -


        <str>\\(.|\n) *string_buf_ptr++ = yytext[1]; -
        -


        <str>[^\\\n\"]+ { -
        char *yptr = yytext; -
        -


        while ( *yptr ) -
        *string_buf_ptr++ = *yptr++; -
        } -
        -


        - -

        -Often, such as in some of the examples above, you wind up writing a -whole bunch of rules all preceded by the same start condition(s). Flex -makes this a little easier and cleaner by introducing a notion of -start condition -scope. -A start condition scope is begun with: -

        -
        -


        <SCs>{ -
        -


        -where -SCs -is a list of one or more start conditions. Inside the start condition -scope, every rule automatically has the prefix -<SCs> -applied to it, until a -'}' -which matches the initial -'{'. -So, for example, -
        -
        -


        <ESC>{ -
        "\\n" return '\n'; -
        "\\r" return '\r'; -
        "\\f" return '\f'; -
        "\\0" return '\0'; -
        } -
        -


        -is equivalent to: -
        -
        -


        <ESC>"\\n" return '\n'; -
        <ESC>"\\r" return '\r'; -
        <ESC>"\\f" return '\f'; -
        <ESC>"\\0" return '\0'; -
        -


        -Start condition scopes may be nested. - -

        -Three routines are available for manipulating stacks of start conditions: -

        void yy_push_state(int new_state) -
        pushes the current start condition onto the top of the start condition -stack and switches to -new_state -as though you had used -BEGIN new_state -(recall that start condition names are also integers). -
        void yy_pop_state() -
        pops the top of the stack and switches to it via -BEGIN. -
        int yy_top_state() -
        returns the top of the stack without altering the stack's contents. -
        -

        -The start condition stack grows dynamically and so has no built-in -size limitation. If memory is exhausted, program execution aborts. - -

        -To use start condition stacks, your scanner must include a -%option stack -directive (see Options below). - -

      MULTIPLE INPUT BUFFERS

        - -Some scanners (such as those which support "include" files) -require reading from several input streams. As -flex -scanners do a large amount of buffering, one cannot control -where the next input will be read from by simply writing a -YY_INPUT -which is sensitive to the scanning context. -YY_INPUT -is only called when the scanner reaches the end of its buffer, which -may be a long time after scanning a statement such as an "include" -which requires switching the input source. - -

        -To negotiate these sorts of problems, -flex -provides a mechanism for creating and switching between multiple -input buffers. An input buffer is created by using: -

        -
        -


        YY_BUFFER_STATE yy_create_buffer( FILE *file, int size ) -
        -


        -which takes a -FILE -pointer and a size and creates a buffer associated with the given -file and large enough to hold -size -characters (when in doubt, use -YY_BUF_SIZE -for the size). It returns a -YY_BUFFER_STATE -handle, which may then be passed to other routines (see below). The -YY_BUFFER_STATE -type is a pointer to an opaque -struct yy_buffer_state -structure, so you may safely initialize YY_BUFFER_STATE variables to -((YY_BUFFER_STATE) 0) -if you wish, and also refer to the opaque structure in order to -correctly declare input buffers in source files other than that -of your scanner. Note that the -FILE -pointer in the call to -yy_create_buffer -is only used as the value of -yyin -seen by -YY_INPUT; -if you redefine -YY_INPUT -so it no longer uses -yyin, -then you can safely pass a nil -FILE -pointer to -yy_create_buffer. -You select a particular buffer to scan from using: -
        -
        -


        void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer ) -
        -


        -switches the scanner's input buffer so subsequent tokens will -come from -new_buffer. -Note that -yy_switch_to_buffer() -may be used by yywrap() to set things up for continued scanning, instead -of opening a new file and pointing -yyin -at it. Note also that switching input sources via either -yy_switch_to_buffer() -or -yywrap() -does -not -change the start condition. -
        -
        -


        void yy_delete_buffer( YY_BUFFER_STATE buffer ) -
        -


        -is used to reclaim the storage associated with a buffer. -You can also clear the current contents of a buffer using: -
        -
        -


        void yy_flush_buffer( YY_BUFFER_STATE buffer ) -
        -


        -This function discards the buffer's contents, -so the next time the scanner attempts to match a token from the -buffer, it will first fill the buffer anew using -YY_INPUT. - -

        -yy_new_buffer() -is an alias for -yy_create_buffer(), -provided for compatibility with the C++ use of -new -and -delete -for creating and destroying dynamic objects. - -

        -Finally, the -YY_CURRENT_BUFFER -macro returns a -YY_BUFFER_STATE -handle to the current buffer. - -

        -Here is an example of using these features for writing a scanner -which expands include files (the -<<EOF>> -feature is discussed below): -

        -
        -


        /* the "incl" state is used for picking up the name -
        * of an include file -
        */ -
        %x incl -
        -


        %{ -
        #define MAX_INCLUDE_DEPTH 10 -
        YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH]; -
        int include_stack_ptr = 0; -
        %} -
        -


        %% -
        include BEGIN(incl); -
        -


        [a-z]+ ECHO; -
        [^a-z\n]*\n? ECHO; -
        -


        <incl>[ \t]* /* eat the whitespace */ -
        <incl>[^ \t\n]+ { /* got the include file name */ -
        if ( include_stack_ptr >= MAX_INCLUDE_DEPTH ) -
        { -
        fprintf( stderr, "Includes nested too deeply" ); -
        exit( 1 ); -
        } -
        -


        include_stack[include_stack_ptr++] = -
        YY_CURRENT_BUFFER; -
        -


        yyin = fopen( yytext, "r" ); -
        -


        if ( ! yyin ) -
        error( ... ); -
        -


        yy_switch_to_buffer( -
        yy_create_buffer( yyin, YY_BUF_SIZE ) ); -
        -


        BEGIN(INITIAL); -
        } -
        -


        <<EOF>> { -
        if ( --include_stack_ptr < 0 ) -
        { -
        yyterminate(); -
        } -
        -


        else -
        { -
        yy_delete_buffer( YY_CURRENT_BUFFER ); -
        yy_switch_to_buffer( -
        include_stack[include_stack_ptr] ); -
        } -
        } -
        -


        -Three routines are available for setting up input buffers for -scanning in-memory strings instead of files. All of them create -a new input buffer for scanning the string, and return a corresponding -YY_BUFFER_STATE -handle (which you should delete with -yy_delete_buffer() -when done with it). They also switch to the new buffer using -yy_switch_to_buffer(), -so the next call to -yylex() -will start scanning the string. -

        yy_scan_string(const char *str) -
        scans a NUL-terminated string. -
        yy_scan_bytes(const char *bytes, int len) -
        scans -len -bytes (including possibly NUL's) -starting at location -bytes. -
        -

        -Note that both of these functions create and scan a -copy -of the string or bytes. (This may be desirable, since -yylex() -modifies the contents of the buffer it is scanning.) You can avoid the -copy by using: -

        yy_scan_buffer(char *base, yy_size_t size) -
        which scans in place the buffer starting at -base, -consisting of -size -bytes, the last two bytes of which -must -be -YY_END_OF_BUFFER_CHAR -(ASCII NUL). -These last two bytes are not scanned; thus, scanning -consists of -base[0] -through -base[size-2], -inclusive. -
        If you fail to set up -base -in this manner (i.e., forget the final two -YY_END_OF_BUFFER_CHAR -bytes), then -yy_scan_buffer() -returns a nil pointer instead of creating a new input buffer. -
        The type -yy_size_t -is an integral type to which you can cast an integer expression -reflecting the size of the buffer. -
        -

      END-OF-FILE RULES

        - -The special rule "<<EOF>>" indicates -actions which are to be taken when an end-of-file is -encountered and yywrap() returns non-zero (i.e., indicates -no further files to process). The action must finish -by doing one of four things: -

        -
        assigning -yyin -to a new input file (in previous versions of flex, after doing the -assignment you had to call the special action -YY_NEW_FILE; -this is no longer necessary); -
        -
        executing a -return -statement; -
        -
        executing the special -yyterminate() -action; -
        -
        or, switching to a new buffer using -yy_switch_to_buffer() -as shown in the example above. -
        -

        -<<EOF>> rules may not be used with other -patterns; they may only be qualified with a list of start -conditions. If an unqualified <<EOF>> rule is given, it -applies to -all -start conditions which do not already have <<EOF>> actions. To -specify an <<EOF>> rule for only the initial start condition, use -

        -
        -


        <INITIAL><<EOF>> -
        -


        - -

        -These rules are useful for catching things like unclosed comments. -An example: -

        -
        -


        %x quote -
        %% -
        -


        ...other rules for dealing with quotes... -
        -


        <quote><<EOF>> { -
        error( "unterminated quote" ); -
        yyterminate(); -
        } -
        <<EOF>> { -
        if ( *++filelist ) -
        yyin = fopen( *filelist, "r" ); -
        else -
        yyterminate(); -
        } -
        -


        - -

      MISCELLANEOUS MACROS

        - -The macro -YY_USER_ACTION -can be defined to provide an action -which is always executed prior to the matched rule's action. For example, -it could be #define'd to call a routine to convert yytext to lower-case. -When -YY_USER_ACTION -is invoked, the variable -yy_act -gives the number of the matched rule (rules are numbered starting with 1). -Suppose you want to profile how often each of your rules is matched. The -following would do the trick: -
        -
        -


        #define YY_USER_ACTION ++ctr[yy_act] -
        -


        -where -ctr -is an array to hold the counts for the different rules. Note that -the macro -YY_NUM_RULES -gives the total number of rules (including the default rule, even if -you use --s), -so a correct declaration for -ctr -is: -
        -
        -


        int ctr[YY_NUM_RULES]; -
        -


        - -

        -The macro -YY_USER_INIT -may be defined to provide an action which is always executed before -the first scan (and before the scanner's internal initializations are done). -For example, it could be used to call a routine to read -in a data table or open a logging file. - -

        -The macro -yy_set_interactive(is_interactive) -can be used to control whether the current buffer is considered -interactive. -An interactive buffer is processed more slowly, -but must be used when the scanner's input source is indeed -interactive to avoid problems due to waiting to fill buffers -(see the discussion of the --I -flag below). A non-zero value -in the macro invocation marks the buffer as interactive, a zero -value as non-interactive. Note that use of this macro overrides -%option always-interactive -or -%option never-interactive -(see Options below). -yy_set_interactive() -must be invoked prior to beginning to scan the buffer that is -(or is not) to be considered interactive. - -

        -The macro -yy_set_bol(at_bol) -can be used to control whether the current buffer's scanning -context for the next token match is done as though at the -beginning of a line. A non-zero macro argument makes rules anchored with -'^' active, while a zero argument makes '^' rules inactive. - -

        -The macro -YY_AT_BOL() -returns true if the next token scanned from the current buffer -will have '^' rules active, false otherwise. - -

        -In the generated scanner, the actions are all gathered in one large -switch statement and separated using -YY_BREAK, -which may be redefined. By default, it is simply a "break", to separate -each rule's action from the following rule's. -Redefining -YY_BREAK -allows, for example, C++ users to -#define YY_BREAK to do nothing (while being very careful that every -rule ends with a "break" or a "return"!) to avoid suffering from -unreachable statement warnings where because a rule's action ends with -"return", the -YY_BREAK -is inaccessible. - -

      VALUES AVAILABLE TO THE USER

        - -This section summarizes the various values available to the user -in the rule actions. -

        -
        char *yytext -holds the text of the current token. It may be modified but not lengthened -(you cannot append characters to the end). -
        If the special directive -%array -appears in the first section of the scanner description, then -yytext -is instead declared -char yytext[YYLMAX], -where -YYLMAX -is a macro definition that you can redefine in the first section -if you don't like the default value (generally 8KB). Using -%array -results in somewhat slower scanners, but the value of -yytext -becomes immune to calls to -input() -and -unput(), -which potentially destroy its value when -yytext -is a character pointer. The opposite of -%array -is -%pointer, -which is the default. -
        You cannot use -%array -when generating C++ scanner classes -(the --+ -flag). -
        -
        int yyleng -holds the length of the current token. -
        -
        FILE *yyin -is the file which by default -flex -reads from. It may be redefined but doing so only makes sense before -scanning begins or after an EOF has been encountered. Changing it in -the midst of scanning will have unexpected results since -flex -buffers its input; use -yyrestart() -instead. -Once scanning terminates because an end-of-file -has been seen, you can assign -yyin -at the new input file and then call the scanner again to continue scanning. -
        -
        void yyrestart( FILE *new_file ) -may be called to point -yyin -at the new input file. The switch-over to the new file is immediate -(any previously buffered-up input is lost). Note that calling -yyrestart() -with -yyin -as an argument thus throws away the current input buffer and continues -scanning the same input file. -
        -
        FILE *yyout -is the file to which -ECHO -actions are done. It can be reassigned by the user. -
        -
        YY_CURRENT_BUFFER -returns a -YY_BUFFER_STATE -handle to the current buffer. -
        -
        YY_START -returns an integer value corresponding to the current start -condition. You can subsequently use this value with -BEGIN -to return to that start condition. -
        -

      INTERFACING WITH YACC

        - -One of the main uses of -flex -is as a companion to the -yacc -parser-generator. -yacc -parsers expect to call a routine named -yylex() -to find the next input token. The routine is supposed to -return the type of the next token as well as putting any associated -value in the global -yylval. -To use -flex -with -yacc, -one specifies the --d -option to -yacc -to instruct it to generate the file -y.tab.h -containing definitions of all the -%tokens -appearing in the -yacc -input. This file is then included in the -flex -scanner. For example, if one of the tokens is "TOK_NUMBER", -part of the scanner might look like: -
        -
        -


        %{ -
        #include "y.tab.h" -
        %} -
        -


        %% -
        -


        [0-9]+ yylval = atoi( yytext ); return TOK_NUMBER; -
        -


        - -

      OPTIONS

        - -flex -has the following options: -

        -b -
        Generate backing-up information to -lex.backup. -This is a list of scanner states which require backing up -and the input characters on which they do so. By adding rules one -can remove backing-up states. If -all -backing-up states are eliminated and --Cf -or --CF -is used, the generated scanner will run faster (see the --p -flag). Only users who wish to squeeze every last cycle out of their -scanners need worry about this option. (See the section on Performance -Considerations below.) -
        -c -
        is a do-nothing, deprecated option included for POSIX compliance. -
        -d -
        makes the generated scanner run in -debug -mode. Whenever a pattern is recognized and the global -yy_flex_debug -is non-zero (which is the default), -the scanner will write to -stderr -a line of the form: -
        -
        -


        --accepting rule at line 53 ("the matched text") -
        -


        -The line number refers to the location of the rule in the file -defining the scanner (i.e., the file that was fed to flex). Messages -are also generated when the scanner backs up, accepts the -default rule, reaches the end of its input buffer (or encounters -a NUL; at this point, the two look the same as far as the scanner's concerned), -or reaches an end-of-file. -
        -f -
        specifies -fast scanner. -No table compression is done and stdio is bypassed. -The result is large but fast. This option is equivalent to --Cfr -(see below). -
        -h -
        generates a "help" summary of -flex's -options to -stdout -and then exits. --? -and ---help -are synonyms for --h. -
        -i -
        instructs -flex -to generate a -case-insensitive -scanner. The case of letters given in the -flex -input patterns will -be ignored, and tokens in the input will be matched regardless of case. The -matched text given in -yytext -will have the preserved case (i.e., it will not be folded). -
        -l -
        turns on maximum compatibility with the original AT&T -lex -implementation. Note that this does not mean -full -compatibility. Use of this option costs a considerable amount of -performance, and it cannot be used with the --+, -f, -F, -Cf, -or --CF -options. For details on the compatibilities it provides, see the section -"Incompatibilities With Lex And POSIX" below. This option also results -in the name -YY_FLEX_LEX_COMPAT -being #define'd in the generated scanner. -
        -n -
        is another do-nothing, deprecated option included only for -POSIX compliance. -
        -p -
        generates a performance report to stderr. The report -consists of comments regarding features of the -flex -input file which will cause a serious loss of performance in the resulting -scanner. If you give the flag twice, you will also get comments regarding -features that lead to minor performance losses. -
        Note that the use of -REJECT, -%option yylineno, -and variable trailing context (see the Deficiencies / Bugs section below) -entails a substantial performance penalty; use of -yymore(), -the -^ -operator, -and the --I -flag entail minor performance penalties. -
        -s -
        causes the -default rule -(that unmatched scanner input is echoed to -stdout) -to be suppressed. If the scanner encounters input that does not -match any of its rules, it aborts with an error. This option is -useful for finding holes in a scanner's rule set. -
        -t -
        instructs -flex -to write the scanner it generates to standard output instead -of -lex.yy.c. -
        -v -
        specifies that -flex -should write to -stderr -a summary of statistics regarding the scanner it generates. -Most of the statistics are meaningless to the casual -flex -user, but the first line identifies the version of -flex -(same as reported by --V), -and the next line the flags used when generating the scanner, including -those that are on by default. -
        -w -
        suppresses warning messages. -
        -B -
        instructs -flex -to generate a -batch -scanner, the opposite of -interactive -scanners generated by --I -(see below). In general, you use --B -when you are -certain -that your scanner will never be used interactively, and you want to -squeeze a -little -more performance out of it. If your goal is instead to squeeze out a -lot -more performance, you should be using the --Cf -or --CF -options (discussed below), which turn on --B -automatically anyway. -
        -F -
        specifies that the -fast -scanner table representation should be used (and stdio -bypassed). This representation is -about as fast as the full table representation -(-f), -and for some sets of patterns will be considerably smaller (and for -others, larger). In general, if the pattern set contains both "keywords" -and a catch-all, "identifier" rule, such as in the set: -
        -
        -


        "case" return TOK_CASE; -
        "switch" return TOK_SWITCH; -
        ... -
        "default" return TOK_DEFAULT; -
        [a-z]+ return TOK_ID; -
        -


        -then you're better off using the full table representation. If only -the "identifier" rule is present and you then use a hash table or some such -to detect the keywords, you're better off using --F. -
        This option is equivalent to --CFr -(see below). It cannot be used with --+. -
        -I -
        instructs -flex -to generate an -interactive -scanner. An interactive scanner is one that only looks ahead to decide -what token has been matched if it absolutely must. It turns out that -always looking one extra character ahead, even if the scanner has already -seen enough text to disambiguate the current token, is a bit faster than -only looking ahead when necessary. But scanners that always look ahead -give dreadful interactive performance; for example, when a user types -a newline, it is not recognized as a newline token until they enter -another -token, which often means typing in another whole line. -
        Flex -scanners default to -interactive -unless you use the --Cf -or --CF -table-compression options (see below). That's because if you're looking -for high-performance you should be using one of these options, so if you -didn't, -flex -assumes you'd rather trade off a bit of run-time performance for intuitive -interactive behavior. Note also that you -cannot -use --I -in conjunction with --Cf -or --CF. -Thus, this option is not really needed; it is on by default for all those -cases in which it is allowed. -
        You can force a scanner to -not -be interactive by using --B -(see above). -
        -L -
        instructs -flex -not to generate -#line -directives. Without this option, -flex -peppers the generated scanner -with #line directives so error messages in the actions will be correctly -located with respect to either the original -flex -input file (if the errors are due to code in the input file), or -lex.yy.c -(if the errors are -flex's -fault -- you should report these sorts of errors to the email address -given below). -
        -T -
        makes -flex -run in -trace -mode. It will generate a lot of messages to -stderr -concerning -the form of the input and the resultant non-deterministic and deterministic -finite automata. This option is mostly for use in maintaining -flex. -
        -V -
        prints the version number to -stdout -and exits. ---version -is a synonym for --V. -
        -7 -
        instructs -flex -to generate a 7-bit scanner, i.e., one which can only recognized 7-bit -characters in its input. The advantage of using --7 -is that the scanner's tables can be up to half the size of those generated -using the --8 -option (see below). The disadvantage is that such scanners often hang -or crash if their input contains an 8-bit character. -
        Note, however, that unless you generate your scanner using the --Cf -or --CF -table compression options, use of --7 -will save only a small amount of table space, and make your scanner -considerably less portable. -Flex's -default behavior is to generate an 8-bit scanner unless you use the --Cf -or --CF, -in which case -flex -defaults to generating 7-bit scanners unless your site was always -configured to generate 8-bit scanners (as will often be the case -with non-USA sites). You can tell whether flex generated a 7-bit -or an 8-bit scanner by inspecting the flag summary in the --v -output as described above. -
        Note that if you use --Cfe -or --CFe -(those table compression options, but also using equivalence classes as -discussed see below), flex still defaults to generating an 8-bit -scanner, since usually with these compression options full 8-bit tables -are not much more expensive than 7-bit tables. -
        -8 -
        instructs -flex -to generate an 8-bit scanner, i.e., one which can recognize 8-bit -characters. This flag is only needed for scanners generated using --Cf -or --CF, -as otherwise flex defaults to generating an 8-bit scanner anyway. -
        See the discussion of --7 -above for flex's default behavior and the tradeoffs between 7-bit -and 8-bit scanners. -
        -+ -
        specifies that you want flex to generate a C++ -scanner class. See the section on Generating C++ Scanners below for -details. -
        -C[aefFmr] -
        controls the degree of table compression and, more generally, trade-offs -between small scanners and fast scanners. -
        -Ca -("align") instructs flex to trade off larger tables in the -generated scanner for faster performance because the elements of -the tables are better aligned for memory access and computation. On some -RISC architectures, fetching and manipulating longwords is more efficient -than with smaller-sized units such as shortwords. This option can -double the size of the tables used by your scanner. -
        -Ce -directs -flex -to construct -equivalence classes, -i.e., sets of characters -which have identical lexical properties (for example, if the only -appearance of digits in the -flex -input is in the character class -"[0-9]" then the digits '0', '1', ..., '9' will all be put -in the same equivalence class). Equivalence classes usually give -dramatic reductions in the final table/object file sizes (typically -a factor of 2-5) and are pretty cheap performance-wise (one array -look-up per character scanned). -
        -Cf -specifies that the -full -scanner tables should be generated - -flex -should not compress the -tables by taking advantages of similar transition functions for -different states. -
        -CF -specifies that the alternate fast scanner representation (described -above under the --F -flag) -should be used. This option cannot be used with --+. -
        -Cm -directs -flex -to construct -meta-equivalence classes, -which are sets of equivalence classes (or characters, if equivalence -classes are not being used) that are commonly used together. Meta-equivalence -classes are often a big win when using compressed tables, but they -have a moderate performance impact (one or two "if" tests and one -array look-up per character scanned). -
        -Cr -causes the generated scanner to -bypass -use of the standard I/O library (stdio) for input. Instead of calling -fread() -or -getc(), -the scanner will use the -read() -system call, resulting in a performance gain which varies from system -to system, but in general is probably negligible unless you are also using --Cf -or --CF. -Using --Cr -can cause strange behavior if, for example, you read from -yyin -using stdio prior to calling the scanner (because the scanner will miss -whatever text your previous reads left in the stdio input buffer). -
        -Cr -has no effect if you define -YY_INPUT -(see The Generated Scanner above). -
        A lone --C -specifies that the scanner tables should be compressed but neither -equivalence classes nor meta-equivalence classes should be used. -
        The options --Cf -or --CF -and --Cm -do not make sense together - there is no opportunity for meta-equivalence -classes if the table is not being compressed. Otherwise the options -may be freely mixed, and are cumulative. -
        The default setting is --Cem, -which specifies that -flex -should generate equivalence classes -and meta-equivalence classes. This setting provides the highest -degree of table compression. You can trade off -faster-executing scanners at the cost of larger tables with -the following generally being true: -
        -
        -


        slowest & smallest -
        -Cem -
        -Cm -
        -Ce -
        -C -
        -C{f,F}e -
        -C{f,F} -
        -C{f,F}a -
        fastest & largest -
        -


        -Note that scanners with the smallest tables are usually generated and -compiled the quickest, so -during development you will usually want to use the default, maximal -compression. -
        -Cfe -is often a good compromise between speed and size for production -scanners. -
        -ooutput -
        directs flex to write the scanner to the file -output -instead of -lex.yy.c. -If you combine --o -with the --t -option, then the scanner is written to -stdout -but its -#line -directives (see the -\-L -option above) refer to the file -output. -
        -Pprefix -
        changes the default -yy -prefix used by -flex -for all globally-visible variable and function names to instead be -prefix. -For example, --Pfoo -changes the name of -yytext -to -footext. -It also changes the name of the default output file from -lex.yy.c -to -lex.foo.c. -Here are all of the names affected: -
        -
        -


        yy_create_buffer -
        yy_delete_buffer -
        yy_flex_debug -
        yy_init_buffer -
        yy_flush_buffer -
        yy_load_buffer_state -
        yy_switch_to_buffer -
        yyin -
        yyleng -
        yylex -
        yylineno -
        yyout -
        yyrestart -
        yytext -
        yywrap -
        -


        -(If you are using a C++ scanner, then only -yywrap -and -yyFlexLexer -are affected.) -Within your scanner itself, you can still refer to the global variables -and functions using either version of their name; but externally, they -have the modified name. -
        This option lets you easily link together multiple -flex -programs into the same executable. Note, though, that using this -option also renames -yywrap(), -so you now -must -either -provide your own (appropriately-named) version of the routine for your -scanner, or use -%option noyywrap, -as linking with --lfl -no longer provides one for you by default. -
        -Sskeleton_file -
        overrides the default skeleton file from which -flex -constructs its scanners. You'll never need this option unless you are doing -flex -maintenance or development. -
        -

        -flex -also provides a mechanism for controlling options within the -scanner specification itself, rather than from the flex command-line. -This is done by including -%option -directives in the first section of the scanner specification. -You can specify multiple options with a single -%option -directive, and multiple directives in the first section of your flex input -file. Most -options are given simply as names, optionally preceded by the -word "no" (with no intervening whitespace) to negate their meaning. -A number are equivalent to flex flags or their negation: -

        -
        -


        7bit -7 option -
        8bit -8 option -
        align -Ca option -
        backup -b option -
        batch -B option -
        c++ -+ option -
        -


        caseful or -
        case-sensitive opposite of -i (default) -
        -


        case-insensitive or -
        caseless -i option -
        -


        debug -d option -
        default opposite of -s option -
        ecs -Ce option -
        fast -F option -
        full -f option -
        interactive -I option -
        lex-compat -l option -
        meta-ecs -Cm option -
        perf-report -p option -
        read -Cr option -
        stdout -t option -
        verbose -v option -
        warn opposite of -w option -
        (use "%option nowarn" for -w) -
        -


        array equivalent to "%array" -
        pointer equivalent to "%pointer" (default) -
        -


        -Some -%option's -provide features otherwise not available: -

        always-interactive -
        instructs flex to generate a scanner which always considers its input -"interactive". Normally, on each new input file the scanner calls -isatty() -in an attempt to determine whether -the scanner's input source is interactive and thus should be read a -character at a time. When this option is used, however, then no -such call is made. -
        main -
        directs flex to provide a default -main() -program for the scanner, which simply calls -yylex(). -This option implies -noyywrap -(see below). -
        never-interactive -
        instructs flex to generate a scanner which never considers its input -"interactive" (again, no call made to -isatty()). -This is the opposite of -always-interactive. -
        stack -
        enables the use of start condition stacks (see Start Conditions above). -
        stdinit -
        if unset (i.e., -%option nostdinit) -initializes -yyin -and -yyout -to nil -FILE -pointers, instead of -stdin -and -stdout. -
        yylineno -
        directs -flex -to generate a scanner that maintains the number of the current line -read from its input in the global variable -yylineno. -This option is implied by -%option lex-compat. -
        yywrap -
        if unset (i.e., -%option noyywrap), -makes the scanner not call -yywrap() -upon an end-of-file, but simply assume that there are no more -files to scan (until the user points -yyin -at a new file and calls -yylex() -again). -
        -

        -flex -scans your rule actions to determine whether you use the -REJECT -or -yymore() -features. The -reject -and -yymore -options are available to override its decision as to whether you use the -options, either by setting them (e.g., -%option reject) -to indicate the feature is indeed used, or -unsetting them to indicate it actually is not used -(e.g., -%option noyymore). - -

        -Three options take string-delimited values, offset with '=': -

        -
        -


        %option outfile="ABC" -
        -


        -is equivalent to --oABC, -and -
        -
        -


        %option prefix="XYZ" -
        -


        -is equivalent to --PXYZ. -Finally, -
        -
        -


        %option yyclass="foo" -
        -


        -only applies when generating a C++ scanner ( --+ -option). It informs -flex -that you have derived -foo -as a subclass of -yyFlexLexer, -so -flex -will place your actions in the member function -foo::yylex() -instead of -yyFlexLexer::yylex(). -It also generates a -yyFlexLexer::yylex() -member function that emits a run-time error (by invoking -yyFlexLexer::LexerError()) -if called. -See Generating C++ Scanners, below, for additional information. - -

        -A number of options are available for lint purists who want to suppress -the appearance of unneeded routines in the generated scanner. Each of the -following, if unset, results in the corresponding routine not appearing in -the generated scanner: -

        -
        -


        input, unput -
        yy_push_state, yy_pop_state, yy_top_state -
        yy_scan_buffer, yy_scan_bytes, yy_scan_string -
        -


        -(though -yy_push_state() -and friends won't appear anyway unless you use -%option stack). - -

      PERFORMANCE CONSIDERATIONS

        - -The main design goal of -flex -is that it generate high-performance scanners. It has been optimized -for dealing well with large sets of rules. Aside from the effects on -scanner speed of the table compression --C -options outlined above, -there are a number of options/actions which degrade performance. These -are, from most expensive to least: -
        -
        -


        REJECT -
        %option yylineno -
        arbitrary trailing context -
        -


        pattern sets that require backing up -
        %array -
        %option interactive -
        %option always-interactive -
        -


        '^' beginning-of-line operator -
        yymore() -
        -


        -with the first three all being quite expensive and the last two -being quite cheap. Note also that -unput() -is implemented as a routine call that potentially does quite a bit of -work, while -yyless() -is a quite-cheap macro; so if just putting back some excess text you -scanned, use -yyless(). - -

        -REJECT -should be avoided at all costs when performance is important. -It is a particularly expensive option. - -

        -Getting rid of backing up is messy and often may be an enormous -amount of work for a complicated scanner. In principal, one begins -by using the --b -flag to generate a -lex.backup -file. For example, on the input -

        -
        -


        %% -
        foo return TOK_KEYWORD; -
        foobar return TOK_KEYWORD; -
        -


        -the file looks like: -
        -
        -


        State #6 is non-accepting - -
        associated rule line numbers: -
        2 3 -
        out-transitions: [ o ] -
        jam-transitions: EOF [ \001-n p-\177 ] -
        -


        State #8 is non-accepting - -
        associated rule line numbers: -
        3 -
        out-transitions: [ a ] -
        jam-transitions: EOF [ \001-` b-\177 ] -
        -


        State #9 is non-accepting - -
        associated rule line numbers: -
        3 -
        out-transitions: [ r ] -
        jam-transitions: EOF [ \001-q s-\177 ] -
        -


        Compressed tables always back up. -
        -


        -The first few lines tell us that there's a scanner state in -which it can make a transition on an 'o' but not on any other -character, and that in that state the currently scanned text does not match -any rule. The state occurs when trying to match the rules found -at lines 2 and 3 in the input file. -If the scanner is in that state and then reads -something other than an 'o', it will have to back up to find -a rule which is matched. With -a bit of headscratching one can see that this must be the -state it's in when it has seen "fo". When this has happened, -if anything other than another 'o' is seen, the scanner will -have to back up to simply match the 'f' (by the default rule). - -

        -The comment regarding State #8 indicates there's a problem -when "foob" has been scanned. Indeed, on any character other -than an 'a', the scanner will have to back up to accept "foo". -Similarly, the comment for State #9 concerns when "fooba" has -been scanned and an 'r' does not follow. - -

        -The final comment reminds us that there's no point going to -all the trouble of removing backing up from the rules unless -we're using --Cf -or --CF, -since there's no performance gain doing so with compressed scanners. - -

        -The way to remove the backing up is to add "error" rules: -

        -
        -


        %% -
        foo return TOK_KEYWORD; -
        foobar return TOK_KEYWORD; -
        -


        fooba | -
        foob | -
        fo { -
        /* false alarm, not really a keyword */ -
        return TOK_ID; -
        } -
        -


        - -

        -Eliminating backing up among a list of keywords can also be -done using a "catch-all" rule: -

        -
        -


        %% -
        foo return TOK_KEYWORD; -
        foobar return TOK_KEYWORD; -
        -


        [a-z]+ return TOK_ID; -
        -


        -This is usually the best solution when appropriate. - -

        -Backing up messages tend to cascade. -With a complicated set of rules it's not uncommon to get hundreds -of messages. If one can decipher them, though, it often -only takes a dozen or so rules to eliminate the backing up (though -it's easy to make a mistake and have an error rule accidentally match -a valid token. A possible future -flex -feature will be to automatically add rules to eliminate backing up). - -

        -It's important to keep in mind that you gain the benefits of eliminating -backing up only if you eliminate -every -instance of backing up. Leaving just one means you gain nothing. - -

        -Variable -trailing context (where both the leading and trailing parts do not have -a fixed length) entails almost the same performance loss as -REJECT -(i.e., substantial). So when possible a rule like: -

        -
        -


        %% -
        mouse|rat/(cat|dog) run(); -
        -


        -is better written: -
        -
        -


        %% -
        mouse/cat|dog run(); -
        rat/cat|dog run(); -
        -


        -or as -
        -
        -


        %% -
        mouse|rat/cat run(); -
        mouse|rat/dog run(); -
        -


        -Note that here the special '|' action does -not -provide any savings, and can even make things worse (see -Deficiencies / Bugs below). - -

        -Another area where the user can increase a scanner's performance -(and one that's easier to implement) arises from the fact that -the longer the tokens matched, the faster the scanner will run. -This is because with long tokens the processing of most input -characters takes place in the (short) inner scanning loop, and -does not often have to go through the additional work of setting up -the scanning environment (e.g., -yytext) -for the action. Recall the scanner for C comments: -

        -
        -


        %x comment -
        %% -
        int line_num = 1; -
        -


        "/*" BEGIN(comment); -
        -


        <comment>[^*\n]* -
        <comment>"*"+[^*/\n]* -
        <comment>\n ++line_num; -
        <comment>"*"+"/" BEGIN(INITIAL); -
        -


        -This could be sped up by writing it as: -
        -
        -


        %x comment -
        %% -
        int line_num = 1; -
        -


        "/*" BEGIN(comment); -
        -


        <comment>[^*\n]* -
        <comment>[^*\n]*\n ++line_num; -
        <comment>"*"+[^*/\n]* -
        <comment>"*"+[^*/\n]*\n ++line_num; -
        <comment>"*"+"/" BEGIN(INITIAL); -
        -


        -Now instead of each newline requiring the processing of another -action, recognizing the newlines is "distributed" over the other rules -to keep the matched text as long as possible. Note that -adding -rules does -not -slow down the scanner! The speed of the scanner is independent -of the number of rules or (modulo the considerations given at the -beginning of this section) how complicated the rules are with -regard to operators such as '*' and '|'. - -

        -A final example in speeding up a scanner: suppose you want to scan -through a file containing identifiers and keywords, one per line -and with no other extraneous characters, and recognize all the -keywords. A natural first approach is: -

        -
        -


        %% -
        asm | -
        auto | -
        break | -
        ... etc ... -
        volatile | -
        while /* it's a keyword */ -
        -


        .|\n /* it's not a keyword */ -
        -


        -To eliminate the back-tracking, introduce a catch-all rule: -
        -
        -


        %% -
        asm | -
        auto | -
        break | -
        ... etc ... -
        volatile | -
        while /* it's a keyword */ -
        -


        [a-z]+ | -
        .|\n /* it's not a keyword */ -
        -


        -Now, if it's guaranteed that there's exactly one word per line, -then we can reduce the total number of matches by a half by -merging in the recognition of newlines with that of the other -tokens: -
        -
        -


        %% -
        asm\n | -
        auto\n | -
        break\n | -
        ... etc ... -
        volatile\n | -
        while\n /* it's a keyword */ -
        -


        [a-z]+\n | -
        .|\n /* it's not a keyword */ -
        -


        -One has to be careful here, as we have now reintroduced backing up -into the scanner. In particular, while -we -know that there will never be any characters in the input stream -other than letters or newlines, -flex -can't figure this out, and it will plan for possibly needing to back up -when it has scanned a token like "auto" and then the next character -is something other than a newline or a letter. Previously it would -then just match the "auto" rule and be done, but now it has no "auto" -rule, only a "auto\n" rule. To eliminate the possibility of backing up, -we could either duplicate all rules but without final newlines, or, -since we never expect to encounter such an input and therefore don't -how it's classified, we can introduce one more catch-all rule, this -one which doesn't include a newline: -
        -
        -


        %% -
        asm\n | -
        auto\n | -
        break\n | -
        ... etc ... -
        volatile\n | -
        while\n /* it's a keyword */ -
        -


        [a-z]+\n | -
        [a-z]+ | -
        .|\n /* it's not a keyword */ -
        -


        -Compiled with --Cf, -this is about as fast as one can get a -flex -scanner to go for this particular problem. - -

        -A final note: -flex -is slow when matching NUL's, particularly when a token contains -multiple NUL's. -It's best to write rules which match -short -amounts of text if it's anticipated that the text will often include NUL's. - -

        -Another final note regarding performance: as mentioned above in the section -How the Input is Matched, dynamically resizing -yytext -to accommodate huge tokens is a slow process because it presently requires that -the (huge) token be rescanned from the beginning. Thus if performance is -vital, you should attempt to match "large" quantities of text but not -"huge" quantities, where the cutoff between the two is at about 8K -characters/token. - -

      GENERATING C++ SCANNERS

        - -flex -provides two different ways to generate scanners for use with C++. The -first way is to simply compile a scanner generated by -flex -using a C++ compiler instead of a C compiler. You should not encounter -any compilations errors (please report any you find to the email address -given in the Author section below). You can then use C++ code in your -rule actions instead of C code. Note that the default input source for -your scanner remains -yyin, -and default echoing is still done to -yyout. -Both of these remain -FILE * -variables and not C++ -streams. - -

        -You can also use -flex -to generate a C++ scanner class, using the --+ -option (or, equivalently, -%option c++), -which is automatically specified if the name of the flex -executable ends in a '+', such as -flex++. -When using this option, flex defaults to generating the scanner to the file -lex.yy.cc -instead of -lex.yy.c. -The generated scanner includes the header file -FlexLexer.h, -which defines the interface to two C++ classes. - -

        -The first class, -FlexLexer, -provides an abstract base class defining the general scanner class -interface. It provides the following member functions: -

        const char* YYText() -
        returns the text of the most recently matched token, the equivalent of -yytext. -
        int YYLeng() -
        returns the length of the most recently matched token, the equivalent of -yyleng. -
        int lineno() const -
        returns the current input line number -(see -%option yylineno), -or -1 -if -%option yylineno -was not used. -
        void set_debug( int flag ) -
        sets the debugging flag for the scanner, equivalent to assigning to -yy_flex_debug -(see the Options section above). Note that you must build the scanner -using -%option debug -to include debugging information in it. -
        int debug() const -
        returns the current setting of the debugging flag. -
        -

        -Also provided are member functions equivalent to -yy_switch_to_buffer(), -yy_create_buffer() -(though the first argument is an -istream* -object pointer and not a -FILE*), -yy_flush_buffer(), -yy_delete_buffer(), -and -yyrestart() -(again, the first argument is a -istream* -object pointer). - -

        -The second class defined in -FlexLexer.h -is -yyFlexLexer, -which is derived from -FlexLexer. -It defines the following additional member functions: -

        yyFlexLexer( istream* arg_yyin = 0, ostream* arg_yyout = 0 ) -
        constructs a -yyFlexLexer -object using the given streams for input and output. If not specified, -the streams default to -cin -and -cout, -respectively. -
        virtual int yylex() -
        performs the same role is -yylex() -does for ordinary flex scanners: it scans the input stream, consuming -tokens, until a rule's action returns a value. If you derive a subclass -S -from -yyFlexLexer -and want to access the member functions and variables of -S -inside -yylex(), -then you need to use -%option yyclass=S -to inform -flex -that you will be using that subclass instead of -yyFlexLexer. -In this case, rather than generating -yyFlexLexer::yylex(), -flex -generates -S::yylex() -(and also generates a dummy -yyFlexLexer::yylex() -that calls -yyFlexLexer::LexerError() -if called). -
        virtual void switch_streams(istream* new_in = 0, -
        ostream* new_out = 0) -reassigns -yyin -to -new_in -(if non-nil) -and -yyout -to -new_out -(ditto), deleting the previous input buffer if -yyin -is reassigned. -
        int yylex( istream* new_in = 0, ostream* new_out = 0 ) -
        first switches the input streams via -switch_streams( new_in, new_out ) -and then returns the value of -yylex(). -
        -

        -In addition, -yyFlexLexer -defines the following protected virtual functions which you can redefine -in derived classes to tailor the scanner: -

        virtual int LexerInput( char* buf, int max_size ) -
        reads up to -max_size -characters into -buf -and returns the number of characters read. To indicate end-of-input, -return 0 characters. Note that "interactive" scanners (see the --B -and --I -flags) define the macro -YY_INTERACTIVE. -If you redefine -LexerInput() -and need to take different actions depending on whether or not -the scanner might be scanning an interactive input source, you can -test for the presence of this name via -#ifdef. -
        virtual void LexerOutput( const char* buf, int size ) -
        writes out -size -characters from the buffer -buf, -which, while NUL-terminated, may also contain "internal" NUL's if -the scanner's rules can match text with NUL's in them. -
        virtual void LexerError( const char* msg ) -
        reports a fatal error message. The default version of this function -writes the message to the stream -cerr -and exits. -
        -

        -Note that a -yyFlexLexer -object contains its -entire -scanning state. Thus you can use such objects to create reentrant -scanners. You can instantiate multiple instances of the same -yyFlexLexer -class, and you can also combine multiple C++ scanner classes together -in the same program using the --P -option discussed above. - -

        -Finally, note that the -%array -feature is not available to C++ scanner classes; you must use -%pointer -(the default). - -

        -Here is an example of a simple C++ scanner: -

        -
        -


        // An example of using the flex C++ scanner class. -
        -


        %{ -
        int mylineno = 0; -
        %} -
        -


        string \"[^\n"]+\" -
        -


        ws [ \t]+ -
        -


        alpha [A-Za-z] -
        dig [0-9] -
        name ({alpha}|{dig}|\$)({alpha}|{dig}|[_.\-/$])* -
        num1 [-+]?{dig}+\.?([eE][-+]?{dig}+)? -
        num2 [-+]?{dig}*\.{dig}+([eE][-+]?{dig}+)? -
        number {num1}|{num2} -
        -


        %% -
        -


        {ws} /* skip blanks and tabs */ -
        -


        "/*" { -
        int c; -
        -


        while((c = yyinput()) != 0) -
        { -
        if(c == '\n') -
        ++mylineno; -
        -


        else if(c == '*') -
        { -
        if((c = yyinput()) == '/') -
        break; -
        else -
        unput(c); -
        } -
        } -
        } -
        -


        {number} cout << "number " << YYText() << '\n'; -
        -


        \n mylineno++; -
        -


        {name} cout << "name " << YYText() << '\n'; -
        -


        {string} cout << "string " << YYText() << '\n'; -
        -


        %% -
        -


        int main( int /* argc */, char** /* argv */ ) -
        { -
        FlexLexer* lexer = new yyFlexLexer; -
        while(lexer->yylex() != 0) -
        ; -
        return 0; -
        } -

        -If you want to create multiple (different) lexer classes, you use the --P -flag (or the -prefix= -option) to rename each -yyFlexLexer -to some other -xxFlexLexer. -You then can include -<FlexLexer.h> -in your other sources once per lexer class, first renaming -yyFlexLexer -as follows: -
        -
        -


        #undef yyFlexLexer -
        #define yyFlexLexer xxFlexLexer -
        #include <FlexLexer.h> -
        -


        #undef yyFlexLexer -
        #define yyFlexLexer zzFlexLexer -
        #include <FlexLexer.h> -
        -


        -if, for example, you used -%option prefix=xx -for one of your scanners and -%option prefix=zz -for the other. - -

        -IMPORTANT: the present form of the scanning class is -experimental -and may change considerably between major releases. - -

      INCOMPATIBILITIES WITH LEX AND POSIX

        - -flex -is a rewrite of the AT&T Unix -lex -tool (the two implementations do not share any code, though), -with some extensions and incompatibilities, both of which -are of concern to those who wish to write scanners acceptable -to either implementation. Flex is fully compliant with the POSIX -lex -specification, except that when using -%pointer -(the default), a call to -unput() -destroys the contents of -yytext, -which is counter to the POSIX specification. - -

        -In this section we discuss all of the known areas of incompatibility -between flex, AT&T lex, and the POSIX specification. - -

        -flex's --l -option turns on maximum compatibility with the original AT&T -lex -implementation, at the cost of a major loss in the generated scanner's -performance. We note below which incompatibilities can be overcome -using the --l -option. - -

        -flex -is fully compatible with -lex -with the following exceptions: -

        -
        The undocumented -lex -scanner internal variable -yylineno -is not supported unless --l -or -%option yylineno -is used. -
        yylineno -should be maintained on a per-buffer basis, rather than a per-scanner -(single global variable) basis. -
        yylineno -is not part of the POSIX specification. -
        -
        The -input() -routine is not redefinable, though it may be called to read characters -following whatever has been matched by a rule. If -input() -encounters an end-of-file the normal -yywrap() -processing is done. A ``real'' end-of-file is returned by -input() -as -EOF. -
        Input is instead controlled by defining the -YY_INPUT -macro. -
        The -flex -restriction that -input() -cannot be redefined is in accordance with the POSIX specification, -which simply does not specify any way of controlling the -scanner's input other than by making an initial assignment to -yyin. -
        -
        The -unput() -routine is not redefinable. This restriction is in accordance with POSIX. -
        -
        flex -scanners are not as reentrant as -lex -scanners. In particular, if you have an interactive scanner and -an interrupt handler which long-jumps out of the scanner, and -the scanner is subsequently called again, you may get the following -message: -
        -
        -


        fatal flex scanner internal error--end of buffer missed -
        -


        -To reenter the scanner, first use -
        -
        -


        yyrestart( yyin ); -
        -


        -Note that this call will throw away any buffered input; usually this -isn't a problem with an interactive scanner. -
        Also note that flex C++ scanner classes -are -reentrant, so if using C++ is an option for you, you should use -them instead. See "Generating C++ Scanners" above for details. -
        -
        output() -is not supported. -Output from the -ECHO -macro is done to the file-pointer -yyout -(default -stdout). -
        output() -is not part of the POSIX specification. -
        -
        lex -does not support exclusive start conditions (%x), though they -are in the POSIX specification. -
        -
        When definitions are expanded, -flex -encloses them in parentheses. -With lex, the following: -
        -
        -


        NAME [A-Z][A-Z0-9]* -
        %% -
        foo{NAME}? printf( "Found it\n" ); -
        %% -
        -


        -will not match the string "foo" because when the macro -is expanded the rule is equivalent to "foo[A-Z][A-Z0-9]*?" -and the precedence is such that the '?' is associated with -"[A-Z0-9]*". With -flex, -the rule will be expanded to -"foo([A-Z][A-Z0-9]*)?" and so the string "foo" will match. -
        Note that if the definition begins with -^ -or ends with -$ -then it is -not -expanded with parentheses, to allow these operators to appear in -definitions without losing their special meanings. But the -<s>, /, -and -<<EOF>> -operators cannot be used in a -flex -definition. -
        Using --l -results in the -lex -behavior of no parentheses around the definition. -
        The POSIX specification is that the definition be enclosed in parentheses. -
        -
        Some implementations of -lex -allow a rule's action to begin on a separate line, if the rule's pattern -has trailing whitespace: -
        -
        -


        %% -
        foo|bar<space here> -
        { foobar_action(); } -
        -


        -flex -does not support this feature. -
        -
        The -lex -%r -(generate a Ratfor scanner) option is not supported. It is not part -of the POSIX specification. -
        -
        After a call to -unput(), -yytext -is undefined until the next token is matched, unless the scanner -was built using -%array. -This is not the case with -lex -or the POSIX specification. The --l -option does away with this incompatibility. -
        -
        The precedence of the -{} -(numeric range) operator is different. -lex -interprets "abc{1,3}" as "match one, two, or -three occurrences of 'abc'", whereas -flex -interprets it as "match 'ab' -followed by one, two, or three occurrences of 'c'". The latter is -in agreement with the POSIX specification. -
        -
        The precedence of the -^ -operator is different. -lex -interprets "^foo|bar" as "match either 'foo' at the beginning of a line, -or 'bar' anywhere", whereas -flex -interprets it as "match either 'foo' or 'bar' if they come at the beginning -of a line". The latter is in agreement with the POSIX specification. -
        -
        The special table-size declarations such as -%a -supported by -lex -are not required by -flex -scanners; -flex -ignores them. -
        -
        The name -FLEX_SCANNER -is #define'd so scanners may be written for use with either -flex -or -lex. -Scanners also include -YY_FLEX_MAJOR_VERSION -and -YY_FLEX_MINOR_VERSION -indicating which version of -flex -generated the scanner -(for example, for the 2.5 release, these defines would be 2 and 5 -respectively). -
        -

        -The following -flex -features are not included in -lex -or the POSIX specification: -

        -
        -


        C++ scanners -
        %option -
        start condition scopes -
        start condition stacks -
        interactive/non-interactive scanners -
        yy_scan_string() and friends -
        yyterminate() -
        yy_set_interactive() -
        yy_set_bol() -
        YY_AT_BOL() -
        <<EOF>> -
        <*> -
        YY_DECL -
        YY_START -
        YY_USER_ACTION -
        YY_USER_INIT -
        #line directives -
        %{}'s around actions -
        multiple actions on a line -
        -


        -plus almost all of the flex flags. -The last feature in the list refers to the fact that with -flex -you can put multiple actions on the same line, separated with -semi-colons, while with -lex, -the following -
        -
        -


        foo handle_foo(); ++num_foos_seen; -
        -


        -is (rather surprisingly) truncated to -
        -
        -


        foo handle_foo(); -
        -


        -flex -does not truncate the action. Actions that are not enclosed in -braces are simply terminated at the end of the line. - -

      DIAGNOSTICS

        - - -

        -warning, rule cannot be matched -indicates that the given rule -cannot be matched because it follows other rules that will -always match the same text as it. For -example, in the following "foo" cannot be matched because it comes after -an identifier "catch-all" rule: -

        -
        -


        [a-z]+ got_identifier(); -
        foo got_foo(); -
        -


        -Using -REJECT -in a scanner suppresses this warning. - -

        -warning, --s -option given but default rule can be matched -means that it is possible (perhaps only in a particular start condition) -that the default rule (match any single character) is the only one -that will match a particular input. Since --s -was given, presumably this is not intended. - -

        -reject_used_but_not_detected undefined -or -yymore_used_but_not_detected undefined - -These errors can occur at compile time. They indicate that the -scanner uses -REJECT -or -yymore() -but that -flex -failed to notice the fact, meaning that -flex -scanned the first two sections looking for occurrences of these actions -and failed to find any, but somehow you snuck some in (via a #include -file, for example). Use -%option reject -or -%option yymore -to indicate to flex that you really do use these features. - -

        -flex scanner jammed - -a scanner compiled with --s -has encountered an input string which wasn't matched by -any of its rules. This error can also occur due to internal problems. - -

        -token too large, exceeds YYLMAX - -your scanner uses -%array -and one of its rules matched a string longer than the -YYLMAX -constant (8K bytes by default). You can increase the value by -#define'ing -YYLMAX -in the definitions section of your -flex -input. - -

        -scanner requires -8 flag to -use the character 'x' - -Your scanner specification includes recognizing the 8-bit character -'x' -and you did not specify the -8 flag, and your scanner defaulted to 7-bit -because you used the --Cf -or --CF -table compression options. See the discussion of the --7 -flag for details. - -

        -flex scanner push-back overflow - -you used -unput() -to push back so much text that the scanner's buffer could not hold -both the pushed-back text and the current token in -yytext. -Ideally the scanner should dynamically resize the buffer in this case, but at -present it does not. - -

        -input buffer overflow, can't enlarge buffer because scanner uses REJECT - -the scanner was working on matching an extremely large token and needed -to expand the input buffer. This doesn't work with scanners that use -REJECT. - -

        -fatal flex scanner internal error--end of buffer missed - -This can occur in an scanner which is reentered after a long-jump -has jumped out (or over) the scanner's activation frame. Before -reentering the scanner, use: -

        -
        -


        yyrestart( yyin ); -
        -


        -or, as noted above, switch to using the C++ scanner class. - -

        -too many start conditions in <> construct! - -you listed more start conditions in a <> construct than exist (so -you must have listed at least one of them twice). - -

      FILES

        - -

        -lfl -
        library with which scanners must be linked. -
        lex.yy.c -
        generated scanner (called -lexyy.c -on some systems). -
        lex.yy.cc -
        generated C++ scanner class, when using --+. -
        <FlexLexer.h> -
        header file defining the C++ scanner base class, -FlexLexer, -and its derived class, -yyFlexLexer. -
        flex.skl -
        skeleton scanner. This file is only used when building flex, not when -flex executes. -
        lex.backup -
        backing-up information for --b -flag (called -lex.bck -on some systems). -
        -

      DEFICIENCIES / BUGS

        - - -

        -Some trailing context -patterns cannot be properly matched and generate -warning messages ("dangerous trailing context"). These are -patterns where the ending of the -first part of the rule matches the beginning of the second -part, such as "zx*/xy*", where the 'x*' matches the 'x' at -the beginning of the trailing context. (Note that the POSIX draft -states that the text matched by such patterns is undefined.) - -

        -For some trailing context rules, parts which are actually fixed-length are -not recognized as such, leading to the abovementioned performance loss. -In particular, parts using '|' or {n} (such as "foo{3}") are always -considered variable-length. - -

        -Combining trailing context with the special '|' action can result in -fixed -trailing context being turned into the more expensive -variable -trailing context. For example, in the following: -

        -
        -


        %% -
        abc | -
        xyz/def -
        -


        - -

        -Use of -unput() -invalidates yytext and yyleng, unless the -%array -directive -or the --l -option has been used. - -

        -Pattern-matching of NUL's is substantially slower than matching other -characters. - -

        -Dynamic resizing of the input buffer is slow, as it entails rescanning -all the text matched so far by the current (generally huge) token. - -

        -Due to both buffering of input and read-ahead, you cannot intermix -calls to <stdio.h> routines, such as, for example, -getchar(), -with -flex -rules and expect it to work. Call -input() -instead. - -

        -The total table entries listed by the --v -flag excludes the number of table entries needed to determine -what rule has been matched. The number of entries is equal -to the number of DFA states if the scanner does not use -REJECT, -and somewhat greater than the number of states if it does. - -

        -REJECT -cannot be used with the --f -or --F -options. - -

        -The -flex -internal algorithms need documentation. - -

      SEE ALSO

        - - -

        -lex(1), yacc(1), sed(1), awk(1). - -

        -John Levine, Tony Mason, and Doug Brown, -Lex & Yacc, -O'Reilly and Associates. Be sure to get the 2nd edition. - -

        -M. E. Lesk and E. Schmidt, -LEX - Lexical Analyzer Generator - -

        -Alfred Aho, Ravi Sethi and Jeffrey Ullman, -Compilers: Principles, Techniques and Tools, -Addison-Wesley (1986). Describes the pattern-matching techniques used by -flex -(deterministic finite automata). - -

      AUTHOR

        - -Vern Paxson, with the help of many ideas and much inspiration from -Van Jacobson. Original version by Jef Poskanzer. The fast table -representation is a partial implementation of a design done by Van -Jacobson. The implementation was done by Kevin Gong and Vern Paxson. - -

        -Thanks to the many -flex -beta-testers, feedbackers, and contributors, especially Francois Pinard, -Casey Leedom, -Stan Adermann, Terry Allen, David Barker-Plummer, John Basrai, -Nelson H.F. Beebe, benson@odi.com, -Karl Berry, Peter A. Bigot, Simon Blanchard, -Keith Bostic, Frederic Brehm, Ian Brockbank, Kin Cho, Nick Christopher, -Brian Clapper, J.T. Conklin, -Jason Coughlin, Bill Cox, Nick Cropper, Dave Curtis, Scott David -Daniels, Chris G. Demetriou, Theo Deraadt, -Mike Donahue, Chuck Doucette, Tom Epperly, Leo Eskin, -Chris Faylor, Chris Flatters, Jon Forrest, Joe Gayda, Kaveh R. Ghazi, -Eric Goldman, Christopher M. Gould, Ulrich Grepel, Peer Griebel, -Jan Hajic, Charles Hemphill, NORO Hideo, -Jarkko Hietaniemi, Scott Hofmann, -Jeff Honig, Dana Hudes, Eric Hughes, John Interrante, -Ceriel Jacobs, Michal Jaegermann, Sakari Jalovaara, Jeffrey R. Jones, -Henry Juengst, Klaus Kaempf, Jonathan I. Kamens, Terrence O Kane, -Amir Katz, ken@ken.hilco.com, Kevin B. Kenny, -Steve Kirsch, Winfried Koenig, Marq Kole, Ronald Lamprecht, -Greg Lee, Rohan Lenard, Craig Leres, John Levine, Steve Liddle, Mike Long, -Mohamed el Lozy, Brian Madsen, Malte, Joe Marshall, -Bengt Martensson, Chris Metcalf, -Luke Mewburn, Jim Meyering, R. Alexander Milowski, Erik Naggum, -G.T. Nicol, Landon Noll, James Nordby, Marc Nozell, -Richard Ohnemus, Karsten Pahnke, -Sven Panne, Roland Pesch, Walter Pelissero, Gaumond -Pierre, Esmond Pitt, Jef Poskanzer, Joe Rahmeh, Jarmo Raiha, -Frederic Raimbault, Pat Rankin, Rick Richardson, -Kevin Rodgers, Kai Uwe Rommel, Jim Roskind, Alberto Santini, -Andreas Scherer, Darrell Schiebel, Raf Schietekat, -Doug Schmidt, Philippe Schnoebelen, Andreas Schwab, -Alex Siegel, Eckehard Stolz, Jan-Erik Strvmquist, -Mike Stump, Paul Stuart, Dave Tallman, Ian Lance Taylor, -Chris Thewalt, Richard M. Timoney, Jodi Tsai, -Paul Tuinenga, Gary Weik, Frank Whaley, Gerhard Wilhelms, Kent Williams, Ken -Yap, Ron Zellar, Nathan Zelle, David Zuhn, -and those whose names have slipped my marginal -mail-archiving skills but whose contributions are appreciated all the -same. - -

        -Thanks to Keith Bostic, Jon Forrest, Noah Friedman, -John Gilmore, Craig Leres, John Levine, Bob Mulcahy, G.T. -Nicol, Francois Pinard, Rich Salz, and Richard Stallman for help with various -distribution headaches. - -

        -Thanks to Esmond Pitt and Earle Horton for 8-bit character support; to -Benson Margulies and Fred Burke for C++ support; to Kent Williams and Tom -Epperly for C++ class support; to Ove Ewerlid for support of NUL's; and to -Eric Hughes for support of multiple buffers. - -

        -This work was primarily done when I was with the Real Time Systems Group -at the Lawrence Berkeley Laboratory in Berkeley, CA. Many thanks to all there -for the support I received. - -

        -Send comments to vern@ee.lbl.gov. -

      \ No newline at end of file diff --git a/Engine/source/console/torquescript/CMDgram.h b/Engine/source/console/torquescript/CMDgram.h new file mode 100644 index 000000000..771702847 --- /dev/null +++ b/Engine/source/console/torquescript/CMDgram.h @@ -0,0 +1,170 @@ +/* A Bison parser, made by GNU Bison 3.8.2. */ + +/* Bison interface for Yacc-like parsers in C + + Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, + especially those whose name start with YY_ or yy_. They are + private implementation details that can be changed or removed. */ + +#ifndef YY_CMD_CMDGRAM_H_INCLUDED +# define YY_CMD_CMDGRAM_H_INCLUDED +/* Debug traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif +#if YYDEBUG +extern int CMDdebug; +#endif + +/* Token kinds. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + enum yytokentype + { + YYEMPTY = -2, + YYEOF = 0, /* "end of file" */ + YYerror = 256, /* error */ + YYUNDEF = 257, /* "invalid token" */ + rwDEFINE = 258, /* rwDEFINE */ + rwENDDEF = 259, /* rwENDDEF */ + rwDECLARE = 260, /* rwDECLARE */ + rwDECLARESINGLETON = 261, /* rwDECLARESINGLETON */ + rwBREAK = 262, /* rwBREAK */ + rwELSE = 263, /* rwELSE */ + rwCONTINUE = 264, /* rwCONTINUE */ + rwGLOBAL = 265, /* rwGLOBAL */ + rwIF = 266, /* rwIF */ + rwNIL = 267, /* rwNIL */ + rwRETURN = 268, /* rwRETURN */ + rwWHILE = 269, /* rwWHILE */ + rwDO = 270, /* rwDO */ + rwENDIF = 271, /* rwENDIF */ + rwENDWHILE = 272, /* rwENDWHILE */ + rwENDFOR = 273, /* rwENDFOR */ + rwDEFAULT = 274, /* rwDEFAULT */ + rwFOR = 275, /* rwFOR */ + rwFOREACH = 276, /* rwFOREACH */ + rwFOREACHSTR = 277, /* rwFOREACHSTR */ + rwIN = 278, /* rwIN */ + rwDATABLOCK = 279, /* rwDATABLOCK */ + rwSWITCH = 280, /* rwSWITCH */ + rwCASE = 281, /* rwCASE */ + rwSWITCHSTR = 282, /* rwSWITCHSTR */ + rwCASEOR = 283, /* rwCASEOR */ + rwPACKAGE = 284, /* rwPACKAGE */ + rwNAMESPACE = 285, /* rwNAMESPACE */ + rwCLASS = 286, /* rwCLASS */ + rwASSERT = 287, /* rwASSERT */ + ILLEGAL_TOKEN = 288, /* ILLEGAL_TOKEN */ + CHRCONST = 289, /* CHRCONST */ + INTCONST = 290, /* INTCONST */ + TTAG = 291, /* TTAG */ + VAR = 292, /* VAR */ + IDENT = 293, /* IDENT */ + TYPEIDENT = 294, /* TYPEIDENT */ + DOCBLOCK = 295, /* DOCBLOCK */ + STRATOM = 296, /* STRATOM */ + TAGATOM = 297, /* TAGATOM */ + FLTCONST = 298, /* FLTCONST */ + opINTNAME = 299, /* opINTNAME */ + opINTNAMER = 300, /* opINTNAMER */ + opMINUSMINUS = 301, /* opMINUSMINUS */ + opPLUSPLUS = 302, /* opPLUSPLUS */ + STMT_SEP = 303, /* STMT_SEP */ + opSHL = 304, /* opSHL */ + opSHR = 305, /* opSHR */ + opPLASN = 306, /* opPLASN */ + opMIASN = 307, /* opMIASN */ + opMLASN = 308, /* opMLASN */ + opDVASN = 309, /* opDVASN */ + opMODASN = 310, /* opMODASN */ + opANDASN = 311, /* opANDASN */ + opXORASN = 312, /* opXORASN */ + opORASN = 313, /* opORASN */ + opSLASN = 314, /* opSLASN */ + opSRASN = 315, /* opSRASN */ + opCAT = 316, /* opCAT */ + opEQ = 317, /* opEQ */ + opNE = 318, /* opNE */ + opGE = 319, /* opGE */ + opLE = 320, /* opLE */ + opAND = 321, /* opAND */ + opOR = 322, /* opOR */ + opSTREQ = 323, /* opSTREQ */ + opCOLONCOLON = 324, /* opCOLONCOLON */ + opMDASN = 325, /* opMDASN */ + opNDASN = 326, /* opNDASN */ + opNTASN = 327, /* opNTASN */ + opSTRNE = 328, /* opSTRNE */ + UNARY = 329 /* UNARY */ + }; + typedef enum yytokentype yytoken_kind_t; +#endif + +/* Value type. */ +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +union YYSTYPE +{ +#line 82 "CMDgram.y" + + Token< char > c; + Token< int > i; + Token< const char* > s; + Token< char* > str; + Token< double > f; + StmtNode* stmt; + ExprNode* expr; + SlotAssignNode* slist; + VarNode* var; + SlotDecl slot; + InternalSlotDecl intslot; + ObjectBlockDecl odcl; + ObjectDeclNode* od; + AssignDecl asn; + IfStmtNode* ifnode; + +#line 156 "CMDgram.h" + +}; +typedef union YYSTYPE YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define YYSTYPE_IS_DECLARED 1 +#endif + + +extern YYSTYPE CMDlval; + + +int CMDparse (void); + + +#endif /* !YY_CMD_CMDGRAM_H_INCLUDED */ diff --git a/Engine/source/console/torquescript/CMDgram.y b/Engine/source/console/torquescript/CMDgram.y index c3e8846b8..942b00992 100644 --- a/Engine/source/console/torquescript/CMDgram.y +++ b/Engine/source/console/torquescript/CMDgram.y @@ -8,7 +8,7 @@ #include #include #include "console/console.h" -#include "console/compiler.h" +#include "console/torquescript/compiler.h" #include "console/consoleInternal.h" #include "core/strings/stringFunctions.h" @@ -166,7 +166,7 @@ decl_list : { $$ = nil; } | decl_list decl - { if(!gStatementList) { gStatementList = $2; } else { gStatementList->append($2); } } + { if(!Script::gStatementList) { Script::gStatementList = $2; } else { Script::gStatementList->append($2); } } ; decl diff --git a/Engine/source/console/torquescript/CMDscan.cpp b/Engine/source/console/torquescript/CMDscan.cpp index f1a844086..054cc394a 100644 --- a/Engine/source/console/torquescript/CMDscan.cpp +++ b/Engine/source/console/torquescript/CMDscan.cpp @@ -1,168 +1,447 @@ +#line 1 "CMDscan.cpp" + +#line 3 "CMDscan.cpp" + +#define YY_INT_ALIGNED short int + +/* A lexical scanner generated by flex */ + #define yy_create_buffer CMD_create_buffer #define yy_delete_buffer CMD_delete_buffer #define yy_scan_buffer CMD_scan_buffer #define yy_scan_string CMD_scan_string #define yy_scan_bytes CMD_scan_bytes -#define yy_flex_debug CMD_flex_debug #define yy_init_buffer CMD_init_buffer #define yy_flush_buffer CMD_flush_buffer #define yy_load_buffer_state CMD_load_buffer_state #define yy_switch_to_buffer CMD_switch_to_buffer +#define yypush_buffer_state CMDpush_buffer_state +#define yypop_buffer_state CMDpop_buffer_state +#define yyensure_buffer_stack CMDensure_buffer_stack +#define yy_flex_debug CMD_flex_debug #define yyin CMDin #define yyleng CMDleng #define yylex CMDlex +#define yylineno CMDlineno #define yyout CMDout #define yyrestart CMDrestart #define yytext CMDtext #define yywrap CMDwrap - -#line 20 "CMDscan.cpp" -/* A lexical scanner generated by flex */ - -/* Scanner skeleton version: - * $Header: /home/daffy/u0/vern/flex/RCS/flex.skl,v 2.85 95/04/24 10:48:47 vern Exp $ - */ +#define yyalloc CMDalloc +#define yyrealloc CMDrealloc +#define yyfree CMDfree #define FLEX_SCANNER #define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 5 +#define YY_FLEX_MINOR_VERSION 6 +#define YY_FLEX_SUBMINOR_VERSION 4 +#if YY_FLEX_SUBMINOR_VERSION > 0 +#define FLEX_BETA +#endif +#ifdef yy_create_buffer +#define CMD_create_buffer_ALREADY_DEFINED +#else +#define yy_create_buffer CMD_create_buffer +#endif + +#ifdef yy_delete_buffer +#define CMD_delete_buffer_ALREADY_DEFINED +#else +#define yy_delete_buffer CMD_delete_buffer +#endif + +#ifdef yy_scan_buffer +#define CMD_scan_buffer_ALREADY_DEFINED +#else +#define yy_scan_buffer CMD_scan_buffer +#endif + +#ifdef yy_scan_string +#define CMD_scan_string_ALREADY_DEFINED +#else +#define yy_scan_string CMD_scan_string +#endif + +#ifdef yy_scan_bytes +#define CMD_scan_bytes_ALREADY_DEFINED +#else +#define yy_scan_bytes CMD_scan_bytes +#endif + +#ifdef yy_init_buffer +#define CMD_init_buffer_ALREADY_DEFINED +#else +#define yy_init_buffer CMD_init_buffer +#endif + +#ifdef yy_flush_buffer +#define CMD_flush_buffer_ALREADY_DEFINED +#else +#define yy_flush_buffer CMD_flush_buffer +#endif + +#ifdef yy_load_buffer_state +#define CMD_load_buffer_state_ALREADY_DEFINED +#else +#define yy_load_buffer_state CMD_load_buffer_state +#endif + +#ifdef yy_switch_to_buffer +#define CMD_switch_to_buffer_ALREADY_DEFINED +#else +#define yy_switch_to_buffer CMD_switch_to_buffer +#endif + +#ifdef yypush_buffer_state +#define CMDpush_buffer_state_ALREADY_DEFINED +#else +#define yypush_buffer_state CMDpush_buffer_state +#endif + +#ifdef yypop_buffer_state +#define CMDpop_buffer_state_ALREADY_DEFINED +#else +#define yypop_buffer_state CMDpop_buffer_state +#endif + +#ifdef yyensure_buffer_stack +#define CMDensure_buffer_stack_ALREADY_DEFINED +#else +#define yyensure_buffer_stack CMDensure_buffer_stack +#endif + +#ifdef yylex +#define CMDlex_ALREADY_DEFINED +#else +#define yylex CMDlex +#endif + +#ifdef yyrestart +#define CMDrestart_ALREADY_DEFINED +#else +#define yyrestart CMDrestart +#endif + +#ifdef yylex_init +#define CMDlex_init_ALREADY_DEFINED +#else +#define yylex_init CMDlex_init +#endif + +#ifdef yylex_init_extra +#define CMDlex_init_extra_ALREADY_DEFINED +#else +#define yylex_init_extra CMDlex_init_extra +#endif + +#ifdef yylex_destroy +#define CMDlex_destroy_ALREADY_DEFINED +#else +#define yylex_destroy CMDlex_destroy +#endif + +#ifdef yyget_debug +#define CMDget_debug_ALREADY_DEFINED +#else +#define yyget_debug CMDget_debug +#endif + +#ifdef yyset_debug +#define CMDset_debug_ALREADY_DEFINED +#else +#define yyset_debug CMDset_debug +#endif + +#ifdef yyget_extra +#define CMDget_extra_ALREADY_DEFINED +#else +#define yyget_extra CMDget_extra +#endif + +#ifdef yyset_extra +#define CMDset_extra_ALREADY_DEFINED +#else +#define yyset_extra CMDset_extra +#endif + +#ifdef yyget_in +#define CMDget_in_ALREADY_DEFINED +#else +#define yyget_in CMDget_in +#endif + +#ifdef yyset_in +#define CMDset_in_ALREADY_DEFINED +#else +#define yyset_in CMDset_in +#endif + +#ifdef yyget_out +#define CMDget_out_ALREADY_DEFINED +#else +#define yyget_out CMDget_out +#endif + +#ifdef yyset_out +#define CMDset_out_ALREADY_DEFINED +#else +#define yyset_out CMDset_out +#endif + +#ifdef yyget_leng +#define CMDget_leng_ALREADY_DEFINED +#else +#define yyget_leng CMDget_leng +#endif + +#ifdef yyget_text +#define CMDget_text_ALREADY_DEFINED +#else +#define yyget_text CMDget_text +#endif + +#ifdef yyget_lineno +#define CMDget_lineno_ALREADY_DEFINED +#else +#define yyget_lineno CMDget_lineno +#endif + +#ifdef yyset_lineno +#define CMDset_lineno_ALREADY_DEFINED +#else +#define yyset_lineno CMDset_lineno +#endif + +#ifdef yywrap +#define CMDwrap_ALREADY_DEFINED +#else +#define yywrap CMDwrap +#endif + +#ifdef yyalloc +#define CMDalloc_ALREADY_DEFINED +#else +#define yyalloc CMDalloc +#endif + +#ifdef yyrealloc +#define CMDrealloc_ALREADY_DEFINED +#else +#define yyrealloc CMDrealloc +#endif + +#ifdef yyfree +#define CMDfree_ALREADY_DEFINED +#else +#define yyfree CMDfree +#endif + +#ifdef yytext +#define CMDtext_ALREADY_DEFINED +#else +#define yytext CMDtext +#endif + +#ifdef yyleng +#define CMDleng_ALREADY_DEFINED +#else +#define yyleng CMDleng +#endif + +#ifdef yyin +#define CMDin_ALREADY_DEFINED +#else +#define yyin CMDin +#endif + +#ifdef yyout +#define CMDout_ALREADY_DEFINED +#else +#define yyout CMDout +#endif + +#ifdef yy_flex_debug +#define CMD_flex_debug_ALREADY_DEFINED +#else +#define yy_flex_debug CMD_flex_debug +#endif + +#ifdef yylineno +#define CMDlineno_ALREADY_DEFINED +#else +#define yylineno CMDlineno +#endif + +/* First, we deal with platform-specific or compiler-specific issues. */ + +/* begin standard C headers. */ #include - -#include "compiler.h" -#include "runtime.h" -#include "console/script.h" - - -/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */ -#ifdef c_plusplus -#ifndef __cplusplus -#define __cplusplus -#endif -#endif - - -#ifdef __cplusplus - +#include +#include #include -//nclude -/* Use prototypes in function declarations. */ -#define YY_USE_PROTOS +/* end standard C headers. */ -/* The "const" storage-class-modifier is valid. */ -#define YY_USE_CONST +/* flex integer type definitions */ -#else /* ! __cplusplus */ +#ifndef FLEXINT_H +#define FLEXINT_H -#if __STDC__ +/* C99 systems have . Non-C99 systems may or may not. */ -#define YY_USE_PROTOS -#define YY_USE_CONST +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L -#endif /* __STDC__ */ -#endif /* ! __cplusplus */ - -#ifdef __TURBOC__ - #pragma warn -rch - #pragma warn -use -#include -#include -#define YY_USE_CONST -#define YY_USE_PROTOS +/* 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 -#ifdef YY_USE_CONST +#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; + +/* 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 + +#ifndef SIZE_MAX +#define SIZE_MAX (~(size_t)0) +#endif + +#endif /* ! C99 */ + +#endif /* ! FLEXINT_H */ + +/* begin standard C++ headers. */ + +/* TODO: this is always defined, so inline it */ #define yyconst const -#else -#define yyconst -#endif - -#ifdef YY_USE_PROTOS -#define YY_PROTO(proto) proto +#if defined(__GNUC__) && __GNUC__ >= 3 +#define yynoreturn __attribute__((__noreturn__)) #else -#define YY_PROTO(proto) () +#define yynoreturn #endif /* Returned upon end-of-file. */ #define YY_NULL 0 -/* Promotes a possibly negative, possibly signed char to an unsigned - * integer for use as an array index. If the signed char is negative, - * we want to instead treat it as an 8-bit unsigned char, hence the - * double cast. +/* Promotes a possibly negative, possibly signed char to an + * integer in range [0..255] for use as an array index. */ -#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) +#define YY_SC_TO_UI(c) ((YY_CHAR) (c)) /* Enter a start condition. This macro really ought to take a parameter, * 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 +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k. + * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. + * Ditto for the __ia64__ case accordingly. + */ +#define YY_BUF_SIZE 32768 +#else #define YY_BUF_SIZE 16384 +#endif /* __ia64__ */ +#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 + +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#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) + #define YY_LINENO_REWIND_TO(ptr) + +/* 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; \ - yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \ + 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 + yyless_macro_arg - YY_MORE_ADJ; \ YY_DO_BEFORE_ACTION; /* set up yytext again */ \ } \ while ( 0 ) +#define unput(c) yyunput( c, (yytext_ptr) ) -#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; - - +#ifndef YY_STRUCT_YY_BUFFER_STATE +#define YY_STRUCT_YY_BUFFER_STATE struct yy_buffer_state { FILE *yy_input_file; @@ -173,7 +452,7 @@ struct yy_buffer_state /* Size of input buffer in bytes, not including room for EOB * characters. */ - yy_size_t yy_buf_size; + int yy_buf_size; /* Number of characters read into yy_ch_buf, not including EOB * characters. @@ -199,12 +478,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 @@ -218,28 +501,37 @@ 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 = NULL; /**< 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 char *yy_c_buf_p = NULL; +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 @@ -247,66 +539,88 @@ 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 ); +#define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER ) -YY_BUFFER_STATE yy_scan_buffer YY_PROTO(( char *base, yy_size_t size )); -YY_BUFFER_STATE yy_scan_string YY_PROTO(( yyconst char *str )); -YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst char *bytes, int len )); +YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size ); +YY_BUFFER_STATE yy_scan_string ( const char *yy_str ); +YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len ); -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 * )); +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_LVALUE->yy_at_bol) -#define YY_AT_BOL() (yy_current_buffer->yy_at_bol) +/* Begin user sect3 */ +typedef flex_uint8_t YY_CHAR; + +FILE *yyin = NULL, *yyout = NULL; -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; +#ifdef yytext_ptr +#undef yytext_ptr +#endif #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 yynoreturn yy_fatal_error ( const 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; \ + (yytext_ptr) = yy_bp; \ yyleng = (int) (yy_cp - yy_bp); \ - yy_hold_char = *yy_cp; \ + (yy_hold_char) = *yy_cp; \ *yy_cp = '\0'; \ - yy_c_buf_p = yy_cp; - + (yy_c_buf_p) = yy_cp; #define YY_NUM_RULES 94 #define YY_END_OF_BUFFER 95 -static yyconst short int yy_accept[224] = +/* 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 const flex_int16_t yy_accept[224] = { 0, 0, 0, 95, 93, 1, 5, 4, 51, 93, 93, 58, 57, 93, 41, 42, 45, 43, 56, 44, 50, @@ -335,7 +649,7 @@ static yyconst short int yy_accept[224] = 84, 77, 0 } ; -static yyconst int yy_ec[256] = +static const YY_CHAR yy_ec[256] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 2, 2, 4, 1, 1, 1, 1, 1, 1, 1, @@ -367,7 +681,7 @@ static yyconst int yy_ec[256] = 1, 1, 1, 1, 1 } ; -static yyconst int yy_meta[68] = +static const YY_CHAR yy_meta[68] = { 0, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 4, 4, @@ -378,7 +692,7 @@ static yyconst int yy_meta[68] = 7, 7, 7, 1, 1, 1, 1 } ; -static yyconst short int yy_base[237] = +static const flex_int16_t yy_base[237] = { 0, 0, 0, 337, 338, 334, 338, 338, 61, 63, 51, 53, 65, 66, 338, 338, 311, 64, 338, 66, 60, @@ -408,7 +722,7 @@ static yyconst short int yy_base[237] = 119, 204, 211, 218, 225, 232 } ; -static yyconst short int yy_def[237] = +static const flex_int16_t yy_def[237] = { 0, 223, 1, 223, 223, 223, 223, 223, 223, 224, 225, 225, 223, 226, 223, 223, 223, 223, 223, 223, 223, @@ -438,7 +752,7 @@ static yyconst short int yy_def[237] = 223, 223, 223, 223, 223, 223 } ; -static yyconst short int yy_nxt[406] = +static const flex_int16_t yy_nxt[406] = { 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, @@ -487,7 +801,7 @@ static yyconst short int yy_nxt[406] = 223, 223, 223, 223, 223 } ; -static yyconst short int yy_chk[406] = +static const flex_int16_t yy_chk[406] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -539,15 +853,18 @@ static yyconst short int yy_chk[406] = 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. */ #define REJECT reject_used_but_not_detected #define yymore() yymore_used_but_not_detected #define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET char *yytext; #line 1 "CMDscan.l" -#define INITIAL 0 #line 2 "CMDscan.l" // flex --nounput -o CMDscan.cpp -P CMD CMDscan.l @@ -555,9 +872,11 @@ char *yytext; #define YYLMAX 4096 #define YY_NO_UNISTD_H +#include #include "platform/platform.h" #include "core/stringTable.h" #include "console/console.h" +#include "console/torquescript/compiler.h" #include "console/dynamicTypes.h" #include "core/strings/stringFunctions.h" @@ -578,7 +897,10 @@ inline Token< T > MakeToken( T value, U32 lineNumber ) return result; } -#include "cmdgram.h" +#include "console/torquescript/CMDgram.h" + +// HACK: C++17 and beyond can't use register keyword +#define register using namespace Compiler; @@ -633,7 +955,53 @@ void CMDerror(const char * s, ...); // Reset the parser. void CMDrestart(FILE *in); -#line 635 "CMDscan.cpp" +#line 958 "CMDscan.cpp" +#line 959 "CMDscan.cpp" + +#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. @@ -641,75 +1009,51 @@ void CMDrestart(FILE *in); #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 )); + + static void yyunput ( 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 *, const char *, int ); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen ( const 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. */ #ifndef YY_READ_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k */ +#define YY_READ_BUF_SIZE 16384 +#else #define YY_READ_BUF_SIZE 8192 +#endif /* __ia64__ */ #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 do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0) #endif /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, @@ -717,9 +1061,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; \ @@ -729,9 +1074,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 = (int) fread(buf, 1, (yy_size_t) 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();" - @@ -752,12 +1110,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. @@ -768,33 +1132,30 @@ YY_MALLOC_DECL /* Code executed at the end of each rule. */ #ifndef YY_BREAK -#define YY_BREAK break; +#define YY_BREAK /*LINTED*/break; #endif #define YY_RULE_SETUP \ YY_USER_ACTION +/** The main scanner function which does all the work. + */ YY_DECL - { - yy_state_type yy_current_state; - char *yy_cp, *yy_bp; - int yy_act; - -#line 105 "CMDscan.l" - - ; -#line 785 "CMDscan.cpp" - - if ( yy_init ) +{ + yy_state_type yy_current_state; + char *yy_cp, *yy_bp; + int yy_act; + + 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; @@ -802,42 +1163,51 @@ YY_DECL if ( ! yyout ) yyout = stdout; - if ( ! yy_current_buffer ) - yy_current_buffer = + if ( ! YY_CURRENT_BUFFER ) { + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = yy_create_buffer( yyin, YY_BUF_SIZE ); - - yy_load_buffer_state(); } - while ( 1 ) /* loops until end-of-file is reached */ + yy_load_buffer_state( ); + } + + { +#line 108 "CMDscan.l" + +#line 110 "CMDscan.l" + ; +#line 1180 "CMDscan.cpp" + + while ( /*CONSTCOND*/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 { - YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; + 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 >= 224 ) - yy_c = yy_meta[(unsigned int) yy_c]; + yy_c = yy_meta[yy_c]; } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; ++yy_cp; } while ( yy_base[yy_current_state] != 338 ); @@ -846,209 +1216,209 @@ yy_find_action: yy_act = yy_accept[yy_current_state]; if ( yy_act == 0 ) { /* have to back up */ - 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); 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: YY_RULE_SETUP -#line 107 "CMDscan.l" +#line 111 "CMDscan.l" { } YY_BREAK case 2: +/* rule 2 can match eol */ YY_RULE_SETUP -#line 108 "CMDscan.l" +#line 112 "CMDscan.l" { return(Sc_ScanDocBlock()); } YY_BREAK case 3: YY_RULE_SETUP -#line 109 "CMDscan.l" +#line 113 "CMDscan.l" ; YY_BREAK case 4: YY_RULE_SETUP -#line 110 "CMDscan.l" +#line 114 "CMDscan.l" ; YY_BREAK case 5: +/* rule 5 can match eol */ YY_RULE_SETUP -#line 111 "CMDscan.l" +#line 115 "CMDscan.l" {lineIndex++;} YY_BREAK case 6: YY_RULE_SETUP -#line 112 "CMDscan.l" +#line 116 "CMDscan.l" { return(Sc_ScanString(STRATOM)); } YY_BREAK case 7: YY_RULE_SETUP -#line 113 "CMDscan.l" +#line 117 "CMDscan.l" { return(Sc_ScanString(TAGATOM)); } YY_BREAK case 8: YY_RULE_SETUP -#line 114 "CMDscan.l" +#line 118 "CMDscan.l" { CMDlval.i = MakeToken< int >( opEQ, lineIndex ); return opEQ; } YY_BREAK case 9: YY_RULE_SETUP -#line 115 "CMDscan.l" +#line 119 "CMDscan.l" { CMDlval.i = MakeToken< int >( opNE, lineIndex ); return opNE; } YY_BREAK case 10: YY_RULE_SETUP -#line 116 "CMDscan.l" +#line 120 "CMDscan.l" { CMDlval.i = MakeToken< int >( opGE, lineIndex ); return opGE; } YY_BREAK case 11: YY_RULE_SETUP -#line 117 "CMDscan.l" +#line 121 "CMDscan.l" { CMDlval.i = MakeToken< int >( opLE, lineIndex ); return opLE; } YY_BREAK case 12: YY_RULE_SETUP -#line 118 "CMDscan.l" +#line 122 "CMDscan.l" { CMDlval.i = MakeToken< int >( opAND, lineIndex ); return opAND; } YY_BREAK case 13: YY_RULE_SETUP -#line 119 "CMDscan.l" +#line 123 "CMDscan.l" { CMDlval.i = MakeToken< int >( opOR, lineIndex ); return opOR; } YY_BREAK case 14: YY_RULE_SETUP -#line 120 "CMDscan.l" +#line 124 "CMDscan.l" { CMDlval.i = MakeToken< int >( opCOLONCOLON, lineIndex ); return opCOLONCOLON; } YY_BREAK case 15: YY_RULE_SETUP -#line 121 "CMDscan.l" +#line 125 "CMDscan.l" { CMDlval.i = MakeToken< int >( opMINUSMINUS, lineIndex ); return opMINUSMINUS; } YY_BREAK case 16: YY_RULE_SETUP -#line 122 "CMDscan.l" +#line 126 "CMDscan.l" { CMDlval.i = MakeToken< int >( opPLUSPLUS, lineIndex ); return opPLUSPLUS; } YY_BREAK case 17: YY_RULE_SETUP -#line 123 "CMDscan.l" +#line 127 "CMDscan.l" { CMDlval.i = MakeToken< int >( opSTREQ, lineIndex ); return opSTREQ; } YY_BREAK case 18: YY_RULE_SETUP -#line 124 "CMDscan.l" +#line 128 "CMDscan.l" { CMDlval.i = MakeToken< int >( opSTRNE, lineIndex ); return opSTRNE; } YY_BREAK case 19: YY_RULE_SETUP -#line 125 "CMDscan.l" +#line 129 "CMDscan.l" { CMDlval.i = MakeToken< int >( opSHL, lineIndex ); return opSHL; } YY_BREAK case 20: YY_RULE_SETUP -#line 126 "CMDscan.l" +#line 130 "CMDscan.l" { CMDlval.i = MakeToken< int >( opSHR, lineIndex ); return opSHR; } YY_BREAK case 21: YY_RULE_SETUP -#line 127 "CMDscan.l" +#line 131 "CMDscan.l" { CMDlval.i = MakeToken< int >( opPLASN, lineIndex ); return opPLASN; } YY_BREAK case 22: YY_RULE_SETUP -#line 128 "CMDscan.l" +#line 132 "CMDscan.l" { CMDlval.i = MakeToken< int >( opMIASN, lineIndex ); return opMIASN; } YY_BREAK case 23: YY_RULE_SETUP -#line 129 "CMDscan.l" +#line 133 "CMDscan.l" { CMDlval.i = MakeToken< int >( opMLASN, lineIndex ); return opMLASN; } YY_BREAK case 24: YY_RULE_SETUP -#line 130 "CMDscan.l" +#line 134 "CMDscan.l" { CMDlval.i = MakeToken< int >( opDVASN, lineIndex ); return opDVASN; } YY_BREAK case 25: YY_RULE_SETUP -#line 131 "CMDscan.l" +#line 135 "CMDscan.l" { CMDlval.i = MakeToken< int >( opMODASN, lineIndex ); return opMODASN; } YY_BREAK case 26: YY_RULE_SETUP -#line 132 "CMDscan.l" +#line 136 "CMDscan.l" { CMDlval.i = MakeToken< int >( opANDASN, lineIndex ); return opANDASN; } YY_BREAK case 27: YY_RULE_SETUP -#line 133 "CMDscan.l" +#line 137 "CMDscan.l" { CMDlval.i = MakeToken< int >( opXORASN, lineIndex ); return opXORASN; } YY_BREAK case 28: YY_RULE_SETUP -#line 134 "CMDscan.l" +#line 138 "CMDscan.l" { CMDlval.i = MakeToken< int >( opORASN, lineIndex ); return opORASN; } YY_BREAK case 29: YY_RULE_SETUP -#line 135 "CMDscan.l" +#line 139 "CMDscan.l" { CMDlval.i = MakeToken< int >( opSLASN, lineIndex ); return opSLASN; } YY_BREAK case 30: YY_RULE_SETUP -#line 136 "CMDscan.l" +#line 140 "CMDscan.l" { CMDlval.i = MakeToken< int >( opSRASN, lineIndex ); return opSRASN; } YY_BREAK case 31: YY_RULE_SETUP -#line 137 "CMDscan.l" +#line 141 "CMDscan.l" { CMDlval.i = MakeToken< int >( opINTNAME, lineIndex ); return opINTNAME; } YY_BREAK case 32: YY_RULE_SETUP -#line 138 "CMDscan.l" +#line 142 "CMDscan.l" { CMDlval.i = MakeToken< int >( opINTNAMER, lineIndex ); return opINTNAMER; } YY_BREAK case 33: YY_RULE_SETUP -#line 139 "CMDscan.l" +#line 143 "CMDscan.l" { CMDlval.i = MakeToken< int >( '\n', lineIndex ); return '@'; } YY_BREAK case 34: YY_RULE_SETUP -#line 140 "CMDscan.l" +#line 144 "CMDscan.l" { CMDlval.i = MakeToken< int >( '\t', lineIndex ); return '@'; } YY_BREAK case 35: YY_RULE_SETUP -#line 141 "CMDscan.l" +#line 145 "CMDscan.l" { CMDlval.i = MakeToken< int >( ' ', lineIndex ); return '@'; } YY_BREAK case 36: YY_RULE_SETUP -#line 142 "CMDscan.l" +#line 146 "CMDscan.l" { CMDlval.i = MakeToken< int >( 0, lineIndex ); return '@'; } YY_BREAK case 37: YY_RULE_SETUP -#line 143 "CMDscan.l" +#line 147 "CMDscan.l" { /* this comment stops syntax highlighting from getting messed up when editing the lexer in TextPad */ int c = 0, l; for ( ; ; ) @@ -1074,247 +1444,248 @@ YY_RULE_SETUP } YY_BREAK case 38: -#line 167 "CMDscan.l" -case 39: -#line 168 "CMDscan.l" -case 40: -#line 169 "CMDscan.l" -case 41: -#line 170 "CMDscan.l" -case 42: #line 171 "CMDscan.l" -case 43: +case 39: #line 172 "CMDscan.l" -case 44: +case 40: #line 173 "CMDscan.l" -case 45: +case 41: #line 174 "CMDscan.l" -case 46: +case 42: #line 175 "CMDscan.l" -case 47: +case 43: #line 176 "CMDscan.l" -case 48: +case 44: #line 177 "CMDscan.l" -case 49: +case 45: #line 178 "CMDscan.l" -case 50: +case 46: #line 179 "CMDscan.l" -case 51: +case 47: #line 180 "CMDscan.l" -case 52: +case 48: #line 181 "CMDscan.l" -case 53: +case 49: #line 182 "CMDscan.l" -case 54: +case 50: #line 183 "CMDscan.l" -case 55: +case 51: #line 184 "CMDscan.l" -case 56: +case 52: #line 185 "CMDscan.l" -case 57: +case 53: #line 186 "CMDscan.l" -case 58: +case 54: #line 187 "CMDscan.l" -case 59: +case 55: #line 188 "CMDscan.l" -case 60: +case 56: #line 189 "CMDscan.l" +case 57: +#line 190 "CMDscan.l" +case 58: +#line 191 "CMDscan.l" +case 59: +#line 192 "CMDscan.l" +case 60: +#line 193 "CMDscan.l" case 61: YY_RULE_SETUP -#line 189 "CMDscan.l" +#line 193 "CMDscan.l" { CMDlval.i = MakeToken< int >( CMDtext[ 0 ], lineIndex ); return CMDtext[ 0 ]; } YY_BREAK case 62: YY_RULE_SETUP -#line 190 "CMDscan.l" +#line 194 "CMDscan.l" { CMDlval.i = MakeToken< int >( rwIN, lineIndex ); return(rwIN); } YY_BREAK case 63: YY_RULE_SETUP -#line 191 "CMDscan.l" +#line 195 "CMDscan.l" { CMDlval.i = MakeToken< int >( rwCASEOR, lineIndex ); return(rwCASEOR); } YY_BREAK case 64: YY_RULE_SETUP -#line 192 "CMDscan.l" +#line 196 "CMDscan.l" { CMDlval.i = MakeToken< int >( rwBREAK, lineIndex ); return(rwBREAK); } YY_BREAK case 65: YY_RULE_SETUP -#line 193 "CMDscan.l" +#line 197 "CMDscan.l" { CMDlval.i = MakeToken< int >( rwRETURN, lineIndex ); return(rwRETURN); } YY_BREAK case 66: YY_RULE_SETUP -#line 194 "CMDscan.l" +#line 198 "CMDscan.l" { CMDlval.i = MakeToken< int >( rwELSE, lineIndex ); return(rwELSE); } YY_BREAK case 67: YY_RULE_SETUP -#line 195 "CMDscan.l" +#line 199 "CMDscan.l" { CMDlval.i = MakeToken< int >( rwASSERT, lineIndex ); return(rwASSERT); } YY_BREAK case 68: YY_RULE_SETUP -#line 196 "CMDscan.l" +#line 200 "CMDscan.l" { CMDlval.i = MakeToken< int >( rwWHILE, lineIndex ); return(rwWHILE); } YY_BREAK case 69: YY_RULE_SETUP -#line 197 "CMDscan.l" +#line 201 "CMDscan.l" { CMDlval.i = MakeToken< int >( rwDO, lineIndex ); return(rwDO); } YY_BREAK case 70: YY_RULE_SETUP -#line 198 "CMDscan.l" +#line 202 "CMDscan.l" { CMDlval.i = MakeToken< int >( rwIF, lineIndex ); return(rwIF); } YY_BREAK case 71: YY_RULE_SETUP -#line 199 "CMDscan.l" +#line 203 "CMDscan.l" { CMDlval.i = MakeToken< int >( rwFOREACHSTR, lineIndex ); return(rwFOREACHSTR); } YY_BREAK case 72: YY_RULE_SETUP -#line 200 "CMDscan.l" +#line 204 "CMDscan.l" { CMDlval.i = MakeToken< int >( rwFOREACH, lineIndex ); return(rwFOREACH); } YY_BREAK case 73: YY_RULE_SETUP -#line 201 "CMDscan.l" +#line 205 "CMDscan.l" { CMDlval.i = MakeToken< int >( rwFOR, lineIndex ); return(rwFOR); } YY_BREAK case 74: YY_RULE_SETUP -#line 202 "CMDscan.l" +#line 206 "CMDscan.l" { CMDlval.i = MakeToken< int >( rwCONTINUE, lineIndex ); return(rwCONTINUE); } YY_BREAK case 75: YY_RULE_SETUP -#line 203 "CMDscan.l" +#line 207 "CMDscan.l" { CMDlval.i = MakeToken< int >( rwDEFINE, lineIndex ); return(rwDEFINE); } YY_BREAK case 76: YY_RULE_SETUP -#line 204 "CMDscan.l" +#line 208 "CMDscan.l" { CMDlval.i = MakeToken< int >( rwDECLARE, lineIndex ); return(rwDECLARE); } YY_BREAK case 77: YY_RULE_SETUP -#line 205 "CMDscan.l" +#line 209 "CMDscan.l" { CMDlval.i = MakeToken< int >( rwDECLARESINGLETON, lineIndex ); return(rwDECLARESINGLETON); } YY_BREAK case 78: YY_RULE_SETUP -#line 206 "CMDscan.l" +#line 210 "CMDscan.l" { CMDlval.i = MakeToken< int >( rwDATABLOCK, lineIndex ); return(rwDATABLOCK); } YY_BREAK case 79: YY_RULE_SETUP -#line 207 "CMDscan.l" +#line 211 "CMDscan.l" { CMDlval.i = MakeToken< int >( rwCASE, lineIndex ); return(rwCASE); } YY_BREAK case 80: YY_RULE_SETUP -#line 208 "CMDscan.l" +#line 212 "CMDscan.l" { CMDlval.i = MakeToken< int >( rwSWITCHSTR, lineIndex ); return(rwSWITCHSTR); } YY_BREAK case 81: YY_RULE_SETUP -#line 209 "CMDscan.l" +#line 213 "CMDscan.l" { CMDlval.i = MakeToken< int >( rwSWITCH, lineIndex ); return(rwSWITCH); } YY_BREAK case 82: YY_RULE_SETUP -#line 210 "CMDscan.l" +#line 214 "CMDscan.l" { CMDlval.i = MakeToken< int >( rwDEFAULT, lineIndex ); return(rwDEFAULT); } YY_BREAK case 83: YY_RULE_SETUP -#line 211 "CMDscan.l" +#line 215 "CMDscan.l" { CMDlval.i = MakeToken< int >( rwPACKAGE, lineIndex ); return(rwPACKAGE); } YY_BREAK case 84: YY_RULE_SETUP -#line 212 "CMDscan.l" +#line 216 "CMDscan.l" { CMDlval.i = MakeToken< int >( rwNAMESPACE, lineIndex ); return(rwNAMESPACE); } YY_BREAK case 85: YY_RULE_SETUP -#line 213 "CMDscan.l" +#line 217 "CMDscan.l" { CMDlval.i = MakeToken< int >( 1, lineIndex ); return INTCONST; } YY_BREAK case 86: YY_RULE_SETUP -#line 214 "CMDscan.l" +#line 218 "CMDscan.l" { CMDlval.i = MakeToken< int >( 0, lineIndex ); return INTCONST; } YY_BREAK case 87: YY_RULE_SETUP -#line 215 "CMDscan.l" +#line 219 "CMDscan.l" { return(Sc_ScanVar()); } YY_BREAK case 88: YY_RULE_SETUP -#line 216 "CMDscan.l" +#line 221 "CMDscan.l" { return Sc_ScanIdent(); } YY_BREAK case 89: YY_RULE_SETUP -#line 217 "CMDscan.l" +#line 222 "CMDscan.l" return(Sc_ScanHex()); YY_BREAK case 90: YY_RULE_SETUP -#line 218 "CMDscan.l" +#line 223 "CMDscan.l" { CMDtext[CMDleng] = 0; CMDlval.i = MakeToken< int >( dAtoi(CMDtext), lineIndex ); return INTCONST; } YY_BREAK case 91: YY_RULE_SETUP -#line 219 "CMDscan.l" +#line 224 "CMDscan.l" return Sc_ScanNum(); YY_BREAK case 92: YY_RULE_SETUP -#line 220 "CMDscan.l" +#line 225 "CMDscan.l" return(ILLEGAL_TOKEN); YY_BREAK case 93: YY_RULE_SETUP -#line 221 "CMDscan.l" +#line 226 "CMDscan.l" return(ILLEGAL_TOKEN); YY_BREAK case 94: YY_RULE_SETUP -#line 222 "CMDscan.l" +#line 227 "CMDscan.l" ECHO; YY_BREAK -#line 1291 "CMDscan.cpp" +#line 1662 "CMDscan.cpp" 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 @@ -1324,13 +1695,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 @@ -1343,30 +1714,30 @@ 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_c_buf_p; + yy_cp = (yy_c_buf_p); 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 @@ -1377,7 +1748,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; @@ -1385,30 +1756,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; @@ -1419,8 +1790,8 @@ 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 user's declarations */ +} /* end of yylex */ /* yy_get_next_buffer - try to read in a new buffer * @@ -1429,23 +1800,22 @@ 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() - { - char *dest = yy_current_buffer->yy_ch_buf; - char *source = yytext_ptr; - int number_to_move, i; +static int yy_get_next_buffer (void) +{ + char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + char *source = (yytext_ptr); + 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 singled characater, the EOB, so + /* We matched a single character, the EOB, so * treat this as a final EOF. */ return EOB_ACT_END_OF_FILE; @@ -1463,34 +1833,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_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_LVALUE; 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 ) { @@ -1503,44 +1869,46 @@ 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, + (yy_size_t) (b->yy_buf_size + 2) ); } else /* Can't grow it, we don't own it. */ - b->yy_ch_buf = 0; + b->yy_ch_buf = NULL; if ( ! b->yy_ch_buf ) 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), num_to_read ); + + 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; } } @@ -1548,162 +1916,175 @@ 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_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + /* Extend the array by 50%, plus the number we really need. */ + int 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, (yy_size_t) new_size ); + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); + /* "- 2" to take care of EOB's */ + YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2); } + (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() - { - yy_state_type yy_current_state; - char *yy_cp; + static yy_state_type yy_get_previous_state (void) +{ + yy_state_type yy_current_state; + 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 ) { - YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + 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 >= 224 ) - yy_c = yy_meta[(unsigned int) yy_c]; + yy_c = yy_meta[yy_c]; } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_current_state = yy_nxt[yy_base[yy_current_state] + 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 ); */ + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) +{ + int yy_is_jam; + char *yy_cp = (yy_c_buf_p); -#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 - { - int yy_is_jam; - char *yy_cp = yy_c_buf_p; - - YY_CHAR yy_c = 1; + 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 >= 224 ) - yy_c = yy_meta[(unsigned int) yy_c]; + yy_c = yy_meta[yy_c]; } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; yy_is_jam = (yy_current_state == 223); - return yy_is_jam ? 0 : yy_current_state; - } - + return yy_is_jam ? 0 : yy_current_state; +} #ifndef YY_NO_UNPUT -#ifdef YY_USE_PROTOS -static void yyunput( int c, char *yy_bp ) -#else -static void yyunput( c, yy_bp ) -int c; -char *yy_bp; -#endif - { - char *yy_cp = yy_c_buf_p; + + static void yyunput (int c, char * yy_bp ) +{ + char *yy_cp; + + yy_cp = (yy_c_buf_p); /* undo effects of setting up yytext */ - *yy_cp = yy_hold_char; + *yy_cp = (yy_hold_char); - if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) { /* need to shift things up to make room */ /* +2 for EOB chars. */ - int number_to_move = yy_n_chars + 2; - char *dest = &yy_current_buffer->yy_ch_buf[ - yy_current_buffer->yy_buf_size + 2]; + int number_to_move = (yy_n_chars) + 2; + char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ + YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; char *source = - &yy_current_buffer->yy_ch_buf[number_to_move]; + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; - while ( source > yy_current_buffer->yy_ch_buf ) + while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) *--dest = *--source; yy_cp += (int) (dest - source); yy_bp += (int) (dest - source); - yy_n_chars = yy_current_buffer->yy_buf_size; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = + (yy_n_chars) = (int) YY_CURRENT_BUFFER_LVALUE->yy_buf_size; - if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->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; +} - yytext_ptr = yy_bp; - yy_hold_char = *yy_cp; - yy_c_buf_p = yy_cp; - } -#endif /* ifndef YY_NO_UNPUT */ - - -#ifdef __cplusplus -static int yyinput() -#else -static int input() #endif - { + +#ifndef YY_NO_INPUT +#ifdef __cplusplus + static int yyinput (void) +#else + 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 */ - yytext_ptr = yy_c_buf_p; - ++yy_c_buf_p; + int offset = (int) ((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() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + yyrestart( yyin ); + + /*FALLTHROUGH*/ + case EOB_ACT_END_OF_FILE: { - if ( yywrap() ) - { - yy_c_buf_p = - yytext_ptr + YY_MORE_ADJ; - return EOF; - } + if ( yywrap( ) ) + return 0; - if ( ! yy_did_buffer_switch_on_eof ) + if ( ! (yy_did_buffer_switch_on_eof) ) YY_NEW_FILE; #ifdef __cplusplus return yyinput(); @@ -1713,99 +2094,92 @@ static int input() } case EOB_ACT_CONTINUE_SCAN: - yy_c_buf_p = yytext_ptr + YY_MORE_ADJ; + (yy_c_buf_p) = (yytext_ptr) + offset; break; - - case EOB_ACT_LAST_MATCH: -#ifdef __cplusplus - YY_FATAL_ERROR( - "unexpected last match in yyinput()" ); -#else - YY_FATAL_ERROR( - "unexpected last match in input()" ); -#endif } } } - 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()" ); @@ -1814,7 +2188,7 @@ 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( (yy_size_t) (b->yy_buf_size + 2) ); if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); @@ -1823,70 +2197,64 @@ int size; 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 - - - { +{ + 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 = file ? (isatty( fileno(file) ) > 0) : 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 +/** 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; /* We always need two end-of-buffer characters. The first causes @@ -1901,90 +2269,181 @@ 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) +{ + yy_size_t 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; /* After all that talk, this was set to 1 anyways... */ + (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. */ + yy_size_t 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; + return NULL; - 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()" ); - b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ + b->yy_buf_size = (int) (size - 2); /* "- 2" to take care of EOB's */ b->yy_buf_pos = b->yy_ch_buf = base; b->yy_is_our_buffer = 0; - b->yy_input_file = 0; + b->yy_input_file = NULL; b->yy_n_chars = b->yy_buf_size; b->yy_is_interactive = 0; b->yy_at_bol = 1; 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 (const char * yystr ) +{ + + return yy_scan_bytes( yystr, (int) strlen(yystr) ); +} -#ifndef YY_NO_SCAN_STRING -#ifdef YY_USE_PROTOS -YY_BUFFER_STATE yy_scan_string( yyconst char *str ) -#else -YY_BUFFER_STATE yy_scan_string( str ) -yyconst char *str; -#endif - { - int len; - for ( len = 0; str[len]; ++len ) - ; - - return yy_scan_bytes( 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 yybytes the byte buffer to scan + * @param _yybytes_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 (const 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 = (yy_size_t) (_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 ); if ( ! b ) @@ -1996,78 +2455,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 yynoreturn yy_fatal_error (const char* msg ) +{ + fprintf( stderr, "%s\n", msg ); exit( YY_EXIT_FAILURE ); - } - - +} /* Redefine yyless() so it works in section 3 code. */ @@ -2076,52 +2474,179 @@ char msg[]; do \ { \ /* Undo effects of setting up yytext. */ \ - yytext[yyleng] = yy_hold_char; \ - yy_c_buf_p = yytext + n - YY_MORE_ADJ; \ - 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 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) = NULL; + (yy_buffer_stack_top) = 0; + (yy_buffer_stack_max) = 0; + (yy_c_buf_p) = NULL; + (yy_init) = 0; + (yy_start) = 0; + +/* Defined in main.c */ +#ifdef YY_STDINIT + yyin = stdin; + yyout = stdout; +#else + yyin = NULL; + yyout = NULL; +#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 - { - int i; +static void yy_flex_strncpy (char* s1, const char * s2, int n ) +{ + + int i; for ( i = 0; i < n; ++i ) s1[i] = s2[i]; - } +} #endif +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (const char * s ) +{ + int n; + for ( n = 0; s[n]; ++n ) + ; -#ifdef YY_USE_PROTOS -static void *yy_flex_alloc( yy_size_t size ) -#else -static void *yy_flex_alloc( size ) -yy_size_t size; + return n; +} #endif - { - 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 *yyalloc (yy_size_t size ) +{ + return malloc(size); +} + +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 @@ -2129,27 +2654,17 @@ yy_size_t size; * any pointer type to void*, and deal with argument conversions * as though doing an assignment. */ - return (void *) realloc( (char *) ptr, size ); - } + return realloc(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 222 "CMDscan.l" +#define YYTABLES_NAME "yytables" + +#line 227 "CMDscan.l" static const char *scanBuffer; @@ -2340,7 +2855,7 @@ static int Sc_ScanDocBlock() static int Sc_ScanString(int ret) { CMDtext[CMDleng - 1] = 0; - if(!TorqueScript::getRuntime()->collapseEscapedCharacters(CMDtext+1)) + if(!collapseEscape(CMDtext+1)) return -1; dsize_t bufferLen = dStrlen( CMDtext ); @@ -2555,3 +3070,4 @@ void CMD_reset() { CMDrestart(NULL); } + diff --git a/Engine/source/console/torquescript/CMDscan.l b/Engine/source/console/torquescript/CMDscan.l index ab2c61a72..08d965075 100644 --- a/Engine/source/console/torquescript/CMDscan.l +++ b/Engine/source/console/torquescript/CMDscan.l @@ -9,7 +9,7 @@ #include "platform/platform.h" #include "core/stringTable.h" #include "console/console.h" -#include "console/compiler.h" +#include "console/torquescript/compiler.h" #include "console/dynamicTypes.h" #include "core/strings/stringFunctions.h" @@ -30,7 +30,7 @@ inline Token< T > MakeToken( T value, U32 lineNumber ) return result; } -#include "console/cmdgram.h" +#include "console/torquescript/CMDgram.h" // HACK: C++17 and beyond can't use register keyword #define register diff --git a/Engine/source/console/torquescript/astNodes.cpp b/Engine/source/console/torquescript/astNodes.cpp index fcf2b69c2..cc911477d 100644 --- a/Engine/source/console/torquescript/astNodes.cpp +++ b/Engine/source/console/torquescript/astNodes.cpp @@ -35,7 +35,7 @@ struct Token T value; S32 lineNumber; }; -#include "cmdgram.h" +#include "CMDgram.h" namespace Compiler { diff --git a/Engine/source/console/torquescript/bison.bat b/Engine/source/console/torquescript/bison.bat index d48aaebbb..275a99c72 100644 --- a/Engine/source/console/torquescript/bison.bat +++ b/Engine/source/console/torquescript/bison.bat @@ -1,6 +1,6 @@ echo Changing to %4 ... cd %4 echo Generating %2 and %3 with prefix %1. -..\..\bin\bison\bison.exe -o %2 %3 --defines -p %1 +..\..\..\bin\bison-flex\win_bison.exe -o %2 %3 --defines -p %1 -H echo Renaming %2 to %5 . move /Y %2 %5 \ No newline at end of file diff --git a/Engine/source/console/torquescript/cmdgram.cpp b/Engine/source/console/torquescript/cmdgram.cpp index 34c7737d3..479b9c1e0 100644 --- a/Engine/source/console/torquescript/cmdgram.cpp +++ b/Engine/source/console/torquescript/cmdgram.cpp @@ -1,90 +1,80 @@ +/* A Bison parser, made by GNU Bison 3.8.2. */ -/* A Bison parser, made from cmdgram.y with Bison version GNU Bison version 1.24 - */ +/* Bison implementation for Yacc-like parsers in C -#define YYBISON 1 /* Identify Bison output. */ + Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, + Inc. -#define yyparse CMDparse -#define yylex CMDlex -#define yyerror CMDerror -#define yylval CMDlval -#define yychar CMDchar -#define yydebug CMDdebug -#define yynerrs CMDnerrs -#define rwDEFINE 258 -#define rwENDDEF 259 -#define rwDECLARE 260 -#define rwDECLARESINGLETON 261 -#define rwBREAK 262 -#define rwELSE 263 -#define rwCONTINUE 264 -#define rwGLOBAL 265 -#define rwIF 266 -#define rwNIL 267 -#define rwRETURN 268 -#define rwWHILE 269 -#define rwDO 270 -#define rwENDIF 271 -#define rwENDWHILE 272 -#define rwENDFOR 273 -#define rwDEFAULT 274 -#define rwFOR 275 -#define rwFOREACH 276 -#define rwFOREACHSTR 277 -#define rwIN 278 -#define rwDATABLOCK 279 -#define rwSWITCH 280 -#define rwCASE 281 -#define rwSWITCHSTR 282 -#define rwCASEOR 283 -#define rwPACKAGE 284 -#define rwNAMESPACE 285 -#define rwCLASS 286 -#define rwASSERT 287 -#define ILLEGAL_TOKEN 288 -#define CHRCONST 289 -#define INTCONST 290 -#define TTAG 291 -#define VAR 292 -#define IDENT 293 -#define TYPEIDENT 294 -#define DOCBLOCK 295 -#define STRATOM 296 -#define TAGATOM 297 -#define FLTCONST 298 -#define opINTNAME 299 -#define opINTNAMER 300 -#define opMINUSMINUS 301 -#define opPLUSPLUS 302 -#define STMT_SEP 303 -#define opSHL 304 -#define opSHR 305 -#define opPLASN 306 -#define opMIASN 307 -#define opMLASN 308 -#define opDVASN 309 -#define opMODASN 310 -#define opANDASN 311 -#define opXORASN 312 -#define opORASN 313 -#define opSLASN 314 -#define opSRASN 315 -#define opCAT 316 -#define opEQ 317 -#define opNE 318 -#define opGE 319 -#define opLE 320 -#define opAND 321 -#define opOR 322 -#define opSTREQ 323 -#define opCOLONCOLON 324 -#define opMDASN 325 -#define opNDASN 326 -#define opNTASN 327 -#define opSTRNE 328 -#define UNARY 329 + 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -#line 1 "cmdgram.y" + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +/* C LALR(1) parser skeleton written by Richard Stallman, by + simplifying the original so-called "semantic" parser. */ + +/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, + especially those whose name start with YY_ or yy_. They are + private implementation details that can be changed or removed. */ + +/* All symbols defined below should begin with yy or YY, to avoid + infringing on user name space. This should be done even for local + variables, as they might otherwise be expanded by user macros. + There are some unavoidable exceptions within include files to + define necessary library symbols; they are noted "INFRINGES ON + USER NAME SPACE" below. */ + +/* Identify Bison output, and Bison version. */ +#define YYBISON 30802 + +/* Bison version string. */ +#define YYBISON_VERSION "3.8.2" + +/* Skeleton name. */ +#define YYSKELETON_NAME "yacc.c" + +/* Pure parsers. */ +#define YYPURE 0 + +/* Push parsers. */ +#define YYPUSH 0 + +/* Pull parsers. */ +#define YYPULL 1 + + +/* Substitute the variable and function names. */ +#define yyparse CMDparse +#define yylex CMDlex +#define yyerror CMDerror +#define yydebug CMDdebug +#define yynerrs CMDnerrs +#define yylval CMDlval +#define yychar CMDchar + +/* First part of user prologue. */ +#line 1 "CMDgram.y" // bison --defines=cmdgram.h --verbose -o cmdgram.cpp -p CMD CMDgram.y @@ -95,7 +85,7 @@ #include #include #include "console/console.h" -#include "compiler.h" +#include "console/torquescript/compiler.h" #include "console/consoleInternal.h" #include "core/strings/stringFunctions.h" @@ -127,2266 +117,3017 @@ struct Token U32 lineNumber; }; -#line 44 "cmdgram.y" +#line 44 "CMDgram.y" /* Reserved Word Definitions */ -#line 55 "cmdgram.y" +#line 55 "CMDgram.y" /* Constants and Identifier Definitions */ -#line 69 "cmdgram.y" +#line 69 "CMDgram.y" /* Operator Definitions */ -#line 82 "cmdgram.y" -typedef union { - Token< char > c; - Token< int > i; - Token< const char* > s; - Token< char* > str; - Token< double > f; - StmtNode* stmt; - ExprNode* expr; - SlotAssignNode* slist; - VarNode* var; - SlotDecl slot; - InternalSlotDecl intslot; - ObjectBlockDecl odcl; - ObjectDeclNode* od; - AssignDecl asn; - IfStmtNode* ifnode; -} YYSTYPE; +#line 131 "CMDgram.c" -#ifndef YYLTYPE -typedef - struct yyltype - { - int timestamp; - int first_line; - int first_column; - int last_line; - int last_column; - char *text; - } - yyltype; +# ifndef YY_CAST +# ifdef __cplusplus +# define YY_CAST(Type, Val) static_cast (Val) +# define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast (Val) +# else +# define YY_CAST(Type, Val) ((Type) (Val)) +# define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val)) +# endif +# endif +# ifndef YY_NULLPTR +# if defined __cplusplus +# if 201103L <= __cplusplus +# define YY_NULLPTR nullptr +# else +# define YY_NULLPTR 0 +# endif +# else +# define YY_NULLPTR ((void*)0) +# endif +# endif -#define YYLTYPE yyltype +#include "CMDgram.h" +/* Symbol kind. */ +enum yysymbol_kind_t +{ + YYSYMBOL_YYEMPTY = -2, + YYSYMBOL_YYEOF = 0, /* "end of file" */ + YYSYMBOL_YYerror = 1, /* error */ + YYSYMBOL_YYUNDEF = 2, /* "invalid token" */ + YYSYMBOL_rwDEFINE = 3, /* rwDEFINE */ + YYSYMBOL_rwENDDEF = 4, /* rwENDDEF */ + YYSYMBOL_rwDECLARE = 5, /* rwDECLARE */ + YYSYMBOL_rwDECLARESINGLETON = 6, /* rwDECLARESINGLETON */ + YYSYMBOL_rwBREAK = 7, /* rwBREAK */ + YYSYMBOL_rwELSE = 8, /* rwELSE */ + YYSYMBOL_rwCONTINUE = 9, /* rwCONTINUE */ + YYSYMBOL_rwGLOBAL = 10, /* rwGLOBAL */ + YYSYMBOL_rwIF = 11, /* rwIF */ + YYSYMBOL_rwNIL = 12, /* rwNIL */ + YYSYMBOL_rwRETURN = 13, /* rwRETURN */ + YYSYMBOL_rwWHILE = 14, /* rwWHILE */ + YYSYMBOL_rwDO = 15, /* rwDO */ + YYSYMBOL_rwENDIF = 16, /* rwENDIF */ + YYSYMBOL_rwENDWHILE = 17, /* rwENDWHILE */ + YYSYMBOL_rwENDFOR = 18, /* rwENDFOR */ + YYSYMBOL_rwDEFAULT = 19, /* rwDEFAULT */ + YYSYMBOL_rwFOR = 20, /* rwFOR */ + YYSYMBOL_rwFOREACH = 21, /* rwFOREACH */ + YYSYMBOL_rwFOREACHSTR = 22, /* rwFOREACHSTR */ + YYSYMBOL_rwIN = 23, /* rwIN */ + YYSYMBOL_rwDATABLOCK = 24, /* rwDATABLOCK */ + YYSYMBOL_rwSWITCH = 25, /* rwSWITCH */ + YYSYMBOL_rwCASE = 26, /* rwCASE */ + YYSYMBOL_rwSWITCHSTR = 27, /* rwSWITCHSTR */ + YYSYMBOL_rwCASEOR = 28, /* rwCASEOR */ + YYSYMBOL_rwPACKAGE = 29, /* rwPACKAGE */ + YYSYMBOL_rwNAMESPACE = 30, /* rwNAMESPACE */ + YYSYMBOL_rwCLASS = 31, /* rwCLASS */ + YYSYMBOL_rwASSERT = 32, /* rwASSERT */ + YYSYMBOL_ILLEGAL_TOKEN = 33, /* ILLEGAL_TOKEN */ + YYSYMBOL_CHRCONST = 34, /* CHRCONST */ + YYSYMBOL_INTCONST = 35, /* INTCONST */ + YYSYMBOL_TTAG = 36, /* TTAG */ + YYSYMBOL_VAR = 37, /* VAR */ + YYSYMBOL_IDENT = 38, /* IDENT */ + YYSYMBOL_TYPEIDENT = 39, /* TYPEIDENT */ + YYSYMBOL_DOCBLOCK = 40, /* DOCBLOCK */ + YYSYMBOL_STRATOM = 41, /* STRATOM */ + YYSYMBOL_TAGATOM = 42, /* TAGATOM */ + YYSYMBOL_FLTCONST = 43, /* FLTCONST */ + YYSYMBOL_44_ = 44, /* '+' */ + YYSYMBOL_45_ = 45, /* '-' */ + YYSYMBOL_46_ = 46, /* '*' */ + YYSYMBOL_47_ = 47, /* '/' */ + YYSYMBOL_48_ = 48, /* '<' */ + YYSYMBOL_49_ = 49, /* '>' */ + YYSYMBOL_50_ = 50, /* '=' */ + YYSYMBOL_51_ = 51, /* '.' */ + YYSYMBOL_52_ = 52, /* '|' */ + YYSYMBOL_53_ = 53, /* '&' */ + YYSYMBOL_54_ = 54, /* '%' */ + YYSYMBOL_55_ = 55, /* '(' */ + YYSYMBOL_56_ = 56, /* ')' */ + YYSYMBOL_57_ = 57, /* ',' */ + YYSYMBOL_58_ = 58, /* ':' */ + YYSYMBOL_59_ = 59, /* ';' */ + YYSYMBOL_60_ = 60, /* '{' */ + YYSYMBOL_61_ = 61, /* '}' */ + YYSYMBOL_62_ = 62, /* '^' */ + YYSYMBOL_63_ = 63, /* '~' */ + YYSYMBOL_64_ = 64, /* '!' */ + YYSYMBOL_65_ = 65, /* '@' */ + YYSYMBOL_opINTNAME = 66, /* opINTNAME */ + YYSYMBOL_opINTNAMER = 67, /* opINTNAMER */ + YYSYMBOL_opMINUSMINUS = 68, /* opMINUSMINUS */ + YYSYMBOL_opPLUSPLUS = 69, /* opPLUSPLUS */ + YYSYMBOL_STMT_SEP = 70, /* STMT_SEP */ + YYSYMBOL_opSHL = 71, /* opSHL */ + YYSYMBOL_opSHR = 72, /* opSHR */ + YYSYMBOL_opPLASN = 73, /* opPLASN */ + YYSYMBOL_opMIASN = 74, /* opMIASN */ + YYSYMBOL_opMLASN = 75, /* opMLASN */ + YYSYMBOL_opDVASN = 76, /* opDVASN */ + YYSYMBOL_opMODASN = 77, /* opMODASN */ + YYSYMBOL_opANDASN = 78, /* opANDASN */ + YYSYMBOL_opXORASN = 79, /* opXORASN */ + YYSYMBOL_opORASN = 80, /* opORASN */ + YYSYMBOL_opSLASN = 81, /* opSLASN */ + YYSYMBOL_opSRASN = 82, /* opSRASN */ + YYSYMBOL_opCAT = 83, /* opCAT */ + YYSYMBOL_opEQ = 84, /* opEQ */ + YYSYMBOL_opNE = 85, /* opNE */ + YYSYMBOL_opGE = 86, /* opGE */ + YYSYMBOL_opLE = 87, /* opLE */ + YYSYMBOL_opAND = 88, /* opAND */ + YYSYMBOL_opOR = 89, /* opOR */ + YYSYMBOL_opSTREQ = 90, /* opSTREQ */ + YYSYMBOL_opCOLONCOLON = 91, /* opCOLONCOLON */ + YYSYMBOL_92_ = 92, /* '[' */ + YYSYMBOL_opMDASN = 93, /* opMDASN */ + YYSYMBOL_opNDASN = 94, /* opNDASN */ + YYSYMBOL_opNTASN = 95, /* opNTASN */ + YYSYMBOL_96_ = 96, /* '?' */ + YYSYMBOL_opSTRNE = 97, /* opSTRNE */ + YYSYMBOL_UNARY = 98, /* UNARY */ + YYSYMBOL_99_ = 99, /* ']' */ + YYSYMBOL_YYACCEPT = 100, /* $accept */ + YYSYMBOL_start = 101, /* start */ + YYSYMBOL_decl_list = 102, /* decl_list */ + YYSYMBOL_decl = 103, /* decl */ + YYSYMBOL_package_decl = 104, /* package_decl */ + YYSYMBOL_fn_decl_list = 105, /* fn_decl_list */ + YYSYMBOL_statement_list = 106, /* statement_list */ + YYSYMBOL_stmt = 107, /* stmt */ + YYSYMBOL_fn_decl_stmt = 108, /* fn_decl_stmt */ + YYSYMBOL_var_list_decl = 109, /* var_list_decl */ + YYSYMBOL_var_list = 110, /* var_list */ + YYSYMBOL_datablock_decl = 111, /* datablock_decl */ + YYSYMBOL_object_decl = 112, /* object_decl */ + YYSYMBOL_parent_block = 113, /* parent_block */ + YYSYMBOL_object_name = 114, /* object_name */ + YYSYMBOL_object_args = 115, /* object_args */ + YYSYMBOL_object_declare_block = 116, /* object_declare_block */ + YYSYMBOL_object_decl_list = 117, /* object_decl_list */ + YYSYMBOL_stmt_block = 118, /* stmt_block */ + YYSYMBOL_switch_stmt = 119, /* switch_stmt */ + YYSYMBOL_case_block = 120, /* case_block */ + YYSYMBOL_case_expr = 121, /* case_expr */ + YYSYMBOL_if_stmt = 122, /* if_stmt */ + YYSYMBOL_while_stmt = 123, /* while_stmt */ + YYSYMBOL_for_stmt = 124, /* for_stmt */ + YYSYMBOL_foreach_stmt = 125, /* foreach_stmt */ + YYSYMBOL_expression_stmt = 126, /* expression_stmt */ + YYSYMBOL_expr = 127, /* expr */ + YYSYMBOL_slot_acc = 128, /* slot_acc */ + YYSYMBOL_intslot_acc = 129, /* intslot_acc */ + YYSYMBOL_class_name_expr = 130, /* class_name_expr */ + YYSYMBOL_assign_op_struct = 131, /* assign_op_struct */ + YYSYMBOL_stmt_expr = 132, /* stmt_expr */ + YYSYMBOL_funcall_expr = 133, /* funcall_expr */ + YYSYMBOL_assert_expr = 134, /* assert_expr */ + YYSYMBOL_expr_list_decl = 135, /* expr_list_decl */ + YYSYMBOL_expr_list = 136, /* expr_list */ + YYSYMBOL_slot_assign_list_opt = 137, /* slot_assign_list_opt */ + YYSYMBOL_slot_assign_list = 138, /* slot_assign_list */ + YYSYMBOL_slot_assign = 139, /* slot_assign */ + YYSYMBOL_aidx_expr = 140 /* aidx_expr */ +}; +typedef enum yysymbol_kind_t yysymbol_kind_t; + + + + +#ifdef short +# undef short #endif -#include +/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure + and (if available) are included + so that the code can choose integer types of a good width. */ -#ifndef __cplusplus -#ifndef __STDC__ -#define const -#endif +#ifndef __PTRDIFF_MAX__ +# include /* INFRINGES ON USER NAME SPACE */ +# if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_STDINT_H +# endif #endif +/* Narrow types that promote to a signed type and that can represent a + signed or unsigned integer of at least N bits. In tables they can + save space and decrease cache pressure. Promoting to a signed type + helps avoid bugs in integer arithmetic. */ - -#define YYFINAL 380 -#define YYFLAG -32768 -#define YYNTBASE 100 - -#define YYTRANSLATE(x) ((unsigned)(x) <= 329 ? yytranslate[x] : 140) - -static const char yytranslate[] = { 0, - 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, 64, 2, 2, 2, 54, 53, 2, 55, - 56, 46, 44, 57, 45, 51, 47, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 58, 59, 48, - 50, 49, 96, 65, 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, - 92, 2, 99, 62, 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, 60, 52, 61, 63, 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, 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, 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, 1, 2, 3, 4, 5, - 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, - 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, - 36, 37, 38, 39, 40, 41, 42, 43, 66, 67, - 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, - 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, - 88, 89, 90, 91, 93, 94, 95, 97, 98 -}; - -#if YYDEBUG != 0 -static const short yyprhs[] = { 0, - 0, 2, 3, 6, 8, 10, 12, 19, 21, 24, - 25, 28, 30, 32, 34, 36, 38, 40, 43, 46, - 49, 53, 56, 61, 68, 70, 79, 90, 91, 93, - 95, 99, 110, 121, 129, 142, 152, 163, 171, 172, - 175, 176, 178, 179, 182, 183, 185, 187, 190, 193, - 197, 201, 203, 211, 219, 224, 232, 238, 240, 244, - 250, 258, 264, 271, 281, 290, 299, 307, 316, 324, - 332, 339, 347, 355, 357, 359, 363, 367, 371, 375, - 379, 383, 387, 391, 395, 398, 401, 403, 409, 413, - 417, 421, 425, 429, 433, 437, 441, 445, 449, 453, - 457, 461, 464, 467, 469, 471, 473, 475, 477, 479, - 481, 483, 485, 490, 494, 501, 505, 509, 511, 515, - 517, 519, 522, 525, 528, 531, 534, 537, 540, 543, - 546, 549, 551, 553, 555, 559, 566, 569, 575, 578, - 582, 588, 593, 600, 607, 612, 619, 620, 622, 624, - 628, 629, 631, 633, 636, 641, 647, 652, 660, 669, - 671 -}; - -static const short yyrhs[] = { 101, - 0, 0, 101, 102, 0, 106, 0, 107, 0, 103, - 0, 29, 38, 60, 104, 61, 59, 0, 107, 0, - 104, 107, 0, 0, 105, 106, 0, 121, 0, 122, - 0, 123, 0, 124, 0, 110, 0, 118, 0, 7, - 59, 0, 9, 59, 0, 13, 59, 0, 13, 126, - 59, 0, 125, 59, 0, 36, 50, 126, 59, 0, - 36, 50, 126, 57, 126, 59, 0, 40, 0, 3, - 38, 55, 108, 56, 60, 105, 61, 0, 3, 38, - 91, 38, 55, 108, 56, 60, 105, 61, 0, 0, - 109, 0, 37, 0, 109, 57, 37, 0, 24, 129, - 55, 126, 112, 56, 60, 136, 61, 59, 0, 5, - 129, 55, 113, 112, 114, 56, 60, 115, 61, 0, - 5, 129, 55, 113, 112, 114, 56, 0, 5, 129, - 55, 92, 113, 99, 112, 114, 56, 60, 115, 61, - 0, 5, 129, 55, 92, 113, 99, 112, 114, 56, - 0, 6, 129, 55, 113, 112, 114, 56, 60, 115, - 61, 0, 6, 129, 55, 113, 112, 114, 56, 0, - 0, 58, 38, 0, 0, 126, 0, 0, 57, 135, - 0, 0, 137, 0, 116, 0, 137, 116, 0, 111, - 59, 0, 116, 111, 59, 0, 60, 105, 61, 0, - 106, 0, 25, 55, 126, 56, 60, 119, 61, 0, - 27, 55, 126, 56, 60, 119, 61, 0, 26, 120, - 58, 105, 0, 26, 120, 58, 105, 19, 58, 105, - 0, 26, 120, 58, 105, 119, 0, 126, 0, 120, - 28, 126, 0, 11, 55, 126, 56, 117, 0, 11, - 55, 126, 56, 117, 8, 117, 0, 14, 55, 126, - 56, 117, 0, 15, 117, 14, 55, 126, 56, 0, - 20, 55, 126, 59, 126, 59, 126, 56, 117, 0, - 20, 55, 126, 59, 126, 59, 56, 117, 0, 20, - 55, 126, 59, 59, 126, 56, 117, 0, 20, 55, - 126, 59, 59, 56, 117, 0, 20, 55, 59, 126, - 59, 126, 56, 117, 0, 20, 55, 59, 126, 59, - 56, 117, 0, 20, 55, 59, 59, 126, 56, 117, - 0, 20, 55, 59, 59, 56, 117, 0, 21, 55, - 37, 23, 126, 56, 117, 0, 22, 55, 37, 23, - 126, 56, 117, 0, 131, 0, 131, 0, 55, 126, - 56, 0, 126, 62, 126, 0, 126, 54, 126, 0, - 126, 53, 126, 0, 126, 52, 126, 0, 126, 44, - 126, 0, 126, 45, 126, 0, 126, 46, 126, 0, - 126, 47, 126, 0, 45, 126, 0, 46, 126, 0, - 36, 0, 126, 96, 126, 58, 126, 0, 126, 48, - 126, 0, 126, 49, 126, 0, 126, 86, 126, 0, - 126, 87, 126, 0, 126, 84, 126, 0, 126, 85, - 126, 0, 126, 89, 126, 0, 126, 71, 126, 0, - 126, 72, 126, 0, 126, 88, 126, 0, 126, 90, - 126, 0, 126, 97, 126, 0, 126, 65, 126, 0, - 64, 126, 0, 63, 126, 0, 42, 0, 43, 0, - 35, 0, 7, 0, 127, 0, 128, 0, 38, 0, - 41, 0, 37, 0, 37, 92, 139, 99, 0, 126, - 51, 38, 0, 126, 51, 38, 92, 139, 99, 0, - 126, 66, 129, 0, 126, 67, 129, 0, 38, 0, - 55, 126, 56, 0, 69, 0, 68, 0, 73, 126, - 0, 74, 126, 0, 75, 126, 0, 76, 126, 0, - 77, 126, 0, 78, 126, 0, 79, 126, 0, 80, - 126, 0, 81, 126, 0, 82, 126, 0, 132, 0, - 133, 0, 111, 0, 37, 50, 126, 0, 37, 92, - 139, 99, 50, 126, 0, 37, 130, 0, 37, 92, - 139, 99, 130, 0, 127, 130, 0, 127, 50, 126, - 0, 127, 50, 60, 135, 61, 0, 38, 55, 134, - 56, 0, 38, 91, 38, 55, 134, 56, 0, 126, - 51, 38, 55, 134, 56, 0, 32, 55, 126, 56, - 0, 32, 55, 126, 57, 41, 56, 0, 0, 135, - 0, 126, 0, 135, 57, 126, 0, 0, 137, 0, - 138, 0, 137, 138, 0, 38, 50, 126, 59, 0, - 39, 38, 50, 126, 59, 0, 24, 50, 126, 59, - 0, 38, 92, 139, 99, 50, 126, 59, 0, 39, - 38, 92, 139, 99, 50, 126, 59, 0, 126, 0, - 139, 57, 126, 0 -}; - +#ifdef __INT_LEAST8_MAX__ +typedef __INT_LEAST8_TYPE__ yytype_int8; +#elif defined YY_STDINT_H +typedef int_least8_t yytype_int8; +#else +typedef signed char yytype_int8; #endif -#if YYDEBUG != 0 -static const short yyrline[] = { 0, - 161, 166, 168, 173, 175, 177, 182, 187, 189, 194, - 196, 201, 202, 203, 204, 205, 206, 207, 209, 211, - 213, 215, 217, 219, 221, 226, 228, 233, 235, 240, - 242, 247, 252, 254, 256, 258, 260, 262, 267, 269, - 274, 276, 281, 283, 288, 290, 292, 294, 299, 301, - 306, 308, 313, 315, 320, 322, 324, 329, 331, 336, - 338, 343, 345, 350, 352, 354, 356, 358, 360, 362, - 364, 369, 371, 376, 381, 383, 385, 387, 389, 391, - 393, 395, 397, 399, 401, 403, 405, 407, 409, 411, - 413, 415, 417, 419, 421, 423, 425, 427, 429, 431, - 433, 435, 437, 439, 441, 443, 445, 447, 449, 451, - 453, 455, 457, 479, 481, 486, 488, 493, 495, 500, - 502, 504, 506, 508, 510, 512, 514, 516, 518, 520, - 522, 527, 529, 531, 533, 535, 537, 539, 541, 543, - 545, 550, 552, 554, 564, 566, 571, 573, 578, 580, - 585, 587, 592, 594, 599, 601, 603, 605, 607, 612, - 614 -}; - -static const char * const yytname[] = { "$","error","$undefined.","rwDEFINE", -"rwENDDEF","rwDECLARE","rwDECLARESINGLETON","rwBREAK","rwELSE","rwCONTINUE", -"rwGLOBAL","rwIF","rwNIL","rwRETURN","rwWHILE","rwDO","rwENDIF","rwENDWHILE", -"rwENDFOR","rwDEFAULT","rwFOR","rwFOREACH","rwFOREACHSTR","rwIN","rwDATABLOCK", -"rwSWITCH","rwCASE","rwSWITCHSTR","rwCASEOR","rwPACKAGE","rwNAMESPACE","rwCLASS", -"rwASSERT","ILLEGAL_TOKEN","CHRCONST","INTCONST","TTAG","VAR","IDENT","TYPEIDENT", -"DOCBLOCK","STRATOM","TAGATOM","FLTCONST","'+'","'-'","'*'","'/'","'<'","'>'", -"'='","'.'","'|'","'&'","'%'","'('","')'","','","':'","';'","'{'","'}'","'^'", -"'~'","'!'","'@'","opINTNAME","opINTNAMER","opMINUSMINUS","opPLUSPLUS","STMT_SEP", -"opSHL","opSHR","opPLASN","opMIASN","opMLASN","opDVASN","opMODASN","opANDASN", -"opXORASN","opORASN","opSLASN","opSRASN","opCAT","opEQ","opNE","opGE","opLE", -"opAND","opOR","opSTREQ","opCOLONCOLON","'['","opMDASN","opNDASN","opNTASN", -"'?'","opSTRNE","UNARY","']'","start","decl_list","decl","package_decl","fn_decl_list", -"statement_list","stmt","fn_decl_stmt","var_list_decl","var_list","datablock_decl", -"object_decl","parent_block","object_name","object_args","object_declare_block", -"object_decl_list","stmt_block","switch_stmt","case_block","case_expr","if_stmt", -"while_stmt","for_stmt","foreach_stmt","expression_stmt","expr","slot_acc","intslot_acc", -"class_name_expr","assign_op_struct","stmt_expr","funcall_expr","assert_expr", -"expr_list_decl","expr_list","slot_assign_list_opt","slot_assign_list","slot_assign", -"aidx_expr","" -}; +#ifdef __INT_LEAST16_MAX__ +typedef __INT_LEAST16_TYPE__ yytype_int16; +#elif defined YY_STDINT_H +typedef int_least16_t yytype_int16; +#else +typedef short yytype_int16; #endif -static const short yyr1[] = { 0, - 100, 101, 101, 102, 102, 102, 103, 104, 104, 105, - 105, 106, 106, 106, 106, 106, 106, 106, 106, 106, - 106, 106, 106, 106, 106, 107, 107, 108, 108, 109, - 109, 110, 111, 111, 111, 111, 111, 111, 112, 112, - 113, 113, 114, 114, 115, 115, 115, 115, 116, 116, - 117, 117, 118, 118, 119, 119, 119, 120, 120, 121, - 121, 122, 122, 123, 123, 123, 123, 123, 123, 123, - 123, 124, 124, 125, 126, 126, 126, 126, 126, 126, - 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, - 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, - 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, - 126, 126, 126, 127, 127, 128, 128, 129, 129, 130, - 130, 130, 130, 130, 130, 130, 130, 130, 130, 130, - 130, 131, 131, 131, 131, 131, 131, 131, 131, 131, - 131, 132, 132, 132, 133, 133, 134, 134, 135, 135, - 136, 136, 137, 137, 138, 138, 138, 138, 138, 139, - 139 -}; - -static const short yyr2[] = { 0, - 1, 0, 2, 1, 1, 1, 6, 1, 2, 0, - 2, 1, 1, 1, 1, 1, 1, 2, 2, 2, - 3, 2, 4, 6, 1, 8, 10, 0, 1, 1, - 3, 10, 10, 7, 12, 9, 10, 7, 0, 2, - 0, 1, 0, 2, 0, 1, 1, 2, 2, 3, - 3, 1, 7, 7, 4, 7, 5, 1, 3, 5, - 7, 5, 6, 9, 8, 8, 7, 8, 7, 7, - 6, 7, 7, 1, 1, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 2, 2, 1, 5, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 2, 2, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 4, 3, 6, 3, 3, 1, 3, 1, - 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 1, 1, 1, 3, 6, 2, 5, 2, 3, - 5, 4, 6, 6, 4, 6, 0, 1, 1, 3, - 0, 1, 1, 2, 4, 5, 4, 7, 8, 1, - 3 -}; - -static const short yydefact[] = { 2, - 1, 0, 0, 0, 107, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 106, 87, - 112, 110, 25, 111, 104, 105, 0, 0, 0, 0, - 0, 3, 6, 4, 5, 16, 134, 17, 12, 13, - 14, 15, 0, 0, 108, 109, 75, 132, 133, 0, - 118, 0, 0, 0, 18, 19, 0, 107, 87, 20, - 0, 75, 0, 10, 52, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 121, 120, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 137, - 147, 0, 85, 86, 0, 103, 102, 22, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 139, 28, 0, 0, 41, 41, - 0, 21, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 135, 122, 123, 124, 125, - 126, 127, 128, 129, 130, 131, 160, 0, 149, 0, - 148, 0, 76, 81, 82, 83, 84, 89, 90, 114, - 80, 79, 78, 77, 101, 116, 117, 96, 97, 93, - 94, 91, 92, 98, 95, 99, 0, 100, 0, 140, - 30, 0, 29, 0, 119, 41, 39, 42, 39, 0, - 0, 51, 11, 0, 0, 0, 0, 0, 0, 39, - 0, 0, 0, 8, 145, 0, 0, 23, 0, 113, - 142, 0, 147, 147, 0, 0, 0, 0, 0, 28, - 0, 0, 43, 43, 60, 62, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, - 0, 161, 0, 138, 150, 0, 0, 0, 88, 141, - 10, 31, 0, 39, 40, 0, 0, 0, 0, 63, - 71, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 7, 146, 24, 136, 143, 144, 115, - 0, 0, 43, 44, 34, 38, 61, 70, 69, 0, - 67, 0, 0, 0, 72, 73, 151, 0, 58, 53, - 54, 26, 10, 0, 45, 45, 68, 66, 65, 0, - 0, 0, 0, 0, 152, 153, 0, 10, 0, 36, - 0, 0, 47, 46, 0, 64, 0, 0, 0, 0, - 0, 154, 59, 55, 27, 45, 49, 33, 0, 48, - 37, 0, 0, 0, 0, 0, 32, 0, 57, 0, - 50, 157, 155, 0, 0, 0, 10, 35, 0, 156, - 0, 56, 0, 0, 158, 0, 159, 0, 0, 0 -}; - -static const short yydefgoto[] = { 378, - 1, 32, 33, 213, 134, 65, 35, 192, 193, 36, - 37, 233, 197, 267, 332, 333, 66, 38, 282, 308, - 39, 40, 41, 42, 43, 44, 45, 46, 53, 90, - 62, 48, 49, 160, 161, 324, 334, 326, 158 -}; - -static const short yypact[] = {-32768, - 396, -30, -7, -7, -5, 29, -39, 166, -29, 488, - -26, 37, 40, -7, 46, 74, 97, 82,-32768, 94, - -36, -28,-32768,-32768,-32768,-32768, 1001, 1001, 1001, 1001, - 1001,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, --32768,-32768, 92, 2464, 2726,-32768, 105,-32768,-32768, -27, --32768, 1001, 110, 111,-32768,-32768, 1001,-32768,-32768,-32768, - 1114,-32768, 1001,-32768,-32768, 156, 707, 137, 139, 123, - 1001, 1001, 120, 1001, 1001, 1001,-32768,-32768, 1001, 1001, - 1001, 1001, 1001, 1001, 1001, 1001, 1001, 1001, 1001,-32768, - 1001, 143, 27, 27, 1168, 27, 27,-32768, 1001, 1001, - 1001, 1001, 1001, 1001, 144, 1001, 1001, 1001, 1001, 1001, - -7, -7, 1001, 1001, 1001, 1001, 1001, 1001, 1001, 1001, - 1001, 1001, 1001, 749,-32768, 146, 147, 1222, 44, 1001, - 1276,-32768, 1330, 548, 129, 791, 1384, 163, 167, 1001, - 1438, 1492, 186, 1006, 1060, 2464, 2464, 2464, 2464, 2464, - 2464, 2464, 2464, 2464, 2464, 2464, 2464, -47, 2464, 135, - 136, 140,-32768, 713, 713, 27, 27, 2721, 2721, -33, - 2605, 2663, 27, 2634, 2785,-32768,-32768, 291, 291, 2692, - 2692, 2721, 2721, 2576, 2547, 2785, 1546, 2785, 1001, 2464, --32768, 138, 153, 141,-32768, 1001, 134, 2464, 134, 488, - 488,-32768,-32768, 1001, 318, 1600, 833, 1001, 1001, 1654, - 154, 155, 14,-32768,-32768, 172, 1001,-32768, 1001, 2746, --32768, 1001, 1001, 1001, 1001, 1001, 48, 157, 160, 146, - 117, 185, 169, 169, 216,-32768, 1708, 488, 1762, 875, - 917, 1816, 1870, 1924, 171, 207, 207, 175,-32768, 180, - 1978, 2464, 1001,-32768, 2464, 183, 184, -46, 2518,-32768, --32768,-32768, 189, 134,-32768, 1001, 193, 194, 488,-32768, --32768, 488, 488, 2032, 488, 2086, 959, 488, 488, 181, - 1001, 190, 196,-32768,-32768,-32768, 2464,-32768,-32768,-32768, - 593, 182, 169, 136, 195, 199,-32768,-32768,-32768, 488, --32768, 488, 488, 2140,-32768,-32768, 59, -3, 2464,-32768, --32768,-32768,-32768, 198, 214, 214,-32768,-32768,-32768, 488, - 210, -35, 228, 206, 59,-32768, 1001,-32768, 638, 213, - 211, 215, 98, 214, 220,-32768, 1001, 1001, 1001, -32, - 223,-32768, 2464, 443,-32768, 214,-32768,-32768, 224, 98, --32768, 2194, 2248, -38, 1001, 1001,-32768, 217,-32768, 225, --32768,-32768,-32768, 234, 2302, -37,-32768,-32768, 1001,-32768, - 235, 683, 2356, 1001,-32768, 2410,-32768, 287, 288,-32768 -}; - -static const short yypgoto[] = {-32768, --32768,-32768,-32768,-32768, -255, 0, -139, 63,-32768,-32768, - -128, -187, -125, -221, -281, -45, 31,-32768, -244,-32768, --32768,-32768,-32768,-32768,-32768, 39,-32768,-32768, 20, -43, - -1,-32768,-32768, -107, -182,-32768, -13, -304, -189 -}; - - -#define YYLAST 2857 - - -static const short yytable[] = { 47, - 34, 125, 283, 214, 199, 291, 227, 50, 47, 219, - 219, 234, 268, 76, 338, 57, 2, 355, 219, 219, - 342, 224, 245, 54, 327, 63, 91, 126, 67, 342, - 51, 77, 78, 70, 335, 258, 79, 80, 81, 82, - 83, 84, 85, 86, 87, 88, 61, 52, 3, 4, - 58, 220, 290, 55, 328, 89, 339, 329, 225, 356, - 364, 371, 92, 127, 360, 93, 94, 95, 96, 97, - 231, 314, 344, 249, 248, 18, 293, 105, 19, 59, - 21, 22, 321, 294, 24, 25, 26, 56, 27, 28, - 128, 68, 111, 112, 69, 131, 322, 323, 29, 359, - 71, 133, 3, 4, 222, 137, 30, 31, 260, 141, - 142, 372, 144, 145, 146, 256, 257, 147, 148, 149, - 150, 151, 152, 153, 154, 155, 156, 157, 72, 159, - 176, 177, 47, 203, 73, 196, 74, 164, 165, 166, - 167, 168, 169, 75, 171, 172, 173, 174, 175, 354, - 98, 178, 179, 180, 181, 182, 183, 184, 185, 186, - 187, 188, 190, -74, 129, 130, 366, 198, 198, 135, - 3, 4, 58, 138, 206, 139, 254, 140, 210, 143, - 162, 170, 191, 204, 194, 208, 331, 331, 2, 209, - 221, 232, 222, 228, 223, 230, 262, 18, 47, 47, - 19, 59, 21, 22, 349, 331, 24, 25, 26, 229, - 27, 28, 250, 246, 247, 264, 261, 331, 3, 4, - 29, 349, 265, 269, 60, 266, 280, 159, 30, 31, - 235, 236, 281, 284, 198, 285, 47, 321, 288, 289, - 307, 313, 237, 239, 292, 242, 243, 244, 295, 296, - 310, 322, 323, 330, 315, 251, 311, 252, 316, 337, - 255, 159, 159, 157, 259, 340, 341, 47, 271, 347, - 47, 47, 346, 47, 367, 348, 47, 47, 274, 276, - 351, 357, 361, 369, 374, 368, 379, 380, 350, 47, - 203, 287, 263, 325, 0, 0, 0, 0, 47, 297, - 47, 47, 298, 299, 159, 301, 0, 0, 305, 306, - 0, 0, 0, 0, 0, 304, 0, 0, 47, 309, - 0, 0, 3, 4, 58, 0, 0, 47, 203, 0, - 317, 0, 318, 319, 99, 100, 101, 102, 0, 0, - 0, 105, 47, 203, 108, 0, 0, 0, 0, 18, - 336, 0, 19, 59, 21, 22, 111, 112, 24, 25, - 26, 0, 27, 28, 0, 343, 0, 0, 0, 0, - 47, 203, 29, 238, 0, 352, 353, 157, 0, 0, - 30, 31, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 365, 157, 0, 0, 0, 2, 0, - 3, 4, 5, 0, 6, 0, 7, 373, 8, 9, - 10, 0, 376, 0, 0, 11, 12, 13, 0, 14, - 15, 0, 16, 0, 17, 0, 0, 18, 0, 0, - 19, 20, 21, 22, 0, 23, 24, 25, 26, 0, - 27, 28, 0, 0, 0, 0, 0, 3, 4, 5, - 29, 6, 0, 7, 0, 8, 9, 10, 30, 31, - 0, 358, 11, 12, 13, 0, 14, 15, 281, 16, - 0, 0, 0, 0, 18, 0, 0, 19, 20, 21, - 22, 0, 23, 24, 25, 26, 0, 27, 28, 0, - 0, 0, 3, 4, 5, 0, 6, 29, 7, 0, - 8, 9, 10, 0, 0, 30, 31, 11, 12, 13, - 0, 14, 15, 0, 16, 0, 0, 0, 0, 18, - 0, 0, 19, 20, 21, 22, 0, 23, 24, 25, - 26, 0, 27, 28, 0, 0, 0, 0, 0, 0, - 0, 0, 29, 0, 0, 0, 0, 64, 0, 0, - 30, 31, 3, 4, 5, 0, 6, 0, 7, 0, - 8, 9, 10, 0, 0, 0, 0, 11, 12, 13, - 0, 14, 15, 0, 16, 0, 0, 0, 0, 18, - 0, 0, 19, 20, 21, 22, 0, 23, 24, 25, - 26, 0, 27, 28, 0, 0, 0, 3, 4, 5, - 0, 6, 29, 7, 0, 8, 9, 10, 202, 0, - 30, 31, 11, 12, 13, 0, 14, 15, 0, 16, - 0, 0, 0, 0, 18, 0, 0, 19, 20, 21, - 22, 0, 23, 24, 25, 26, 0, 27, 28, 0, - 0, 0, 3, 4, 5, 0, 6, 29, 7, 0, - 8, 9, 10, 312, 0, 30, 31, 11, 12, 13, - 0, 14, 15, 0, 16, 0, 0, 0, 0, 18, - 0, 0, 19, 20, 21, 22, 0, 23, 24, 25, - 26, 0, 27, 28, 0, 0, 0, 3, 4, 5, - 0, 6, 29, 7, 0, 8, 9, 10, 345, 0, - 30, 31, 11, 12, 13, 0, 14, 15, 0, 16, - 0, 3, 4, 58, 18, 0, 0, 19, 20, 21, - 22, 0, 23, 24, 25, 26, 0, 27, 28, 0, - 0, 0, 0, 0, 0, 0, 0, 29, 18, 0, - 0, 19, 59, 21, 22, 30, 31, 24, 25, 26, - 0, 27, 28, 3, 4, 58, 0, 0, 101, 102, - 0, 29, 0, 105, 0, 136, 108, 0, 0, 30, - 31, 0, 0, 0, 0, 0, 0, 0, 111, 112, - 18, 0, 0, 19, 59, 21, 22, 0, 0, 24, - 25, 26, 0, 27, 28, 3, 4, 58, 0, 0, - 0, 0, 0, 29, 0, 0, 0, 0, 189, 0, - 0, 30, 31, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 18, 0, 0, 19, 59, 21, 22, 0, - 0, 24, 25, 26, 0, 27, 28, 3, 4, 58, - 0, 0, 0, 0, 0, 29, 0, 0, 0, 205, - 0, 0, 0, 30, 31, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 18, 0, 0, 19, 59, 21, - 22, 0, 0, 24, 25, 26, 0, 27, 28, 3, - 4, 58, 0, 0, 0, 0, 0, 29, 0, 0, - 0, 241, 0, 0, 0, 30, 31, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 18, 0, 0, 19, - 59, 21, 22, 0, 0, 24, 25, 26, 0, 27, - 28, 3, 4, 58, 0, 0, 0, 0, 0, 29, - 273, 0, 0, 0, 0, 0, 0, 30, 31, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, - 0, 19, 59, 21, 22, 0, 0, 24, 25, 26, - 0, 27, 28, 3, 4, 58, 0, 0, 0, 0, - 0, 29, 275, 0, 0, 0, 0, 0, 0, 30, - 31, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 18, 0, 0, 19, 59, 21, 22, 0, 0, 24, - 25, 26, 0, 27, 28, 3, 4, 58, 0, 0, - 0, 0, 0, 29, 303, 0, 0, 0, 0, 0, - 0, 30, 31, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 18, 0, 0, 19, 59, 21, 22, 0, - 0, 24, 25, 26, 0, 27, 28, 0, 0, 99, - 100, 101, 102, 103, 104, 29, 105, 106, 107, 108, - 0, 215, 216, 30, 31, 0, 0, 109, 0, 0, - 110, 111, 112, 0, 0, 0, 113, 114, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 115, - 116, 117, 118, 119, 120, 121, 0, 0, 0, 0, - 0, 122, 123, 99, 100, 101, 102, 103, 104, 0, - 105, 106, 107, 108, 0, 0, 217, 0, 218, 0, - 0, 109, 0, 0, 110, 111, 112, 0, 0, 0, - 113, 114, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 115, 116, 117, 118, 119, 120, 121, - 0, 0, 0, 0, 0, 122, 123, 99, 100, 101, - 102, 103, 104, 0, 105, 106, 107, 108, 0, 0, - 0, 0, 132, 0, 0, 109, 0, 0, 110, 111, - 112, 0, 0, 0, 113, 114, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 115, 116, 117, - 118, 119, 120, 121, 0, 0, 0, 0, 0, 122, - 123, 99, 100, 101, 102, 103, 104, 0, 105, 106, - 107, 108, 0, 163, 0, 0, 0, 0, 0, 109, - 0, 0, 110, 111, 112, 0, 0, 0, 113, 114, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 115, 116, 117, 118, 119, 120, 121, 0, 0, - 0, 0, 0, 122, 123, 99, 100, 101, 102, 103, - 104, 0, 105, 106, 107, 108, 0, 195, 0, 0, - 0, 0, 0, 109, 0, 0, 110, 111, 112, 0, - 0, 0, 113, 114, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 115, 116, 117, 118, 119, - 120, 121, 0, 0, 0, 0, 0, 122, 123, 99, - 100, 101, 102, 103, 104, 0, 105, 106, 107, 108, - 0, 200, 0, 0, 0, 0, 0, 109, 0, 0, - 110, 111, 112, 0, 0, 0, 113, 114, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 115, - 116, 117, 118, 119, 120, 121, 0, 0, 0, 0, - 0, 122, 123, 99, 100, 101, 102, 103, 104, 0, - 105, 106, 107, 108, 0, 201, 0, 0, 0, 0, - 0, 109, 0, 0, 110, 111, 112, 0, 0, 0, - 113, 114, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 115, 116, 117, 118, 119, 120, 121, - 0, 0, 0, 0, 0, 122, 123, 99, 100, 101, - 102, 103, 104, 0, 105, 106, 107, 108, 0, 0, - 0, 0, 207, 0, 0, 109, 0, 0, 110, 111, - 112, 0, 0, 0, 113, 114, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 115, 116, 117, - 118, 119, 120, 121, 0, 0, 0, 0, 0, 122, - 123, 99, 100, 101, 102, 103, 104, 0, 105, 106, - 107, 108, 0, 211, 0, 0, 0, 0, 0, 109, - 0, 0, 110, 111, 112, 0, 0, 0, 113, 114, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 115, 116, 117, 118, 119, 120, 121, 0, 0, - 0, 0, 0, 122, 123, 99, 100, 101, 102, 103, - 104, 0, 105, 106, 107, 108, 0, 212, 0, 0, - 0, 0, 0, 109, 0, 0, 110, 111, 112, 0, - 0, 0, 113, 114, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 115, 116, 117, 118, 119, - 120, 121, 0, 0, 0, 0, 0, 122, 123, 99, - 100, 101, 102, 103, 104, 0, 105, 106, 107, 108, - 0, 0, 0, 226, 0, 0, 0, 109, 0, 0, - 110, 111, 112, 0, 0, 0, 113, 114, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 115, - 116, 117, 118, 119, 120, 121, 0, 0, 0, 0, - 0, 122, 123, 99, 100, 101, 102, 103, 104, 0, - 105, 106, 107, 108, 0, 0, 0, 0, 240, 0, - 0, 109, 0, 0, 110, 111, 112, 0, 0, 0, - 113, 114, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 115, 116, 117, 118, 119, 120, 121, - 0, 0, 0, 0, 0, 122, 123, 99, 100, 101, - 102, 103, 104, 0, 105, 106, 107, 108, 0, 0, - 0, 232, 0, 0, 0, 109, 0, 0, 110, 111, - 112, 0, 0, 0, 113, 114, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 115, 116, 117, - 118, 119, 120, 121, 0, 0, 0, 0, 0, 122, - 123, 99, 100, 101, 102, 103, 104, 0, 105, 106, - 107, 108, 0, 270, 0, 0, 0, 0, 0, 109, - 0, 0, 110, 111, 112, 0, 0, 0, 113, 114, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 115, 116, 117, 118, 119, 120, 121, 0, 0, - 0, 0, 0, 122, 123, 99, 100, 101, 102, 103, - 104, 0, 105, 106, 107, 108, 0, 272, 0, 0, - 0, 0, 0, 109, 0, 0, 110, 111, 112, 0, - 0, 0, 113, 114, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 115, 116, 117, 118, 119, - 120, 121, 0, 0, 0, 0, 0, 122, 123, 99, - 100, 101, 102, 103, 104, 0, 105, 106, 107, 108, - 0, 0, 0, 0, 277, 0, 0, 109, 0, 0, - 110, 111, 112, 0, 0, 0, 113, 114, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 115, - 116, 117, 118, 119, 120, 121, 0, 0, 0, 0, - 0, 122, 123, 99, 100, 101, 102, 103, 104, 0, - 105, 106, 107, 108, 0, 278, 0, 0, 0, 0, - 0, 109, 0, 0, 110, 111, 112, 0, 0, 0, - 113, 114, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 115, 116, 117, 118, 119, 120, 121, - 0, 0, 0, 0, 0, 122, 123, 99, 100, 101, - 102, 103, 104, 0, 105, 106, 107, 108, 0, 279, - 0, 0, 0, 0, 0, 109, 0, 0, 110, 111, - 112, 0, 0, 0, 113, 114, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 115, 116, 117, - 118, 119, 120, 121, 0, 0, 0, 0, 0, 122, - 123, 99, 100, 101, 102, 103, 104, 0, 105, 106, - 107, 108, 0, 0, 0, 0, 286, 0, 0, 109, - 0, 0, 110, 111, 112, 0, 0, 0, 113, 114, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 115, 116, 117, 118, 119, 120, 121, 0, 0, - 0, 0, 0, 122, 123, 99, 100, 101, 102, 103, - 104, 0, 105, 106, 107, 108, 0, 300, 0, 0, - 0, 0, 0, 109, 0, 0, 110, 111, 112, 0, - 0, 0, 113, 114, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 115, 116, 117, 118, 119, - 120, 121, 0, 0, 0, 0, 0, 122, 123, 99, - 100, 101, 102, 103, 104, 0, 105, 106, 107, 108, - 0, 302, 0, 0, 0, 0, 0, 109, 0, 0, - 110, 111, 112, 0, 0, 0, 113, 114, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 115, - 116, 117, 118, 119, 120, 121, 0, 0, 0, 0, - 0, 122, 123, 99, 100, 101, 102, 103, 104, 0, - 105, 106, 107, 108, 0, 320, 0, 0, 0, 0, - 0, 109, 0, 0, 110, 111, 112, 0, 0, 0, - 113, 114, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 115, 116, 117, 118, 119, 120, 121, - 0, 0, 0, 0, 0, 122, 123, 99, 100, 101, - 102, 103, 104, 0, 105, 106, 107, 108, 0, 0, - 0, 0, 362, 0, 0, 109, 0, 0, 110, 111, - 112, 0, 0, 0, 113, 114, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 115, 116, 117, - 118, 119, 120, 121, 0, 0, 0, 0, 0, 122, - 123, 99, 100, 101, 102, 103, 104, 0, 105, 106, - 107, 108, 0, 0, 0, 0, 363, 0, 0, 109, - 0, 0, 110, 111, 112, 0, 0, 0, 113, 114, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 115, 116, 117, 118, 119, 120, 121, 0, 0, - 0, 0, 0, 122, 123, 99, 100, 101, 102, 103, - 104, 0, 105, 106, 107, 108, 0, 0, 0, 0, - 370, 0, 0, 109, 0, 0, 110, 111, 112, 0, - 0, 0, 113, 114, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 115, 116, 117, 118, 119, - 120, 121, 0, 0, 0, 0, 0, 122, 123, 99, - 100, 101, 102, 103, 104, 0, 105, 106, 107, 108, - 0, 0, 0, 0, 375, 0, 0, 109, 0, 0, - 110, 111, 112, 0, 0, 0, 113, 114, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 115, - 116, 117, 118, 119, 120, 121, 0, 0, 0, 0, - 0, 122, 123, 99, 100, 101, 102, 103, 104, 0, - 105, 106, 107, 108, 0, 0, 0, 0, 377, 0, - 0, 109, 0, 0, 110, 111, 112, 0, 0, 0, - 113, 114, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 115, 116, 117, 118, 119, 120, 121, - 0, 0, 0, 0, 0, 122, 123, 99, 100, 101, - 102, 103, 104, 0, 105, 106, 107, 108, 0, 0, - 0, 0, 0, 0, 0, 109, 0, 0, 110, 111, - 112, 0, 0, 0, 113, 114, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 115, 116, 117, - 118, 119, 120, 121, 0, 0, 0, 0, 0, 122, - 123, 99, 100, 101, 102, 103, 104, 0, 105, 106, - 107, 108, 0, 0, 0, 0, 0, 0, 0, 109, - 0, 0, 110, 111, 112, 0, 0, 0, 113, 114, - 99, 100, 101, 102, 103, 104, 0, 105, 106, 107, - 108, 115, 116, 117, 118, 119, 120, 121, 109, 0, - 0, 110, 111, 112, 123, 0, 0, 113, 114, 99, - 100, 101, 102, 103, 104, 0, 105, 106, 107, 108, - 115, 116, 117, 118, 119, 0, 121, 109, 0, 0, - 110, 111, 112, 123, 0, 0, 113, 114, 99, 100, - 101, 102, 103, 104, 0, 105, 0, 107, 108, 115, - 116, 117, 118, 0, 0, 121, 109, 0, 0, 110, - 111, 112, 123, 0, 0, 113, 114, 99, 100, 101, - 102, 103, 104, 0, 105, 0, 107, 108, 115, 116, - 117, 118, 0, 0, 121, 0, 0, 0, 110, 111, - 112, 123, 0, 0, 113, 114, 99, 100, 101, 102, - 103, 104, 0, 105, 0, 0, 108, 115, 116, 117, - 118, 0, 0, 121, 0, 0, 0, 110, 111, 112, - 123, 0, 0, 113, 114, 99, 100, 101, 102, 103, - 104, 0, 105, 0, 0, 108, 115, 116, 117, 118, - 0, 0, 121, 0, 0, 0, 110, 111, 112, 123, - 0, 0, 113, 114, 99, 100, 101, 102, 0, 0, - 0, 105, 0, 0, 108, 124, 0, 117, 118, 0, - 0, 121, 0, 0, 0, 110, 111, 112, 123, 0, - 0, 113, 114, 77, 78, 253, 0, 0, 79, 80, - 81, 82, 83, 84, 85, 86, 87, 88, 0, 0, - 121, 0, 0, 77, 78, 0, 0, 123, 79, 80, - 81, 82, 83, 84, 85, 86, 87, 88, 99, 100, - 101, 102, 0, 0, 0, 105, 0, 0, 108, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 111, 112, 0, 0, 0, 113, 114 -}; - -static const short yycheck[] = { 1, - 1, 45, 247, 143, 130, 261, 189, 38, 10, 57, - 57, 199, 234, 50, 50, 55, 3, 50, 57, 57, - 325, 55, 210, 4, 28, 55, 55, 55, 55, 334, - 38, 68, 69, 14, 316, 225, 73, 74, 75, 76, - 77, 78, 79, 80, 81, 82, 8, 55, 5, 6, - 7, 99, 99, 59, 58, 92, 92, 313, 92, 92, - 99, 99, 91, 91, 346, 27, 28, 29, 30, 31, - 196, 293, 328, 213, 61, 32, 264, 51, 35, 36, - 37, 38, 24, 266, 41, 42, 43, 59, 45, 46, - 52, 55, 66, 67, 55, 57, 38, 39, 55, 344, - 55, 63, 5, 6, 57, 67, 63, 64, 61, 71, - 72, 367, 74, 75, 76, 223, 224, 79, 80, 81, - 82, 83, 84, 85, 86, 87, 88, 89, 55, 91, - 111, 112, 134, 134, 38, 92, 55, 99, 100, 101, - 102, 103, 104, 50, 106, 107, 108, 109, 110, 339, - 59, 113, 114, 115, 116, 117, 118, 119, 120, 121, - 122, 123, 124, 59, 55, 55, 356, 129, 130, 14, - 5, 6, 7, 37, 136, 37, 220, 55, 140, 60, - 38, 38, 37, 55, 38, 23, 315, 316, 3, 23, - 56, 58, 57, 56, 55, 55, 37, 32, 200, 201, - 35, 36, 37, 38, 333, 334, 41, 42, 43, 57, - 45, 46, 41, 60, 60, 99, 60, 346, 5, 6, - 55, 350, 38, 8, 59, 57, 56, 189, 63, 64, - 200, 201, 26, 59, 196, 56, 238, 24, 56, 56, - 60, 60, 204, 205, 56, 207, 208, 209, 56, 56, - 61, 38, 39, 56, 60, 217, 61, 219, 60, 50, - 222, 223, 224, 225, 226, 38, 61, 269, 238, 59, - 272, 273, 60, 275, 58, 61, 278, 279, 240, 241, - 61, 59, 59, 50, 50, 61, 0, 0, 334, 291, - 291, 253, 230, 307, -1, -1, -1, -1, 300, 269, - 302, 303, 272, 273, 266, 275, -1, -1, 278, 279, - -1, -1, -1, -1, -1, 277, -1, -1, 320, 281, - -1, -1, 5, 6, 7, -1, -1, 329, 329, -1, - 300, -1, 302, 303, 44, 45, 46, 47, -1, -1, - -1, 51, 344, 344, 54, -1, -1, -1, -1, 32, - 320, -1, 35, 36, 37, 38, 66, 67, 41, 42, - 43, -1, 45, 46, -1, 327, -1, -1, -1, -1, - 372, 372, 55, 56, -1, 337, 338, 339, -1, -1, - 63, 64, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 355, 356, -1, -1, -1, 3, -1, - 5, 6, 7, -1, 9, -1, 11, 369, 13, 14, - 15, -1, 374, -1, -1, 20, 21, 22, -1, 24, - 25, -1, 27, -1, 29, -1, -1, 32, -1, -1, - 35, 36, 37, 38, -1, 40, 41, 42, 43, -1, - 45, 46, -1, -1, -1, -1, -1, 5, 6, 7, - 55, 9, -1, 11, -1, 13, 14, 15, 63, 64, - -1, 19, 20, 21, 22, -1, 24, 25, 26, 27, - -1, -1, -1, -1, 32, -1, -1, 35, 36, 37, - 38, -1, 40, 41, 42, 43, -1, 45, 46, -1, - -1, -1, 5, 6, 7, -1, 9, 55, 11, -1, - 13, 14, 15, -1, -1, 63, 64, 20, 21, 22, - -1, 24, 25, -1, 27, -1, -1, -1, -1, 32, - -1, -1, 35, 36, 37, 38, -1, 40, 41, 42, - 43, -1, 45, 46, -1, -1, -1, -1, -1, -1, - -1, -1, 55, -1, -1, -1, -1, 60, -1, -1, - 63, 64, 5, 6, 7, -1, 9, -1, 11, -1, - 13, 14, 15, -1, -1, -1, -1, 20, 21, 22, - -1, 24, 25, -1, 27, -1, -1, -1, -1, 32, - -1, -1, 35, 36, 37, 38, -1, 40, 41, 42, - 43, -1, 45, 46, -1, -1, -1, 5, 6, 7, - -1, 9, 55, 11, -1, 13, 14, 15, 61, -1, - 63, 64, 20, 21, 22, -1, 24, 25, -1, 27, - -1, -1, -1, -1, 32, -1, -1, 35, 36, 37, - 38, -1, 40, 41, 42, 43, -1, 45, 46, -1, - -1, -1, 5, 6, 7, -1, 9, 55, 11, -1, - 13, 14, 15, 61, -1, 63, 64, 20, 21, 22, - -1, 24, 25, -1, 27, -1, -1, -1, -1, 32, - -1, -1, 35, 36, 37, 38, -1, 40, 41, 42, - 43, -1, 45, 46, -1, -1, -1, 5, 6, 7, - -1, 9, 55, 11, -1, 13, 14, 15, 61, -1, - 63, 64, 20, 21, 22, -1, 24, 25, -1, 27, - -1, 5, 6, 7, 32, -1, -1, 35, 36, 37, - 38, -1, 40, 41, 42, 43, -1, 45, 46, -1, - -1, -1, -1, -1, -1, -1, -1, 55, 32, -1, - -1, 35, 36, 37, 38, 63, 64, 41, 42, 43, - -1, 45, 46, 5, 6, 7, -1, -1, 46, 47, - -1, 55, -1, 51, -1, 59, 54, -1, -1, 63, - 64, -1, -1, -1, -1, -1, -1, -1, 66, 67, - 32, -1, -1, 35, 36, 37, 38, -1, -1, 41, - 42, 43, -1, 45, 46, 5, 6, 7, -1, -1, - -1, -1, -1, 55, -1, -1, -1, -1, 60, -1, - -1, 63, 64, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 32, -1, -1, 35, 36, 37, 38, -1, - -1, 41, 42, 43, -1, 45, 46, 5, 6, 7, - -1, -1, -1, -1, -1, 55, -1, -1, -1, 59, - -1, -1, -1, 63, 64, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 32, -1, -1, 35, 36, 37, - 38, -1, -1, 41, 42, 43, -1, 45, 46, 5, - 6, 7, -1, -1, -1, -1, -1, 55, -1, -1, - -1, 59, -1, -1, -1, 63, 64, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 32, -1, -1, 35, - 36, 37, 38, -1, -1, 41, 42, 43, -1, 45, - 46, 5, 6, 7, -1, -1, -1, -1, -1, 55, - 56, -1, -1, -1, -1, -1, -1, 63, 64, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 32, -1, - -1, 35, 36, 37, 38, -1, -1, 41, 42, 43, - -1, 45, 46, 5, 6, 7, -1, -1, -1, -1, - -1, 55, 56, -1, -1, -1, -1, -1, -1, 63, - 64, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 32, -1, -1, 35, 36, 37, 38, -1, -1, 41, - 42, 43, -1, 45, 46, 5, 6, 7, -1, -1, - -1, -1, -1, 55, 56, -1, -1, -1, -1, -1, - -1, 63, 64, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 32, -1, -1, 35, 36, 37, 38, -1, - -1, 41, 42, 43, -1, 45, 46, -1, -1, 44, - 45, 46, 47, 48, 49, 55, 51, 52, 53, 54, - -1, 56, 57, 63, 64, -1, -1, 62, -1, -1, - 65, 66, 67, -1, -1, -1, 71, 72, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 84, - 85, 86, 87, 88, 89, 90, -1, -1, -1, -1, - -1, 96, 97, 44, 45, 46, 47, 48, 49, -1, - 51, 52, 53, 54, -1, -1, 57, -1, 59, -1, - -1, 62, -1, -1, 65, 66, 67, -1, -1, -1, - 71, 72, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 84, 85, 86, 87, 88, 89, 90, - -1, -1, -1, -1, -1, 96, 97, 44, 45, 46, - 47, 48, 49, -1, 51, 52, 53, 54, -1, -1, - -1, -1, 59, -1, -1, 62, -1, -1, 65, 66, - 67, -1, -1, -1, 71, 72, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 84, 85, 86, - 87, 88, 89, 90, -1, -1, -1, -1, -1, 96, - 97, 44, 45, 46, 47, 48, 49, -1, 51, 52, - 53, 54, -1, 56, -1, -1, -1, -1, -1, 62, - -1, -1, 65, 66, 67, -1, -1, -1, 71, 72, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 84, 85, 86, 87, 88, 89, 90, -1, -1, - -1, -1, -1, 96, 97, 44, 45, 46, 47, 48, - 49, -1, 51, 52, 53, 54, -1, 56, -1, -1, - -1, -1, -1, 62, -1, -1, 65, 66, 67, -1, - -1, -1, 71, 72, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 84, 85, 86, 87, 88, - 89, 90, -1, -1, -1, -1, -1, 96, 97, 44, - 45, 46, 47, 48, 49, -1, 51, 52, 53, 54, - -1, 56, -1, -1, -1, -1, -1, 62, -1, -1, - 65, 66, 67, -1, -1, -1, 71, 72, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 84, - 85, 86, 87, 88, 89, 90, -1, -1, -1, -1, - -1, 96, 97, 44, 45, 46, 47, 48, 49, -1, - 51, 52, 53, 54, -1, 56, -1, -1, -1, -1, - -1, 62, -1, -1, 65, 66, 67, -1, -1, -1, - 71, 72, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 84, 85, 86, 87, 88, 89, 90, - -1, -1, -1, -1, -1, 96, 97, 44, 45, 46, - 47, 48, 49, -1, 51, 52, 53, 54, -1, -1, - -1, -1, 59, -1, -1, 62, -1, -1, 65, 66, - 67, -1, -1, -1, 71, 72, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 84, 85, 86, - 87, 88, 89, 90, -1, -1, -1, -1, -1, 96, - 97, 44, 45, 46, 47, 48, 49, -1, 51, 52, - 53, 54, -1, 56, -1, -1, -1, -1, -1, 62, - -1, -1, 65, 66, 67, -1, -1, -1, 71, 72, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 84, 85, 86, 87, 88, 89, 90, -1, -1, - -1, -1, -1, 96, 97, 44, 45, 46, 47, 48, - 49, -1, 51, 52, 53, 54, -1, 56, -1, -1, - -1, -1, -1, 62, -1, -1, 65, 66, 67, -1, - -1, -1, 71, 72, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 84, 85, 86, 87, 88, - 89, 90, -1, -1, -1, -1, -1, 96, 97, 44, - 45, 46, 47, 48, 49, -1, 51, 52, 53, 54, - -1, -1, -1, 58, -1, -1, -1, 62, -1, -1, - 65, 66, 67, -1, -1, -1, 71, 72, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 84, - 85, 86, 87, 88, 89, 90, -1, -1, -1, -1, - -1, 96, 97, 44, 45, 46, 47, 48, 49, -1, - 51, 52, 53, 54, -1, -1, -1, -1, 59, -1, - -1, 62, -1, -1, 65, 66, 67, -1, -1, -1, - 71, 72, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 84, 85, 86, 87, 88, 89, 90, - -1, -1, -1, -1, -1, 96, 97, 44, 45, 46, - 47, 48, 49, -1, 51, 52, 53, 54, -1, -1, - -1, 58, -1, -1, -1, 62, -1, -1, 65, 66, - 67, -1, -1, -1, 71, 72, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 84, 85, 86, - 87, 88, 89, 90, -1, -1, -1, -1, -1, 96, - 97, 44, 45, 46, 47, 48, 49, -1, 51, 52, - 53, 54, -1, 56, -1, -1, -1, -1, -1, 62, - -1, -1, 65, 66, 67, -1, -1, -1, 71, 72, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 84, 85, 86, 87, 88, 89, 90, -1, -1, - -1, -1, -1, 96, 97, 44, 45, 46, 47, 48, - 49, -1, 51, 52, 53, 54, -1, 56, -1, -1, - -1, -1, -1, 62, -1, -1, 65, 66, 67, -1, - -1, -1, 71, 72, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 84, 85, 86, 87, 88, - 89, 90, -1, -1, -1, -1, -1, 96, 97, 44, - 45, 46, 47, 48, 49, -1, 51, 52, 53, 54, - -1, -1, -1, -1, 59, -1, -1, 62, -1, -1, - 65, 66, 67, -1, -1, -1, 71, 72, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 84, - 85, 86, 87, 88, 89, 90, -1, -1, -1, -1, - -1, 96, 97, 44, 45, 46, 47, 48, 49, -1, - 51, 52, 53, 54, -1, 56, -1, -1, -1, -1, - -1, 62, -1, -1, 65, 66, 67, -1, -1, -1, - 71, 72, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 84, 85, 86, 87, 88, 89, 90, - -1, -1, -1, -1, -1, 96, 97, 44, 45, 46, - 47, 48, 49, -1, 51, 52, 53, 54, -1, 56, - -1, -1, -1, -1, -1, 62, -1, -1, 65, 66, - 67, -1, -1, -1, 71, 72, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 84, 85, 86, - 87, 88, 89, 90, -1, -1, -1, -1, -1, 96, - 97, 44, 45, 46, 47, 48, 49, -1, 51, 52, - 53, 54, -1, -1, -1, -1, 59, -1, -1, 62, - -1, -1, 65, 66, 67, -1, -1, -1, 71, 72, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 84, 85, 86, 87, 88, 89, 90, -1, -1, - -1, -1, -1, 96, 97, 44, 45, 46, 47, 48, - 49, -1, 51, 52, 53, 54, -1, 56, -1, -1, - -1, -1, -1, 62, -1, -1, 65, 66, 67, -1, - -1, -1, 71, 72, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 84, 85, 86, 87, 88, - 89, 90, -1, -1, -1, -1, -1, 96, 97, 44, - 45, 46, 47, 48, 49, -1, 51, 52, 53, 54, - -1, 56, -1, -1, -1, -1, -1, 62, -1, -1, - 65, 66, 67, -1, -1, -1, 71, 72, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 84, - 85, 86, 87, 88, 89, 90, -1, -1, -1, -1, - -1, 96, 97, 44, 45, 46, 47, 48, 49, -1, - 51, 52, 53, 54, -1, 56, -1, -1, -1, -1, - -1, 62, -1, -1, 65, 66, 67, -1, -1, -1, - 71, 72, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 84, 85, 86, 87, 88, 89, 90, - -1, -1, -1, -1, -1, 96, 97, 44, 45, 46, - 47, 48, 49, -1, 51, 52, 53, 54, -1, -1, - -1, -1, 59, -1, -1, 62, -1, -1, 65, 66, - 67, -1, -1, -1, 71, 72, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 84, 85, 86, - 87, 88, 89, 90, -1, -1, -1, -1, -1, 96, - 97, 44, 45, 46, 47, 48, 49, -1, 51, 52, - 53, 54, -1, -1, -1, -1, 59, -1, -1, 62, - -1, -1, 65, 66, 67, -1, -1, -1, 71, 72, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 84, 85, 86, 87, 88, 89, 90, -1, -1, - -1, -1, -1, 96, 97, 44, 45, 46, 47, 48, - 49, -1, 51, 52, 53, 54, -1, -1, -1, -1, - 59, -1, -1, 62, -1, -1, 65, 66, 67, -1, - -1, -1, 71, 72, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 84, 85, 86, 87, 88, - 89, 90, -1, -1, -1, -1, -1, 96, 97, 44, - 45, 46, 47, 48, 49, -1, 51, 52, 53, 54, - -1, -1, -1, -1, 59, -1, -1, 62, -1, -1, - 65, 66, 67, -1, -1, -1, 71, 72, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 84, - 85, 86, 87, 88, 89, 90, -1, -1, -1, -1, - -1, 96, 97, 44, 45, 46, 47, 48, 49, -1, - 51, 52, 53, 54, -1, -1, -1, -1, 59, -1, - -1, 62, -1, -1, 65, 66, 67, -1, -1, -1, - 71, 72, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 84, 85, 86, 87, 88, 89, 90, - -1, -1, -1, -1, -1, 96, 97, 44, 45, 46, - 47, 48, 49, -1, 51, 52, 53, 54, -1, -1, - -1, -1, -1, -1, -1, 62, -1, -1, 65, 66, - 67, -1, -1, -1, 71, 72, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 84, 85, 86, - 87, 88, 89, 90, -1, -1, -1, -1, -1, 96, - 97, 44, 45, 46, 47, 48, 49, -1, 51, 52, - 53, 54, -1, -1, -1, -1, -1, -1, -1, 62, - -1, -1, 65, 66, 67, -1, -1, -1, 71, 72, - 44, 45, 46, 47, 48, 49, -1, 51, 52, 53, - 54, 84, 85, 86, 87, 88, 89, 90, 62, -1, - -1, 65, 66, 67, 97, -1, -1, 71, 72, 44, - 45, 46, 47, 48, 49, -1, 51, 52, 53, 54, - 84, 85, 86, 87, 88, -1, 90, 62, -1, -1, - 65, 66, 67, 97, -1, -1, 71, 72, 44, 45, - 46, 47, 48, 49, -1, 51, -1, 53, 54, 84, - 85, 86, 87, -1, -1, 90, 62, -1, -1, 65, - 66, 67, 97, -1, -1, 71, 72, 44, 45, 46, - 47, 48, 49, -1, 51, -1, 53, 54, 84, 85, - 86, 87, -1, -1, 90, -1, -1, -1, 65, 66, - 67, 97, -1, -1, 71, 72, 44, 45, 46, 47, - 48, 49, -1, 51, -1, -1, 54, 84, 85, 86, - 87, -1, -1, 90, -1, -1, -1, 65, 66, 67, - 97, -1, -1, 71, 72, 44, 45, 46, 47, 48, - 49, -1, 51, -1, -1, 54, 84, 85, 86, 87, - -1, -1, 90, -1, -1, -1, 65, 66, 67, 97, - -1, -1, 71, 72, 44, 45, 46, 47, -1, -1, - -1, 51, -1, -1, 54, 50, -1, 86, 87, -1, - -1, 90, -1, -1, -1, 65, 66, 67, 97, -1, - -1, 71, 72, 68, 69, 50, -1, -1, 73, 74, - 75, 76, 77, 78, 79, 80, 81, 82, -1, -1, - 90, -1, -1, 68, 69, -1, -1, 97, 73, 74, - 75, 76, 77, 78, 79, 80, 81, 82, 44, 45, - 46, 47, -1, -1, -1, 51, -1, -1, 54, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 66, 67, -1, -1, -1, 71, 72 -}; -/* -*-C-*- Note some compilers choke on comments on `#line' lines. */ -#line 3 "bison.simple" - -/* Skeleton output parser for bison, - Copyright (C) 1984, 1989, 1990 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 - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* As a special exception, when this file is copied by Bison into a - Bison output file, you may use that output file without restriction. - This special exception was added by the Free Software Foundation - in version 1.24 of Bison. */ - -#ifndef alloca -#ifdef __GNUC__ -#define alloca __builtin_alloca -#else /* not GNU C. */ -#if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) -#include -#else /* not sparc */ -#if defined (MSDOS) && !defined (__TURBOC__) -#include -#else /* not MSDOS, or __TURBOC__ */ -#if defined(_AIX) -#include - #pragma alloca -#else /* not MSDOS, __TURBOC__, or _AIX */ +/* Work around bug in HP-UX 11.23, which defines these macros + incorrectly for preprocessor constants. This workaround can likely + be removed in 2023, as HPE has promised support for HP-UX 11.23 + (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of + . */ #ifdef __hpux -#ifdef __cplusplus -extern "C" { -void *alloca (unsigned int); +# undef UINT_LEAST8_MAX +# undef UINT_LEAST16_MAX +# define UINT_LEAST8_MAX 255 +# define UINT_LEAST16_MAX 65535 +#endif + +#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST8_TYPE__ yytype_uint8; +#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \ + && UINT_LEAST8_MAX <= INT_MAX) +typedef uint_least8_t yytype_uint8; +#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX +typedef unsigned char yytype_uint8; +#else +typedef short yytype_uint8; +#endif + +#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST16_TYPE__ yytype_uint16; +#elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \ + && UINT_LEAST16_MAX <= INT_MAX) +typedef uint_least16_t yytype_uint16; +#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX +typedef unsigned short yytype_uint16; +#else +typedef int yytype_uint16; +#endif + +#ifndef YYPTRDIFF_T +# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__ +# define YYPTRDIFF_T __PTRDIFF_TYPE__ +# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__ +# elif defined PTRDIFF_MAX +# ifndef ptrdiff_t +# include /* INFRINGES ON USER NAME SPACE */ +# endif +# define YYPTRDIFF_T ptrdiff_t +# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX +# else +# define YYPTRDIFF_T long +# define YYPTRDIFF_MAXIMUM LONG_MAX +# endif +#endif + +#ifndef YYSIZE_T +# ifdef __SIZE_TYPE__ +# define YYSIZE_T __SIZE_TYPE__ +# elif defined size_t +# define YYSIZE_T size_t +# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ +# include /* INFRINGES ON USER NAME SPACE */ +# define YYSIZE_T size_t +# else +# define YYSIZE_T unsigned +# endif +#endif + +#define YYSIZE_MAXIMUM \ + YY_CAST (YYPTRDIFF_T, \ + (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \ + ? YYPTRDIFF_MAXIMUM \ + : YY_CAST (YYSIZE_T, -1))) + +#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X)) + + +/* Stored state numbers (used for stacks). */ +typedef yytype_int16 yy_state_t; + +/* State numbers in computations. */ +typedef int yy_state_fast_t; + +#ifndef YY_ +# if defined YYENABLE_NLS && YYENABLE_NLS +# if ENABLE_NLS +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_(Msgid) dgettext ("bison-runtime", Msgid) +# endif +# endif +# ifndef YY_ +# define YY_(Msgid) Msgid +# endif +#endif + + +#ifndef YY_ATTRIBUTE_PURE +# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_PURE __attribute__ ((__pure__)) +# else +# define YY_ATTRIBUTE_PURE +# endif +#endif + +#ifndef YY_ATTRIBUTE_UNUSED +# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__)) +# else +# define YY_ATTRIBUTE_UNUSED +# endif +#endif + +/* Suppress unused-variable warnings by "using" E. */ +#if ! defined lint || defined __GNUC__ +# define YY_USE(E) ((void) (E)) +#else +# define YY_USE(E) /* empty */ +#endif + +/* Suppress an incorrect diagnostic about yylval being uninitialized. */ +#if defined __GNUC__ && ! defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__ +# if __GNUC__ * 100 + __GNUC_MINOR__ < 407 +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") +# else +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \ + _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +# endif +# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ + _Pragma ("GCC diagnostic pop") +#else +# define YY_INITIAL_VALUE(Value) Value +#endif +#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 + +#if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__ +# define YY_IGNORE_USELESS_CAST_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"") +# define YY_IGNORE_USELESS_CAST_END \ + _Pragma ("GCC diagnostic pop") +#endif +#ifndef YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_END +#endif + + +#define YY_ASSERT(E) ((void) (0 && (E))) + +#if !defined yyoverflow + +/* The parser invokes alloca or malloc; define the necessary symbols. */ + +# ifdef YYSTACK_USE_ALLOCA +# if YYSTACK_USE_ALLOCA +# ifdef __GNUC__ +# define YYSTACK_ALLOC __builtin_alloca +# elif defined __BUILTIN_VA_ARG_INCR +# include /* INFRINGES ON USER NAME SPACE */ +# elif defined _AIX +# define YYSTACK_ALLOC __alloca +# elif defined _MSC_VER +# include /* INFRINGES ON USER NAME SPACE */ +# define alloca _alloca +# else +# define YYSTACK_ALLOC alloca +# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS +# include /* INFRINGES ON USER NAME SPACE */ + /* Use EXIT_SUCCESS as a witness for stdlib.h. */ +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 +# endif +# endif +# endif +# endif +# endif + +# ifdef YYSTACK_ALLOC + /* Pacify GCC's 'empty if-body' warning. */ +# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) +# ifndef YYSTACK_ALLOC_MAXIMUM + /* The OS might guarantee only one guard page at the bottom of the stack, + and a page size can be as small as 4096 bytes. So we cannot safely + invoke alloca (N) if N exceeds 4096. Use a slightly smaller number + to allow for a few compiler-allocated temporary stack slots. */ +# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ +# endif +# else +# define YYSTACK_ALLOC YYMALLOC +# define YYSTACK_FREE YYFREE +# ifndef YYSTACK_ALLOC_MAXIMUM +# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM +# endif +# if (defined __cplusplus && ! defined EXIT_SUCCESS \ + && ! ((defined YYMALLOC || defined malloc) \ + && (defined YYFREE || defined free))) +# include /* INFRINGES ON USER NAME SPACE */ +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 +# endif +# endif +# ifndef YYMALLOC +# define YYMALLOC malloc +# if ! defined malloc && ! defined EXIT_SUCCESS +void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# ifndef YYFREE +# define YYFREE free +# if ! defined free && ! defined EXIT_SUCCESS +void free (void *); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# endif +#endif /* !defined yyoverflow */ + +#if (! defined yyoverflow \ + && (! defined __cplusplus \ + || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) + +/* A type that is properly aligned for any stack member. */ +union yyalloc +{ + yy_state_t yyss_alloc; + YYSTYPE yyvs_alloc; }; -#else /* not __cplusplus */ -void *alloca (); -#endif /* not __cplusplus */ -#endif /* __hpux */ -#endif /* not _AIX */ -#endif /* not MSDOS, or __TURBOC__ */ -#endif /* not sparc. */ -#endif /* not GNU C. */ -#endif /* alloca not defined. */ -/* This is the parser code that is written into each bison parser - when the %semantic_parser declaration is not specified in the grammar. - It was written by Richard Stallman by simplifying the hairy parser - used when %semantic_parser is specified. */ +/* The size of the maximum gap between one aligned stack and the next. */ +# define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1) + +/* The size of an array large to enough to hold all stacks, each with + N elements. */ +# define YYSTACK_BYTES(N) \ + ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \ + + YYSTACK_GAP_MAXIMUM) + +# 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 + elements in the stack, and YYPTR gives the new location of the + stack. Advance YYPTR to a properly aligned location for the next + stack. */ +# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ + do \ + { \ + YYPTRDIFF_T yynewbytes; \ + YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ + Stack = &yyptr->Stack_alloc; \ + yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / YYSIZEOF (*yyptr); \ + } \ + while (0) + +#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, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src))) +# else +# define YYCOPY(Dst, Src, Count) \ + do \ + { \ + YYPTRDIFF_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (Dst)[yyi] = (Src)[yyi]; \ + } \ + while (0) +# endif +# endif +#endif /* !YYCOPY_NEEDED */ + +/* YYFINAL -- State number of the termination state. */ +#define YYFINAL 3 +/* YYLAST -- Last index in YYTABLE. */ +#define YYLAST 2858 + +/* YYNTOKENS -- Number of terminals. */ +#define YYNTOKENS 100 +/* YYNNTS -- Number of nonterminals. */ +#define YYNNTS 41 +/* YYNRULES -- Number of rules. */ +#define YYNRULES 162 +/* YYNSTATES -- Number of states. */ +#define YYNSTATES 380 + +/* YYMAXUTOK -- Last valid token kind. */ +#define YYMAXUTOK 329 + + +/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM + as returned by yylex, with out-of-bounds checking. */ +#define YYTRANSLATE(YYX) \ + (0 <= (YYX) && (YYX) <= YYMAXUTOK \ + ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \ + : YYSYMBOL_YYUNDEF) + +/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM + as returned by yylex. */ +static const yytype_int8 yytranslate[] = +{ + 0, 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, 64, 2, 2, 2, 54, 53, 2, + 55, 56, 46, 44, 57, 45, 51, 47, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 58, 59, + 48, 50, 49, 96, 65, 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, 92, 2, 99, 62, 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, 60, 52, 61, 63, 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, 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, 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, 1, 2, 3, 4, + 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, + 35, 36, 37, 38, 39, 40, 41, 42, 43, 66, + 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, + 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, + 87, 88, 89, 90, 91, 93, 94, 95, 97, 98 +}; + +#if YYDEBUG +/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ +static const yytype_int16 yyrline[] = +{ + 0, 161, 161, 167, 168, 173, 175, 177, 182, 187, + 189, 195, 196, 201, 202, 203, 204, 205, 206, 207, + 209, 211, 213, 215, 217, 219, 221, 226, 228, 234, + 235, 240, 242, 247, 252, 254, 256, 258, 260, 262, + 268, 269, 275, 276, 282, 283, 289, 290, 292, 294, + 299, 301, 306, 308, 313, 315, 320, 322, 324, 329, + 331, 336, 338, 343, 345, 350, 352, 354, 356, 358, + 360, 362, 364, 369, 371, 376, 381, 383, 385, 387, + 389, 391, 393, 395, 397, 399, 401, 403, 405, 407, + 409, 411, 413, 415, 417, 419, 421, 423, 425, 427, + 429, 431, 433, 435, 437, 439, 441, 443, 445, 447, + 449, 451, 453, 455, 457, 479, 481, 486, 488, 493, + 495, 500, 502, 504, 506, 508, 510, 512, 514, 516, + 518, 520, 522, 527, 529, 531, 533, 535, 537, 539, + 541, 543, 545, 550, 552, 554, 564, 566, 572, 573, + 578, 580, 586, 587, 592, 594, 599, 601, 603, 605, + 607, 612, 614 +}; +#endif + +/** Accessing symbol of state STATE. */ +#define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State]) + +#if YYDEBUG || 0 +/* The user-facing name of the symbol whose (internal) number is + YYSYMBOL. No bounds checking. */ +static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED; + +/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at YYNTOKENS, nonterminals. */ +static const char *const yytname[] = +{ + "\"end of file\"", "error", "\"invalid token\"", "rwDEFINE", "rwENDDEF", + "rwDECLARE", "rwDECLARESINGLETON", "rwBREAK", "rwELSE", "rwCONTINUE", + "rwGLOBAL", "rwIF", "rwNIL", "rwRETURN", "rwWHILE", "rwDO", "rwENDIF", + "rwENDWHILE", "rwENDFOR", "rwDEFAULT", "rwFOR", "rwFOREACH", + "rwFOREACHSTR", "rwIN", "rwDATABLOCK", "rwSWITCH", "rwCASE", + "rwSWITCHSTR", "rwCASEOR", "rwPACKAGE", "rwNAMESPACE", "rwCLASS", + "rwASSERT", "ILLEGAL_TOKEN", "CHRCONST", "INTCONST", "TTAG", "VAR", + "IDENT", "TYPEIDENT", "DOCBLOCK", "STRATOM", "TAGATOM", "FLTCONST", + "'+'", "'-'", "'*'", "'/'", "'<'", "'>'", "'='", "'.'", "'|'", "'&'", + "'%'", "'('", "')'", "','", "':'", "';'", "'{'", "'}'", "'^'", "'~'", + "'!'", "'@'", "opINTNAME", "opINTNAMER", "opMINUSMINUS", "opPLUSPLUS", + "STMT_SEP", "opSHL", "opSHR", "opPLASN", "opMIASN", "opMLASN", "opDVASN", + "opMODASN", "opANDASN", "opXORASN", "opORASN", "opSLASN", "opSRASN", + "opCAT", "opEQ", "opNE", "opGE", "opLE", "opAND", "opOR", "opSTREQ", + "opCOLONCOLON", "'['", "opMDASN", "opNDASN", "opNTASN", "'?'", "opSTRNE", + "UNARY", "']'", "$accept", "start", "decl_list", "decl", "package_decl", + "fn_decl_list", "statement_list", "stmt", "fn_decl_stmt", + "var_list_decl", "var_list", "datablock_decl", "object_decl", + "parent_block", "object_name", "object_args", "object_declare_block", + "object_decl_list", "stmt_block", "switch_stmt", "case_block", + "case_expr", "if_stmt", "while_stmt", "for_stmt", "foreach_stmt", + "expression_stmt", "expr", "slot_acc", "intslot_acc", "class_name_expr", + "assign_op_struct", "stmt_expr", "funcall_expr", "assert_expr", + "expr_list_decl", "expr_list", "slot_assign_list_opt", + "slot_assign_list", "slot_assign", "aidx_expr", YY_NULLPTR +}; + +static const char * +yysymbol_name (yysymbol_kind_t yysymbol) +{ + return yytname[yysymbol]; +} +#endif + +#define YYPACT_NINF (-310) + +#define yypact_value_is_default(Yyn) \ + ((Yyn) == YYPACT_NINF) + +#define YYTABLE_NINF (-76) + +#define yytable_value_is_error(Yyn) \ + 0 + +/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ +static const yytype_int16 yypact[] = +{ + -310, 31, 397, -310, 4, 2, 2, -3, 32, 27, + 167, 34, 489, 40, 41, 43, 2, 44, 47, 66, + 55, -310, 67, 115, -33, -310, -310, -310, -310, 1002, + 1002, 1002, 1002, 1002, -310, -310, -310, -310, -310, -310, + -310, -310, -310, -310, -310, 59, 2465, 2727, -310, 71, + -310, -310, -12, -310, 1002, 81, 82, -310, -310, 1002, + -310, -310, -310, 1115, -310, 1002, -310, -310, 124, 708, + 108, 129, 97, 1002, 1002, 107, 1002, 1002, 1002, -310, + -310, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, + 1002, 1002, -310, 1002, 133, -34, -34, 1169, -34, -34, + -310, 1002, 1002, 1002, 1002, 1002, 1002, 137, 1002, 1002, + 1002, 1002, 1002, 2, 2, 1002, 1002, 1002, 1002, 1002, + 1002, 1002, 1002, 1002, 1002, 1002, 750, -310, 141, 143, + 1223, 9, 1002, 1277, -310, 1331, 549, 127, 792, 1385, + 156, 162, 1002, 1439, 1493, 183, 1007, 1061, 2465, 2465, + 2465, 2465, 2465, 2465, 2465, 2465, 2465, 2465, 2465, 2465, + -39, 2465, 131, 149, 159, -310, 292, 292, -34, -34, + 2722, 2722, -43, 2606, 2664, -34, 2635, 2786, -310, -310, + 39, 39, 2693, 2693, 2722, 2722, 2577, 2548, 2786, 1547, + 2786, 1002, 2465, -310, 142, 154, 160, -310, 1002, 158, + 2465, 158, 489, 489, -310, -310, 1002, 319, 1601, 834, + 1002, 1002, 1655, 157, 161, 5, -310, -310, 179, 1002, + -310, 1002, 2747, -310, 1002, 1002, 1002, 1002, 1002, -31, + 165, 190, 141, 135, 197, 171, 171, 231, -310, 1709, + 489, 1763, 876, 918, 1817, 1871, 1925, 184, 217, 217, + 187, -310, 194, 1979, 2465, 1002, -310, 2465, 199, 200, + -38, 2519, -310, -310, -310, 204, 158, -310, 1002, 205, + 211, 489, -310, -310, 489, 489, 2033, 489, 2087, 960, + 489, 489, 193, 1002, 207, 210, -310, -310, -310, 2465, + -310, -310, -310, 594, 214, 171, 149, 216, 222, -310, + -310, -310, 489, -310, 489, 489, 2141, -310, -310, 70, + -5, 2465, -310, -310, -310, -310, 221, 213, 213, -310, + -310, -310, 489, 233, -30, 246, 224, 70, -310, 1002, + -310, 639, 226, 228, 227, 23, 213, 229, -310, 1002, + 1002, 1002, -29, 230, -310, 2465, 444, -310, 213, -310, + -310, 235, 23, -310, 2195, 2249, -23, 1002, 1002, -310, + 237, -310, 236, -310, -310, -310, 248, 2303, -19, -310, + -310, 1002, -310, 249, 684, 2357, 1002, -310, 2411, -310 +}; + +/* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. + Performed when YYTABLE does not specify something else to do. Zero + means the default is an error. */ +static const yytype_uint8 yydefact[] = +{ + 3, 0, 2, 1, 0, 0, 0, 108, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 107, 88, 113, 111, 26, 112, 105, 106, 0, + 0, 0, 0, 0, 4, 7, 5, 6, 17, 135, + 18, 13, 14, 15, 16, 0, 0, 109, 110, 76, + 133, 134, 0, 119, 0, 0, 0, 19, 20, 0, + 108, 88, 21, 0, 76, 0, 11, 53, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 122, + 121, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 138, 148, 0, 86, 87, 0, 104, 103, + 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 140, 29, 0, + 0, 42, 42, 0, 22, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 136, 123, + 124, 125, 126, 127, 128, 129, 130, 131, 132, 161, + 0, 150, 0, 149, 0, 77, 82, 83, 84, 85, + 90, 91, 115, 81, 80, 79, 78, 102, 117, 118, + 97, 98, 94, 95, 92, 93, 99, 96, 100, 0, + 101, 0, 141, 31, 0, 30, 0, 120, 42, 40, + 43, 40, 0, 0, 52, 12, 0, 0, 0, 0, + 0, 0, 40, 0, 0, 0, 9, 146, 0, 0, + 24, 0, 114, 143, 0, 148, 148, 0, 0, 0, + 0, 0, 29, 0, 0, 44, 44, 61, 63, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 10, 0, 0, 162, 0, 139, 151, 0, 0, + 0, 89, 142, 11, 32, 0, 40, 41, 0, 0, + 0, 0, 64, 72, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 8, 147, 25, 137, + 144, 145, 116, 0, 0, 44, 45, 35, 39, 62, + 71, 70, 0, 68, 0, 0, 0, 73, 74, 152, + 0, 59, 54, 55, 27, 11, 0, 46, 46, 69, + 67, 66, 0, 0, 0, 0, 0, 153, 154, 0, + 11, 0, 37, 0, 0, 48, 47, 0, 65, 0, + 0, 0, 0, 0, 155, 60, 56, 28, 46, 50, + 34, 0, 49, 38, 0, 0, 0, 0, 0, 33, + 0, 58, 0, 51, 158, 156, 0, 0, 0, 11, + 36, 0, 157, 0, 57, 0, 0, 159, 0, 160 +}; + +/* YYPGOTO[NTERM-NUM]. */ +static const yytype_int16 yypgoto[] = +{ + -310, -310, -310, -310, -310, -310, -256, -1, -140, 64, + -310, -310, -94, -188, -121, -230, -309, -28, 30, -310, + -246, -310, -310, -310, -310, -310, -310, 38, -310, -310, + 19, -45, -2, -310, -310, -138, -187, -310, 0, -300, + -190 +}; + +/* YYDEFGOTO[NTERM-NUM]. */ +static const yytype_int16 yydefgoto[] = +{ + 0, 1, 2, 34, 35, 215, 136, 67, 37, 194, + 195, 38, 39, 235, 199, 269, 334, 335, 68, 40, + 284, 310, 41, 42, 43, 44, 45, 46, 47, 48, + 55, 92, 64, 50, 51, 162, 163, 326, 336, 328, + 160 +}; + +/* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule whose + number is the opposite. If YYTABLE_NINF, syntax error. */ +static const yytype_int16 yytable[] = +{ + 49, 36, 127, 285, 229, 216, 270, 293, 4, 337, + 49, 201, 226, 236, 5, 6, 60, 107, 221, 221, + 340, 357, 93, 329, 247, 56, 224, 344, 5, 6, + 262, 3, 113, 114, 221, 72, 344, 260, 221, 362, + 53, 20, 52, 128, 21, 61, 23, 24, 63, 227, + 26, 27, 28, 330, 29, 30, 57, 54, 94, 331, + 222, 292, 341, 358, 31, 316, 250, 95, 96, 97, + 98, 99, 32, 33, 346, 251, 366, 233, 295, 129, + 373, 296, 59, 101, 102, 103, 104, 258, 259, 65, + 107, 58, 130, 110, 323, 69, 70, 133, 71, 73, + 361, 198, 74, 135, 75, 113, 114, 139, 324, 325, + 76, 143, 144, 374, 146, 147, 148, 77, 100, 149, + 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, + -75, 161, 178, 179, 49, 205, 131, 132, 137, 166, + 167, 168, 169, 170, 171, 140, 173, 174, 175, 176, + 177, 356, 142, 180, 181, 182, 183, 184, 185, 186, + 187, 188, 189, 190, 192, 78, 141, 145, 368, 200, + 200, 164, 5, 6, 60, 172, 208, 256, 193, 210, + 212, 196, 206, 79, 80, 211, 4, 223, 81, 82, + 83, 84, 85, 86, 87, 88, 89, 90, 230, 20, + 49, 49, 21, 61, 23, 24, 224, 91, 26, 27, + 28, 231, 29, 30, 225, 232, 234, 248, 5, 6, + 252, 249, 31, 333, 333, 263, 62, 264, 268, 161, + 32, 33, 237, 238, 266, 267, 200, 323, 49, 271, + 282, 351, 333, 283, 239, 241, 286, 244, 245, 246, + 287, 324, 325, 309, 333, 290, 291, 253, 351, 254, + 294, 297, 257, 161, 161, 159, 261, 298, 312, 49, + 273, 313, 49, 49, 315, 49, 317, 332, 49, 49, + 276, 278, 318, 339, 342, 343, 348, 349, 350, 359, + 353, 49, 205, 289, 363, 369, 265, 370, 371, 376, + 49, 299, 49, 49, 300, 301, 161, 303, 352, 327, + 307, 308, 0, 0, 0, 0, 0, 306, 0, 0, + 49, 311, 0, 0, 5, 6, 60, 0, 0, 49, + 205, 0, 319, 0, 320, 321, 0, 0, 103, 104, + 0, 0, 0, 107, 49, 205, 110, 0, 0, 0, + 0, 20, 338, 0, 21, 61, 23, 24, 113, 114, + 26, 27, 28, 0, 29, 30, 0, 345, 0, 0, + 0, 0, 49, 205, 31, 240, 0, 354, 355, 159, + 0, 0, 32, 33, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 367, 159, 0, 0, 0, + 4, 0, 5, 6, 7, 0, 8, 0, 9, 375, + 10, 11, 12, 0, 378, 0, 0, 13, 14, 15, + 0, 16, 17, 0, 18, 0, 19, 0, 0, 20, + 0, 0, 21, 22, 23, 24, 0, 25, 26, 27, + 28, 0, 29, 30, 0, 0, 0, 0, 0, 5, + 6, 7, 31, 8, 0, 9, 0, 10, 11, 12, + 32, 33, 0, 360, 13, 14, 15, 0, 16, 17, + 283, 18, 0, 0, 0, 0, 20, 0, 0, 21, + 22, 23, 24, 0, 25, 26, 27, 28, 0, 29, + 30, 0, 0, 0, 5, 6, 7, 0, 8, 31, + 9, 0, 10, 11, 12, 0, 0, 32, 33, 13, + 14, 15, 0, 16, 17, 0, 18, 0, 0, 0, + 0, 20, 0, 0, 21, 22, 23, 24, 0, 25, + 26, 27, 28, 0, 29, 30, 0, 0, 0, 0, + 0, 0, 0, 0, 31, 0, 0, 0, 0, 66, + 0, 0, 32, 33, 5, 6, 7, 0, 8, 0, + 9, 0, 10, 11, 12, 0, 0, 0, 0, 13, + 14, 15, 0, 16, 17, 0, 18, 0, 0, 0, + 0, 20, 0, 0, 21, 22, 23, 24, 0, 25, + 26, 27, 28, 0, 29, 30, 0, 0, 0, 5, + 6, 7, 0, 8, 31, 9, 0, 10, 11, 12, + 204, 0, 32, 33, 13, 14, 15, 0, 16, 17, + 0, 18, 0, 0, 0, 0, 20, 0, 0, 21, + 22, 23, 24, 0, 25, 26, 27, 28, 0, 29, + 30, 0, 0, 0, 5, 6, 7, 0, 8, 31, + 9, 0, 10, 11, 12, 314, 0, 32, 33, 13, + 14, 15, 0, 16, 17, 0, 18, 0, 0, 0, + 0, 20, 0, 0, 21, 22, 23, 24, 0, 25, + 26, 27, 28, 0, 29, 30, 0, 0, 0, 5, + 6, 7, 0, 8, 31, 9, 0, 10, 11, 12, + 347, 0, 32, 33, 13, 14, 15, 0, 16, 17, + 0, 18, 0, 5, 6, 60, 20, 0, 0, 21, + 22, 23, 24, 0, 25, 26, 27, 28, 0, 29, + 30, 0, 0, 0, 0, 0, 0, 0, 0, 31, + 20, 0, 0, 21, 61, 23, 24, 32, 33, 26, + 27, 28, 0, 29, 30, 5, 6, 60, 0, 0, + 0, 0, 0, 31, 0, 0, 0, 138, 0, 0, + 0, 32, 33, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 20, 0, 0, 21, 61, 23, 24, 0, + 0, 26, 27, 28, 0, 29, 30, 5, 6, 60, + 0, 0, 0, 0, 0, 31, 0, 0, 0, 0, + 191, 0, 0, 32, 33, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 20, 0, 0, 21, 61, 23, + 24, 0, 0, 26, 27, 28, 0, 29, 30, 5, + 6, 60, 0, 0, 0, 0, 0, 31, 0, 0, + 0, 207, 0, 0, 0, 32, 33, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 20, 0, 0, 21, + 61, 23, 24, 0, 0, 26, 27, 28, 0, 29, + 30, 5, 6, 60, 0, 0, 0, 0, 0, 31, + 0, 0, 0, 243, 0, 0, 0, 32, 33, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, + 0, 21, 61, 23, 24, 0, 0, 26, 27, 28, + 0, 29, 30, 5, 6, 60, 0, 0, 0, 0, + 0, 31, 275, 0, 0, 0, 0, 0, 0, 32, + 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 20, 0, 0, 21, 61, 23, 24, 0, 0, 26, + 27, 28, 0, 29, 30, 5, 6, 60, 0, 0, + 0, 0, 0, 31, 277, 0, 0, 0, 0, 0, + 0, 32, 33, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 20, 0, 0, 21, 61, 23, 24, 0, + 0, 26, 27, 28, 0, 29, 30, 5, 6, 60, + 0, 0, 0, 0, 0, 31, 305, 0, 0, 0, + 0, 0, 0, 32, 33, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 20, 0, 0, 21, 61, 23, + 24, 0, 0, 26, 27, 28, 0, 29, 30, 0, + 0, 101, 102, 103, 104, 105, 106, 31, 107, 108, + 109, 110, 0, 217, 218, 32, 33, 0, 0, 111, + 0, 0, 112, 113, 114, 0, 0, 0, 115, 116, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 117, 118, 119, 120, 121, 122, 123, 0, 0, + 0, 0, 0, 124, 125, 101, 102, 103, 104, 105, + 106, 0, 107, 108, 109, 110, 0, 0, 219, 0, + 220, 0, 0, 111, 0, 0, 112, 113, 114, 0, + 0, 0, 115, 116, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 117, 118, 119, 120, 121, + 122, 123, 0, 0, 0, 0, 0, 124, 125, 101, + 102, 103, 104, 105, 106, 0, 107, 108, 109, 110, + 0, 0, 0, 0, 134, 0, 0, 111, 0, 0, + 112, 113, 114, 0, 0, 0, 115, 116, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 117, + 118, 119, 120, 121, 122, 123, 0, 0, 0, 0, + 0, 124, 125, 101, 102, 103, 104, 105, 106, 0, + 107, 108, 109, 110, 0, 165, 0, 0, 0, 0, + 0, 111, 0, 0, 112, 113, 114, 0, 0, 0, + 115, 116, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 117, 118, 119, 120, 121, 122, 123, + 0, 0, 0, 0, 0, 124, 125, 101, 102, 103, + 104, 105, 106, 0, 107, 108, 109, 110, 0, 197, + 0, 0, 0, 0, 0, 111, 0, 0, 112, 113, + 114, 0, 0, 0, 115, 116, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 117, 118, 119, + 120, 121, 122, 123, 0, 0, 0, 0, 0, 124, + 125, 101, 102, 103, 104, 105, 106, 0, 107, 108, + 109, 110, 0, 202, 0, 0, 0, 0, 0, 111, + 0, 0, 112, 113, 114, 0, 0, 0, 115, 116, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 117, 118, 119, 120, 121, 122, 123, 0, 0, + 0, 0, 0, 124, 125, 101, 102, 103, 104, 105, + 106, 0, 107, 108, 109, 110, 0, 203, 0, 0, + 0, 0, 0, 111, 0, 0, 112, 113, 114, 0, + 0, 0, 115, 116, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 117, 118, 119, 120, 121, + 122, 123, 0, 0, 0, 0, 0, 124, 125, 101, + 102, 103, 104, 105, 106, 0, 107, 108, 109, 110, + 0, 0, 0, 0, 209, 0, 0, 111, 0, 0, + 112, 113, 114, 0, 0, 0, 115, 116, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 117, + 118, 119, 120, 121, 122, 123, 0, 0, 0, 0, + 0, 124, 125, 101, 102, 103, 104, 105, 106, 0, + 107, 108, 109, 110, 0, 213, 0, 0, 0, 0, + 0, 111, 0, 0, 112, 113, 114, 0, 0, 0, + 115, 116, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 117, 118, 119, 120, 121, 122, 123, + 0, 0, 0, 0, 0, 124, 125, 101, 102, 103, + 104, 105, 106, 0, 107, 108, 109, 110, 0, 214, + 0, 0, 0, 0, 0, 111, 0, 0, 112, 113, + 114, 0, 0, 0, 115, 116, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 117, 118, 119, + 120, 121, 122, 123, 0, 0, 0, 0, 0, 124, + 125, 101, 102, 103, 104, 105, 106, 0, 107, 108, + 109, 110, 0, 0, 0, 228, 0, 0, 0, 111, + 0, 0, 112, 113, 114, 0, 0, 0, 115, 116, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 117, 118, 119, 120, 121, 122, 123, 0, 0, + 0, 0, 0, 124, 125, 101, 102, 103, 104, 105, + 106, 0, 107, 108, 109, 110, 0, 0, 0, 0, + 242, 0, 0, 111, 0, 0, 112, 113, 114, 0, + 0, 0, 115, 116, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 117, 118, 119, 120, 121, + 122, 123, 0, 0, 0, 0, 0, 124, 125, 101, + 102, 103, 104, 105, 106, 0, 107, 108, 109, 110, + 0, 0, 0, 234, 0, 0, 0, 111, 0, 0, + 112, 113, 114, 0, 0, 0, 115, 116, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 117, + 118, 119, 120, 121, 122, 123, 0, 0, 0, 0, + 0, 124, 125, 101, 102, 103, 104, 105, 106, 0, + 107, 108, 109, 110, 0, 272, 0, 0, 0, 0, + 0, 111, 0, 0, 112, 113, 114, 0, 0, 0, + 115, 116, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 117, 118, 119, 120, 121, 122, 123, + 0, 0, 0, 0, 0, 124, 125, 101, 102, 103, + 104, 105, 106, 0, 107, 108, 109, 110, 0, 274, + 0, 0, 0, 0, 0, 111, 0, 0, 112, 113, + 114, 0, 0, 0, 115, 116, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 117, 118, 119, + 120, 121, 122, 123, 0, 0, 0, 0, 0, 124, + 125, 101, 102, 103, 104, 105, 106, 0, 107, 108, + 109, 110, 0, 0, 0, 0, 279, 0, 0, 111, + 0, 0, 112, 113, 114, 0, 0, 0, 115, 116, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 117, 118, 119, 120, 121, 122, 123, 0, 0, + 0, 0, 0, 124, 125, 101, 102, 103, 104, 105, + 106, 0, 107, 108, 109, 110, 0, 280, 0, 0, + 0, 0, 0, 111, 0, 0, 112, 113, 114, 0, + 0, 0, 115, 116, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 117, 118, 119, 120, 121, + 122, 123, 0, 0, 0, 0, 0, 124, 125, 101, + 102, 103, 104, 105, 106, 0, 107, 108, 109, 110, + 0, 281, 0, 0, 0, 0, 0, 111, 0, 0, + 112, 113, 114, 0, 0, 0, 115, 116, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 117, + 118, 119, 120, 121, 122, 123, 0, 0, 0, 0, + 0, 124, 125, 101, 102, 103, 104, 105, 106, 0, + 107, 108, 109, 110, 0, 0, 0, 0, 288, 0, + 0, 111, 0, 0, 112, 113, 114, 0, 0, 0, + 115, 116, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 117, 118, 119, 120, 121, 122, 123, + 0, 0, 0, 0, 0, 124, 125, 101, 102, 103, + 104, 105, 106, 0, 107, 108, 109, 110, 0, 302, + 0, 0, 0, 0, 0, 111, 0, 0, 112, 113, + 114, 0, 0, 0, 115, 116, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 117, 118, 119, + 120, 121, 122, 123, 0, 0, 0, 0, 0, 124, + 125, 101, 102, 103, 104, 105, 106, 0, 107, 108, + 109, 110, 0, 304, 0, 0, 0, 0, 0, 111, + 0, 0, 112, 113, 114, 0, 0, 0, 115, 116, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 117, 118, 119, 120, 121, 122, 123, 0, 0, + 0, 0, 0, 124, 125, 101, 102, 103, 104, 105, + 106, 0, 107, 108, 109, 110, 0, 322, 0, 0, + 0, 0, 0, 111, 0, 0, 112, 113, 114, 0, + 0, 0, 115, 116, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 117, 118, 119, 120, 121, + 122, 123, 0, 0, 0, 0, 0, 124, 125, 101, + 102, 103, 104, 105, 106, 0, 107, 108, 109, 110, + 0, 0, 0, 0, 364, 0, 0, 111, 0, 0, + 112, 113, 114, 0, 0, 0, 115, 116, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 117, + 118, 119, 120, 121, 122, 123, 0, 0, 0, 0, + 0, 124, 125, 101, 102, 103, 104, 105, 106, 0, + 107, 108, 109, 110, 0, 0, 0, 0, 365, 0, + 0, 111, 0, 0, 112, 113, 114, 0, 0, 0, + 115, 116, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 117, 118, 119, 120, 121, 122, 123, + 0, 0, 0, 0, 0, 124, 125, 101, 102, 103, + 104, 105, 106, 0, 107, 108, 109, 110, 0, 0, + 0, 0, 372, 0, 0, 111, 0, 0, 112, 113, + 114, 0, 0, 0, 115, 116, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 117, 118, 119, + 120, 121, 122, 123, 0, 0, 0, 0, 0, 124, + 125, 101, 102, 103, 104, 105, 106, 0, 107, 108, + 109, 110, 0, 0, 0, 0, 377, 0, 0, 111, + 0, 0, 112, 113, 114, 0, 0, 0, 115, 116, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 117, 118, 119, 120, 121, 122, 123, 0, 0, + 0, 0, 0, 124, 125, 101, 102, 103, 104, 105, + 106, 0, 107, 108, 109, 110, 0, 0, 0, 0, + 379, 0, 0, 111, 0, 0, 112, 113, 114, 0, + 0, 0, 115, 116, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 117, 118, 119, 120, 121, + 122, 123, 0, 0, 0, 0, 0, 124, 125, 101, + 102, 103, 104, 105, 106, 0, 107, 108, 109, 110, + 0, 0, 0, 0, 0, 0, 0, 111, 0, 0, + 112, 113, 114, 0, 0, 0, 115, 116, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 117, + 118, 119, 120, 121, 122, 123, 0, 0, 0, 0, + 0, 124, 125, 101, 102, 103, 104, 105, 106, 0, + 107, 108, 109, 110, 0, 0, 0, 0, 0, 0, + 0, 111, 0, 0, 112, 113, 114, 0, 0, 0, + 115, 116, 101, 102, 103, 104, 105, 106, 0, 107, + 108, 109, 110, 117, 118, 119, 120, 121, 122, 123, + 111, 0, 0, 112, 113, 114, 125, 0, 0, 115, + 116, 101, 102, 103, 104, 105, 106, 0, 107, 108, + 109, 110, 117, 118, 119, 120, 121, 0, 123, 111, + 0, 0, 112, 113, 114, 125, 0, 0, 115, 116, + 101, 102, 103, 104, 105, 106, 0, 107, 0, 109, + 110, 117, 118, 119, 120, 0, 0, 123, 111, 0, + 0, 112, 113, 114, 125, 0, 0, 115, 116, 101, + 102, 103, 104, 105, 106, 0, 107, 0, 109, 110, + 117, 118, 119, 120, 0, 0, 123, 0, 0, 0, + 112, 113, 114, 125, 0, 0, 115, 116, 101, 102, + 103, 104, 105, 106, 0, 107, 0, 0, 110, 117, + 118, 119, 120, 0, 0, 123, 0, 0, 0, 112, + 113, 114, 125, 0, 0, 115, 116, 101, 102, 103, + 104, 105, 106, 0, 107, 0, 0, 110, 117, 118, + 119, 120, 0, 0, 123, 0, 0, 0, 112, 113, + 114, 125, 0, 0, 115, 116, 101, 102, 103, 104, + 0, 0, 0, 107, 0, 0, 110, 126, 0, 119, + 120, 0, 0, 123, 0, 0, 0, 112, 113, 114, + 125, 0, 0, 115, 116, 79, 80, 255, 0, 0, + 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, + 0, 0, 123, 0, 0, 79, 80, 0, 0, 125, + 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, + 101, 102, 103, 104, 0, 0, 0, 107, 0, 0, + 110, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 113, 114, 0, 0, 0, 115, 116 +}; + +static const yytype_int16 yycheck[] = +{ + 2, 2, 47, 249, 191, 145, 236, 263, 3, 318, + 12, 132, 55, 201, 5, 6, 7, 51, 57, 57, + 50, 50, 55, 28, 212, 6, 57, 327, 5, 6, + 61, 0, 66, 67, 57, 16, 336, 227, 57, 348, + 38, 32, 38, 55, 35, 36, 37, 38, 10, 92, + 41, 42, 43, 58, 45, 46, 59, 55, 91, 315, + 99, 99, 92, 92, 55, 295, 61, 29, 30, 31, + 32, 33, 63, 64, 330, 215, 99, 198, 266, 91, + 99, 268, 55, 44, 45, 46, 47, 225, 226, 55, + 51, 59, 54, 54, 24, 55, 55, 59, 55, 55, + 346, 92, 55, 65, 38, 66, 67, 69, 38, 39, + 55, 73, 74, 369, 76, 77, 78, 50, 59, 81, + 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, + 59, 93, 113, 114, 136, 136, 55, 55, 14, 101, + 102, 103, 104, 105, 106, 37, 108, 109, 110, 111, + 112, 341, 55, 115, 116, 117, 118, 119, 120, 121, + 122, 123, 124, 125, 126, 50, 37, 60, 358, 131, + 132, 38, 5, 6, 7, 38, 138, 222, 37, 23, + 142, 38, 55, 68, 69, 23, 3, 56, 73, 74, + 75, 76, 77, 78, 79, 80, 81, 82, 56, 32, + 202, 203, 35, 36, 37, 38, 57, 92, 41, 42, + 43, 57, 45, 46, 55, 55, 58, 60, 5, 6, + 41, 60, 55, 317, 318, 60, 59, 37, 57, 191, + 63, 64, 202, 203, 99, 38, 198, 24, 240, 8, + 56, 335, 336, 26, 206, 207, 59, 209, 210, 211, + 56, 38, 39, 60, 348, 56, 56, 219, 352, 221, + 56, 56, 224, 225, 226, 227, 228, 56, 61, 271, + 240, 61, 274, 275, 60, 277, 60, 56, 280, 281, + 242, 243, 60, 50, 38, 61, 60, 59, 61, 59, + 61, 293, 293, 255, 59, 58, 232, 61, 50, 50, + 302, 271, 304, 305, 274, 275, 268, 277, 336, 309, + 280, 281, -1, -1, -1, -1, -1, 279, -1, -1, + 322, 283, -1, -1, 5, 6, 7, -1, -1, 331, + 331, -1, 302, -1, 304, 305, -1, -1, 46, 47, + -1, -1, -1, 51, 346, 346, 54, -1, -1, -1, + -1, 32, 322, -1, 35, 36, 37, 38, 66, 67, + 41, 42, 43, -1, 45, 46, -1, 329, -1, -1, + -1, -1, 374, 374, 55, 56, -1, 339, 340, 341, + -1, -1, 63, 64, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 357, 358, -1, -1, -1, + 3, -1, 5, 6, 7, -1, 9, -1, 11, 371, + 13, 14, 15, -1, 376, -1, -1, 20, 21, 22, + -1, 24, 25, -1, 27, -1, 29, -1, -1, 32, + -1, -1, 35, 36, 37, 38, -1, 40, 41, 42, + 43, -1, 45, 46, -1, -1, -1, -1, -1, 5, + 6, 7, 55, 9, -1, 11, -1, 13, 14, 15, + 63, 64, -1, 19, 20, 21, 22, -1, 24, 25, + 26, 27, -1, -1, -1, -1, 32, -1, -1, 35, + 36, 37, 38, -1, 40, 41, 42, 43, -1, 45, + 46, -1, -1, -1, 5, 6, 7, -1, 9, 55, + 11, -1, 13, 14, 15, -1, -1, 63, 64, 20, + 21, 22, -1, 24, 25, -1, 27, -1, -1, -1, + -1, 32, -1, -1, 35, 36, 37, 38, -1, 40, + 41, 42, 43, -1, 45, 46, -1, -1, -1, -1, + -1, -1, -1, -1, 55, -1, -1, -1, -1, 60, + -1, -1, 63, 64, 5, 6, 7, -1, 9, -1, + 11, -1, 13, 14, 15, -1, -1, -1, -1, 20, + 21, 22, -1, 24, 25, -1, 27, -1, -1, -1, + -1, 32, -1, -1, 35, 36, 37, 38, -1, 40, + 41, 42, 43, -1, 45, 46, -1, -1, -1, 5, + 6, 7, -1, 9, 55, 11, -1, 13, 14, 15, + 61, -1, 63, 64, 20, 21, 22, -1, 24, 25, + -1, 27, -1, -1, -1, -1, 32, -1, -1, 35, + 36, 37, 38, -1, 40, 41, 42, 43, -1, 45, + 46, -1, -1, -1, 5, 6, 7, -1, 9, 55, + 11, -1, 13, 14, 15, 61, -1, 63, 64, 20, + 21, 22, -1, 24, 25, -1, 27, -1, -1, -1, + -1, 32, -1, -1, 35, 36, 37, 38, -1, 40, + 41, 42, 43, -1, 45, 46, -1, -1, -1, 5, + 6, 7, -1, 9, 55, 11, -1, 13, 14, 15, + 61, -1, 63, 64, 20, 21, 22, -1, 24, 25, + -1, 27, -1, 5, 6, 7, 32, -1, -1, 35, + 36, 37, 38, -1, 40, 41, 42, 43, -1, 45, + 46, -1, -1, -1, -1, -1, -1, -1, -1, 55, + 32, -1, -1, 35, 36, 37, 38, 63, 64, 41, + 42, 43, -1, 45, 46, 5, 6, 7, -1, -1, + -1, -1, -1, 55, -1, -1, -1, 59, -1, -1, + -1, 63, 64, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 32, -1, -1, 35, 36, 37, 38, -1, + -1, 41, 42, 43, -1, 45, 46, 5, 6, 7, + -1, -1, -1, -1, -1, 55, -1, -1, -1, -1, + 60, -1, -1, 63, 64, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 32, -1, -1, 35, 36, 37, + 38, -1, -1, 41, 42, 43, -1, 45, 46, 5, + 6, 7, -1, -1, -1, -1, -1, 55, -1, -1, + -1, 59, -1, -1, -1, 63, 64, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 32, -1, -1, 35, + 36, 37, 38, -1, -1, 41, 42, 43, -1, 45, + 46, 5, 6, 7, -1, -1, -1, -1, -1, 55, + -1, -1, -1, 59, -1, -1, -1, 63, 64, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 32, -1, + -1, 35, 36, 37, 38, -1, -1, 41, 42, 43, + -1, 45, 46, 5, 6, 7, -1, -1, -1, -1, + -1, 55, 56, -1, -1, -1, -1, -1, -1, 63, + 64, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 32, -1, -1, 35, 36, 37, 38, -1, -1, 41, + 42, 43, -1, 45, 46, 5, 6, 7, -1, -1, + -1, -1, -1, 55, 56, -1, -1, -1, -1, -1, + -1, 63, 64, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 32, -1, -1, 35, 36, 37, 38, -1, + -1, 41, 42, 43, -1, 45, 46, 5, 6, 7, + -1, -1, -1, -1, -1, 55, 56, -1, -1, -1, + -1, -1, -1, 63, 64, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 32, -1, -1, 35, 36, 37, + 38, -1, -1, 41, 42, 43, -1, 45, 46, -1, + -1, 44, 45, 46, 47, 48, 49, 55, 51, 52, + 53, 54, -1, 56, 57, 63, 64, -1, -1, 62, + -1, -1, 65, 66, 67, -1, -1, -1, 71, 72, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 84, 85, 86, 87, 88, 89, 90, -1, -1, + -1, -1, -1, 96, 97, 44, 45, 46, 47, 48, + 49, -1, 51, 52, 53, 54, -1, -1, 57, -1, + 59, -1, -1, 62, -1, -1, 65, 66, 67, -1, + -1, -1, 71, 72, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 84, 85, 86, 87, 88, + 89, 90, -1, -1, -1, -1, -1, 96, 97, 44, + 45, 46, 47, 48, 49, -1, 51, 52, 53, 54, + -1, -1, -1, -1, 59, -1, -1, 62, -1, -1, + 65, 66, 67, -1, -1, -1, 71, 72, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 84, + 85, 86, 87, 88, 89, 90, -1, -1, -1, -1, + -1, 96, 97, 44, 45, 46, 47, 48, 49, -1, + 51, 52, 53, 54, -1, 56, -1, -1, -1, -1, + -1, 62, -1, -1, 65, 66, 67, -1, -1, -1, + 71, 72, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 84, 85, 86, 87, 88, 89, 90, + -1, -1, -1, -1, -1, 96, 97, 44, 45, 46, + 47, 48, 49, -1, 51, 52, 53, 54, -1, 56, + -1, -1, -1, -1, -1, 62, -1, -1, 65, 66, + 67, -1, -1, -1, 71, 72, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 84, 85, 86, + 87, 88, 89, 90, -1, -1, -1, -1, -1, 96, + 97, 44, 45, 46, 47, 48, 49, -1, 51, 52, + 53, 54, -1, 56, -1, -1, -1, -1, -1, 62, + -1, -1, 65, 66, 67, -1, -1, -1, 71, 72, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 84, 85, 86, 87, 88, 89, 90, -1, -1, + -1, -1, -1, 96, 97, 44, 45, 46, 47, 48, + 49, -1, 51, 52, 53, 54, -1, 56, -1, -1, + -1, -1, -1, 62, -1, -1, 65, 66, 67, -1, + -1, -1, 71, 72, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 84, 85, 86, 87, 88, + 89, 90, -1, -1, -1, -1, -1, 96, 97, 44, + 45, 46, 47, 48, 49, -1, 51, 52, 53, 54, + -1, -1, -1, -1, 59, -1, -1, 62, -1, -1, + 65, 66, 67, -1, -1, -1, 71, 72, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 84, + 85, 86, 87, 88, 89, 90, -1, -1, -1, -1, + -1, 96, 97, 44, 45, 46, 47, 48, 49, -1, + 51, 52, 53, 54, -1, 56, -1, -1, -1, -1, + -1, 62, -1, -1, 65, 66, 67, -1, -1, -1, + 71, 72, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 84, 85, 86, 87, 88, 89, 90, + -1, -1, -1, -1, -1, 96, 97, 44, 45, 46, + 47, 48, 49, -1, 51, 52, 53, 54, -1, 56, + -1, -1, -1, -1, -1, 62, -1, -1, 65, 66, + 67, -1, -1, -1, 71, 72, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 84, 85, 86, + 87, 88, 89, 90, -1, -1, -1, -1, -1, 96, + 97, 44, 45, 46, 47, 48, 49, -1, 51, 52, + 53, 54, -1, -1, -1, 58, -1, -1, -1, 62, + -1, -1, 65, 66, 67, -1, -1, -1, 71, 72, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 84, 85, 86, 87, 88, 89, 90, -1, -1, + -1, -1, -1, 96, 97, 44, 45, 46, 47, 48, + 49, -1, 51, 52, 53, 54, -1, -1, -1, -1, + 59, -1, -1, 62, -1, -1, 65, 66, 67, -1, + -1, -1, 71, 72, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 84, 85, 86, 87, 88, + 89, 90, -1, -1, -1, -1, -1, 96, 97, 44, + 45, 46, 47, 48, 49, -1, 51, 52, 53, 54, + -1, -1, -1, 58, -1, -1, -1, 62, -1, -1, + 65, 66, 67, -1, -1, -1, 71, 72, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 84, + 85, 86, 87, 88, 89, 90, -1, -1, -1, -1, + -1, 96, 97, 44, 45, 46, 47, 48, 49, -1, + 51, 52, 53, 54, -1, 56, -1, -1, -1, -1, + -1, 62, -1, -1, 65, 66, 67, -1, -1, -1, + 71, 72, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 84, 85, 86, 87, 88, 89, 90, + -1, -1, -1, -1, -1, 96, 97, 44, 45, 46, + 47, 48, 49, -1, 51, 52, 53, 54, -1, 56, + -1, -1, -1, -1, -1, 62, -1, -1, 65, 66, + 67, -1, -1, -1, 71, 72, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 84, 85, 86, + 87, 88, 89, 90, -1, -1, -1, -1, -1, 96, + 97, 44, 45, 46, 47, 48, 49, -1, 51, 52, + 53, 54, -1, -1, -1, -1, 59, -1, -1, 62, + -1, -1, 65, 66, 67, -1, -1, -1, 71, 72, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 84, 85, 86, 87, 88, 89, 90, -1, -1, + -1, -1, -1, 96, 97, 44, 45, 46, 47, 48, + 49, -1, 51, 52, 53, 54, -1, 56, -1, -1, + -1, -1, -1, 62, -1, -1, 65, 66, 67, -1, + -1, -1, 71, 72, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 84, 85, 86, 87, 88, + 89, 90, -1, -1, -1, -1, -1, 96, 97, 44, + 45, 46, 47, 48, 49, -1, 51, 52, 53, 54, + -1, 56, -1, -1, -1, -1, -1, 62, -1, -1, + 65, 66, 67, -1, -1, -1, 71, 72, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 84, + 85, 86, 87, 88, 89, 90, -1, -1, -1, -1, + -1, 96, 97, 44, 45, 46, 47, 48, 49, -1, + 51, 52, 53, 54, -1, -1, -1, -1, 59, -1, + -1, 62, -1, -1, 65, 66, 67, -1, -1, -1, + 71, 72, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 84, 85, 86, 87, 88, 89, 90, + -1, -1, -1, -1, -1, 96, 97, 44, 45, 46, + 47, 48, 49, -1, 51, 52, 53, 54, -1, 56, + -1, -1, -1, -1, -1, 62, -1, -1, 65, 66, + 67, -1, -1, -1, 71, 72, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 84, 85, 86, + 87, 88, 89, 90, -1, -1, -1, -1, -1, 96, + 97, 44, 45, 46, 47, 48, 49, -1, 51, 52, + 53, 54, -1, 56, -1, -1, -1, -1, -1, 62, + -1, -1, 65, 66, 67, -1, -1, -1, 71, 72, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 84, 85, 86, 87, 88, 89, 90, -1, -1, + -1, -1, -1, 96, 97, 44, 45, 46, 47, 48, + 49, -1, 51, 52, 53, 54, -1, 56, -1, -1, + -1, -1, -1, 62, -1, -1, 65, 66, 67, -1, + -1, -1, 71, 72, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 84, 85, 86, 87, 88, + 89, 90, -1, -1, -1, -1, -1, 96, 97, 44, + 45, 46, 47, 48, 49, -1, 51, 52, 53, 54, + -1, -1, -1, -1, 59, -1, -1, 62, -1, -1, + 65, 66, 67, -1, -1, -1, 71, 72, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 84, + 85, 86, 87, 88, 89, 90, -1, -1, -1, -1, + -1, 96, 97, 44, 45, 46, 47, 48, 49, -1, + 51, 52, 53, 54, -1, -1, -1, -1, 59, -1, + -1, 62, -1, -1, 65, 66, 67, -1, -1, -1, + 71, 72, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 84, 85, 86, 87, 88, 89, 90, + -1, -1, -1, -1, -1, 96, 97, 44, 45, 46, + 47, 48, 49, -1, 51, 52, 53, 54, -1, -1, + -1, -1, 59, -1, -1, 62, -1, -1, 65, 66, + 67, -1, -1, -1, 71, 72, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 84, 85, 86, + 87, 88, 89, 90, -1, -1, -1, -1, -1, 96, + 97, 44, 45, 46, 47, 48, 49, -1, 51, 52, + 53, 54, -1, -1, -1, -1, 59, -1, -1, 62, + -1, -1, 65, 66, 67, -1, -1, -1, 71, 72, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 84, 85, 86, 87, 88, 89, 90, -1, -1, + -1, -1, -1, 96, 97, 44, 45, 46, 47, 48, + 49, -1, 51, 52, 53, 54, -1, -1, -1, -1, + 59, -1, -1, 62, -1, -1, 65, 66, 67, -1, + -1, -1, 71, 72, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 84, 85, 86, 87, 88, + 89, 90, -1, -1, -1, -1, -1, 96, 97, 44, + 45, 46, 47, 48, 49, -1, 51, 52, 53, 54, + -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, + 65, 66, 67, -1, -1, -1, 71, 72, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 84, + 85, 86, 87, 88, 89, 90, -1, -1, -1, -1, + -1, 96, 97, 44, 45, 46, 47, 48, 49, -1, + 51, 52, 53, 54, -1, -1, -1, -1, -1, -1, + -1, 62, -1, -1, 65, 66, 67, -1, -1, -1, + 71, 72, 44, 45, 46, 47, 48, 49, -1, 51, + 52, 53, 54, 84, 85, 86, 87, 88, 89, 90, + 62, -1, -1, 65, 66, 67, 97, -1, -1, 71, + 72, 44, 45, 46, 47, 48, 49, -1, 51, 52, + 53, 54, 84, 85, 86, 87, 88, -1, 90, 62, + -1, -1, 65, 66, 67, 97, -1, -1, 71, 72, + 44, 45, 46, 47, 48, 49, -1, 51, -1, 53, + 54, 84, 85, 86, 87, -1, -1, 90, 62, -1, + -1, 65, 66, 67, 97, -1, -1, 71, 72, 44, + 45, 46, 47, 48, 49, -1, 51, -1, 53, 54, + 84, 85, 86, 87, -1, -1, 90, -1, -1, -1, + 65, 66, 67, 97, -1, -1, 71, 72, 44, 45, + 46, 47, 48, 49, -1, 51, -1, -1, 54, 84, + 85, 86, 87, -1, -1, 90, -1, -1, -1, 65, + 66, 67, 97, -1, -1, 71, 72, 44, 45, 46, + 47, 48, 49, -1, 51, -1, -1, 54, 84, 85, + 86, 87, -1, -1, 90, -1, -1, -1, 65, 66, + 67, 97, -1, -1, 71, 72, 44, 45, 46, 47, + -1, -1, -1, 51, -1, -1, 54, 50, -1, 86, + 87, -1, -1, 90, -1, -1, -1, 65, 66, 67, + 97, -1, -1, 71, 72, 68, 69, 50, -1, -1, + 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, + -1, -1, 90, -1, -1, 68, 69, -1, -1, 97, + 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, + 44, 45, 46, 47, -1, -1, -1, 51, -1, -1, + 54, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 66, 67, -1, -1, -1, 71, 72 +}; + +/* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of + state STATE-NUM. */ +static const yytype_uint8 yystos[] = +{ + 0, 101, 102, 0, 3, 5, 6, 7, 9, 11, + 13, 14, 15, 20, 21, 22, 24, 25, 27, 29, + 32, 35, 36, 37, 38, 40, 41, 42, 43, 45, + 46, 55, 63, 64, 103, 104, 107, 108, 111, 112, + 119, 122, 123, 124, 125, 126, 127, 128, 129, 132, + 133, 134, 38, 38, 55, 130, 130, 59, 59, 55, + 7, 36, 59, 127, 132, 55, 60, 107, 118, 55, + 55, 55, 130, 55, 55, 38, 55, 50, 50, 68, + 69, 73, 74, 75, 76, 77, 78, 79, 80, 81, + 82, 92, 131, 55, 91, 127, 127, 127, 127, 127, + 59, 44, 45, 46, 47, 48, 49, 51, 52, 53, + 54, 62, 65, 66, 67, 71, 72, 84, 85, 86, + 87, 88, 89, 90, 96, 97, 50, 131, 55, 91, + 127, 55, 55, 127, 59, 127, 106, 14, 59, 127, + 37, 37, 55, 127, 127, 60, 127, 127, 127, 127, + 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, + 140, 127, 135, 136, 38, 56, 127, 127, 127, 127, + 127, 127, 38, 127, 127, 127, 127, 127, 130, 130, + 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, + 127, 60, 127, 37, 109, 110, 38, 56, 92, 114, + 127, 114, 56, 56, 61, 107, 55, 59, 127, 59, + 23, 23, 127, 56, 56, 105, 108, 56, 57, 57, + 59, 57, 99, 56, 57, 55, 55, 92, 58, 136, + 56, 57, 55, 114, 58, 113, 113, 118, 118, 127, + 56, 127, 59, 59, 127, 127, 127, 113, 60, 60, + 61, 108, 41, 127, 127, 50, 131, 127, 135, 135, + 140, 127, 61, 60, 37, 109, 99, 38, 57, 115, + 115, 8, 56, 118, 56, 56, 127, 56, 127, 59, + 56, 56, 56, 26, 120, 120, 59, 56, 59, 127, + 56, 56, 99, 106, 56, 113, 136, 56, 56, 118, + 118, 118, 56, 118, 56, 56, 127, 118, 118, 60, + 121, 127, 61, 61, 61, 60, 115, 60, 60, 118, + 118, 118, 56, 24, 38, 39, 137, 138, 139, 28, + 58, 106, 56, 112, 116, 117, 138, 116, 118, 50, + 50, 92, 38, 61, 139, 127, 106, 61, 60, 59, + 61, 112, 117, 61, 127, 127, 140, 50, 92, 59, + 19, 120, 116, 59, 59, 59, 99, 127, 140, 58, + 61, 50, 59, 99, 106, 127, 50, 59, 127, 59 +}; + +/* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM. */ +static const yytype_uint8 yyr1[] = +{ + 0, 100, 101, 102, 102, 103, 103, 103, 104, 105, + 105, 106, 106, 107, 107, 107, 107, 107, 107, 107, + 107, 107, 107, 107, 107, 107, 107, 108, 108, 109, + 109, 110, 110, 111, 112, 112, 112, 112, 112, 112, + 113, 113, 114, 114, 115, 115, 116, 116, 116, 116, + 117, 117, 118, 118, 119, 119, 120, 120, 120, 121, + 121, 122, 122, 123, 123, 124, 124, 124, 124, 124, + 124, 124, 124, 125, 125, 126, 127, 127, 127, 127, + 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, + 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, + 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, + 127, 127, 127, 127, 127, 128, 128, 129, 129, 130, + 130, 131, 131, 131, 131, 131, 131, 131, 131, 131, + 131, 131, 131, 132, 132, 132, 132, 132, 132, 132, + 132, 132, 132, 133, 133, 133, 134, 134, 135, 135, + 136, 136, 137, 137, 138, 138, 139, 139, 139, 139, + 139, 140, 140 +}; + +/* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM. */ +static const yytype_int8 yyr2[] = +{ + 0, 2, 1, 0, 2, 1, 1, 1, 6, 1, + 2, 0, 2, 1, 1, 1, 1, 1, 1, 2, + 2, 2, 3, 2, 4, 6, 1, 8, 10, 0, + 1, 1, 3, 10, 10, 7, 12, 9, 10, 7, + 0, 2, 0, 1, 0, 2, 0, 1, 1, 2, + 2, 3, 3, 1, 7, 7, 4, 7, 5, 1, + 3, 5, 7, 5, 6, 9, 8, 8, 7, 8, + 7, 7, 6, 7, 7, 1, 1, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 2, 2, 1, 5, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 2, 2, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 4, 3, 6, 3, 3, 1, + 3, 1, 1, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 1, 1, 1, 3, 6, 2, 5, + 2, 3, 5, 4, 6, 6, 4, 6, 0, 1, + 1, 3, 0, 1, 1, 2, 4, 5, 4, 7, + 8, 1, 3 +}; + + +enum { YYENOMEM = -2 }; + +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab +#define YYNOMEM goto yyexhaustedlab -/* Note: there must be only one dollar sign in this file. - It is replaced by the list of actions, each action - as one case of the switch. */ -#define yyerrok (yyerrstatus = 0) -#define yyclearin (yychar = YYEMPTY) -#define YYEMPTY -2 -#define YYEOF 0 -#define YYACCEPT return(0) -#define YYABORT return(1) -#define YYERROR goto yyerrlab1 -/* 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. */ -#define YYFAIL goto yyerrlab #define YYRECOVERING() (!!yyerrstatus) -#define YYBACKUP(token, value) \ -do \ - if (yychar == YYEMPTY && yylen == 1) \ - { yychar = (token), yylval = (value); \ - yychar1 = YYTRANSLATE (yychar); \ - YYPOPSTACK; \ - goto yybackup; \ - } \ - else \ - { yyerror ("syntax error: cannot back up"); YYERROR; } \ -while (0) -#define YYTERROR 1 -#define YYERRCODE 256 +#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 (0) -#ifndef YYPURE -#define YYLEX yylex() +/* Backward compatibility with an undocumented macro. + Use YYerror or YYUNDEF. */ +#define YYERRCODE YYUNDEF + + +/* Enable debugging if requested. */ +#if YYDEBUG + +# ifndef YYFPRINTF +# include /* INFRINGES ON USER NAME SPACE */ +# define YYFPRINTF fprintf +# endif + +# define YYDPRINTF(Args) \ +do { \ + if (yydebug) \ + YYFPRINTF Args; \ +} while (0) + + + + +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ +do { \ + if (yydebug) \ + { \ + YYFPRINTF (stderr, "%s ", Title); \ + yy_symbol_print (stderr, \ + Kind, Value); \ + YYFPRINTF (stderr, "\n"); \ + } \ +} while (0) + + +/*-----------------------------------. +| Print this symbol's value on YYO. | +`-----------------------------------*/ + +static void +yy_symbol_value_print (FILE *yyo, + yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) +{ + FILE *yyoutput = yyo; + YY_USE (yyoutput); + if (!yyvaluep) + return; + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + YY_USE (yykind); + YY_IGNORE_MAYBE_UNINITIALIZED_END +} + + +/*---------------------------. +| Print this symbol on YYO. | +`---------------------------*/ + +static void +yy_symbol_print (FILE *yyo, + yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) +{ + YYFPRINTF (yyo, "%s %s (", + yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind)); + + yy_symbol_value_print (yyo, yykind, yyvaluep); + YYFPRINTF (yyo, ")"); +} + +/*------------------------------------------------------------------. +| yy_stack_print -- Print the state stack from its BOTTOM up to its | +| TOP (included). | +`------------------------------------------------------------------*/ + +static void +yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop) +{ + YYFPRINTF (stderr, "Stack now"); + for (; yybottom <= yytop; yybottom++) + { + int yybot = *yybottom; + YYFPRINTF (stderr, " %d", yybot); + } + YYFPRINTF (stderr, "\n"); +} + +# define YY_STACK_PRINT(Bottom, Top) \ +do { \ + if (yydebug) \ + yy_stack_print ((Bottom), (Top)); \ +} while (0) + + +/*------------------------------------------------. +| Report that the YYRULE is going to be reduced. | +`------------------------------------------------*/ + +static void +yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, + int yyrule) +{ + int yylno = yyrline[yyrule]; + int yynrhs = yyr2[yyrule]; + int yyi; + YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n", + yyrule - 1, yylno); + /* The symbols being reduced. */ + for (yyi = 0; yyi < yynrhs; yyi++) + { + YYFPRINTF (stderr, " $%d = ", yyi + 1); + yy_symbol_print (stderr, + YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]), + &yyvsp[(yyi + 1) - (yynrhs)]); + YYFPRINTF (stderr, "\n"); + } +} + +# define YY_REDUCE_PRINT(Rule) \ +do { \ + if (yydebug) \ + yy_reduce_print (yyssp, yyvsp, Rule); \ +} while (0) + +/* Nonzero means print parse trace. It is left uninitialized so that + multiple parsers can coexist. */ +int yydebug; +#else /* !YYDEBUG */ +# define YYDPRINTF(Args) ((void) 0) +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) +# define YY_STACK_PRINT(Bottom, Top) +# define YY_REDUCE_PRINT(Rule) +#endif /* !YYDEBUG */ + + +/* YYINITDEPTH -- initial size of the parser's stacks. */ +#ifndef YYINITDEPTH +# define YYINITDEPTH 200 #endif -#ifdef YYPURE -#ifdef YYLSP_NEEDED -#ifdef YYLEX_PARAM -#define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM) -#else -#define YYLEX yylex(&yylval, &yylloc) -#endif -#else /* not YYLSP_NEEDED */ -#ifdef YYLEX_PARAM -#define YYLEX yylex(&yylval, YYLEX_PARAM) -#else -#define YYLEX yylex(&yylval) -#endif -#endif /* not YYLSP_NEEDED */ -#endif +/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only + if the built-in stack extension method is used). -/* If nonreentrant, generate the variables here */ - -#ifndef YYPURE - -int yychar; /* the lookahead symbol */ -YYSTYPE yylval; /* the semantic value of the */ - /* lookahead symbol */ - -#ifdef YYLSP_NEEDED -YYLTYPE yylloc; /* location data for the lookahead */ - /* symbol */ -#endif - -int yynerrs; /* number of parse errors so far */ -#endif /* not YYPURE */ - -#if YYDEBUG != 0 -int yydebug; /* nonzero means print parse trace */ -/* Since this is uninitialized, it does not stop multiple parsers - from coexisting. */ -#endif - -/* YYINITDEPTH indicates the initial size of the parser's stacks */ - -#ifndef YYINITDEPTH -#define YYINITDEPTH 200 -#endif - -/* YYMAXDEPTH is the maximum size the stacks can grow to - (effective only if the built-in stack extension method is used). */ - -#if YYMAXDEPTH == 0 -#undef YYMAXDEPTH -#endif + Do not make this value too large; the results are undefined if + YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) + evaluated with infinite-precision integer arithmetic. */ #ifndef YYMAXDEPTH -#define YYMAXDEPTH 10000 +# define YYMAXDEPTH 10000 #endif -/* Prevent warning if -Wstrict-prototypes. */ -#ifdef __GNUC__ -int yyparse (void); -#endif - -#if __GNUC__ > 1 /* GNU C and GNU C++ define this. */ -#define __yy_memcpy(FROM,TO,COUNT) __builtin_memcpy(TO,FROM,COUNT) -#else /* not GNU C or C++ */ -#ifndef __cplusplus -/* This is the most reliable way to avoid incompatibilities - in available built-in functions on various systems. */ + + + + +/*-----------------------------------------------. +| Release the memory associated to this symbol. | +`-----------------------------------------------*/ + static void -__yy_memcpy (from, to, count) - char *from; - char *to; - int count; +yydestruct (const char *yymsg, + yysymbol_kind_t yykind, YYSTYPE *yyvaluep) { - char *f = from; - char *t = to; - int i = count; + YY_USE (yyvaluep); + if (!yymsg) + yymsg = "Deleting"; + YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp); - while (i-- > 0) - *t++ = *f++; + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + YY_USE (yykind); + YY_IGNORE_MAYBE_UNINITIALIZED_END } -#else /* __cplusplus */ -/* This is the most reliable way to avoid incompatibilities - in available built-in functions on various systems. */ -static void -__yy_memcpy (char *from, char *to, int count) -{ - char *f = from; - char *t = to; - int i = count; +/* Lookahead token kind. */ +int yychar; - while (i-- > 0) - *t++ = *f++; -} +/* The semantic value of the lookahead symbol. */ +YYSTYPE yylval; +/* Number of syntax errors so far. */ +int yynerrs; -#endif -#endif - -#line 192 "bison.simple" -/* The user can define YYPARSE_PARAM as the name of an argument to be passed - into yyparse. The argument should have type void *. - It should actually point to an object. - Grammar actions can access the variable by casting it - to the proper pointer type. */ -#ifdef YYPARSE_PARAM -#define YYPARSE_PARAM_DECL void *YYPARSE_PARAM; -#else -#define YYPARSE_PARAM -#define YYPARSE_PARAM_DECL -#endif + +/*----------. +| yyparse. | +`----------*/ int -yyparse(YYPARSE_PARAM) - YYPARSE_PARAM_DECL +yyparse (void) { - int yystate; + yy_state_fast_t yystate = 0; + /* Number of tokens to shift before error messages enabled. */ + int yyerrstatus = 0; + + /* Refer to the stacks through separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ + + /* Their size. */ + YYPTRDIFF_T yystacksize = YYINITDEPTH; + + /* The state stack: array, bottom, top. */ + yy_state_t yyssa[YYINITDEPTH]; + yy_state_t *yyss = yyssa; + yy_state_t *yyssp = yyss; + + /* The semantic value stack: array, bottom, top. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE *yyvs = yyvsa; + YYSTYPE *yyvsp = yyvs; + int yyn; - short *yyssp; - YYSTYPE *yyvsp; - int yyerrstatus; /* number of tokens to shift before error messages enabled */ - int yychar1 = 0; /* lookahead token as an internal (translated) token number */ + /* The return value of yyparse. */ + int yyresult; + /* Lookahead symbol kind. */ + yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY; + /* The variables used to return semantic value and location from the + action routines. */ + YYSTYPE yyval; - short yyssa[YYINITDEPTH]; /* the state stack */ - YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */ - short *yyss = yyssa; /* refer to the stacks thru separate pointers */ - YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */ -#ifdef YYLSP_NEEDED - YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */ - YYLTYPE *yyls = yylsa; - YYLTYPE *yylsp; +#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) -#define YYPOPSTACK (yyvsp--, yyssp--, yylsp--) -#else -#define YYPOPSTACK (yyvsp--, yyssp--) -#endif + /* The number of symbols on the RHS of the reduced rule. + Keep to zero when no symbol should be popped. */ + int yylen = 0; - int yystacksize = YYINITDEPTH; + YYDPRINTF ((stderr, "Starting parse\n")); -#ifdef YYPURE - int yychar; - YYSTYPE yylval; - int yynerrs; -#ifdef YYLSP_NEEDED - YYLTYPE yylloc; -#endif -#endif + yychar = YYEMPTY; /* Cause a token to be read. */ - YYSTYPE yyval; /* the variable used to return */ - /* semantic values from the action */ - /* routines */ + goto yysetstate; - int yylen; -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Starting parse\n"); -#endif - - yystate = 0; - 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 - 1; - yyvsp = yyvs; -#ifdef YYLSP_NEEDED - yylsp = yyls; -#endif - -/* Push a new state, which is found in yystate . */ -/* In all cases, when you get here, the value and location stacks - have just been pushed. so pushing a state here evens the stacks. */ +/*------------------------------------------------------------. +| yynewstate -- push a new state, which is found in yystate. | +`------------------------------------------------------------*/ yynewstate: + /* In all cases, when you get here, the value and location stacks + have just been pushed. So pushing a state here evens the stacks. */ + yyssp++; - *++yyssp = yystate; - if (yyssp >= yyss + yystacksize - 1) - { - /* Give user a chance to reallocate the stack */ - /* Use copies of these so that the &'s don't force the real ones into memory. */ - YYSTYPE *yyvs1 = yyvs; - short *yyss1 = yyss; -#ifdef YYLSP_NEEDED - YYLTYPE *yyls1 = yyls; -#endif +/*--------------------------------------------------------------------. +| yysetstate -- set current state (the top of the stack) to yystate. | +`--------------------------------------------------------------------*/ +yysetstate: + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + YY_ASSERT (0 <= yystate && yystate < YYNSTATES); + YY_IGNORE_USELESS_CAST_BEGIN + *yyssp = YY_CAST (yy_state_t, yystate); + YY_IGNORE_USELESS_CAST_END + YY_STACK_PRINT (yyss, yyssp); - /* Get the current used size of the three stacks, in elements. */ - int size = yyssp - yyss + 1; - -#ifdef yyoverflow - /* Each stack pointer address is followed by the size of - the data in use in that stack, in bytes. */ -#ifdef YYLSP_NEEDED - /* This used to be a conditional around just the two extra args, - but that might be undefined if yyoverflow is a macro. */ - yyoverflow("parser stack overflow", - &yyss1, size * sizeof (*yyssp), - &yyvs1, size * sizeof (*yyvsp), - &yyls1, size * sizeof (*yylsp), - &yystacksize); + if (yyss + yystacksize - 1 <= yyssp) +#if !defined yyoverflow && !defined YYSTACK_RELOCATE + YYNOMEM; #else - yyoverflow("parser stack overflow", - &yyss1, size * sizeof (*yyssp), - &yyvs1, size * sizeof (*yyvsp), - &yystacksize); -#endif + { + /* Get the current used size of the three stacks, in elements. */ + YYPTRDIFF_T yysize = yyssp - yyss + 1; - yyss = yyss1; yyvs = yyvs1; -#ifdef YYLSP_NEEDED - yyls = yyls1; -#endif -#else /* no yyoverflow */ +# if defined yyoverflow + { + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + yy_state_t *yyss1 = yyss; + YYSTYPE *yyvs1 = yyvs; + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow (YY_("memory exhausted"), + &yyss1, yysize * YYSIZEOF (*yyssp), + &yyvs1, yysize * YYSIZEOF (*yyvsp), + &yystacksize); + yyss = yyss1; + yyvs = yyvs1; + } +# else /* defined YYSTACK_RELOCATE */ /* Extend the stack our own way. */ - if (yystacksize >= YYMAXDEPTH) - { - yyerror("parser stack overflow"); - return 2; - } + if (YYMAXDEPTH <= yystacksize) + YYNOMEM; yystacksize *= 2; - if (yystacksize > YYMAXDEPTH) - yystacksize = YYMAXDEPTH; - yyss = (short *) alloca (yystacksize * sizeof (*yyssp)); - __yy_memcpy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp)); - yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp)); - __yy_memcpy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp)); -#ifdef YYLSP_NEEDED - yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp)); - __yy_memcpy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp)); -#endif -#endif /* no yyoverflow */ + if (YYMAXDEPTH < yystacksize) + yystacksize = YYMAXDEPTH; - yyssp = yyss + size - 1; - yyvsp = yyvs + size - 1; -#ifdef YYLSP_NEEDED - yylsp = yyls + size - 1; -#endif + { + yy_state_t *yyss1 = yyss; + union yyalloc *yyptr = + YY_CAST (union yyalloc *, + YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); + if (! yyptr) + YYNOMEM; + YYSTACK_RELOCATE (yyss_alloc, yyss); + YYSTACK_RELOCATE (yyvs_alloc, yyvs); +# undef YYSTACK_RELOCATE + if (yyss1 != yyssa) + YYSTACK_FREE (yyss1); + } +# endif -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Stack size increased to %d\n", yystacksize); -#endif + yyssp = yyss + yysize - 1; + yyvsp = yyvs + yysize - 1; - if (yyssp >= yyss + yystacksize - 1) - YYABORT; + YY_IGNORE_USELESS_CAST_BEGIN + YYDPRINTF ((stderr, "Stack size increased to %ld\n", + YY_CAST (long, yystacksize))); + YY_IGNORE_USELESS_CAST_END + + if (yyss + yystacksize - 1 <= yyssp) + YYABORT; } +#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Entering state %d\n", yystate); -#endif + + if (yystate == YYFINAL) + YYACCEPT; goto yybackup; - yybackup: -/* Do appropriate processing given the current state. */ -/* Read a lookahead token if we need one and don't already have one. */ -/* yyresume: */ + +/*-----------. +| yybackup. | +`-----------*/ +yybackup: + /* Do appropriate processing given the current state. Read a + lookahead token if we need one and don't already have one. */ /* First try to decide what to do without reference to lookahead token. */ - yyn = yypact[yystate]; - if (yyn == YYFLAG) + if (yypact_value_is_default (yyn)) goto yydefault; /* Not known => get a lookahead token if don't already have one. */ - /* yychar is either YYEMPTY or YYEOF - or a valid token in external form. */ - + /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */ if (yychar == YYEMPTY) { -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Reading a token: "); -#endif - yychar = YYLEX; + YYDPRINTF ((stderr, "Reading a token\n")); + yychar = yylex (); } - /* Convert token to internal form (in yychar1) for indexing tables with */ - - if (yychar <= 0) /* This means end of input. */ + if (yychar <= YYEOF) { - yychar1 = 0; - yychar = YYEOF; /* Don't call YYLEX any more */ - -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Now at end of input.\n"); -#endif + yychar = YYEOF; + yytoken = YYSYMBOL_YYEOF; + YYDPRINTF ((stderr, "Now at end of input.\n")); + } + else if (yychar == YYerror) + { + /* The scanner already issued an error message, process directly + to error recovery. But do not keep the error token as + lookahead, it is too special and may lead us to an endless + loop in error recovery. */ + yychar = YYUNDEF; + yytoken = YYSYMBOL_YYerror; + goto yyerrlab1; } else { - yychar1 = YYTRANSLATE(yychar); - -#if YYDEBUG != 0 - if (yydebug) - { - fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]); - /* Give the individual parser a way to print the precise meaning - of a token, for further debugging info. */ -#ifdef YYPRINT - YYPRINT (stderr, yychar, yylval); -#endif - fprintf (stderr, ")\n"); - } -#endif + yytoken = YYTRANSLATE (yychar); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); } - yyn += yychar1; - if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1) + /* If the proper action on seeing token YYTOKEN is to reduce or to + detect an error, take that action. */ + yyn += yytoken; + if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) goto yydefault; - yyn = yytable[yyn]; - - /* yyn is what to do for this token type in this state. - Negative => reduce, -yyn is rule number. - Positive => shift, yyn is new state. - New state is final state => don't bother to shift, - just return success. - 0, or most negative number => error. */ - - if (yyn < 0) + if (yyn <= 0) { - if (yyn == YYFLAG) - goto yyerrlab; + if (yytable_value_is_error (yyn)) + goto yyerrlab; yyn = -yyn; goto yyreduce; } - else if (yyn == 0) - goto yyerrlab; - if (yyn == YYFINAL) - YYACCEPT; + /* Count tokens shifted since error; after three, turn off error + status. */ + if (yyerrstatus) + yyerrstatus--; /* Shift the lookahead token. */ - -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]); -#endif - - /* Discard the token being shifted unless it is eof. */ - if (yychar != YYEOF) - yychar = YYEMPTY; - - *++yyvsp = yylval; -#ifdef YYLSP_NEEDED - *++yylsp = yylloc; -#endif - - /* count tokens shifted since error; after three, turn off error status. */ - if (yyerrstatus) yyerrstatus--; - + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); yystate = yyn; + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END + + /* Discard the shifted token. */ + yychar = YYEMPTY; goto yynewstate; -/* Do the default action for the current state. */ -yydefault: +/*-----------------------------------------------------------. +| yydefault -- do the default action for the current state. | +`-----------------------------------------------------------*/ +yydefault: yyn = yydefact[yystate]; if (yyn == 0) goto yyerrlab; + goto yyreduce; -/* Do a reduction. yyn is the number of a rule to reduce with. */ + +/*-----------------------------. +| yyreduce -- do a reduction. | +`-----------------------------*/ yyreduce: + /* yyn is the number of a rule to reduce with. */ yylen = yyr2[yyn]; - if (yylen > 0) - yyval = yyvsp[1-yylen]; /* implement default value of the action */ -#if YYDEBUG != 0 - if (yydebug) + /* If YYLEN is nonzero, implement the default value of the action: + '$$ = $1'. + + Otherwise, the following line sets YYVAL to garbage. + This behavior is undocumented and Bison + users should not rely upon it. Assigning to YYVAL + unconditionally makes the parser a bit smaller, and it avoids a + GCC warning that YYVAL may be used uninitialized. */ + yyval = yyvsp[1-yylen]; + + + YY_REDUCE_PRINT (yyn); + switch (yyn) { - int i; + case 2: /* start: decl_list */ +#line 162 "CMDgram.y" + { } +#line 2011 "CMDgram.c" + break; - fprintf (stderr, "Reducing via rule %d (line %d), ", - yyn, yyrline[yyn]); + case 3: /* decl_list: %empty */ +#line 167 "CMDgram.y" + { (yyval.stmt) = nil; } +#line 2017 "CMDgram.c" + break; - /* Print the symbols being reduced, and their result. */ - for (i = yyprhs[yyn]; yyrhs[i] > 0; i++) - fprintf (stderr, "%s ", yytname[yyrhs[i]]); - fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]); + case 4: /* decl_list: decl_list decl */ +#line 169 "CMDgram.y" + { if(!Script::gStatementList) { Script::gStatementList = (yyvsp[0].stmt); } else { Script::gStatementList->append((yyvsp[0].stmt)); } } +#line 2023 "CMDgram.c" + break; + + case 5: /* decl: stmt */ +#line 174 "CMDgram.y" + { (yyval.stmt) = (yyvsp[0].stmt); } +#line 2029 "CMDgram.c" + break; + + case 6: /* decl: fn_decl_stmt */ +#line 176 "CMDgram.y" + { (yyval.stmt) = (yyvsp[0].stmt); } +#line 2035 "CMDgram.c" + break; + + case 7: /* decl: package_decl */ +#line 178 "CMDgram.y" + { (yyval.stmt) = (yyvsp[0].stmt); } +#line 2041 "CMDgram.c" + break; + + case 8: /* package_decl: rwPACKAGE IDENT '{' fn_decl_list '}' ';' */ +#line 183 "CMDgram.y" + { (yyval.stmt) = (yyvsp[-2].stmt); for(StmtNode *walk = ((yyvsp[-2].stmt));walk;walk = walk->getNext() ) walk->setPackage((yyvsp[-4].s).value); } +#line 2047 "CMDgram.c" + break; + + case 9: /* fn_decl_list: fn_decl_stmt */ +#line 188 "CMDgram.y" + { (yyval.stmt) = (yyvsp[0].stmt); } +#line 2053 "CMDgram.c" + break; + + case 10: /* fn_decl_list: fn_decl_list fn_decl_stmt */ +#line 190 "CMDgram.y" + { (yyval.stmt) = (yyvsp[-1].stmt); ((yyvsp[-1].stmt))->append((yyvsp[0].stmt)); } +#line 2059 "CMDgram.c" + break; + + case 11: /* statement_list: %empty */ +#line 195 "CMDgram.y" + { (yyval.stmt) = nil; } +#line 2065 "CMDgram.c" + break; + + case 12: /* statement_list: statement_list stmt */ +#line 197 "CMDgram.y" + { if(!(yyvsp[-1].stmt)) { (yyval.stmt) = (yyvsp[0].stmt); } else { ((yyvsp[-1].stmt))->append((yyvsp[0].stmt)); (yyval.stmt) = (yyvsp[-1].stmt); } } +#line 2071 "CMDgram.c" + break; + + case 19: /* stmt: rwBREAK ';' */ +#line 208 "CMDgram.y" + { (yyval.stmt) = BreakStmtNode::alloc( (yyvsp[-1].i).lineNumber ); } +#line 2077 "CMDgram.c" + break; + + case 20: /* stmt: rwCONTINUE ';' */ +#line 210 "CMDgram.y" + { (yyval.stmt) = ContinueStmtNode::alloc( (yyvsp[-1].i).lineNumber ); } +#line 2083 "CMDgram.c" + break; + + case 21: /* stmt: rwRETURN ';' */ +#line 212 "CMDgram.y" + { (yyval.stmt) = ReturnStmtNode::alloc( (yyvsp[-1].i).lineNumber, NULL ); } +#line 2089 "CMDgram.c" + break; + + case 22: /* stmt: rwRETURN expr ';' */ +#line 214 "CMDgram.y" + { (yyval.stmt) = ReturnStmtNode::alloc( (yyvsp[-2].i).lineNumber, (yyvsp[-1].expr) ); } +#line 2095 "CMDgram.c" + break; + + case 23: /* stmt: expression_stmt ';' */ +#line 216 "CMDgram.y" + { (yyval.stmt) = (yyvsp[-1].stmt); } +#line 2101 "CMDgram.c" + break; + + case 24: /* stmt: TTAG '=' expr ';' */ +#line 218 "CMDgram.y" + { (yyval.stmt) = TTagSetStmtNode::alloc( (yyvsp[-3].s).lineNumber, (yyvsp[-3].s).value, (yyvsp[-1].expr), NULL ); } +#line 2107 "CMDgram.c" + break; + + case 25: /* stmt: TTAG '=' expr ',' expr ';' */ +#line 220 "CMDgram.y" + { (yyval.stmt) = TTagSetStmtNode::alloc( (yyvsp[-5].s).lineNumber, (yyvsp[-5].s).value, (yyvsp[-3].expr), (yyvsp[-1].expr) ); } +#line 2113 "CMDgram.c" + break; + + case 26: /* stmt: DOCBLOCK */ +#line 222 "CMDgram.y" + { (yyval.stmt) = StrConstNode::alloc( (yyvsp[0].str).lineNumber, (yyvsp[0].str).value, false, true ); } +#line 2119 "CMDgram.c" + break; + + case 27: /* fn_decl_stmt: rwDEFINE IDENT '(' var_list_decl ')' '{' statement_list '}' */ +#line 227 "CMDgram.y" + { (yyval.stmt) = FunctionDeclStmtNode::alloc( (yyvsp[-7].i).lineNumber, (yyvsp[-6].s).value, NULL, (yyvsp[-4].var), (yyvsp[-1].stmt) ); } +#line 2125 "CMDgram.c" + break; + + case 28: /* fn_decl_stmt: rwDEFINE IDENT opCOLONCOLON IDENT '(' var_list_decl ')' '{' statement_list '}' */ +#line 229 "CMDgram.y" + { (yyval.stmt) = FunctionDeclStmtNode::alloc( (yyvsp[-9].i).lineNumber, (yyvsp[-6].s).value, (yyvsp[-8].s).value, (yyvsp[-4].var), (yyvsp[-1].stmt) ); } +#line 2131 "CMDgram.c" + break; + + case 29: /* var_list_decl: %empty */ +#line 234 "CMDgram.y" + { (yyval.var) = NULL; } +#line 2137 "CMDgram.c" + break; + + case 30: /* var_list_decl: var_list */ +#line 236 "CMDgram.y" + { (yyval.var) = (yyvsp[0].var); } +#line 2143 "CMDgram.c" + break; + + case 31: /* var_list: VAR */ +#line 241 "CMDgram.y" + { (yyval.var) = VarNode::alloc( (yyvsp[0].s).lineNumber, (yyvsp[0].s).value, NULL ); } +#line 2149 "CMDgram.c" + break; + + case 32: /* var_list: var_list ',' VAR */ +#line 243 "CMDgram.y" + { (yyval.var) = (yyvsp[-2].var); ((StmtNode*)((yyvsp[-2].var)))->append((StmtNode*)VarNode::alloc( (yyvsp[0].s).lineNumber, (yyvsp[0].s).value, NULL ) ); } +#line 2155 "CMDgram.c" + break; + + case 33: /* datablock_decl: rwDATABLOCK class_name_expr '(' expr parent_block ')' '{' slot_assign_list_opt '}' ';' */ +#line 248 "CMDgram.y" + { (yyval.stmt) = ObjectDeclNode::alloc( (yyvsp[-9].i).lineNumber, (yyvsp[-8].expr), (yyvsp[-6].expr), NULL, (yyvsp[-5].s).value, (yyvsp[-2].slist), NULL, true, false, false); } +#line 2161 "CMDgram.c" + break; + + case 34: /* object_decl: rwDECLARE class_name_expr '(' object_name parent_block object_args ')' '{' object_declare_block '}' */ +#line 253 "CMDgram.y" + { (yyval.od) = ObjectDeclNode::alloc( (yyvsp[-9].i).lineNumber, (yyvsp[-8].expr), (yyvsp[-6].expr), (yyvsp[-4].expr), (yyvsp[-5].s).value, (yyvsp[-1].odcl).slots, (yyvsp[-1].odcl).decls, false, false, false); } +#line 2167 "CMDgram.c" + break; + + case 35: /* object_decl: rwDECLARE class_name_expr '(' object_name parent_block object_args ')' */ +#line 255 "CMDgram.y" + { (yyval.od) = ObjectDeclNode::alloc( (yyvsp[-6].i).lineNumber, (yyvsp[-5].expr), (yyvsp[-3].expr), (yyvsp[-1].expr), (yyvsp[-2].s).value, NULL, NULL, false, false, false); } +#line 2173 "CMDgram.c" + break; + + case 36: /* object_decl: rwDECLARE class_name_expr '(' '[' object_name ']' parent_block object_args ')' '{' object_declare_block '}' */ +#line 257 "CMDgram.y" + { (yyval.od) = ObjectDeclNode::alloc( (yyvsp[-11].i).lineNumber, (yyvsp[-10].expr), (yyvsp[-7].expr), (yyvsp[-4].expr), (yyvsp[-5].s).value, (yyvsp[-1].odcl).slots, (yyvsp[-1].odcl).decls, false, true, false); } +#line 2179 "CMDgram.c" + break; + + case 37: /* object_decl: rwDECLARE class_name_expr '(' '[' object_name ']' parent_block object_args ')' */ +#line 259 "CMDgram.y" + { (yyval.od) = ObjectDeclNode::alloc( (yyvsp[-8].i).lineNumber, (yyvsp[-7].expr), (yyvsp[-4].expr), (yyvsp[-1].expr), (yyvsp[-2].s).value, NULL, NULL, false, true, false); } +#line 2185 "CMDgram.c" + break; + + case 38: /* object_decl: rwDECLARESINGLETON class_name_expr '(' object_name parent_block object_args ')' '{' object_declare_block '}' */ +#line 261 "CMDgram.y" + { (yyval.od) = ObjectDeclNode::alloc( (yyvsp[-9].i).lineNumber, (yyvsp[-8].expr), (yyvsp[-6].expr), (yyvsp[-4].expr), (yyvsp[-5].s).value, (yyvsp[-1].odcl).slots, (yyvsp[-1].odcl).decls, false, false, true); } +#line 2191 "CMDgram.c" + break; + + case 39: /* object_decl: rwDECLARESINGLETON class_name_expr '(' object_name parent_block object_args ')' */ +#line 263 "CMDgram.y" + { (yyval.od) = ObjectDeclNode::alloc( (yyvsp[-6].i).lineNumber, (yyvsp[-5].expr), (yyvsp[-3].expr), (yyvsp[-1].expr), (yyvsp[-2].s).value, NULL, NULL, false, false, true); } +#line 2197 "CMDgram.c" + break; + + case 40: /* parent_block: %empty */ +#line 268 "CMDgram.y" + { (yyval.s).value = NULL; } +#line 2203 "CMDgram.c" + break; + + case 41: /* parent_block: ':' IDENT */ +#line 270 "CMDgram.y" + { (yyval.s) = (yyvsp[0].s); } +#line 2209 "CMDgram.c" + break; + + case 42: /* object_name: %empty */ +#line 275 "CMDgram.y" + { (yyval.expr) = StrConstNode::alloc( CodeBlock::smCurrentParser->getCurrentLine(), "", false); } +#line 2215 "CMDgram.c" + break; + + case 43: /* object_name: expr */ +#line 277 "CMDgram.y" + { (yyval.expr) = (yyvsp[0].expr); } +#line 2221 "CMDgram.c" + break; + + case 44: /* object_args: %empty */ +#line 282 "CMDgram.y" + { (yyval.expr) = NULL; } +#line 2227 "CMDgram.c" + break; + + case 45: /* object_args: ',' expr_list */ +#line 284 "CMDgram.y" + { (yyval.expr) = (yyvsp[0].expr); } +#line 2233 "CMDgram.c" + break; + + case 46: /* object_declare_block: %empty */ +#line 289 "CMDgram.y" + { (yyval.odcl).slots = NULL; (yyval.odcl).decls = NULL; } +#line 2239 "CMDgram.c" + break; + + case 47: /* object_declare_block: slot_assign_list */ +#line 291 "CMDgram.y" + { (yyval.odcl).slots = (yyvsp[0].slist); (yyval.odcl).decls = NULL; } +#line 2245 "CMDgram.c" + break; + + case 48: /* object_declare_block: object_decl_list */ +#line 293 "CMDgram.y" + { (yyval.odcl).slots = NULL; (yyval.odcl).decls = (yyvsp[0].od); } +#line 2251 "CMDgram.c" + break; + + case 49: /* object_declare_block: slot_assign_list object_decl_list */ +#line 295 "CMDgram.y" + { (yyval.odcl).slots = (yyvsp[-1].slist); (yyval.odcl).decls = (yyvsp[0].od); } +#line 2257 "CMDgram.c" + break; + + case 50: /* object_decl_list: object_decl ';' */ +#line 300 "CMDgram.y" + { (yyval.od) = (yyvsp[-1].od); } +#line 2263 "CMDgram.c" + break; + + case 51: /* object_decl_list: object_decl_list object_decl ';' */ +#line 302 "CMDgram.y" + { (yyvsp[-2].od)->append((yyvsp[-1].od)); (yyval.od) = (yyvsp[-2].od); } +#line 2269 "CMDgram.c" + break; + + case 52: /* stmt_block: '{' statement_list '}' */ +#line 307 "CMDgram.y" + { (yyval.stmt) = (yyvsp[-1].stmt); } +#line 2275 "CMDgram.c" + break; + + case 53: /* stmt_block: stmt */ +#line 309 "CMDgram.y" + { (yyval.stmt) = (yyvsp[0].stmt); } +#line 2281 "CMDgram.c" + break; + + case 54: /* switch_stmt: rwSWITCH '(' expr ')' '{' case_block '}' */ +#line 314 "CMDgram.y" + { (yyval.stmt) = (yyvsp[-1].ifnode); (yyvsp[-1].ifnode)->propagateSwitchExpr((yyvsp[-4].expr), false); } +#line 2287 "CMDgram.c" + break; + + case 55: /* switch_stmt: rwSWITCHSTR '(' expr ')' '{' case_block '}' */ +#line 316 "CMDgram.y" + { (yyval.stmt) = (yyvsp[-1].ifnode); (yyvsp[-1].ifnode)->propagateSwitchExpr((yyvsp[-4].expr), true); } +#line 2293 "CMDgram.c" + break; + + case 56: /* case_block: rwCASE case_expr ':' statement_list */ +#line 321 "CMDgram.y" + { (yyval.ifnode) = IfStmtNode::alloc( (yyvsp[-3].i).lineNumber, (yyvsp[-2].expr), (yyvsp[0].stmt), NULL, false); } +#line 2299 "CMDgram.c" + break; + + case 57: /* case_block: rwCASE case_expr ':' statement_list rwDEFAULT ':' statement_list */ +#line 323 "CMDgram.y" + { (yyval.ifnode) = IfStmtNode::alloc( (yyvsp[-6].i).lineNumber, (yyvsp[-5].expr), (yyvsp[-3].stmt), (yyvsp[0].stmt), false); } +#line 2305 "CMDgram.c" + break; + + case 58: /* case_block: rwCASE case_expr ':' statement_list case_block */ +#line 325 "CMDgram.y" + { (yyval.ifnode) = IfStmtNode::alloc( (yyvsp[-4].i).lineNumber, (yyvsp[-3].expr), (yyvsp[-1].stmt), (yyvsp[0].ifnode), true); } +#line 2311 "CMDgram.c" + break; + + case 59: /* case_expr: expr */ +#line 330 "CMDgram.y" + { (yyval.expr) = (yyvsp[0].expr);} +#line 2317 "CMDgram.c" + break; + + case 60: /* case_expr: case_expr rwCASEOR expr */ +#line 332 "CMDgram.y" + { ((yyvsp[-2].expr))->append((yyvsp[0].expr)); (yyval.expr)=(yyvsp[-2].expr); } +#line 2323 "CMDgram.c" + break; + + case 61: /* if_stmt: rwIF '(' expr ')' stmt_block */ +#line 337 "CMDgram.y" + { (yyval.stmt) = IfStmtNode::alloc((yyvsp[-4].i).lineNumber, (yyvsp[-2].expr), (yyvsp[0].stmt), NULL, false); } +#line 2329 "CMDgram.c" + break; + + case 62: /* if_stmt: rwIF '(' expr ')' stmt_block rwELSE stmt_block */ +#line 339 "CMDgram.y" + { (yyval.stmt) = IfStmtNode::alloc((yyvsp[-6].i).lineNumber, (yyvsp[-4].expr), (yyvsp[-2].stmt), (yyvsp[0].stmt), false); } +#line 2335 "CMDgram.c" + break; + + case 63: /* while_stmt: rwWHILE '(' expr ')' stmt_block */ +#line 344 "CMDgram.y" + { (yyval.stmt) = LoopStmtNode::alloc((yyvsp[-4].i).lineNumber, nil, (yyvsp[-2].expr), nil, (yyvsp[0].stmt), false); } +#line 2341 "CMDgram.c" + break; + + case 64: /* while_stmt: rwDO stmt_block rwWHILE '(' expr ')' */ +#line 346 "CMDgram.y" + { (yyval.stmt) = LoopStmtNode::alloc((yyvsp[-3].i).lineNumber, nil, (yyvsp[-1].expr), nil, (yyvsp[-4].stmt), true); } +#line 2347 "CMDgram.c" + break; + + case 65: /* for_stmt: rwFOR '(' expr ';' expr ';' expr ')' stmt_block */ +#line 351 "CMDgram.y" + { (yyval.stmt) = LoopStmtNode::alloc((yyvsp[-8].i).lineNumber, (yyvsp[-6].expr), (yyvsp[-4].expr), (yyvsp[-2].expr), (yyvsp[0].stmt), false); } +#line 2353 "CMDgram.c" + break; + + case 66: /* for_stmt: rwFOR '(' expr ';' expr ';' ')' stmt_block */ +#line 353 "CMDgram.y" + { (yyval.stmt) = LoopStmtNode::alloc((yyvsp[-7].i).lineNumber, (yyvsp[-5].expr), (yyvsp[-3].expr), NULL, (yyvsp[0].stmt), false); } +#line 2359 "CMDgram.c" + break; + + case 67: /* for_stmt: rwFOR '(' expr ';' ';' expr ')' stmt_block */ +#line 355 "CMDgram.y" + { (yyval.stmt) = LoopStmtNode::alloc((yyvsp[-7].i).lineNumber, (yyvsp[-5].expr), NULL, (yyvsp[-2].expr), (yyvsp[0].stmt), false); } +#line 2365 "CMDgram.c" + break; + + case 68: /* for_stmt: rwFOR '(' expr ';' ';' ')' stmt_block */ +#line 357 "CMDgram.y" + { (yyval.stmt) = LoopStmtNode::alloc((yyvsp[-6].i).lineNumber, (yyvsp[-4].expr), NULL, NULL, (yyvsp[0].stmt), false); } +#line 2371 "CMDgram.c" + break; + + case 69: /* for_stmt: rwFOR '(' ';' expr ';' expr ')' stmt_block */ +#line 359 "CMDgram.y" + { (yyval.stmt) = LoopStmtNode::alloc((yyvsp[-7].i).lineNumber, NULL, (yyvsp[-4].expr), (yyvsp[-2].expr), (yyvsp[0].stmt), false); } +#line 2377 "CMDgram.c" + break; + + case 70: /* for_stmt: rwFOR '(' ';' expr ';' ')' stmt_block */ +#line 361 "CMDgram.y" + { (yyval.stmt) = LoopStmtNode::alloc((yyvsp[-6].i).lineNumber, NULL, (yyvsp[-3].expr), NULL, (yyvsp[0].stmt), false); } +#line 2383 "CMDgram.c" + break; + + case 71: /* for_stmt: rwFOR '(' ';' ';' expr ')' stmt_block */ +#line 363 "CMDgram.y" + { (yyval.stmt) = LoopStmtNode::alloc((yyvsp[-6].i).lineNumber, NULL, NULL, (yyvsp[-2].expr), (yyvsp[0].stmt), false); } +#line 2389 "CMDgram.c" + break; + + case 72: /* for_stmt: rwFOR '(' ';' ';' ')' stmt_block */ +#line 365 "CMDgram.y" + { (yyval.stmt) = LoopStmtNode::alloc((yyvsp[-5].i).lineNumber, NULL, NULL, NULL, (yyvsp[0].stmt), false); } +#line 2395 "CMDgram.c" + break; + + case 73: /* foreach_stmt: rwFOREACH '(' VAR rwIN expr ')' stmt_block */ +#line 370 "CMDgram.y" + { (yyval.stmt) = IterStmtNode::alloc( (yyvsp[-6].i).lineNumber, (yyvsp[-4].s).value, (yyvsp[-2].expr), (yyvsp[0].stmt), false ); } +#line 2401 "CMDgram.c" + break; + + case 74: /* foreach_stmt: rwFOREACHSTR '(' VAR rwIN expr ')' stmt_block */ +#line 372 "CMDgram.y" + { (yyval.stmt) = IterStmtNode::alloc( (yyvsp[-6].i).lineNumber, (yyvsp[-4].s).value, (yyvsp[-2].expr), (yyvsp[0].stmt), true ); } +#line 2407 "CMDgram.c" + break; + + case 75: /* expression_stmt: stmt_expr */ +#line 377 "CMDgram.y" + { (yyval.stmt) = (yyvsp[0].expr); } +#line 2413 "CMDgram.c" + break; + + case 76: /* expr: stmt_expr */ +#line 382 "CMDgram.y" + { (yyval.expr) = (yyvsp[0].expr); } +#line 2419 "CMDgram.c" + break; + + case 77: /* expr: '(' expr ')' */ +#line 384 "CMDgram.y" + { (yyval.expr) = (yyvsp[-1].expr); } +#line 2425 "CMDgram.c" + break; + + case 78: /* expr: expr '^' expr */ +#line 386 "CMDgram.y" + { (yyval.expr) = IntBinaryExprNode::alloc( (yyvsp[-2].expr)->dbgLineNumber, (yyvsp[-1].i).value, (yyvsp[-2].expr), (yyvsp[0].expr)); } +#line 2431 "CMDgram.c" + break; + + case 79: /* expr: expr '%' expr */ +#line 388 "CMDgram.y" + { (yyval.expr) = IntBinaryExprNode::alloc( (yyvsp[-2].expr)->dbgLineNumber, (yyvsp[-1].i).value, (yyvsp[-2].expr), (yyvsp[0].expr)); } +#line 2437 "CMDgram.c" + break; + + case 80: /* expr: expr '&' expr */ +#line 390 "CMDgram.y" + { (yyval.expr) = IntBinaryExprNode::alloc( (yyvsp[-2].expr)->dbgLineNumber, (yyvsp[-1].i).value, (yyvsp[-2].expr), (yyvsp[0].expr)); } +#line 2443 "CMDgram.c" + break; + + case 81: /* expr: expr '|' expr */ +#line 392 "CMDgram.y" + { (yyval.expr) = IntBinaryExprNode::alloc( (yyvsp[-2].expr)->dbgLineNumber, (yyvsp[-1].i).value, (yyvsp[-2].expr), (yyvsp[0].expr)); } +#line 2449 "CMDgram.c" + break; + + case 82: /* expr: expr '+' expr */ +#line 394 "CMDgram.y" + { (yyval.expr) = FloatBinaryExprNode::alloc( (yyvsp[-2].expr)->dbgLineNumber, (yyvsp[-1].i).value, (yyvsp[-2].expr), (yyvsp[0].expr)); } +#line 2455 "CMDgram.c" + break; + + case 83: /* expr: expr '-' expr */ +#line 396 "CMDgram.y" + { (yyval.expr) = FloatBinaryExprNode::alloc( (yyvsp[-2].expr)->dbgLineNumber, (yyvsp[-1].i).value, (yyvsp[-2].expr), (yyvsp[0].expr)); } +#line 2461 "CMDgram.c" + break; + + case 84: /* expr: expr '*' expr */ +#line 398 "CMDgram.y" + { (yyval.expr) = FloatBinaryExprNode::alloc( (yyvsp[-2].expr)->dbgLineNumber, (yyvsp[-1].i).value, (yyvsp[-2].expr), (yyvsp[0].expr)); } +#line 2467 "CMDgram.c" + break; + + case 85: /* expr: expr '/' expr */ +#line 400 "CMDgram.y" + { (yyval.expr) = FloatBinaryExprNode::alloc( (yyvsp[-2].expr)->dbgLineNumber, (yyvsp[-1].i).value, (yyvsp[-2].expr), (yyvsp[0].expr)); } +#line 2473 "CMDgram.c" + break; + + case 86: /* expr: '-' expr */ +#line 402 "CMDgram.y" + { (yyval.expr) = FloatUnaryExprNode::alloc( (yyvsp[-1].i).lineNumber, (yyvsp[-1].i).value, (yyvsp[0].expr)); } +#line 2479 "CMDgram.c" + break; + + case 87: /* expr: '*' expr */ +#line 404 "CMDgram.y" + { (yyval.expr) = TTagDerefNode::alloc( (yyvsp[-1].i).lineNumber, (yyvsp[0].expr) ); } +#line 2485 "CMDgram.c" + break; + + case 88: /* expr: TTAG */ +#line 406 "CMDgram.y" + { (yyval.expr) = TTagExprNode::alloc( (yyvsp[0].s).lineNumber, (yyvsp[0].s).value ); } +#line 2491 "CMDgram.c" + break; + + case 89: /* expr: expr '?' expr ':' expr */ +#line 408 "CMDgram.y" + { (yyval.expr) = ConditionalExprNode::alloc( (yyvsp[-4].expr)->dbgLineNumber, (yyvsp[-4].expr), (yyvsp[-2].expr), (yyvsp[0].expr)); } +#line 2497 "CMDgram.c" + break; + + case 90: /* expr: expr '<' expr */ +#line 410 "CMDgram.y" + { (yyval.expr) = IntBinaryExprNode::alloc( (yyvsp[-2].expr)->dbgLineNumber, (yyvsp[-1].i).value, (yyvsp[-2].expr), (yyvsp[0].expr)); } +#line 2503 "CMDgram.c" + break; + + case 91: /* expr: expr '>' expr */ +#line 412 "CMDgram.y" + { (yyval.expr) = IntBinaryExprNode::alloc( (yyvsp[-2].expr)->dbgLineNumber, (yyvsp[-1].i).value, (yyvsp[-2].expr), (yyvsp[0].expr)); } +#line 2509 "CMDgram.c" + break; + + case 92: /* expr: expr opGE expr */ +#line 414 "CMDgram.y" + { (yyval.expr) = IntBinaryExprNode::alloc( (yyvsp[-2].expr)->dbgLineNumber, (yyvsp[-1].i).value, (yyvsp[-2].expr), (yyvsp[0].expr)); } +#line 2515 "CMDgram.c" + break; + + case 93: /* expr: expr opLE expr */ +#line 416 "CMDgram.y" + { (yyval.expr) = IntBinaryExprNode::alloc( (yyvsp[-2].expr)->dbgLineNumber, (yyvsp[-1].i).value, (yyvsp[-2].expr), (yyvsp[0].expr)); } +#line 2521 "CMDgram.c" + break; + + case 94: /* expr: expr opEQ expr */ +#line 418 "CMDgram.y" + { (yyval.expr) = IntBinaryExprNode::alloc( (yyvsp[-2].expr)->dbgLineNumber, (yyvsp[-1].i).value, (yyvsp[-2].expr), (yyvsp[0].expr)); } +#line 2527 "CMDgram.c" + break; + + case 95: /* expr: expr opNE expr */ +#line 420 "CMDgram.y" + { (yyval.expr) = IntBinaryExprNode::alloc( (yyvsp[-2].expr)->dbgLineNumber, (yyvsp[-1].i).value, (yyvsp[-2].expr), (yyvsp[0].expr)); } +#line 2533 "CMDgram.c" + break; + + case 96: /* expr: expr opOR expr */ +#line 422 "CMDgram.y" + { (yyval.expr) = IntBinaryExprNode::alloc( (yyvsp[-2].expr)->dbgLineNumber, (yyvsp[-1].i).value, (yyvsp[-2].expr), (yyvsp[0].expr)); } +#line 2539 "CMDgram.c" + break; + + case 97: /* expr: expr opSHL expr */ +#line 424 "CMDgram.y" + { (yyval.expr) = IntBinaryExprNode::alloc( (yyvsp[-2].expr)->dbgLineNumber, (yyvsp[-1].i).value, (yyvsp[-2].expr), (yyvsp[0].expr)); } +#line 2545 "CMDgram.c" + break; + + case 98: /* expr: expr opSHR expr */ +#line 426 "CMDgram.y" + { (yyval.expr) = IntBinaryExprNode::alloc( (yyvsp[-2].expr)->dbgLineNumber, (yyvsp[-1].i).value, (yyvsp[-2].expr), (yyvsp[0].expr)); } +#line 2551 "CMDgram.c" + break; + + case 99: /* expr: expr opAND expr */ +#line 428 "CMDgram.y" + { (yyval.expr) = IntBinaryExprNode::alloc( (yyvsp[-2].expr)->dbgLineNumber, (yyvsp[-1].i).value, (yyvsp[-2].expr), (yyvsp[0].expr)); } +#line 2557 "CMDgram.c" + break; + + case 100: /* expr: expr opSTREQ expr */ +#line 430 "CMDgram.y" + { (yyval.expr) = StreqExprNode::alloc( (yyvsp[-2].expr)->dbgLineNumber, (yyvsp[-2].expr), (yyvsp[0].expr), true); } +#line 2563 "CMDgram.c" + break; + + case 101: /* expr: expr opSTRNE expr */ +#line 432 "CMDgram.y" + { (yyval.expr) = StreqExprNode::alloc( (yyvsp[-2].expr)->dbgLineNumber, (yyvsp[-2].expr), (yyvsp[0].expr), false); } +#line 2569 "CMDgram.c" + break; + + case 102: /* expr: expr '@' expr */ +#line 434 "CMDgram.y" + { (yyval.expr) = StrcatExprNode::alloc( (yyvsp[-2].expr)->dbgLineNumber, (yyvsp[-2].expr), (yyvsp[0].expr), (yyvsp[-1].i).value); } +#line 2575 "CMDgram.c" + break; + + case 103: /* expr: '!' expr */ +#line 436 "CMDgram.y" + { (yyval.expr) = IntUnaryExprNode::alloc((yyvsp[-1].i).lineNumber, (yyvsp[-1].i).value, (yyvsp[0].expr)); } +#line 2581 "CMDgram.c" + break; + + case 104: /* expr: '~' expr */ +#line 438 "CMDgram.y" + { (yyval.expr) = IntUnaryExprNode::alloc((yyvsp[-1].i).lineNumber, (yyvsp[-1].i).value, (yyvsp[0].expr)); } +#line 2587 "CMDgram.c" + break; + + case 105: /* expr: TAGATOM */ +#line 440 "CMDgram.y" + { (yyval.expr) = StrConstNode::alloc( (yyvsp[0].str).lineNumber, (yyvsp[0].str).value, true); } +#line 2593 "CMDgram.c" + break; + + case 106: /* expr: FLTCONST */ +#line 442 "CMDgram.y" + { (yyval.expr) = FloatNode::alloc( (yyvsp[0].f).lineNumber, (yyvsp[0].f).value ); } +#line 2599 "CMDgram.c" + break; + + case 107: /* expr: INTCONST */ +#line 444 "CMDgram.y" + { (yyval.expr) = IntNode::alloc( (yyvsp[0].i).lineNumber, (yyvsp[0].i).value ); } +#line 2605 "CMDgram.c" + break; + + case 108: /* expr: rwBREAK */ +#line 446 "CMDgram.y" + { (yyval.expr) = ConstantNode::alloc( (yyvsp[0].i).lineNumber, StringTable->insert("break")); } +#line 2611 "CMDgram.c" + break; + + case 109: /* expr: slot_acc */ +#line 448 "CMDgram.y" + { (yyval.expr) = SlotAccessNode::alloc( (yyvsp[0].slot).lineNumber, (yyvsp[0].slot).object, (yyvsp[0].slot).array, (yyvsp[0].slot).slotName ); } +#line 2617 "CMDgram.c" + break; + + case 110: /* expr: intslot_acc */ +#line 450 "CMDgram.y" + { (yyval.expr) = InternalSlotAccessNode::alloc( (yyvsp[0].intslot).lineNumber, (yyvsp[0].intslot).object, (yyvsp[0].intslot).slotExpr, (yyvsp[0].intslot).recurse); } +#line 2623 "CMDgram.c" + break; + + case 111: /* expr: IDENT */ +#line 452 "CMDgram.y" + { (yyval.expr) = ConstantNode::alloc( (yyvsp[0].s).lineNumber, (yyvsp[0].s).value ); } +#line 2629 "CMDgram.c" + break; + + case 112: /* expr: STRATOM */ +#line 454 "CMDgram.y" + { (yyval.expr) = StrConstNode::alloc( (yyvsp[0].str).lineNumber, (yyvsp[0].str).value, false); } +#line 2635 "CMDgram.c" + break; + + case 113: /* expr: VAR */ +#line 456 "CMDgram.y" + { (yyval.expr) = (ExprNode*)VarNode::alloc( (yyvsp[0].s).lineNumber, (yyvsp[0].s).value, NULL); } +#line 2641 "CMDgram.c" + break; + + case 114: /* expr: VAR '[' aidx_expr ']' */ +#line 458 "CMDgram.y" + { (yyval.expr) = (ExprNode*)VarNode::alloc( (yyvsp[-3].s).lineNumber, (yyvsp[-3].s).value, (yyvsp[-1].expr) ); } +#line 2647 "CMDgram.c" + break; + + case 115: /* slot_acc: expr '.' IDENT */ +#line 480 "CMDgram.y" + { (yyval.slot).lineNumber = (yyvsp[-2].expr)->dbgLineNumber; (yyval.slot).object = (yyvsp[-2].expr); (yyval.slot).slotName = (yyvsp[0].s).value; (yyval.slot).array = NULL; } +#line 2653 "CMDgram.c" + break; + + case 116: /* slot_acc: expr '.' IDENT '[' aidx_expr ']' */ +#line 482 "CMDgram.y" + { (yyval.slot).lineNumber = (yyvsp[-5].expr)->dbgLineNumber; (yyval.slot).object = (yyvsp[-5].expr); (yyval.slot).slotName = (yyvsp[-3].s).value; (yyval.slot).array = (yyvsp[-1].expr); } +#line 2659 "CMDgram.c" + break; + + case 117: /* intslot_acc: expr opINTNAME class_name_expr */ +#line 487 "CMDgram.y" + { (yyval.intslot).lineNumber = (yyvsp[-2].expr)->dbgLineNumber; (yyval.intslot).object = (yyvsp[-2].expr); (yyval.intslot).slotExpr = (yyvsp[0].expr); (yyval.intslot).recurse = false; } +#line 2665 "CMDgram.c" + break; + + case 118: /* intslot_acc: expr opINTNAMER class_name_expr */ +#line 489 "CMDgram.y" + { (yyval.intslot).lineNumber = (yyvsp[-2].expr)->dbgLineNumber; (yyval.intslot).object = (yyvsp[-2].expr); (yyval.intslot).slotExpr = (yyvsp[0].expr); (yyval.intslot).recurse = true; } +#line 2671 "CMDgram.c" + break; + + case 119: /* class_name_expr: IDENT */ +#line 494 "CMDgram.y" + { (yyval.expr) = ConstantNode::alloc( (yyvsp[0].s).lineNumber, (yyvsp[0].s).value ); } +#line 2677 "CMDgram.c" + break; + + case 120: /* class_name_expr: '(' expr ')' */ +#line 496 "CMDgram.y" + { (yyval.expr) = (yyvsp[-1].expr); } +#line 2683 "CMDgram.c" + break; + + case 121: /* assign_op_struct: opPLUSPLUS */ +#line 501 "CMDgram.y" + { (yyval.asn).lineNumber = (yyvsp[0].i).lineNumber; (yyval.asn).token = opPLUSPLUS; (yyval.asn).expr = FloatNode::alloc( (yyvsp[0].i).lineNumber, 1 ); } +#line 2689 "CMDgram.c" + break; + + case 122: /* assign_op_struct: opMINUSMINUS */ +#line 503 "CMDgram.y" + { (yyval.asn).lineNumber = (yyvsp[0].i).lineNumber; (yyval.asn).token = opMINUSMINUS; (yyval.asn).expr = FloatNode::alloc( (yyvsp[0].i).lineNumber, 1 ); } +#line 2695 "CMDgram.c" + break; + + case 123: /* assign_op_struct: opPLASN expr */ +#line 505 "CMDgram.y" + { (yyval.asn).lineNumber = (yyvsp[-1].i).lineNumber; (yyval.asn).token = '+'; (yyval.asn).expr = (yyvsp[0].expr); } +#line 2701 "CMDgram.c" + break; + + case 124: /* assign_op_struct: opMIASN expr */ +#line 507 "CMDgram.y" + { (yyval.asn).lineNumber = (yyvsp[-1].i).lineNumber; (yyval.asn).token = '-'; (yyval.asn).expr = (yyvsp[0].expr); } +#line 2707 "CMDgram.c" + break; + + case 125: /* assign_op_struct: opMLASN expr */ +#line 509 "CMDgram.y" + { (yyval.asn).lineNumber = (yyvsp[-1].i).lineNumber; (yyval.asn).token = '*'; (yyval.asn).expr = (yyvsp[0].expr); } +#line 2713 "CMDgram.c" + break; + + case 126: /* assign_op_struct: opDVASN expr */ +#line 511 "CMDgram.y" + { (yyval.asn).lineNumber = (yyvsp[-1].i).lineNumber; (yyval.asn).token = '/'; (yyval.asn).expr = (yyvsp[0].expr); } +#line 2719 "CMDgram.c" + break; + + case 127: /* assign_op_struct: opMODASN expr */ +#line 513 "CMDgram.y" + { (yyval.asn).lineNumber = (yyvsp[-1].i).lineNumber; (yyval.asn).token = '%'; (yyval.asn).expr = (yyvsp[0].expr); } +#line 2725 "CMDgram.c" + break; + + case 128: /* assign_op_struct: opANDASN expr */ +#line 515 "CMDgram.y" + { (yyval.asn).lineNumber = (yyvsp[-1].i).lineNumber; (yyval.asn).token = '&'; (yyval.asn).expr = (yyvsp[0].expr); } +#line 2731 "CMDgram.c" + break; + + case 129: /* assign_op_struct: opXORASN expr */ +#line 517 "CMDgram.y" + { (yyval.asn).lineNumber = (yyvsp[-1].i).lineNumber; (yyval.asn).token = '^'; (yyval.asn).expr = (yyvsp[0].expr); } +#line 2737 "CMDgram.c" + break; + + case 130: /* assign_op_struct: opORASN expr */ +#line 519 "CMDgram.y" + { (yyval.asn).lineNumber = (yyvsp[-1].i).lineNumber; (yyval.asn).token = '|'; (yyval.asn).expr = (yyvsp[0].expr); } +#line 2743 "CMDgram.c" + break; + + case 131: /* assign_op_struct: opSLASN expr */ +#line 521 "CMDgram.y" + { (yyval.asn).lineNumber = (yyvsp[-1].i).lineNumber; (yyval.asn).token = opSHL; (yyval.asn).expr = (yyvsp[0].expr); } +#line 2749 "CMDgram.c" + break; + + case 132: /* assign_op_struct: opSRASN expr */ +#line 523 "CMDgram.y" + { (yyval.asn).lineNumber = (yyvsp[-1].i).lineNumber; (yyval.asn).token = opSHR; (yyval.asn).expr = (yyvsp[0].expr); } +#line 2755 "CMDgram.c" + break; + + case 133: /* stmt_expr: funcall_expr */ +#line 528 "CMDgram.y" + { (yyval.expr) = (yyvsp[0].expr); } +#line 2761 "CMDgram.c" + break; + + case 134: /* stmt_expr: assert_expr */ +#line 530 "CMDgram.y" + { (yyval.expr) = (yyvsp[0].expr); } +#line 2767 "CMDgram.c" + break; + + case 135: /* stmt_expr: object_decl */ +#line 532 "CMDgram.y" + { (yyval.expr) = (yyvsp[0].od); } +#line 2773 "CMDgram.c" + break; + + case 136: /* stmt_expr: VAR '=' expr */ +#line 534 "CMDgram.y" + { (yyval.expr) = AssignExprNode::alloc( (yyvsp[-2].s).lineNumber, (yyvsp[-2].s).value, NULL, (yyvsp[0].expr)); } +#line 2779 "CMDgram.c" + break; + + case 137: /* stmt_expr: VAR '[' aidx_expr ']' '=' expr */ +#line 536 "CMDgram.y" + { (yyval.expr) = AssignExprNode::alloc( (yyvsp[-5].s).lineNumber, (yyvsp[-5].s).value, (yyvsp[-3].expr), (yyvsp[0].expr)); } +#line 2785 "CMDgram.c" + break; + + case 138: /* stmt_expr: VAR assign_op_struct */ +#line 538 "CMDgram.y" + { (yyval.expr) = AssignOpExprNode::alloc( (yyvsp[-1].s).lineNumber, (yyvsp[-1].s).value, NULL, (yyvsp[0].asn).expr, (yyvsp[0].asn).token); } +#line 2791 "CMDgram.c" + break; + + case 139: /* stmt_expr: VAR '[' aidx_expr ']' assign_op_struct */ +#line 540 "CMDgram.y" + { (yyval.expr) = AssignOpExprNode::alloc( (yyvsp[-4].s).lineNumber, (yyvsp[-4].s).value, (yyvsp[-2].expr), (yyvsp[0].asn).expr, (yyvsp[0].asn).token); } +#line 2797 "CMDgram.c" + break; + + case 140: /* stmt_expr: slot_acc assign_op_struct */ +#line 542 "CMDgram.y" + { (yyval.expr) = SlotAssignOpNode::alloc( (yyvsp[-1].slot).lineNumber, (yyvsp[-1].slot).object, (yyvsp[-1].slot).slotName, (yyvsp[-1].slot).array, (yyvsp[0].asn).token, (yyvsp[0].asn).expr); } +#line 2803 "CMDgram.c" + break; + + case 141: /* stmt_expr: slot_acc '=' expr */ +#line 544 "CMDgram.y" + { (yyval.expr) = SlotAssignNode::alloc( (yyvsp[-2].slot).lineNumber, (yyvsp[-2].slot).object, (yyvsp[-2].slot).array, (yyvsp[-2].slot).slotName, (yyvsp[0].expr)); } +#line 2809 "CMDgram.c" + break; + + case 142: /* stmt_expr: slot_acc '=' '{' expr_list '}' */ +#line 546 "CMDgram.y" + { (yyval.expr) = SlotAssignNode::alloc( (yyvsp[-4].slot).lineNumber, (yyvsp[-4].slot).object, (yyvsp[-4].slot).array, (yyvsp[-4].slot).slotName, (yyvsp[-1].expr)); } +#line 2815 "CMDgram.c" + break; + + case 143: /* funcall_expr: IDENT '(' expr_list_decl ')' */ +#line 551 "CMDgram.y" + { (yyval.expr) = FuncCallExprNode::alloc( (yyvsp[-3].s).lineNumber, (yyvsp[-3].s).value, NULL, (yyvsp[-1].expr), false); } +#line 2821 "CMDgram.c" + break; + + case 144: /* funcall_expr: IDENT opCOLONCOLON IDENT '(' expr_list_decl ')' */ +#line 553 "CMDgram.y" + { (yyval.expr) = FuncCallExprNode::alloc( (yyvsp[-5].s).lineNumber, (yyvsp[-3].s).value, (yyvsp[-5].s).value, (yyvsp[-1].expr), false); } +#line 2827 "CMDgram.c" + break; + + case 145: /* funcall_expr: expr '.' IDENT '(' expr_list_decl ')' */ +#line 555 "CMDgram.y" + { (yyvsp[-5].expr)->append((yyvsp[-1].expr)); (yyval.expr) = FuncCallExprNode::alloc( (yyvsp[-5].expr)->dbgLineNumber, (yyvsp[-3].s).value, NULL, (yyvsp[-5].expr), true); } +#line 2833 "CMDgram.c" + break; + + case 146: /* assert_expr: rwASSERT '(' expr ')' */ +#line 565 "CMDgram.y" + { (yyval.expr) = AssertCallExprNode::alloc( (yyvsp[-3].i).lineNumber, (yyvsp[-1].expr), NULL ); } +#line 2839 "CMDgram.c" + break; + + case 147: /* assert_expr: rwASSERT '(' expr ',' STRATOM ')' */ +#line 567 "CMDgram.y" + { (yyval.expr) = AssertCallExprNode::alloc( (yyvsp[-5].i).lineNumber, (yyvsp[-3].expr), (yyvsp[-1].str).value ); } +#line 2845 "CMDgram.c" + break; + + case 148: /* expr_list_decl: %empty */ +#line 572 "CMDgram.y" + { (yyval.expr) = NULL; } +#line 2851 "CMDgram.c" + break; + + case 149: /* expr_list_decl: expr_list */ +#line 574 "CMDgram.y" + { (yyval.expr) = (yyvsp[0].expr); } +#line 2857 "CMDgram.c" + break; + + case 150: /* expr_list: expr */ +#line 579 "CMDgram.y" + { (yyval.expr) = (yyvsp[0].expr); } +#line 2863 "CMDgram.c" + break; + + case 151: /* expr_list: expr_list ',' expr */ +#line 581 "CMDgram.y" + { ((yyvsp[-2].expr))->append((yyvsp[0].expr)); (yyval.expr) = (yyvsp[-2].expr); } +#line 2869 "CMDgram.c" + break; + + case 152: /* slot_assign_list_opt: %empty */ +#line 586 "CMDgram.y" + { (yyval.slist) = NULL; } +#line 2875 "CMDgram.c" + break; + + case 153: /* slot_assign_list_opt: slot_assign_list */ +#line 588 "CMDgram.y" + { (yyval.slist) = (yyvsp[0].slist); } +#line 2881 "CMDgram.c" + break; + + case 154: /* slot_assign_list: slot_assign */ +#line 593 "CMDgram.y" + { (yyval.slist) = (yyvsp[0].slist); } +#line 2887 "CMDgram.c" + break; + + case 155: /* slot_assign_list: slot_assign_list slot_assign */ +#line 595 "CMDgram.y" + { (yyvsp[-1].slist)->append((yyvsp[0].slist)); (yyval.slist) = (yyvsp[-1].slist); } +#line 2893 "CMDgram.c" + break; + + case 156: /* slot_assign: IDENT '=' expr ';' */ +#line 600 "CMDgram.y" + { (yyval.slist) = SlotAssignNode::alloc( (yyvsp[-3].s).lineNumber, NULL, NULL, (yyvsp[-3].s).value, (yyvsp[-1].expr)); } +#line 2899 "CMDgram.c" + break; + + case 157: /* slot_assign: TYPEIDENT IDENT '=' expr ';' */ +#line 602 "CMDgram.y" + { (yyval.slist) = SlotAssignNode::alloc( (yyvsp[-4].i).lineNumber, NULL, NULL, (yyvsp[-3].s).value, (yyvsp[-1].expr), (yyvsp[-4].i).value); } +#line 2905 "CMDgram.c" + break; + + case 158: /* slot_assign: rwDATABLOCK '=' expr ';' */ +#line 604 "CMDgram.y" + { (yyval.slist) = SlotAssignNode::alloc( (yyvsp[-3].i).lineNumber, NULL, NULL, StringTable->insert("datablock"), (yyvsp[-1].expr)); } +#line 2911 "CMDgram.c" + break; + + case 159: /* slot_assign: IDENT '[' aidx_expr ']' '=' expr ';' */ +#line 606 "CMDgram.y" + { (yyval.slist) = SlotAssignNode::alloc( (yyvsp[-6].s).lineNumber, NULL, (yyvsp[-4].expr), (yyvsp[-6].s).value, (yyvsp[-1].expr)); } +#line 2917 "CMDgram.c" + break; + + case 160: /* slot_assign: TYPEIDENT IDENT '[' aidx_expr ']' '=' expr ';' */ +#line 608 "CMDgram.y" + { (yyval.slist) = SlotAssignNode::alloc( (yyvsp[-7].i).lineNumber, NULL, (yyvsp[-4].expr), (yyvsp[-6].s).value, (yyvsp[-1].expr), (yyvsp[-7].i).value); } +#line 2923 "CMDgram.c" + break; + + case 161: /* aidx_expr: expr */ +#line 613 "CMDgram.y" + { (yyval.expr) = (yyvsp[0].expr); } +#line 2929 "CMDgram.c" + break; + + case 162: /* aidx_expr: aidx_expr ',' expr */ +#line 615 "CMDgram.y" + { (yyval.expr) = CommaCatExprNode::alloc( (yyvsp[-2].expr)->dbgLineNumber, (yyvsp[-2].expr), (yyvsp[0].expr)); } +#line 2935 "CMDgram.c" + break; + + +#line 2939 "CMDgram.c" + + default: break; } -#endif + /* 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 ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc); - - switch (yyn) { - -case 1: -#line 162 "cmdgram.y" -{ ; - break;} -case 2: -#line 167 "cmdgram.y" -{ yyval.stmt = nil; ; - break;} -case 3: -#line 169 "cmdgram.y" -{ if(!Script::gStatementList) { Script::gStatementList = yyvsp[0].stmt; } else { Script::gStatementList->append(yyvsp[0].stmt); } ; - break;} -case 4: -#line 174 "cmdgram.y" -{ yyval.stmt = yyvsp[0].stmt; ; - break;} -case 5: -#line 176 "cmdgram.y" -{ yyval.stmt = yyvsp[0].stmt; ; - break;} -case 6: -#line 178 "cmdgram.y" -{ yyval.stmt = yyvsp[0].stmt; ; - break;} -case 7: -#line 183 "cmdgram.y" -{ yyval.stmt = yyvsp[-2].stmt; for(StmtNode *walk = (yyvsp[-2].stmt);walk;walk = walk->getNext() ) walk->setPackage(yyvsp[-4].s.value); ; - break;} -case 8: -#line 188 "cmdgram.y" -{ yyval.stmt = yyvsp[0].stmt; ; - break;} -case 9: -#line 190 "cmdgram.y" -{ yyval.stmt = yyvsp[-1].stmt; (yyvsp[-1].stmt)->append(yyvsp[0].stmt); ; - break;} -case 10: -#line 195 "cmdgram.y" -{ yyval.stmt = nil; ; - break;} -case 11: -#line 197 "cmdgram.y" -{ if(!yyvsp[-1].stmt) { yyval.stmt = yyvsp[0].stmt; } else { (yyvsp[-1].stmt)->append(yyvsp[0].stmt); yyval.stmt = yyvsp[-1].stmt; } ; - break;} -case 18: -#line 208 "cmdgram.y" -{ yyval.stmt = BreakStmtNode::alloc( yyvsp[-1].i.lineNumber ); ; - break;} -case 19: -#line 210 "cmdgram.y" -{ yyval.stmt = ContinueStmtNode::alloc( yyvsp[-1].i.lineNumber ); ; - break;} -case 20: -#line 212 "cmdgram.y" -{ yyval.stmt = ReturnStmtNode::alloc( yyvsp[-1].i.lineNumber, NULL ); ; - break;} -case 21: -#line 214 "cmdgram.y" -{ yyval.stmt = ReturnStmtNode::alloc( yyvsp[-2].i.lineNumber, yyvsp[-1].expr ); ; - break;} -case 22: -#line 216 "cmdgram.y" -{ yyval.stmt = yyvsp[-1].stmt; ; - break;} -case 23: -#line 218 "cmdgram.y" -{ yyval.stmt = TTagSetStmtNode::alloc( yyvsp[-3].s.lineNumber, yyvsp[-3].s.value, yyvsp[-1].expr, NULL ); ; - break;} -case 24: -#line 220 "cmdgram.y" -{ yyval.stmt = TTagSetStmtNode::alloc( yyvsp[-5].s.lineNumber, yyvsp[-5].s.value, yyvsp[-3].expr, yyvsp[-1].expr ); ; - break;} -case 25: -#line 222 "cmdgram.y" -{ yyval.stmt = StrConstNode::alloc( yyvsp[0].str.lineNumber, yyvsp[0].str.value, false, true ); ; - break;} -case 26: -#line 227 "cmdgram.y" -{ yyval.stmt = FunctionDeclStmtNode::alloc( yyvsp[-7].i.lineNumber, yyvsp[-6].s.value, NULL, yyvsp[-4].var, yyvsp[-1].stmt ); ; - break;} -case 27: -#line 229 "cmdgram.y" -{ yyval.stmt = FunctionDeclStmtNode::alloc( yyvsp[-9].i.lineNumber, yyvsp[-6].s.value, yyvsp[-8].s.value, yyvsp[-4].var, yyvsp[-1].stmt ); ; - break;} -case 28: -#line 234 "cmdgram.y" -{ yyval.var = NULL; ; - break;} -case 29: -#line 236 "cmdgram.y" -{ yyval.var = yyvsp[0].var; ; - break;} -case 30: -#line 241 "cmdgram.y" -{ yyval.var = VarNode::alloc( yyvsp[0].s.lineNumber, yyvsp[0].s.value, NULL ); ; - break;} -case 31: -#line 243 "cmdgram.y" -{ yyval.var = yyvsp[-2].var; ((StmtNode*)(yyvsp[-2].var))->append((StmtNode*)VarNode::alloc( yyvsp[0].s.lineNumber, yyvsp[0].s.value, NULL ) ); ; - break;} -case 32: -#line 248 "cmdgram.y" -{ yyval.stmt = ObjectDeclNode::alloc( yyvsp[-9].i.lineNumber, yyvsp[-8].expr, yyvsp[-6].expr, NULL, yyvsp[-5].s.value, yyvsp[-2].slist, NULL, true, false, false); ; - break;} -case 33: -#line 253 "cmdgram.y" -{ yyval.od = ObjectDeclNode::alloc( yyvsp[-9].i.lineNumber, yyvsp[-8].expr, yyvsp[-6].expr, yyvsp[-4].expr, yyvsp[-5].s.value, yyvsp[-1].odcl.slots, yyvsp[-1].odcl.decls, false, false, false); ; - break;} -case 34: -#line 255 "cmdgram.y" -{ yyval.od = ObjectDeclNode::alloc( yyvsp[-6].i.lineNumber, yyvsp[-5].expr, yyvsp[-3].expr, yyvsp[-1].expr, yyvsp[-2].s.value, NULL, NULL, false, false, false); ; - break;} -case 35: -#line 257 "cmdgram.y" -{ yyval.od = ObjectDeclNode::alloc( yyvsp[-11].i.lineNumber, yyvsp[-10].expr, yyvsp[-7].expr, yyvsp[-4].expr, yyvsp[-5].s.value, yyvsp[-1].odcl.slots, yyvsp[-1].odcl.decls, false, true, false); ; - break;} -case 36: -#line 259 "cmdgram.y" -{ yyval.od = ObjectDeclNode::alloc( yyvsp[-8].i.lineNumber, yyvsp[-7].expr, yyvsp[-4].expr, yyvsp[-1].expr, yyvsp[-2].s.value, NULL, NULL, false, true, false); ; - break;} -case 37: -#line 261 "cmdgram.y" -{ yyval.od = ObjectDeclNode::alloc( yyvsp[-9].i.lineNumber, yyvsp[-8].expr, yyvsp[-6].expr, yyvsp[-4].expr, yyvsp[-5].s.value, yyvsp[-1].odcl.slots, yyvsp[-1].odcl.decls, false, false, true); ; - break;} -case 38: -#line 263 "cmdgram.y" -{ yyval.od = ObjectDeclNode::alloc( yyvsp[-6].i.lineNumber, yyvsp[-5].expr, yyvsp[-3].expr, yyvsp[-1].expr, yyvsp[-2].s.value, NULL, NULL, false, false, true); ; - break;} -case 39: -#line 268 "cmdgram.y" -{ yyval.s.value = NULL; ; - break;} -case 40: -#line 270 "cmdgram.y" -{ yyval.s = yyvsp[0].s; ; - break;} -case 41: -#line 275 "cmdgram.y" -{ yyval.expr = StrConstNode::alloc( CodeBlock::smCurrentParser->getCurrentLine(), "", false); ; - break;} -case 42: -#line 277 "cmdgram.y" -{ yyval.expr = yyvsp[0].expr; ; - break;} -case 43: -#line 282 "cmdgram.y" -{ yyval.expr = NULL; ; - break;} -case 44: -#line 284 "cmdgram.y" -{ yyval.expr = yyvsp[0].expr; ; - break;} -case 45: -#line 289 "cmdgram.y" -{ yyval.odcl.slots = NULL; yyval.odcl.decls = NULL; ; - break;} -case 46: -#line 291 "cmdgram.y" -{ yyval.odcl.slots = yyvsp[0].slist; yyval.odcl.decls = NULL; ; - break;} -case 47: -#line 293 "cmdgram.y" -{ yyval.odcl.slots = NULL; yyval.odcl.decls = yyvsp[0].od; ; - break;} -case 48: -#line 295 "cmdgram.y" -{ yyval.odcl.slots = yyvsp[-1].slist; yyval.odcl.decls = yyvsp[0].od; ; - break;} -case 49: -#line 300 "cmdgram.y" -{ yyval.od = yyvsp[-1].od; ; - break;} -case 50: -#line 302 "cmdgram.y" -{ yyvsp[-2].od->append(yyvsp[-1].od); yyval.od = yyvsp[-2].od; ; - break;} -case 51: -#line 307 "cmdgram.y" -{ yyval.stmt = yyvsp[-1].stmt; ; - break;} -case 52: -#line 309 "cmdgram.y" -{ yyval.stmt = yyvsp[0].stmt; ; - break;} -case 53: -#line 314 "cmdgram.y" -{ yyval.stmt = yyvsp[-1].ifnode; yyvsp[-1].ifnode->propagateSwitchExpr(yyvsp[-4].expr, false); ; - break;} -case 54: -#line 316 "cmdgram.y" -{ yyval.stmt = yyvsp[-1].ifnode; yyvsp[-1].ifnode->propagateSwitchExpr(yyvsp[-4].expr, true); ; - break;} -case 55: -#line 321 "cmdgram.y" -{ yyval.ifnode = IfStmtNode::alloc( yyvsp[-3].i.lineNumber, yyvsp[-2].expr, yyvsp[0].stmt, NULL, false); ; - break;} -case 56: -#line 323 "cmdgram.y" -{ yyval.ifnode = IfStmtNode::alloc( yyvsp[-6].i.lineNumber, yyvsp[-5].expr, yyvsp[-3].stmt, yyvsp[0].stmt, false); ; - break;} -case 57: -#line 325 "cmdgram.y" -{ yyval.ifnode = IfStmtNode::alloc( yyvsp[-4].i.lineNumber, yyvsp[-3].expr, yyvsp[-1].stmt, yyvsp[0].ifnode, true); ; - break;} -case 58: -#line 330 "cmdgram.y" -{ yyval.expr = yyvsp[0].expr;; - break;} -case 59: -#line 332 "cmdgram.y" -{ (yyvsp[-2].expr)->append(yyvsp[0].expr); yyval.expr=yyvsp[-2].expr; ; - break;} -case 60: -#line 337 "cmdgram.y" -{ yyval.stmt = IfStmtNode::alloc(yyvsp[-4].i.lineNumber, yyvsp[-2].expr, yyvsp[0].stmt, NULL, false); ; - break;} -case 61: -#line 339 "cmdgram.y" -{ yyval.stmt = IfStmtNode::alloc(yyvsp[-6].i.lineNumber, yyvsp[-4].expr, yyvsp[-2].stmt, yyvsp[0].stmt, false); ; - break;} -case 62: -#line 344 "cmdgram.y" -{ yyval.stmt = LoopStmtNode::alloc(yyvsp[-4].i.lineNumber, nil, yyvsp[-2].expr, nil, yyvsp[0].stmt, false); ; - break;} -case 63: -#line 346 "cmdgram.y" -{ yyval.stmt = LoopStmtNode::alloc(yyvsp[-3].i.lineNumber, nil, yyvsp[-1].expr, nil, yyvsp[-4].stmt, true); ; - break;} -case 64: -#line 351 "cmdgram.y" -{ yyval.stmt = LoopStmtNode::alloc(yyvsp[-8].i.lineNumber, yyvsp[-6].expr, yyvsp[-4].expr, yyvsp[-2].expr, yyvsp[0].stmt, false); ; - break;} -case 65: -#line 353 "cmdgram.y" -{ yyval.stmt = LoopStmtNode::alloc(yyvsp[-7].i.lineNumber, yyvsp[-5].expr, yyvsp[-3].expr, NULL, yyvsp[0].stmt, false); ; - break;} -case 66: -#line 355 "cmdgram.y" -{ yyval.stmt = LoopStmtNode::alloc(yyvsp[-7].i.lineNumber, yyvsp[-5].expr, NULL, yyvsp[-2].expr, yyvsp[0].stmt, false); ; - break;} -case 67: -#line 357 "cmdgram.y" -{ yyval.stmt = LoopStmtNode::alloc(yyvsp[-6].i.lineNumber, yyvsp[-4].expr, NULL, NULL, yyvsp[0].stmt, false); ; - break;} -case 68: -#line 359 "cmdgram.y" -{ yyval.stmt = LoopStmtNode::alloc(yyvsp[-7].i.lineNumber, NULL, yyvsp[-4].expr, yyvsp[-2].expr, yyvsp[0].stmt, false); ; - break;} -case 69: -#line 361 "cmdgram.y" -{ yyval.stmt = LoopStmtNode::alloc(yyvsp[-6].i.lineNumber, NULL, yyvsp[-3].expr, NULL, yyvsp[0].stmt, false); ; - break;} -case 70: -#line 363 "cmdgram.y" -{ yyval.stmt = LoopStmtNode::alloc(yyvsp[-6].i.lineNumber, NULL, NULL, yyvsp[-2].expr, yyvsp[0].stmt, false); ; - break;} -case 71: -#line 365 "cmdgram.y" -{ yyval.stmt = LoopStmtNode::alloc(yyvsp[-5].i.lineNumber, NULL, NULL, NULL, yyvsp[0].stmt, false); ; - break;} -case 72: -#line 370 "cmdgram.y" -{ yyval.stmt = IterStmtNode::alloc( yyvsp[-6].i.lineNumber, yyvsp[-4].s.value, yyvsp[-2].expr, yyvsp[0].stmt, false ); ; - break;} -case 73: -#line 372 "cmdgram.y" -{ yyval.stmt = IterStmtNode::alloc( yyvsp[-6].i.lineNumber, yyvsp[-4].s.value, yyvsp[-2].expr, yyvsp[0].stmt, true ); ; - break;} -case 74: -#line 377 "cmdgram.y" -{ yyval.stmt = yyvsp[0].expr; ; - break;} -case 75: -#line 382 "cmdgram.y" -{ yyval.expr = yyvsp[0].expr; ; - break;} -case 76: -#line 384 "cmdgram.y" -{ yyval.expr = yyvsp[-1].expr; ; - break;} -case 77: -#line 386 "cmdgram.y" -{ yyval.expr = IntBinaryExprNode::alloc( yyvsp[-2].expr->dbgLineNumber, yyvsp[-1].i.value, yyvsp[-2].expr, yyvsp[0].expr); ; - break;} -case 78: -#line 388 "cmdgram.y" -{ yyval.expr = IntBinaryExprNode::alloc( yyvsp[-2].expr->dbgLineNumber, yyvsp[-1].i.value, yyvsp[-2].expr, yyvsp[0].expr); ; - break;} -case 79: -#line 390 "cmdgram.y" -{ yyval.expr = IntBinaryExprNode::alloc( yyvsp[-2].expr->dbgLineNumber, yyvsp[-1].i.value, yyvsp[-2].expr, yyvsp[0].expr); ; - break;} -case 80: -#line 392 "cmdgram.y" -{ yyval.expr = IntBinaryExprNode::alloc( yyvsp[-2].expr->dbgLineNumber, yyvsp[-1].i.value, yyvsp[-2].expr, yyvsp[0].expr); ; - break;} -case 81: -#line 394 "cmdgram.y" -{ yyval.expr = FloatBinaryExprNode::alloc( yyvsp[-2].expr->dbgLineNumber, yyvsp[-1].i.value, yyvsp[-2].expr, yyvsp[0].expr); ; - break;} -case 82: -#line 396 "cmdgram.y" -{ yyval.expr = FloatBinaryExprNode::alloc( yyvsp[-2].expr->dbgLineNumber, yyvsp[-1].i.value, yyvsp[-2].expr, yyvsp[0].expr); ; - break;} -case 83: -#line 398 "cmdgram.y" -{ yyval.expr = FloatBinaryExprNode::alloc( yyvsp[-2].expr->dbgLineNumber, yyvsp[-1].i.value, yyvsp[-2].expr, yyvsp[0].expr); ; - break;} -case 84: -#line 400 "cmdgram.y" -{ yyval.expr = FloatBinaryExprNode::alloc( yyvsp[-2].expr->dbgLineNumber, yyvsp[-1].i.value, yyvsp[-2].expr, yyvsp[0].expr); ; - break;} -case 85: -#line 402 "cmdgram.y" -{ yyval.expr = FloatUnaryExprNode::alloc( yyvsp[-1].i.lineNumber, yyvsp[-1].i.value, yyvsp[0].expr); ; - break;} -case 86: -#line 404 "cmdgram.y" -{ yyval.expr = TTagDerefNode::alloc( yyvsp[-1].i.lineNumber, yyvsp[0].expr ); ; - break;} -case 87: -#line 406 "cmdgram.y" -{ yyval.expr = TTagExprNode::alloc( yyvsp[0].s.lineNumber, yyvsp[0].s.value ); ; - break;} -case 88: -#line 408 "cmdgram.y" -{ yyval.expr = ConditionalExprNode::alloc( yyvsp[-4].expr->dbgLineNumber, yyvsp[-4].expr, yyvsp[-2].expr, yyvsp[0].expr); ; - break;} -case 89: -#line 410 "cmdgram.y" -{ yyval.expr = IntBinaryExprNode::alloc( yyvsp[-2].expr->dbgLineNumber, yyvsp[-1].i.value, yyvsp[-2].expr, yyvsp[0].expr); ; - break;} -case 90: -#line 412 "cmdgram.y" -{ yyval.expr = IntBinaryExprNode::alloc( yyvsp[-2].expr->dbgLineNumber, yyvsp[-1].i.value, yyvsp[-2].expr, yyvsp[0].expr); ; - break;} -case 91: -#line 414 "cmdgram.y" -{ yyval.expr = IntBinaryExprNode::alloc( yyvsp[-2].expr->dbgLineNumber, yyvsp[-1].i.value, yyvsp[-2].expr, yyvsp[0].expr); ; - break;} -case 92: -#line 416 "cmdgram.y" -{ yyval.expr = IntBinaryExprNode::alloc( yyvsp[-2].expr->dbgLineNumber, yyvsp[-1].i.value, yyvsp[-2].expr, yyvsp[0].expr); ; - break;} -case 93: -#line 418 "cmdgram.y" -{ yyval.expr = IntBinaryExprNode::alloc( yyvsp[-2].expr->dbgLineNumber, yyvsp[-1].i.value, yyvsp[-2].expr, yyvsp[0].expr); ; - break;} -case 94: -#line 420 "cmdgram.y" -{ yyval.expr = IntBinaryExprNode::alloc( yyvsp[-2].expr->dbgLineNumber, yyvsp[-1].i.value, yyvsp[-2].expr, yyvsp[0].expr); ; - break;} -case 95: -#line 422 "cmdgram.y" -{ yyval.expr = IntBinaryExprNode::alloc( yyvsp[-2].expr->dbgLineNumber, yyvsp[-1].i.value, yyvsp[-2].expr, yyvsp[0].expr); ; - break;} -case 96: -#line 424 "cmdgram.y" -{ yyval.expr = IntBinaryExprNode::alloc( yyvsp[-2].expr->dbgLineNumber, yyvsp[-1].i.value, yyvsp[-2].expr, yyvsp[0].expr); ; - break;} -case 97: -#line 426 "cmdgram.y" -{ yyval.expr = IntBinaryExprNode::alloc( yyvsp[-2].expr->dbgLineNumber, yyvsp[-1].i.value, yyvsp[-2].expr, yyvsp[0].expr); ; - break;} -case 98: -#line 428 "cmdgram.y" -{ yyval.expr = IntBinaryExprNode::alloc( yyvsp[-2].expr->dbgLineNumber, yyvsp[-1].i.value, yyvsp[-2].expr, yyvsp[0].expr); ; - break;} -case 99: -#line 430 "cmdgram.y" -{ yyval.expr = StreqExprNode::alloc( yyvsp[-2].expr->dbgLineNumber, yyvsp[-2].expr, yyvsp[0].expr, true); ; - break;} -case 100: -#line 432 "cmdgram.y" -{ yyval.expr = StreqExprNode::alloc( yyvsp[-2].expr->dbgLineNumber, yyvsp[-2].expr, yyvsp[0].expr, false); ; - break;} -case 101: -#line 434 "cmdgram.y" -{ yyval.expr = StrcatExprNode::alloc( yyvsp[-2].expr->dbgLineNumber, yyvsp[-2].expr, yyvsp[0].expr, yyvsp[-1].i.value); ; - break;} -case 102: -#line 436 "cmdgram.y" -{ yyval.expr = IntUnaryExprNode::alloc(yyvsp[-1].i.lineNumber, yyvsp[-1].i.value, yyvsp[0].expr); ; - break;} -case 103: -#line 438 "cmdgram.y" -{ yyval.expr = IntUnaryExprNode::alloc(yyvsp[-1].i.lineNumber, yyvsp[-1].i.value, yyvsp[0].expr); ; - break;} -case 104: -#line 440 "cmdgram.y" -{ yyval.expr = StrConstNode::alloc( yyvsp[0].str.lineNumber, yyvsp[0].str.value, true); ; - break;} -case 105: -#line 442 "cmdgram.y" -{ yyval.expr = FloatNode::alloc( yyvsp[0].f.lineNumber, yyvsp[0].f.value ); ; - break;} -case 106: -#line 444 "cmdgram.y" -{ yyval.expr = IntNode::alloc( yyvsp[0].i.lineNumber, yyvsp[0].i.value ); ; - break;} -case 107: -#line 446 "cmdgram.y" -{ yyval.expr = ConstantNode::alloc( yyvsp[0].i.lineNumber, StringTable->insert("break")); ; - break;} -case 108: -#line 448 "cmdgram.y" -{ yyval.expr = SlotAccessNode::alloc( yyvsp[0].slot.lineNumber, yyvsp[0].slot.object, yyvsp[0].slot.array, yyvsp[0].slot.slotName ); ; - break;} -case 109: -#line 450 "cmdgram.y" -{ yyval.expr = InternalSlotAccessNode::alloc( yyvsp[0].intslot.lineNumber, yyvsp[0].intslot.object, yyvsp[0].intslot.slotExpr, yyvsp[0].intslot.recurse); ; - break;} -case 110: -#line 452 "cmdgram.y" -{ yyval.expr = ConstantNode::alloc( yyvsp[0].s.lineNumber, yyvsp[0].s.value ); ; - break;} -case 111: -#line 454 "cmdgram.y" -{ yyval.expr = StrConstNode::alloc( yyvsp[0].str.lineNumber, yyvsp[0].str.value, false); ; - break;} -case 112: -#line 456 "cmdgram.y" -{ yyval.expr = (ExprNode*)VarNode::alloc( yyvsp[0].s.lineNumber, yyvsp[0].s.value, NULL); ; - break;} -case 113: -#line 458 "cmdgram.y" -{ yyval.expr = (ExprNode*)VarNode::alloc( yyvsp[-3].s.lineNumber, yyvsp[-3].s.value, yyvsp[-1].expr ); ; - break;} -case 114: -#line 480 "cmdgram.y" -{ yyval.slot.lineNumber = yyvsp[-2].expr->dbgLineNumber; yyval.slot.object = yyvsp[-2].expr; yyval.slot.slotName = yyvsp[0].s.value; yyval.slot.array = NULL; ; - break;} -case 115: -#line 482 "cmdgram.y" -{ yyval.slot.lineNumber = yyvsp[-5].expr->dbgLineNumber; yyval.slot.object = yyvsp[-5].expr; yyval.slot.slotName = yyvsp[-3].s.value; yyval.slot.array = yyvsp[-1].expr; ; - break;} -case 116: -#line 487 "cmdgram.y" -{ yyval.intslot.lineNumber = yyvsp[-2].expr->dbgLineNumber; yyval.intslot.object = yyvsp[-2].expr; yyval.intslot.slotExpr = yyvsp[0].expr; yyval.intslot.recurse = false; ; - break;} -case 117: -#line 489 "cmdgram.y" -{ yyval.intslot.lineNumber = yyvsp[-2].expr->dbgLineNumber; yyval.intslot.object = yyvsp[-2].expr; yyval.intslot.slotExpr = yyvsp[0].expr; yyval.intslot.recurse = true; ; - break;} -case 118: -#line 494 "cmdgram.y" -{ yyval.expr = ConstantNode::alloc( yyvsp[0].s.lineNumber, yyvsp[0].s.value ); ; - break;} -case 119: -#line 496 "cmdgram.y" -{ yyval.expr = yyvsp[-1].expr; ; - break;} -case 120: -#line 501 "cmdgram.y" -{ yyval.asn.lineNumber = yyvsp[0].i.lineNumber; yyval.asn.token = opPLUSPLUS; yyval.asn.expr = FloatNode::alloc( yyvsp[0].i.lineNumber, 1 ); ; - break;} -case 121: -#line 503 "cmdgram.y" -{ yyval.asn.lineNumber = yyvsp[0].i.lineNumber; yyval.asn.token = opMINUSMINUS; yyval.asn.expr = FloatNode::alloc( yyvsp[0].i.lineNumber, 1 ); ; - break;} -case 122: -#line 505 "cmdgram.y" -{ yyval.asn.lineNumber = yyvsp[-1].i.lineNumber; yyval.asn.token = '+'; yyval.asn.expr = yyvsp[0].expr; ; - break;} -case 123: -#line 507 "cmdgram.y" -{ yyval.asn.lineNumber = yyvsp[-1].i.lineNumber; yyval.asn.token = '-'; yyval.asn.expr = yyvsp[0].expr; ; - break;} -case 124: -#line 509 "cmdgram.y" -{ yyval.asn.lineNumber = yyvsp[-1].i.lineNumber; yyval.asn.token = '*'; yyval.asn.expr = yyvsp[0].expr; ; - break;} -case 125: -#line 511 "cmdgram.y" -{ yyval.asn.lineNumber = yyvsp[-1].i.lineNumber; yyval.asn.token = '/'; yyval.asn.expr = yyvsp[0].expr; ; - break;} -case 126: -#line 513 "cmdgram.y" -{ yyval.asn.lineNumber = yyvsp[-1].i.lineNumber; yyval.asn.token = '%'; yyval.asn.expr = yyvsp[0].expr; ; - break;} -case 127: -#line 515 "cmdgram.y" -{ yyval.asn.lineNumber = yyvsp[-1].i.lineNumber; yyval.asn.token = '&'; yyval.asn.expr = yyvsp[0].expr; ; - break;} -case 128: -#line 517 "cmdgram.y" -{ yyval.asn.lineNumber = yyvsp[-1].i.lineNumber; yyval.asn.token = '^'; yyval.asn.expr = yyvsp[0].expr; ; - break;} -case 129: -#line 519 "cmdgram.y" -{ yyval.asn.lineNumber = yyvsp[-1].i.lineNumber; yyval.asn.token = '|'; yyval.asn.expr = yyvsp[0].expr; ; - break;} -case 130: -#line 521 "cmdgram.y" -{ yyval.asn.lineNumber = yyvsp[-1].i.lineNumber; yyval.asn.token = opSHL; yyval.asn.expr = yyvsp[0].expr; ; - break;} -case 131: -#line 523 "cmdgram.y" -{ yyval.asn.lineNumber = yyvsp[-1].i.lineNumber; yyval.asn.token = opSHR; yyval.asn.expr = yyvsp[0].expr; ; - break;} -case 132: -#line 528 "cmdgram.y" -{ yyval.expr = yyvsp[0].expr; ; - break;} -case 133: -#line 530 "cmdgram.y" -{ yyval.expr = yyvsp[0].expr; ; - break;} -case 134: -#line 532 "cmdgram.y" -{ yyval.expr = yyvsp[0].od; ; - break;} -case 135: -#line 534 "cmdgram.y" -{ yyval.expr = AssignExprNode::alloc( yyvsp[-2].s.lineNumber, yyvsp[-2].s.value, NULL, yyvsp[0].expr); ; - break;} -case 136: -#line 536 "cmdgram.y" -{ yyval.expr = AssignExprNode::alloc( yyvsp[-5].s.lineNumber, yyvsp[-5].s.value, yyvsp[-3].expr, yyvsp[0].expr); ; - break;} -case 137: -#line 538 "cmdgram.y" -{ yyval.expr = AssignOpExprNode::alloc( yyvsp[-1].s.lineNumber, yyvsp[-1].s.value, NULL, yyvsp[0].asn.expr, yyvsp[0].asn.token); ; - break;} -case 138: -#line 540 "cmdgram.y" -{ yyval.expr = AssignOpExprNode::alloc( yyvsp[-4].s.lineNumber, yyvsp[-4].s.value, yyvsp[-2].expr, yyvsp[0].asn.expr, yyvsp[0].asn.token); ; - break;} -case 139: -#line 542 "cmdgram.y" -{ yyval.expr = SlotAssignOpNode::alloc( yyvsp[-1].slot.lineNumber, yyvsp[-1].slot.object, yyvsp[-1].slot.slotName, yyvsp[-1].slot.array, yyvsp[0].asn.token, yyvsp[0].asn.expr); ; - break;} -case 140: -#line 544 "cmdgram.y" -{ yyval.expr = SlotAssignNode::alloc( yyvsp[-2].slot.lineNumber, yyvsp[-2].slot.object, yyvsp[-2].slot.array, yyvsp[-2].slot.slotName, yyvsp[0].expr); ; - break;} -case 141: -#line 546 "cmdgram.y" -{ yyval.expr = SlotAssignNode::alloc( yyvsp[-4].slot.lineNumber, yyvsp[-4].slot.object, yyvsp[-4].slot.array, yyvsp[-4].slot.slotName, yyvsp[-1].expr); ; - break;} -case 142: -#line 551 "cmdgram.y" -{ yyval.expr = FuncCallExprNode::alloc( yyvsp[-3].s.lineNumber, yyvsp[-3].s.value, NULL, yyvsp[-1].expr, false); ; - break;} -case 143: -#line 553 "cmdgram.y" -{ yyval.expr = FuncCallExprNode::alloc( yyvsp[-5].s.lineNumber, yyvsp[-3].s.value, yyvsp[-5].s.value, yyvsp[-1].expr, false); ; - break;} -case 144: -#line 555 "cmdgram.y" -{ yyvsp[-5].expr->append(yyvsp[-1].expr); yyval.expr = FuncCallExprNode::alloc( yyvsp[-5].expr->dbgLineNumber, yyvsp[-3].s.value, NULL, yyvsp[-5].expr, true); ; - break;} -case 145: -#line 565 "cmdgram.y" -{ yyval.expr = AssertCallExprNode::alloc( yyvsp[-3].i.lineNumber, yyvsp[-1].expr, NULL ); ; - break;} -case 146: -#line 567 "cmdgram.y" -{ yyval.expr = AssertCallExprNode::alloc( yyvsp[-5].i.lineNumber, yyvsp[-3].expr, yyvsp[-1].str.value ); ; - break;} -case 147: -#line 572 "cmdgram.y" -{ yyval.expr = NULL; ; - break;} -case 148: -#line 574 "cmdgram.y" -{ yyval.expr = yyvsp[0].expr; ; - break;} -case 149: -#line 579 "cmdgram.y" -{ yyval.expr = yyvsp[0].expr; ; - break;} -case 150: -#line 581 "cmdgram.y" -{ (yyvsp[-2].expr)->append(yyvsp[0].expr); yyval.expr = yyvsp[-2].expr; ; - break;} -case 151: -#line 586 "cmdgram.y" -{ yyval.slist = NULL; ; - break;} -case 152: -#line 588 "cmdgram.y" -{ yyval.slist = yyvsp[0].slist; ; - break;} -case 153: -#line 593 "cmdgram.y" -{ yyval.slist = yyvsp[0].slist; ; - break;} -case 154: -#line 595 "cmdgram.y" -{ yyvsp[-1].slist->append(yyvsp[0].slist); yyval.slist = yyvsp[-1].slist; ; - break;} -case 155: -#line 600 "cmdgram.y" -{ yyval.slist = SlotAssignNode::alloc( yyvsp[-3].s.lineNumber, NULL, NULL, yyvsp[-3].s.value, yyvsp[-1].expr); ; - break;} -case 156: -#line 602 "cmdgram.y" -{ yyval.slist = SlotAssignNode::alloc( yyvsp[-4].i.lineNumber, NULL, NULL, yyvsp[-3].s.value, yyvsp[-1].expr, yyvsp[-4].i.value); ; - break;} -case 157: -#line 604 "cmdgram.y" -{ yyval.slist = SlotAssignNode::alloc( yyvsp[-3].i.lineNumber, NULL, NULL, StringTable->insert("datablock"), yyvsp[-1].expr); ; - break;} -case 158: -#line 606 "cmdgram.y" -{ yyval.slist = SlotAssignNode::alloc( yyvsp[-6].s.lineNumber, NULL, yyvsp[-4].expr, yyvsp[-6].s.value, yyvsp[-1].expr); ; - break;} -case 159: -#line 608 "cmdgram.y" -{ yyval.slist = SlotAssignNode::alloc( yyvsp[-7].i.lineNumber, NULL, yyvsp[-4].expr, yyvsp[-6].s.value, yyvsp[-1].expr, yyvsp[-7].i.value); ; - break;} -case 160: -#line 613 "cmdgram.y" -{ yyval.expr = yyvsp[0].expr; ; - break;} -case 161: -#line 615 "cmdgram.y" -{ yyval.expr = CommaCatExprNode::alloc( yyvsp[-2].expr->dbgLineNumber, yyvsp[-2].expr, yyvsp[0].expr); ; - break;} -} - /* the action file gets copied in in place of this dollarsign */ -#line 487 "bison.simple" - - yyvsp -= yylen; - yyssp -= yylen; -#ifdef YYLSP_NEEDED - yylsp -= yylen; -#endif - -#if YYDEBUG != 0 - if (yydebug) - { - short *ssp1 = yyss - 1; - fprintf (stderr, "state stack now"); - while (ssp1 != yyssp) - fprintf (stderr, " %d", *++ssp1); - fprintf (stderr, "\n"); - } -#endif + YYPOPSTACK (yylen); + yylen = 0; *++yyvsp = yyval; -#ifdef YYLSP_NEEDED - yylsp++; - if (yylen == 0) - { - yylsp->first_line = yylloc.first_line; - yylsp->first_column = yylloc.first_column; - yylsp->last_line = (yylsp-1)->last_line; - yylsp->last_column = (yylsp-1)->last_column; - yylsp->text = 0; - } - else - { - yylsp->last_line = (yylsp+yylen-1)->last_line; - yylsp->last_column = (yylsp+yylen-1)->last_column; - } -#endif - - /* Now "shift" the result of the reduction. - Determine what state that goes to, - based on the state we popped back to - and the rule number reduced by. */ - - yyn = yyr1[yyn]; - - yystate = yypgoto[yyn - YYNTBASE] + *yyssp; - if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp) - yystate = yytable[yystate]; - else - yystate = yydefgoto[yyn - YYNTBASE]; + /* Now 'shift' the result of the reduction. Determine what state + that goes to, based on the state we popped back to and the rule + number reduced by. */ + { + const int yylhs = yyr1[yyn] - YYNTOKENS; + const int yyi = yypgoto[yylhs] + *yyssp; + yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp + ? yytable[yyi] + : yydefgoto[yylhs]); + } goto yynewstate; -yyerrlab: /* here on detecting error */ - if (! yyerrstatus) - /* If not already recovering from an error, report this error. */ +/*--------------------------------------. +| 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 ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar); + /* If not already recovering from an error, report this error. */ + if (!yyerrstatus) { ++yynerrs; - -#ifdef YYERROR_VERBOSE - yyn = yypact[yystate]; - - if (yyn > YYFLAG && yyn < YYLAST) - { - int size = 0; - char *msg; - int x, count; - - count = 0; - /* Start X at -yyn if nec to avoid negative indexes in yycheck. */ - for (x = (yyn < 0 ? -yyn : 0); - x < (sizeof(yytname) / sizeof(char *)); x++) - if (yycheck[x + yyn] == x) - size += strlen(yytname[x]) + 15, count++; - msg = (char *) malloc(size + 15); - if (msg != 0) - { - strcpy(msg, "parse error"); - - if (count < 5) - { - count = 0; - for (x = (yyn < 0 ? -yyn : 0); - x < (sizeof(yytname) / sizeof(char *)); x++) - if (yycheck[x + yyn] == x) - { - strcat(msg, count == 0 ? ", expecting `" : " or `"); - strcat(msg, yytname[x]); - strcat(msg, "'"); - count++; - } - } - yyerror(msg); - free(msg); - } - else - yyerror ("parse error; also virtual memory exceeded"); - } - else -#endif /* YYERROR_VERBOSE */ - yyerror("parse error"); + yyerror (YY_("syntax error")); } - goto yyerrlab1; -yyerrlab1: /* here on error raised explicitly by an action */ - if (yyerrstatus == 3) { - /* if just tried and failed to reuse lookahead token after an error, discard it. */ + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ - /* return failure if at end of input */ - if (yychar == YYEOF) - YYABORT; - -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]); -#endif - - yychar = YYEMPTY; + if (yychar <= YYEOF) + { + /* Return failure if at end of input. */ + if (yychar == YYEOF) + YYABORT; + } + else + { + yydestruct ("Error: discarding", + yytoken, &yylval); + yychar = YYEMPTY; + } } - /* Else will try to reuse lookahead token - after shifting the error token. */ + /* Else will try to reuse lookahead token after shifting the error + token. */ + goto yyerrlab1; - yyerrstatus = 3; /* Each real token shifted decrements this */ - goto yyerrhandle; +/*---------------------------------------------------. +| yyerrorlab -- error raised explicitly by YYERROR. | +`---------------------------------------------------*/ +yyerrorlab: + /* Pacify compilers when the user code never invokes YYERROR and the + label yyerrorlab therefore never appears in user code. */ + if (0) + YYERROR; + ++yynerrs; -yyerrdefault: /* current state does not do anything special for the error token. */ + /* Do not reclaim the symbols of the rule whose action triggered + this YYERROR. */ + YYPOPSTACK (yylen); + yylen = 0; + YY_STACK_PRINT (yyss, yyssp); + yystate = *yyssp; + goto yyerrlab1; -#if 0 - /* This is wrong; only states that explicitly want error tokens - should shift them. */ - yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/ - if (yyn) goto yydefault; -#endif -yyerrpop: /* pop the current state because it cannot handle the error token */ +/*-------------------------------------------------------------. +| yyerrlab1 -- common code for both syntax error and YYERROR. | +`-------------------------------------------------------------*/ +yyerrlab1: + yyerrstatus = 3; /* Each real token shifted decrements this. */ - if (yyssp == yyss) YYABORT; - yyvsp--; - yystate = *--yyssp; -#ifdef YYLSP_NEEDED - yylsp--; -#endif - -#if YYDEBUG != 0 - if (yydebug) + /* Pop stack until we find a state that shifts the error token. */ + for (;;) { - short *ssp1 = yyss - 1; - fprintf (stderr, "Error: state stack now"); - while (ssp1 != yyssp) - fprintf (stderr, " %d", *++ssp1); - fprintf (stderr, "\n"); + yyn = yypact[yystate]; + if (!yypact_value_is_default (yyn)) + { + yyn += YYSYMBOL_YYerror; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } + + /* Pop the current state because it cannot handle the error token. */ + if (yyssp == yyss) + YYABORT; + + + yydestruct ("Error: popping", + YY_ACCESSING_SYMBOL (yystate), yyvsp); + YYPOPSTACK (1); + yystate = *yyssp; + YY_STACK_PRINT (yyss, yyssp); } -#endif - -yyerrhandle: - - yyn = yypact[yystate]; - if (yyn == YYFLAG) - goto yyerrdefault; - - yyn += YYTERROR; - if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR) - goto yyerrdefault; - - yyn = yytable[yyn]; - if (yyn < 0) - { - if (yyn == YYFLAG) - goto yyerrpop; - yyn = -yyn; - goto yyreduce; - } - else if (yyn == 0) - goto yyerrpop; - - if (yyn == YYFINAL) - YYACCEPT; - -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Shifting error token, "); -#endif + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; -#ifdef YYLSP_NEEDED - *++yylsp = yylloc; -#endif + YY_IGNORE_MAYBE_UNINITIALIZED_END + + + /* Shift the error token. */ + YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp); yystate = yyn; goto yynewstate; + + +/*-------------------------------------. +| yyacceptlab -- YYACCEPT comes here. | +`-------------------------------------*/ +yyacceptlab: + yyresult = 0; + goto yyreturnlab; + + +/*-----------------------------------. +| yyabortlab -- YYABORT comes here. | +`-----------------------------------*/ +yyabortlab: + yyresult = 1; + goto yyreturnlab; + + +/*-----------------------------------------------------------. +| yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here. | +`-----------------------------------------------------------*/ +yyexhaustedlab: + yyerror (YY_("memory exhausted")); + yyresult = 2; + goto yyreturnlab; + + +/*----------------------------------------------------------. +| yyreturnlab -- parsing is finished, clean up and return. | +`----------------------------------------------------------*/ +yyreturnlab: + if (yychar != YYEMPTY) + { + /* 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 whose action triggered + this YYABORT or YYACCEPT. */ + YYPOPSTACK (yylen); + YY_STACK_PRINT (yyss, yyssp); + while (yyssp != yyss) + { + yydestruct ("Cleanup: popping", + YY_ACCESSING_SYMBOL (+*yyssp), yyvsp); + YYPOPSTACK (1); + } +#ifndef yyoverflow + if (yyss != yyssa) + YYSTACK_FREE (yyss); +#endif + + return yyresult; } -#line 617 "cmdgram.y" + +#line 617 "CMDgram.y" + + diff --git a/Engine/source/console/torquescript/cmdgram.h b/Engine/source/console/torquescript/cmdgram.h deleted file mode 100644 index 5316b2fda..000000000 --- a/Engine/source/console/torquescript/cmdgram.h +++ /dev/null @@ -1,97 +0,0 @@ -#ifndef _CMDGRAM_H_ -#define _CMDGRAM_H_ - -typedef union { - Token< char > c; - Token< int > i; - Token< const char* > s; - Token< char* > str; - Token< double > f; - StmtNode* stmt; - ExprNode* expr; - SlotAssignNode* slist; - VarNode* var; - SlotDecl slot; - InternalSlotDecl intslot; - ObjectBlockDecl odcl; - ObjectDeclNode* od; - AssignDecl asn; - IfStmtNode* ifnode; -} YYSTYPE; -#define rwDEFINE 258 -#define rwENDDEF 259 -#define rwDECLARE 260 -#define rwDECLARESINGLETON 261 -#define rwBREAK 262 -#define rwELSE 263 -#define rwCONTINUE 264 -#define rwGLOBAL 265 -#define rwIF 266 -#define rwNIL 267 -#define rwRETURN 268 -#define rwWHILE 269 -#define rwDO 270 -#define rwENDIF 271 -#define rwENDWHILE 272 -#define rwENDFOR 273 -#define rwDEFAULT 274 -#define rwFOR 275 -#define rwFOREACH 276 -#define rwFOREACHSTR 277 -#define rwIN 278 -#define rwDATABLOCK 279 -#define rwSWITCH 280 -#define rwCASE 281 -#define rwSWITCHSTR 282 -#define rwCASEOR 283 -#define rwPACKAGE 284 -#define rwNAMESPACE 285 -#define rwCLASS 286 -#define rwASSERT 287 -#define ILLEGAL_TOKEN 288 -#define CHRCONST 289 -#define INTCONST 290 -#define TTAG 291 -#define VAR 292 -#define IDENT 293 -#define TYPEIDENT 294 -#define DOCBLOCK 295 -#define STRATOM 296 -#define TAGATOM 297 -#define FLTCONST 298 -#define opINTNAME 299 -#define opINTNAMER 300 -#define opMINUSMINUS 301 -#define opPLUSPLUS 302 -#define STMT_SEP 303 -#define opSHL 304 -#define opSHR 305 -#define opPLASN 306 -#define opMIASN 307 -#define opMLASN 308 -#define opDVASN 309 -#define opMODASN 310 -#define opANDASN 311 -#define opXORASN 312 -#define opORASN 313 -#define opSLASN 314 -#define opSRASN 315 -#define opCAT 316 -#define opEQ 317 -#define opNE 318 -#define opGE 319 -#define opLE 320 -#define opAND 321 -#define opOR 322 -#define opSTREQ 323 -#define opCOLONCOLON 324 -#define opMDASN 325 -#define opNDASN 326 -#define opNTASN 327 -#define opSTRNE 328 -#define UNARY 329 - - -extern YYSTYPE CMDlval; - -#endif diff --git a/Engine/source/console/torquescript/generateCompiler.bat b/Engine/source/console/torquescript/generateCompiler.bat new file mode 100644 index 000000000..08ae5f564 --- /dev/null +++ b/Engine/source/console/torquescript/generateCompiler.bat @@ -0,0 +1,3 @@ + +call bison.bat CMD CMDgram.c CMDgram.y . CMDgram.cpp +..\..\..\bin\bison-flex\win_flex -PCMD -oCMDscan.cpp CMDscan.l