Skip to content

Instantly share code, notes, and snippets.

@marshalhayes
Last active July 14, 2018 00:07
Show Gist options
  • Save marshalhayes/095bac74b1d3296104816f66710d9f77 to your computer and use it in GitHub Desktop.
Save marshalhayes/095bac74b1d3296104816f66710d9f77 to your computer and use it in GitHub Desktop.
An antlr4 grammar application of a C# abstract class which includes only abstract methods and variables
grammar AbstractClass;
prog : abstractclass;
abstractclass : visibility abstr clas CLASSNAME OPEN_BRACKET statement+ CLOSE_BRACKET;
visibility : ('public'|'protected'|'internal'|'private');
abstr : 'abstract';
clas : 'class';
CLASSNAME : AlphaNum+;
OPEN_BRACKET : '{';
CLOSE_BRACKET : '}';
statement : variable | (normal_func | abstr_func);
variable : visibility type VARIABLENAME;
normal_func : visibility type FUNCTIONNAME;
abstr_func : visibility abstr type FUNCTIONNAME;
type : ('bool'|'byte'|'sbyte'|'char'|'decimal'|'double'|'float'|'int'|
'uint'|'long'|'ulong'|'object'|'short'|'ushort'|'string'|'void');
FUNCTIONNAME : (AlphaNum+'();');
VARIABLENAME : (AlphaNum_LetterFirst+';');
fragment AlphaNum : [a-zA-Z0-9];
fragment AlphaNum_LetterFirst : ([a-zA-Z]AlphaNum+);
WS : [ \t\r\n]+ -> skip ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment