nitcc -
nitcc, a parser and lexer generator for Nit
nitcc is a simple LR generator for Nit programs. It features a small subset of the functionalities of SableCC 3 and 4.
How to compile
Have a valid compiler in bin/
Just run make
in the contrib/nitcc/
directory
How to run
Usage:
nitcc file.sablecc
nitcc generates a bunches of control files, a lexer, a parser, and a tester.
To compile and run the tester:
nitc file_test_parser.nit
./file_test_parser an_input_file_to_parse
Examples and regression tests
The sub-directory examples/
contains simple grammars and interpretors.
The sub-directory tests/
contains regression tests.
Features (aka TODO list)
- [x] command line tool (
nitcc
) - [x] Grammar syntax of SableCC4 (with pieces of SableCC3)
- [x] Generates a Lexer
- [x] Generates a SLR parser
- [ ] Generates a LALR parser
- [x] Generates classes for the AST and utils
For the tool (and the code)
- [x] usable
- [x] bootstrap itself (see
nitcc.sablecc
)
For the lexer (and regexp, NFA, and DFA)
- [x] Any
- [x] interval of characters and subtraction of characters
- [x] implicit priorities (by inclusion of languages)
- [x] Except and And
- [x] Shortest and Longest (but dummy semantic without lookahead)
- [x] efficient implementation of intervals
- [x] DFA minimization
For the parser (and grammar and LR)
- [x] Modifiers (
?
,*
,+
) - [x] Ignored
- [x] Rejected
- [x] Empty (but not mandatory)
- [ ] Opportunistic
- [x] Precedence
- [ ] Separator
- [x] Dangling (automatic, so mitigate the SLR limitations)
- [x] simple transformation (unchecked)
- [x] simple inlining (non automatic, except for
?
and*
)
For the AST (generated classes, utils and their API)
- [x] Common runtime-library
nitcc_runtime.nit
- [x] Terminal nodes; see
NToken
. - [x] Heterogeneous non-terminal nodes with named fields; see
NProd
. - [x] Homogeneous non-terminal nodes for lists (
+
and*
); seeNodes
. - [x] Visitor design pattern; see
Visitor
. - [x] Syntactic and lexical errors; see
NError
. - [x] positions of tokens in the input stream; see
Position
- [ ] positions of non-terminal nodes.
- [ ] API for the input source
- [ ] sane API to invoke/initialize the parser (and the lexer)
BUGS and limitations
- Limited error checking; bad grammars can produce uncompilable, or worse buggy, nit code.
- The SLR automaton is not very expressive; do not except to parse big and complex language like Nit or Java.
- The generated Nit code is inefficient and large; even if you get an acceptable grammar, do not except to parse efficiently big and complex language like Nit or Java.
- No real unicode support.
- Advanced features of SableCC4 are not planed.
Content
- nitcc: nitcc, a parser and lexer generator for Nit (contrib/nitcc)
- examples (contrib/nitcc/examples)
- blob (contrib/nitcc/examples/blob.nit)
- blob_lexer: Lexer generated by nitcc for the grammar blob (contrib/nitcc/examples/blob_lexer.nit)
- blob_parser: Parser generated by nitcc for the grammar blob (contrib/nitcc/examples/blob_parser.nit)
- blob_test_parser: Standalone parser tester for the language blob (contrib/nitcc/examples/blob_test_parser.nit)
- calc: Example of a calculation used nitcc (contrib/nitcc/examples/calc.nit)
- calc_lexer: Lexer generated by nitcc for the grammar calc (contrib/nitcc/examples/calc_lexer.nit)
- calc_parser: Parser generated by nitcc for the grammar calc (contrib/nitcc/examples/calc_parser.nit)
- calc_test_parser: Standalone parser tester for the language calc (contrib/nitcc/examples/calc_test_parser.nit)
- minilang (contrib/nitcc/examples/minilang.nit)
- minilang_lexer: Lexer generated by nitcc for the grammar minilang (contrib/nitcc/examples/minilang_lexer.nit)
- minilang_parser: Parser generated by nitcc for the grammar minilang (contrib/nitcc/examples/minilang_parser.nit)
- minilang_test_parser: Standalone parser tester for the language minilang (contrib/nitcc/examples/minilang_test_parser.nit)
- src (contrib/nitcc/src)
- autom: Finite automaton (NFA & DFA) (contrib/nitcc/src/autom.nit)
- grammar (contrib/nitcc/src/grammar.nit)
- nitcc: nitcc, a parser and lexer generator for Nit (contrib/nitcc/src/nitcc.nit)
- nitcc_lexer: Lexer generated by nitcc for the grammar nitcc (contrib/nitcc/src/nitcc_lexer.nit)
- nitcc_lexer0: Ad-hoc hand-written lexer for nitcc (contrib/nitcc/src/nitcc_lexer0.nit)
- nitcc_parser: Parser generated by nitcc for the grammar nitcc (contrib/nitcc/src/nitcc_parser.nit)
- nitcc_parser_gen: Bootstraping the nitcc parser (contrib/nitcc/src/nitcc_parser_gen.nit)
- nitcc_semantic: Semantic analysis of a sablecc grammar file (contrib/nitcc/src/nitcc_semantic.nit)
- nitcc_test_parser: Standalone parser tester for the language nitcc (contrib/nitcc/src/nitcc_test_parser.nit)
- re2nfa: Transformation of regular expression to NFA (contrib/nitcc/src/re2nfa.nit)
- regexparser: A tool to analyse and compare regular expressions (contrib/nitcc/src/regexparser.nit)
- examples (contrib/nitcc/examples)