Perl Monk, Perl Meditation | |
PerlMonks |
Re: Syntax highlighting EBNF grammar languageby ikegami (Patriarch) |
on Dec 05, 2004 at 08:27 UTC ( [id://412470]=note: print w/replies, xml ) | Need Help?? |
I found a few problems when I read through your grammar quickly. 1) By default, anything matching /\s+/ between tokens is ignored. That includes newlines, yet one of your tokens is a newline. I don't think that's going to work. You have to use <skip>. 2) Are you using $::RD_AUTOACTION or <autotree>? You won't get much from the grammar if you don't use either of these, or actions ({ ... }) to return selected tokens at the end of every rule. See 410587 for an example which uses actions to return selected tokens. 3) It would probably be better if you defined program as file(s) /^\Z/ rather than just file(s). 4) You defined fourcc as "'" /.{4}/ "'", which is the same as /'\s*.{4}\s'/ (with the default <skip>). I think you want fourcc: /'.{4}'/. 5) const must be above id in expr, or else true and false will be considered ids instead of bool_consts. 6) type : id | 'code' | 'handle' | 'integer' | 'real' | 'boolean' | 'string' 7) I don't know if PRD can handle your expr and binary_op. Fix:
8) Actually, unary_op is probably slightly more efficient when written as:
9) All your binary operators all have the same precendance. How to fix:
10) That which you called "const" are really literals. Literals are constant, but constants are not necessarily literals. 11) Your definition of id has a space in it, and it shouldn't. Also concerning the defintion of id, you should use (?:...) instead of (...). The former is faster, and you don't need to capture. Result: /[a-zA-Z](?:[a-zA-Z0-9_]*[a-zA-Z0-9])?/ 12) Your definition of string_const is way too greedy. It'll match up to the last double-quote in the file. You didn't include the escape mechanism. Finally, you shoulnd't allow newlines in it. Try string_const : /"(?:[^\\"\n]|\\[^\n])*"/
In Section
Seekers of Perl Wisdom
|
|