From c7fb7dfd794700bf6977a907a8612e9b644e4fe4 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Mon, 4 Jul 2016 21:53:55 +0200 Subject: o Improved parser. --- cmake/elfinfo/src/main/antlr4/Test1Lexer.g4 | 22 ++++++++++++++++++++++ cmake/elfinfo/src/main/antlr4/Test1Parser.g4 | 23 +++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 cmake/elfinfo/src/main/antlr4/Test1Lexer.g4 create mode 100644 cmake/elfinfo/src/main/antlr4/Test1Parser.g4 (limited to 'cmake/elfinfo/src/main/antlr4') diff --git a/cmake/elfinfo/src/main/antlr4/Test1Lexer.g4 b/cmake/elfinfo/src/main/antlr4/Test1Lexer.g4 new file mode 100644 index 0000000..142229d --- /dev/null +++ b/cmake/elfinfo/src/main/antlr4/Test1Lexer.g4 @@ -0,0 +1,22 @@ +lexer grammar Test1Lexer; + +channels { + WHITESPACE_CHANNEL +} + +NAME : [a-z]+; + +// Characters +C_PLUS : '+'; +C_MINUS : '-'; +C_QUOTE : '"' -> skip, pushMode(STRING); + +//SPACE : [ ]; + +WS + : [ \t\r\n]+ -> channel(WHITESPACE_CHANNEL) + ; + +mode STRING; +STRING_ANY : ~'"'; +STRING_END_QUOTE : '"' -> skip, popMode; diff --git a/cmake/elfinfo/src/main/antlr4/Test1Parser.g4 b/cmake/elfinfo/src/main/antlr4/Test1Parser.g4 new file mode 100644 index 0000000..affdfe5 --- /dev/null +++ b/cmake/elfinfo/src/main/antlr4/Test1Parser.g4 @@ -0,0 +1,23 @@ +parser grammar Test1Parser; + +options { + tokenVocab = Test1Lexer; +} + +name + : NAME + | STRING_ANY* + ; + +file + : stmt* + ; + +stmt + : expr + ; + +expr + : name C_PLUS name + | name C_MINUS name + ; -- cgit v1.2.3