nimbleparse
nimbleparse
is a simple grammar debugging aid. It takes as input a Lex
specification, a Yacc specification, and an input file and prints any warnings
about the specifications (e.g. shift/reduce errors) as well as the resulting
parse tree to stdout. If the parse is unsuccessful it will report parsing
errors and, when possible fixes. If parsing is successful, nimbleparse
exits
with 0; if an error is detected it exits with 1.
The full command-line specification is as follows:
nimbleparse [-r <cpctplus|none>] [-y <eco|grmtools|original>] [-q] <lexer.l> <parser.y> <input file>
where:
-r
selects the recovery algorithm to be used. Defaults to cpctplus
.-y
selects the Yacc variant to be used. Defaults to original
.-q
prevents warnings (e.g. shift/reduce errors) from being reported.You can use your own Lex/Yacc files. A small repository of example grammars can be found at https://github.com/softdevteam/grammars/.
An example invocation is as follows:
``` $ cat Hello.java class Hello { public static void main(String[] args) { System.out.println("Hello world"); } } $ nimbleparse java7.l java7.y Hello.java goal compilationunit typedeclarationsopt typedeclarations typedeclaration classdeclaration modifiersopt CLASS class IDENTIFIER Hello typeparametersopt superopt interfacesopt classbody LBRACE { classbodydeclarationsopt classbodydeclarations classbodydeclaration classmemberdeclaration methoddeclaration methodheader modifiersopt modifiers modifiers modifier PUBLIC public modifier STATIC static VOID void methoddeclarator IDENTIFIER main LPAREN ( formalparameterlistopt formalparameterlist formalparameter type referencetype arraytype name simplename IDENTIFIER String dims LBRACK [ RBRACK ] variabledeclaratorid IDENTIFIER args RPAREN ) throwsopt methodbody block LBRACE { blockstatementsopt blockstatements blockstatement statement statementwithouttrailingsubstatement expressionstatement statementexpression methodinvocation qualifiedname name qualifiedname name simplename IDENTIFIER System DOT . IDENTIFIER out DOT . IDENTIFIER println LPAREN ( argumentlistopt argumentlist expression assignmentexpression conditionalexpression conditionalorexpression conditionalandexpression inclusiveorexpression exclusiveorexpression andexpression equalityexpression instanceofexpression relationalexpression shiftexpression additiveexpression multiplicativeexpression unaryexpression unaryexpressionnotplusminus postfixexpression primary primarynonewarray literal STRINGLITERAL "Hello world" RPAREN ) SEMICOLON ; RBRACE } RBRACE } $ cat SyntaxError.java class SyntaxError { int x y; } $ nimbleparse java7.l java7.y Hello.java goal compilationunit typedeclarationsopt typedeclarations typedeclaration classdeclaration modifiersopt CLASS class IDENTIFIER SyntaxError typeparametersopt superopt interfacesopt classbody LBRACE { classbodydeclarationsopt classbodydeclarations classbodydeclaration classmemberdeclaration fielddeclaration modifiersopt type primitivetype numerictype integraltype INT int variabledeclarators variabledeclarators variabledeclarator variabledeclaratorid IDENTIFIER x COMMA variabledeclarator variabledeclarator_id IDENTIFIER y SEMICOLON ; RBRACE }
Parsing error at line 2 column 11. Repair sequences found: 1: Insert , 2: Insert = 3: Delete y ```