Created
December 29, 2016 09:17
-
-
Save wsd1/d343ea9096db775a39c0c8206cbee1ff to your computer and use it in GitHub Desktop.
This is pulse width codec for PEG.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| program_unit "程序" | |
| = desc_unit+ | |
| desc_unit "描述单元" | |
| = param:desc_unit_primitive+";" | |
| { | |
| return param; | |
| } | |
| desc_unit_primitive "描述单元中的基础单元" | |
| // | |
| = desc_unit_ref | |
| / pulse_seq_unit | |
| / pulse_global_unit | |
| //循环运算 | |
| / param1:integer"*" param2:desc_unit_ref | |
| { | |
| return { | |
| typ:"Repeat", | |
| cnt:param1, | |
| val:param2 | |
| } | |
| } | |
| //循环运算 | |
| / param1:integer"*" param2:pulse_seq_unit | |
| { | |
| return { | |
| typ:"Repeat", | |
| cnt:param1, | |
| val:param2 | |
| } | |
| } | |
| //循环运算 | |
| / param1:integer"*" param2:pulse_global_unit | |
| { | |
| return { | |
| typ:"Repeat", | |
| cnt:param1, | |
| val:param2 | |
| } | |
| } | |
| desc_unit_ref "描述单元引用" | |
| = "["param:integer"]" | |
| { | |
| return { | |
| typ:"DescUnitRef", | |
| val:param | |
| }; | |
| } | |
| pulse_seq_unit "波形单元" | |
| = "("param1:pulse_and* param2:pulse")" | |
| { | |
| var ret = param1; | |
| ret.push(param2); | |
| return { | |
| typ:"PulseSeq", | |
| val:ret | |
| }; | |
| } | |
| pulse_global_unit "全局波形单元" | |
| = "<"param:pulse">" | |
| { | |
| return { | |
| typ:"PulseGlb", | |
| val:param | |
| }; | |
| } | |
| pulse_and | |
| = | |
| param:pulse"," | |
| {return param;} | |
| pulse "Pulse" | |
| = "+"param:integer | |
| { | |
| return {s:1,w:param}; | |
| } | |
| /"-"param:integer | |
| { | |
| return {s:-1,w:param}; | |
| } | |
| /param:integer | |
| { | |
| return {s:0,w:param}; | |
| } | |
| integer "Integer" | |
| = digits:[0-9]+ { return parseInt(digits.join(""), 10); } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment