Created
February 22, 2016 18:57
-
-
Save rkrishnasanka/e6d7570ac15376026c7f to your computer and use it in GitHub Desktop.
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
/* | |
* This is an basic example show the various parsing and | |
*/ | |
grammar example; | |
//Parsing rules | |
//This is the statement that tells ANTLR the structure of the program. | |
programBlock | |
: programStat+; | |
//Shows that one or more of the statements should exist in the program | |
//This tells ANTLR the different kinds of statements that will be present | |
programStat | |
: combineoperationStat | |
| transferOperationStat | |
| flutterOperationStat | |
; | |
//Defines the parser tree for the combine operation syntax | |
combineoperationStat | |
: 'C' '(' INPUT_ID ',' OUTPUT_ID '->' VALVE_ID ')' | |
; | |
//Defines the parser tree for the transfer operation syntax | |
transferOperationStat | |
: '[' 'T' '(' INPUT_ID '->' OUTPUT_ID ')' VOLUMES_PER_CYCLE_INT ']' | |
REPEAT_INT | |
; | |
//Defines the parser tree for the flutter operation syntax | |
flutterOperationStat | |
: 'F' '(' VALVE_ID ')' | |
; | |
// Parameter parsing Rules | |
INPUT_ID : ID; | |
OUTPUT_ID : ID; | |
VALVE_ID : ID; | |
VOLUMES_PER_CYCLE_INT : INT; | |
REPEAT_INT : INT; | |
//Common Lexical Rules | |
ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')* | |
; // For referencing variable names, etc. | |
INT : [0-9]+ ; // Define token INT as one or more digits | |
WS : [ \t\r\n]+ -> skip ; // Define whitespace rule, toss it out | |
COMMENT : '#' ~[\r\n]* -> skip //Standard one line comments | |
; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment