Contribution:
javaParser
Headline
Recursive-descent parsing in Language:Java
Characteristics
Recursive-descent parsing is used to process a text-based representation of companies. The underlying lexer is custom-made, too. Both lexer and parser use a lookahead of 1. The lexer reports all tokens excluding whitespace. The parser relies on protected handler methods to allow for injection of semantic actions. For instance, Feature:Total is implemented by defining the handler for employees to aggregate salaries. The implementation of Feature:Cut requires ad hoc pretty printing. Such a combination of parsing and pretty printing implements Feature:Parsing and Feature:Unparsing.
Illustration
The data model is implemented as plain textual files:
company "ACME Corporation" {
department "Research" {
manager "Craig" {
address "Redmond"
salary 123456
}
employee "Erik" {
address "Utrecht"
salary 12345
}
employee "Ralf" {
address "Koblenz"
salary 1234
}
}
department "Development" {
manager "Ray" {
address "Redmond"
salary 234567
}
department "Dev1" {
manager "Klaus" {
address "Boston"
salary 23456
}
department "Dev1.1" {
manager "Karl" {
address "Riga"
salary 2345
}
employee "Joe" {
address "Wifi City"
salary 2344
}
}
}
}
}
Feature:Parsing is implemented with helper class org.softlang.company.features.recognizer.Parser:
public class Parsing {
public static void accept(String file) throws FileNotFoundException {
Acceptor a = new Acceptor();
a.accept(file);
}
public static void parse(String file) throws FileNotFoundException {
Parser p = new Parser();
p.parse(file);
}
}
Feature:Unparsing is implemented as part of Feature:Cut.
Feature:Total and Feature:Cut extend the Parser with semantic actions. For example Total:
public double getTotal() {
return total;
}
Test cases are implemented for all Namespace:Features. There is also an invalid input:
company "foobar" {
department "barfoo" {
}
}
Relationships
For plain syntax checking with Technology:ANTLR see Contribution:antlrAcceptor.
For lexer-based text processing in pure Language:Java see Contribution:javaScanner.
For lexing/tokenization with Technology:ANTLR see Contribution:antlrLexer.
For a custom made lexer in pure Language:Java see Contribution:javaLexer.
For parsing with semantic actions with Technology:ANTLR see Contribution:antlrParser.
For recursive-descent parsing in pure Language:Java] see Contribution:javaParser.
For parser combinators in pure Language:Java] see Contribution:javaParseLib.
For object/text mapping from test to companies with Technology:ANTLR see Contribution:antlrObjects.
For object/text mapping from text to trees with Technology:ANTLR see Contribution:antlrTrees.
Architecture
The contribution follows a standardized structure:
- inputs contains input files for tests
- src/main/java contains the following packages:
- org.softlang.company.features for implementations of Functional requirements.
- org.softlang.company.features.recognizer for lexer, acceptor and parser for companies.
- org.softlang.company.features for implementations of Functional requirements.
- src/test/java contains the following packages:
- org.softlang.company.tests for Technology:JUnit test cases for Namespace:Features.
Usage
This contribution uses Technology:Gradle for building. Technology:Eclipse is supported.
See https://github.com/101companies/101simplejava/blob/master/README.md
There are no revisions for this page.
User contributions
User edits
Syntax for editing wiki
For you are available next options:will make text bold.
will make text italic.
will make text underlined.
will make text striked.
will allow you to paste code headline into the page.
will allow you to link into the page.
will allow you to paste code with syntax highlight into the page. You will need to define used programming language.
will allow you to paste image into the page.
is list with bullets.
is list with numbers.
will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.
will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.
will allow your to insert code snippets from @worker.
Syntax for editing wiki
For you are available next options:will make text bold.
will make text italic.
will make text underlined.
will make text striked.
will allow you to paste code headline into the page.
will allow you to link into the page.
will allow you to paste code with syntax highlight into the page. You will need to define used programming language.
will allow you to paste image into the page.
is list with bullets.
is list with numbers.
will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.
will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.
will allow your to insert code snippets from @worker.