You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by jf...@apache.org on 2019/05/17 05:11:52 UTC

[plc4x] branch feature/code-gen updated: Added first stub of a grammar for Chris imaginary language.

This is an automated email from the ASF dual-hosted git repository.

jfeinauer pushed a commit to branch feature/code-gen
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/feature/code-gen by this push:
     new 3abd0f5  Added first stub of a grammar for Chris imaginary language.
3abd0f5 is described below

commit 3abd0f5346635cb552926e2fad6ff15a796091d4
Author: Julian Feinauer <j....@pragmaticminds.de>
AuthorDate: Fri May 17 07:11:27 2019 +0200

    Added first stub of a grammar for Chris imaginary language.
---
 sandbox/code-gen/src/main/antlr4/imaginary.g4 | 107 ++++++++++++++++++++++++++
 1 file changed, 107 insertions(+)

diff --git a/sandbox/code-gen/src/main/antlr4/imaginary.g4 b/sandbox/code-gen/src/main/antlr4/imaginary.g4
new file mode 100644
index 0000000..f239663
--- /dev/null
+++ b/sandbox/code-gen/src/main/antlr4/imaginary.g4
@@ -0,0 +1,107 @@
+grammar imaginary;
+
+file
+ : statement*
+ ;
+
+statement
+ : COMMENT
+ | typeDefinition
+ ;
+
+typeDefinition
+ : LBRACKET K_TYPE IDENTIFIER COMMENT? (LBRACKET fieldDefinition RBRACKET COMMENT?)+ RBRACKET
+ | LBRACKET K_DISCRIMINATED_TYPE IDENTIFIER '[length]' COMMENT? (LBRACKET fieldDefinition RBRACKET COMMENT?)+ RBRACKET
+ ;
+
+fieldDefinition
+ : K_CONST dataType IDENTIFIER expression
+ | K_RESERVED dataType expression
+ | K_IMPLICIT dataType IDENTIFIER expression
+ | K_EMBEDDED IDENTIFIER LCBRACKET context RCBRACKET
+ | K_DISCRIMINATOR dataType IDENTIFIER
+ ;
+
+
+dataType
+ : K_UINT8
+ | K_UINT16
+ ;
+
+expression
+ : TICK innerExpression TICK
+ ;
+
+innerExpression
+ : HEX_LITERAL
+ | INTEGER_LITERAL
+ | IDENTIFIER   // Variable reference
+ | innerExpression '.' IDENTIFIER // Field Reference
+ | innerExpression BinaryOperator innerExpression  // Addition
+ | '(' innerExpression ')'
+ ;
+
+context
+ : IDENTIFIER ':' expression (',' IDENTIFIER ':' expression)*
+ ;
+
+COMMENT
+ : K_COMMENT [a-zA-Z0-9,.'":()/ \t\r\n\u000C-]*
+ | '//' [a-zA-Z0-9,.'":()/ \t-]*
+ ;
+
+INTEGER_LITERAL
+ : [0-9]+
+ ;
+
+HEX_LITERAL
+ : HexNumeral
+ ;
+
+fragment HexNumeral
+ : '0' [xX] HexDigit HexDigit?;
+
+fragment HexDigit
+ : [0-9a-fA-F]
+;
+
+modifier
+ : K_CONST
+ | K_RESERVED
+ | K_IMPLICIT
+ | K_EMBEDDED
+ ;
+
+fragment K_COMMENT : '<--';
+K_CONST : 'const';
+K_RESERVED : 'reserved';
+K_IMPLICIT : 'implicit';
+K_EMBEDDED : 'embedded';
+K_DISCRIMINATOR : 'discriminator';
+K_TYPE : 'type';
+K_DISCRIMINATED_TYPE : 'discriminatedType';
+
+K_UINT8 : 'uint8';
+K_UINT16 : 'uint16';
+
+TICK : '\'';
+TIMES : 'x';
+LBRACKET : '[';
+RBRACKET : ']';
+LCBRACKET : '{';
+RCBRACKET : '}';
+
+BinaryOperator
+ : '+'
+ | '-'
+ ;
+
+ZERO : '0';
+HEX_VALUE : [0-9A-F];
+
+IDENTIFIER
+ : [A-Za-z0-9_-]+
+ ;
+
+WS  :  [ \t\r\n\u000C]+ -> skip
+;
\ No newline at end of file