From: Terence Parr <> Date: Tue, 12 Sep 1995 00:13:02 +0000 (-0500) Subject: auto commit for import X-Git-Url: https://pd.if.org/git/?p=pccts;a=commitdiff_plain;h=e516827ddf30d5222969ff76d199ab5a36494767 auto commit for import --- 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]+"