From c4211d5f8b4f92384f79c0077238be06d7a46b1c Mon Sep 17 00:00:00 2001 From: Kiril Kovachev Date: Fri, 7 Mar 2025 15:21:43 +0000 Subject: [PATCH] Add base parser specification --- assignment.jj | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 assignment.jj diff --git a/assignment.jj b/assignment.jj new file mode 100644 index 0000000..9e9c779 --- /dev/null +++ b/assignment.jj @@ -0,0 +1,42 @@ +PARSER_BEGIN(Assignment) + class Assignment { + public static void main(String[] args) throws ParseException, TokenMgrError + { + try { + Assignment parser = new Assignment(System.in); + parser.Start(); + System.out.println("PASS"); + } catch (ParseException e) { + System.out.println("FAIL"); + System.err.println(e.currentToken.beginLine); + } + } + } +PARSER_END(Assignment) + +TOKEN : { } +TOKEN : { } +TOKEN : { } +TOKEN : { } + +void Start() : {} +{ + (ValidLine())+ +} + +// Single well-parenthesized string +void ValidLine() : {} +{ + Parens()Parens() +} + +// Recursion to allow arbitrary length of parentheses +void Parens() : {} +{ + Parens()Parens() | Epsilon() +} + +void Epsilon() : {} +{ + {} // Have to have some kind of body apparently +}