From e516827ddf30d5222969ff76d199ab5a36494767 Mon Sep 17 00:00:00 2001 From: Terence Parr <> Date: Mon, 11 Sep 1995 19:13:02 -0500 Subject: [PATCH] auto commit for import --- testcpp/13/test.g | 77 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100755 testcpp/13/test.g diff --git a/testcpp/13/test.g b/testcpp/13/test.g new file mode 100755 index 0000000..eaffc4f --- /dev/null +++ b/testcpp/13/test.g @@ -0,0 +1,77 @@ +/* C++ interface test of Parser Exception Handling + * + * Given input: + * + * if a+ then a=b+b; + * + * the program should respond with + * + * invalid conditional in 'if' statement + * found assignment to a + */ +<< +#include +#include "DLGLexer.h" +#include "PBlackBox.h" +typedef ANTLRCommonToken ANTLRToken; + +int main() +{ + ParserBlackBox p(stdin); + int retsignal; + p.parser()->rule(&retsignal); + return 0; +} +>> + +/* +Uncommenting this will make ANTLR think you put these handlers at the +end of each rule: + +exception + catch MismatchedToken : <> + default : <> +*/ + +#token "[\ \t]+" <> +#token "\n" <> +#token THEN "then" +#tokclass DIE { "@" "if" ID "else" } + +class PEHTest { + +rule: ( stat )+ + ; + +stat: "if" t:expr THEN stat { "else" stat } + | id:ID "=" expr ";" + <getText());>> + ; + exception[t] + default : + << + printf("invalid conditional in 'if' statement\n"); + consumeUntilToken(THEN); + >> + exception + catch MismatchedToken : + catch NoViableAlt : + catch NoSemViableAlt : + << + printf("stat:caught predefined signal\n"); + consumeUntil(DIE_set); + >> + +expr: expr1 ("\+" expr1)* + ; + +expr1 + : expr2 ("\*" expr2)* + ; + +expr2: ID + ; + +} + +#token ID "[a-z]+" -- 2.40.0