Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I am attempting to parse some input using Parse::RecDescent version 1.80; however, it does not appear to be parsing my grammar correctly, thinking an implicit subrule spans much more than it does. Following the trace after that confuses me; I am not sure what is going on. Full grammar follows, with comments added to indicate how PRD appears to be parsing my grammar:

# buggo, where's the case-sensitivity go, here or elsewhere? # the first subrule here... command: ( oops /\s+/ word { "(oops '$item[2])" } | ap { "(order me $item[1])" } | np ', ' ap { "(order $item[1] $item[3])" } ) ...!/\S/ { $item[1] } ap: <leftop: vp then vp> { "(actions @{$item[1]})" } # buggo, omit thens in return vp: again /\s+/ { "'again" } | verb /\s+/ <matchrule:v_$item[1]> /\s+/ { $item[2] } np: <leftop: basic_np np_con basic_np> { "(phrases @{$item[1]})" } basic_np: ( <leftop: descriptor /\s+/ descriptor> )(?) <leftop: noun /\s+/ noun> /\s+/ { "(phrases @{$item[1]} @{$item[2]})" } descriptor: article | all | other | number | possessive noun: me | pronoun | word verb: word { $::Verbs{$item[1]} } np_con: <reject> # todo # need to add to this prep: /o(:?n|ver|ff|ut of)|with(?:out)?|under|in(?:to)?| at|to|sans|from|toward/xi # buggo, doesn't parse word numbers as well as it should # should use module for that number_part: /([0-9]+)/ { $item[1] } | /one|t(?:w(?:o|e(?:lve|enty))|h(?:ree|ousand)|en)|f(?:our +|ive)| s(?:ix|even)|e(?:ight|leven)|nine|zero| (?:thir|f(?:ou?r|if)|s(?:ix|even)|eigh|nine)t(?:een|y)| hundred|[mb]illion/ix { $::Numbers{$item[1]} } number: number_part /\s+/ | number_part /\s+/ number { [$item[1], $item[1] + $item[2], $item[1] * $item[2]] ->[$item[1] <=> $item[2]] } me: 'me' | 'myself' | 'i' | 'self' pronoun: 'it' | 'him' | 'you' | 'her' | 'them' possessive: 'my' | 'his' | 'her' | 'your' article: 'the' | 'a' | 'an' all: 'all' | 'every' other: 'other' oops: 'oops' | 'o' then: ',' 'then' | 'then' | '. ' again: 'again' | 'g' # would appear to be thought to end at the right-paren here word: /([a-zA-Z\-]+)/ v_go: direction { "(go '$item[1])" } direction: /((?:n(?:orth)?|s(?:outh)?)?(?:e(?:ast)?|w(?:est)?)?|(?:up| +down))/i

RD_TRACE trace follows:

