Add base parser specification
This commit is contained in:
commit
c4211d5f8b
42
assignment.jj
Normal file
42
assignment.jj
Normal file
@ -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 : { <LEFT_PAREN: "(">}
|
||||||
|
TOKEN : { <RIGHT_PAREN: ")">}
|
||||||
|
TOKEN : { <NEWLINE: "\n">}
|
||||||
|
TOKEN : { <ANY: (~[])>}
|
||||||
|
|
||||||
|
void Start() : {}
|
||||||
|
{
|
||||||
|
(ValidLine()<NEWLINE>)+<EOF>
|
||||||
|
}
|
||||||
|
|
||||||
|
// Single well-parenthesized string
|
||||||
|
void ValidLine() : {}
|
||||||
|
{
|
||||||
|
<LEFT_PAREN>Parens()<RIGHT_PAREN>Parens()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recursion to allow arbitrary length of parentheses
|
||||||
|
void Parens() : {}
|
||||||
|
{
|
||||||
|
<LEFT_PAREN>Parens()<RIGHT_PAREN>Parens() | Epsilon()
|
||||||
|
}
|
||||||
|
|
||||||
|
void Epsilon() : {}
|
||||||
|
{
|
||||||
|
{} // Have to have some kind of body apparently
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user