CH - 2008-03-24

Hallo,

needing a parser for various purposes I have taken the time to check out the latest YARD 1.2 version; in particular I wanted to check on the quality of error messages by trying out one of the examples.

(The templated approach leads to horrible error messages from the compiler when there is a problem in the grammar; I can live with that; what I am interested in are the error messages produced at runtime when actually using the parser, where the templated approach might be a hindrance (due to the inability to use string literals as template arguments)).

The first problems I encountered were when trying to compile the Scheme parser example: neither yard_tester.hpp, nor the io functionality used for reading the files is included. After a few quick changes (remove the test code, directly use argv[i] as input rather than as filename, fixing the makefile and a few missing headers) it compiles, leading directly to the second problem:

yard-1.2.ch/docs/scheme_parser> ./yard_scheme_parser ")"
running ./yard_scheme_parser
successfullly parsed input [ ) ] 1 times
yard_scheme_parser(47155) malloc: *** error for object 0xbffff8c1: Non-aligned pointer being freed
*** set a breakpoint in malloc_error_break to debug

Below are my changes, but I can't see any immediate connection to the two problems...

Regards, Colin

> g++ -v
Using built-in specs.
Target: i686-apple-darwin9
Configured with: /var/tmp/gcc/gcc-5465~16/src/configure --disable-checking -enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.0/ --with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/usr/lib --build=i686-apple-darwin9 --with-arch=apple --with-tune=generic --host=i686-apple-darwin9 --target=i686-apple-darwin9
Thread model: posix
gcc version 4.0.1 (Apple Inc. build 5465)

> uname -a
Darwin tigger.local 9.2.0 Darwin Kernel Version 9.2.0: Tue Feb  5 16:13:22 PST 2008; root:xnu-1228.3.13~1/RELEASE_I386 i386 i386 MacBookPro3,1 Darwin

> diff -ur yard-1.2/docs/scheme_parser/Makefile yard-1.2.ch/docs/scheme_parser/Makefile
--- yard-1.2/docs/scheme_parser/Makefile        2007-11-27 07:16:00.000000000 +0100
+++ yard-1.2.ch/docs/scheme_parser/Makefile     2008-03-21 21:58:59.000000000 +0100
@@ -4,8 +4,8 @@
TARGET = yard_scheme_parser
SRC = ${TARGET}_main.cpp
OBJ = $(SRC:.cpp=.o)
-INC = ../../../include
-CFLAGS = -Werror -O3 -I"$(INC)" 
+INC = ../../include
+CFLAGS = -Werror -O3 -I$(INC)
CC = g++

#####################
Only in yard-1.2.ch/docs/scheme_parser: yard_scheme_parser
diff -ur yard-1.2/docs/scheme_parser/yard_scheme_parser_main.cpp yard-1.2.ch/docs/scheme_parser/yard_scheme_parser_main.cpp
--- yard-1.2/docs/scheme_parser/yard_scheme_parser_main.cpp     2007-11-27 07:16:00.000000000 +0100
+++ yard-1.2.ch/docs/scheme_parser/yard_scheme_parser_main.cpp  2008-03-24 11:19:03.000000000 +0100
@@ -9,74 +9,19 @@
#include "yard/yard.hpp"
#include "yard_scheme_grammar.hpp"

-#include "misc/io.hpp"
-
using namespace yard;
-using namespace yard_test;
+// using namespace yard_test;
using namespace scheme_grammar;

-void RunUnitTests()
-{
-       Test<Num<2> >("#b01");
-       Test<Num<8> >("#o12");
-       Test<Num<10> >("#d12");
-       Test<Num<16> >("#x12");
-       Test<Number>("#b#i01");
-       Test<Exactness>("#i");
-       Test<Exactness>("#e");
-       Test<Prefix<10> >("#d");
-       Test<Prefix<10> >("#i");
-       Test<Prefix<10> >("#e");
-       Test<Radix<10> >("#d");
-       Test<Prefix<10> >("#i#d");
-       Test<Prefix<10> >("#d#i");
-       Test<Number>("#o#e12");
-       Test<Number>("#i#d12");
-       Test<Number>("#d#i12");
-       Test<Number>("#e#x12");
-       Test<Number>("#i12");
-       Test<Number>("#e12");
-       Test<Number>("12");
-       Test<Identifier>("+");
-       Test<Identifier>("-");
-       Test<Identifier>("...");
-       Test<Identifier>("qwerty");
-       Test<Identifier>("A");
-       Test<Identifier>("b12");
-       Test<Identifier>("a-b");
-       Test<Identifier>("ab?");
-       Test<Identifier>("a?-b!");
-       Test<Boolean>("#t");
-       Test<String>("\&quot;qwerty\&quot;");
-       Test<List>("()");
-       Test<List>("(a)");
-       Test<List>("(12)");
-       Test<List>("(a 13 #t)");
-       Test<List>("(())");
-       Test<List>("((()))");
-       Test<List>("(()())");
-       Test<List>("(()a())");
-       Test<List>("((a)(b)(c))");
-       Test<Vector>("#(1 2 3)");
-       Test<Abbreviation>(",1");
-       Test<Abbreviation>("'1");
-       Test<Abbreviation>(",1");
-       Test<Abbreviation>(",@1");
-       Test<Abbreviation>(",(1 2 3)");
-       Test<Abbreviation>("'(1 2 3)");
-       Test<Abbreviation>(",(1 2 3)");
-       Test<Abbreviation>(",@(1 2 3)");
-}
-
int main(int argn, char* argv[])
{     
        printf("running %s\n", argv[0]);

-       RunUnitTests();
+//     RunUnitTests();

        for (int i=1; i < argn; ++i)
        {
-               char* input = ReadFile(argv[i]);
+               char* input = argv[i];
                bool b = true;
                size_t len = strlen(input);
                int cnt = 1;
@@ -87,10 +32,10 @@
                }
               
                if (b)
-                       printf("successfullly parsed file %s %d times\n", argv[i], cnt); else
+                       printf("successfullly parsed input [ %s ] %d times\n", argv[i], cnt); else
                        printf("failed to parse file %s\n", argv[i]);

                free(input);
        }
-       return 1;
+       return 0;
}
Only in yard-1.2.ch/docs/scheme_parser: yard_scheme_parser_main.o
Only in yard-1.2.ch/include: yard
diff -ur yard-1.2/include/yard.hpp yard-1.2.ch/include/yard.hpp
--- yard-1.2/include/yard.hpp   2007-11-27 07:16:00.000000000 +0100
+++ yard-1.2.ch/include/yard.hpp        2008-03-21 22:02:52.000000000 +0100
@@ -12,12 +12,16 @@
#include <string.h>
#include <assert.h>
#include <typeinfo>
+#include <iostream>
+#include <string>
+#include <stdexcept>

#include "yard_tree.hpp"
#include "yard_parser.hpp"
#include "yard_base_grammar.hpp"
#include "yard_char_set.hpp"
#include "yard_text_grammar.hpp"
-#include "yard_tester.hpp"
+// #include "yard_error.hpp"
+// #include "yard_actions.hpp"

#endif