Skip to content

Commit a3029ca

Browse files
committed
2 parents d1a3500 + 2640c3a commit a3029ca

File tree

1 file changed

+75
-14
lines changed

1 file changed

+75
-14
lines changed

README.md

Lines changed: 75 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ For more details see the following:
77

88
* JavaDoc: https://sv-giampa.github.io/JointyC-Library/
99

10-
* Tutorials and template project: https://github.com/sv-giampa/JointyC-Tutorials
10+
* Tutorials Wiki: https://github.com/sv-giampa/JointyC-Tutorials/wiki
1111

12-
## 1. Introduction.
12+
* Tutorials and template project: https://github.com/sv-giampa/JointyC-Tutorials
13+
14+
## Introduction
1315

1416
JointyC is a Java library to write compilers. Its main target is to move
1517
the attention of the developer from parsing to the semantic analysis and,
@@ -27,10 +29,70 @@ the JointyC Definition Language (JDL), used to define recursive-descent
2729
parsers for context-free languages, that can be adorned with contextual
2830
information during semantic analysis.
2931

30-
31-
## 2. Software Engineering in the scope.
32-
33-
As anticipated, the most important target of JointyC is to simplify the
32+
Follows a fast presentation of the library and more detailed introduction.
33+
34+
# A very fast presentation of the idea
35+
After this very short description, really few things will be clear, but probably the power of JointyC will be one of these.
36+
37+
Execute three main steps to write a compiler with JointyC:
38+
39+
1) write your language specifics in the JointyC Definition Language:
40+
```
41+
//Language.jdl file
42+
language: yourLanguage;
43+
44+
lexicon:{
45+
myToken = /token1/$, "description of token";
46+
mySecondToken = /token2/$, "description of the second token";
47+
}
48+
49+
grammar:{
50+
axiom = nonTerminal $myToken;
51+
nonTerminal = $mySecondToken;
52+
}
53+
```
54+
55+
2) write the interpreter of the language:
56+
```
57+
//MyInterpreter.java file
58+
class MyInterpreter implements Interpreter{
59+
60+
@TerminalToken(type="yourLanguage.myToken") //bind the "firstToken" method to the "myToken" token
61+
private String firstToken(){
62+
return "myToken";
63+
}
64+
65+
@TerminalToken(type="yourLanguage.mySecondToken") //bind the "secondToken" method to the "mySecondToken" token
66+
private String secondToken(SyntaxTree tree){
67+
return tree.token();
68+
}
69+
70+
@NonTerminalToken(ruleHead="yourLanguage.axiom", ruleProduction = {"yourLanguage.nonTerminal", "$yourLanguage.myToken"}) //bind the "computeAxiom" method to the non-temrinal "axiom"
71+
private String computeAxiom(String firstToken, String secondToken){
72+
return firstToken + " - " + secondToken;
73+
}
74+
}
75+
```
76+
77+
3) instantiate the compiler:
78+
```
79+
//some main() method or façade
80+
JdlCompiler jdlc = new JdlCompiler();
81+
StandardCompiler compiler = jdlc.compileResource("Language.jdl", new MyInterpreter());
82+
83+
//...then use the compiler...
84+
String compilationResult = compiler.compile(" token1 token2 ");
85+
System.out.println(compilationResult); //prints "token1 - token2"
86+
```
87+
88+
And now, please continue reading.
89+
90+
# Goals of the library
91+
This is a more detailed presentation of the library.
92+
93+
## Software Engineering in the scope
94+
95+
As anticipated, the most important goal of JointyC is to simplify the
3496
work of the developers, not only during construction, but also during
3597
maintenance. In fact, writing a recursive descent parser may result in
3698
a difficult maintenance task. On the other hand, using a parser generator
@@ -50,16 +112,16 @@ runtime, but only loaded).
50112
The target, from the point of view of Software Engineering, is to write
51113
a parser according to its language specifics, and to modify it when the
52114
language specifics are changed or extended.
53-
More details over this process and other functionalities are described
115+
More details about this process and other functionalities are reported
54116
in the documentation and in the wiki.
55117

56118

57-
## 3. The analysis framework.
119+
## The analysis framework
58120

59121
The analysis framework is divided in three sub-modules: lexer, parser and
60122
semantic analyzer. The framework provides all the interfaces that define
61123
the functionalities for lexers, parsers and interpreters.
62-
Lexer and parser modules define a proper final implementation, indicated
124+
Lexer and parser modules define proper final implementations, named
63125
with the "Standard" prefix: the StandardLexer and the StandardParser.
64126
The semantic module provides a standard syntax tree exploring machinery,
65127
defined by the SemanticAnalyzer class. This class implements an iterative
@@ -73,7 +135,7 @@ necessarily use the JDL Compiler. Moreover, it is recommended to use the
73135
JDL Compiler, to obtain a higher maintenance and readability performance.
74136

75137

76-
## 4. The JointyC Definition Language Compiler (JDL Compiler).
138+
## The JointyC Definition Language Compiler (JDL Compiler)
77139

78140
By using the JDL Compiler it is possible to define and compile a parser
79141
and the associated lexer at run-time. The objective is to have a double
@@ -83,8 +145,7 @@ possible to divide the languages in modules, and at the same time,
83145
it is possible to design one interpreter for each language module. Then
84146
different modules and their interpreters may be composed in a single
85147
work. A JDL file is divided in two parts: lexicon and grammar. To define
86-
a lexicon for the language, regular expressions are used. Each lexicon
87-
type should be seen as a variable for the grammar. The grammar is
148+
a lexicon for the language, regular expressions are used. The grammar is
88149
expressed in BNF (Backus-Naur Form), because, in many cases, the BNF is
89150
simpler to manage during semantic analysis than the EBNF (Extended BNF).
90151
A grammar rule cannot produce directly a ground terminal, but each
@@ -93,14 +154,14 @@ allows to keep the grammar and the access to the syntax tree as generic
93154
as possible.
94155

95156

96-
## 5. Conclusions and recommendations.
157+
## Conclusions and recommendations
97158

98159
For the explained reasons, the JointyC library could be one of the best
99160
choices for designing a language for some project. It is emphasized
100161
that this library is under Apache License 2.0, and then it could be
101162
integrated also in a proprietary software, or used as a starting point
102163
to obtain an enhanced version of it. To familiarize with JointyC and its
103-
programming method, it is highly recommended to start exploring the
164+
programming logics, it is highly recommended to start exploring the
104165
provided tutorials and documentation.
105166

106167

0 commit comments

Comments
 (0)