my debuggery grammar first, "final" grammar second

basically, name every part, keep it under six "words", stuff that repeats get a quantifier, an (s), stuff that is optional gets a quantifier of (?)

#!/usr/bin/perl -- use Parse::RecDescent; use Data::Dumper; #~ $::RD_TRACE = 1; $::RD_AUTOACTION = q { [@item] }; #~ (SBARQ #~ (WHNP #~ (WP What) #~ ) #~ (SQ #~ (VBZ is) #~ (NP #~ (NNP Head) #~ (NNP Start) #~ ) #~ ) #~ (. ?) #~ ) my $grammar= q { start :seq(s) ## seq : '('TAG (seq | word) | ("." "?")')' ## seq : '(' TAG ( seq | word ) | TAIL ')' ## seqWord: seq | word ## seq : '(' TAG seqWord TAIL ')' ## seq: '(' TAG ( seq | word ) TAIL ')' ## seq : '(' TAG ( seq(s) | word | TAIL ) ')' #~ seq : '(' TAG ( seq(s) | word ) | TAIL ')' #~ seq : opener TAG ( seq(s) | word ) | TAIL closer #~ seq : opener TAG ( seq(s) | word ) TAIL? closer #~ seq : opener TAG ( seq(s) | word ) TAIL closer ## seq : opener TAG seqtween TAIL(?) closer ## seq : '(' TAG seqtween TAIL(?) ')' seq : opener TAG seqtween TAIL(?) closer seqtween: seq(s) | word opener : '(' closer: ')' TAG : /[A-Z]+/ TAIL : "(. ?)" word : m(\w*) }; $grammar = q{ start : seq(s) seq : opener TAG sub_seq TAIL(?) closer sub_seq : seq(s) | word opener : '(' closer : ')' TAG : /[A-Z]+/ TAIL : "(. ?)" word : m(\w*) }; my $parser=Parse::RecDescent->new($grammar); my $result = $parser->start("(SBARQ (WHNP (WP What))(SQ (VBZ is)(NP (N +NP Head)(NNP Start)))(. ?))"); print Dumper($result);

In reply to Re: Parse syntactically analyzed sentence by Anonymous Monk
in thread Parse syntactically analyzed sentence by nido203

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.