Last active
June 6, 2023 09:24
-
-
Save Arathi/846156fc4f91d24ef3dd006c5b0daaa3 to your computer and use it in GitHub Desktop.
MHRD语法
This file contains 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
grammar MHRD; | |
component | |
: inputs outputs parts wires | |
; | |
inputs | |
: INPUTS_BEGIN portsDeclare eom | |
; | |
outputs | |
: OUTPUTS_BEGIN portsDeclare eom | |
; | |
parts | |
: PARTS_BEGIN partsDeclare eom | |
; | |
wires | |
: WIRES_BEGIN wiresDeclare eom | |
; | |
portsDeclare | |
: portDeclare (CM portDeclare)* | |
; | |
portDeclare | |
: pin | |
| pinInBus | |
| bus | |
; | |
pin | |
: portName | |
; | |
pinInBus | |
: portName SL index SR | |
; | |
bus | |
: portName SL rangeBegin CL rangeEnd SR | |
; | |
portName | |
: PART_PORT_NAME | |
; | |
index | |
: NUMBER | |
; | |
amount | |
: POSITIVE_NUMBER | |
; | |
rangeBegin | |
: NUMBER | |
; | |
rangeEnd | |
: NUMBER | |
; | |
partsDeclare | |
: partDeclare (CM partDeclare)* | |
; | |
partDeclare | |
: partName partType | |
; | |
partName | |
: PART_PORT_NAME | |
; | |
partType | |
: COMPONENT_NAME | |
; | |
wiresDeclare | |
: wireDeclare (CM wireDeclare)* | |
; | |
wireDeclare | |
: wireStart TO wireEnd | |
; | |
wireStart | |
: logicLevel | |
| partPorts | |
| componentPorts | |
; | |
wireEnd | |
: partPorts | |
| componentPorts | |
; | |
logicLevel | |
: LOW | |
| HIGH | |
; | |
eom | |
: SC | |
; | |
componentPorts | |
: bus | |
| pinInBus | |
| pin | |
; | |
partPorts | |
: partName DT bus | |
| partName DT pinInBus | |
| partName DT pin | |
; | |
/* 关键字 */ | |
INPUTS_BEGIN: 'Inputs:'; | |
OUTPUTS_BEGIN: 'Outputs:'; | |
PARTS_BEGIN: 'Parts:'; | |
WIRES_BEGIN: 'Wires:'; | |
LOW: '0'; | |
HIGH: '1'; | |
/* 符号 */ | |
// semicolon | |
SC: ';'; | |
// comma | |
CM: ','; | |
// colon | |
CL: ':'; | |
// 导线连接符 | |
TO: '->'; | |
// dot | |
DT: '.'; | |
/* 定界符 */ | |
// parenthesis 圆括号 | |
PL: '('; | |
PR: ')'; | |
// square brackets 方括号 | |
SL: '['; | |
SR: ']'; | |
// angle brackets 尖括号 | |
LT: '<'; | |
GT: '>'; | |
// braces 花括号 | |
BL: '{'; | |
BR: '}'; | |
/* 模式 */ | |
// 组件名称 | |
COMPONENT_NAME | |
: [A-Z][0-9A-Z]* | |
; | |
PART_PORT_NAME | |
: [a-z][0-9A-Za-z]* | |
; | |
// 整数 | |
NUMBER | |
: [0-9]+ | |
; | |
// 正数 | |
POSITIVE_NUMBER | |
: [1-9][0-9]? | |
; | |
// 空字符 | |
WS | |
: [ \r\n\t]+ -> channel(HIDDEN) | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment