Claude | 5 Feb 22:45
Picon
Favicon
Gravatar

Rule and C++11 auto type on VS2010

Hi!
I used this code for parsing a date in format yyyy-mm-dd:

    uint32_t day=0,month=0;
    uint32_t year;
    std::string myStr("1974-5-10");

    std::string::const_iterator begin = myStr.begin(), end = myStr.end();

    auto rDate = qi::uint_>>'-'>>qi::uint_>>'-'>>qi::uint_;

    if (qi::phrase_parse(begin, end, rDate, qi::space,year,month,day) )
	{
         cout<<"Parse Ok!"<<endl;
	 cout&lt;&lt;&quot;Year: &quot;&lt;&lt;year&lt;&lt;&quot; Month:
&quot;&lt;&lt;month&lt;&lt;&quot; Day: &quot;&lt;&lt;day&lt;&lt;endl;
	}

This code work well, but if I use it in most complex program, it don’t work
&lt;smiley image=&quot;smiley_what.gif&quot;/>

I discovered that the problem is the rDate variable. If it is a C++11 /auto/
variable, in my complex program, on the Visual C++2010, phrase_parse() don’t
parse correctly. (this problem are not present on GCC 4.6.1 on Ubuntu!)

For this reason I changed the rValue type:

qi::rule<std::string::const_iterator> rDate =
qi::uint_>>'-'>>qi::uint_>>'-'>>qi::uint_;
	
(Continue reading)

Öyvind Strand | 5 Feb 18:50
Picon
Gravatar

Phoenix pointer to member operator not working when compiling with gcc and -std=c++0x

Hi,

A phoenix expression using the pointer to member operator pointing to a member function doesn't compile. This occurs only
when compiling with -std=c++0x AND taking the address of the object inside the phoenix expression. There's no problem
when pointing to a data member or passing something that is already a pointer to the phoenix expression or compiling without -std=c++0x.

class type {
 public:
  void func() {}
  int data;
};

int main() {
  using boost::phoenix::arg_names::arg1;
  
  type obj;
  
  (
    ((&arg1)->*&type::func)() , //Doesn't compile
    (&arg1)->*&type::data       //Compiles
  )
  (obj);
  
  (
    (arg1->*&type::func)() , //Compiles
    arg1->*&type::data       //Compiles
  )
  (&obj);
  
  return 0;
}

Regards

Öyvind


Attachment (main.cpp): text/x-c++src, 385 bytes
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Spirit-general mailing list
Spirit-general <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spirit-general
Öyvind Strand | 1 Feb 21:40
Picon
Gravatar

Problem refering to data member of nested struct in Karma

Hi,

If I have nested data types like these (I've added the dummy member to avoid the special case where
the attribute is a single element fusion sequence which can lead to unrelated problems when compiling):

struct Inner {
  int value;
  double dummy;
};
struct Outer {
  Inner inner;
  double dummy;
};

and want to refer to the member value of the deeper struct I would do it like this using stand-alone phoenix:

Outer data;
using phx::arg_names::arg1;
(
  ((&arg1)->*&Outer::inner)->*&Inner::value
)
(data);

Doing the same thing in qi works fine:

typedef std::string::iterator IIter;
qi::rule<IIter, Inner()> inner_input_rule = qi::int_ >> qi::double_;
qi::rule<IIter, Outer()> outer_input_rule;
  
outer_input_rule = (inner_input_rule >> qi::double_)[
  ((&qi::_val)->*&Outer::inner)->*&Inner::value
];

But it won't compile when using karma:

typedef std::ostream_iterator<char> OIter;
kma::rule<OIter, Inner()> inner_output_rule = kma::int_ << kma::double_;
kma::rule<OIter, Outer()> outer_output_rule;
  
using phx::local_names::_a;
outer_output_rule = (inner_output_rule << kma::double_)[
  //This phoenix expression won't compile
  //((&kma::_val)->*&Outer::inner)->*&Inner::value,
    
  //Split it and it will compile
  phx::let(_a = (&kma::_val)->*&Outer::inner)[
    (&_a)->*&Inner::value
  ]
];

There are of course several ways to work around this like using at_c<>(at_c<>()) or using local variables so it's not
really a big problem but it would make programs more readable if you were able to do it the same way as in qi.

Regards

Öyvind



Attachment (main.cpp): text/x-c++src, 1563 bytes
------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Spirit-general mailing list
Spirit-general <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spirit-general
Öyvind Strand | 30 Jan 18:56
Picon
Gravatar

Nested structs and Karma

Hi,

Using the following simplified nested struct works fine with qi but doesn't compile with karma.
Shouldn't it work the same way?

namespace kma = boost::spirit::karma;
namespace qi = boost::spirit::qi;

struct Inner {
  int value;
};
struct Outer {
  Inner inner;
};

BOOST_FUSION_ADAPT_STRUCT(
  Inner,
  (int, value)
)
BOOST_FUSION_ADAPT_STRUCT(
  Outer,
  (Inner, inner)
)

int main() {
  typedef std::string::iterator IIter;
  qi::rule<IIter, Inner()> inner_input_rule = qi::int_;
 //This works fine 
 qi::rule<IIter, Outer()> outer_input_rule = inner_input_rule;
  
  typedef std::ostream_iterator<char> OIter;
  kma::rule<OIter, Inner()> inner_output_rule = kma::int_;
  //The following line won't compile
  kma::rule<OIter, Outer()> outer_output_rule = inner_output_rule;
  
  return 0;
}

If I don't use FUSION_ADAPT_STRUCT but do like this:

typedef fsn::vector<int> Inner;
typedef fsn::vector<Inner> Outer;

it doesn't work either but produces a different error message (returning reference to temporary).

Regards

Öyvind
Attachment (main.cpp): text/x-c++src, 1006 bytes
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Spirit-general mailing list
Spirit-general <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spirit-general
Leo Goodstadt | 29 Jan 17:48
Picon
Gravatar

Read columns in any order

I am required to parse certain columns from a tab-delimited file with data types known at compile time.

Unfortunately, the number and order of columns is only known at run time.
What would be best way to tackle this?

Say I have three values I need to parse: A, B, C 
where A is a string, and B and C are int.

In one file <A>, <B> and <C> could be columns 1, 4 and 6
I could parse this by padding my grammar with a repeat directive to consume unwanted columns:
<A><2 columns ignored><B><1 column ignored><C>

However, in other files, <B> might precede <A>.
<A>, <B> and <C> might be columns 5, 2 and 4

The only way to handle this, I can think of, would be to have separate grammars for all the permutations of the orders of A, B, C.

Is there an elegant and efficient solution? These are big files.

Thanks

Leo Goodstadt
University of Oxford
United Kingdom


------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Spirit-general mailing list
Spirit-general <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spirit-general
Sérgio Carvalho | 28 Jan 20:32
Picon
Gravatar

skippers

Hi,

I am having difficulty to parse a file MD5mesh.

If I have all on one line, the parser goes well
--- FILE ---
MD5Version 10 commandline "XXX" numJoints 12 numMeshes 32
--- EOF ---

--- OUTPUT ---
got: (10 XXX 12 32)
--- OUTPUT ---

Otherwise, if the file have this configuration, the parser fails.
MD5Version 10
--- FILE ---
commandline "XXX"
numJoints 12
numMeshes 32
--- EOF ---

--- OUTPUT ---
got: (10  0 0)
--- OUTPUT ---

--- MAIN.CPP ---
#include <boost/filesystem.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_fusion.hpp>
#include <boost/spirit/include/phoenix_stl.hpp>
#include <boost/spirit/include/phoenix_object.hpp>

#include <iostream>
#include <fstream>
#include <string>

class Model
{
public:
	static Model*	import(const std::string& pathname);
};

struct MD5_abstract_syntax_tree
{
	int			version;
	std::string	commandline;
	int			num_joints;
	int			num_meshes;
};

