Add option to control support for nested comments (default is off, as defined in IEC 61131-3 v2)
authormjsousa
Sun, 16 Feb 2014 00:37:40 +0000
changeset 867 a435684a5223
parent 866 c8c48ab075e0
child 868 23f271534a7c
Add option to control support for nested comments (default is off, as defined in IEC 61131-3 v2)
main.cc
stage1_2/iec_flex.ll
stage1_2/stage1_2.cc
stage1_2/stage1_2.hh
stage1_2/stage1_2_priv.hh
--- a/main.cc	Sat Feb 15 23:58:16 2014 +0000
+++ b/main.cc	Sun Feb 16 00:37:40 2014 +0000
@@ -120,8 +120,9 @@
       /* Part 1: Concepts and Function Blocks,              */
       /* Version 1.0 is Official Release                    */
       /******************************************************/
-  printf("  s : allow use of safe extensions\n");
-  printf("  c : create conversion functions\n");
+  printf("  s : allow use of safe extensions (e.g. SAFExxx data types))\n");
+  printf("  n : allow use of nested comments\n");
+  printf("  c : create conversion functions for enumerated data types\n");
   printf("\n");
   printf("%s - Copyright (C) 2003-2011 \n"
          "This program comes with ABSOLUTELY NO WARRANTY!\n"
@@ -133,15 +134,21 @@
 int main(int argc, char **argv) {
   symbol_c *tree_root;
   char * builddir = NULL;
-  stage1_2_options_t stage1_2_options = {false, false, NULL};
+  stage1_2_options_t stage1_2_options;
   int optres, errflg = 0;
   int path_len;
 
+  /* Default values for the command line options... */
+  stage1_2_options.safe_extensions      = false; /* allow use of SAFExxx datatypes */
+  stage1_2_options.full_token_loc       = false; /* error messages specify full token location */
+  stage1_2_options.conversion_functions = false; /* Create a conversion function for derived datatype */
+  stage1_2_options.nested_comments      = false; /* Allow the use of nested comments. */
+  stage1_2_options.includedir           = NULL;  /* Include directory, where included files will be searched for... */
 
   /******************************************/
   /*   Parse command line options...        */
   /******************************************/
-  while ((optres = getopt(argc, argv, ":hvfscI:T:")) != -1) {
+  while ((optres = getopt(argc, argv, ":nhvfscI:T:")) != -1) {
     switch(optres) {
     case 'h':
       printusage(argv[0]);
@@ -164,6 +171,10 @@
       stage1_2_options.conversion_functions = true;
       break;
 
+    case 'n':
+      stage1_2_options.nested_comments = true;
+      break;
+
     case 'I':
       /* NOTE: To improve the usability under windows:
        *       We delete last char's path if it ends with "\".
--- a/stage1_2/iec_flex.ll	Sat Feb 15 23:58:16 2014 +0000
+++ b/stage1_2/iec_flex.ll	Sun Feb 16 00:37:40 2014 +0000
@@ -1143,13 +1143,13 @@
 <il_state>{il_whitespace}		/* Eat any whitespace */
 
 	/* The comments */
-<body_state,vardecl_list_state>{comment_beg}	yy_push_state(comment_state);
-{comment_beg}							yy_push_state(comment_state);
+<body_state,vardecl_list_state>{comment_beg}		yy_push_state(comment_state);
+{comment_beg}						yy_push_state(comment_state);
 <comment_state>{
-{comment_beg}							yy_push_state(comment_state);
-{comment_end}							yy_pop_state();
-.								/* Ignore text inside comment! */
-\n								/* Ignore text inside comment! */
+{comment_beg}						{if (get_opt_nested_comments()) yy_push_state(comment_state);}
+{comment_end}						yy_pop_state();
+.							/* Ignore text inside comment! */
+\n							/* Ignore text inside comment! */
 }
 
 	/*****************************************/
--- a/stage1_2/stage1_2.cc	Sat Feb 15 23:58:16 2014 +0000
+++ b/stage1_2/stage1_2.cc	Sun Feb 16 00:37:40 2014 +0000
@@ -63,6 +63,12 @@
 bool safe_extensions_ = false;
 bool get_opt_safe_extensions() {return safe_extensions_;}
 
+/************************************/
+/* whether to allow nested comments */
+/************************************/
+bool nested_comments_ = false;
+bool get_opt_nested_comments() {return nested_comments_;}
+
 /******************************************************/
 /* whether we are supporting conversion functions     */
 /* for enumerate data types                           */
@@ -241,6 +247,7 @@
        *       We now set those variables...
        */
 
+  nested_comments_ = options.nested_comments;    
   safe_extensions_ = options.safe_extensions;
   conversion_functions_ = options.conversion_functions;
   return stage2__(filename, options.includedir, tree_root_ref, options.full_token_loc);
--- a/stage1_2/stage1_2.hh	Sat Feb 15 23:58:16 2014 +0000
+++ b/stage1_2/stage1_2.hh	Sun Feb 16 00:37:40 2014 +0000
@@ -57,12 +57,10 @@
 		/* Version 1.0 – Official Release                     */
 		/******************************************************/
 	bool safe_extensions;
-		/* error messages specify full token location */
-	bool full_token_loc; 
-		/* Include directory, where included files will be searched for... */
-	bool conversion_functions;
-		/* Create a conversion function for derived datatype */
-	const char *includedir;
+	bool full_token_loc;       /* error messages specify full token location */
+	bool conversion_functions; /* Create a conversion function for derived datatype */
+	bool nested_comments;      /* Allow the use of nested comments. */
+	const char *includedir;    /* Include directory, where included files will be searched for... */
 } stage1_2_options_t;
 
 
--- a/stage1_2/stage1_2_priv.hh	Sat Feb 15 23:58:16 2014 +0000
+++ b/stage1_2/stage1_2_priv.hh	Sun Feb 16 00:37:40 2014 +0000
@@ -88,6 +88,10 @@
 /******************************************************/
 bool get_opt_safe_extensions();
 
+/************************************/
+/* whether to allow nested comments */
+/************************************/
+bool get_opt_nested_comments();
 
 
 /*************************************************************/