e_bachmann has asked for the wisdom of the Perl Monks concerning the following question:

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