BOOST_FUSION_ADAPT_STRUCT(
	MD5_abstract_syntax_tree,
	(int,			version)
	(std::string,	commandline)
	(int,			num_joints)
	(int,			num_meshes)
)

template <typename Iterator>
struct MD5_grammar
	: boost::spirit::qi::grammar<Iterator, MD5_abstract_syntax_tree(),
		boost::spirit::ascii::space_type>
{
	MD5_grammar() : MD5_grammar::base_type(start, "MD5_grammar")
	{
		using namespace boost::spirit::qi;
		
		qw		=	lexeme['"' >> +(char_ - '"') >> '"']
				;
		qw.name("qw");
		
		start	=	lit("MD5Version")	>>	int_
				>>	lit("commandline")	>>	qw
				>>	lit("numJoints")	>>	int_
				>>	lit("numMeshes")	>>	int_
				;
		start.name("start");
		
		using namespace boost::phoenix;
		on_error<fail>(start, std::cout
			<< val("parse error:") << construct<std::string>(_3, _2)
			<< val(": ") << _4 << std::endl);
	}
	
	boost::spirit::qi::rule<Iterator, std::string(),
		boost::spirit::ascii::space_type>	qw;
	boost::spirit::qi::rule<Iterator, MD5_abstract_syntax_tree(),
		boost::spirit::ascii::space_type>	start;
};

Model*
Model::import(const std::string& pathname)
{
	typedef std::string::const_iterator	iterator_type;
	MD5_grammar<iterator_type>	grammar;
	MD5_abstract_syntax_tree	ast;
	
	std::ifstream	ifs(boost::filesystem::path(pathname).c_str());
	std::string		line;
	while (std::getline(ifs, line)) {
		iterator_type begin	= line.begin();
		iterator_type end	= line.end();
		phrase_parse(begin, end, grammar, boost::spirit::ascii::space, ast);
	}
	ifs.close();
	
	std::cout << "got: " << boost::fusion::as_vector(ast) << std::endl;
	
	return NULL;
}

int main(int argc, char **argv)
{
  Model::import(argv[1]);

  return 0;
}

--- MAIN.CPP ---

Thanks ,
Sérgio Carvalho

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Spirit-general mailing list
Spirit-general <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spirit-general
Hicham Mouline | 27 Jan 02:43
Picon

Exact permutation operator

Hello

A while back, there were mentions of a exact permutation operator which
required all the operands to be present, but in whatever order, as opposed
to the normal permutation operator which allows some operands to be absent.

Of course, the current solution I have uses phoenix function to ensure all
the operands are indeed present, but aa primitive spirit operator would be
more elegant.

MM

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
richard.smart | 26 Jan 03:28
Favicon
Gravatar

Strange behaviour Karma locals

Hi All,

Whilst attempting to use karma locals I have hit upon the following unexpected behavour. I was attempting
to implement the rule Hartmut describes in his article
http://boost-spirit.com/home/2010/01/21/what-are-rule-bound-semantic-actions/  as practise.

The rule is 

rule<OutIter, locals<int>, std::vector<std::string>()> r =
    eps[_a = 1] << (lit(_a) << eps[++_a] << " " << string) % '\n';

I found I was unable to get this rule to compile for me with msvc 8.0. I attempted to simplify the problem and
arrived at the curious short sample program I enclose below. This program (as presented) does not
compile. I'm at a loss to understand why. Adjusting the rule has the following strange effects.

For rule<OutputIterator, locals<int>, std::string() > column_test;

column_test = eps [_a = 1 ] << string << lit(_a) ;  --> does not compile
column_test = eps << string [_a = 1 ] << lit(_a) ; --> compiles and produces the output  '1'.

I find this strange as I would expect it to output "bob 1"

column_test = string << eps [ _a = 1 ] << lit(_a); --> does not compile

column_test = string [ _a = 1 ] << lit(_a) [ ++_a ] << lit(_a); --> compiles and produces the output  '22'.

Does anyone have any thoughts as to what might be going on here? To me my rule  eps [_a = 1 ] << string << lit(_a) ; 
seems spiritually similar to Hartmuts rule eps[_a = 1] << (lit(_a) << eps[++_a] << " " << string) % '\n';  In
that they both intialise the local in a preceeding eps. But neither of them compile for me.

All help most gratefully received.
Thanks
Richard

Here is the program.

#pragma warning( disable : 4244 )

#include <boost/config/warning_disable.hpp>
#include <boost/spirit/include/karma.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/fusion/include/vector.hpp>
#include <boost/spirit/include/phoenix_function.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_statement.hpp>
#include <boost/spirit/include/phoenix_object.hpp>
#include <boost/spirit/include/phoenix_scope.hpp>
#include <boost/spirit/include/phoenix_bind.hpp>
#include <boost/spirit/include/phoenix_container.hpp>
#include <boost/spirit/include/phoenix_algorithm.hpp>
#include <boost/spirit/include/phoenix_fusion.hpp>
#include <boost/spirit/include/phoenix_version.hpp>
#include <boost/spirit/include/phoenix_stl.hpp>

#include <string>
#include <vector>

namespace client {

    namespace karma = boost::spirit::karma;
    namespace phoenix = boost::phoenix;
    namespace fusion = boost::fusion;

    template <typename OutputIterator>
    struct bob
        : karma::grammar<OutputIterator, karma::locals<int>, std::string() > 
    {
        bob() : bob::base_type(column_test)
        {
            using karma::debug;
            using karma::lit;
            using karma::_a;
            using karma::eps;
            using karma::string;

            column_test = eps [_a = 1 ] << string << lit(_a);
            column_test.name("column_test");
            debug (column_test);

        }

        karma::rule<OutputIterator, karma::locals<int>, std::string() > column_test;
    }; 

    template <typename OutputIterator>
    bool generate_output(OutputIterator sink, std::string const& data)
    { 
        using karma::generate;
        bob<OutputIterator> the_grammar;

        return generate(sink,
            the_grammar
            , data     //  Data to output
        );
    }
}

int main(void)
{
    std::string the_string;
    std::back_insert_iterator<std::string> sink(the_string);
    std::string v("bob"); 
    bool res = client::generate_output(sink, v);
    std::cout << "Res is : " << res << std::endl;
    std::cout << "Generated string is : " << the_string << std::endl;
    return 0;
}

This e-mail (including any attachments) is confidential, may contain
proprietary or privileged information and is intended for the named
recipient(s) only. Unintended recipients are prohibited from taking action
on the basis of information in this e-mail and must delete all copies.
Nomura will not accept responsibility or liability for the accuracy or
completeness of, or the presence of any virus or disabling code in, this
e-mail. If verification is sought please request a hard copy. Any reference
to the terms of executed transactions should be treated as preliminary only
and subject to formal written confirmation by Nomura. Nomura reserves the
right to monitor e-mail communications through its networks (in accordance
with applicable laws). No confidentiality or privilege is waived or lost by
Nomura by any mistransmission of this e-mail. Any reference to "Nomura" is
a reference to any entity in the Nomura Holdings, Inc. group. Please read
our Electronic Communications Legal Notice which forms part of this e-mail:
http://www.Nomura.com/email_disclaimer.htm

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
Öyvind Strand | 25 Jan 19:56
Picon
Gravatar

Strange error when using phoenix::if_ in SA with boost::optional as attribute

Hi,

A rule that yields a boost::optional as attribute won't compile when using qi::_1 as condition for phoenix::_if.
However, if you add a phoenix statement after the if_ statement the rule compiles.

  //Doesn't compile
  qi::rule<Iter, boost::optional<int>()> rule_a = 
    (-qi::int_)[
      phx::if_(qi::_1)[
        phx::nothing
      ]
      //Uncomment next line and it compiles
      // , phx::nothing
    ]
 ;

