Still working on a CCL parser and really getting pretty frustrated.
I followed the surgestions in Parsing CCL (Common Command Language) commands and I've gone for the YAPP and taken the Calp.yp example and replaced the grammer with the CCL grammer (leaving out the "Set" statement for now). Compiled it using:
yapp -v myParser.yp
with one message:
1 shift/reduce conflict
Then I've written a test script using Yapp's Calc.t as template:
$^W=0; use Parse::Yapp; my($parser,$grammar); my($yapptxt); $grammar=join('',<DATA>); $parser=new Parse::Yapp(input => $grammar); $yapptxt=$parser->Output(classname => 'MyParser'); eval $yapptxt; my($parser); $parser=new MyParser(); $parser->YYData->{DATA}= [ "a and B\n" ]; $data=$parser->YYData->{DATA}[0]; print "data=[$data]\n"; exit; __DATA__ %% CCLFind: CCLFind Op Elements | Elements ; Op: 'and' | 'or' | 'not' ; # -- The above means that Elements are separated by boolean operators +. Elements: '(' CCLFind ')' #! | Set | Terms | Qualifiers Relation Terms | Qualifiers Relation '(' CCLFind ')' | Qualifiers '=' string '-' string ; # -- Elements is either a recursive definition, a result set referenc +e, a # -- list of terms, qualifiers followed by terms, qualifiers followed # -- by a recursive definition or qualifiers in a range (lower - uppe +r). #!Set: 'set' = string #!; # -- Reference to a result set Terms: Terms Prox Term | Term ; # -- Proximity of terms. Term: Term string | string ; # -- This basically means that a term may include a blank Qualifiers: Qualifiers ',' string | string ; # -- Qualifiers is a list of strings separated by comma Relation: '=' | '>=' | '<=' | '<>' | '>' | '<' ; # -- Relational operators. This really doesn't follow the ISO8777 # -- standard. Prox: '%' | '!' ; # -- Proximity operator %% sub _Error { exists $_[0]->YYData->{ERRMSG} and do { print $_[0]->YYData->{ERRMSG}; delete $_[0]->YYData->{ERRMSG}; return; }; print "Syntax error.\n"; } sub _Lexer { my($parser)=shift; $parser->YYData->{INPUT} or $parser->YYData->{INPUT} = <STDIN> or return('',undef); $parser->YYData->{INPUT}=~s/^[ \t]//; for ($parser->YYData->{INPUT}) { s/^([0-9]+(?:\.[0-9]+)?)// and return('NUM',$1); s/^([A-Za-z][A-Za-z0-9_]*)// and return('VAR',$1); s/^(.)//s and return($1,$1); } } sub Run { my($self)=shift; $self->YYParse( yylex => \&_Lexer, yyerror => \&_Error ); }
BUT this really brings me nowhere. It just returns the string I gave as argument "If there are two or more ways to do something and one of them can lead to a disaster, then one or more persons will do it"
Edgar A. Murphy, Captain in U.S. Air Force (1949)

Edited: ~Mon Oct 21 19:36:02 2002 (GMT) by footpad: Added <readmore> tag, per Consideration


In reply to Parsing CCL (Common Command Language) using YAPP by e_bachmann

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.