3

I have data stored in specific text format:

FIDS_A1=CF_LAST:1|line_NETCHNG:2|QoS:3; FIDS_A2=[High and Low]:[{High} – {Low}]:1|CF_LAST:2; FIDS_A3=YR_RANGE:3|VOL:3; FIDS_A4=GR_AskBid; FIDS_C3=line_BID:3|line_ASK:3;

I need to parse it and get a C# typed data structure from it.

It's not simple to write parser in C# (very many Regexps and hard code).

I heard something about Oslo\MGrammar from Microsoft. Does this tool generate C# parser code for my specific data ?

Output i need only C# code of parser without reference to other libraries.

Eugene Gluhotorenko
  • 3,094
  • 2
  • 33
  • 52

3 Answers3

1

You could have a look at the GOLD Parser Builder and the bsn GoldParser engine (which can create a typed data structure when parsing the data using a grammar built with GOLD).

There's also a CodeProject article which shows how to use this engine.

Lucero
  • 59,176
  • 9
  • 122
  • 152
  • It's good solution but result parser will contain bsn.GoldParser reference. But i need only C# source code without depending on other libs – Eugene Gluhotorenko Apr 19 '11 at 13:14
  • You can always use ILMERGE to merge the external lib into your project, so that there is no (visible) external reference. – Lucero Apr 19 '11 at 16:34
0

Parser generators don't help you avoid regexes. In fact, at least for the generators I used, a parser generator is a second stage of parsing. It accepts a stream of tokens, and outputs an abstract syntax tree.

In order to convert text to tokens, you would write a lexer, and that can include a regex or three.

If the language is simple enough, you might find it less work to write a parser from scratch than to learn how to use a parser generator.

Roman Starkov
  • 59,298
  • 38
  • 251
  • 324
0

Reading this update on M's status I don't see it coming to the market very soon.

I suggest using ANTLR, which:

  • is able to generate very powerful parsers in C# among others.
  • is a very mature product - has it's own IDE with debugger
  • uses standard EBNF grammars, so you won't invest your time in something that will die out soon
grzeg
  • 338
  • 1
  • 6