Logicalshift / TameParse

LALR parser with context-sensitive extensions
MIT License
21 stars 2 forks source link

Failed to build with gcc9 #2

Open mingodad opened 1 year ago

mingodad commented 1 year ago

When trying to build this project on Ubuntu-18.04 with gcc9 I was getting errors due to non matching parameter/return value, with the patch shown bellow I was able to build it:

diff --git a/TameParse/Lr/parser.h b/TameParse/Lr/parser.h
index 89b4151..1cf83f3 100644
--- a/TameParse/Lr/parser.h
+++ b/TameParse/Lr/parser.h
@@ -165,7 +165,7 @@ namespace lr {
             // (For hard-coded parsers, the tables often aren't, so there's no need to copy)
             if (copyFrom.m_OwnsTables) {
                 m_OwnsTables    = true;
-                m_ParserTables  = new parser_tables(copyFrom.m_ParserTables);
+                m_ParserTables  = new parser_tables(*copyFrom.m_ParserTables);
             } else {
                 m_OwnsTables    = false;
                 m_ParserTables  = copyFrom.m_ParserTables;
@@ -728,7 +728,7 @@ namespace lr {
         }

         /// \brief Retrieves the tables for this parser
-        inline const parser_tables& get_tables() const { return m_ParserTables; }
+        inline const parser_tables& get_tables() const { return *m_ParserTables; }
     };

     ///
Logicalshift commented 1 year ago

Sorry for the slow reply, I've been spending the last month recovering from an annoyingly persistent cold.

Oddly this seems to still be accepted with clang which is what I've been able to test with this evening, but I've made these changes as they don't produce any issues (also made some very minimal updates to the very old autoconf scripts).

mingodad commented 1 year ago

Thank you for reply and for your great work !

I've been playing with tameparse and got a bit confused when trying the following:

../parsetool/tameparse --enable-lr1-resolver --run-tests C99.tp
TameParse 0.1.0
    C99: 41/41 passed
echo 'int x = 0;' | ../parsetool/tameparse --enable-lr1-resolver --test C99.tp
TameParse 0.1.0
C99.tp::: error: Could not determine a start symbol for the language (use the start-symbol option to specify one manually)
echo 'int x = 0;' | ../parsetool/tameparse --enable-lr1-resolver --test -S '<Parser-Language>' C99.tp
TameParse 0.1.0
C99.tp::: error: Start symbol is not defined: <Parser-Language>
C99.tp::: error: No start symbols are defined
echo 'int x = 0;' | ../parsetool/tameparse --enable-lr1-resolver --test -S 'Parser-Language' C99.tp
TameParse 0.1.0
C99.tp::: error: Start symbol is not defined: Parser-Language
C99.tp::: error: No start symbols are defined
echo 'int x = 0;' | ../parsetool/tameparse --enable-lr1-resolver --test -S '<TopLevel-Block>' C99.tp
TameParse 0.1.0
C99.tp::: error: Start symbol is not defined: <TopLevel-Block>
C99.tp::: error: No start symbols are defined

How is this supposed to work ?

I'm looking to create a kind of online playground like:

Because it seems that this project compiled to WASM could be used for it (although it's a bit slower to produce an output, maybe due to processing the grammar).

mingodad commented 1 year ago

Compiling to generate profiling info I'm getting this:

../tameparse-am-prof  --enable-lr1-resolver --run-tests C99.tp
gprof tameparse-am-prof Examples/gmon.out
head -c 8192 tameparse-am.prof.txt 
Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls   s/call   s/call  name    
  3.69      0.57     0.57 320132289     0.00     0.00  contextfree::rule::identifier(contextfree::grammar const&) const
  3.69      1.14     0.57 38422526     0.00     0.00  contextfree::item_set::item_set(contextfree::item_set const&)
  3.60      1.70     0.56 142889547     0.00     0.00  lr::lr0_item::operator<(lr::lr0_item const&) const
  2.85      2.14     0.44 139117820     0.00     0.00  lr::lr1_item_set::kernel_only_comparison::operator()(util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> > const&, util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> > const&) const
  2.56      2.53     0.40 346951657     0.00     0.00  util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> >::operator->() const
  2.14      2.86     0.33 345318484     0.00     0.00  lr::lr0_item::rule() const
  2.11      3.19     0.33 139117820     0.00     0.00  std::_Rb_tree<util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> >, util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> >, std::_Identity<util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> > >, lr::lr1_item_set::kernel_only_comparison, std::allocator<util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> > > >::_S_key(std::_Rb_tree_node<util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> > > const*)
  1.81      3.47     0.28 65785274     0.00     0.00  contextfree::item::compare(contextfree::item const&, contextfree::item const&)
  1.81      3.75     0.28 15856488     0.00     0.00  contextfree::item_set::merge(contextfree::item_set const&)
  1.78      4.02     0.28 327243284     0.00     0.00  util::container<contextfree::rule, util::simple_constructor<contextfree::rule> >::operator->() const
  1.75      4.29     0.27 295929651     0.00     0.00  lr::lr1_item::get_lr0_item() const
  1.69      4.55     0.26 191955725     0.00     0.00  std::_Rb_tree_node<util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> > >::_M_valptr() const
  1.69      4.81     0.26 17664545     0.00     0.00  std::_Rb_tree<util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> >, util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> >, std::_Identity<util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> > >, lr::lr1_item_set::kernel_only_comparison, std::allocator<util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> > > >::_M_lower_bound(std::_Rb_tree_node<util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> > >*, std::_Rb_tree_node_base*, util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> > const&)
  1.62      5.06     0.25 17664545     0.00     0.00  lr::lr1_item_set::insert(util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> >)
  1.56      5.30     0.24  5264517     0.00     0.00  contextfree::item_set::count_size()
  1.13      5.48     0.18 296988405     0.00     0.00  util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> >::operator*() const
  1.10      5.65     0.17 191955725     0.00     0.00  __gnu_cxx::__aligned_membuf<util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> > >::_M_ptr() const
  1.10      5.82     0.17 191955725     0.00     0.00  __gnu_cxx::__aligned_membuf<util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> > >::_M_addr() const
  1.10      5.99     0.17 77265858     0.00     0.00  contextfree::item::compare(contextfree::item const*, contextfree::item const*)
  1.10      6.16     0.17 77265858     0.00     0.00  util::container<contextfree::item, contextfree::empty_item_constructor>::operator<(util::container<contextfree::item, contextfree::empty_item_constructor> const&) const
  0.91      6.30     0.14 57531975     0.00     0.00  std::less<util::container<contextfree::item, contextfree::empty_item_constructor> >::operator()(util::container<contextfree::item, contextfree::empty_item_constructor> const&, util::container<contextfree::item, contextfree::empty_item_constructor> const&) const
  0.87      6.43     0.14 150584202     0.00     0.00  std::_Identity<util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> > >::operator()(util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> > const&) const
  0.84      6.56     0.13 19264856     0.00     0.00  std::_Rb_tree<util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> >, util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> >, std::_Identity<util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> > >, lr::lr1_item_set::kernel_only_comparison, std::allocator<util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> > > >::end() const
  0.84      6.69     0.13      327     0.00     0.00  std::map<util::container<contextfree::rule, util::simple_constructor<contextfree::rule> >, int, std::less<util::container<contextfree::rule, util::simple_constructor<contextfree::rule> > >, std::allocator<std::pair<util::container<contextfree::rule, util::simple_constructor<contextfree::rule> > const, int> > >::size() const
  0.78      6.81     0.12 52836106     0.00     0.00  std::_Rb_tree_const_iterator<util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> > >::operator*() const
  0.78      6.93     0.12  3990908     0.00     0.00  std::_Rb_tree<util::container<contextfree::item, contextfree::empty_item_constructor>, std::pair<util::container<contextfree::item, contextfree::empty_item_constructor> const, int>, std::_Select1st<std::pair<util::container<contextfree::item, contextfree::empty_item_constructor> const, int> >, std::less<util::container<contextfree::item, contextfree::empty_item_constructor> >, std::allocator<std::pair<util::container<contextfree::item, contextfree::empty_item_constructor> const, int> > >::_M_lower_bound(std::_Rb_tree_node<std::pair<util::container<contextfree::item, contextfree::empty_item_constructor> const, int> >*, std::_Rb_tree_node_base*, util::container<contextfree::item, contextfree::empty_item_constructor> const&)
  0.75      7.05     0.12  4986998     0.00     0.00  std::_Rb_tree<util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> >, util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> >, std::_Identity<util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> > >, lr::lr1_item_set::kernel_only_comparison, std::allocator<util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> > > >::_M_get_insert_unique_pos(util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> > const&)
  0.71      7.16     0.11  2919397     0.00     0.00  contextfree::nonterminal::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const
  0.71      7.27     0.11 21821906     0.00     0.00  lr::lr0_item::lr0_item(contextfree::grammar const*, util::container<contextfree::rule, util::simple_constructor<contextfree::rule> > const&, int)
  0.65      7.37     0.10 70785644     0.00     0.00  std::_Rb_tree<util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> >, util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> >, std::_Identity<util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> > >, lr::lr1_item_set::kernel_only_comparison, std::allocator<util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> > > >::_S_right(std::_Rb_tree_node_base*)
  0.65      7.47     0.10  4857742     0.00     0.00  contextfree::ebnf::operator<(contextfree::item const&) const
  0.62      7.56     0.10 17398086     0.00     0.00  util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> >::operator*()
  0.58      7.65     0.09 73188989     0.00     0.00  contextfree::terminal::type() const
  0.58      7.74     0.09 59109005     0.00     0.00  std::_Rb_tree<util::container<lr::lr1_item, util::simple_constructor<lr::lr1_item> >, util::container<lr::lr1_item, util::simple

It seems a lot of calls 320,132,289 to contextfree::rule::identifier(contextfree::grammar const&) const

mingodad commented 1 year ago

I made a Lua script to create an amalgamation of this project:

local re2c_files = [==[
config.h
TameParse/version.cpp
TameParse/tameparse_language.cpp
TameParse/Compiler/compilation_stage.cpp
TameParse/Compiler/conflict_attribute_rewriter.cpp
TameParse/Compiler/console.cpp
TameParse/Compiler/error.cpp
TameParse/Compiler/import_stage.cpp
TameParse/Compiler/language_builder_stage.cpp
TameParse/Compiler/language_stage.cpp
TameParse/Compiler/lexer_stage.cpp
TameParse/Compiler/lr_parser_stage.cpp
TameParse/Compiler/output_stage.cpp
TameParse/Compiler/parser_stage.cpp
TameParse/Compiler/precedence_block_rewriter.cpp
TameParse/Compiler/std_console.cpp
TameParse/Compiler/test_stage.cpp
TameParse/Compiler/OutputStages/cplusplus.cpp
TameParse/Compiler/Data/lexer_data.cpp
TameParse/Compiler/Data/lexer_item.cpp
TameParse/Compiler/Data/rule_item_data.cpp
TameParse/ContextFree/ebnf_items.cpp
TameParse/ContextFree/grammar.cpp
TameParse/ContextFree/guard.cpp
TameParse/ContextFree/item.cpp
TameParse/ContextFree/item_set.cpp
TameParse/ContextFree/rule.cpp
TameParse/ContextFree/standard_items.cpp
TameParse/ContextFree/terminal_dictionary.cpp
TameParse/Dfa/accept_action.cpp
TameParse/Dfa/basic_lexer.cpp
TameParse/Dfa/character_lexer.cpp
TameParse/Dfa/epsilon.cpp
TameParse/Dfa/hard_coded_symbol_table.cpp
TameParse/Dfa/lexeme.cpp
TameParse/Dfa/lexer.cpp
TameParse/Dfa/ndfa.cpp
TameParse/Dfa/ndfa_regex.cpp
TameParse/Dfa/ndfa_transformations.cpp
TameParse/Dfa/position.cpp
TameParse/Dfa/range.cpp
TameParse/Dfa/remapped_symbol_map.cpp
TameParse/Dfa/regex_error.cpp
TameParse/Dfa/state.cpp
TameParse/Dfa/state_machine.cpp
TameParse/Dfa/symbol_map.cpp
TameParse/Dfa/symbol_set.cpp
TameParse/Dfa/symbol_table.cpp
TameParse/Dfa/symbol_translator.cpp
TameParse/Dfa/transition.cpp
TameParse/Language/block.cpp
TameParse/Language/definition_file.cpp
TameParse/Language/ebnf_item.cpp
TameParse/Language/ebnf_item_attributes.cpp
TameParse/Language/formatter.cpp
TameParse/Language/grammar_block.cpp
TameParse/Language/import_block.cpp
TameParse/Language/language_block.cpp
TameParse/Language/language_parser.cpp
TameParse/Language/language_unit.cpp
TameParse/Language/lexeme_definition.cpp
TameParse/Language/lexer_block.cpp
TameParse/Language/nonterminal_definition.cpp
TameParse/Language/parser_block.cpp
TameParse/Language/precedence_block.cpp
TameParse/Language/process.cpp
TameParse/Language/production_definition.cpp
TameParse/Language/test_block.cpp
TameParse/Language/test_definition.cpp
TameParse/Language/toplevel_block.cpp
TameParse/Lr/action_rewriter.cpp
TameParse/Lr/ast_parser.cpp
TameParse/Lr/conflict.cpp
TameParse/Lr/ignored_symbols.cpp
TameParse/Lr/lalr_builder.cpp
TameParse/Lr/lalr_machine.cpp
TameParse/Lr/lalr_state.cpp
TameParse/Lr/lr1_item_set.cpp
TameParse/Lr/lr_action.cpp
TameParse/Lr/lr_item.cpp
TameParse/Lr/lr_state.cpp
TameParse/Lr/lr1_rewriter.cpp
TameParse/Lr/parser.cpp
TameParse/Lr/parser_stack.cpp
TameParse/Lr/parser_tables.cpp
TameParse/Lr/precedence_rewriter.cpp
TameParse/Lr/weak_symbols.cpp
TameParse/Util/astnode.cpp
TameParse/Util/container.cpp
TameParse/Util/stringreader.cpp
TameParse/Util/syntax_ptr.cpp
TameParse/Util/unicode.cpp
TameParse/Util/utf8reader.cpp
]==];

local folder_list = [==[
TameParse/
TameParse/Compiler/
TameParse/Language/
TameParse/ContextFree/
TameParse/Dfa/
TameParse/Lr/
TameParse/Util/
parsetool/
]==];

local included = {}
local inc_sys = {}
local inc_sys_count = 0
local out = io.stdout

local function openInclude(prefix, filename)
    --print("//", prefix, filename)
    local inp = io.open(prefix .. filename, "r")
    if inp ~= null then return inp end
    for folder in folder_list:gmatch('([^\n]+)') do
        local fname = prefix .. folder .. filename
        local inp = io.open(fname, "r")
        --print(inp, fname)
        if inp ~= null then return inp end
    end
    return null
end

local ifdefListSI = {
    ["TameParse/ContextFree/grammar.cpp"] = "xxxx",
}

function CopyWithInline(prefix, filename)
    if included[filename] then return end
    included[filename] = true
    print('//--Start of', filename);
    local ifdefSINeeded = ifdefListSI[filename];
    if ifdefSINeeded ~= null then
        out:write("#define an_empty_item grm_an_empty_item\n")
        out:write("#define an_empty_item_c grm_an_empty_item_c\n")
    end
    --if(filename:match("luac?.c"))
    local inp = assert(openInclude(prefix, filename))
    for line in inp:lines() do
        if line:match('static const empty_item the_empty_item;') then
            out:write("#ifndef THE_EMPTY_ITEM_DEFINED\n")
            out:write("#define THE_EMPTY_ITEM_DEFINED\n")
            out:write("" .. line .. "\n")
            out:write("#endif\n")
        elseif line:match('static const empty_item an_empty_item;') then
            out:write("#ifndef AN_EMPTY_ITEM_DEFINED\n")
            out:write("#define AN_EMPTY_ITEM_DEFINED\n")
            out:write(line .. "\n")
            out:write("#endif\n")
        elseif line:match('static item_container an_empty_item_c((item*)&an_empty_item, false);') then
            out:write("#ifndef AN_EMPTY_ITEM_C_DEFINED\n")
            out:write("#define AN_EMPTY_ITEM_C_DEFINED\n")
            out:write(line .. "\n")
            out:write("#endif\n")
        else
            local inc = line:match('#include%s+(["<].-)[">]')
            if inc  and not line:match("#include \"boost/") then
                out:write("//" .. line .. "\n")
                if inc:sub(1,1) == '"' then
                    CopyWithInline(prefix, inc:sub(2))
                else
                    local fn = inc:sub(2)
                    if inc_sys[fn] == null then
                        inc_sys_count = inc_sys_count +1
                        inc_sys[fn] = inc_sys_count
                    end
                end
            else
                out:write(line .. "\n")
            end
        end
    end
    if ifdefSINeeded ~= null then
        out:write("#undef an_empty_item\n")
        out:write("#undef an_empty_item_c\n")
    end
    print('//--End of', filename);
end

print([==[
#ifdef TAMEPARSE_WITH_COSMOPOLITAN
#include "cosmopolitan.h"
//STATIC_STACK_SIZE(0x80000);
#else
//g++  -DHAVE_CONFIG_H -c tameparse-am.cpp
//g++ -DHAVE_CONFIG_H -DMAKE_TAMEPARSE_CMD  tameparse-am.cpp -o tameparse-am -L/usr/lib64 -lboost_system -lboost_filesystem -lboost_program_options
#include <string> //1
#include <iostream> //7
#include <cstdlib> //2
#include <queue> //16
#include <set> //5
#include <sstream> //11
#include <stack> //6
#include <algorithm> //8
#include <memory> //17
#include <climits> //12
#include <fstream> //14
#include <typeinfo> //10
#include <map> //3
#include <cstring> //9
#include <locale> //13
#include <vector> //4
#include <time.h> //15
#endif //TAMEPARSE_WITH_COSMOPOLITAN

]==])

local prefix = '/home/mingo/dev/c/A_grammars/TameParse/';
for filename in re2c_files:gmatch('([^\n]+)') do
    CopyWithInline(prefix, filename);
end
print('#ifdef MAKE_TAMEPARSE_CMD');
CopyWithInline(prefix, "parsetool/boost_console.cpp");
CopyWithInline(prefix, "parsetool/main.cpp");
print('#endif //MAKE_TAMEPARSE_CMD');

print('/*');
for k, v in pairs(inc_sys) do print("#include <" .. k .. "> //" .. v ) end
print('*/');
mingodad commented 1 year ago

For the amalgamation produced by the script shown above to compile/build I needed to make this small changes to this project:

diff --git a/TameParse/ContextFree/item.cpp b/TameParse/ContextFree/item.cpp
index d5de756..59ab467 100644
--- a/TameParse/ContextFree/item.cpp
+++ b/TameParse/ContextFree/item.cpp
@@ -104,7 +104,7 @@ bool item::compare(const item& a, const item& b) {
 }

 static const empty_item the_empty_item;
-static item_container   an_empty_item_c((item*) &the_empty_item, false);
+static item_container the_empty_item_c((item*) &the_empty_item, false);

 /// \brief Fills in the items that follow this one
 void item::fill_follow(item_set& follow, const lr::lr1_item& item, const grammar& gram) const {
@@ -123,9 +123,9 @@ void item::fill_follow(item_set& follow, const lr::lr1_item& item, const grammar

         // Add further following items if the follow set can be empty, until we reach the end
         ++followOffset;
-        while (followOffset < numItems && follow.contains(an_empty_item_c)) {
+        while (followOffset < numItems && follow.contains(the_empty_item_c)) {
             // Remove the empty item
-            follow.erase(an_empty_item_c);
+            follow.erase(the_empty_item_c);

             // Add the items from the next item in the rule
             const item_set& newItems = gram.first(rule.items()[followOffset]);
@@ -137,8 +137,8 @@ void item::fill_follow(item_set& follow, const lr::lr1_item& item, const grammar

         // If the empty set is still included, remove it and add the item lookahead
         // (Note that if the loop above terminated early, then the empty set can't be in the follow set at this point)
-        if (followOffset >= numItems && follow.contains(an_empty_item_c)) {
-            follow.erase(an_empty_item_c);
+        if (followOffset >= numItems && follow.contains(the_empty_item_c)) {
+            follow.erase(the_empty_item_c);
             follow.merge(item.lookahead());
         }
     }    
diff --git a/TameParse/Lr/lr_action.cpp b/TameParse/Lr/lr_action.cpp
index e94e9b1..4788aec 100644
--- a/TameParse/Lr/lr_action.cpp
+++ b/TameParse/Lr/lr_action.cpp
@@ -30,7 +30,7 @@
 using namespace contextfree;
 using namespace lr;

-static empty_item an_empty_item;
+static const empty_item an_empty_item;

 /// \brief Empty rule
 static rule an_empty_rule(an_empty_item);
mingodad commented 1 year ago

Compiling this project with -O2 -g and running under valgrind gives thie output shown bellow:

valgrind ../tameparse-am  --enable-lr1-resolver --run-tests C99.tp

==19990== Memcheck, a memory error detector
==19990== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==19990== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info
==19990== Command: ../tameparse-am --enable-lr1-resolver --run-tests C99.tp
==19990== 
TameParse 0.1.0
==19990== Conditional jump or move depends on uninitialised value(s)
==19990==    at 0x16C1E6: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33640)
==19990==    by 0x17D385: lr::lalr_builder::create_closure(std::set<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> >, std::less<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> > >, std::allocator<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> > > >&, lr::lalr_state const&, contextfree::grammar const*) (tameparse-am.cpp:42158)
==19990==    by 0x186D40: lr::lalr_builder::complete_parser() (tameparse-am.cpp:42194)
==19990==    by 0x18F6E2: compiler::lr_parser_stage::compile() (tameparse-am.cpp:27826)
==19990==    by 0x191E27: compiler::test_stage::get_parser(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, dfa::position const&) (tameparse-am.cpp:29850)
==19990==    by 0x1967D6: compiler::test_stage::compile() (tameparse-am.cpp:29926)
==19990==    by 0x12DA11: main (tameparse-am.cpp:46778)
==19990== 
==19990== Conditional jump or move depends on uninitialised value(s)
==19990==    at 0x16C1E6: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33640)
==19990==    by 0x16C058: contextfree::nonterminal::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:34327)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x17D385: lr::lalr_builder::create_closure(std::set<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> >, std::less<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> > >, std::allocator<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> > > >&, lr::lalr_state const&, contextfree::grammar const*) (tameparse-am.cpp:42158)
==19990==    by 0x186D40: lr::lalr_builder::complete_parser() (tameparse-am.cpp:42194)
==19990==    by 0x18F6E2: compiler::lr_parser_stage::compile() (tameparse-am.cpp:27826)
==19990==    by 0x191E27: compiler::test_stage::get_parser(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, dfa::position const&) (tameparse-am.cpp:29850)
==19990==    by 0x1967D6: compiler::test_stage::compile() (tameparse-am.cpp:29926)
==19990==    by 0x12DA11: main (tameparse-am.cpp:46778)
==19990== 
==19990== Conditional jump or move depends on uninitialised value(s)
==19990==    at 0x16C1E6: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33640)
==19990==    by 0x16AD47: contextfree::ebnf_repeating::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:32618)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x16C058: contextfree::nonterminal::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:34327)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x17D385: lr::lalr_builder::create_closure(std::set<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> >, std::less<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> > >, std::allocator<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> > > >&, lr::lalr_state const&, contextfree::grammar const*) (tameparse-am.cpp:42158)
==19990==    by 0x186D40: lr::lalr_builder::complete_parser() (tameparse-am.cpp:42194)
==19990==    by 0x18F6E2: compiler::lr_parser_stage::compile() (tameparse-am.cpp:27826)
==19990==    by 0x191E27: compiler::test_stage::get_parser(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, dfa::position const&) (tameparse-am.cpp:29850)
==19990==    by 0x1967D6: compiler::test_stage::compile() (tameparse-am.cpp:29926)
==19990==    by 0x12DA11: main (tameparse-am.cpp:46778)
==19990== 
==19990== Conditional jump or move depends on uninitialised value(s)
==19990==    at 0x16C1E6: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33640)
==19990==    by 0x16C058: contextfree::nonterminal::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:34327)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x16AD47: contextfree::ebnf_repeating::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:32618)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x16C058: contextfree::nonterminal::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:34327)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x17D385: lr::lalr_builder::create_closure(std::set<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> >, std::less<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> > >, std::allocator<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> > > >&, lr::lalr_state const&, contextfree::grammar const*) (tameparse-am.cpp:42158)
==19990==    by 0x186D40: lr::lalr_builder::complete_parser() (tameparse-am.cpp:42194)
==19990==    by 0x18F6E2: compiler::lr_parser_stage::compile() (tameparse-am.cpp:27826)
==19990==    by 0x191E27: compiler::test_stage::get_parser(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, dfa::position const&) (tameparse-am.cpp:29850)
==19990==    by 0x1967D6: compiler::test_stage::compile() (tameparse-am.cpp:29926)
==19990== 
==19990== Conditional jump or move depends on uninitialised value(s)
==19990==    at 0x16C1E6: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33640)
==19990==    by 0x16C058: contextfree::nonterminal::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:34327)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x16C058: contextfree::nonterminal::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:34327)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x16AD47: contextfree::ebnf_repeating::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:32618)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x16C058: contextfree::nonterminal::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:34327)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x17D385: lr::lalr_builder::create_closure(std::set<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> >, std::less<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> > >, std::allocator<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> > > >&, lr::lalr_state const&, contextfree::grammar const*) (tameparse-am.cpp:42158)
==19990==    by 0x186D40: lr::lalr_builder::complete_parser() (tameparse-am.cpp:42194)
==19990==    by 0x18F6E2: compiler::lr_parser_stage::compile() (tameparse-am.cpp:27826)
==19990== 
==19990== Conditional jump or move depends on uninitialised value(s)
==19990==    at 0x16C1E6: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33640)
==19990==    by 0x16B305: contextfree::ebnf_alternate::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:32782)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x16AD47: contextfree::ebnf_repeating::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:32618)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x16C058: contextfree::nonterminal::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:34327)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x16C058: contextfree::nonterminal::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:34327)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x16C058: contextfree::nonterminal::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:34327)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x16AD47: contextfree::ebnf_repeating::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:32618)
==19990== 
==19990== Conditional jump or move depends on uninitialised value(s)
==19990==    at 0x16C1E6: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33640)
==19990==    by 0x16B836: contextfree::ebnf_alternate::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:32774)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x16AD47: contextfree::ebnf_repeating::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:32618)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x16C058: contextfree::nonterminal::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:34327)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x16C058: contextfree::nonterminal::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:34327)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x16C058: contextfree::nonterminal::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:34327)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x16AD47: contextfree::ebnf_repeating::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:32618)
==19990== 
==19990== Conditional jump or move depends on uninitialised value(s)
==19990==    at 0x16C1E6: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33640)
==19990==    by 0x16C058: contextfree::nonterminal::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:34327)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x16B836: contextfree::ebnf_alternate::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:32774)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x16AD47: contextfree::ebnf_repeating::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:32618)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x16C058: contextfree::nonterminal::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:34327)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x16C058: contextfree::nonterminal::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:34327)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x16C058: contextfree::nonterminal::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:34327)
==19990== 
==19990== Conditional jump or move depends on uninitialised value(s)
==19990==    at 0x16C1E6: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33640)
==19990==    by 0x16AB0B: contextfree::ebnf_optional::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:32568)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x16C058: contextfree::nonterminal::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:34327)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x17D385: lr::lalr_builder::create_closure(std::set<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> >, std::less<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> > >, std::allocator<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> > > >&, lr::lalr_state const&, contextfree::grammar const*) (tameparse-am.cpp:42158)
==19990==    by 0x186D40: lr::lalr_builder::complete_parser() (tameparse-am.cpp:42194)
==19990==    by 0x18F6E2: compiler::lr_parser_stage::compile() (tameparse-am.cpp:27826)
==19990==    by 0x191E27: compiler::test_stage::get_parser(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, dfa::position const&) (tameparse-am.cpp:29850)
==19990==    by 0x1967D6: compiler::test_stage::compile() (tameparse-am.cpp:29926)
==19990==    by 0x12DA11: main (tameparse-am.cpp:46778)
==19990== 
==19990== Conditional jump or move depends on uninitialised value(s)
==19990==    at 0x16C1E6: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33640)
==19990==    by 0x16AB0B: contextfree::ebnf_optional::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:32568)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x17D385: lr::lalr_builder::create_closure(std::set<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> >, std::less<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> > >, std::allocator<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> > > >&, lr::lalr_state const&, contextfree::grammar const*) (tameparse-am.cpp:42158)
==19990==    by 0x186D40: lr::lalr_builder::complete_parser() (tameparse-am.cpp:42194)
==19990==    by 0x18F6E2: compiler::lr_parser_stage::compile() (tameparse-am.cpp:27826)
==19990==    by 0x191E27: compiler::test_stage::get_parser(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, dfa::position const&) (tameparse-am.cpp:29850)
==19990==    by 0x1967D6: compiler::test_stage::compile() (tameparse-am.cpp:29926)
==19990==    by 0x12DA11: main (tameparse-am.cpp:46778)
==19990== 
==19990== Conditional jump or move depends on uninitialised value(s)
==19990==    at 0x16C1E6: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33640)
==19990==    by 0x16C058: contextfree::nonterminal::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:34327)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x16AB0B: contextfree::ebnf_optional::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:32568)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x17D385: lr::lalr_builder::create_closure(std::set<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> >, std::less<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> > >, std::allocator<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> > > >&, lr::lalr_state const&, contextfree::grammar const*) (tameparse-am.cpp:42158)
==19990==    by 0x186D40: lr::lalr_builder::complete_parser() (tameparse-am.cpp:42194)
==19990==    by 0x18F6E2: compiler::lr_parser_stage::compile() (tameparse-am.cpp:27826)
==19990==    by 0x191E27: compiler::test_stage::get_parser(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, dfa::position const&) (tameparse-am.cpp:29850)
==19990==    by 0x1967D6: compiler::test_stage::compile() (tameparse-am.cpp:29926)
==19990==    by 0x12DA11: main (tameparse-am.cpp:46778)
==19990== 
==19990== Conditional jump or move depends on uninitialised value(s)
==19990==    at 0x16C1E6: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33640)
==19990==    by 0x16C058: contextfree::nonterminal::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:34327)
==19990==    by 0x16C1ED: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33641)
==19990==    by 0x16C058: contextfree::nonterminal::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:34327)
==19990==    by 0x16C1ED: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33641)
==19990==    by 0x16C058: contextfree::nonterminal::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:34327)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x16C058: contextfree::nonterminal::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:34327)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x17D385: lr::lalr_builder::create_closure(std::set<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> >, std::less<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> > >, std::allocator<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> > > >&, lr::lalr_state const&, contextfree::grammar const*) (tameparse-am.cpp:42158)
==19990==    by 0x186D40: lr::lalr_builder::complete_parser() (tameparse-am.cpp:42194)
==19990==    by 0x18F6E2: compiler::lr_parser_stage::compile() (tameparse-am.cpp:27826)
==19990== 
==19990== Conditional jump or move depends on uninitialised value(s)
==19990==    at 0x16C1E6: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33640)
==19990==    by 0x16B305: contextfree::ebnf_alternate::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:32782)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x17D385: lr::lalr_builder::create_closure(std::set<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> >, std::less<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> > >, std::allocator<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> > > >&, lr::lalr_state const&, contextfree::grammar const*) (tameparse-am.cpp:42158)
==19990==    by 0x186D40: lr::lalr_builder::complete_parser() (tameparse-am.cpp:42194)
==19990==    by 0x18F6E2: compiler::lr_parser_stage::compile() (tameparse-am.cpp:27826)
==19990==    by 0x191E27: compiler::test_stage::get_parser(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, dfa::position const&) (tameparse-am.cpp:29850)
==19990==    by 0x1967D6: compiler::test_stage::compile() (tameparse-am.cpp:29926)
==19990==    by 0x12DA11: main (tameparse-am.cpp:46778)
==19990== 
==19990== Conditional jump or move depends on uninitialised value(s)
==19990==    at 0x16C1E6: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33640)
==19990==    by 0x16C058: contextfree::nonterminal::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:34327)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x16B305: contextfree::ebnf_alternate::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:32782)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x17D385: lr::lalr_builder::create_closure(std::set<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> >, std::less<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> > >, std::allocator<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> > > >&, lr::lalr_state const&, contextfree::grammar const*) (tameparse-am.cpp:42158)
==19990==    by 0x186D40: lr::lalr_builder::complete_parser() (tameparse-am.cpp:42194)
==19990==    by 0x18F6E2: compiler::lr_parser_stage::compile() (tameparse-am.cpp:27826)
==19990==    by 0x191E27: compiler::test_stage::get_parser(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, dfa::position const&) (tameparse-am.cpp:29850)
==19990==    by 0x1967D6: compiler::test_stage::compile() (tameparse-am.cpp:29926)
==19990==    by 0x12DA11: main (tameparse-am.cpp:46778)
==19990== 
==19990== Conditional jump or move depends on uninitialised value(s)
==19990==    at 0x16C1E6: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33640)
==19990==    by 0x16AD47: contextfree::ebnf_repeating::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:32618)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x17D385: lr::lalr_builder::create_closure(std::set<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> >, std::less<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> > >, std::allocator<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> > > >&, lr::lalr_state const&, contextfree::grammar const*) (tameparse-am.cpp:42158)
==19990==    by 0x186D40: lr::lalr_builder::complete_parser() (tameparse-am.cpp:42194)
==19990==    by 0x18F6E2: compiler::lr_parser_stage::compile() (tameparse-am.cpp:27826)
==19990==    by 0x191E27: compiler::test_stage::get_parser(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, dfa::position const&) (tameparse-am.cpp:29850)
==19990==    by 0x1967D6: compiler::test_stage::compile() (tameparse-am.cpp:29926)
==19990==    by 0x12DA11: main (tameparse-am.cpp:46778)
==19990== 
==19990== Conditional jump or move depends on uninitialised value(s)
==19990==    at 0x16C1E6: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33640)
==19990==    by 0x16B305: contextfree::ebnf_alternate::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:32782)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x16AB0B: contextfree::ebnf_optional::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:32568)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x17D385: lr::lalr_builder::create_closure(std::set<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> >, std::less<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> > >, std::allocator<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> > > >&, lr::lalr_state const&, contextfree::grammar const*) (tameparse-am.cpp:42158)
==19990==    by 0x186D40: lr::lalr_builder::complete_parser() (tameparse-am.cpp:42194)
==19990==    by 0x18F6E2: compiler::lr_parser_stage::compile() (tameparse-am.cpp:27826)
==19990==    by 0x191E27: compiler::test_stage::get_parser(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, dfa::position const&) (tameparse-am.cpp:29850)
==19990==    by 0x1967D6: compiler::test_stage::compile() (tameparse-am.cpp:29926)
==19990==    by 0x12DA11: main (tameparse-am.cpp:46778)
==19990== 
==19990== Conditional jump or move depends on uninitialised value(s)
==19990==    at 0x16C1E6: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33640)
==19990==    by 0x16B836: contextfree::ebnf_alternate::closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:32774)
==19990==    by 0x16C68B: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33667)
==19990==    by 0x17D385: lr::lalr_builder::create_closure(std::set<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> >, std::less<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> > >, std::allocator<util::container<lr::lr0_item, util::simple_constructor<lr::lr0_item> > > >&, lr::lalr_state const&, contextfree::grammar const*) (tameparse-am.cpp:42158)
==19990==    by 0x186D40: lr::lalr_builder::complete_parser() (tameparse-am.cpp:42194)
==19990==    by 0x18F6E2: compiler::lr_parser_stage::compile() (tameparse-am.cpp:27826)
==19990==    by 0x191E27: compiler::test_stage::get_parser(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, dfa::position const&) (tameparse-am.cpp:29850)
==19990==    by 0x1967D6: compiler::test_stage::compile() (tameparse-am.cpp:29926)
==19990==    by 0x12DA11: main (tameparse-am.cpp:46778)
==19990== 
==19990== Invalid read of size 4
==19990==    at 0x1D8A3D: bool lr::parser<int, lr::simple_parser_actions, lr::no_parser_trace>::state::can_reduce<lr::parser<int, lr::simple_parser_actions, lr::no_parser_trace>::state::nonterminal_fetcher>(int, int, std::stack<int, std::deque<int, std::allocator<int> > >, lr::parser_stack<int, 64> const&) (tameparse-am.cpp:9149)
==19990==    by 0x1DD4F7: can_reduce_nonterminal (tameparse-am.cpp:8477)
==19990==    by 0x1DD4F7: lr::parser<int, lr::simple_parser_actions, lr::no_parser_trace>::state::check_guard(int, int) (tameparse-am.cpp:8983)
==19990==    by 0x1DD2F4: check_guard (tameparse-am.cpp:8439)
==19990==    by 0x1DD2F4: lr::parser<int, lr::simple_parser_actions, lr::no_parser_trace>::state::check_guard(int, int) (tameparse-am.cpp:9032)
==19990==    by 0x1DD2F4: check_guard (tameparse-am.cpp:8439)
==19990==    by 0x1DD2F4: lr::parser<int, lr::simple_parser_actions, lr::no_parser_trace>::state::check_guard(int, int) (tameparse-am.cpp:9032)
==19990==    by 0x196EA5: check_guard (tameparse-am.cpp:8320)
==19990==    by 0x196EA5: process_generic<lr::parser<int, lr::simple_parser_actions>::state::standard_actions> (tameparse-am.cpp:9256)
==19990==    by 0x196EA5: process_generic<lr::parser<int, lr::simple_parser_actions>::state::standard_actions> (tameparse-am.cpp:9320)
==19990==    by 0x196EA5: process (tameparse-am.cpp:8629)
==19990==    by 0x196EA5: parse (tameparse-am.cpp:8637)
==19990==    by 0x196EA5: compiler::test_stage::compile() (tameparse-am.cpp:29971)
==19990==    by 0x12DA11: main (tameparse-am.cpp:46778)
==19990==  Address 0xb791d64 is 4 bytes after a block of size 0 alloc'd
==19990==    at 0x4C348C7: operator new[](unsigned long) (vg_replace_malloc.c:579)
==19990==    by 0x18E6A5: lr::parser_tables::parser_tables(lr::lalr_builder const&, lr::weak_symbols const*) (tameparse-am.cpp:43584)
==19990==    by 0x190381: compiler::lr_parser_stage::compile() (tameparse-am.cpp:27939)
==19990==    by 0x191E27: compiler::test_stage::get_parser(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, dfa::position const&) (tameparse-am.cpp:29850)
==19990==    by 0x1967D6: compiler::test_stage::compile() (tameparse-am.cpp:29926)
==19990==    by 0x12DA11: main (tameparse-am.cpp:46778)
==19990== 
==19990== Invalid read of size 4
==19990==    at 0x1D8A3D: bool lr::parser<int, lr::simple_parser_actions, lr::no_parser_trace>::state::can_reduce<lr::parser<int, lr::simple_parser_actions, lr::no_parser_trace>::state::nonterminal_fetcher>(int, int, std::stack<int, std::deque<int, std::allocator<int> > >, lr::parser_stack<int, 64> const&) (tameparse-am.cpp:9149)
==19990==    by 0x1DD4F7: can_reduce_nonterminal (tameparse-am.cpp:8477)
==19990==    by 0x1DD4F7: lr::parser<int, lr::simple_parser_actions, lr::no_parser_trace>::state::check_guard(int, int) (tameparse-am.cpp:8983)
==19990==    by 0x1DD2F4: check_guard (tameparse-am.cpp:8439)
==19990==    by 0x1DD2F4: lr::parser<int, lr::simple_parser_actions, lr::no_parser_trace>::state::check_guard(int, int) (tameparse-am.cpp:9032)
==19990==    by 0x196EA5: check_guard (tameparse-am.cpp:8320)
==19990==    by 0x196EA5: process_generic<lr::parser<int, lr::simple_parser_actions>::state::standard_actions> (tameparse-am.cpp:9256)
==19990==    by 0x196EA5: process_generic<lr::parser<int, lr::simple_parser_actions>::state::standard_actions> (tameparse-am.cpp:9320)
==19990==    by 0x196EA5: process (tameparse-am.cpp:8629)
==19990==    by 0x196EA5: parse (tameparse-am.cpp:8637)
==19990==    by 0x196EA5: compiler::test_stage::compile() (tameparse-am.cpp:29971)
==19990==    by 0x12DA11: main (tameparse-am.cpp:46778)
==19990==  Address 0xb791d64 is 4 bytes after a block of size 0 alloc'd
==19990==    at 0x4C348C7: operator new[](unsigned long) (vg_replace_malloc.c:579)
==19990==    by 0x18E6A5: lr::parser_tables::parser_tables(lr::lalr_builder const&, lr::weak_symbols const*) (tameparse-am.cpp:43584)
==19990==    by 0x190381: compiler::lr_parser_stage::compile() (tameparse-am.cpp:27939)
==19990==    by 0x191E27: compiler::test_stage::get_parser(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, dfa::position const&) (tameparse-am.cpp:29850)
==19990==    by 0x1967D6: compiler::test_stage::compile() (tameparse-am.cpp:29926)
==19990==    by 0x12DA11: main (tameparse-am.cpp:46778)
==19990== 
==19990== Invalid read of size 4
==19990==    at 0x1D8A3D: bool lr::parser<int, lr::simple_parser_actions, lr::no_parser_trace>::state::can_reduce<lr::parser<int, lr::simple_parser_actions, lr::no_parser_trace>::state::nonterminal_fetcher>(int, int, std::stack<int, std::deque<int, std::allocator<int> > >, lr::parser_stack<int, 64> const&) (tameparse-am.cpp:9149)
==19990==    by 0x1DD4F7: can_reduce_nonterminal (tameparse-am.cpp:8477)
==19990==    by 0x1DD4F7: lr::parser<int, lr::simple_parser_actions, lr::no_parser_trace>::state::check_guard(int, int) (tameparse-am.cpp:8983)
==19990==    by 0x196EA5: check_guard (tameparse-am.cpp:8320)
==19990==    by 0x196EA5: process_generic<lr::parser<int, lr::simple_parser_actions>::state::standard_actions> (tameparse-am.cpp:9256)
==19990==    by 0x196EA5: process_generic<lr::parser<int, lr::simple_parser_actions>::state::standard_actions> (tameparse-am.cpp:9320)
==19990==    by 0x196EA5: process (tameparse-am.cpp:8629)
==19990==    by 0x196EA5: parse (tameparse-am.cpp:8637)
==19990==    by 0x196EA5: compiler::test_stage::compile() (tameparse-am.cpp:29971)
==19990==    by 0x12DA11: main (tameparse-am.cpp:46778)
==19990==  Address 0xb791d64 is 4 bytes after a block of size 0 alloc'd
==19990==    at 0x4C348C7: operator new[](unsigned long) (vg_replace_malloc.c:579)
==19990==    by 0x18E6A5: lr::parser_tables::parser_tables(lr::lalr_builder const&, lr::weak_symbols const*) (tameparse-am.cpp:43584)
==19990==    by 0x190381: compiler::lr_parser_stage::compile() (tameparse-am.cpp:27939)
==19990==    by 0x191E27: compiler::test_stage::get_parser(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, dfa::position const&) (tameparse-am.cpp:29850)
==19990==    by 0x1967D6: compiler::test_stage::compile() (tameparse-am.cpp:29926)
==19990==    by 0x12DA11: main (tameparse-am.cpp:46778)
==19990== 
==19990== Conditional jump or move depends on uninitialised value(s)
==19990==    at 0x16C1E6: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33640)
==19990==    by 0x17F922: lr::lalr_builder::complete_lookaheads() (tameparse-am.cpp:42323)
==19990==    by 0x187049: lr::lalr_builder::complete_parser() (tameparse-am.cpp:42273)
==19990==    by 0x18F6E2: compiler::lr_parser_stage::compile() (tameparse-am.cpp:27826)
==19990==    by 0x191E27: compiler::test_stage::get_parser(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, dfa::position const&) (tameparse-am.cpp:29850)
==19990==    by 0x1967D6: compiler::test_stage::compile() (tameparse-am.cpp:29926)
==19990==    by 0x12DA11: main (tameparse-am.cpp:46778)
==19990== 
==19990== Conditional jump or move depends on uninitialised value(s)
==19990==    at 0x16C1E6: contextfree::item::cache_closure(lr::lr1_item const&, lr::lr1_item_set&, contextfree::grammar const&) const (tameparse-am.cpp:33640)
==19990==    by 0x17D921: lr::lalr_builder::generate_closure(lr::lalr_state const&, lr::lr1_item_set&, contextfree::grammar const*) (tameparse-am.cpp:42459)
==19990==    by 0x180E9F: lr::lalr_builder::actions_for_state(int) const (tameparse-am.cpp:42515)
==19990==    by 0x18BB09: find_conflicts(lr::lalr_builder const&, int, std::vector<util::container<lr::conflict, util::simple_constructor<lr::conflict> >, std::allocator<util::container<lr::conflict, util::simple_constructor<lr::conflict> > > >&) (tameparse-am.cpp:41775)
==19990==    by 0x18F76C: find_conflicts (tameparse-am.cpp:41921)
==19990==    by 0x18F76C: compiler::lr_parser_stage::compile() (tameparse-am.cpp:27831)
==19990==    by 0x191E27: compiler::test_stage::get_parser(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, dfa::position const&) (tameparse-am.cpp:29850)
==19990==    by 0x1967D6: compiler::test_stage::compile() (tameparse-am.cpp:29926)
==19990==    by 0x12DA11: main (tameparse-am.cpp:46778)
==19990== 
    C99: 41/41 passed