It doesn't help if you use another operator than -

  //Doesn't compile
  qi::rule<Iter, boost::optional< boost::variant<int, double> >() > rule_b =
    (qi::int_ | qi::double_ | qi::eps)[
      phx::if_(qi::_1)[
        phx::nothing
      ]
      //Uncomment next line and it compiles
      // , phx::nothing
    ]
  ;

The error doesn't manifest if you don't refer to qi::_1

  //Compiles
  qi::rule<Iter, boost::optional< boost::variant<int, double> >() > rule_c =
    (qi::int_ | qi::double_ | qi::eps)[
      phx::if_(phx::val(true))[
        phx::nothing
      ]
    ]
  ;

It also works if you refer to qi::_1 but don't use phoenix::if_

  //Compiles
  qi::rule<Iter, boost::optional<int>()> rule_d = 
    (-qi::int_)[
      std::cout << qi::_1
    ]
  ;

Doing the same thing as in rule_a and rule_b outside of Spirit semantic actions also works

  //Compiles
  phx::if_(arg1)[
    phx::nothing
  ]
  (boost::optional<int>(5));


Am I doing something wrong or is this a bug?

Regards

Öyvind
Attachment (test_phoenix_if.cpp): text/x-c++src, 1250 bytes
------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Spirit-general mailing list
Spirit-general <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spirit-general
richard.smart | 24 Jan 11:29
Favicon
Gravatar

Karma alternatives and the & predicate

Hi All,

I have a newbie Karma question. I've used Qi a few times before but I'm struggling to get my head around
alternatives and the & predicate in Karma. I've been through the docs and the samples and I can't figure it out.

Below is a (slightly contrived) sample program which should give an idea of what I'm trying to achieve. It
compiles for me with MSVC8.0. I'm afraid I haven't tried it on anything else yet. 

The problem, essentially, is that the input data struct contains a 'table_type' member and depending on
the value of that member the output SQL needs to be slightly different.

The alternative is posed on l.70 of the program. As the program is presented the generate step fails for the
given input.

However if you change l. 104 to be 

input.table_type = "SingleFixedRow";

then the generation succeeds.

It's clear that I am not quite saying what I want to say here but I am baffled as to how to say "If SingleFixedRow
then output some stuff else if MultipleFixedRow output something different". I've tried all manner of
combinations of moving brackets and the & around. Almost none of which compiled (and none worked)

A interesting (possibly related) problem is that when the generation succeeds (i.e. when you pass in
"SingleFixedRow") the trailing lit(')') from l.76 does not appear in the output. I'd also love to know why
that is.

All help most gratefully received.

Thanks
Richard

#include <boost/spirit/include/karma.hpp>
#include <boost/fusion/include/adapt_struct.hpp>

#include <string>
#include <vector>

namespace accumulator {

		namespace karma = boost::spirit::karma;
    	namespace phoenix = boost::phoenix;

		struct column_t
		{
			std::string column_name;
			std::string column_type;
		};

		struct data_defn_t
		{
			std::string table_name;
			std::string table_type;
			int num_header_rows;
			std::vector<column_t> columns;
		};
}

BOOST_FUSION_ADAPT_STRUCT(
    accumulator::column_t,
    (std::string, column_name)
	(std::string, column_type)
)

BOOST_FUSION_ADAPT_STRUCT(
    accumulator::data_defn_t,
    (std::string, table_name)
	(std::string, table_type)
	(int, num_header_rows)
	(std::vector<accumulator::column_t>, columns)
)

namespace accumulator {

