parser: add a basic sabblecc3 parser in Java
[nit.git] / src / parser / README.md
1 Parser and AST for the Nit language
2
3 The parser ans the AST are mostly used by all tools.
4
5 The `parser` is the tool that transform source-files into abstract syntax trees (AST) (see `parser_nodes`)
6 While the AST is a higher abstraction than blob of text, the AST is still limited and represents only *What the programmer says*.
7
8 Classes of nodes of the AST starts with the letter `A` (for most things, eg. `AClassdef`) or `T` (for token eg. `TId`), there is no real reason except historical that might be solved with a new parser.
9
10 Variable names of the AST usually starts with `n` (for node). This is also historical but some names with a `a` (to mimic the class name) remains.
11
12 ## SableCC
13
14 Most files in this directory are generated from a grammar for sablecc3 ( http://www.sablecc.org ).
15 In order to generate nit parser, you need the alternate SableCC3 generator ( http://www.mare.ee/indrek/sablecc/ ).
16
17 Moreover, the Nit language description file extends the standard SableCC3 syntax and includes parametric productions to factorize the description of the language.
18
19 In order to simplify the development of the Nit tools, files produced by the parser generator are committed in the repository; therefore Java and SableCC3 is only required to alter the Nit syntax.
20
21 ## Contents
22
23 * fact_parser.pl: Script used to factorize parser.nit
24 * Makefile: Update grammar and generate .nit files
25 * nit.sablecc3xx: Extended sablecc3 grammar (see prescc.pl)
26 * prescc.pl: Program to transform an extended sablecc3 to a standard one
27 * parser_nodes.nit: token and nodes classes hierarchy used by the parser and the lexer
28 * tables.nit, tables_nit.h: Interfaces to access the tables needed by the parser and the lexer
29 * xss/*.xss: alternate SableCC3 template files for the Nit language
30 * org/nitlanguage/gen: A Nit parser in Java, used for tests. use the `make java` rule to build it.
31
32 The following are generated but present to avoid the need of sablecc3:
33
34 * lexer.nit: generated lexer
35 * parser.nit: generated parser
36 * parser_prod.nit: All production with generated visit methods
37 * tables_nit.c: The tables needed by the parser and the lexer
38 * parser_abs.nit: Raw generated token and nodes classes used to maintain coherence of parser_nodes.nit
39
40
41 Other temp files produced by the Makefile:
42
43 * .nit.sablecc3: Sablecc3 grammar after processing
44 * .nit.sablecc3.dump: Dump of the grammar to improve sablecc3 multiple runs
45 * .parser-nofact.nit: The parser generated by SableCC3 before factorization by fact_parser.pl