Parse::RecDescent: Treating "# buggo, where's the case-sensitivity + go, here or elsewhere?" as a comment Parse::RecDescent: Treating "command:" as a rule declaration Parse::RecDescent: Treating "( oops /\s+/ word { "(oops '$item[2]) +" } | ap { "(order me $item[1])" } | np ', ' ap { "(orde +r $item[1] $item[3])" } ) ...!/\S/ { $item[1] } a +p: <leftop: vp then vp> { "(actions @{$item[1]})" +} # buggo, omit thens in return vp: again /\s+/ { " +'again" } | verb /\s+/ <matchrule:v_$item[1]> /\s+/ { $ +item[2] } np: <leftop: basic_np np_con basic_np> { "(ph +rases @{$item[1]})" } basic_np: ( <leftop: descriptor + /\s+/ descriptor> )(?) <leftop: noun /\s+/ noun> /\s+ +/ { "(phrases @{$item[1]} @{$item[2]})" } descripto +r: article | all | other | number | possessive nou +n: me | pronoun | word verb: word { $::Verbs{$item[1]} +} np_con: <reject> # todo # need to add to this p +rep: /o(:?n|ver|ff|ut of)|with(?:out)?|under|in(?:to +)?| at|to|sans|from|toward/xi # buggo, doesn't pars +e word numbers as well as it should # should use modul +e for that number_part: /([0-9]+)/ { $item[1] } | /one|t(?:w(?:o|e(?:lve|enty))|h(?:ree|ousand)|e +n)|f(?:o ur|ive)| s(?:ix|even)|e(?:ight|leven)|nine|zero +| (?:thir|f(?:ou?r|if)|s(?:ix|even)|eigh|nine)t(? +:een|y)| hundred|[mb]illion/ix { $::Numbers{$item[1]} } +number: number_part /\s+/ | number_part /\s+/ number { [$item[1], $item[1] + $item[2], $item[1] * $ite +m[2]] - >[$item[1] <=> $item[2]] } me: 'me' | 'myself' +| 'i' | 'self' pronoun: 'it' | 'him' | 'you' | 'her' | +'them' possessive: 'my' | 'his' | 'her' | 'your' artic +le: 'the' | 'a' | 'an' all: 'all' | 'every' other: +'other' oops: 'oops' | 'o' then: ',' 'then' | 'then' | +'. ' again: 'again' | 'g' word: /([a-zA-Z\-]+ )" as +an implicit subrule Parse::RecDescent: Treating "_alternation_1_of_production_1_of_rule_command + :" as a rule declaration Parse::RecDescent: Treating "oops" as a subrule match Parse::RecDescent: Treating "/\s+/" as a /../ pattern terminal Parse::RecDescent: Treating "word" as a subrule match Parse::RecDescent: Treating "{ "(oops '$item[2])" }" as an action Parse::RecDescent: Treating "|" as a new production Parse::RecDescent: Treating "ap" as a subrule match Parse::RecDescent: Treating "{ "(order me $item[1])" }" as an acti +on Parse::RecDescent: Treating "|" as a new production Parse::RecDescent: Treating "np" as a subrule match Parse::RecDescent: Treating ", " as a literal terminal Parse::RecDescent: Treating "ap" as a subrule match Parse::RecDescent: Treating "{ "(order $item[1] $item[3])" }" as a +n action ERROR (line 8): Untranslatable item encountered: ")" Parse::RecDescent: Treating "...!" as a negative lookahead Parse::RecDescent: Treating "/\S/" as a /../ pattern terminal Parse::RecDescent: Treating "{ $item[1] }" as an action Parse::RecDescent: Treating "ap:" as a rule declaration Parse::RecDescent: Treating "<leftop:...>" as a left-associative o +perator directive Parse::RecDescent: Treating "vp" as a subrule match Parse::RecDescent: Treating "then" as a subrule match Parse::RecDescent: Treating "vp" as a subrule match Parse::RecDescent: Treating "{ "(actions @{$item[1]})" }" as an ac +tion Parse::RecDescent: Treating "# buggo, omit thens in return" as a c +omment Parse::RecDescent: Treating "vp:" as a rule declaration Parse::RecDescent: Treating "again" as a subrule match Parse::RecDescent: Treating "/\s+/" as a /../ pattern terminal Parse::RecDescent: Treating "{ "'again" }" as an action Parse::RecDescent: Treating "|" as a new production Parse::RecDescent: Treating "verb" as a subrule match Parse::RecDescent: Treating "/\s+/" as a /../ pattern terminal Parse::RecDescent: Treating "<matchrule:v_$item[1]>" as a subrule +match Parse::RecDescent: Treating "/\s+/" as a /../ pattern terminal Parse::RecDescent: Treating "{ $item[2] }" as an action Parse::RecDescent: Treating "np:" as a rule declaration Parse::RecDescent: Treating "<leftop:...>" as a left-associative o +perator directive Parse::RecDescent: Treating "basic_np" as a subrule match Parse::RecDescent: Treating "np_con" as a subrule match Parse::RecDescent: Treating "basic_np" as a subrule match Parse::RecDescent: Treating "{ "(phrases @{$item[1]})" }" as an ac +tion Parse::RecDescent: Treating "basic_np:" as a rule declaration Parse::RecDescent: Treating "_alternation_1_of_production_1_of_rule_command +" as a subrule match Parse::RecDescent: Treating "/ v_go: direction { "(go '$item[1])" +} direction: /" as a /../ pattern terminal Parse::RecDescent: Treating "( (?:n(?:orth)?|s(?:outh )" as an imp +licit subrule Parse::RecDescent: Treating "_alternation_2_of_production_1_of_rule_command + :" as a rule declaration Parse::RecDescent: Treating "( ?:n(?:orth )" as an implicit subrul +e Parse::RecDescent: Treating "_alternation_1_of_production_1_of_rule__altern +ation_2_ of_production_1_of_rule_command :" as a rule declaration ERROR (line 49): Untranslatable item encountered: "?:n(?:orth" Parse::RecDescent: Treating "_alternation_1_of_production_1_of_rule__altern +ation_2_ of_production_1_of_rule_command" as a subrule m +atch ERROR (line 49): Untranslatable item encountered: "?|s(?:outh" Parse::RecDescent: Treating "_alternation_2_of_production_1_of_rule_command +" as a subrule match ERROR (line 48): Untranslatable item encountered: "?)?(?:e(?:ast)?|w(?:est)?)?|(?:up|down))/i"

Thank you for your patience and attention.

update (broquaint): added <readmore>


In reply to Parse::RecDescent eats large part of grammar, thinking it to be implicit subrule by premchai21

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-03-28 21:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found