I was thinking that a derived grammar would be unambiguous about the output format, but you would reuse many useful grammar rules.
Instead of $a := (\d+), write $a := <number_token> where number_token is itself defined as you show, or more complex such as (0|0[xX])\d+. Then, a derived grammar would override number_token to be something that formats, as opposed to something that accepts flexible input. Some standard mechanism would say "here is the string to be emitted" within the {} block of the rule.
Terminals, by definition, would need to contain code to format the output. Nonterminals just state the arrangement of terminals, and in the absence of alternation and repitition (push that down to a lower level rule) would be used as-is.
—John
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.