==19990== 
==19990== HEAP SUMMARY:
==19990==     in use at exit: 106,458,884 bytes in 3,666,958 blocks
==19990==   total heap usage: 9,443,237 allocs, 5,776,279 frees, 294,874,792 bytes allocated
==19990== 
==19990== LEAK SUMMARY:
==19990==    definitely lost: 32,235,320 bytes in 805,755 blocks
==19990==    indirectly lost: 74,220,124 bytes in 2,861,050 blocks
==19990==      possibly lost: 3,204 bytes in 142 blocks
==19990==    still reachable: 236 bytes in 11 blocks
==19990==         suppressed: 0 bytes in 0 blocks
==19990== Rerun with --leak-check=full to see details of leaked memory
==19990== 
==19990== Use --track-origins=yes to see where uninitialised values come from
==19990== For lists of detected and suppressed errors, rerun with: -s
==19990== ERROR SUMMARY: 928 errors from 22 contexts (suppressed: 0 from 0)
mingodad commented 1 year ago

The Conditional jump or move depends on uninitialised value(s) can be solved with:

diff --git a/TameParse/ContextFree/item.h b/TameParse/ContextFree/item.h
index 41813c4..96b0d69 100644
--- a/TameParse/ContextFree/item.h
+++ b/TameParse/ContextFree/item.h
@@ -100,7 +100,7 @@ namespace contextfree {

     public:
         /// \brief Standard constructor
-        explicit inline item(int symbol) : m_Symbol(symbol) { }
+        explicit inline item(int symbol) : m_Symbol(symbol), m_CachingClosure(false) { }

         /// \brief Destructor
         virtual ~item();
mingodad commented 1 year ago

The problem with Invalid read of size 4 is an interesting one it says that it's passing a 0 byte allocation here:

 // Allocate action tables of the appropriate size
        action* termActions     = new action[termCount];
        action* nontermActions  = new action[nontermCount];  ///!!! just here <<<<<<

        int     termPos         = 0;                    // Current item in the terminal table
        int     nontermPos      = 0;                    // Current item in the nonterminal table

And the invalid read is here:

        // Get the initial action for the terminal
        parser_tables::action_iterator act = symbol_fetcher::find_symbol(m_Tables, state, symbol);

        // Find the first reduce action for this item
        while (act != symbol_fetcher::last_symbol_action(m_Tables, state)) {
            // Fail if there are no actions for this terminal
            if (act->symbolId != symbol) return false; ///!!!! just here <<<<<

I do not see any check for the act iterator been invalid.

mingodad commented 1 year ago

It seems that a check need to be done after or before ++act; to see if it's still valid (in range).

mingodad commented 1 year ago

Shouldn't this two functions use m_Counts[stateId].num - 1 ?

        /// \brief An iterator pointing to the last action referring to a terminal symbol in the specified state
        inline action_iterator last_terminal_action(int stateId) const { 
            return m_TerminalActions[stateId] + m_Counts[stateId].numTerminals;  //!!<<< here
        }

        /// \brief An iterator pointing to the last action referring to a non-terminal symbol in the specified state
        inline action_iterator last_nonterminal_action(int stateId) const { 
            return m_NonterminalActions[stateId] + m_Counts[stateId].numNonterminals;  //!!<<< here
        }

Because they alloc:

        // Allocate the array for this state
        m_TerminalActions[stateId]      = new action[m_Counts[stateId].numTerminals];
        m_NonterminalActions[stateId]   = new action[m_Counts[stateId].numNonterminals];

        // Copy the terminals and nonterminals
        for (int x=0; x<m_Counts[stateId].numTerminals; ++x) {
            m_TerminalActions[stateId][x] = copyFrom.m_TerminalActions[stateId][x];
        }
        for (int x=0; x<m_Counts[stateId].numNonterminals; ++x) {
            m_NonterminalActions[stateId][x] = copyFrom.m_NonterminalActions[stateId][x];
        }
mingodad commented 1 year ago

Wow add +1 to all allocations in TameParse/Lr/parser_tables.cpp removed the valgrind warning/error and also improved preformance (7x) and memory usage (2/3) (although there is a need to a better inspection overall).

#original
/usr/bin/time ../parsetool/tameparse --enable-lr1-resolver --run-tests C99.tp
TameParse 0.1.0
    C99: 41/41 passed
6.97user 0.12system 0:07.09elapsed 100%CPU (0avgtext+0avgdata 257012maxresident)k
0inputs+0outputs (0major+64464minor)pagefaults 0swaps

#with +1 on allocations
 /usr/bin/time ../parsetool/tameparse --enable-lr1-resolver --run-tests C99.tp
TameParse 0.1.0
    C99: 41/41 passed
0.95user 0.04system 0:00.98elapsed 100%CPU (0avgtext+0avgdata 156432maxresident)k
0inputs+0outputs (0major+39325minor)pagefaults 0swaps
diff --git a/TameParse/Lr/parser_tables.cpp b/TameParse/Lr/parser_tables.cpp
index 06d9a28..36b2ca2 100644
--- a/TameParse/Lr/parser_tables.cpp
+++ b/TameParse/Lr/parser_tables.cpp
@@ -84,9 +84,9 @@ parser_tables::parser_tables(const lalr_builder& builder, const weak_symbols* we
 : m_DeleteTables(true) {
     // Allocate the tables
     m_NumStates             = builder.count_states();
-    m_NonterminalActions    = new action*[m_NumStates];
-    m_TerminalActions       = new action*[m_NumStates];
-    m_Counts                = new action_count[m_NumStates];
+    m_NonterminalActions    = new action*[m_NumStates+1];
+    m_TerminalActions       = new action*[m_NumStates+1];
+    m_Counts                = new action_count[m_NumStates+1];

     contextfree::end_of_input eoi;
     contextfree::end_of_guard eog;
@@ -116,8 +116,8 @@ parser_tables::parser_tables(const lalr_builder& builder, const weak_symbols* we
         }

         // Allocate action tables of the appropriate size
-        action* termActions     = new action[termCount];
-        action* nontermActions  = new action[nontermCount];
+        action* termActions     = new action[termCount+1];
+        action* nontermActions  = new action[nontermCount+1];

         int     termPos         = 0;                    // Current item in the terminal table
         int     nontermPos      = 0;                    // Current item in the nonterminal table
@@ -176,7 +176,7 @@ parser_tables::parser_tables(const lalr_builder& builder, const weak_symbols* we

     // Store the end of guard state table (we evaluate states in order, so this is already sorted)
     m_NumEndOfGuards    = (int) eogStates.size();
-    m_EndGuardStates    = new int[m_NumEndOfGuards];
+    m_EndGuardStates    = new int[m_NumEndOfGuards+1];
     for (int x=0; x<m_NumEndOfGuards; ++x) {
         m_EndGuardStates[x] = eogStates[x];
     }
@@ -206,7 +206,7 @@ parser_tables::parser_tables(const lalr_builder& builder, const weak_symbols* we
         }

         // Fill in the table as an unordered list
-        m_WeakToStrong      = new symbol_equivalent[m_NumWeakToStrong];
+        m_WeakToStrong      = new symbol_equivalent[m_NumWeakToStrong+1];
         int pos = 0;
         for (weak_symbols::strong_iterator weakForStrong = weakSymbols->begin_strong(); weakForStrong != weakSymbols->end_strong(); ++weakForStrong) {
             // Fetch the strong symbol
@@ -263,9 +263,9 @@ parser_tables::parser_tables(const parser_tables& copyFrom)
 , m_DeleteTables(copyFrom.m_DeleteTables)
 , m_NumWeakToStrong(copyFrom.m_NumWeakToStrong) {
     // Allocate the action tables
-    m_TerminalActions       = new action*[m_NumStates];
-    m_NonterminalActions    = new action*[m_NumStates];
-    m_Counts                = new action_count[m_NumStates];
+    m_TerminalActions       = new action*[m_NumStates+1];
+    m_NonterminalActions    = new action*[m_NumStates+1];
+    m_Counts                = new action_count[m_NumStates+1];

     // Copy the states
     for (int stateId=0; stateId<m_NumStates; ++stateId) {
@@ -273,8 +273,8 @@ parser_tables::parser_tables(const parser_tables& copyFrom)
         m_Counts[stateId] = copyFrom.m_Counts[stateId];

         // Allocate the array for this state
-        m_TerminalActions[stateId]      = new action[m_Counts[stateId].numTerminals];
-        m_NonterminalActions[stateId]   = new action[m_Counts[stateId].numNonterminals];
+        m_TerminalActions[stateId]      = new action[m_Counts[stateId].numTerminals+1];
+        m_NonterminalActions[stateId]   = new action[m_Counts[stateId].numNonterminals+1];

         // Copy the terminals and nonterminals
         for (int x=0; x<m_Counts[stateId].numTerminals; ++x) {
@@ -286,14 +286,14 @@ parser_tables::parser_tables(const parser_tables& copyFrom)
     }

     // Allocate the rule table
-    m_Rules = new reduce_rule[m_NumRules];
+    m_Rules = new reduce_rule[m_NumRules+1];
     for (int ruleId=0; ruleId<m_NumRules; ++ruleId) {
         m_Rules[ruleId] = copyFrom.m_Rules[ruleId];
     }

     // Allocate the end of guard state table
     m_NumEndOfGuards    = copyFrom.m_NumEndOfGuards;
-    m_EndGuardStates    = new int[m_NumEndOfGuards];
+    m_EndGuardStates    = new int[m_NumEndOfGuards+1];

     // Copy the states
     for (int x=0; x<m_NumEndOfGuards; ++x) {
@@ -302,7 +302,7 @@ parser_tables::parser_tables(const parser_tables& copyFrom)

     // Copy the weak to strong table
     if (copyFrom.m_WeakToStrong) {
-        m_WeakToStrong = new symbol_equivalent[m_NumWeakToStrong];
+        m_WeakToStrong = new symbol_equivalent[m_NumWeakToStrong+1];

         for (int x=0; x<m_NumWeakToStrong; ++x) {
             m_WeakToStrong[x] = copyFrom.m_WeakToStrong[x];
@@ -343,9 +343,9 @@ parser_tables& parser_tables::operator=(const parser_tables& copyFrom) {
     m_NumWeakToStrong   = copyFrom.m_NumWeakToStrong;

     // Allocate the action tables
-    m_TerminalActions       = new action*[m_NumStates];
-    m_NonterminalActions    = new action*[m_NumStates];
-    m_Counts                = new action_count[m_NumStates];
+    m_TerminalActions       = new action*[m_NumStates+1];
+    m_NonterminalActions    = new action*[m_NumStates+1];
+    m_Counts                = new action_count[m_NumStates+1];

     // Copy the states
     for (int stateId=0; stateId<m_NumStates; ++stateId) {
@@ -353,8 +353,8 @@ parser_tables& parser_tables::operator=(const parser_tables& copyFrom) {
         m_Counts[stateId] = copyFrom.m_Counts[stateId];

         // Allocate the array for this state
-        m_TerminalActions[stateId]      = new action[m_Counts[stateId].numTerminals];
-        m_NonterminalActions[stateId]   = new action[m_Counts[stateId].numNonterminals];
+        m_TerminalActions[stateId]      = new action[m_Counts[stateId].numTerminals+1];
+        m_NonterminalActions[stateId]   = new action[m_Counts[stateId].numNonterminals+1];

         // Copy the terminals and nonterminals
         for (int x=0; x<m_Counts[stateId].numTerminals; ++x) {
@@ -366,14 +366,14 @@ parser_tables& parser_tables::operator=(const parser_tables& copyFrom) {
     }

     // Allocate the rule table
-    m_Rules = new reduce_rule[m_NumRules];
+    m_Rules = new reduce_rule[m_NumRules+1];
     for (int ruleId=0; ruleId<m_NumRules; ++ruleId) {
         m_Rules[ruleId] = copyFrom.m_Rules[ruleId];
     }

     // Allocate the end of guard state table
     m_NumEndOfGuards    = copyFrom.m_NumEndOfGuards;
-    m_EndGuardStates    = new int[m_NumEndOfGuards];
+    m_EndGuardStates    = new int[m_NumEndOfGuards+1];

     // Copy the states
     for (int x=0; x<m_NumEndOfGuards; ++x) {
@@ -382,7 +382,7 @@ parser_tables& parser_tables::operator=(const parser_tables& copyFrom) {

     // Copy the weak to strong table
     if (copyFrom.m_WeakToStrong) {
-        m_WeakToStrong = new symbol_equivalent[m_NumWeakToStrong];
+        m_WeakToStrong = new symbol_equivalent[m_NumWeakToStrong+1];

         for (int x=0; x<m_NumWeakToStrong; ++x) {
             m_WeakToStrong[x] = copyFrom.m_WeakToStrong[x];
mingodad commented 1 year ago

But there is some differences in the Test/test output:

--- /home/mingo/dev/c/A_grammars/TameParse0/Test/test.log
+++ /home/mingo/dev/c/A_grammars/TameParse/Test/test.log
@@ -510,12 +510,12 @@
 STATE 0
   3: #(0) -> * S'(1), $(3) [S'(1) >FIRST> #(0) S'(1) S(2)]

-  0: S'(1) -> * S(2), #(0) [S(2) >FIRST> #(0) S(2)]
-  1: S(2) -> *, #(0) 'i' []
-  2: S(2) -> * S(2) 'i', #(0) 'i' [S(2) >FIRST> #(0) S(2)]
-
-  REDUCE $(3) on 1: S(2) ->
-  REDUCE 'i' on 1: S(2) ->
+  0: S(2) -> *, #(0) 'i' []
+  1: S(2) -> * S(2) 'i', #(0) 'i' [S(2) >FIRST> #(0) S(2)]
+  2: S'(1) -> * S(2), #(0) [S(2) >FIRST> #(0) S(2)]
+
+  REDUCE $(3) on 0: S(2) ->
+  REDUCE 'i' on 0: S(2) ->
   GOTO S'(1) -> 1
   GOTO S(2) -> 2

@@ -525,17 +525,17 @@
   ACCEPT $(3) -> -1

 STATE 2
-  0: S'(1) -> S(2) *, $(3) []
-  2: S(2) -> S(2) * 'i', $(3) 'i' ['i' >FIRST> 'i']
-
-  REDUCE $(3) on 0: S'(1) -> S(2)
+  1: S(2) -> S(2) * 'i', $(3) 'i' ['i' >FIRST> 'i']
+  2: S'(1) -> S(2) *, $(3) []
+
+  REDUCE $(3) on 2: S'(1) -> S(2)
   SHIFT 'i' -> 3

 STATE 3
-  2: S(2) -> S(2) 'i' *, $(3) 'i' []
-
-  REDUCE $(3) on 2: S(2) -> S(2) 'i'
-  REDUCE 'i' on 2: S(2) -> S(2) 'i'
+  1: S(2) -> S(2) 'i' *, $(3) 'i' []
+
+  REDUCE $(3) on 1: S(2) -> S(2) 'i'
+  REDUCE 'i' on 1: S(2) -> S(2) 'i'

 lalr-general.NoConflicts2...................................ok
 lalr-general.Empty..........................................ok
@@ -805,9 +805,9 @@
 Language-Definition = ^ Lexer-Symbols-Definition [Language-Definition, Lexer-Symbols-Definition, Lexer-Definition, Ignore-Definition, Keywords-Definition, Grammar-Definition, grammar, lexer-symbols, lexer, ignore, weak, keywords, '}']
 Lexer-Symbols-Definition = ^ lexer-symbols '{' ( Lexeme-Definition )* '}' [Language-Definition, Lexer-Symbols-Definition, Lexer-Definition, Ignore-Definition, Keywords-Definition, Grammar-Definition, grammar, lexer-symbols, lexer, ignore, weak, keywords, '}']
 Language-Definition = ^ Lexer-Definition [Language-Definition, Lexer-Symbols-Definition, Lexer-Definition, Ignore-Definition, Keywords-Definition, Grammar-Definition, grammar, lexer-symbols, lexer, ignore, weak, keywords, '}']
-Lexer-Definition = ^ ( weak )? lexer '{' ( Lexeme-Definition )* '}' [Language-Definition, Lexer-Symbols-Definition, Lexer-Definition, Ignore-Definition, Keywords-Definition, Grammar-Definition, grammar, lexer-symbols, lexer, ignore, weak, keywords, '}']
 ( weak )? = ^ [lexer, keywords]
 ( weak )? = ^ weak [lexer, keywords]
+Lexer-Definition = ^ ( weak )? lexer '{' ( Lexeme-Definition )* '}' [Language-Definition, Lexer-Symbols-Definition, Lexer-Definition, Ignore-Definition, Keywords-Definition, Grammar-Definition, grammar, lexer-symbols, lexer, ignore, weak, keywords, '}']
 Language-Definition = ^ Ignore-Definition [Language-Definition, Lexer-Symbols-Definition, Lexer-Definition, Ignore-Definition, Keywords-Definition, Grammar-Definition, grammar, lexer-symbols, lexer, ignore, weak, keywords, '}']
 Ignore-Definition = ^ ignore '{' ( Keyword-Definition )* '}' [Language-Definition, Lexer-Symbols-Definition, Lexer-Definition, Ignore-Definition, Keywords-Definition, Grammar-Definition, grammar, lexer-symbols, lexer, ignore, weak, keywords, '}']
 Language-Definition = ^ Keywords-Definition [Language-Definition, Lexer-Symbols-Definition, Lexer-Definition, Ignore-Definition, Keywords-Definition, Grammar-Definition, grammar, lexer-symbols, lexer, ignore, weak, keywords, '}']
@@ -1569,9 +1569,9 @@
 State #65
 Nonterminal-Definition = [=> nonterminal '='] nonterminal '=' ^ Production ( '|' Production )* (Nonterminal-Definition, '}', [=> nonterminal '='])
 --
-Production = ^ ( Simple-Ebnf-Item )* [Nonterminal-Definition, '}', [=> nonterminal '='], '|']
 ( Simple-Ebnf-Item )* = ^ [Nonterminal-Definition, Simple-Ebnf-Item, Guard, Nonterminal, Terminal, Basic-Terminal, identifier, '}', nonterminal, [=> nonterminal '='], string, character, '(', "[=>", '|']
 ( Simple-Ebnf-Item )* = ^ ( Simple-Ebnf-Item )* Simple-Ebnf-Item [Nonterminal-Definition, Simple-Ebnf-Item, Guard, Nonterminal, Terminal, Basic-Terminal, identifier, '}', nonterminal, [=> nonterminal '='], string, character, '(', "[=>", '|']
+Production = ^ ( Simple-Ebnf-Item )* [Nonterminal-Definition, '}', [=> nonterminal '='], '|']
 Nonterminal-Definition = [=> nonterminal '='] nonterminal '=' ^ Production ( '|' Production )* [Nonterminal-Definition, '}', [=> nonterminal '=']]

 Reduce on language (( Simple-Ebnf-Item )* = )
@@ -1701,8 +1701,8 @@
 Goto 74 on ( '|' Production )*

 State #72
+( Simple-Ebnf-Item )* = ( Simple-Ebnf-Item )* ^ Simple-Ebnf-Item (Nonterminal-Definition, Simple-Ebnf-Item, Guard, Nonterminal, Terminal, Basic-Terminal, identifier, '}', nonterminal, [=> nonterminal '='], string, character, '(', "[=>", '|')
 Production = ( Simple-Ebnf-Item )* ^ (Nonterminal-Definition, '}', [=> nonterminal '='], '|')
-( Simple-Ebnf-Item )* = ( Simple-Ebnf-Item )* ^ Simple-Ebnf-Item (Nonterminal-Definition, Simple-Ebnf-Item, Guard, Nonterminal, Terminal, Basic-Terminal, identifier, '}', nonterminal, [=> nonterminal '='], string, character, '(', "[=>", '|')
 --
 Simple-Ebnf-Item = ^ Nonterminal ( Item-Name )? [Nonterminal-Definition, Simple-Ebnf-Item, Guard, Nonterminal, Terminal, Basic-Terminal, identifier, '}', nonterminal, [=> nonterminal '='], string, character, '(', "[=>", '|', '*', '+', '?']
 Nonterminal = ^ nonterminal [Nonterminal-Definition, Simple-Ebnf-Item, Guard, Nonterminal, Terminal, Basic-Terminal, Item-Name, identifier, '}', nonterminal, [=> nonterminal '='], string, character, '(', "[=>", '|', '[', '*', '+', '?']
@@ -1717,8 +1717,8 @@
 Simple-Ebnf-Item = ^ '(' Ebnf-Item ')' [Nonterminal-Definition, Simple-Ebnf-Item, Guard, Nonterminal, Terminal, Basic-Terminal, identifier, '}', nonterminal, [=> nonterminal '='], string, character, '(', "[=>", '|', '*', '+', '?']
 Simple-Ebnf-Item = ^ Guard [Nonterminal-Definition, Simple-Ebnf-Item, Guard, Nonterminal, Terminal, Basic-Terminal, identifier, '}', nonterminal, [=> nonterminal '='], string, character, '(', "[=>", '|', '*', '+', '?']
 Guard = ^ "[=>" Ebnf-Item ']' [Nonterminal-Definition, Simple-Ebnf-Item, Guard, Nonterminal, Terminal, Basic-Terminal, identifier, '}', nonterminal, [=> nonterminal '='], string, character, '(', "[=>", '|', '*', '+', '?']
+( Simple-Ebnf-Item )* = ( Simple-Ebnf-Item )* ^ Simple-Ebnf-Item [Nonterminal-Definition, Simple-Ebnf-Item, Guard, Nonterminal, Terminal, Basic-Terminal, identifier, '}', nonterminal, [=> nonterminal '='], string, character, '(', "[=>", '|']
 Production = ( Simple-Ebnf-Item )* ^ [Nonterminal-Definition, '}', [=> nonterminal '='], '|']
-( Simple-Ebnf-Item )* = ( Simple-Ebnf-Item )* ^ Simple-Ebnf-Item [Nonterminal-Definition, Simple-Ebnf-Item, Guard, Nonterminal, Terminal, Basic-Terminal, identifier, '}', nonterminal, [=> nonterminal '='], string, character, '(', "[=>", '|']

 Shift strong equivalent to 77 on language
 Shift strong equivalent to 77 on grammar
@@ -2175,9 +2175,9 @@
 State #87
 ( '|' Production )* = ( '|' Production )* '|' ^ Production (Nonterminal-Definition, '}', [=> nonterminal '='], '|')
 --
-Production = ^ ( Simple-Ebnf-Item )* [Nonterminal-Definition, '}', [=> nonterminal '='], '|']
 ( Simple-Ebnf-Item )* = ^ [Nonterminal-Definition, Simple-Ebnf-Item, Guard, Nonterminal, Terminal, Basic-Terminal, identifier, '}', nonterminal, [=> nonterminal '='], string, character, '(', "[=>", '|']
 ( Simple-Ebnf-Item )* = ^ ( Simple-Ebnf-Item )* Simple-Ebnf-Item [Nonterminal-Definition, Simple-Ebnf-Item, Guard, Nonterminal, Terminal, Basic-Terminal, identifier, '}', nonterminal, [=> nonterminal '='], string, character, '(', "[=>", '|']
+Production = ^ ( Simple-Ebnf-Item )* [Nonterminal-Definition, '}', [=> nonterminal '='], '|']
 ( '|' Production )* = ( '|' Production )* '|' ^ Production [Nonterminal-Definition, '}', [=> nonterminal '='], '|']

 Reduce on language (( Simple-Ebnf-Item )* = )
mingodad commented 1 year ago

Somehow my amalgamation still shows valgrind warnings/errors but the original binary built with make doesn't, need to investigate.

mingodad commented 1 year ago

Now I found how to test the parser with external input and found that the AnsiC.tp grammar doesn't accept <Enumerator-List> with a trailing comma. test.c

int x = 3;
//comment
double d = 2.0;
/* another comment */
enum ex {
    car,
    cdr
};

enum ex2 {
    car2 = 2,
    cdr2
};

enum {
  SEEK_SET,  // 0
  SEEK_CUR,  // 1
  SEEK_END,  // 2 ////!!!! error here trailing comma
};
cat test.c | ../parsetool/tameparse --enable-lr1-resolver --test -S '<Translation-Unit>' C99.tp
TameParse 0.1.0
stdin:19:1: error: Syntax error
mingodad commented 1 year ago

It seems that C99 does accept trailing comma and adding this rule to C99.tp fix it:

replace <Enumerator-List> = <Enumerator> (',' <Enumerator>)* ','?
mingodad commented 1 year ago

I'm trying to parse the attached source file and I'm getting this error:

cat lemon.pp.c | ../parsetool/tameparse --enable-lr1-resolver --test -S '<Translation-Unit>' C99.tp
TameParse 0.1.0
stdin:425:15: error: Syntax error

Just here int v =:

      if( c=='d' ){
        int v = ({   char *p;   switch (__builtin_type_kind(int)) {   case  6:     p = ((ap)->fp_offset < (6 + 8) * 8     ? (char*)(ap)->reg_save_area + ((ap)->fp_offset += 8) - 8     : ({   uintptr_t p = (uintptr_t)((ap)->overflow_arg_area);   if ((_Alignof(int)) > 8)  p = (p + 15) / 16 * 16;   (ap)->overflow_arg_area = (void*)((p + (sizeof(int)) + 7) & -8);   (char*)p; })); break;   case  1: case  2:     p = ((ap)->gp_offset < 6 * 8     ? (char*)(ap)->reg_save_area + ((ap)->gp_offset += 8) - 8     : ({   uintptr_t p = (uintptr_t)((ap)->overflow_arg_area);   if ((_Alignof(int)) > 8)  p = (p + 15) / 16 * 16;   (ap)->overflow_arg_area = (void*)((p + (sizeof(int)) + 7) & -8);   (char*)p; })); break;   default:     p = ({   uintptr_t p = (uintptr_t)((ap)->overflow_arg_area);   if ((_Alignof(int)) > 8)  p = (p + 15) / 16 * 16;   (ap)->overflow_arg_area = (void*)((p + (sizeof(int)) + 7) & -8);   (char*)p; }); break;   }   *(int *)p; });
        if( v<0 ){
          lemon_addtext(str, &nUsed, "-", 1, iWidth);
          v = -v;
        }else if( v==0 ){
          lemon_addtext(str, &nUsed, "0", 1, iWidth);
        }

lemon.pp.c.zip

mingodad commented 1 year ago

Here is one small but non trivial source that is parsed correctly and can be used to profile this project. miniyacc.pp.c.zip

mingodad commented 1 year ago

Trying to create a parser using the C99.tp grammar we get errors due to use of reserved words as identifiers in the generated code (_Complex), probably we need an option to specify a prefix for user defined symbols like yacc/bison has yy_:

mk-c99-parser.sh:

../parsetool/tameparse --enable-lr1-resolver -o c99 -S '<Translation-Unit>' C99.tp
g++ -DHAVE_CONFIG_H -I. -I..  -O2 -g -o c99_tp c99_main.cpp c99.cpp ../TameParse/.libs/libTameParse.so -Wl,-rpath -Wl,/home/mingo/local/tameparse/lib

c99_main.cpp:

//
// Simple JSON formatter, reads from stdin and writes a pretty-printed version
// to stdout
//

#include <iostream>
#include <string>
#include "c99.h"

using namespace std;

//
// Parses stdin as C99
//
int main(int argc, const char** argv) {
    // Create the parser - unicode from wcin
    C99::state* parser = C99::create_Translation_Unit<wchar_t>(wcin);

    // Generate the AST
    bool success = parser->parse();

    if (!success) {
        // Report syntax error
        if (parser->look().item()) {
            // The lookahead contains the symbol that generated the error
            cerr << "Syntax error on line " << parser->look()->pos().line() << ", column " << parser->look()->pos().column() << endl;
        } else {
            // No lookahead: file is incomplete
            cerr << "Syntax error: unexpected end of file" << endl;
        }

        // Abort if there's an error
        return 1;
    }

    // Exit success
    return 0;
}

Output:

./mk-c99-parser.sh
TameParse 0.1.0
In file included from c99_main.cpp:8:
c99.h:110:35: error: expected unqualified-id before ‘=’ token
  110 |         static const int _Complex = 91;
      |                                   ^
In file included from c99_main.cpp:8:
c99.h:3384:44: error: declaration does not declare anything [-fpermissive]
 3384 |         const util::syntax_ptr<_Complex_n> _Complex;
      |                                            ^~~~~~~~
In file included from c99.cpp:6:
c99.h:110:35: error: expected unqualified-id before ‘=’ token
  110 |         static const int _Complex = 91;
      |                                   ^
In file included from c99.cpp:6:
c99.h:3384:44: error: declaration does not declare anything [-fpermissive]
 3384 |         const util::syntax_ptr<_Complex_n> _Complex;
      |                                            ^~~~~~~~
c99.cpp: In constructor ‘C99::Type_Specifier_n::Type_Specifier_n(const util::syntax_ptr<C99::_Complex_n>&)’:
c99.cpp:8741:3: error: expected identifier before ‘_Complex’
 8741 | , _Complex(_Complex_0) {
      |   ^~~~~~~~
c99.cpp:8741:3: error: expected ‘{’ before ‘_Complex’
c99.cpp: At global scope:
c99.cpp:8745:1: error: expected ‘,’ or ‘;’ before ‘C99’
 8745 | C99::Type_Specifier_n::Type_Specifier_n(const util::syntax_ptr<class _Imaginary_n>& _Imaginary_0)
      | ^~~
c99.cpp: In constructor ‘C99::Direct_Declarator_n::Direct_Declarator_n(const util::syntax_ptr<C99::Direct_Declarator_n>&, const util::syntax_ptr<C99::_opensquare__n>&, const util::syntax_ptr<C99::list_of_Type_Qualifier_2_n>&, const util::syntax_ptr<C99::static_n>&, const util::syntax_ptr<C99::Assignment_Expression_n>&, const util::syntax_ptr<C99::_closesquare__n>&)’:
c99.cpp:9158:32: error: no matching function for call to ‘util::syntax_ptr<C99::list_of_Type_Qualifier_n>::syntax_ptr(const util::syntax_ptr<C99::list_of_Type_Qualifier_2_n>&)’
 9158 | , _closesquare_(_closesquare__5) {
      |                                ^
In file included from c99.h:9,
                 from c99.cpp:6:
../TameParse/Util/syntax_ptr.h:94:16: note: candidate: ‘util::syntax_ptr<ptr_type>::syntax_ptr(const util::syntax_ptr<ptr_type>&) [with ptr_type = C99::list_of_Type_Qualifier_n]’
   94 |         inline syntax_ptr(const syntax_ptr<ptr_type>& copyFrom)
      |                ^~~~~~~~~~
../TameParse/Util/syntax_ptr.h:94:55: note:   no known conversion for argument 1 from ‘const util::syntax_ptr<C99::list_of_Type_Qualifier_2_n>’ to ‘const util::syntax_ptr<C99::list_of_Type_Qualifier_n>&’
   94 |         inline syntax_ptr(const syntax_ptr<ptr_type>& copyFrom)
      |                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
../TameParse/Util/syntax_ptr.h:89:25: note: candidate: ‘util::syntax_ptr<ptr_type>::syntax_ptr(const ptr_type*) [with ptr_type = C99::list_of_Type_Qualifier_n]’
   89 |         explicit inline syntax_ptr(const ptr_type* value)
      |                         ^~~~~~~~~~
../TameParse/Util/syntax_ptr.h:89:52: note:   no known conversion for argument 1 from ‘const util::syntax_ptr<C99::list_of_Type_Qualifier_2_n>’ to ‘const C99::list_of_Type_Qualifier_n*’
   89 |         explicit inline syntax_ptr(const ptr_type* value)
      |                                    ~~~~~~~~~~~~~~~~^~~~~
../TameParse/Util/syntax_ptr.h:81:16: note: candidate: ‘util::syntax_ptr<ptr_type>::syntax_ptr() [with ptr_type = C99::list_of_Type_Qualifier_n]’
   81 |         inline syntax_ptr()
      |                ^~~~~~~~~~
../TameParse/Util/syntax_ptr.h:81:16: note:   candidate expects 0 arguments, 1 provided
../TameParse/Util/syntax_ptr.h:74:25: note: candidate: ‘util::syntax_ptr<ptr_type>::syntax_ptr(util::syntax_ptr_reference*) [with ptr_type = C99::list_of_Type_Qualifier_n]’
   74 |         inline explicit syntax_ptr(syntax_ptr_reference* ref)
      |                         ^~~~~~~~~~
../TameParse/Util/syntax_ptr.h:74:58: note:   no known conversion for argument 1 from ‘const util::syntax_ptr<C99::list_of_Type_Qualifier_2_n>’ to ‘util::syntax_ptr_reference*’
   74 |         inline explicit syntax_ptr(syntax_ptr_reference* ref)
      |                                    ~~~~~~~~~~~~~~~~~~~~~~^~~
c99.cpp: In member function ‘virtual dfa::position C99::Type_Specifier_n::pos() const’:
c99.cpp:11839:16: error: expected primary-expression before ‘_Complex’
11839 |         return _Complex->pos();
      |                ^~~~~~~~
c99.cpp:11839:15: error: expected ‘;’ before ‘_Complex’
11839 |         return _Complex->pos();
      |               ^~~~~~~~~
      |               ;
c99.cpp:11839:24: error: expected unqualified-id before ‘->’ token
11839 |         return _Complex->pos();
      |                        ^~
c99.cpp: In member function ‘virtual dfa::position C99::Type_Specifier_n::final_pos() const’:
c99.cpp:11891:16: error: expected primary-expression before ‘_Complex’
11891 |         return _Complex->final_pos();
      |                ^~~~~~~~
c99.cpp:11891:15: error: expected ‘;’ before ‘_Complex’
11891 |         return _Complex->final_pos();
      |               ^~~~~~~~~
      |               ;
c99.cpp:11891:24: error: expected unqualified-id before ‘->’ token
11891 |         return _Complex->final_pos();
      |                        ^~
mingodad commented 1 year ago

There is a list of reserved words to add suffix in output_cplusplus::output_cplusplus but I think that having a custom prefix added to all user defined symbols is easier/cleaner.

mingodad commented 1 year ago

Hello Andrew ! Are you still interested in this project ? Cheers !

Logicalshift commented 1 year ago

Ah, it's very much a back-burner project for me, being something I originally wrote way back in 2010. Still, didn't realise I'd left this sitting quite so long (March & April this year seem to have disappeared into a black hole for me). I've merged the PR that switches to using a 'yy_' prefix now (finally).

I originally did want to do away with prefixes as they do make code that uses the parser output harder to read, but I think the approach I took here could definitely have used some improvement (it definitely causes issues as the C++ standard changes over time, and it's not always obvious when the name of something will change too)