	template <typename OutputIterator>
	struct create_table_sql_generator
		: karma::grammar<OutputIterator, data_defn_t()>
	{
		create_table_sql_generator() : create_table_sql_generator::base_type(create_table_sql)
		{
			using boost::spirit::ascii::string;
			using karma::skip;
			using karma::lit;
			using karma::int_;
			using phoenix::val;

			column = string
					 << lit(' ')
					 << string
					 ;

			columns = column % lit(',');

			create_table_sql = lit("CREATE TABLE ") 
								<<  string
								<< lit(" ( ")
								<< lit("id INTEGER PRIMARY KEY NOT NULL")
								<< lit(", info_type TEXT")
								<< lit(", qualifier TEXT")
								<< lit(", ")
								<< 
								  ( &string("SingleFixedRow") << skip[int_] << columns )
								  | ( &string("MultipleFixedRow") << skip[int_] << lit("row_id INTEGER, ") << columns )
								<< lit(')')
								;
		}

		karma::rule<OutputIterator, data_defn_t()> create_table_sql;
		karma::rule<OutputIterator, column_t()> column;
		karma::rule<OutputIterator, std::vector<column_t>()> columns;
	};

	template <typename OutputIterator>
	bool generate_create_table_sql(OutputIterator sink, data_defn_t const& acc_defn)
	{
		using karma::generate;
		using karma::lit;

		create_table_sql_generator<OutputIterator> the_grammar;

		return generate(sink,
			the_grammar
			, acc_defn     //  Data to output
		);
	}
}

int main(void)
{
	std::string the_sql;
	std::back_insert_iterator<std::string> sink(the_sql);
	accumulator::data_defn_t input;
	input.table_name = "FakeDataDefn";
	input.table_type = "MultipleFixedRow";
	input.num_header_rows = 0;
	std::vector<accumulator::column_t> the_columns;
	accumulator::column_t c1;
	c1.column_name = "a_text_column";
	c1.column_type = "TEXT";
	the_columns.push_back(c1);
	accumulator::column_t c2;
	c2.column_name = "a_double_column";
	c2.column_type = "REAL";
	the_columns.push_back(c2);
	input.columns = the_columns; 
	bool res = accumulator::generate_create_table_sql(sink, input);
	std::cout << "Res is " << res << std::endl;
	std::cout << the_sql << std::endl;
	return 0;
}

This e-mail (including any attachments) is confidential, may contain
proprietary or privileged information and is intended for the named
recipient(s) only. Unintended recipients are prohibited from taking action
on the basis of information in this e-mail and must delete all copies.
Nomura will not accept responsibility or liability for the accuracy or
completeness of, or the presence of any virus or disabling code in, this
e-mail. If verification is sought please request a hard copy. Any reference
to the terms of executed transactions should be treated as preliminary only
and subject to formal written confirmation by Nomura. Nomura reserves the
right to monitor e-mail communications through its networks (in accordance
with applicable laws). No confidentiality or privilege is waived or lost by
Nomura by any mistransmission of this e-mail. Any reference to "Nomura" is
a reference to any entity in the Nomura Holdings, Inc. group. Please read
our Electronic Communications Legal Notice which forms part of this e-mail:
http://www.Nomura.com/email_disclaimer.htm

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
Sam Hertz | 23 Jan 17:43
Picon
Gravatar

Ambiguous Parsing

Hey All,


I am having some trouble with a portion of my grammar. It seems that it is slightly ambiguous so it is causing some trouble. I am creating a parser for the Verilog hardware description language (similar to C in syntax).

In verilog, a basic variable represents a bit vector, declared like this:

reg [3:0] x;

This says that x is a bit vector with four bits. However, a variable can also be an array of bit vectors with an arbitrary number of dimensions:

reg [3:0] x[7:0][7:0];

This says that x is a two-dimensional array (eight rows, eight columns) of bit vectors with four bits.

The trouble comes with expressions. Consider the following rules:

range_expression =
lit('[') >> expression >> ':' >> expression >> ']' |
lit('[') >> expression >> ']'
;

primary =
identifier >> *('[' >> expression >> ']') >> -range_expression
;

The problem here is that the *('[' >> expression >> ']') part of the primary rule can accidentally consume the range_expression part, but they need to be treated differently.

Any ideas how to solve this issue?

Thanks,

Sam

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Spirit-general mailing list
Spirit-general <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spirit-general

Gmane