# HG changeset patch # User mjsousa # Date 1392511060 0 # Node ID a435684a5223aa5eda154fde2f6166126971a034 # Parent c8c48ab075e09462dae17e08dee82537a0327313 Add option to control support for nested comments (default is off, as defined in IEC 61131-3 v2) diff -r c8c48ab075e0 -r a435684a5223 main.cc --- 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 "\". diff -r c8c48ab075e0 -r a435684a5223 stage1_2/iec_flex.ll --- 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_whitespace} /* Eat any whitespace */ /* The comments */ -{comment_beg} yy_push_state(comment_state); -{comment_beg} yy_push_state(comment_state); +{comment_beg} yy_push_state(comment_state); +{comment_beg} yy_push_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! */ } /*****************************************/ diff -r c8c48ab075e0 -r a435684a5223 stage1_2/stage1_2.cc --- 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); diff -r c8c48ab075e0 -r a435684a5223 stage1_2/stage1_2.hh --- 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; diff -r c8c48ab075e0 -r a435684a5223 stage1_2/stage1_2_priv.hh --- 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(); /*************************************************************/