Hello,

As we previously discussed, I started modifying code in the src/conv/csg (
on top of your integrated patch, Cliff) to make it parse group() and
identify some basic tokens. The problem I encountered and could not solve
is the following:

[ 91%] [ 91%] Building C object
src/conv/csg/CMakeFiles/csg.dir/csg_scanner.c.o
Building C object src/conv/csg/CMakeFiles/csg.dir/csg_parser.c.o
[ 91%] /home/andrei/buildbrlcad/src/conv/csg/csg_scanner.c:1:0: error: ISO
C forbids an empty translation unit [-Wpedantic]
make[2]: *** [src/conv/csg/CMakeFiles/csg.dir/csg_scanner.c.o] Error 1

I tried adding # pragma GCC diagnostic ignored "-Wpedantic" to the parser
file but the error persisted, and it's obviously not the right way to go,
either. Parser is generating and empty file (csg_scanner.c) . Most likely,
this isn't intended behavior, but I can't seem to reason what causes this.
Presumably, there is an issue with the grammar, but I could not figure out
a fix.

I attached below a patch with my code.

Cheers,
Andrei


On Sun, May 31, 2015 at 3:46 PM, Clifford Yapp <cliffy...@gmail.com> wrote:

> On Fri, May 29, 2015 at 5:55 PM, Ilinca Andrei
> <andrei.ilinc...@gmail.com> wrote:
>
> > I tried to change its grammar to parse some simple .csg functions
> > like group() or multimatrix() and it corectly identified them but I run
> into
> > some errors which I could not solve at that time.
>
> Were you able to subsequently get this working to your satisfaction,
> with the build sytem issues cleared away?
>
> > So far, I have noticed the following aspects. Lemon documentation is slim
> > and the examples are scarce. Those in the first link are (mostly) broken
> and
> > I spent a good deal of time fixing what was supposed to be working.
>
> You'd be surprised how often such situations arise in software
> development - it's a normal part of the process.
>
> > I'm certainly not backing down from this challenge. The way I see it, it
> would
> > be useful to choose Lemon over self-developed parser in case the
> extension
> > to .scad would be easier. I know we're one week in the coding period and
> I'm
> > still stuck and I'm self-pressured about getting things going.
>
> What specifically are you stuck with?  Can you share some of the
> particular problems you're seeing with re2c/lemon?
>
> Either approach (custom or re2c/lemon) is fine - you should pick the
> one you feel is the best fit to both your skills and the problem.  Nor
> is this a situation where you necessarily have to commit to one
> approach and never look back - you may find that as you get more
> deeply into the problem with one approach you are learning more about
> the problem which indicates the other approach would have been better.
> You will most likely find that the code you write (and *certainly* the
> knowledge you develop) will be useful regardless, even you have to
> "translate" it from one approach to another.
>
> Cheers,
> CY
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> BRL-CAD Developer mailing list
> brlcad-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/brlcad-devel
>
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt	(revision 65039)
+++ CMakeLists.txt	(working copy)
@@ -12,6 +12,7 @@
 add_subdirectory(3dm)
 add_subdirectory(gcv)
 add_subdirectory(step)
+add_subdirectory(csg)
 
 add_subdirectory(iges)
 add_subdirectory(intaval)
