initial commit
This commit is contained in:
commit
85bcb906ed
77 changed files with 7183 additions and 0 deletions
12
.gitignore
vendored
Normal file
12
.gitignore
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
/data
|
||||
/work
|
||||
/logs
|
||||
/.idea
|
||||
/target
|
||||
.DS_Store
|
||||
/.settings
|
||||
/.classpath
|
||||
/.project
|
||||
/.gradle
|
||||
/build
|
||||
*~
|
33
LICENSE-jacc.txt
Normal file
33
LICENSE-jacc.txt
Normal file
|
@ -0,0 +1,33 @@
|
|||
Copyright (c) 1999-2004, Mark P Jones, Oregon Health & Science
|
||||
University (OGI School of Science & Engineering at OHSU)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or
|
||||
without modification, are permitted provided that the following
|
||||
conditions are met:
|
||||
|
||||
o Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
o Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer in the documentation and/or other materials provided
|
||||
with the distribution.
|
||||
|
||||
o Neither the name of the Oregon Health & Science University, the
|
||||
OGI School of Science & Engineering at OHSU nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
45
build.gradle
Normal file
45
build.gradle
Normal file
|
@ -0,0 +1,45 @@
|
|||
plugins {
|
||||
id "org.sonarqube" version '2.1-rc1'
|
||||
}
|
||||
|
||||
ext {
|
||||
user = 'jprante'
|
||||
name = 'jacc'
|
||||
description = 'Java implementation of Yet Another Compiler-Compiler'
|
||||
scmUrl = 'https://github.com/' + user + '/' + name
|
||||
scmConnection = 'scm:git:git://github.com/' + user + '/' + name + '.git'
|
||||
scmDeveloperConnection = 'scm:git:git://github.com/' + user + '/' + name + '.git'
|
||||
}
|
||||
|
||||
group = 'org.xbib'
|
||||
version = '2.1.0'
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'maven'
|
||||
apply plugin: 'signing'
|
||||
apply plugin: 'findbugs'
|
||||
apply plugin: 'pmd'
|
||||
apply plugin: 'checkstyle'
|
||||
apply plugin: 'jacoco'
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
url "http://xbib.org/repository"
|
||||
}
|
||||
}
|
||||
|
||||
configurations {
|
||||
wagon
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testCompile 'junit:junit:4.12'
|
||||
wagon 'org.apache.maven.wagon:wagon-ssh-external:2.10'
|
||||
}
|
||||
|
||||
apply from: 'gradle/publish.gradle'
|
||||
apply from: 'gradle/sonarqube.gradle'
|
323
config/checkstyle/checkstyle.xml
Normal file
323
config/checkstyle/checkstyle.xml
Normal file
|
@ -0,0 +1,323 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE module PUBLIC
|
||||
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
|
||||
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
|
||||
|
||||
<!-- This is a checkstyle configuration file. For descriptions of
|
||||
what the following rules do, please see the checkstyle configuration
|
||||
page at http://checkstyle.sourceforge.net/config.html -->
|
||||
|
||||
<module name="Checker">
|
||||
|
||||
<module name="FileTabCharacter">
|
||||
<!-- Checks that there are no tab characters in the file.
|
||||
-->
|
||||
</module>
|
||||
|
||||
<module name="NewlineAtEndOfFile">
|
||||
<property name="lineSeparator" value="lf"/>
|
||||
</module>
|
||||
|
||||
<module name="RegexpSingleline">
|
||||
<!-- Checks that FIXME is not used in comments. TODO is preferred.
|
||||
-->
|
||||
<property name="format" value="((//.*)|(\*.*))FIXME" />
|
||||
<property name="message" value='TODO is preferred to FIXME. e.g. "TODO(johndoe): Refactor when v2 is released."' />
|
||||
</module>
|
||||
|
||||
<module name="RegexpSingleline">
|
||||
<!-- Checks that TODOs are named. (Actually, just that they are followed
|
||||
by an open paren.)
|
||||
-->
|
||||
<property name="format" value="((//.*)|(\*.*))TODO[^(]" />
|
||||
<property name="message" value='All TODOs should be named. e.g. "TODO(johndoe): Refactor when v2 is released."' />
|
||||
</module>
|
||||
|
||||
<module name="JavadocPackage">
|
||||
<!-- Checks that each Java package has a Javadoc file used for commenting.
|
||||
Only allows a package-info.java, not package.html. -->
|
||||
</module>
|
||||
|
||||
<!-- All Java AST specific tests live under TreeWalker module. -->
|
||||
<module name="TreeWalker">
|
||||
|
||||
<!--
|
||||
|
||||
IMPORT CHECKS
|
||||
|
||||
-->
|
||||
|
||||
<module name="RedundantImport">
|
||||
<!-- Checks for redundant import statements. -->
|
||||
<property name="severity" value="error"/>
|
||||
</module>
|
||||
|
||||
<module name="ImportOrder">
|
||||
<!-- Checks for out of order import statements. -->
|
||||
|
||||
<property name="severity" value="warning"/>
|
||||
<property name="groups" value="com,junit,net,org,java,javax"/>
|
||||
<!-- This ensures that static imports go first. -->
|
||||
<property name="option" value="top"/>
|
||||
<property name="tokens" value="STATIC_IMPORT, IMPORT"/>
|
||||
</module>
|
||||
|
||||
<!--
|
||||
|
||||
JAVADOC CHECKS
|
||||
|
||||
-->
|
||||
|
||||
<!-- Checks for Javadoc comments. -->
|
||||
<!-- See http://checkstyle.sf.net/config_javadoc.html -->
|
||||
<module name="JavadocMethod">
|
||||
<property name="scope" value="protected"/>
|
||||
<property name="severity" value="warning"/>
|
||||
<property name="allowMissingJavadoc" value="true"/>
|
||||
<property name="allowMissingParamTags" value="true"/>
|
||||
<property name="allowMissingReturnTag" value="true"/>
|
||||
<property name="allowMissingThrowsTags" value="true"/>
|
||||
<property name="allowThrowsTagsForSubclasses" value="true"/>
|
||||
<property name="allowUndeclaredRTE" value="true"/>
|
||||
</module>
|
||||
|
||||
<module name="JavadocType">
|
||||
<property name="scope" value="protected"/>
|
||||
<property name="severity" value="error"/>
|
||||
</module>
|
||||
|
||||
<module name="JavadocStyle">
|
||||
<property name="severity" value="warning"/>
|
||||
</module>
|
||||
|
||||
<!--
|
||||
|
||||
NAMING CHECKS
|
||||
|
||||
-->
|
||||
|
||||
<!-- Item 38 - Adhere to generally accepted naming conventions -->
|
||||
|
||||
<module name="PackageName">
|
||||
<!-- Validates identifiers for package names against the
|
||||
supplied expression. -->
|
||||
<!-- Here the default checkstyle rule restricts package name parts to
|
||||
seven characters, this is not in line with common practice at Google.
|
||||
-->
|
||||
<property name="format" value="^[a-z]+(\.[a-z][a-z0-9]{1,})*$"/>
|
||||
<property name="severity" value="warning"/>
|
||||
</module>
|
||||
|
||||
<module name="TypeNameCheck">
|
||||
<!-- Validates static, final fields against the
|
||||
expression "^[A-Z][a-zA-Z0-9]*$". -->
|
||||
<metadata name="altname" value="TypeName"/>
|
||||
<property name="severity" value="warning"/>
|
||||
</module>
|
||||
|
||||
<module name="ConstantNameCheck">
|
||||
<!-- Validates non-private, static, final fields against the supplied
|
||||
public/package final fields "^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$". -->
|
||||
<metadata name="altname" value="ConstantName"/>
|
||||
<property name="applyToPublic" value="true"/>
|
||||
<property name="applyToProtected" value="true"/>
|
||||
<property name="applyToPackage" value="true"/>
|
||||
<property name="applyToPrivate" value="false"/>
|
||||
<property name="format" value="^([A-Z][A-Z0-9]*(_[A-Z0-9]+)*|FLAG_.*)$"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Variable ''{0}'' should be in ALL_CAPS (if it is a constant) or be private (otherwise)."/>
|
||||
<property name="severity" value="warning"/>
|
||||
</module>
|
||||
|
||||
<module name="StaticVariableNameCheck">
|
||||
<!-- Validates static, non-final fields against the supplied
|
||||
expression "^[a-z][a-zA-Z0-9]*_?$". -->
|
||||
<metadata name="altname" value="StaticVariableName"/>
|
||||
<property name="applyToPublic" value="true"/>
|
||||
<property name="applyToProtected" value="true"/>
|
||||
<property name="applyToPackage" value="true"/>
|
||||
<property name="applyToPrivate" value="true"/>
|
||||
<property name="format" value="^[a-z][a-zA-Z0-9]*_?$"/>
|
||||
<property name="severity" value="warning"/>
|
||||
</module>
|
||||
|
||||
<module name="MemberNameCheck">
|
||||
<!-- Validates non-static members against the supplied expression. -->
|
||||
<metadata name="altname" value="MemberName"/>
|
||||
<property name="applyToPublic" value="true"/>
|
||||
<property name="applyToProtected" value="true"/>
|
||||
<property name="applyToPackage" value="true"/>
|
||||
<property name="applyToPrivate" value="true"/>
|
||||
<property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
|
||||
<property name="severity" value="warning"/>
|
||||
</module>
|
||||
|
||||
<module name="MethodNameCheck">
|
||||
<!-- Validates identifiers for method names. -->
|
||||
<metadata name="altname" value="MethodName"/>
|
||||
<property name="format" value="^[a-z][a-zA-Z0-9]*(_[a-zA-Z0-9]+)*$"/>
|
||||
<property name="severity" value="warning"/>
|
||||
</module>
|
||||
|
||||
<module name="ParameterName">
|
||||
<!-- Validates identifiers for method parameters against the
|
||||
expression "^[a-z][a-zA-Z0-9]*$". -->
|
||||
<property name="severity" value="warning"/>
|
||||
</module>
|
||||
|
||||
<module name="LocalFinalVariableName">
|
||||
<!-- Validates identifiers for local final variables against the
|
||||
expression "^[a-z][a-zA-Z0-9]*$". -->
|
||||
<property name="severity" value="warning"/>
|
||||
</module>
|
||||
|
||||
<module name="LocalVariableName">
|
||||
<!-- Validates identifiers for local variables against the
|
||||
expression "^[a-z][a-zA-Z0-9]*$". -->
|
||||
<property name="severity" value="warning"/>
|
||||
</module>
|
||||
|
||||
|
||||
<!--
|
||||
|
||||
LENGTH and CODING CHECKS
|
||||
|
||||
-->
|
||||
|
||||
<module name="LineLength">
|
||||
<!-- Checks if a line is too long. -->
|
||||
<property name="max" value="${com.puppycrawl.tools.checkstyle.checks.sizes.LineLength.max}" default="128"/>
|
||||
<property name="severity" value="error"/>
|
||||
|
||||
<!--
|
||||
The default ignore pattern exempts the following elements:
|
||||
- import statements
|
||||
- long URLs inside comments
|
||||
-->
|
||||
|
||||
<property name="ignorePattern"
|
||||
value="${com.puppycrawl.tools.checkstyle.checks.sizes.LineLength.ignorePattern}"
|
||||
default="^(package .*;\s*)|(import .*;\s*)|( *(\*|//).*https?://.*)$"/>
|
||||
</module>
|
||||
|
||||
<module name="LeftCurly">
|
||||
<!-- Checks for placement of the left curly brace ('{'). -->
|
||||
<property name="severity" value="warning"/>
|
||||
</module>
|
||||
|
||||
<module name="RightCurly">
|
||||
<!-- Checks right curlies on CATCH, ELSE, and TRY blocks are on
|
||||
the same line. e.g., the following example is fine:
|
||||
<pre>
|
||||
if {
|
||||
...
|
||||
} else
|
||||
</pre>
|
||||
-->
|
||||
<!-- This next example is not fine:
|
||||
<pre>
|
||||
if {
|
||||
...
|
||||
}
|
||||
else
|
||||
</pre>
|
||||
-->
|
||||
<property name="option" value="same"/>
|
||||
<property name="severity" value="warning"/>
|
||||
</module>
|
||||
|
||||
<!-- Checks for braces around if and else blocks -->
|
||||
<module name="NeedBraces">
|
||||
<property name="severity" value="warning"/>
|
||||
<property name="tokens" value="LITERAL_IF, LITERAL_ELSE, LITERAL_FOR, LITERAL_WHILE, LITERAL_DO"/>
|
||||
</module>
|
||||
|
||||
<module name="UpperEll">
|
||||
<!-- Checks that long constants are defined with an upper ell.-->
|
||||
<property name="severity" value="error"/>
|
||||
</module>
|
||||
|
||||
<module name="FallThrough">
|
||||
<!-- Warn about falling through to the next case statement. Similar to
|
||||
javac -Xlint:fallthrough, but the check is suppressed if a single-line comment
|
||||
on the last non-blank line preceding the fallen-into case contains 'fall through' (or
|
||||
some other variants which we don't publicized to promote consistency).
|
||||
-->
|
||||
<property name="reliefPattern"
|
||||
value="fall through|Fall through|fallthru|Fallthru|falls through|Falls through|fallthrough|Fallthrough|No break|NO break|no break|continue on"/>
|
||||
<property name="severity" value="error"/>
|
||||
</module>
|
||||
|
||||
|
||||
<!--
|
||||
|
||||
MODIFIERS CHECKS
|
||||
|
||||
-->
|
||||
|
||||
<module name="ModifierOrder">
|
||||
<!-- Warn if modifier order is inconsistent with JLS3 8.1.1, 8.3.1, and
|
||||
8.4.3. The prescribed order is:
|
||||
public, protected, private, abstract, static, final, transient, volatile,
|
||||
synchronized, native, strictfp
|
||||
-->
|
||||
</module>
|
||||
|
||||
|
||||
<!--
|
||||
|
||||
WHITESPACE CHECKS
|
||||
|
||||
-->
|
||||
|
||||
<module name="WhitespaceAround">
|
||||
<!-- Checks that various tokens are surrounded by whitespace.
|
||||
This includes most binary operators and keywords followed
|
||||
by regular or curly braces.
|
||||
-->
|
||||
<property name="tokens" value="ASSIGN, BAND, BAND_ASSIGN, BOR,
|
||||
BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR, BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN,
|
||||
EQUAL, GE, GT, LAND, LE, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE,
|
||||
LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_RETURN,
|
||||
LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS,
|
||||
MINUS_ASSIGN, MOD, MOD_ASSIGN, NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION,
|
||||
SL, SL_ASSIGN, SR_ASSIGN, STAR, STAR_ASSIGN"/>
|
||||
<property name="severity" value="error"/>
|
||||
</module>
|
||||
|
||||
<module name="WhitespaceAfter">
|
||||
<!-- Checks that commas, semicolons and typecasts are followed by
|
||||
whitespace.
|
||||
-->
|
||||
<property name="tokens" value="COMMA, SEMI, TYPECAST"/>
|
||||
</module>
|
||||
|
||||
<module name="NoWhitespaceAfter">
|
||||
<!-- Checks that there is no whitespace after various unary operators.
|
||||
Linebreaks are allowed.
|
||||
-->
|
||||
<property name="tokens" value="BNOT, DEC, DOT, INC, LNOT, UNARY_MINUS,
|
||||
UNARY_PLUS"/>
|
||||
<property name="allowLineBreaks" value="true"/>
|
||||
<property name="severity" value="error"/>
|
||||
</module>
|
||||
|
||||
<module name="NoWhitespaceBefore">
|
||||
<!-- Checks that there is no whitespace before various unary operators.
|
||||
Linebreaks are allowed.
|
||||
-->
|
||||
<property name="tokens" value="SEMI, DOT, POST_DEC, POST_INC"/>
|
||||
<property name="allowLineBreaks" value="true"/>
|
||||
<property name="severity" value="error"/>
|
||||
</module>
|
||||
|
||||
<module name="ParenPad">
|
||||
<!-- Checks that there is no whitespace before close parens or after
|
||||
open parens.
|
||||
-->
|
||||
<property name="severity" value="warning"/>
|
||||
</module>
|
||||
|
||||
</module>
|
||||
</module>
|
||||
|
104
gradle/publish.gradle
Normal file
104
gradle/publish.gradle
Normal file
|
@ -0,0 +1,104 @@
|
|||
|
||||
task xbibUpload(type: Upload) {
|
||||
configuration = configurations.archives
|
||||
uploadDescriptor = true
|
||||
repositories {
|
||||
if (project.hasProperty("xbibUsername")) {
|
||||
mavenDeployer {
|
||||
configuration = configurations.wagon
|
||||
repository(url: 'scpexe://xbib.org/repository') {
|
||||
authentication(userName: xbibUsername, privateKey: xbibPrivateKey)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task sonaTypeUpload(type: Upload) {
|
||||
configuration = configurations.archives
|
||||
uploadDescriptor = true
|
||||
repositories {
|
||||
if (project.hasProperty('ossrhUsername')) {
|
||||
mavenDeployer {
|
||||
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
|
||||
repository(url: 'https://oss.sonatype.org/service/local/staging/deploy/maven2') {
|
||||
authentication(userName: ossrhUsername, password: ossrhPassword)
|
||||
}
|
||||
snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots') {
|
||||
authentication(userName: ossrhUsername, password: ossrhPassword)
|
||||
}
|
||||
pom.project {
|
||||
name name
|
||||
description description
|
||||
packaging 'jar'
|
||||
inceptionYear '2012'
|
||||
url scmUrl
|
||||
organization {
|
||||
name 'xbib'
|
||||
url 'http://xbib.org'
|
||||
}
|
||||
developers {
|
||||
developer {
|
||||
id user
|
||||
name 'Jörg Prante'
|
||||
email 'joergprante@gmail.com'
|
||||
url 'https://github.com/jprante'
|
||||
}
|
||||
}
|
||||
scm {
|
||||
url scmUrl
|
||||
connection scmConnection
|
||||
developerConnection scmDeveloperConnection
|
||||
}
|
||||
licenses {
|
||||
license {
|
||||
name 'The Apache License, Version 2.0'
|
||||
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
task hbzUpload(type: Upload) {
|
||||
configuration = configurations.archives
|
||||
uploadDescriptor = true
|
||||
repositories {
|
||||
if (project.hasProperty('hbzUserName')) {
|
||||
mavenDeployer {
|
||||
configuration = configurations.wagon
|
||||
beforeDeployment { MavenDeployment deployment ->
|
||||
signing.signPom(deployment)
|
||||
}
|
||||
repository(url: uri(hbzUrl)) {
|
||||
authentication(userName: hbzUserName, privateKey: hbzPrivateKey)
|
||||
}
|
||||
pom.project {
|
||||
developers {
|
||||
developer {
|
||||
id 'jprante'
|
||||
name 'Jörg Prante'
|
||||
email 'joergprante@gmail.com'
|
||||
url 'https://github.com/jprante'
|
||||
}
|
||||
}
|
||||
scm {
|
||||
url 'https://github.com/xbib/groovy-webapp'
|
||||
connection 'scm:git:git://github.com/xbib/groovy-webapp.git'
|
||||
developerConnection 'scm:git:git://github.com/xbib/groovy-webapp.git'
|
||||
}
|
||||
inceptionYear '2016'
|
||||
licenses {
|
||||
license {
|
||||
name 'The Apache License, Version 2.0'
|
||||
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
42
gradle/sonarqube.gradle
Normal file
42
gradle/sonarqube.gradle
Normal file
|
@ -0,0 +1,42 @@
|
|||
tasks.withType(Checkstyle) {
|
||||
ignoreFailures = true
|
||||
reports {
|
||||
xml.enabled = true
|
||||
html.enabled = true
|
||||
}
|
||||
}
|
||||
tasks.withType(Pmd) {
|
||||
ignoreFailures = true
|
||||
reports {
|
||||
xml.enabled = true
|
||||
html.enabled = true
|
||||
}
|
||||
}
|
||||
tasks.withType(FindBugs) {
|
||||
ignoreFailures = true
|
||||
reports {
|
||||
xml.enabled = true
|
||||
html.enabled = false
|
||||
}
|
||||
}
|
||||
jacocoTestReport {
|
||||
reports {
|
||||
xml.enabled true
|
||||
csv.enabled false
|
||||
xml.destination "${buildDir}/reports/jacoco-xml"
|
||||
html.destination "${buildDir}/reports/jacoco-html"
|
||||
}
|
||||
}
|
||||
|
||||
sonarqube {
|
||||
properties {
|
||||
property "sonar.projectName", "jacc"
|
||||
property "sonar.sourceEncoding", "UTF-8"
|
||||
property "sonar.language", "java"
|
||||
property "sonar.sources", "src/main/java"
|
||||
property "sonar.tests", "src/test/java"
|
||||
property "sonar.scm.provider", "git"
|
||||
property "sonar.java.coveragePlugin", "jacoco"
|
||||
property "sonar.junit.reportsPath", "build/test-results/test/"
|
||||
}
|
||||
}
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
#Sat Oct 22 21:01:39 CEST 2016
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-3.1-bin.zip
|
169
gradlew
vendored
Executable file
169
gradlew
vendored
Executable file
|
@ -0,0 +1,169 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn ( ) {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die ( ) {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
|
||||
function splitJvmOpts() {
|
||||
JVM_OPTS=("$@")
|
||||
}
|
||||
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
|
||||
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
|
||||
|
||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||
if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then
|
||||
cd "$(dirname "$0")"
|
||||
fi
|
||||
|
||||
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
|
84
gradlew.bat
vendored
Normal file
84
gradlew.bat
vendored
Normal file
|
@ -0,0 +1,84 @@
|
|||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
1
settings.gradle
Normal file
1
settings.gradle
Normal file
|
@ -0,0 +1 @@
|
|||
rootProject.name = 'jacc'
|
77
src/main/java/org/xbib/jacc/Conflicts.java
Normal file
77
src/main/java/org/xbib/jacc/Conflicts.java
Normal file
|
@ -0,0 +1,77 @@
|
|||
package org.xbib.jacc;
|
||||
|
||||
import org.xbib.jacc.grammar.Grammar;
|
||||
import org.xbib.jacc.grammar.Machine;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Conflicts {
|
||||
|
||||
private int type;
|
||||
private int arg1;
|
||||
private int arg2;
|
||||
private Grammar.Symbol sym;
|
||||
private Conflicts next;
|
||||
|
||||
private Conflicts(int i, int j, int k, Grammar.Symbol symbol, Conflicts conflicts) {
|
||||
type = i;
|
||||
arg1 = j;
|
||||
arg2 = k;
|
||||
sym = symbol;
|
||||
next = conflicts;
|
||||
}
|
||||
|
||||
static Conflicts sr(int i, int j, Grammar.Symbol symbol, Conflicts conflicts) {
|
||||
return append(conflicts, new Conflicts(0, i, j, symbol, null));
|
||||
}
|
||||
|
||||
static Conflicts rr(int i, int j, Grammar.Symbol symbol, Conflicts conflicts) {
|
||||
return append(conflicts, new Conflicts(1, i, j, symbol, null));
|
||||
}
|
||||
|
||||
private static Conflicts append(Conflicts conflicts, Conflicts conflicts1) {
|
||||
if (conflicts == null) {
|
||||
return conflicts1;
|
||||
}
|
||||
Conflicts conflicts2;
|
||||
conflicts2 = conflicts;
|
||||
while (conflicts2.next != null) {
|
||||
conflicts2 = conflicts2.next;
|
||||
}
|
||||
conflicts2.next = conflicts1;
|
||||
return conflicts;
|
||||
}
|
||||
|
||||
static String describe(Machine machine, int i, Conflicts conflicts) {
|
||||
if (conflicts == null) {
|
||||
return "";
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String s = System.getProperty("line.separator", "\n");
|
||||
for (; conflicts != null; conflicts = conflicts.next) {
|
||||
sb.append(i);
|
||||
sb.append(": ");
|
||||
if (conflicts.type == 0) {
|
||||
sb.append("shift/reduce conflict (");
|
||||
if (conflicts.arg1 < 0) {
|
||||
sb.append("$end");
|
||||
} else {
|
||||
sb.append("shift ");
|
||||
sb.append(conflicts.arg1);
|
||||
}
|
||||
sb.append(" and red'n ");
|
||||
sb.append(machine.reduceItem(i, conflicts.arg2).getSeqNo());
|
||||
} else {
|
||||
sb.append("reduce/reduce conflict (red'ns ");
|
||||
sb.append(machine.reduceItem(i, conflicts.arg1).getSeqNo());
|
||||
sb.append(" and ");
|
||||
sb.append(machine.reduceItem(i, conflicts.arg2).getSeqNo());
|
||||
}
|
||||
sb.append(") on ");
|
||||
sb.append(conflicts.sym.getName());
|
||||
sb.append(s);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
58
src/main/java/org/xbib/jacc/Fixity.java
Normal file
58
src/main/java/org/xbib/jacc/Fixity.java
Normal file
|
@ -0,0 +1,58 @@
|
|||
package org.xbib.jacc;
|
||||
|
||||
class Fixity {
|
||||
|
||||
private static final int LEFT = 1;
|
||||
private static final int NONASS = 2;
|
||||
private static final int RIGHT = 3;
|
||||
private int assoc;
|
||||
private int prec;
|
||||
|
||||
private Fixity(int i, int j) {
|
||||
assoc = i;
|
||||
prec = j;
|
||||
}
|
||||
|
||||
public static Fixity left(int i) {
|
||||
return new Fixity(LEFT, i);
|
||||
}
|
||||
|
||||
static Fixity nonass(int i) {
|
||||
return new Fixity(NONASS, i);
|
||||
}
|
||||
|
||||
static Fixity right(int i) {
|
||||
return new Fixity(RIGHT, i);
|
||||
}
|
||||
|
||||
static int which(Fixity fixity, Fixity fixity1) {
|
||||
if (fixity != null && fixity1 != null) {
|
||||
if (fixity.prec > fixity1.prec) {
|
||||
return LEFT;
|
||||
}
|
||||
if (fixity.prec < fixity1.prec) {
|
||||
return RIGHT;
|
||||
}
|
||||
if (fixity.assoc == LEFT && fixity1.assoc == LEFT) {
|
||||
return LEFT;
|
||||
}
|
||||
if (fixity.assoc == RIGHT && fixity1.assoc == RIGHT) {
|
||||
return RIGHT;
|
||||
}
|
||||
}
|
||||
return NONASS;
|
||||
}
|
||||
|
||||
boolean equalsFixity(Fixity fixity) {
|
||||
return assoc == fixity.assoc && prec == fixity.prec;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof Fixity && equalsFixity((Fixity) obj);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return assoc ^ prec;
|
||||
}
|
||||
}
|
201
src/main/java/org/xbib/jacc/Jacc.java
Normal file
201
src/main/java/org/xbib/jacc/Jacc.java
Normal file
|
@ -0,0 +1,201 @@
|
|||
package org.xbib.jacc;
|
||||
|
||||
import org.xbib.jacc.compiler.ConsoleHandler;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class Jacc {
|
||||
|
||||
public Jacc() {
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
NameList namelist = null;
|
||||
String s = ".jacc";
|
||||
Settings settings = new Settings();
|
||||
boolean flag = true;
|
||||
boolean flag1 = true;
|
||||
boolean flag2 = false;
|
||||
boolean flag4 = false;
|
||||
NameList namelist1 = null;
|
||||
NameList namelist2 = null;
|
||||
boolean flag5 = false;
|
||||
String dir = null;
|
||||
Writer writer = new BufferedWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8));
|
||||
label0:
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
String s1 = args[i];
|
||||
if (s1.startsWith("-")) {
|
||||
if (s1.length() == 1) {
|
||||
usage("Missing command line options");
|
||||
}
|
||||
int j = 1;
|
||||
do {
|
||||
if (j >= s1.length()) {
|
||||
continue label0;
|
||||
}
|
||||
switch (s1.charAt(j)) {
|
||||
case 102: // 'f'
|
||||
flag4 = true;
|
||||
break;
|
||||
|
||||
case 112: // 'p'
|
||||
flag = false;
|
||||
break;
|
||||
|
||||
case 116: // 't'
|
||||
flag1 = false;
|
||||
break;
|
||||
|
||||
case 118: // 'v'
|
||||
flag2 = true;
|
||||
break;
|
||||
|
||||
case 48: // '0'
|
||||
settings.setMachineType(0);
|
||||
break;
|
||||
|
||||
case 115: // 's'
|
||||
settings.setMachineType(1);
|
||||
break;
|
||||
|
||||
case 97: // 'a'
|
||||
settings.setMachineType(2);
|
||||
break;
|
||||
|
||||
case 101: // 'e'
|
||||
if (i + 1 >= args.length) {
|
||||
usage("Missing filename for -e option");
|
||||
}
|
||||
namelist1 = new NameList(args[++i], namelist1);
|
||||
break;
|
||||
|
||||
case 114: // 'r'
|
||||
if (i + 1 >= args.length) {
|
||||
usage("Missing filename for -r option");
|
||||
}
|
||||
namelist2 = new NameList(args[++i], namelist2);
|
||||
break;
|
||||
|
||||
case 110: // 'n'
|
||||
flag5 = true;
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
if (i + 1 >= args.length) {
|
||||
usage("Missing directory for -d option");
|
||||
}
|
||||
dir = args[++i];
|
||||
break;
|
||||
|
||||
default:
|
||||
usage("Unrecognized command line option " + s1.charAt(j));
|
||||
break;
|
||||
}
|
||||
j++;
|
||||
} while (true);
|
||||
}
|
||||
if (!s1.endsWith(s)) {
|
||||
usage("Input file must have \"" + s + "\" suffix");
|
||||
} else {
|
||||
namelist = new NameList(s1, namelist);
|
||||
}
|
||||
}
|
||||
|
||||
if (namelist == null) {
|
||||
usage("No input file(s) specified");
|
||||
}
|
||||
ConsoleHandler simplehandler = new ConsoleHandler();
|
||||
String s2 = namelist.getFirst();
|
||||
int k = 1 + Math.max(s2.lastIndexOf('\\'), s2.lastIndexOf('/'));
|
||||
dir = dir == null ? s2.substring(0, k) : dir;
|
||||
String s4 = s2.substring(k, s2.length() - s.length());
|
||||
final JaccJob job = new JaccJob(simplehandler, writer, settings);
|
||||
NameList.visit(namelist, new NameList.Visitor() {
|
||||
public void visit(String s5) throws IOException {
|
||||
job.parseGrammarFile(s5);
|
||||
}
|
||||
});
|
||||
job.buildTables();
|
||||
settings.fillBlanks(s4);
|
||||
NameList.visit(namelist1, new NameList.Visitor() {
|
||||
public void visit(String s5) throws IOException {
|
||||
job.readErrorExamples(s5);
|
||||
}
|
||||
});
|
||||
if (simplehandler.getNumFailures() > 0) {
|
||||
return;
|
||||
}
|
||||
if (flag) {
|
||||
(new ParserOutput(simplehandler, job)).write(dir + settings.getClassName() + ".java");
|
||||
}
|
||||
if (flag1) {
|
||||
(new TokensOutput(simplehandler, job)).write(dir + settings.getInterfaceName() + ".java");
|
||||
}
|
||||
if (flag2) {
|
||||
(new TextOutput(simplehandler, job, flag4)).write(dir + s4 + ".output");
|
||||
}
|
||||
final boolean showState = flag5;
|
||||
NameList.visit(namelist2, new NameList.Visitor() {
|
||||
public void visit(String s5) throws IOException {
|
||||
job.readRunExample(s5, showState);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void usage(String s) {
|
||||
System.err.println(s);
|
||||
System.err.println("usage: jacc [options] file.jacc ...");
|
||||
System.err.println("options (individually, or in combination):");
|
||||
System.err.println(" -p do not generate parser");
|
||||
System.err.println(" -t do not generate token specification");
|
||||
System.err.println(" -v output text description of machine");
|
||||
System.err.println(" -f show first/follow sets (with -h or -v)");
|
||||
System.err.println(" -a treat as LALR(1) grammar (default)");
|
||||
System.err.println(" -s treat as SLR(1) grammar");
|
||||
System.err.println(" -0 treat as LR(0) grammar");
|
||||
System.err.println(" -r file run parser on input in file");
|
||||
System.err.println(" -n show state numbers in parser output");
|
||||
System.err.println(" -e file read error cases from file");
|
||||
System.err.println(" -d dir output files to directory");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
private static class NameList {
|
||||
|
||||
String name;
|
||||
NameList names;
|
||||
|
||||
NameList(String s, NameList namelist) {
|
||||
name = s;
|
||||
names = namelist;
|
||||
}
|
||||
|
||||
static void visit(NameList namelist, Visitor visitor) throws IOException {
|
||||
if (namelist != null) {
|
||||
visit(namelist.names, visitor);
|
||||
visitor.visit(namelist.name);
|
||||
}
|
||||
}
|
||||
|
||||
String getFirst() {
|
||||
NameList namelist;
|
||||
namelist = this;
|
||||
while (namelist.names != null) {
|
||||
namelist = namelist.names;
|
||||
}
|
||||
return namelist.name;
|
||||
}
|
||||
|
||||
interface Visitor {
|
||||
void visit(String s) throws IOException;
|
||||
}
|
||||
}
|
||||
}
|
182
src/main/java/org/xbib/jacc/JaccJob.java
Normal file
182
src/main/java/org/xbib/jacc/JaccJob.java
Normal file
|
@ -0,0 +1,182 @@
|
|||
package org.xbib.jacc;
|
||||
|
||||
import org.xbib.jacc.compiler.Failure;
|
||||
import org.xbib.jacc.compiler.Handler;
|
||||
import org.xbib.jacc.compiler.JavaSource;
|
||||
import org.xbib.jacc.compiler.Phase;
|
||||
import org.xbib.jacc.compiler.Position;
|
||||
import org.xbib.jacc.compiler.Warning;
|
||||
import org.xbib.jacc.grammar.Finitary;
|
||||
import org.xbib.jacc.grammar.Grammar;
|
||||
import org.xbib.jacc.grammar.LookaheadMachine;
|
||||
import org.xbib.jacc.grammar.Parser;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
class JaccJob extends Phase {
|
||||
|
||||
private Settings settings;
|
||||
|
||||
private JaccParser parser;
|
||||
|
||||
private JaccTables tables;
|
||||
|
||||
private JaccResolver resolver;
|
||||
|
||||
private Writer out;
|
||||
|
||||
JaccJob(Handler handler, Writer out, Settings settings) {
|
||||
super(handler);
|
||||
this.out = out;
|
||||
this.settings = settings;
|
||||
this.parser = new JaccParser(handler, settings);
|
||||
}
|
||||
|
||||
Settings getSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
JaccTables getTables() {
|
||||
return tables;
|
||||
}
|
||||
|
||||
JaccResolver getResolver() {
|
||||
return resolver;
|
||||
}
|
||||
|
||||
private JaccLexer lexerFromFile(String s) {
|
||||
JaccLexer jacclexer;
|
||||
try {
|
||||
Reader filereader = new InputStreamReader(new FileInputStream(s), StandardCharsets.UTF_8);
|
||||
jacclexer = new JaccLexer(getHandler(), new JavaSource(getHandler(), s, filereader));
|
||||
jacclexer.nextToken();
|
||||
return jacclexer;
|
||||
} catch (IOException e) {
|
||||
report(new Failure("Could not open file \"" + s + "\""));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
void parseGrammarFile(String s) throws IOException {
|
||||
JaccLexer jacclexer = lexerFromFile(s);
|
||||
if (jacclexer != null) {
|
||||
parser.parse(jacclexer);
|
||||
}
|
||||
}
|
||||
|
||||
void buildTables() {
|
||||
Grammar grammar = parser.getGrammar();
|
||||
if (grammar == null || !allDeriveFinite(grammar)) {
|
||||
return;
|
||||
}
|
||||
LookaheadMachine lookaheadmachine = settings.makeMachine(grammar);
|
||||
resolver = new JaccResolver(lookaheadmachine);
|
||||
tables = new JaccTables(lookaheadmachine, resolver);
|
||||
if (tables.getProdUnused() > 0) {
|
||||
report(new Warning(tables.getProdUnused() + " rules never reduced"));
|
||||
}
|
||||
if (resolver.getNumSRConflicts() > 0 || resolver.getNumRRConflicts() > 0) {
|
||||
report(new Warning("conflicts: " +
|
||||
resolver.getNumSRConflicts() +
|
||||
" shift/reduce, " +
|
||||
resolver.getNumRRConflicts() +
|
||||
" reduce/reduce"));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean allDeriveFinite(Grammar grammar) {
|
||||
Finitary finitary = grammar.getFinitary();
|
||||
boolean flag = true;
|
||||
for (int i = 0; i < grammar.getNumNTs(); i++) {
|
||||
if (!finitary.at(i)) {
|
||||
flag = false;
|
||||
report(new Failure("No finite strings can be derived for " +
|
||||
grammar.getNonterminal(i)));
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
void readRunExample(String s, boolean flag) throws IOException {
|
||||
out.write("Running example from \"" + s + "\"]\n");
|
||||
JaccLexer jacclexer = lexerFromFile(s);
|
||||
if (jacclexer != null) {
|
||||
runExample(parser.parseSymbols(jacclexer), flag);
|
||||
}
|
||||
}
|
||||
|
||||
private void runExample(int ai[], boolean flag) throws IOException {
|
||||
Grammar grammar = parser.getGrammar();
|
||||
Parser parser1 = new Parser(tables, ai);
|
||||
out.write("start ");
|
||||
do {
|
||||
out.write(" : ");
|
||||
parser1.display(out, flag);
|
||||
switch (parser1.step()) {
|
||||
case 0:
|
||||
out.write("Accept!\n");
|
||||
return;
|
||||
case 1:
|
||||
out.write("error in state ");
|
||||
out.write(parser1.getState());
|
||||
out.write(", next symbol ");
|
||||
out.write(grammar.getSymbol(parser1.getNextSymbol()).toString());
|
||||
return;
|
||||
case 3:
|
||||
out.write("goto ");
|
||||
break;
|
||||
case 2:
|
||||
out.write("shift ");
|
||||
break;
|
||||
case 4:
|
||||
out.write("reduce");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
}
|
||||
|
||||
void readErrorExamples(String s) throws IOException {
|
||||
out.write("Reading error examples from \"" + s + "\"");
|
||||
JaccLexer jacclexer = lexerFromFile(s);
|
||||
if (jacclexer != null) {
|
||||
parser.parseErrorExamples(jacclexer, this);
|
||||
}
|
||||
}
|
||||
|
||||
void errorExample(Position position, String s, int ai[]) {
|
||||
Parser parser1 = new Parser(tables, ai);
|
||||
int i;
|
||||
do {
|
||||
i = parser1.step();
|
||||
} while (i != 0 && i != 1);
|
||||
if (i == 0) {
|
||||
report(new Warning(position, "Example for \"" + s + "\" does not produce an error"));
|
||||
} else {
|
||||
Grammar grammar = tables.getMachine().getGrammar();
|
||||
int j = parser1.getNextSymbol();
|
||||
if (grammar.isNonterminal(j)) {
|
||||
report(new Warning(position,
|
||||
"Example for \"" + s + "\" reaches an error at the nonterminal " + grammar.getSymbol(j)));
|
||||
} else {
|
||||
int k = parser1.getState();
|
||||
if (!tables.errorAt(k, j)) {
|
||||
report(new Failure(position, "Error example results in internal error"));
|
||||
} else {
|
||||
String s1 = tables.errorSet(k, j, s);
|
||||
if (s1 != null) {
|
||||
report(new Warning(position,
|
||||
"Multiple errors are possible in state " + k + " on terminal " +
|
||||
grammar.getSymbol(j) + ":\n - " + s1 + "\n - " + s));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
419
src/main/java/org/xbib/jacc/JaccLexer.java
Normal file
419
src/main/java/org/xbib/jacc/JaccLexer.java
Normal file
|
@ -0,0 +1,419 @@
|
|||
package org.xbib.jacc;
|
||||
|
||||
import org.xbib.jacc.compiler.Failure;
|
||||
import org.xbib.jacc.compiler.Handler;
|
||||
import org.xbib.jacc.compiler.Source;
|
||||
import org.xbib.jacc.compiler.SourceLexer;
|
||||
import org.xbib.jacc.compiler.Warning;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class JaccLexer extends SourceLexer implements JaccTokens {
|
||||
|
||||
private int lastLiteral;
|
||||
|
||||
JaccLexer(Handler handler, Source source) throws IOException {
|
||||
super(handler, source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextToken() throws IOException {
|
||||
do {
|
||||
skipWhitespace();
|
||||
markPosition();
|
||||
lexemeText = null;
|
||||
switch (c) {
|
||||
case -1:
|
||||
return token = ENDINPUT;
|
||||
|
||||
case 58: // ':'
|
||||
nextChar();
|
||||
return token = COLON;
|
||||
|
||||
case 59: // ';'
|
||||
nextChar();
|
||||
return token = SEMI;
|
||||
|
||||
case 124: // '|'
|
||||
nextChar();
|
||||
return token = BAR;
|
||||
|
||||
case 60: // '<'
|
||||
nextChar();
|
||||
return token = TOPEN;
|
||||
|
||||
case 62: // '>'
|
||||
nextChar();
|
||||
return token = TCLOSE;
|
||||
|
||||
case 91: // '['
|
||||
nextChar();
|
||||
return token = BOPEN;
|
||||
|
||||
case 93: // ']'
|
||||
nextChar();
|
||||
return token = BCLOSE;
|
||||
|
||||
case 46: // '.'
|
||||
nextChar();
|
||||
return token = DOT;
|
||||
|
||||
case 37: // '%'
|
||||
if (directive() != -1) {
|
||||
return token;
|
||||
}
|
||||
break;
|
||||
|
||||
case 34: // '"'
|
||||
if (string() != -1) {
|
||||
return token;
|
||||
}
|
||||
break;
|
||||
|
||||
case 39: // '\''
|
||||
if (literal() != -1) {
|
||||
return token;
|
||||
}
|
||||
break;
|
||||
|
||||
case 123: // '{'
|
||||
if (action() != -1) {
|
||||
return token;
|
||||
}
|
||||
break;
|
||||
|
||||
case 47: // '/'
|
||||
skipComment();
|
||||
break;
|
||||
|
||||
default:
|
||||
if (Character.isJavaIdentifierStart((char) c)) {
|
||||
return identifier();
|
||||
}
|
||||
if (Character.isDigit((char) c)) {
|
||||
return number();
|
||||
}
|
||||
illegalCharacter();
|
||||
nextChar();
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
}
|
||||
|
||||
String readWholeLine() throws IOException {
|
||||
if (line == null) {
|
||||
return null;
|
||||
}
|
||||
String s = line;
|
||||
if (col > 0) {
|
||||
s = s.substring(col);
|
||||
}
|
||||
nextLine();
|
||||
return s;
|
||||
}
|
||||
|
||||
String readCodeLine() throws IOException {
|
||||
while (isWhitespace(c)) {
|
||||
nextChar();
|
||||
}
|
||||
return readWholeLine();
|
||||
}
|
||||
|
||||
private boolean isWhitespace(int i) {
|
||||