I have difficulty understanding the article. In my humble opinion it is rather theoretical. Maybe I am not worthy ;-)

No, it probably means that you are not the intended target audience. Or that I did a bad job at writing.

The "slightly" is an understatement. Some of my nightmare examples to illustrate the point:

You're right, I underestimated the complexity. I thought you could just take lines, and multiple lines if they contained non-closed quoted strings.

Still you should not give up hope. I wrote a simple lexer that works for the example you gave:

use strict; use warnings; use Data::Dumper; use Math::Expression::Evaluator::Lexer qw(lex); my $d = do { local $/; <DATA> }; my @tokens = ( ['Commment', qr{/\*.*?\*/}s, sub { return }], ['Identifier', qr{[a-zA-Z_]\w+}], ['Number', qr{\d+}], ['Operator', qr{[=(),+-/*{}]}], ['Quoted String', qr{"[^"]*"}], ['Newline', qr{\n}], ['Whitespace', qr{\s+}, sub { return }], ); print Dumper lex($d, \@tokens); __DATA__ /* A 2-dimensional sequence as the value is being called in ODL */ KEYWORD = ((1,2) (3,4) (5,8) /* some comment */ 9,11)) /* A set as the value is being called in ODL */ KEYWORD = { RED, BLUE, /* some comment */ GREEN, HAZEL } /* A text string spanning multiple lines */ KEYWORD = "some text /* not a comment but part of the value! */ more text even more text" /* this is again a comment*/

This is far from ideal, but it does tokenize the data in a meaningful way, and strips comments, but not those inside quoted strings.

(The lexer in Math::Expression::Evaluator::Lexer is quite simple and not iterator-like. If you don't want to read all input at once, you need to come up with something more sophisticated.)


In reply to Re^3: Writing an ODL parser? by moritz
in thread Writing an ODL parser? by dHarry

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.