Index: csg/CMakeLists.txt
===================================================================
--- csg/CMakeLists.txt	(revision 0)
+++ csg/CMakeLists.txt	(working copy)
@@ -0,0 +1,36 @@
+set(CSG_INCLUDE_DIRS
+  ${GCV_INCLUDE_DIRS}
+  ${BU_INCLUDE_DIRS}
+  )
+BRLCAD_INCLUDE_DIRS(CSG_INCLUDE_DIRS)
+
+# Also want local dirs
+include_directories(
+  ${CMAKE_CURRENT_BINARY_DIR}
+  ${CMAKE_CURRENT_SOURCE_DIR}
+  )
+
+PERPLEX_TARGET(csg_scanner csg_scanner.perplex
+  ${CMAKE_CURRENT_BINARY_DIR}/csg_scanner.c
+  ${CMAKE_CURRENT_BINARY_DIR}/csg_scanner.h)
+LEMON_TARGET(csg_parser csg_parser.lemon
+  ${CMAKE_CURRENT_BINARY_DIR}/csg_parser.c
+  ${CMAKE_CURRENT_BINARY_DIR}/csg_parser.h)
+ADD_PERPLEX_LEMON_DEPENDENCY(csg_scanner csg_parser)
+
+set(CSG_SRCS
+  csg.c
+  ${CMAKE_CURRENT_BINARY_DIR}/csg_scanner.c
+  ${CMAKE_CURRENT_BINARY_DIR}/csg_parser.c
+  )
+
+BRLCAD_ADDEXEC(csg "${CSG_SRCS}" "libgcv;libbu" NO_INSTALL)
+
+CMAKEFILES(csg.h)
+
+# Local Variables:
+# tab-width: 8
+# mode: cmake
+# indent-tabs-mode: t
+# End:
+# ex: shiftwidth=2 tabstop=8
Index: csg/csg.c
===================================================================
--- csg/csg.c	(revision 0)
+++ csg/csg.c	(working copy)
@@ -0,0 +1,81 @@
+/*                       C S G . C
+ * BRL-CAD
+ *
+ * Copyright (c) 2013 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; see the file named COPYING for more
+ * information.
+ */
+/** @file csg.c
+ *
+ * Brief description
+ *
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include "csg.h"
+
+static void *
+parse_alloc(size_t size)
+{
+    return bu_malloc(size, "parse_alloc");
+}
+
+int
+main(int argc, char *argv[])
+{
+    FILE *inputFile, *outputFile;
+    void *parser;
+    int tokenID;
+    perplex_t scanner;
+    token_t *tokenData;
+    app_data_t appData;
+
+    if (argc != 3) {
+	fprintf(stderr, "Usage: %s input output", argv[0]);
+	exit(1);
+    }
+
+    inputFile = fopen(argv[1], "r");
+    outputFile = fopen(argv[2], "w");
+
+    scanner = perplexFileScanner(inputFile);
+    perplexSetExtra(scanner, &appData);
+    appData.outfile = outputFile;
+    appData.example_text = 0;
+    bu_vls_init(&appData.description);
+    bu_vls_init(&appData.tags);
+
+    parser = ParseAlloc(parse_alloc);
+
+    BU_GET(tokenData, token_t);
+    bu_vls_init(&tokenData->value);
+    appData.tokenData = tokenData;
+
+    while ((tokenID = yylex(scanner)) != YYEOF) {
+	Parse(parser, tokenID, tokenData, &appData);
+	BU_GET(tokenData, token_t);
+	bu_vls_init(&tokenData->value);
+	appData.tokenData = tokenData;
+    }
+    Parse(parser, 0, tokenData, &appData);
+
+    ParseFree(parser, free);
+    perplexFree(scanner);
+    fclose(inputFile);
+    fclose(outputFile);
+
+    return 0;
+}
Index: csg/csg.h
===================================================================
--- csg/csg.h	(revision 0)
+++ csg/csg.h	(working copy)
@@ -0,0 +1,71 @@
+/*                       C S G . H
+ * BRL-CAD
+ *
+ * Copyright (c) 2013 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; see the file named COPYING for more
+ * information.
+ */
+/** @file csg.h
+ *
+ * Brief description
+ *
+ */
+
+#ifndef ON2JAVA_H
+#define ON2JAVA_H
+
+#include "common.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "bu.h"
+
+typedef struct {
+    struct bu_vls value;
+} token_t;
+
+/* this structure is the dom2dox app_data_t structure with some useless fields
+deleted */
+typedef struct {
+    token_t *tokenData;
+    FILE *outfile;
+    int example_text;
+    struct bu_vls description;
+    struct bu_vls tags;
+} app_data_t;
+
+/* lemon prototypes */
+void *ParseAlloc(void *(*mallocProc)(size_t));
+void ParseFree(void *parser, void (*freeProc)(void *));
+void Parse(void *yyp, int yymajor, token_t *tokenData, app_data_t *appData);
+void ParseTrace(FILE *fp, char *s);
+
+/* definitions generated by lemon */
+#include "csg_parser.h"
+
+#define PERPLEX_ON_ENTER \
+    app_data_t *appData = (app_data_t *)yyextra; \
+    token_t *tokenData = appData->tokenData;
+
+/* definitions generated by perplex */
+#include "csg_scanner.h"
+
+/* utils */
+#define END_EXAMPLE \
+if (appData->example_text) { \
+    bu_vls_strcat(&appData->description, "\n\\endcode\n\n"); \
+    appData->example_text = 0; \
+}
+
+#endif
Index: csg/csg_parser.lemon
===================================================================
--- csg/csg_parser.lemon	(revision 0)
+++ csg/csg_parser.lemon	(working copy)
@@ -0,0 +1,66 @@
+/*                 C S G _ P A R S E R . L E M O N
+ * BRL-CAD
+ *
+ * Copyright (c) 2013 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; see the file named COPYING for more
+ * information.
+ */
+
+%include {
+#include <assert.h>
+#include <string.h>
+#include "csg.h"
+
+#if defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) && !defined(__clang__)
+#  pragma GCC diagnostic ignored "-Wunused-variable"
+#  pragma GCC diagnostic ignored "-Wunused-parameter"
+
+#endif
+#if defined(__clang__)
+#  pragma clang diagnostic ignored "-Wunused-variable"
+#  pragma clang diagnostic ignored "-Wunused-parameter"
+#endif
+
+}
+
+%token_type {token_t *}
+%extra_argument {app_data_t *appData}
+
+/* priorities , not sure if this is how is intended to be used */
+
+%left GROUP_BEGIN.
+%left GROUP_CONTENT.
+%left GROUP_END.
+
+
+/* I believe here I get the compiling error */
+start_symbol ::= block.
+
+//source ::= /* empty */.
+
+/* Initial, simple grammar, just for testing  */
+block ::= code.
+code ::= group_begin.
+{
+  fprintf(appData->outfile, "we found group() {\n");
+}
+group_begin ::= GROUP_BEGIN group_content.
+{
+  fprintf(appData->outfile, "in group(), we found %s ",bu_vls_addr(&appData->description));
+}
+group_content ::= GROUP_END.
+{
+  fprintf(appData->outfile, "we found the end of group()");
+}
Index: csg/csg_scanner.perplex
===================================================================
--- csg/csg_scanner.perplex	(revision 0)
+++ csg/csg_scanner.perplex	(working copy)
@@ -0,0 +1,55 @@
+/*           C S G _ S C A N N E R . P E R P L E X
+ * BRL-CAD
+ *
+ * Copyright (c) 2013 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; see the file named COPYING for more
+ * information.
+ */
+
+/* perplex input file */
+#include "csg.h"
+
+/* condition states - no idea what this enum does but I modified it according
+to what I used below */
+enum {INITIAL, code, group, group_in};
+
+%%
+<> => code { continue; }
+
+/* matching group() { , funtions inside group() and the end of group() */
+
+group_begin = "group() {";
+group_content = [a-z]+ "("*")";
+group_end = "}";
+
+/* returning the tokens found, not sure if correct or not */
+<code>  {
+(optional_ws)(group_begin) {
+    return GROUP_BEGIN;
+  }
+}
+
+<group> {
+(optional_ws)(group_content) {
+     YYSETCONDITION(code);
+     return GROUP_CONTENT;
+   }
+}
+<group_in> {
+  (optional_ws)(group_end) {
+     YYSETCONDITION(group);
+     return GROUP_END;
+}
+}
------------------------------------------------------------------------------
_______________________________________________
BRL-CAD Developer mailing list
brlcad-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-devel

Reply via email to