diff -Nru jsurf-alggeo-0.3.0+ds/CHANGELOG.md jsurf-alggeo-0.4.1+ds/CHANGELOG.md --- jsurf-alggeo-0.3.0+ds/CHANGELOG.md 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/CHANGELOG.md 2018-06-05 16:36:49.000000000 +0000 @@ -4,16 +4,29 @@ ## [Unreleased][unreleased] +## [0.4.1] - 2017-12-04 +### Fixed +- allow to disable RotateSphericalDragger when mouse button is released + +## [0.4.0] - 2017-11-25 +### Changed +- some backward compatibility for option machinery +- more detailed help text + +### Added +- add support for EditorConfig to unify coding style +- AST nodes keep track of parentheses in the input + ## [0.3.0] - 2015-11-17 ### Changed - default to headless instead of graphical operation - use Sun's javax.vecmath 1.5.2 implementation again (GPLv2 w/ classpath exception) -## Added +### Added - new command line option --gui -## Fixed +### Fixed - background threads do not prevent application from exiting anymore ## [0.2.0] - 2015-11-09 @@ -64,7 +77,9 @@ ### Changed - improved scheduling of parallel rendering tasks -[unreleased]: https://github.com/IMAGINARY/jsurf/compare/v0.3.0...HEAD +[unreleased]: https://github.com/IMAGINARY/jsurf/compare/v0.4.1...HEAD +[0.4.1]: https://github.com/IMAGINARY/jsurf/compare/v0.4.0...v0.4.1 +[0.4.0]: https://github.com/IMAGINARY/jsurf/compare/v0.3.0...v0.4.0 [0.3.0]: https://github.com/IMAGINARY/jsurf/compare/v0.2.0...v0.3.0 [0.2.0]: https://github.com/IMAGINARY/jsurf/compare/v0.1.4...v0.2.0 [0.1.4]: https://github.com/IMAGINARY/jsurf/compare/v0.1.3...v0.1.4 diff -Nru jsurf-alggeo-0.3.0+ds/debian/adhoc/examples/Makefile jsurf-alggeo-0.4.1+ds/debian/adhoc/examples/Makefile --- jsurf-alggeo-0.3.0+ds/debian/adhoc/examples/Makefile 2015-12-02 09:07:26.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/debian/adhoc/examples/Makefile 2018-06-04 03:52:20.000000000 +0000 @@ -18,7 +18,7 @@ # # written for Debian by Jerome Benoit # on behalf of the Debian Science Team -# copyright: 2015 Jerome Benoit +# copyright: 2015-2018 Jerome Benoit # distributed under the terms and conditions of GPL version 3 or later # diff -Nru jsurf-alggeo-0.3.0+ds/debian/changelog jsurf-alggeo-0.4.1+ds/debian/changelog --- jsurf-alggeo-0.3.0+ds/debian/changelog 2015-12-02 09:07:26.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/debian/changelog 2018-06-05 16:38:01.000000000 +0000 @@ -1,3 +1,50 @@ +jsurf-alggeo (0.4.1+ds-1) unstable; urgency=medium + + * New upstream release. + * Write secure source URI on d/copyright. + * Removed unnecessary upstream-revisit-option_machnery.patch + (included in the new sources). + * Added add-generated-java-files.patch because the .java files + are not compiled with the ANTLR version 3.5. + * Updated d/control Uploaders field. + * Updated debianization.patch to new upstream version. + + -- Innocent De Marchi Tue, 05 Jun 2018 17:38:01 +0100 + +jsurf-alggeo (0.3.0+ds-3) unstable; urgency=medium + + * Debianization: + - debian/control: + - Vcs-* fields, correct. + + -- Jerome Benoit Mon, 04 Jun 2018 10:15:56 +0000 + +jsurf-alggeo (0.3.0+ds-2) unstable; urgency=medium + + * Debianization: + - debian/copyright: + - Format field, secure URI; + - Copyright fields, update year tuples; + - debian/control: + - debhelper, bump to 11 (refresh d/control and d/rules); + - Standards Version, bump to 4.1.4 (no change); + - Homepage field, secure URI; + - Vcs-* fields, migration to Salsa; + - debian/watch: + - version, bump to 4; + - repack option, add; + - compression option, add; + - debian/rules: + - pkg-info.mk include, add and adapt; + - get-orig-source target, discard; + - debian/jsurf-alggeo.docs, introduce to distribute NOTICE; + - debian/source: + - d/s/lintian-overrides , update; + - debian/adhoc: + - d/a/examples/Makefile , update copyright year tuple. + + -- Jerome Benoit Mon, 04 Jun 2018 10:01:09 +0000 + jsurf-alggeo (0.3.0+ds-1) unstable; urgency=medium * New upstream release. diff -Nru jsurf-alggeo-0.3.0+ds/debian/compat jsurf-alggeo-0.4.1+ds/debian/compat --- jsurf-alggeo-0.3.0+ds/debian/compat 2015-12-02 09:07:26.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/debian/compat 2018-06-04 03:53:15.000000000 +0000 @@ -1 +1 @@ -9 +11 diff -Nru jsurf-alggeo-0.3.0+ds/debian/control jsurf-alggeo-0.4.1+ds/debian/control --- jsurf-alggeo-0.3.0+ds/debian/control 2015-12-02 09:07:26.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/debian/control 2018-06-05 16:38:01.000000000 +0000 @@ -2,16 +2,17 @@ Section: math Priority: optional Maintainer: Debian Science Maintainers -Uploaders: Jerome Benoit -Build-Depends: debhelper (>= 9), javahelper, maven-repo-helper, help2man +Uploaders: Jerome Benoit , + Innocent De Marchi +Build-Depends: debhelper (>= 11), javahelper, maven-repo-helper, help2man Build-Depends-Indep: default-jdk, antlr3, libvecmath-java, libcommons-io-java, libcommons-cli-java, rdfind, symlinks -Standards-Version: 3.9.6 -Homepage: http://imaginary.org/program/jsurf -Vcs-Git: git://anonscm.debian.org/debian-science/packages/jsurf-alggeo.git -Vcs-Browser: http://anonscm.debian.org/cgit/debian-science/packages/jsurf-alggeo.git +Standards-Version: 4.1.4 +Homepage: https://imaginary.org/program/jsurf +Vcs-Git: https://salsa.debian.org/science-team/jsurf-alggeo.git +Vcs-Browser: https://salsa.debian.org/science-team/jsurf-alggeo Package: jsurf-alggeo Architecture: all @@ -23,7 +24,7 @@ . Beside the library, this package also provides a simple script driven tool for drawing real algebraic geometric surfaces, as well as some - script samples. (This simple tool is similar to, but not comptible with, + script samples. (This simple tool is similar to, but not compatible with, the tool surf-alggeo distributed within the package surf-alggeo.) . jsurf is free software distributed under the Apache 2.0 License. diff -Nru jsurf-alggeo-0.3.0+ds/debian/copyright jsurf-alggeo-0.4.1+ds/debian/copyright --- jsurf-alggeo-0.3.0+ds/debian/copyright 2015-12-02 09:07:26.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/debian/copyright 2018-06-05 16:38:01.000000000 +0000 @@ -1,7 +1,7 @@ -Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0 +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0 Upstream-Name: jsurf Upstream-Contact: info@imaginary.org -Source: http://imaginary.org/program/jsurf +Source: https://imaginary.org/program/jsurf Comment: The jsurf-alggeo program is part of IMAGINARY by the Mathematisches Forschungsinstitut Oberwolfach . @@ -16,12 +16,12 @@ Files: * Copyright: - 2008-2015 Mathematisches Forschungsinstitut Oberwolfach + 2008-2018 Mathematisches Forschungsinstitut Oberwolfach License: Apache-2.0 Files: debian/* Copyright: - 2015 Jerome Benoit + 2015-2018 Jerome Benoit License: GPL-3+ License: Apache-2.0 diff -Nru jsurf-alggeo-0.3.0+ds/debian/jsurf-alggeo.docs jsurf-alggeo-0.4.1+ds/debian/jsurf-alggeo.docs --- jsurf-alggeo-0.3.0+ds/debian/jsurf-alggeo.docs 1970-01-01 00:00:00.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/debian/jsurf-alggeo.docs 2018-06-04 03:50:18.000000000 +0000 @@ -0,0 +1 @@ +NOTICE diff -Nru jsurf-alggeo-0.3.0+ds/debian/patches/add-generated-java-files.patch jsurf-alggeo-0.4.1+ds/debian/patches/add-generated-java-files.patch --- jsurf-alggeo-0.3.0+ds/debian/patches/add-generated-java-files.patch 1970-01-01 00:00:00.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/debian/patches/add-generated-java-files.patch 2018-06-05 16:38:01.000000000 +0000 @@ -0,0 +1,2995 @@ +Description: The .java files compiled with ANTLR 3.4 have been added + because they are not correctly compiled with ANTLR 3.5 +Forwarded: yes +Author: Innocent De Marchi +Last-Update: 2018-06-04 + +--- /dev/null ++++ b/src/main/antlr/de/mfo/jsurf/parser/AlgebraicExpressionLexer.java +@@ -0,0 +1,1080 @@ ++// $ANTLR 3.4 de/mfo/jsurf/parser/AlgebraicExpression.g 2018-05-24 10:32:48 ++ ++package de.mfo.jsurf.parser; ++ ++ ++import org.antlr.runtime.*; ++import java.util.Stack; ++import java.util.List; ++import java.util.ArrayList; ++ ++@SuppressWarnings({"all", "warnings", "unchecked"}) ++public class AlgebraicExpressionLexer extends Lexer { ++ public static final int EOF=-1; ++ public static final int DECIMAL_LITERAL=4; ++ public static final int DIGIT=5; ++ public static final int DIV=6; ++ public static final int ERRCHAR=7; ++ public static final int EXPONENT=8; ++ public static final int FLOATING_POINT_LITERAL=9; ++ public static final int IDENTIFIER=10; ++ public static final int LETTER=11; ++ public static final int LPAR=12; ++ public static final int MINUS=13; ++ public static final int MULT=14; ++ public static final int PARENTHESES=15; ++ public static final int PLUS=16; ++ public static final int POW=17; ++ public static final int RPAR=18; ++ public static final int WHITESPACE=19; ++ ++ // delegates ++ // delegators ++ public Lexer[] getDelegates() { ++ return new Lexer[] {}; ++ } ++ ++ public AlgebraicExpressionLexer() {} ++ public AlgebraicExpressionLexer(CharStream input) { ++ this(input, new RecognizerSharedState()); ++ } ++ public AlgebraicExpressionLexer(CharStream input, RecognizerSharedState state) { ++ super(input,state); ++ } ++ public String getGrammarFileName() { return "de/mfo/jsurf/parser/AlgebraicExpression.g"; } ++ ++ // $ANTLR start "DIV" ++ public final void mDIV() throws RecognitionException { ++ try { ++ int _type = DIV; ++ int _channel = DEFAULT_TOKEN_CHANNEL; ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:11:5: ( '/' ) ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:11:7: '/' ++ { ++ match('/'); ++ ++ } ++ ++ state.type = _type; ++ state.channel = _channel; ++ } ++ finally { ++ // do for sure before leaving ++ } ++ } ++ // $ANTLR end "DIV" ++ ++ // $ANTLR start "LPAR" ++ public final void mLPAR() throws RecognitionException { ++ try { ++ int _type = LPAR; ++ int _channel = DEFAULT_TOKEN_CHANNEL; ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:12:6: ( '(' ) ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:12:8: '(' ++ { ++ match('('); ++ ++ } ++ ++ state.type = _type; ++ state.channel = _channel; ++ } ++ finally { ++ // do for sure before leaving ++ } ++ } ++ // $ANTLR end "LPAR" ++ ++ // $ANTLR start "MINUS" ++ public final void mMINUS() throws RecognitionException { ++ try { ++ int _type = MINUS; ++ int _channel = DEFAULT_TOKEN_CHANNEL; ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:13:7: ( '-' ) ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:13:9: '-' ++ { ++ match('-'); ++ ++ } ++ ++ state.type = _type; ++ state.channel = _channel; ++ } ++ finally { ++ // do for sure before leaving ++ } ++ } ++ // $ANTLR end "MINUS" ++ ++ // $ANTLR start "MULT" ++ public final void mMULT() throws RecognitionException { ++ try { ++ int _type = MULT; ++ int _channel = DEFAULT_TOKEN_CHANNEL; ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:14:6: ( '*' ) ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:14:8: '*' ++ { ++ match('*'); ++ ++ } ++ ++ state.type = _type; ++ state.channel = _channel; ++ } ++ finally { ++ // do for sure before leaving ++ } ++ } ++ // $ANTLR end "MULT" ++ ++ // $ANTLR start "PLUS" ++ public final void mPLUS() throws RecognitionException { ++ try { ++ int _type = PLUS; ++ int _channel = DEFAULT_TOKEN_CHANNEL; ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:15:6: ( '+' ) ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:15:8: '+' ++ { ++ match('+'); ++ ++ } ++ ++ state.type = _type; ++ state.channel = _channel; ++ } ++ finally { ++ // do for sure before leaving ++ } ++ } ++ // $ANTLR end "PLUS" ++ ++ // $ANTLR start "POW" ++ public final void mPOW() throws RecognitionException { ++ try { ++ int _type = POW; ++ int _channel = DEFAULT_TOKEN_CHANNEL; ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:16:5: ( '^' ) ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:16:7: '^' ++ { ++ match('^'); ++ ++ } ++ ++ state.type = _type; ++ state.channel = _channel; ++ } ++ finally { ++ // do for sure before leaving ++ } ++ } ++ // $ANTLR end "POW" ++ ++ // $ANTLR start "RPAR" ++ public final void mRPAR() throws RecognitionException { ++ try { ++ int _type = RPAR; ++ int _channel = DEFAULT_TOKEN_CHANNEL; ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:17:6: ( ')' ) ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:17:8: ')' ++ { ++ match(')'); ++ ++ } ++ ++ state.type = _type; ++ state.channel = _channel; ++ } ++ finally { ++ // do for sure before leaving ++ } ++ } ++ // $ANTLR end "RPAR" ++ ++ // $ANTLR start "DECIMAL_LITERAL" ++ public final void mDECIMAL_LITERAL() throws RecognitionException { ++ try { ++ int _type = DECIMAL_LITERAL; ++ int _channel = DEFAULT_TOKEN_CHANNEL; ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:141:17: ( ( '0' | '1' .. '9' ( '0' .. '9' )* ) ) ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:141:19: ( '0' | '1' .. '9' ( '0' .. '9' )* ) ++ { ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:141:19: ( '0' | '1' .. '9' ( '0' .. '9' )* ) ++ int alt2=2; ++ int LA2_0 = input.LA(1); ++ ++ if ( (LA2_0=='0') ) { ++ alt2=1; ++ } ++ else if ( ((LA2_0 >= '1' && LA2_0 <= '9')) ) { ++ alt2=2; ++ } ++ else { ++ NoViableAltException nvae = ++ new NoViableAltException("", 2, 0, input); ++ ++ throw nvae; ++ ++ } ++ switch (alt2) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:141:21: '0' ++ { ++ match('0'); ++ ++ } ++ break; ++ case 2 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:141:27: '1' .. '9' ( '0' .. '9' )* ++ { ++ matchRange('1','9'); ++ ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:141:36: ( '0' .. '9' )* ++ loop1: ++ do { ++ int alt1=2; ++ int LA1_0 = input.LA(1); ++ ++ if ( ((LA1_0 >= '0' && LA1_0 <= '9')) ) { ++ alt1=1; ++ } ++ ++ ++ switch (alt1) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g: ++ { ++ if ( (input.LA(1) >= '0' && input.LA(1) <= '9') ) { ++ input.consume(); ++ } ++ else { ++ MismatchedSetException mse = new MismatchedSetException(null,input); ++ recover(mse); ++ throw mse; ++ } ++ ++ ++ } ++ break; ++ ++ default : ++ break loop1; ++ } ++ } while (true); ++ ++ ++ } ++ break; ++ ++ } ++ ++ ++ } ++ ++ state.type = _type; ++ state.channel = _channel; ++ } ++ finally { ++ // do for sure before leaving ++ } ++ } ++ // $ANTLR end "DECIMAL_LITERAL" ++ ++ // $ANTLR start "FLOATING_POINT_LITERAL" ++ public final void mFLOATING_POINT_LITERAL() throws RecognitionException { ++ try { ++ int _type = FLOATING_POINT_LITERAL; ++ int _channel = DEFAULT_TOKEN_CHANNEL; ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:144:2: ( ( DIGIT )+ '.' ( DIGIT )* ( EXPONENT )? | '.' ( DIGIT )+ ( EXPONENT )? | ( DIGIT )+ EXPONENT ) ++ int alt9=3; ++ alt9 = dfa9.predict(input); ++ switch (alt9) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:144:4: ( DIGIT )+ '.' ( DIGIT )* ( EXPONENT )? ++ { ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:144:4: ( DIGIT )+ ++ int cnt3=0; ++ loop3: ++ do { ++ int alt3=2; ++ int LA3_0 = input.LA(1); ++ ++ if ( ((LA3_0 >= '0' && LA3_0 <= '9')) ) { ++ alt3=1; ++ } ++ ++ ++ switch (alt3) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g: ++ { ++ if ( (input.LA(1) >= '0' && input.LA(1) <= '9') ) { ++ input.consume(); ++ } ++ else { ++ MismatchedSetException mse = new MismatchedSetException(null,input); ++ recover(mse); ++ throw mse; ++ } ++ ++ ++ } ++ break; ++ ++ default : ++ if ( cnt3 >= 1 ) break loop3; ++ EarlyExitException eee = ++ new EarlyExitException(3, input); ++ throw eee; ++ } ++ cnt3++; ++ } while (true); ++ ++ ++ match('.'); ++ ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:144:15: ( DIGIT )* ++ loop4: ++ do { ++ int alt4=2; ++ int LA4_0 = input.LA(1); ++ ++ if ( ((LA4_0 >= '0' && LA4_0 <= '9')) ) { ++ alt4=1; ++ } ++ ++ ++ switch (alt4) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g: ++ { ++ if ( (input.LA(1) >= '0' && input.LA(1) <= '9') ) { ++ input.consume(); ++ } ++ else { ++ MismatchedSetException mse = new MismatchedSetException(null,input); ++ recover(mse); ++ throw mse; ++ } ++ ++ ++ } ++ break; ++ ++ default : ++ break loop4; ++ } ++ } while (true); ++ ++ ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:144:22: ( EXPONENT )? ++ int alt5=2; ++ int LA5_0 = input.LA(1); ++ ++ if ( (LA5_0=='E'||LA5_0=='e') ) { ++ alt5=1; ++ } ++ switch (alt5) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:144:22: EXPONENT ++ { ++ mEXPONENT(); ++ ++ ++ } ++ break; ++ ++ } ++ ++ ++ } ++ break; ++ case 2 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:145:4: '.' ( DIGIT )+ ( EXPONENT )? ++ { ++ match('.'); ++ ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:145:8: ( DIGIT )+ ++ int cnt6=0; ++ loop6: ++ do { ++ int alt6=2; ++ int LA6_0 = input.LA(1); ++ ++ if ( ((LA6_0 >= '0' && LA6_0 <= '9')) ) { ++ alt6=1; ++ } ++ ++ ++ switch (alt6) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g: ++ { ++ if ( (input.LA(1) >= '0' && input.LA(1) <= '9') ) { ++ input.consume(); ++ } ++ else { ++ MismatchedSetException mse = new MismatchedSetException(null,input); ++ recover(mse); ++ throw mse; ++ } ++ ++ ++ } ++ break; ++ ++ default : ++ if ( cnt6 >= 1 ) break loop6; ++ EarlyExitException eee = ++ new EarlyExitException(6, input); ++ throw eee; ++ } ++ cnt6++; ++ } while (true); ++ ++ ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:145:15: ( EXPONENT )? ++ int alt7=2; ++ int LA7_0 = input.LA(1); ++ ++ if ( (LA7_0=='E'||LA7_0=='e') ) { ++ alt7=1; ++ } ++ switch (alt7) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:145:15: EXPONENT ++ { ++ mEXPONENT(); ++ ++ ++ } ++ break; ++ ++ } ++ ++ ++ } ++ break; ++ case 3 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:146:4: ( DIGIT )+ EXPONENT ++ { ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:146:4: ( DIGIT )+ ++ int cnt8=0; ++ loop8: ++ do { ++ int alt8=2; ++ int LA8_0 = input.LA(1); ++ ++ if ( ((LA8_0 >= '0' && LA8_0 <= '9')) ) { ++ alt8=1; ++ } ++ ++ ++ switch (alt8) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g: ++ { ++ if ( (input.LA(1) >= '0' && input.LA(1) <= '9') ) { ++ input.consume(); ++ } ++ else { ++ MismatchedSetException mse = new MismatchedSetException(null,input); ++ recover(mse); ++ throw mse; ++ } ++ ++ ++ } ++ break; ++ ++ default : ++ if ( cnt8 >= 1 ) break loop8; ++ EarlyExitException eee = ++ new EarlyExitException(8, input); ++ throw eee; ++ } ++ cnt8++; ++ } while (true); ++ ++ ++ mEXPONENT(); ++ ++ ++ } ++ break; ++ ++ } ++ state.type = _type; ++ state.channel = _channel; ++ } ++ finally { ++ // do for sure before leaving ++ } ++ } ++ // $ANTLR end "FLOATING_POINT_LITERAL" ++ ++ // $ANTLR start "EXPONENT" ++ public final void mEXPONENT() throws RecognitionException { ++ try { ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:151:10: ( ( 'e' | 'E' ) ( PLUS | MINUS )? ( DIGIT )+ ) ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:151:12: ( 'e' | 'E' ) ( PLUS | MINUS )? ( DIGIT )+ ++ { ++ if ( input.LA(1)=='E'||input.LA(1)=='e' ) { ++ input.consume(); ++ } ++ else { ++ MismatchedSetException mse = new MismatchedSetException(null,input); ++ recover(mse); ++ throw mse; ++ } ++ ++ ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:151:26: ( PLUS | MINUS )? ++ int alt10=2; ++ int LA10_0 = input.LA(1); ++ ++ if ( (LA10_0=='+'||LA10_0=='-') ) { ++ alt10=1; ++ } ++ switch (alt10) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g: ++ { ++ if ( input.LA(1)=='+'||input.LA(1)=='-' ) { ++ input.consume(); ++ } ++ else { ++ MismatchedSetException mse = new MismatchedSetException(null,input); ++ recover(mse); ++ throw mse; ++ } ++ ++ ++ } ++ break; ++ ++ } ++ ++ ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:151:44: ( DIGIT )+ ++ int cnt11=0; ++ loop11: ++ do { ++ int alt11=2; ++ int LA11_0 = input.LA(1); ++ ++ if ( ((LA11_0 >= '0' && LA11_0 <= '9')) ) { ++ alt11=1; ++ } ++ ++ ++ switch (alt11) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g: ++ { ++ if ( (input.LA(1) >= '0' && input.LA(1) <= '9') ) { ++ input.consume(); ++ } ++ else { ++ MismatchedSetException mse = new MismatchedSetException(null,input); ++ recover(mse); ++ throw mse; ++ } ++ ++ ++ } ++ break; ++ ++ default : ++ if ( cnt11 >= 1 ) break loop11; ++ EarlyExitException eee = ++ new EarlyExitException(11, input); ++ throw eee; ++ } ++ cnt11++; ++ } while (true); ++ ++ ++ } ++ ++ ++ } ++ finally { ++ // do for sure before leaving ++ } ++ } ++ // $ANTLR end "EXPONENT" ++ ++ // $ANTLR start "IDENTIFIER" ++ public final void mIDENTIFIER() throws RecognitionException { ++ try { ++ int _type = IDENTIFIER; ++ int _channel = DEFAULT_TOKEN_CHANNEL; ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:152:12: ( LETTER ( LETTER | DIGIT )* ) ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:152:14: LETTER ( LETTER | DIGIT )* ++ { ++ mLETTER(); ++ ++ ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:152:21: ( LETTER | DIGIT )* ++ loop12: ++ do { ++ int alt12=2; ++ int LA12_0 = input.LA(1); ++ ++ if ( ((LA12_0 >= '0' && LA12_0 <= '9')||(LA12_0 >= 'A' && LA12_0 <= 'Z')||LA12_0=='_'||(LA12_0 >= 'a' && LA12_0 <= 'z')) ) { ++ alt12=1; ++ } ++ ++ ++ switch (alt12) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g: ++ { ++ if ( (input.LA(1) >= '0' && input.LA(1) <= '9')||(input.LA(1) >= 'A' && input.LA(1) <= 'Z')||input.LA(1)=='_'||(input.LA(1) >= 'a' && input.LA(1) <= 'z') ) { ++ input.consume(); ++ } ++ else { ++ MismatchedSetException mse = new MismatchedSetException(null,input); ++ recover(mse); ++ throw mse; ++ } ++ ++ ++ } ++ break; ++ ++ default : ++ break loop12; ++ } ++ } while (true); ++ ++ ++ } ++ ++ state.type = _type; ++ state.channel = _channel; ++ } ++ finally { ++ // do for sure before leaving ++ } ++ } ++ // $ANTLR end "IDENTIFIER" ++ ++ // $ANTLR start "WHITESPACE" ++ public final void mWHITESPACE() throws RecognitionException { ++ try { ++ int _type = WHITESPACE; ++ int _channel = DEFAULT_TOKEN_CHANNEL; ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:154:12: ( ( '\\t' | ' ' | '\\r' | '\\n' | '\\u000C' )+ ) ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:154:14: ( '\\t' | ' ' | '\\r' | '\\n' | '\\u000C' )+ ++ { ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:154:14: ( '\\t' | ' ' | '\\r' | '\\n' | '\\u000C' )+ ++ int cnt13=0; ++ loop13: ++ do { ++ int alt13=2; ++ int LA13_0 = input.LA(1); ++ ++ if ( ((LA13_0 >= '\t' && LA13_0 <= '\n')||(LA13_0 >= '\f' && LA13_0 <= '\r')||LA13_0==' ') ) { ++ alt13=1; ++ } ++ ++ ++ switch (alt13) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g: ++ { ++ if ( (input.LA(1) >= '\t' && input.LA(1) <= '\n')||(input.LA(1) >= '\f' && input.LA(1) <= '\r')||input.LA(1)==' ' ) { ++ input.consume(); ++ } ++ else { ++ MismatchedSetException mse = new MismatchedSetException(null,input); ++ recover(mse); ++ throw mse; ++ } ++ ++ ++ } ++ break; ++ ++ default : ++ if ( cnt13 >= 1 ) break loop13; ++ EarlyExitException eee = ++ new EarlyExitException(13, input); ++ throw eee; ++ } ++ cnt13++; ++ } while (true); ++ ++ ++ _channel = HIDDEN; ++ ++ } ++ ++ state.type = _type; ++ state.channel = _channel; ++ } ++ finally { ++ // do for sure before leaving ++ } ++ } ++ // $ANTLR end "WHITESPACE" ++ ++ // $ANTLR start "DIGIT" ++ public final void mDIGIT() throws RecognitionException { ++ try { ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:156:16: ( '0' .. '9' ) ++ // de/mfo/jsurf/parser/AlgebraicExpression.g: ++ { ++ if ( (input.LA(1) >= '0' && input.LA(1) <= '9') ) { ++ input.consume(); ++ } ++ else { ++ MismatchedSetException mse = new MismatchedSetException(null,input); ++ recover(mse); ++ throw mse; ++ } ++ ++ ++ } ++ ++ ++ } ++ finally { ++ // do for sure before leaving ++ } ++ } ++ // $ANTLR end "DIGIT" ++ ++ // $ANTLR start "LETTER" ++ public final void mLETTER() throws RecognitionException { ++ try { ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:161:2: ( 'A' .. 'Z' | 'a' .. 'z' | '_' ) ++ // de/mfo/jsurf/parser/AlgebraicExpression.g: ++ { ++ if ( (input.LA(1) >= 'A' && input.LA(1) <= 'Z')||input.LA(1)=='_'||(input.LA(1) >= 'a' && input.LA(1) <= 'z') ) { ++ input.consume(); ++ } ++ else { ++ MismatchedSetException mse = new MismatchedSetException(null,input); ++ recover(mse); ++ throw mse; ++ } ++ ++ ++ } ++ ++ ++ } ++ finally { ++ // do for sure before leaving ++ } ++ } ++ // $ANTLR end "LETTER" ++ ++ // $ANTLR start "ERRCHAR" ++ public final void mERRCHAR() throws RecognitionException { ++ try { ++ int _type = ERRCHAR; ++ int _channel = DEFAULT_TOKEN_CHANNEL; ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:165:9: ( . ) ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:165:11: . ++ { ++ matchAny(); ++ ++ } ++ ++ state.type = _type; ++ state.channel = _channel; ++ } ++ finally { ++ // do for sure before leaving ++ } ++ } ++ // $ANTLR end "ERRCHAR" ++ ++ public void mTokens() throws RecognitionException { ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:1:8: ( DIV | LPAR | MINUS | MULT | PLUS | POW | RPAR | DECIMAL_LITERAL | FLOATING_POINT_LITERAL | IDENTIFIER | WHITESPACE | ERRCHAR ) ++ int alt14=12; ++ alt14 = dfa14.predict(input); ++ switch (alt14) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:1:10: DIV ++ { ++ mDIV(); ++ ++ ++ } ++ break; ++ case 2 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:1:14: LPAR ++ { ++ mLPAR(); ++ ++ ++ } ++ break; ++ case 3 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:1:19: MINUS ++ { ++ mMINUS(); ++ ++ ++ } ++ break; ++ case 4 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:1:25: MULT ++ { ++ mMULT(); ++ ++ ++ } ++ break; ++ case 5 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:1:30: PLUS ++ { ++ mPLUS(); ++ ++ ++ } ++ break; ++ case 6 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:1:35: POW ++ { ++ mPOW(); ++ ++ ++ } ++ break; ++ case 7 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:1:39: RPAR ++ { ++ mRPAR(); ++ ++ ++ } ++ break; ++ case 8 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:1:44: DECIMAL_LITERAL ++ { ++ mDECIMAL_LITERAL(); ++ ++ ++ } ++ break; ++ case 9 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:1:60: FLOATING_POINT_LITERAL ++ { ++ mFLOATING_POINT_LITERAL(); ++ ++ ++ } ++ break; ++ case 10 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:1:83: IDENTIFIER ++ { ++ mIDENTIFIER(); ++ ++ ++ } ++ break; ++ case 11 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:1:94: WHITESPACE ++ { ++ mWHITESPACE(); ++ ++ ++ } ++ break; ++ case 12 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:1:105: ERRCHAR ++ { ++ mERRCHAR(); ++ ++ ++ } ++ break; ++ ++ } ++ ++ } ++ ++ ++ protected DFA9 dfa9 = new DFA9(this); ++ protected DFA14 dfa14 = new DFA14(this); ++ static final String DFA9_eotS = ++ "\5\uffff"; ++ static final String DFA9_eofS = ++ "\5\uffff"; ++ static final String DFA9_minS = ++ "\2\56\3\uffff"; ++ static final String DFA9_maxS = ++ "\1\71\1\145\3\uffff"; ++ static final String DFA9_acceptS = ++ "\2\uffff\1\2\1\1\1\3"; ++ static final String DFA9_specialS = ++ "\5\uffff}>"; ++ static final String[] DFA9_transitionS = { ++ "\1\2\1\uffff\12\1", ++ "\1\3\1\uffff\12\1\13\uffff\1\4\37\uffff\1\4", ++ "", ++ "", ++ "" ++ }; ++ ++ static final short[] DFA9_eot = DFA.unpackEncodedString(DFA9_eotS); ++ static final short[] DFA9_eof = DFA.unpackEncodedString(DFA9_eofS); ++ static final char[] DFA9_min = DFA.unpackEncodedStringToUnsignedChars(DFA9_minS); ++ static final char[] DFA9_max = DFA.unpackEncodedStringToUnsignedChars(DFA9_maxS); ++ static final short[] DFA9_accept = DFA.unpackEncodedString(DFA9_acceptS); ++ static final short[] DFA9_special = DFA.unpackEncodedString(DFA9_specialS); ++ static final short[][] DFA9_transition; ++ ++ static { ++ int numStates = DFA9_transitionS.length; ++ DFA9_transition = new short[numStates][]; ++ for (int i=0; i"; ++ static final String[] DFA14_transitionS = { ++ "\11\15\2\14\1\15\2\14\22\15\1\14\7\15\1\2\1\7\1\4\1\5\1\15\1"+ ++ "\3\1\12\1\1\1\10\11\11\7\15\32\13\3\15\1\6\1\13\1\15\32\13\uff85"+ ++ "\15", ++ "", ++ "", ++ "", ++ "", ++ "", ++ "", ++ "", ++ "\1\26\1\uffff\12\26\13\uffff\1\26\37\uffff\1\26", ++ "\1\26\1\uffff\12\27\13\uffff\1\26\37\uffff\1\26", ++ "\12\26", ++ "", ++ "", ++ "", ++ "", ++ "", ++ "", ++ "", ++ "", ++ "", ++ "", ++ "", ++ "", ++ "\1\26\1\uffff\12\27\13\uffff\1\26\37\uffff\1\26", ++ "", ++ "" ++ }; ++ ++ static final short[] DFA14_eot = DFA.unpackEncodedString(DFA14_eotS); ++ static final short[] DFA14_eof = DFA.unpackEncodedString(DFA14_eofS); ++ static final char[] DFA14_min = DFA.unpackEncodedStringToUnsignedChars(DFA14_minS); ++ static final char[] DFA14_max = DFA.unpackEncodedStringToUnsignedChars(DFA14_maxS); ++ static final short[] DFA14_accept = DFA.unpackEncodedString(DFA14_acceptS); ++ static final short[] DFA14_special = DFA.unpackEncodedString(DFA14_specialS); ++ static final short[][] DFA14_transition; ++ ++ static { ++ int numStates = DFA14_transitionS.length; ++ DFA14_transition = new short[numStates][]; ++ for (int i=0; i= '1' && LA14_0 <= '9')) ) {s = 9;} ++ ++ else if ( (LA14_0=='.') ) {s = 10;} ++ ++ else if ( ((LA14_0 >= 'A' && LA14_0 <= 'Z')||LA14_0=='_'||(LA14_0 >= 'a' && LA14_0 <= 'z')) ) {s = 11;} ++ ++ else if ( ((LA14_0 >= '\t' && LA14_0 <= '\n')||(LA14_0 >= '\f' && LA14_0 <= '\r')||LA14_0==' ') ) {s = 12;} ++ ++ else if ( ((LA14_0 >= '\u0000' && LA14_0 <= '\b')||LA14_0=='\u000B'||(LA14_0 >= '\u000E' && LA14_0 <= '\u001F')||(LA14_0 >= '!' && LA14_0 <= '\'')||LA14_0==','||(LA14_0 >= ':' && LA14_0 <= '@')||(LA14_0 >= '[' && LA14_0 <= ']')||LA14_0=='`'||(LA14_0 >= '{' && LA14_0 <= '\uFFFF')) ) {s = 13;} ++ ++ if ( s>=0 ) return s; ++ break; ++ } ++ NoViableAltException nvae = ++ new NoViableAltException(getDescription(), 14, _s, input); ++ error(nvae); ++ throw nvae; ++ } ++ ++ } ++ ++ ++} +\ No newline at end of file +--- /dev/null ++++ b/src/main/antlr/de/mfo/jsurf/parser/AlgebraicExpressionParser.java +@@ -0,0 +1,986 @@ ++// $ANTLR 3.4 de/mfo/jsurf/parser/AlgebraicExpression.g 2018-05-24 10:32:47 ++ ++package de.mfo.jsurf.parser; ++ ++import de.mfo.jsurf.algebra.*; ++ ++ ++import org.antlr.runtime.*; ++import java.util.Stack; ++import java.util.List; ++import java.util.ArrayList; ++ ++import org.antlr.runtime.tree.*; ++ ++ ++@SuppressWarnings({"all", "warnings", "unchecked"}) ++public class AlgebraicExpressionParser extends Parser { ++ public static final String[] tokenNames = new String[] { ++ "", "", "", "", "DECIMAL_LITERAL", "DIGIT", "DIV", "ERRCHAR", "EXPONENT", "FLOATING_POINT_LITERAL", "IDENTIFIER", "LETTER", "LPAR", "MINUS", "MULT", "PARENTHESES", "PLUS", "POW", "RPAR", "WHITESPACE" ++ }; ++ ++ public static final int EOF=-1; ++ public static final int DECIMAL_LITERAL=4; ++ public static final int DIGIT=5; ++ public static final int DIV=6; ++ public static final int ERRCHAR=7; ++ public static final int EXPONENT=8; ++ public static final int FLOATING_POINT_LITERAL=9; ++ public static final int IDENTIFIER=10; ++ public static final int LETTER=11; ++ public static final int LPAR=12; ++ public static final int MINUS=13; ++ public static final int MULT=14; ++ public static final int PARENTHESES=15; ++ public static final int PLUS=16; ++ public static final int POW=17; ++ public static final int RPAR=18; ++ public static final int WHITESPACE=19; ++ ++ // delegates ++ public Parser[] getDelegates() { ++ return new Parser[] {}; ++ } ++ ++ // delegators ++ ++ ++ public AlgebraicExpressionParser(TokenStream input) { ++ this(input, new RecognizerSharedState()); ++ } ++ public AlgebraicExpressionParser(TokenStream input, RecognizerSharedState state) { ++ super(input, state); ++ } ++ ++protected TreeAdaptor adaptor = new CommonTreeAdaptor(); ++ ++public void setTreeAdaptor(TreeAdaptor adaptor) { ++ this.adaptor = adaptor; ++} ++public TreeAdaptor getTreeAdaptor() { ++ return adaptor; ++} ++ public String[] getTokenNames() { return AlgebraicExpressionParser.tokenNames; } ++ public String getGrammarFileName() { return "de/mfo/jsurf/parser/AlgebraicExpression.g"; } ++ ++ ++ public static PolynomialOperation parse( String s ) ++ throws Exception ++ { ++ // Create a string ++ ANTLRStringStream input = new ANTLRStringStream( s ); ++ ++ // Create an ExprLexer that feeds from that stream ++ AlgebraicExpressionLexer lexer = new AlgebraicExpressionLexer( input ); ++ ++ // Create a stream of tokens fed by the lexer ++ CommonTokenStream tokens = new CommonTokenStream( lexer ); ++ ++ // Create a parser that feeds off the token stream ++ AlgebraicExpressionParser parser = new AlgebraicExpressionParser( tokens ); ++ ++ // Begin parsing at start rule ++ AlgebraicExpressionParser.start_return r = parser.start(); ++ ++ // Create a stream of nodes fed by the parser ++ CommonTreeNodeStream nodes = new CommonTreeNodeStream( ( CommonTree ) r.getTree() ); ++ ++ // Create a tree parser that feeds off the node stream ++ AlgebraicExpressionWalker walker = new AlgebraicExpressionWalker( nodes ); ++ ++ // Begin tree parsing at start rule ++ return walker.start(); ++ } ++ ++ protected void mismatch( IntStream input, int ttype, BitSet follow ) ++ throws RecognitionException ++ { ++ throw new MismatchedTokenException(ttype, input); ++ } ++ ++ @Override ++ public java.lang.Object recoverFromMismatchedSet( IntStream input, RecognitionException e, BitSet follow ) ++ throws RecognitionException ++ { ++ throw e; ++ } ++ ++ @Override ++ protected Object recoverFromMismatchedToken( IntStream input, int ttype, BitSet follow ) ++ throws RecognitionException ++ { ++ throw new MismatchedTokenException( ttype, input ); ++ } ++ ++ ++ public static class start_return extends ParserRuleReturnScope { ++ Object tree; ++ public Object getTree() { return tree; } ++ }; ++ ++ ++ // $ANTLR start "start" ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:104:1: start : add_expr EOF !; ++ public final AlgebraicExpressionParser.start_return start() throws RecognitionException { ++ AlgebraicExpressionParser.start_return retval = new AlgebraicExpressionParser.start_return(); ++ retval.start = input.LT(1); ++ ++ ++ Object root_0 = null; ++ ++ Token EOF2=null; ++ AlgebraicExpressionParser.add_expr_return add_expr1 =null; ++ ++ ++ Object EOF2_tree=null; ++ ++ try { ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:105:2: ( add_expr EOF !) ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:105:4: add_expr EOF ! ++ { ++ root_0 = (Object)adaptor.nil(); ++ ++ ++ pushFollow(FOLLOW_add_expr_in_start138); ++ add_expr1=add_expr(); ++ ++ state._fsp--; ++ ++ adaptor.addChild(root_0, add_expr1.getTree()); ++ ++ EOF2=(Token)match(input,EOF,FOLLOW_EOF_in_start140); ++ ++ } ++ ++ retval.stop = input.LT(-1); ++ ++ ++ retval.tree = (Object)adaptor.rulePostProcessing(root_0); ++ adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); ++ ++ } ++ ++ catch( RecognitionException e ) ++ { ++ throw e; ++ } ++ ++ finally { ++ // do for sure before leaving ++ } ++ return retval; ++ } ++ // $ANTLR end "start" ++ ++ ++ public static class add_expr_return extends ParserRuleReturnScope { ++ Object tree; ++ public Object getTree() { return tree; } ++ }; ++ ++ ++ // $ANTLR start "add_expr" ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:108:1: add_expr : mult_expr ( PLUS ^ mult_expr | MINUS ^ mult_expr )* ; ++ public final AlgebraicExpressionParser.add_expr_return add_expr() throws RecognitionException { ++ AlgebraicExpressionParser.add_expr_return retval = new AlgebraicExpressionParser.add_expr_return(); ++ retval.start = input.LT(1); ++ ++ ++ Object root_0 = null; ++ ++ Token PLUS4=null; ++ Token MINUS6=null; ++ AlgebraicExpressionParser.mult_expr_return mult_expr3 =null; ++ ++ AlgebraicExpressionParser.mult_expr_return mult_expr5 =null; ++ ++ AlgebraicExpressionParser.mult_expr_return mult_expr7 =null; ++ ++ ++ Object PLUS4_tree=null; ++ Object MINUS6_tree=null; ++ ++ try { ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:109:2: ( mult_expr ( PLUS ^ mult_expr | MINUS ^ mult_expr )* ) ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:109:4: mult_expr ( PLUS ^ mult_expr | MINUS ^ mult_expr )* ++ { ++ root_0 = (Object)adaptor.nil(); ++ ++ ++ pushFollow(FOLLOW_mult_expr_in_add_expr152); ++ mult_expr3=mult_expr(); ++ ++ state._fsp--; ++ ++ adaptor.addChild(root_0, mult_expr3.getTree()); ++ ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:109:14: ( PLUS ^ mult_expr | MINUS ^ mult_expr )* ++ loop1: ++ do { ++ int alt1=3; ++ int LA1_0 = input.LA(1); ++ ++ if ( (LA1_0==PLUS) ) { ++ alt1=1; ++ } ++ else if ( (LA1_0==MINUS) ) { ++ alt1=2; ++ } ++ ++ ++ switch (alt1) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:109:16: PLUS ^ mult_expr ++ { ++ PLUS4=(Token)match(input,PLUS,FOLLOW_PLUS_in_add_expr156); ++ PLUS4_tree = ++ (Object)adaptor.create(PLUS4) ++ ; ++ root_0 = (Object)adaptor.becomeRoot(PLUS4_tree, root_0); ++ ++ ++ pushFollow(FOLLOW_mult_expr_in_add_expr159); ++ mult_expr5=mult_expr(); ++ ++ state._fsp--; ++ ++ adaptor.addChild(root_0, mult_expr5.getTree()); ++ ++ } ++ break; ++ case 2 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:109:34: MINUS ^ mult_expr ++ { ++ MINUS6=(Token)match(input,MINUS,FOLLOW_MINUS_in_add_expr163); ++ MINUS6_tree = ++ (Object)adaptor.create(MINUS6) ++ ; ++ root_0 = (Object)adaptor.becomeRoot(MINUS6_tree, root_0); ++ ++ ++ pushFollow(FOLLOW_mult_expr_in_add_expr166); ++ mult_expr7=mult_expr(); ++ ++ state._fsp--; ++ ++ adaptor.addChild(root_0, mult_expr7.getTree()); ++ ++ } ++ break; ++ ++ default : ++ break loop1; ++ } ++ } while (true); ++ ++ ++ } ++ ++ retval.stop = input.LT(-1); ++ ++ ++ retval.tree = (Object)adaptor.rulePostProcessing(root_0); ++ adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); ++ ++ } ++ ++ catch( RecognitionException e ) ++ { ++ throw e; ++ } ++ ++ finally { ++ // do for sure before leaving ++ } ++ return retval; ++ } ++ // $ANTLR end "add_expr" ++ ++ ++ public static class mult_expr_return extends ParserRuleReturnScope { ++ Object tree; ++ public Object getTree() { return tree; } ++ }; ++ ++ ++ // $ANTLR start "mult_expr" ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:112:1: mult_expr : neg_expr ( MULT ^ neg_expr | DIV ^ neg_expr )* ; ++ public final AlgebraicExpressionParser.mult_expr_return mult_expr() throws RecognitionException { ++ AlgebraicExpressionParser.mult_expr_return retval = new AlgebraicExpressionParser.mult_expr_return(); ++ retval.start = input.LT(1); ++ ++ ++ Object root_0 = null; ++ ++ Token MULT9=null; ++ Token DIV11=null; ++ AlgebraicExpressionParser.neg_expr_return neg_expr8 =null; ++ ++ AlgebraicExpressionParser.neg_expr_return neg_expr10 =null; ++ ++ AlgebraicExpressionParser.neg_expr_return neg_expr12 =null; ++ ++ ++ Object MULT9_tree=null; ++ Object DIV11_tree=null; ++ ++ try { ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:113:2: ( neg_expr ( MULT ^ neg_expr | DIV ^ neg_expr )* ) ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:113:4: neg_expr ( MULT ^ neg_expr | DIV ^ neg_expr )* ++ { ++ root_0 = (Object)adaptor.nil(); ++ ++ ++ pushFollow(FOLLOW_neg_expr_in_mult_expr180); ++ neg_expr8=neg_expr(); ++ ++ state._fsp--; ++ ++ adaptor.addChild(root_0, neg_expr8.getTree()); ++ ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:113:13: ( MULT ^ neg_expr | DIV ^ neg_expr )* ++ loop2: ++ do { ++ int alt2=3; ++ int LA2_0 = input.LA(1); ++ ++ if ( (LA2_0==MULT) ) { ++ alt2=1; ++ } ++ else if ( (LA2_0==DIV) ) { ++ alt2=2; ++ } ++ ++ ++ switch (alt2) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:113:15: MULT ^ neg_expr ++ { ++ MULT9=(Token)match(input,MULT,FOLLOW_MULT_in_mult_expr184); ++ MULT9_tree = ++ (Object)adaptor.create(MULT9) ++ ; ++ root_0 = (Object)adaptor.becomeRoot(MULT9_tree, root_0); ++ ++ ++ pushFollow(FOLLOW_neg_expr_in_mult_expr187); ++ neg_expr10=neg_expr(); ++ ++ state._fsp--; ++ ++ adaptor.addChild(root_0, neg_expr10.getTree()); ++ ++ } ++ break; ++ case 2 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:113:32: DIV ^ neg_expr ++ { ++ DIV11=(Token)match(input,DIV,FOLLOW_DIV_in_mult_expr191); ++ DIV11_tree = ++ (Object)adaptor.create(DIV11) ++ ; ++ root_0 = (Object)adaptor.becomeRoot(DIV11_tree, root_0); ++ ++ ++ pushFollow(FOLLOW_neg_expr_in_mult_expr194); ++ neg_expr12=neg_expr(); ++ ++ state._fsp--; ++ ++ adaptor.addChild(root_0, neg_expr12.getTree()); ++ ++ } ++ break; ++ ++ default : ++ break loop2; ++ } ++ } while (true); ++ ++ ++ } ++ ++ retval.stop = input.LT(-1); ++ ++ ++ retval.tree = (Object)adaptor.rulePostProcessing(root_0); ++ adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); ++ ++ } ++ ++ catch( RecognitionException e ) ++ { ++ throw e; ++ } ++ ++ finally { ++ // do for sure before leaving ++ } ++ return retval; ++ } ++ // $ANTLR end "mult_expr" ++ ++ ++ public static class neg_expr_return extends ParserRuleReturnScope { ++ Object tree; ++ public Object getTree() { return tree; } ++ }; ++ ++ ++ // $ANTLR start "neg_expr" ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:116:1: neg_expr : ( MINUS ^ pow_expr | pow_expr ); ++ public final AlgebraicExpressionParser.neg_expr_return neg_expr() throws RecognitionException { ++ AlgebraicExpressionParser.neg_expr_return retval = new AlgebraicExpressionParser.neg_expr_return(); ++ retval.start = input.LT(1); ++ ++ ++ Object root_0 = null; ++ ++ Token MINUS13=null; ++ AlgebraicExpressionParser.pow_expr_return pow_expr14 =null; ++ ++ AlgebraicExpressionParser.pow_expr_return pow_expr15 =null; ++ ++ ++ Object MINUS13_tree=null; ++ ++ try { ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:117:9: ( MINUS ^ pow_expr | pow_expr ) ++ int alt3=2; ++ int LA3_0 = input.LA(1); ++ ++ if ( (LA3_0==MINUS) ) { ++ alt3=1; ++ } ++ else if ( (LA3_0==DECIMAL_LITERAL||(LA3_0 >= FLOATING_POINT_LITERAL && LA3_0 <= IDENTIFIER)||LA3_0==LPAR) ) { ++ alt3=2; ++ } ++ else { ++ NoViableAltException nvae = ++ new NoViableAltException("", 3, 0, input); ++ ++ throw nvae; ++ ++ } ++ switch (alt3) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:117:11: MINUS ^ pow_expr ++ { ++ root_0 = (Object)adaptor.nil(); ++ ++ ++ MINUS13=(Token)match(input,MINUS,FOLLOW_MINUS_in_neg_expr215); ++ MINUS13_tree = ++ (Object)adaptor.create(MINUS13) ++ ; ++ root_0 = (Object)adaptor.becomeRoot(MINUS13_tree, root_0); ++ ++ ++ pushFollow(FOLLOW_pow_expr_in_neg_expr218); ++ pow_expr14=pow_expr(); ++ ++ state._fsp--; ++ ++ adaptor.addChild(root_0, pow_expr14.getTree()); ++ ++ } ++ break; ++ case 2 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:118:11: pow_expr ++ { ++ root_0 = (Object)adaptor.nil(); ++ ++ ++ pushFollow(FOLLOW_pow_expr_in_neg_expr230); ++ pow_expr15=pow_expr(); ++ ++ state._fsp--; ++ ++ adaptor.addChild(root_0, pow_expr15.getTree()); ++ ++ } ++ break; ++ ++ } ++ retval.stop = input.LT(-1); ++ ++ ++ retval.tree = (Object)adaptor.rulePostProcessing(root_0); ++ adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); ++ ++ } ++ ++ catch( RecognitionException e ) ++ { ++ throw e; ++ } ++ ++ finally { ++ // do for sure before leaving ++ } ++ return retval; ++ } ++ // $ANTLR end "neg_expr" ++ ++ ++ public static class pow_expr_return extends ParserRuleReturnScope { ++ Object tree; ++ public Object getTree() { return tree; } ++ }; ++ ++ ++ // $ANTLR start "pow_expr" ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:121:1: pow_expr : unary_expr ( POW ^ pow_expr )? ; ++ public final AlgebraicExpressionParser.pow_expr_return pow_expr() throws RecognitionException { ++ AlgebraicExpressionParser.pow_expr_return retval = new AlgebraicExpressionParser.pow_expr_return(); ++ retval.start = input.LT(1); ++ ++ ++ Object root_0 = null; ++ ++ Token POW17=null; ++ AlgebraicExpressionParser.unary_expr_return unary_expr16 =null; ++ ++ AlgebraicExpressionParser.pow_expr_return pow_expr18 =null; ++ ++ ++ Object POW17_tree=null; ++ ++ try { ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:122:2: ( unary_expr ( POW ^ pow_expr )? ) ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:122:4: unary_expr ( POW ^ pow_expr )? ++ { ++ root_0 = (Object)adaptor.nil(); ++ ++ ++ pushFollow(FOLLOW_unary_expr_in_pow_expr248); ++ unary_expr16=unary_expr(); ++ ++ state._fsp--; ++ ++ adaptor.addChild(root_0, unary_expr16.getTree()); ++ ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:122:15: ( POW ^ pow_expr )? ++ int alt4=2; ++ int LA4_0 = input.LA(1); ++ ++ if ( (LA4_0==POW) ) { ++ alt4=1; ++ } ++ switch (alt4) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:122:17: POW ^ pow_expr ++ { ++ POW17=(Token)match(input,POW,FOLLOW_POW_in_pow_expr252); ++ POW17_tree = ++ (Object)adaptor.create(POW17) ++ ; ++ root_0 = (Object)adaptor.becomeRoot(POW17_tree, root_0); ++ ++ ++ pushFollow(FOLLOW_pow_expr_in_pow_expr255); ++ pow_expr18=pow_expr(); ++ ++ state._fsp--; ++ ++ adaptor.addChild(root_0, pow_expr18.getTree()); ++ ++ } ++ break; ++ ++ } ++ ++ ++ } ++ ++ retval.stop = input.LT(-1); ++ ++ ++ retval.tree = (Object)adaptor.rulePostProcessing(root_0); ++ adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); ++ ++ } ++ ++ catch( RecognitionException e ) ++ { ++ throw e; ++ } ++ ++ finally { ++ // do for sure before leaving ++ } ++ return retval; ++ } ++ // $ANTLR end "pow_expr" ++ ++ ++ public static class unary_expr_return extends ParserRuleReturnScope { ++ Object tree; ++ public Object getTree() { return tree; } ++ }; ++ ++ ++ // $ANTLR start "unary_expr" ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:125:1: unary_expr : ( primary_expr | IDENTIFIER LPAR add_expr RPAR -> ^( IDENTIFIER PARENTHESES add_expr ) ); ++ public final AlgebraicExpressionParser.unary_expr_return unary_expr() throws RecognitionException { ++ AlgebraicExpressionParser.unary_expr_return retval = new AlgebraicExpressionParser.unary_expr_return(); ++ retval.start = input.LT(1); ++ ++ ++ Object root_0 = null; ++ ++ Token IDENTIFIER20=null; ++ Token LPAR21=null; ++ Token RPAR23=null; ++ AlgebraicExpressionParser.primary_expr_return primary_expr19 =null; ++ ++ AlgebraicExpressionParser.add_expr_return add_expr22 =null; ++ ++ ++ Object IDENTIFIER20_tree=null; ++ Object LPAR21_tree=null; ++ Object RPAR23_tree=null; ++ RewriteRuleTokenStream stream_LPAR=new RewriteRuleTokenStream(adaptor,"token LPAR"); ++ RewriteRuleTokenStream stream_RPAR=new RewriteRuleTokenStream(adaptor,"token RPAR"); ++ RewriteRuleTokenStream stream_IDENTIFIER=new RewriteRuleTokenStream(adaptor,"token IDENTIFIER"); ++ RewriteRuleSubtreeStream stream_add_expr=new RewriteRuleSubtreeStream(adaptor,"rule add_expr"); ++ try { ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:126:9: ( primary_expr | IDENTIFIER LPAR add_expr RPAR -> ^( IDENTIFIER PARENTHESES add_expr ) ) ++ int alt5=2; ++ int LA5_0 = input.LA(1); ++ ++ if ( (LA5_0==DECIMAL_LITERAL||LA5_0==FLOATING_POINT_LITERAL||LA5_0==LPAR) ) { ++ alt5=1; ++ } ++ else if ( (LA5_0==IDENTIFIER) ) { ++ int LA5_2 = input.LA(2); ++ ++ if ( (LA5_2==LPAR) ) { ++ alt5=2; ++ } ++ else if ( (LA5_2==EOF||LA5_2==DIV||(LA5_2 >= MINUS && LA5_2 <= MULT)||(LA5_2 >= PLUS && LA5_2 <= RPAR)) ) { ++ alt5=1; ++ } ++ else { ++ NoViableAltException nvae = ++ new NoViableAltException("", 5, 2, input); ++ ++ throw nvae; ++ ++ } ++ } ++ else { ++ NoViableAltException nvae = ++ new NoViableAltException("", 5, 0, input); ++ ++ throw nvae; ++ ++ } ++ switch (alt5) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:126:11: primary_expr ++ { ++ root_0 = (Object)adaptor.nil(); ++ ++ ++ pushFollow(FOLLOW_primary_expr_in_unary_expr276); ++ primary_expr19=primary_expr(); ++ ++ state._fsp--; ++ ++ adaptor.addChild(root_0, primary_expr19.getTree()); ++ ++ } ++ break; ++ case 2 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:127:4: IDENTIFIER LPAR add_expr RPAR ++ { ++ IDENTIFIER20=(Token)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_unary_expr281); ++ stream_IDENTIFIER.add(IDENTIFIER20); ++ ++ ++ LPAR21=(Token)match(input,LPAR,FOLLOW_LPAR_in_unary_expr283); ++ stream_LPAR.add(LPAR21); ++ ++ ++ pushFollow(FOLLOW_add_expr_in_unary_expr285); ++ add_expr22=add_expr(); ++ ++ state._fsp--; ++ ++ stream_add_expr.add(add_expr22.getTree()); ++ ++ RPAR23=(Token)match(input,RPAR,FOLLOW_RPAR_in_unary_expr287); ++ stream_RPAR.add(RPAR23); ++ ++ ++ // AST REWRITE ++ // elements: IDENTIFIER, add_expr ++ // token labels: ++ // rule labels: retval ++ // token list labels: ++ // rule list labels: ++ // wildcard labels: ++ retval.tree = root_0; ++ RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); ++ ++ root_0 = (Object)adaptor.nil(); ++ // 127:34: -> ^( IDENTIFIER PARENTHESES add_expr ) ++ { ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:127:37: ^( IDENTIFIER PARENTHESES add_expr ) ++ { ++ Object root_1 = (Object)adaptor.nil(); ++ root_1 = (Object)adaptor.becomeRoot( ++ stream_IDENTIFIER.nextNode() ++ , root_1); ++ ++ adaptor.addChild(root_1, ++ (Object)adaptor.create(PARENTHESES, "PARENTHESES") ++ ); ++ ++ adaptor.addChild(root_1, stream_add_expr.nextTree()); ++ ++ adaptor.addChild(root_0, root_1); ++ } ++ ++ } ++ ++ ++ retval.tree = root_0; ++ ++ } ++ break; ++ ++ } ++ retval.stop = input.LT(-1); ++ ++ ++ retval.tree = (Object)adaptor.rulePostProcessing(root_0); ++ adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); ++ ++ } ++ ++ catch( RecognitionException e ) ++ { ++ throw e; ++ } ++ ++ finally { ++ // do for sure before leaving ++ } ++ return retval; ++ } ++ // $ANTLR end "unary_expr" ++ ++ ++ public static class primary_expr_return extends ParserRuleReturnScope { ++ Object tree; ++ public Object getTree() { return tree; } ++ }; ++ ++ ++ // $ANTLR start "primary_expr" ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:130:1: primary_expr : ( DECIMAL_LITERAL | FLOATING_POINT_LITERAL | IDENTIFIER | LPAR add_expr RPAR -> PARENTHESES add_expr ); ++ public final AlgebraicExpressionParser.primary_expr_return primary_expr() throws RecognitionException { ++ AlgebraicExpressionParser.primary_expr_return retval = new AlgebraicExpressionParser.primary_expr_return(); ++ retval.start = input.LT(1); ++ ++ ++ Object root_0 = null; ++ ++ Token DECIMAL_LITERAL24=null; ++ Token FLOATING_POINT_LITERAL25=null; ++ Token IDENTIFIER26=null; ++ Token LPAR27=null; ++ Token RPAR29=null; ++ AlgebraicExpressionParser.add_expr_return add_expr28 =null; ++ ++ ++ Object DECIMAL_LITERAL24_tree=null; ++ Object FLOATING_POINT_LITERAL25_tree=null; ++ Object IDENTIFIER26_tree=null; ++ Object LPAR27_tree=null; ++ Object RPAR29_tree=null; ++ RewriteRuleTokenStream stream_LPAR=new RewriteRuleTokenStream(adaptor,"token LPAR"); ++ RewriteRuleTokenStream stream_RPAR=new RewriteRuleTokenStream(adaptor,"token RPAR"); ++ RewriteRuleSubtreeStream stream_add_expr=new RewriteRuleSubtreeStream(adaptor,"rule add_expr"); ++ try { ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:131:2: ( DECIMAL_LITERAL | FLOATING_POINT_LITERAL | IDENTIFIER | LPAR add_expr RPAR -> PARENTHESES add_expr ) ++ int alt6=4; ++ switch ( input.LA(1) ) { ++ case DECIMAL_LITERAL: ++ { ++ alt6=1; ++ } ++ break; ++ case FLOATING_POINT_LITERAL: ++ { ++ alt6=2; ++ } ++ break; ++ case IDENTIFIER: ++ { ++ alt6=3; ++ } ++ break; ++ case LPAR: ++ { ++ alt6=4; ++ } ++ break; ++ default: ++ NoViableAltException nvae = ++ new NoViableAltException("", 6, 0, input); ++ ++ throw nvae; ++ ++ } ++ ++ switch (alt6) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:131:4: DECIMAL_LITERAL ++ { ++ root_0 = (Object)adaptor.nil(); ++ ++ ++ DECIMAL_LITERAL24=(Token)match(input,DECIMAL_LITERAL,FOLLOW_DECIMAL_LITERAL_in_primary_expr308); ++ DECIMAL_LITERAL24_tree = ++ (Object)adaptor.create(DECIMAL_LITERAL24) ++ ; ++ adaptor.addChild(root_0, DECIMAL_LITERAL24_tree); ++ ++ ++ } ++ break; ++ case 2 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:132:4: FLOATING_POINT_LITERAL ++ { ++ root_0 = (Object)adaptor.nil(); ++ ++ ++ FLOATING_POINT_LITERAL25=(Token)match(input,FLOATING_POINT_LITERAL,FOLLOW_FLOATING_POINT_LITERAL_in_primary_expr313); ++ FLOATING_POINT_LITERAL25_tree = ++ (Object)adaptor.create(FLOATING_POINT_LITERAL25) ++ ; ++ adaptor.addChild(root_0, FLOATING_POINT_LITERAL25_tree); ++ ++ ++ } ++ break; ++ case 3 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:133:4: IDENTIFIER ++ { ++ root_0 = (Object)adaptor.nil(); ++ ++ ++ IDENTIFIER26=(Token)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_primary_expr318); ++ IDENTIFIER26_tree = ++ (Object)adaptor.create(IDENTIFIER26) ++ ; ++ adaptor.addChild(root_0, IDENTIFIER26_tree); ++ ++ ++ } ++ break; ++ case 4 : ++ // de/mfo/jsurf/parser/AlgebraicExpression.g:134:4: LPAR add_expr RPAR ++ { ++ LPAR27=(Token)match(input,LPAR,FOLLOW_LPAR_in_primary_expr323); ++ stream_LPAR.add(LPAR27); ++ ++ ++ pushFollow(FOLLOW_add_expr_in_primary_expr325); ++ add_expr28=add_expr(); ++ ++ state._fsp--; ++ ++ stream_add_expr.add(add_expr28.getTree()); ++ ++ RPAR29=(Token)match(input,RPAR,FOLLOW_RPAR_in_primary_expr327); ++ stream_RPAR.add(RPAR29); ++ ++ ++ // AST REWRITE ++ // elements: add_expr ++ // token labels: ++ // rule labels: retval ++ // token list labels: ++ // rule list labels: ++ // wildcard labels: ++ retval.tree = root_0; ++ RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); ++ ++ root_0 = (Object)adaptor.nil(); ++ // 134:23: -> PARENTHESES add_expr ++ { ++ adaptor.addChild(root_0, ++ (Object)adaptor.create(PARENTHESES, "PARENTHESES") ++ ); ++ ++ adaptor.addChild(root_0, stream_add_expr.nextTree()); ++ ++ } ++ ++ ++ retval.tree = root_0; ++ ++ } ++ break; ++ ++ } ++ retval.stop = input.LT(-1); ++ ++ ++ retval.tree = (Object)adaptor.rulePostProcessing(root_0); ++ adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); ++ ++ } ++ ++ catch( RecognitionException e ) ++ { ++ throw e; ++ } ++ ++ finally { ++ // do for sure before leaving ++ } ++ return retval; ++ } ++ // $ANTLR end "primary_expr" ++ ++ // Delegated rules ++ ++ ++ ++ ++ public static final BitSet FOLLOW_add_expr_in_start138 = new BitSet(new long[]{0x0000000000000000L}); ++ public static final BitSet FOLLOW_EOF_in_start140 = new BitSet(new long[]{0x0000000000000002L}); ++ public static final BitSet FOLLOW_mult_expr_in_add_expr152 = new BitSet(new long[]{0x0000000000012002L}); ++ public static final BitSet FOLLOW_PLUS_in_add_expr156 = new BitSet(new long[]{0x0000000000003610L}); ++ public static final BitSet FOLLOW_mult_expr_in_add_expr159 = new BitSet(new long[]{0x0000000000012002L}); ++ public static final BitSet FOLLOW_MINUS_in_add_expr163 = new BitSet(new long[]{0x0000000000003610L}); ++ public static final BitSet FOLLOW_mult_expr_in_add_expr166 = new BitSet(new long[]{0x0000000000012002L}); ++ public static final BitSet FOLLOW_neg_expr_in_mult_expr180 = new BitSet(new long[]{0x0000000000004042L}); ++ public static final BitSet FOLLOW_MULT_in_mult_expr184 = new BitSet(new long[]{0x0000000000003610L}); ++ public static final BitSet FOLLOW_neg_expr_in_mult_expr187 = new BitSet(new long[]{0x0000000000004042L}); ++ public static final BitSet FOLLOW_DIV_in_mult_expr191 = new BitSet(new long[]{0x0000000000003610L}); ++ public static final BitSet FOLLOW_neg_expr_in_mult_expr194 = new BitSet(new long[]{0x0000000000004042L}); ++ public static final BitSet FOLLOW_MINUS_in_neg_expr215 = new BitSet(new long[]{0x0000000000001610L}); ++ public static final BitSet FOLLOW_pow_expr_in_neg_expr218 = new BitSet(new long[]{0x0000000000000002L}); ++ public static final BitSet FOLLOW_pow_expr_in_neg_expr230 = new BitSet(new long[]{0x0000000000000002L}); ++ public static final BitSet FOLLOW_unary_expr_in_pow_expr248 = new BitSet(new long[]{0x0000000000020002L}); ++ public static final BitSet FOLLOW_POW_in_pow_expr252 = new BitSet(new long[]{0x0000000000001610L}); ++ public static final BitSet FOLLOW_pow_expr_in_pow_expr255 = new BitSet(new long[]{0x0000000000000002L}); ++ public static final BitSet FOLLOW_primary_expr_in_unary_expr276 = new BitSet(new long[]{0x0000000000000002L}); ++ public static final BitSet FOLLOW_IDENTIFIER_in_unary_expr281 = new BitSet(new long[]{0x0000000000001000L}); ++ public static final BitSet FOLLOW_LPAR_in_unary_expr283 = new BitSet(new long[]{0x0000000000003610L}); ++ public static final BitSet FOLLOW_add_expr_in_unary_expr285 = new BitSet(new long[]{0x0000000000040000L}); ++ public static final BitSet FOLLOW_RPAR_in_unary_expr287 = new BitSet(new long[]{0x0000000000000002L}); ++ public static final BitSet FOLLOW_DECIMAL_LITERAL_in_primary_expr308 = new BitSet(new long[]{0x0000000000000002L}); ++ public static final BitSet FOLLOW_FLOATING_POINT_LITERAL_in_primary_expr313 = new BitSet(new long[]{0x0000000000000002L}); ++ public static final BitSet FOLLOW_IDENTIFIER_in_primary_expr318 = new BitSet(new long[]{0x0000000000000002L}); ++ public static final BitSet FOLLOW_LPAR_in_primary_expr323 = new BitSet(new long[]{0x0000000000003610L}); ++ public static final BitSet FOLLOW_add_expr_in_primary_expr325 = new BitSet(new long[]{0x0000000000040000L}); ++ public static final BitSet FOLLOW_RPAR_in_primary_expr327 = new BitSet(new long[]{0x0000000000000002L}); ++ ++} +\ No newline at end of file +--- /dev/null ++++ b/src/main/antlr/de/mfo/jsurf/parser/AlgebraicExpressionWalker.java +@@ -0,0 +1,911 @@ ++// $ANTLR 3.4 de/mfo/jsurf/parser/AlgebraicExpressionWalker.g 2018-05-24 10:32:48 ++ ++package de.mfo.jsurf.parser; ++ ++import de.mfo.jsurf.algebra.*; ++ ++ ++import org.antlr.runtime.*; ++import org.antlr.runtime.tree.*; ++import java.util.Stack; ++import java.util.List; ++import java.util.ArrayList; ++ ++@SuppressWarnings({"all", "warnings", "unchecked"}) ++public class AlgebraicExpressionWalker extends TreeParser { ++ public static final String[] tokenNames = new String[] { ++ "", "", "", "", "DECIMAL_LITERAL", "DIGIT", "DIV", "ERRCHAR", "EXPONENT", "FLOATING_POINT_LITERAL", "IDENTIFIER", "LETTER", "LPAR", "MINUS", "MULT", "PARENTHESES", "PLUS", "POW", "RPAR", "WHITESPACE" ++ }; ++ ++ public static final int EOF=-1; ++ public static final int DECIMAL_LITERAL=4; ++ public static final int DIGIT=5; ++ public static final int DIV=6; ++ public static final int ERRCHAR=7; ++ public static final int EXPONENT=8; ++ public static final int FLOATING_POINT_LITERAL=9; ++ public static final int IDENTIFIER=10; ++ public static final int LETTER=11; ++ public static final int LPAR=12; ++ public static final int MINUS=13; ++ public static final int MULT=14; ++ public static final int PARENTHESES=15; ++ public static final int PLUS=16; ++ public static final int POW=17; ++ public static final int RPAR=18; ++ public static final int WHITESPACE=19; ++ ++ // delegates ++ public TreeParser[] getDelegates() { ++ return new TreeParser[] {}; ++ } ++ ++ // delegators ++ ++ ++ public AlgebraicExpressionWalker(TreeNodeStream input) { ++ this(input, new RecognizerSharedState()); ++ } ++ public AlgebraicExpressionWalker(TreeNodeStream input, RecognizerSharedState state) { ++ super(input, state); ++ } ++ ++ public String[] getTokenNames() { return AlgebraicExpressionWalker.tokenNames; } ++ public String getGrammarFileName() { return "de/mfo/jsurf/parser/AlgebraicExpressionWalker.g"; } ++ ++ ++ public static PolynomialOperation createVariable( String name, boolean hasParentheses ) ++ { ++ try ++ { ++ return new PolynomialVariable( PolynomialVariable.Var.valueOf( name ), hasParentheses ); ++ } ++ catch( Exception e ) ++ { ++ return new DoubleVariable( name, hasParentheses ); ++ } ++ } ++ ++ public static int createInteger( String text ) ++ { ++ try ++ { ++ return Integer.parseInt( text ); ++ } ++ catch( NumberFormatException nfe ) ++ { ++ return 0; ++ } ++ } ++ ++ ++ ++ // $ANTLR start "start" ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:55:1: start returns [ PolynomialOperation op ] : e= expr ; ++ public final PolynomialOperation start() throws RecognitionException { ++ PolynomialOperation op = null; ++ ++ ++ AlgebraicExpressionWalker.expr_return e =null; ++ ++ ++ try { ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:56:5: (e= expr ) ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:56:7: e= expr ++ { ++ pushFollow(FOLLOW_expr_in_start58); ++ e=expr(); ++ ++ state._fsp--; ++ ++ ++ op = (e!=null?e.op:null); ++ ++ } ++ ++ } ++ catch (RecognitionException re) { ++ reportError(re); ++ recover(input,re); ++ } ++ ++ finally { ++ // do for sure before leaving ++ } ++ return op; ++ } ++ // $ANTLR end "start" ++ ++ ++ public static class expr_return extends TreeRuleReturnScope { ++ public PolynomialOperation op; ++ public Integer decimal; ++ }; ++ ++ ++ // $ANTLR start "expr" ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:59:1: expr returns [ PolynomialOperation op, Integer decimal ] : ( (p= PARENTHESES )? ^( PLUS e1= expr e2= expr ) | (p= PARENTHESES )? ^( MINUS e1= expr (e2= expr )? ) | (p= PARENTHESES )? ^( MULT e1= expr e2= expr ) | (p= PARENTHESES )? ^( DIV e1= expr e2= expr ) | (p= PARENTHESES )? ^( POW e1= expr e2= expr ) | (p= PARENTHESES )? ^(id= IDENTIFIER e1= expr (e2= expr )? ) |pe= primary_expr ); ++ public final AlgebraicExpressionWalker.expr_return expr() throws RecognitionException { ++ AlgebraicExpressionWalker.expr_return retval = new AlgebraicExpressionWalker.expr_return(); ++ retval.start = input.LT(1); ++ ++ ++ CommonTree p=null; ++ CommonTree id=null; ++ AlgebraicExpressionWalker.expr_return e1 =null; ++ ++ AlgebraicExpressionWalker.expr_return e2 =null; ++ ++ AlgebraicExpressionWalker.primary_expr_return pe =null; ++ ++ ++ try { ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:60:2: ( (p= PARENTHESES )? ^( PLUS e1= expr e2= expr ) | (p= PARENTHESES )? ^( MINUS e1= expr (e2= expr )? ) | (p= PARENTHESES )? ^( MULT e1= expr e2= expr ) | (p= PARENTHESES )? ^( DIV e1= expr e2= expr ) | (p= PARENTHESES )? ^( POW e1= expr e2= expr ) | (p= PARENTHESES )? ^(id= IDENTIFIER e1= expr (e2= expr )? ) |pe= primary_expr ) ++ int alt9=7; ++ switch ( input.LA(1) ) { ++ case PARENTHESES: ++ { ++ switch ( input.LA(2) ) { ++ case PLUS: ++ { ++ alt9=1; ++ } ++ break; ++ case MINUS: ++ { ++ alt9=2; ++ } ++ break; ++ case MULT: ++ { ++ alt9=3; ++ } ++ break; ++ case DIV: ++ { ++ alt9=4; ++ } ++ break; ++ case POW: ++ { ++ alt9=5; ++ } ++ break; ++ case IDENTIFIER: ++ { ++ int LA9_7 = input.LA(3); ++ ++ if ( (LA9_7==DOWN) ) { ++ alt9=6; ++ } ++ else if ( (LA9_7==EOF||(LA9_7 >= UP && LA9_7 <= DECIMAL_LITERAL)||LA9_7==DIV||(LA9_7 >= FLOATING_POINT_LITERAL && LA9_7 <= IDENTIFIER)||(LA9_7 >= MINUS && LA9_7 <= POW)) ) { ++ alt9=7; ++ } ++ else { ++ NoViableAltException nvae = ++ new NoViableAltException("", 9, 7, input); ++ ++ throw nvae; ++ ++ } ++ } ++ break; ++ case DECIMAL_LITERAL: ++ case FLOATING_POINT_LITERAL: ++ { ++ alt9=7; ++ } ++ break; ++ default: ++ NoViableAltException nvae = ++ new NoViableAltException("", 9, 1, input); ++ ++ throw nvae; ++ ++ } ++ ++ } ++ break; ++ case PLUS: ++ { ++ alt9=1; ++ } ++ break; ++ case MINUS: ++ { ++ alt9=2; ++ } ++ break; ++ case MULT: ++ { ++ alt9=3; ++ } ++ break; ++ case DIV: ++ { ++ alt9=4; ++ } ++ break; ++ case POW: ++ { ++ alt9=5; ++ } ++ break; ++ case IDENTIFIER: ++ { ++ int LA9_7 = input.LA(2); ++ ++ if ( (LA9_7==DOWN) ) { ++ alt9=6; ++ } ++ else if ( (LA9_7==EOF||(LA9_7 >= UP && LA9_7 <= DECIMAL_LITERAL)||LA9_7==DIV||(LA9_7 >= FLOATING_POINT_LITERAL && LA9_7 <= IDENTIFIER)||(LA9_7 >= MINUS && LA9_7 <= POW)) ) { ++ alt9=7; ++ } ++ else { ++ NoViableAltException nvae = ++ new NoViableAltException("", 9, 7, input); ++ ++ throw nvae; ++ ++ } ++ } ++ break; ++ case DECIMAL_LITERAL: ++ case FLOATING_POINT_LITERAL: ++ { ++ alt9=7; ++ } ++ break; ++ default: ++ NoViableAltException nvae = ++ new NoViableAltException("", 9, 0, input); ++ ++ throw nvae; ++ ++ } ++ ++ switch (alt9) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:60:5: (p= PARENTHESES )? ^( PLUS e1= expr e2= expr ) ++ { ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:60:5: (p= PARENTHESES )? ++ int alt1=2; ++ int LA1_0 = input.LA(1); ++ ++ if ( (LA1_0==PARENTHESES) ) { ++ alt1=1; ++ } ++ switch (alt1) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:60:7: p= PARENTHESES ++ { ++ p=(CommonTree)match(input,PARENTHESES,FOLLOW_PARENTHESES_in_expr85); ++ ++ } ++ break; ++ ++ } ++ ++ ++ match(input,PLUS,FOLLOW_PLUS_in_expr92); ++ ++ match(input, Token.DOWN, null); ++ pushFollow(FOLLOW_expr_in_expr98); ++ e1=expr(); ++ ++ state._fsp--; ++ ++ ++ pushFollow(FOLLOW_expr_in_expr104); ++ e2=expr(); ++ ++ state._fsp--; ++ ++ ++ match(input, Token.UP, null); ++ ++ ++ ++ try ++ { ++ retval.op = new DoubleBinaryOperation( DoubleBinaryOperation.Op.add, ( DoubleOperation ) (e1!=null?e1.op:null), ( DoubleOperation ) (e2!=null?e2.op:null), p != null ); ++ } ++ catch( ClassCastException cce ) ++ { ++ retval.op = new PolynomialAddition( (e1!=null?e1.op:null), (e2!=null?e2.op:null), p != null ); ++ } ++ ++ ++ } ++ break; ++ case 2 : ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:71:11: (p= PARENTHESES )? ^( MINUS e1= expr (e2= expr )? ) ++ { ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:71:11: (p= PARENTHESES )? ++ int alt2=2; ++ int LA2_0 = input.LA(1); ++ ++ if ( (LA2_0==PARENTHESES) ) { ++ alt2=1; ++ } ++ switch (alt2) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:71:13: p= PARENTHESES ++ { ++ p=(CommonTree)match(input,PARENTHESES,FOLLOW_PARENTHESES_in_expr138); ++ ++ } ++ break; ++ ++ } ++ ++ ++ match(input,MINUS,FOLLOW_MINUS_in_expr145); ++ ++ match(input, Token.DOWN, null); ++ pushFollow(FOLLOW_expr_in_expr151); ++ e1=expr(); ++ ++ state._fsp--; ++ ++ ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:71:51: (e2= expr )? ++ int alt3=2; ++ int LA3_0 = input.LA(1); ++ ++ if ( (LA3_0==DECIMAL_LITERAL||LA3_0==DIV||(LA3_0 >= FLOATING_POINT_LITERAL && LA3_0 <= IDENTIFIER)||(LA3_0 >= MINUS && LA3_0 <= POW)) ) { ++ alt3=1; ++ } ++ switch (alt3) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:71:53: e2= expr ++ { ++ pushFollow(FOLLOW_expr_in_expr159); ++ e2=expr(); ++ ++ state._fsp--; ++ ++ ++ } ++ break; ++ ++ } ++ ++ ++ match(input, Token.UP, null); ++ ++ ++ ++ if( e2 != null ) ++ { ++ // subtraction ++ try ++ { ++ retval.op = new DoubleBinaryOperation( DoubleBinaryOperation.Op.sub, ( DoubleOperation ) (e1!=null?e1.op:null), ( DoubleOperation ) (e2!=null?e2.op:null), p != null ); ++ } ++ catch( ClassCastException cce ) ++ { ++ retval.op = new PolynomialSubtraction( (e1!=null?e1.op:null), (e2!=null?e2.op:null), p != null ); ++ } ++ } ++ else ++ { ++ try ++ { ++ retval.op = new DoubleUnaryOperation( DoubleUnaryOperation.Op.neg, ( DoubleOperation ) (e1!=null?e1.op:null), p != null ); ++ } ++ catch( ClassCastException cce ) ++ { ++ retval.op = new PolynomialNegation( (e1!=null?e1.op:null), p != null ); ++ } ++ } ++ ++ ++ } ++ break; ++ case 3 : ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:97:11: (p= PARENTHESES )? ^( MULT e1= expr e2= expr ) ++ { ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:97:11: (p= PARENTHESES )? ++ int alt4=2; ++ int LA4_0 = input.LA(1); ++ ++ if ( (LA4_0==PARENTHESES) ) { ++ alt4=1; ++ } ++ switch (alt4) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:97:13: p= PARENTHESES ++ { ++ p=(CommonTree)match(input,PARENTHESES,FOLLOW_PARENTHESES_in_expr197); ++ ++ } ++ break; ++ ++ } ++ ++ ++ match(input,MULT,FOLLOW_MULT_in_expr204); ++ ++ match(input, Token.DOWN, null); ++ pushFollow(FOLLOW_expr_in_expr210); ++ e1=expr(); ++ ++ state._fsp--; ++ ++ ++ pushFollow(FOLLOW_expr_in_expr216); ++ e2=expr(); ++ ++ state._fsp--; ++ ++ ++ match(input, Token.UP, null); ++ ++ ++ ++ try ++ { ++ retval.op = new DoubleBinaryOperation( DoubleBinaryOperation.Op.mult, ( DoubleOperation ) (e1!=null?e1.op:null), ( DoubleOperation ) (e2!=null?e2.op:null) ); ++ } ++ catch( ClassCastException cce ) ++ { ++ retval.op = new PolynomialMultiplication( (e1!=null?e1.op:null), (e2!=null?e2.op:null), p != null ); ++ } ++ ++ ++ } ++ break; ++ case 4 : ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:108:11: (p= PARENTHESES )? ^( DIV e1= expr e2= expr ) ++ { ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:108:11: (p= PARENTHESES )? ++ int alt5=2; ++ int LA5_0 = input.LA(1); ++ ++ if ( (LA5_0==PARENTHESES) ) { ++ alt5=1; ++ } ++ switch (alt5) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:108:13: p= PARENTHESES ++ { ++ p=(CommonTree)match(input,PARENTHESES,FOLLOW_PARENTHESES_in_expr250); ++ ++ } ++ break; ++ ++ } ++ ++ ++ match(input,DIV,FOLLOW_DIV_in_expr257); ++ ++ match(input, Token.DOWN, null); ++ pushFollow(FOLLOW_expr_in_expr263); ++ e1=expr(); ++ ++ state._fsp--; ++ ++ ++ pushFollow(FOLLOW_expr_in_expr269); ++ e2=expr(); ++ ++ state._fsp--; ++ ++ ++ match(input, Token.UP, null); ++ ++ ++ ++ try ++ { ++ retval.op = new DoubleBinaryOperation( DoubleBinaryOperation.Op.div, ( DoubleOperation ) (e1!=null?e1.op:null), ( DoubleOperation ) (e2!=null?e2.op:null), p != null ); ++ } ++ catch( ClassCastException cce1 ) ++ { ++ try ++ { ++ retval.op = new PolynomialDoubleDivision( (e1!=null?e1.op:null), ( DoubleOperation ) (e2!=null?e2.op:null), p != null ); ++ } ++ catch( ClassCastException cce2 ) ++ { ++ throw new RecognitionException(); ++ } ++ } ++ ++ ++ } ++ break; ++ case 5 : ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:126:11: (p= PARENTHESES )? ^( POW e1= expr e2= expr ) ++ { ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:126:11: (p= PARENTHESES )? ++ int alt6=2; ++ int LA6_0 = input.LA(1); ++ ++ if ( (LA6_0==PARENTHESES) ) { ++ alt6=1; ++ } ++ switch (alt6) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:126:13: p= PARENTHESES ++ { ++ p=(CommonTree)match(input,PARENTHESES,FOLLOW_PARENTHESES_in_expr303); ++ ++ } ++ break; ++ ++ } ++ ++ ++ match(input,POW,FOLLOW_POW_in_expr310); ++ ++ match(input, Token.DOWN, null); ++ pushFollow(FOLLOW_expr_in_expr316); ++ e1=expr(); ++ ++ state._fsp--; ++ ++ ++ pushFollow(FOLLOW_expr_in_expr322); ++ e2=expr(); ++ ++ state._fsp--; ++ ++ ++ match(input, Token.UP, null); ++ ++ ++ ++ try ++ { ++ retval.op = new DoubleBinaryOperation( DoubleBinaryOperation.Op.pow, ( DoubleOperation ) (e1!=null?e1.op:null), ( DoubleOperation ) (e2!=null?e2.op:null), p != null ); ++ } ++ catch( ClassCastException cce ) ++ { ++ if( (e2!=null?e2.decimal:null) == null ) ++ { ++ throw new RecognitionException(); ++ } ++ else ++ { ++ retval.op = new PolynomialPower( (e1!=null?e1.op:null), (e2!=null?e2.decimal:null), p != null ); ++ } ++ } ++ ++ ++ } ++ break; ++ case 6 : ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:144:11: (p= PARENTHESES )? ^(id= IDENTIFIER e1= expr (e2= expr )? ) ++ { ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:144:11: (p= PARENTHESES )? ++ int alt7=2; ++ int LA7_0 = input.LA(1); ++ ++ if ( (LA7_0==PARENTHESES) ) { ++ alt7=1; ++ } ++ switch (alt7) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:144:13: p= PARENTHESES ++ { ++ p=(CommonTree)match(input,PARENTHESES,FOLLOW_PARENTHESES_in_expr356); ++ ++ } ++ break; ++ ++ } ++ ++ ++ id=(CommonTree)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_expr367); ++ ++ match(input, Token.DOWN, null); ++ pushFollow(FOLLOW_expr_in_expr373); ++ e1=expr(); ++ ++ state._fsp--; ++ ++ ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:144:61: (e2= expr )? ++ int alt8=2; ++ int LA8_0 = input.LA(1); ++ ++ if ( (LA8_0==DECIMAL_LITERAL||LA8_0==DIV||(LA8_0 >= FLOATING_POINT_LITERAL && LA8_0 <= IDENTIFIER)||(LA8_0 >= MINUS && LA8_0 <= POW)) ) { ++ alt8=1; ++ } ++ switch (alt8) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:144:63: e2= expr ++ { ++ pushFollow(FOLLOW_expr_in_expr381); ++ e2=expr(); ++ ++ state._fsp--; ++ ++ ++ } ++ break; ++ ++ } ++ ++ ++ match(input, Token.UP, null); ++ ++ ++ ++ if( e2 != null ) ++ { ++ try ++ { ++ retval.op = new DoubleBinaryOperation( DoubleBinaryOperation.Op.valueOf( (id!=null?id.getText():null) ), ( DoubleOperation ) (e1!=null?e1.op:null), ( DoubleOperation ) (e2!=null?e2.op:null), p != null ); ++ } ++ catch( ClassCastException cce ) ++ { ++ throw new RecognitionException(); ++ } ++ catch( IllegalArgumentException iae ) ++ { ++ throw new RecognitionException(); ++ } ++ } ++ else ++ { ++ try ++ { ++ retval.op = new DoubleUnaryOperation( DoubleUnaryOperation.Op.valueOf( (id!=null?id.getText():null) ), ( DoubleOperation ) (e1!=null?e1.op:null), p != null ); ++ } ++ catch( ClassCastException cce ) ++ { ++ throw new RecognitionException(); ++ } ++ catch( IllegalArgumentException iae ) ++ { ++ throw new RecognitionException(); ++ } ++ } ++ ++ ++ } ++ break; ++ case 7 : ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:177:11: pe= primary_expr ++ { ++ pushFollow(FOLLOW_primary_expr_in_expr416); ++ pe=primary_expr(); ++ ++ state._fsp--; ++ ++ ++ retval.op = (pe!=null?pe.op:null); retval.decimal = pe.decimal; ++ ++ } ++ break; ++ ++ } ++ } ++ catch (RecognitionException re) { ++ reportError(re); ++ recover(input,re); ++ } ++ ++ finally { ++ // do for sure before leaving ++ } ++ return retval; ++ } ++ // $ANTLR end "expr" ++ ++ ++ public static class primary_expr_return extends TreeRuleReturnScope { ++ public PolynomialOperation op; ++ public Integer decimal; ++ }; ++ ++ ++ // $ANTLR start "primary_expr" ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:180:1: primary_expr returns [ PolynomialOperation op, Integer decimal ] : ( (p= PARENTHESES )? i= DECIMAL_LITERAL | (p= PARENTHESES )? f= FLOATING_POINT_LITERAL | (p= PARENTHESES )? id= IDENTIFIER ); ++ public final AlgebraicExpressionWalker.primary_expr_return primary_expr() throws RecognitionException { ++ AlgebraicExpressionWalker.primary_expr_return retval = new AlgebraicExpressionWalker.primary_expr_return(); ++ retval.start = input.LT(1); ++ ++ ++ CommonTree p=null; ++ CommonTree i=null; ++ CommonTree f=null; ++ CommonTree id=null; ++ ++ try { ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:181:2: ( (p= PARENTHESES )? i= DECIMAL_LITERAL | (p= PARENTHESES )? f= FLOATING_POINT_LITERAL | (p= PARENTHESES )? id= IDENTIFIER ) ++ int alt13=3; ++ switch ( input.LA(1) ) { ++ case PARENTHESES: ++ { ++ switch ( input.LA(2) ) { ++ case DECIMAL_LITERAL: ++ { ++ alt13=1; ++ } ++ break; ++ case FLOATING_POINT_LITERAL: ++ { ++ alt13=2; ++ } ++ break; ++ case IDENTIFIER: ++ { ++ alt13=3; ++ } ++ break; ++ default: ++ NoViableAltException nvae = ++ new NoViableAltException("", 13, 1, input); ++ ++ throw nvae; ++ ++ } ++ ++ } ++ break; ++ case DECIMAL_LITERAL: ++ { ++ alt13=1; ++ } ++ break; ++ case FLOATING_POINT_LITERAL: ++ { ++ alt13=2; ++ } ++ break; ++ case IDENTIFIER: ++ { ++ alt13=3; ++ } ++ break; ++ default: ++ NoViableAltException nvae = ++ new NoViableAltException("", 13, 0, input); ++ ++ throw nvae; ++ ++ } ++ ++ switch (alt13) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:181:4: (p= PARENTHESES )? i= DECIMAL_LITERAL ++ { ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:181:4: (p= PARENTHESES )? ++ int alt10=2; ++ int LA10_0 = input.LA(1); ++ ++ if ( (LA10_0==PARENTHESES) ) { ++ alt10=1; ++ } ++ switch (alt10) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:181:6: p= PARENTHESES ++ { ++ p=(CommonTree)match(input,PARENTHESES,FOLLOW_PARENTHESES_in_primary_expr439); ++ ++ } ++ break; ++ ++ } ++ ++ ++ i=(CommonTree)match(input,DECIMAL_LITERAL,FOLLOW_DECIMAL_LITERAL_in_primary_expr448); ++ ++ retval.op = new DoubleValue( (i!=null?i.getText():null), p != null ); retval.decimal = Integer.valueOf( createInteger( (i!=null?i.getText():null) ) ); ++ ++ } ++ break; ++ case 2 : ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:182:4: (p= PARENTHESES )? f= FLOATING_POINT_LITERAL ++ { ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:182:4: (p= PARENTHESES )? ++ int alt11=2; ++ int LA11_0 = input.LA(1); ++ ++ if ( (LA11_0==PARENTHESES) ) { ++ alt11=1; ++ } ++ switch (alt11) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:182:6: p= PARENTHESES ++ { ++ p=(CommonTree)match(input,PARENTHESES,FOLLOW_PARENTHESES_in_primary_expr461); ++ ++ } ++ break; ++ ++ } ++ ++ ++ f=(CommonTree)match(input,FLOATING_POINT_LITERAL,FOLLOW_FLOATING_POINT_LITERAL_in_primary_expr470); ++ ++ retval.op = new DoubleValue( (f!=null?f.getText():null), p != null ); ++ ++ } ++ break; ++ case 3 : ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:183:4: (p= PARENTHESES )? id= IDENTIFIER ++ { ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:183:4: (p= PARENTHESES )? ++ int alt12=2; ++ int LA12_0 = input.LA(1); ++ ++ if ( (LA12_0==PARENTHESES) ) { ++ alt12=1; ++ } ++ switch (alt12) { ++ case 1 : ++ // de/mfo/jsurf/parser/AlgebraicExpressionWalker.g:183:6: p= PARENTHESES ++ { ++ p=(CommonTree)match(input,PARENTHESES,FOLLOW_PARENTHESES_in_primary_expr483); ++ ++ } ++ break; ++ ++ } ++ ++ ++ id=(CommonTree)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_primary_expr492); ++ ++ retval.op = createVariable( (id!=null?id.getText():null), p != null ); ++ ++ } ++ break; ++ ++ } ++ } ++ catch (RecognitionException re) { ++ reportError(re); ++ recover(input,re); ++ } ++ ++ finally { ++ // do for sure before leaving ++ } ++ return retval; ++ } ++ // $ANTLR end "primary_expr" ++ ++ // Delegated rules ++ ++ ++ ++ ++ public static final BitSet FOLLOW_expr_in_start58 = new BitSet(new long[]{0x0000000000000002L}); ++ public static final BitSet FOLLOW_PARENTHESES_in_expr85 = new BitSet(new long[]{0x0000000000010000L}); ++ public static final BitSet FOLLOW_PLUS_in_expr92 = new BitSet(new long[]{0x0000000000000004L}); ++ public static final BitSet FOLLOW_expr_in_expr98 = new BitSet(new long[]{0x000000000003E650L}); ++ public static final BitSet FOLLOW_expr_in_expr104 = new BitSet(new long[]{0x0000000000000008L}); ++ public static final BitSet FOLLOW_PARENTHESES_in_expr138 = new BitSet(new long[]{0x0000000000002000L}); ++ public static final BitSet FOLLOW_MINUS_in_expr145 = new BitSet(new long[]{0x0000000000000004L}); ++ public static final BitSet FOLLOW_expr_in_expr151 = new BitSet(new long[]{0x000000000003E658L}); ++ public static final BitSet FOLLOW_expr_in_expr159 = new BitSet(new long[]{0x0000000000000008L}); ++ public static final BitSet FOLLOW_PARENTHESES_in_expr197 = new BitSet(new long[]{0x0000000000004000L}); ++ public static final BitSet FOLLOW_MULT_in_expr204 = new BitSet(new long[]{0x0000000000000004L}); ++ public static final BitSet FOLLOW_expr_in_expr210 = new BitSet(new long[]{0x000000000003E650L}); ++ public static final BitSet FOLLOW_expr_in_expr216 = new BitSet(new long[]{0x0000000000000008L}); ++ public static final BitSet FOLLOW_PARENTHESES_in_expr250 = new BitSet(new long[]{0x0000000000000040L}); ++ public static final BitSet FOLLOW_DIV_in_expr257 = new BitSet(new long[]{0x0000000000000004L}); ++ public static final BitSet FOLLOW_expr_in_expr263 = new BitSet(new long[]{0x000000000003E650L}); ++ public static final BitSet FOLLOW_expr_in_expr269 = new BitSet(new long[]{0x0000000000000008L}); ++ public static final BitSet FOLLOW_PARENTHESES_in_expr303 = new BitSet(new long[]{0x0000000000020000L}); ++ public static final BitSet FOLLOW_POW_in_expr310 = new BitSet(new long[]{0x0000000000000004L}); ++ public static final BitSet FOLLOW_expr_in_expr316 = new BitSet(new long[]{0x000000000003E650L}); ++ public static final BitSet FOLLOW_expr_in_expr322 = new BitSet(new long[]{0x0000000000000008L}); ++ public static final BitSet FOLLOW_PARENTHESES_in_expr356 = new BitSet(new long[]{0x0000000000000400L}); ++ public static final BitSet FOLLOW_IDENTIFIER_in_expr367 = new BitSet(new long[]{0x0000000000000004L}); ++ public static final BitSet FOLLOW_expr_in_expr373 = new BitSet(new long[]{0x000000000003E658L}); ++ public static final BitSet FOLLOW_expr_in_expr381 = new BitSet(new long[]{0x0000000000000008L}); ++ public static final BitSet FOLLOW_primary_expr_in_expr416 = new BitSet(new long[]{0x0000000000000002L}); ++ public static final BitSet FOLLOW_PARENTHESES_in_primary_expr439 = new BitSet(new long[]{0x0000000000000010L}); ++ public static final BitSet FOLLOW_DECIMAL_LITERAL_in_primary_expr448 = new BitSet(new long[]{0x0000000000000002L}); ++ public static final BitSet FOLLOW_PARENTHESES_in_primary_expr461 = new BitSet(new long[]{0x0000000000000200L}); ++ public static final BitSet FOLLOW_FLOATING_POINT_LITERAL_in_primary_expr470 = new BitSet(new long[]{0x0000000000000002L}); ++ public static final BitSet FOLLOW_PARENTHESES_in_primary_expr483 = new BitSet(new long[]{0x0000000000000400L}); ++ public static final BitSet FOLLOW_IDENTIFIER_in_primary_expr492 = new BitSet(new long[]{0x0000000000000002L}); ++ ++} +\ No newline at end of file diff -Nru jsurf-alggeo-0.3.0+ds/debian/patches/debianization.patch jsurf-alggeo-0.4.1+ds/debian/patches/debianization.patch --- jsurf-alggeo-0.3.0+ds/debian/patches/debianization.patch 2015-12-02 09:07:26.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/debian/patches/debianization.patch 2018-06-05 16:38:01.000000000 +0000 @@ -4,11 +4,11 @@ Origin: debian Forwarded: not-needed Author: Jerome Benoit -Last-Update: 2015-11-26 +Last-Update: 2018-06-05 --- a/src/main/java/de/mfo/jsurf/Main.java +++ b/src/main/java/de/mfo/jsurf/Main.java -@@ -40,7 +40,7 @@ +@@ -49,7 +49,7 @@ public class Main { @@ -16,4 +16,4 @@ + public static final String jsurf_progname = "jsurf-alggeo"; static int size = 512; - static AntiAliasingMode aam; + static int quality = 1; diff -Nru jsurf-alggeo-0.3.0+ds/debian/patches/series jsurf-alggeo-0.4.1+ds/debian/patches/series --- jsurf-alggeo-0.3.0+ds/debian/patches/series 2015-12-02 09:07:26.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/debian/patches/series 2018-06-05 16:38:01.000000000 +0000 @@ -1,3 +1,3 @@ -upstream-revisit-option_machnery.patch debianization.patch +add-generated-java-files.patch debianization-documentation.patch diff -Nru jsurf-alggeo-0.3.0+ds/debian/patches/upstream-revisit-option_machnery.patch jsurf-alggeo-0.4.1+ds/debian/patches/upstream-revisit-option_machnery.patch --- jsurf-alggeo-0.3.0+ds/debian/patches/upstream-revisit-option_machnery.patch 2015-12-02 09:07:26.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/debian/patches/upstream-revisit-option_machnery.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,150 +0,0 @@ -Description: revisit (and fix) option machniery - Attempt to format and harmonize the options, usages, and help messages - of jsurf-alggeo front-end programs wrt UN*X customs: - reinsert the output option for both backward compatibility and customary - usage; render compatible with help2man; ps2pdf(1) has been a source of - reference and inspiration in that matter; meant to be submitted to the - upstream maintainer. -Origin: debian -Author: Jerome Benoit -Last-Update: 2015-11-26 - ---- a/src/main/java/de/mfo/jsurf/Main.java -+++ b/src/main/java/de/mfo/jsurf/Main.java -@@ -30,6 +30,7 @@ - import javax.swing.JLabel; - import javax.swing.SwingUtilities; - -+import org.apache.commons.io.FilenameUtils; - import org.apache.commons.cli.*; - - import de.mfo.jsurf.rendering.cpu.AntiAliasingPattern; -@@ -41,7 +42,7 @@ - - public static final String jsurf_progname = "jsurf"; - -- static int size = 100; -+ static int size = 512; - static AntiAliasingMode aam; - static AntiAliasingPattern aap; - -@@ -72,9 +73,10 @@ - */ - public static void main(String[] args) { - -+ int helper_width = 103; - String jsurf_filename = null; - String output_filename = null; -- boolean show_gui = false; -+ boolean show_gui = false; - - Options options = new Options(); - -@@ -82,22 +84,28 @@ - options.addOption( OptionBuilder.withLongOpt( "version" ).withDescription( "print program version and exit" ).create() ); - options.addOption("s","size", true, "image width and height (default: " + size + ")"); - options.addOption("q","quality",true,"quality of the rendering: 0 (low), 1 (medium, default), 2 (high), 3 (extreme)"); -- if( !java.awt.GraphicsEnvironment.isHeadless() ) -- options.addOption( OptionBuilder.withLongOpt( "gui" ).withDescription( "display the rendering (png_output becomes optional)" ).create() ); -+ options.addOption("o","output",true,"output PNG into this file (overrode by the 2nd argument if present)"); -+ options.addOption( OptionBuilder.withLongOpt( "gui" ).withDescription( "display rendering (overrides output options)" ).create() ); - - CommandLineParser parser = new PosixParser(); - HelpFormatter formatter = new HelpFormatter(); -- String cmd_line_syntax = jsurf_progname + " [options] jsurf_input png_output\n\n"; -+ String cmd_line_syntax = jsurf_progname + " [options...] {jsurf_input|-} [png_output|-]\n\n"; - String help_header = jsurf_progname + " is a renderer for real algebraic surfaces.\n" + -- "Specify files as '-' for standard input and output."; -+ jsurf_progname + " translates its own language script files (generally with extension '.jsurf') into Portable Network Graphics (PNG) files; " + -+ "PNG is a raster graphics file format that supports lossless data compression.\n" + -+ "If the output filename is not specified, the output is placed in a file of the same basename with a '.png' extension in the current working directory.\n" + -+ "Either the input filename or the output filename can be '-' to request reading from stdin or writing to stdout, respectively. " + -+ "Whenever the Graphic Unit Interface (GUI) is available, the gui option takes precedence over the output options, otherwise it is ignored. " + -+ "That is, whenever the gui option is present (and available), the output is displayed in a window rather than written in a PNG file.\n" + -+ "\n" ; - String help_footer = ""; - try - { - CommandLine cmd = parser.parse( options, args ); -- -+ - if( cmd.hasOption( "help" ) ) - { -- formatter.printHelp( cmd_line_syntax, help_header, options, help_footer ); -+ formatter.printHelp( helper_width, cmd_line_syntax, help_header, options, help_footer ); - return; - } - -@@ -107,6 +115,9 @@ - return; - } - -+ if( cmd.hasOption( "output" ) ) -+ output_filename = cmd.getOptionValue("output"); -+ - if( cmd.hasOption("size") ) - size = Integer.parseInt( cmd.getOptionValue("size") ); - -@@ -132,19 +143,30 @@ - aap = AntiAliasingPattern.QUINCUNX; - } - -- show_gui = cmd.hasOption( "gui" ); -+ if( cmd.hasOption( "gui" ) ) -+ show_gui = !java.awt.GraphicsEnvironment.isHeadless() ; - -- if( cmd.getArgs().length == 0 || ( cmd.getArgs().length == 1 && !show_gui ) || cmd.getArgs().length > 2 ) -- { -- formatter.printHelp( cmd_line_syntax, help_header, options, help_footer ); -+ if( cmd.getArgs().length == 0 || cmd.getArgs().length > 2 ) -+ { -+ formatter.printHelp( helper_width, cmd_line_syntax, help_header, options, help_footer ); - System.exit( -1 ); - } - else -- { -- jsurf_filename = cmd.getArgs()[ 0 ]; -- if( cmd.getArgs().length > 1 ) -- output_filename = cmd.getArgs()[ 1 ]; -- } -+ { -+ jsurf_filename = cmd.getArgs()[ 0 ]; -+ if (!show_gui) -+ { -+ if( cmd.getArgs().length > 1 ) output_filename = cmd.getArgs()[ 1 ]; -+ if( output_filename == null ) -+ { -+ output_filename = FilenameUtils.getBaseName( jsurf_filename ) + ".png" ; -+ } -+ } -+ else -+ { -+ output_filename = null ; -+ } -+ } - } - catch( ParseException exp ) { - System.out.println( "Unexpected exception:" + exp.getMessage() ); -@@ -155,7 +177,7 @@ - formatter.printHelp( cmd_line_syntax, help_header, options, help_footer ); - System.exit( -1 ); - } -- -+ - try - { - Properties jsurf = new Properties(); -@@ -214,8 +236,11 @@ - - if( show_gui ) - { -- // display the image in a window -- final String window_title = "jsurf: " + jsurf_filename; -+ // display the image in a window -+ final String window_title = -+ jsurf_progname + ": " + -+ FilenameUtils.getBaseName( jsurf_filename ) + -+ " (" + FilenameUtils.getFullPathNoEndSeparator( jsurf_filename ) + ")" ; - final BufferedImage window_image = bi; - SwingUtilities.invokeLater( new Runnable() { - public void run() diff -Nru jsurf-alggeo-0.3.0+ds/debian/rules jsurf-alggeo-0.4.1+ds/debian/rules --- jsurf-alggeo-0.3.0+ds/debian/rules 2015-12-02 09:07:26.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/debian/rules 2018-06-04 03:46:13.000000000 +0000 @@ -1,7 +1,8 @@ #!/usr/bin/make -f +include /usr/share/dpkg/pkg-info.mk -UPS_PKG_VERSION = $(shell dpkg-parsechangelog | sed -n -e '/^Version:/s/Version: //p' | sed s/+.*//) -DEB_PKG_VERSION = $(shell dpkg-parsechangelog | sed -n -e '/^Version:/s/Version: //p') +UPS_PKG_VERSION = $(shell echo $(DEB_VERSION_UPSTREAM) | sed s/+.*//) +DEB_PKG_VERSION = $(DEB_VERSION) export JAVA_HOME ?= /usr/lib/jvm/default-java export CLASSPATH = /usr/share/java/vecmath.jar:/usr/share/java/antlr3-runtime.jar:/usr/share/java/commons-io.jar:/usr/share/java/commons-cli.jar @@ -48,9 +49,6 @@ -$(RM) debian/poms/jsurf-alggeo.pom -$(RMDIR) debian/poms -get-orig-source: - uscan --no-conf --download-current-version --compression xz --verbose - MKDIR_P ?= /bin/mkdir --parents -RMDIR ?= /bin/rmdir +RMDIR ?= /bin/rmdir RM ?= /bin/rm diff -Nru jsurf-alggeo-0.3.0+ds/debian/source/lintian-overrides jsurf-alggeo-0.4.1+ds/debian/source/lintian-overrides --- jsurf-alggeo-0.3.0+ds/debian/source/lintian-overrides 2015-12-02 09:07:26.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/debian/source/lintian-overrides 2018-06-04 03:28:54.000000000 +0000 @@ -1 +1 @@ -debian-watch-may-check-gpg-signature +debian-watch-does-not-check-gpg-signature diff -Nru jsurf-alggeo-0.3.0+ds/debian/watch jsurf-alggeo-0.4.1+ds/debian/watch --- jsurf-alggeo-0.3.0+ds/debian/watch 2015-12-02 09:07:26.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/debian/watch 2018-06-04 03:32:09.000000000 +0000 @@ -1,3 +1,3 @@ -version=3 -opts=dversionmangle=s/\+ds//,repacksuffix=+ds,filenamemangle=s/.+\/v?(\d\S*)\.tar\.gz/jsurf-alggeo-$1\.tar\.gz/ \ +version=4 +opts=repack,compression=xz,dversionmangle=s/\+ds//,repacksuffix=+ds,filenamemangle=s/.+\/v?(\d\S*)\.tar\.gz/jsurf-alggeo-$1\.tar\.gz/ \ https://github.com/IMAGINARY/jsurf/releases .*/v?(\d+\.\d+\.\d+)\.tar\.gz diff -Nru jsurf-alggeo-0.3.0+ds/.editorconfig jsurf-alggeo-0.4.1+ds/.editorconfig --- jsurf-alggeo-0.3.0+ds/.editorconfig 1970-01-01 00:00:00.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/.editorconfig 2018-06-05 16:36:49.000000000 +0000 @@ -0,0 +1,13 @@ +# This file is for unifying the coding style for different editors and IDEs. +# More information at http://EditorConfig.org + +# No .editorconfig files above the root directory +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true diff -Nru jsurf-alggeo-0.3.0+ds/src/main/antlr/de/mfo/jsurf/parser/AlgebraicExpression.g jsurf-alggeo-0.4.1+ds/src/main/antlr/de/mfo/jsurf/parser/AlgebraicExpression.g --- jsurf-alggeo-0.3.0+ds/src/main/antlr/de/mfo/jsurf/parser/AlgebraicExpression.g 1970-01-01 00:00:00.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/antlr/de/mfo/jsurf/parser/AlgebraicExpression.g 2018-06-05 16:36:49.000000000 +0000 @@ -0,0 +1,165 @@ +/* + * Copyright 2008 Christian Stussak + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +grammar AlgebraicExpression; + +options { language = Java; output = AST; } + +tokens { + PLUS = '+' ; + MINUS = '-' ; + MULT = '*' ; + DIV = '/' ; + POW = '^' ; + LPAR = '(' ; + RPAR = ')' ; + PARENTHESES; +} + +@header +{ +package de.mfo.jsurf.parser; + +import de.mfo.jsurf.algebra.*; +} +@lexer::header +{ +package de.mfo.jsurf.parser; +} + +@members { + public static PolynomialOperation parse( String s ) + throws Exception + { + // Create a string + ANTLRStringStream input = new ANTLRStringStream( s ); + + // Create an ExprLexer that feeds from that stream + AlgebraicExpressionLexer lexer = new AlgebraicExpressionLexer( input ); + + // Create a stream of tokens fed by the lexer + CommonTokenStream tokens = new CommonTokenStream( lexer ); + + // Create a parser that feeds off the token stream + AlgebraicExpressionParser parser = new AlgebraicExpressionParser( tokens ); + + // Begin parsing at start rule + AlgebraicExpressionParser.start_return r = parser.start(); + + // Create a stream of nodes fed by the parser + CommonTreeNodeStream nodes = new CommonTreeNodeStream( ( CommonTree ) r.getTree() ); + + // Create a tree parser that feeds off the node stream + AlgebraicExpressionWalker walker = new AlgebraicExpressionWalker( nodes ); + + // Begin tree parsing at start rule + return walker.start(); + } + + protected void mismatch( IntStream input, int ttype, BitSet follow ) + throws RecognitionException + { + throw new MismatchedTokenException(ttype, input); + } + + @Override + public java.lang.Object recoverFromMismatchedSet( IntStream input, RecognitionException e, BitSet follow ) + throws RecognitionException + { + throw e; + } + + @Override + protected Object recoverFromMismatchedToken( IntStream input, int ttype, BitSet follow ) + throws RecognitionException + { + throw new MismatchedTokenException( ttype, input ); + } +} + +@rulecatch { + catch( RecognitionException e ) + { + throw e; + } +} + +/*------------------------------------------------------------------ + * PARSER RULES + *------------------------------------------------------------------*/ + +start + : add_expr EOF! + ; + +add_expr + : mult_expr ( PLUS^ mult_expr | MINUS^ mult_expr )* + ; + +mult_expr + : neg_expr ( MULT^ neg_expr | DIV^ neg_expr )* + ; + +neg_expr + : MINUS^ pow_expr + | pow_expr + ; + +pow_expr + : unary_expr ( POW^ pow_expr )? + ; + +unary_expr + : primary_expr + | IDENTIFIER LPAR add_expr RPAR -> ^(IDENTIFIER PARENTHESES add_expr) + ; + +primary_expr + : DECIMAL_LITERAL + | FLOATING_POINT_LITERAL + | IDENTIFIER + | LPAR add_expr RPAR -> PARENTHESES add_expr + ; + +/*------------------------------------------------------------------ + * LEXER RULES + *------------------------------------------------------------------*/ + +DECIMAL_LITERAL : ( '0' | '1'..'9' '0'..'9'* ) ; + +FLOATING_POINT_LITERAL + : DIGIT+ '.' DIGIT* EXPONENT? + | '.' DIGIT+ EXPONENT? + | DIGIT+ EXPONENT + ; + +fragment +EXPONENT : ( 'e' | 'E' ) ( PLUS | MINUS )? DIGIT+ ; + +IDENTIFIER : LETTER ( LETTER | DIGIT )*; + +WHITESPACE : ( '\t' | ' ' | '\r' | '\n' | '\u000C' )+ { $channel = HIDDEN; } ; + +fragment DIGIT : '0'..'9' ; + +fragment +LETTER + : 'A'..'Z' + | 'a'..'z' + | '_' + ; + +ERRCHAR : .; diff -Nru jsurf-alggeo-0.3.0+ds/src/main/antlr/de/mfo/jsurf/parser/AlgebraicExpressionWalker.g jsurf-alggeo-0.4.1+ds/src/main/antlr/de/mfo/jsurf/parser/AlgebraicExpressionWalker.g --- jsurf-alggeo-0.3.0+ds/src/main/antlr/de/mfo/jsurf/parser/AlgebraicExpressionWalker.g 1970-01-01 00:00:00.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/antlr/de/mfo/jsurf/parser/AlgebraicExpressionWalker.g 2018-06-05 16:36:49.000000000 +0000 @@ -0,0 +1,184 @@ +/* + * Copyright 2008 Christian Stussak + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +tree grammar AlgebraicExpressionWalker; + +options { tokenVocab = AlgebraicExpression; ASTLabelType = CommonTree; } + +@header +{ +package de.mfo.jsurf.parser; + +import de.mfo.jsurf.algebra.*; +} + +@members +{ + public static PolynomialOperation createVariable( String name, boolean hasParentheses ) + { + try + { + return new PolynomialVariable( PolynomialVariable.Var.valueOf( name ), hasParentheses ); + } + catch( Exception e ) + { + return new DoubleVariable( name, hasParentheses ); + } + } + + public static int createInteger( String text ) + { + try + { + return Integer.parseInt( text ); + } + catch( NumberFormatException nfe ) + { + return 0; + } + } +} + +start returns [ PolynomialOperation op ] + : e = expr { $op = $e.op; } + ; + +expr returns [ PolynomialOperation op, Integer decimal ] + : ( p = PARENTHESES )? ^( PLUS e1 = expr e2 = expr ) + { + try + { + $op = new DoubleBinaryOperation( DoubleBinaryOperation.Op.add, ( DoubleOperation ) $e1.op, ( DoubleOperation ) $e2.op, p != null ); + } + catch( ClassCastException cce ) + { + $op = new PolynomialAddition( $e1.op, $e2.op, p != null ); + } + } + | ( p = PARENTHESES )? ^( MINUS e1 = expr ( e2 = expr )? ) + { + if( e2 != null ) + { + // subtraction + try + { + $op = new DoubleBinaryOperation( DoubleBinaryOperation.Op.sub, ( DoubleOperation ) $e1.op, ( DoubleOperation ) $e2.op, p != null ); + } + catch( ClassCastException cce ) + { + $op = new PolynomialSubtraction( $e1.op, $e2.op, p != null ); + } + } + else + { + try + { + $op = new DoubleUnaryOperation( DoubleUnaryOperation.Op.neg, ( DoubleOperation ) $e1.op, p != null ); + } + catch( ClassCastException cce ) + { + $op = new PolynomialNegation( $e1.op, p != null ); + } + } + } + | ( p = PARENTHESES )? ^( MULT e1 = expr e2 = expr ) + { + try + { + $op = new DoubleBinaryOperation( DoubleBinaryOperation.Op.mult, ( DoubleOperation ) $e1.op, ( DoubleOperation ) $e2.op ); + } + catch( ClassCastException cce ) + { + $op = new PolynomialMultiplication( $e1.op, $e2.op, p != null ); + } + } + | ( p = PARENTHESES )? ^( DIV e1 = expr e2 = expr ) + { + try + { + $op = new DoubleBinaryOperation( DoubleBinaryOperation.Op.div, ( DoubleOperation ) $e1.op, ( DoubleOperation ) $e2.op, p != null ); + } + catch( ClassCastException cce1 ) + { + try + { + $op = new PolynomialDoubleDivision( $e1.op, ( DoubleOperation ) $e2.op, p != null ); + } + catch( ClassCastException cce2 ) + { + throw new RecognitionException(); + } + } + } + | ( p = PARENTHESES )? ^( POW e1 = expr e2 = expr ) + { + try + { + $op = new DoubleBinaryOperation( DoubleBinaryOperation.Op.pow, ( DoubleOperation ) $e1.op, ( DoubleOperation ) $e2.op, p != null ); + } + catch( ClassCastException cce ) + { + if( $e2.decimal == null ) + { + throw new RecognitionException(); + } + else + { + $op = new PolynomialPower( $e1.op, $e2.decimal, p != null ); + } + } + } + | ( p = PARENTHESES )? ^( id = IDENTIFIER e1 = expr ( e2 = expr )? ) + { + if( e2 != null ) + { + try + { + $op = new DoubleBinaryOperation( DoubleBinaryOperation.Op.valueOf( $id.text ), ( DoubleOperation ) $e1.op, ( DoubleOperation ) $e2.op, p != null ); + } + catch( ClassCastException cce ) + { + throw new RecognitionException(); + } + catch( IllegalArgumentException iae ) + { + throw new RecognitionException(); + } + } + else + { + try + { + $op = new DoubleUnaryOperation( DoubleUnaryOperation.Op.valueOf( $id.text ), ( DoubleOperation ) $e1.op, p != null ); + } + catch( ClassCastException cce ) + { + throw new RecognitionException(); + } + catch( IllegalArgumentException iae ) + { + throw new RecognitionException(); + } + } + } + | pe = primary_expr { $op = $pe.op; $decimal = pe.decimal; } + ; + +primary_expr returns [ PolynomialOperation op, Integer decimal ] + : ( p = PARENTHESES )? i = DECIMAL_LITERAL { $op = new DoubleValue( $i.text, p != null ); $decimal = Integer.valueOf( createInteger( $i.text ) ); } + | ( p = PARENTHESES )? f = FLOATING_POINT_LITERAL { $op = new DoubleValue( $f.text, p != null ); } + | ( p = PARENTHESES )? id = IDENTIFIER { $op = createVariable( $id.text, p != null ); } + ; diff -Nru jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/CloneVisitor.java jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/CloneVisitor.java --- jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/CloneVisitor.java 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/CloneVisitor.java 2018-06-05 16:36:49.000000000 +0000 @@ -20,32 +20,32 @@ public PolynomialOperation visit( PolynomialAddition pa, Void param ) { - return new PolynomialAddition( pa.firstOperand.accept( this, ( Void ) null ), pa.secondOperand.accept( this, ( Void ) null ) ); + return new PolynomialAddition( pa.getFirstOperand().accept( this, ( Void ) null ), pa.getSecondOperand().accept( this, ( Void ) null ) ); } public PolynomialOperation visit( PolynomialSubtraction ps, Void param ) { - return new PolynomialSubtraction( ps.firstOperand.accept( this, ( Void ) null ), ps.secondOperand.accept( this, ( Void ) null ) ); + return new PolynomialSubtraction( ps.getFirstOperand().accept( this, ( Void ) null ), ps.getSecondOperand().accept( this, ( Void ) null ) ); } public PolynomialOperation visit( PolynomialMultiplication pm, Void param ) { - return new PolynomialMultiplication( pm.firstOperand.accept( this, ( Void ) null ), pm.secondOperand.accept( this, ( Void ) null ) ); + return new PolynomialMultiplication( pm.getFirstOperand().accept( this, ( Void ) null ), pm.getSecondOperand().accept( this, ( Void ) null ) ); } public PolynomialOperation visit( PolynomialPower pp, Void param ) { - return new PolynomialPower( pp.base.accept( this, ( Void ) null ), pp.exponent ); + return new PolynomialPower( pp.getBase().accept( this, ( Void ) null ), pp.getExponent() ); } public PolynomialOperation visit( PolynomialNegation pn, Void param ) { - return new PolynomialNegation( pn.operand.accept( this, ( Void ) null ) ); + return new PolynomialNegation( pn.getOperand().accept( this, ( Void ) null ) ); } public PolynomialOperation visit( PolynomialDoubleDivision pdd, Void param ) { - return new PolynomialDoubleDivision( pdd.dividend.accept( this, ( Void ) null ), ( DoubleOperation ) pdd.divisor.accept( this, ( Void ) null ) ); + return new PolynomialDoubleDivision( pdd.getDividend().accept( this, ( Void ) null ), ( DoubleOperation ) pdd.getDivisor().accept( this, ( Void ) null ) ); } public PolynomialOperation visit( PolynomialVariable pv, Void param ) @@ -55,14 +55,14 @@ public DoubleOperation visit( DoubleBinaryOperation dbop, Void param ) { - DoubleOperation firstOperand = ( DoubleOperation ) dbop.firstOperand.accept( this, ( Void ) null ); - DoubleOperation secondOperand = ( DoubleOperation ) dbop.secondOperand.accept( this, ( Void ) null ); - return new DoubleBinaryOperation( dbop.operator, firstOperand, secondOperand ); + DoubleOperation firstOperand = ( DoubleOperation ) dbop.getFirstOperand().accept( this, ( Void ) null ); + DoubleOperation secondOperand = ( DoubleOperation ) dbop.getSecondOperand().accept( this, ( Void ) null ); + return new DoubleBinaryOperation( dbop.getOperator(), firstOperand, secondOperand ); } public DoubleOperation visit( DoubleUnaryOperation duop, Void param ) { - return new DoubleUnaryOperation( duop.operator, ( DoubleOperation ) duop.operand.accept( this, ( Void ) null ) ); + return new DoubleUnaryOperation( duop.getOperator(), ( DoubleOperation ) duop.getOperand().accept( this, ( Void ) null ) ); } public DoubleOperation visit( DoubleValue dv, Void param ) @@ -72,6 +72,6 @@ public DoubleOperation visit( DoubleVariable dv, Void param ) { - return new DoubleVariable( dv.name ); + return new DoubleVariable( dv.getName() ); } } diff -Nru jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/DegreeCalculator.java jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/DegreeCalculator.java --- jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/DegreeCalculator.java 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/DegreeCalculator.java 2018-06-05 16:36:49.000000000 +0000 @@ -20,44 +20,44 @@ { public Integer visit( PolynomialAddition pa, Void param ) { - return Math.max( pa.firstOperand.accept( this, ( Void ) null ), pa.secondOperand.accept( this, ( Void ) null ) ); + return Math.max( pa.getFirstOperand().accept( this, ( Void ) null ), pa.getSecondOperand().accept( this, ( Void ) null ) ); } public Integer visit( PolynomialSubtraction ps, Void param ) { - return Math.max( ps.firstOperand.accept( this, ( Void ) null ), ps.secondOperand.accept( this, ( Void ) null ) ); + return Math.max( ps.getFirstOperand().accept( this, ( Void ) null ), ps.getSecondOperand().accept( this, ( Void ) null ) ); } - + public Integer visit( PolynomialMultiplication pm, Void param ) { - return pm.firstOperand.accept( this, ( Void ) null ) + pm.secondOperand.accept( this, ( Void ) null ); + return pm.getFirstOperand().accept( this, ( Void ) null ) + pm.getSecondOperand().accept( this, ( Void ) null ); } public Integer visit( PolynomialPower pp, Void param ) { - return pp.exponent * pp.base.accept( this, ( Void ) null ); + return pp.getExponent() * pp.getBase().accept( this, ( Void ) null ); } - + public Integer visit( PolynomialNegation pn, Void param ) { - return pn.operand.accept( this, ( Void ) null ); + return pn.getOperand().accept( this, ( Void ) null ); } public Integer visit( PolynomialDoubleDivision pdd, Void param ) { - return pdd.dividend.accept( this, ( Void ) null ); + return pdd.getDividend().accept( this, ( Void ) null ); } - + public Integer visit( PolynomialVariable pv, Void param ) { return 1; - } - + } + public Integer visit( DoubleBinaryOperation dbop, Void param ) { return 0; } - + public Integer visit( DoubleUnaryOperation duop, Void param ) { return 0; diff -Nru jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/Differentiator.java jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/Differentiator.java --- jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/Differentiator.java 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/Differentiator.java 2018-06-05 16:36:49.000000000 +0000 @@ -19,86 +19,86 @@ public class Differentiator extends AbstractVisitor< PolynomialOperation, Void > { private PolynomialVariable.Var var; - + public Differentiator( PolynomialVariable.Var var ) { this.var = var; } - + public PolynomialVariable.Var getVariable() { return this.var; } - + public void setVariable( PolynomialVariable.Var var ) { this.var = var; } - + public PolynomialOperation visit( PolynomialAddition pa, Void param ) { - return new PolynomialAddition( pa.firstOperand.accept( this, ( Void ) null ), pa.secondOperand.accept( this, ( Void ) null ) ); + return new PolynomialAddition( pa.getFirstOperand().accept( this, ( Void ) null ), pa.getSecondOperand().accept( this, ( Void ) null ) ); } - + public PolynomialOperation visit( PolynomialSubtraction ps, Void param ) { - return new PolynomialSubtraction( ps.firstOperand.accept( this, ( Void ) null ), ps.secondOperand.accept( this, ( Void ) null ) ); + return new PolynomialSubtraction( ps.getFirstOperand().accept( this, ( Void ) null ), ps.getSecondOperand().accept( this, ( Void ) null ) ); } - + public PolynomialOperation visit( PolynomialMultiplication pm, Void param ) { - PolynomialOperation u = pm.firstOperand; - PolynomialOperation v = pm.secondOperand; + PolynomialOperation u = pm.getFirstOperand(); + PolynomialOperation v = pm.getSecondOperand(); PolynomialOperation udiff = u.accept( this, ( Void ) null ); PolynomialOperation vdiff = v.accept( this, ( Void ) null ); - + return new PolynomialAddition( new PolynomialMultiplication( udiff, v ), new PolynomialMultiplication( u, vdiff ) ); } - + public PolynomialOperation visit( PolynomialPower pp, Void param ) { - switch( pp.exponent ) + switch( pp.getExponent() ) { case 1: return new DoubleValue( 1.0 ); case 2: { - PolynomialOperation u = pp.base; + PolynomialOperation u = pp.getBase(); PolynomialOperation udiff = u.accept( this, ( Void ) null ); - return new PolynomialMultiplication( new PolynomialMultiplication( new DoubleValue( ( double ) pp.exponent ), u ), udiff ); + return new PolynomialMultiplication( new PolynomialMultiplication( new DoubleValue( ( double ) pp.getExponent() ), u ), udiff ); } default: { - PolynomialOperation u = pp.base; + PolynomialOperation u = pp.getBase(); PolynomialOperation udiff = u.accept( this, ( Void ) null ); - return new PolynomialMultiplication( new PolynomialMultiplication( new DoubleValue( ( double ) pp.exponent ), new PolynomialPower( u, pp.exponent - 1 ) ), udiff ); + return new PolynomialMultiplication( new PolynomialMultiplication( new DoubleValue( ( double ) pp.getExponent() ), new PolynomialPower( u, pp.getExponent() - 1 ) ), udiff ); } } } public PolynomialOperation visit( PolynomialNegation pn, Void param ) { - return new PolynomialNegation( pn.operand.accept( this,( Void ) null ) ); + return new PolynomialNegation( pn.getOperand().accept( this,( Void ) null ) ); } - + public PolynomialOperation visit( PolynomialDoubleDivision pdd, Void param ) { - return new PolynomialDoubleDivision( pdd.dividend.accept( this,( Void ) null ), pdd.divisor ); + return new PolynomialDoubleDivision( pdd.getDividend().accept( this,( Void ) null ), pdd.getDivisor() ); } public PolynomialOperation visit( PolynomialVariable pv, Void param ) { - if( pv.variable == this.var ) + if( pv.getVariable() == this.var ) return new DoubleValue( 1.0 ); else return new DoubleValue( 0.0 ); } - + public PolynomialOperation visit( DoubleBinaryOperation dbop, Void param ) { return new DoubleValue( 0.0 ); } - + public PolynomialOperation visit( DoubleUnaryOperation duop, Void param ) { return new DoubleValue( 0.0 ); diff -Nru jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/DoubleBinaryOperation.java jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/DoubleBinaryOperation.java --- jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/DoubleBinaryOperation.java 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/DoubleBinaryOperation.java 2018-06-05 16:36:49.000000000 +0000 @@ -18,19 +18,31 @@ public class DoubleBinaryOperation implements DoubleOperation { - public enum Op { add, sub, mult, div, pow, atan2; } - - public Op operator; - public DoubleOperation firstOperand; - public DoubleOperation secondOperand; - + public enum Op { add, sub, mult, div, pow; } + + private Op operator; + private DoubleOperation firstOperand; + private DoubleOperation secondOperand; + private boolean hasParentheses; + public DoubleBinaryOperation( Op operator, DoubleOperation firstOperand, DoubleOperation secondOperand ) { + this( operator, firstOperand, secondOperand, false ); + } + + public DoubleBinaryOperation( Op operator, DoubleOperation firstOperand, DoubleOperation secondOperand, boolean hasParentheses ) + { this.operator = operator; this.firstOperand = firstOperand; this.secondOperand = secondOperand; + this.hasParentheses = hasParentheses; } + public Op getOperator() { return operator; } + public DoubleOperation getFirstOperand() { return firstOperand; } + public DoubleOperation getSecondOperand() { return secondOperand; } + public boolean hasParentheses() { return hasParentheses; } + public < RETURN_TYPE, PARAM_TYPE > RETURN_TYPE accept( Visitor< RETURN_TYPE, PARAM_TYPE > visitor, PARAM_TYPE arg ) { return visitor.visit( this, arg ); diff -Nru jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/DoubleUnaryOperation.java jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/DoubleUnaryOperation.java --- jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/DoubleUnaryOperation.java 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/DoubleUnaryOperation.java 2018-06-05 16:36:49.000000000 +0000 @@ -19,16 +19,27 @@ public class DoubleUnaryOperation implements DoubleOperation { public enum Op { neg, sin, cos, tan, asin, acos, atan, exp, log, sqrt, ceil, floor, abs, sign; } - - public Op operator; - public DoubleOperation operand; - + + private Op operator; + private DoubleOperation operand; + private boolean hasParentheses; + public DoubleUnaryOperation( Op operator, DoubleOperation operand ) { + this( operator, operand, false ); + } + + public DoubleUnaryOperation( Op operator, DoubleOperation operand, boolean hasParentheses ) + { this.operator = operator; this.operand = operand; + this.hasParentheses = hasParentheses; } - + + public Op getOperator() { return operator; } + public DoubleOperation getOperand() { return operand; } + public boolean hasParentheses() { return hasParentheses; } + public < RETURN_TYPE, PARAM_TYPE > RETURN_TYPE accept( Visitor< RETURN_TYPE, PARAM_TYPE > visitor, PARAM_TYPE arg ) { return visitor.visit( this, arg ); diff -Nru jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/DoubleValue.java jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/DoubleValue.java --- jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/DoubleValue.java 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/DoubleValue.java 2018-06-05 16:36:49.000000000 +0000 @@ -18,15 +18,45 @@ public class DoubleValue implements DoubleOperation { - public double value; - + private double value; + private String stringValue; + private boolean hasParentheses; + + public DoubleValue( String stringValue ) + { + this( stringValue, false ); + } + + public DoubleValue( String stringValue, boolean hasParentheses ) + { + this.stringValue = stringValue; + this.value = Double.parseDouble( stringValue ); + this.hasParentheses = hasParentheses; + } + public DoubleValue( double value ) { + this( value, false ); + } + + public DoubleValue( double value, boolean hasParentheses ) + { this.value = value; + this.stringValue = value == (int) value ? String.valueOf( (int) value ) : String.valueOf( value ); + this.hasParentheses = hasParentheses; } - + + public double getValue() { return value; } + public boolean hasParentheses() { return hasParentheses; } + public < RETURN_TYPE, PARAM_TYPE > RETURN_TYPE accept( Visitor< RETURN_TYPE, PARAM_TYPE > visitor, PARAM_TYPE arg ) { return visitor.visit( this, arg ); } + + @Override + public String toString() + { + return this.stringValue; + } } diff -Nru jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/DoubleVariableExtractor.java jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/DoubleVariableExtractor.java --- jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/DoubleVariableExtractor.java 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/DoubleVariableExtractor.java 2018-06-05 16:36:49.000000000 +0000 @@ -22,39 +22,39 @@ { public Set< String > visit( PolynomialAddition pa, Void param ) { - Set< String > s = pa.firstOperand.accept( this, ( Void ) null ); - s.addAll( pa.secondOperand.accept( this, ( Void ) null ) ); + Set< String > s = pa.getFirstOperand().accept( this, ( Void ) null ); + s.addAll( pa.getSecondOperand().accept( this, ( Void ) null ) ); return s; } public Set< String > visit( PolynomialSubtraction ps, Void param ) { - Set< String > s = ps.firstOperand.accept( this, ( Void ) null ); - s.addAll( ps.secondOperand.accept( this, ( Void ) null ) ); + Set< String > s = ps.getFirstOperand().accept( this, ( Void ) null ); + s.addAll( ps.getSecondOperand().accept( this, ( Void ) null ) ); return s; } public Set< String > visit( PolynomialMultiplication pm, Void param ) { - Set< String > s = pm.firstOperand.accept( this, ( Void ) null ); - s.addAll( pm.secondOperand.accept( this, ( Void ) null ) ); + Set< String > s = pm.getFirstOperand().accept( this, ( Void ) null ); + s.addAll( pm.getSecondOperand().accept( this, ( Void ) null ) ); return s; } public Set< String > visit( PolynomialPower pp, Void param ) { - return pp.base.accept( this, ( Void ) null ); + return pp.getBase().accept( this, ( Void ) null ); } public Set< String > visit( PolynomialNegation pn, Void param ) { - return pn.operand.accept( this, ( Void ) null ); + return pn.getOperand().accept( this, ( Void ) null ); } public Set< String > visit( PolynomialDoubleDivision pdd, Void param ) { - Set< String > s = pdd.dividend.accept( this, ( Void ) null ); - s.addAll( pdd.divisor.accept( this, ( Void ) null ) ); + Set< String > s = pdd.getDividend().accept( this, ( Void ) null ); + s.addAll( pdd.getDivisor().accept( this, ( Void ) null ) ); return s; } @@ -65,14 +65,14 @@ public Set< String > visit( DoubleBinaryOperation dbop, Void param ) { - Set< String > s = dbop.firstOperand.accept( this, ( Void ) null ); - s.addAll( dbop.secondOperand.accept( this, ( Void ) null ) ); + Set< String > s = dbop.getFirstOperand().accept( this, ( Void ) null ); + s.addAll( dbop.getSecondOperand().accept( this, ( Void ) null ) ); return s; } public Set< String > visit( DoubleUnaryOperation duop, Void param ) { - return duop.operand.accept( this, ( Void ) null ); + return duop.getOperand().accept( this, ( Void ) null ); } public Set< String > visit( DoubleValue dv, Void param ) @@ -83,7 +83,7 @@ public Set< String > visit( DoubleVariable dv, Void param ) { HashSet< String > s = new HashSet< String >(); - s.add( dv.name ); + s.add( dv.getName() ); return s; } } diff -Nru jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/DoubleVariable.java jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/DoubleVariable.java --- jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/DoubleVariable.java 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/DoubleVariable.java 2018-06-05 16:36:49.000000000 +0000 @@ -18,13 +18,23 @@ public class DoubleVariable implements DoubleOperation { - public String name; - + private String name; + private boolean hasParentheses; + public DoubleVariable( String name ) { + this( name, false ); + } + + public DoubleVariable( String name, boolean hasParentheses ) + { this.name = name; + this.hasParentheses = hasParentheses; } - + + public String getName() { return name; } + public boolean hasParentheses() { return hasParentheses; } + public < RETURN_TYPE, PARAM_TYPE > RETURN_TYPE accept( Visitor< RETURN_TYPE, PARAM_TYPE > visitor, PARAM_TYPE arg ) { return visitor.visit( this, arg ); diff -Nru jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/DoubleVariableRenameVisitor.java jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/DoubleVariableRenameVisitor.java --- jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/DoubleVariableRenameVisitor.java 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/DoubleVariableRenameVisitor.java 2018-06-05 16:36:49.000000000 +0000 @@ -21,45 +21,45 @@ public class DoubleVariableRenameVisitor extends AbstractVisitor< PolynomialOperation, Void > { private Map< String, String > m; - + public DoubleVariableRenameVisitor( Map< String, String > m ) { this.m = m; } - + public PolynomialOperation visit( PolynomialAddition pa, Void param ) { - pa.firstOperand.accept( this, ( Void ) null ); - pa.secondOperand.accept( this, ( Void ) null ); + pa.getFirstOperand().accept( this, ( Void ) null ); + pa.getSecondOperand().accept( this, ( Void ) null ); return pa; } public PolynomialOperation visit( PolynomialSubtraction ps, Void param ) { - ps.firstOperand.accept( this, ( Void ) null ); - ps.secondOperand.accept( this, ( Void ) null ); + ps.getFirstOperand().accept( this, ( Void ) null ); + ps.getSecondOperand().accept( this, ( Void ) null ); return ps; } public PolynomialOperation visit( PolynomialMultiplication pm, Void param ) { - pm.firstOperand.accept( this, ( Void ) null ); - pm.secondOperand.accept( this, ( Void ) null ); + pm.getFirstOperand().accept( this, ( Void ) null ); + pm.getSecondOperand().accept( this, ( Void ) null ); return pm; } public PolynomialOperation visit( PolynomialPower pp, Void param ) { - return pp.base.accept( this, ( Void ) null ); + return pp.getBase().accept( this, ( Void ) null ); } public PolynomialOperation visit( PolynomialNegation pn, Void param ) { - pn.operand.accept( this, ( Void ) null ); + pn.getOperand().accept( this, ( Void ) null ); return pn; } public PolynomialOperation visit( PolynomialDoubleDivision pdd, Void param ) { - pdd.dividend.accept( this, ( Void ) null ); - pdd.divisor.accept( this, ( Void ) null ); + pdd.getDividend().accept( this, ( Void ) null ); + pdd.getDivisor().accept( this, ( Void ) null ); return pdd; } @@ -70,14 +70,14 @@ public PolynomialOperation visit( DoubleBinaryOperation dbop, Void param ) { - dbop.firstOperand.accept( this, ( Void ) null ); - dbop.secondOperand.accept( this, ( Void ) null ); + dbop.getFirstOperand().accept( this, ( Void ) null ); + dbop.getSecondOperand().accept( this, ( Void ) null ); return dbop; } public PolynomialOperation visit( DoubleUnaryOperation duop, Void param ) { - return duop.operand.accept( this, ( Void ) null ); + return duop.getOperand().accept( this, ( Void ) null ); } public PolynomialOperation visit( DoubleValue dv, Void param ) @@ -86,9 +86,8 @@ } public PolynomialOperation visit( DoubleVariable dv, Void param ) - { - String new_name = m.get( dv.name ); - dv.name = new_name != null ? new_name : dv.name; - return dv; + { + String new_name = m.get( dv.getName() ); + return new DoubleVariable( new_name != null ? new_name : dv.getName() ); } } diff -Nru jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/Expand.java jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/Expand.java --- jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/Expand.java 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/Expand.java 2018-06-05 16:36:49.000000000 +0000 @@ -19,57 +19,57 @@ public class Expand extends AbstractVisitor< XYZPolynomial, Void > { private ValueCalculator valueCalculator; - + public Expand() { this.valueCalculator = new ValueCalculator( 0.0, 0.0, 0.0 ); } - + public XYZPolynomial visit( PolynomialAddition pa, Void param ) { - XYZPolynomial first = pa.firstOperand.accept( this,( Void ) null ); - XYZPolynomial second = pa.secondOperand.accept( this,( Void ) null ); + XYZPolynomial first = pa.getFirstOperand().accept( this,( Void ) null ); + XYZPolynomial second = pa.getSecondOperand().accept( this,( Void ) null ); return first.add( second ); } - + public XYZPolynomial visit( PolynomialSubtraction ps, Void param ) { - XYZPolynomial first = ps.firstOperand.accept( this,( Void ) null ); - XYZPolynomial second = ps.secondOperand.accept( this,( Void ) null ); - + XYZPolynomial first = ps.getFirstOperand().accept( this,( Void ) null ); + XYZPolynomial second = ps.getSecondOperand().accept( this,( Void ) null ); + return first.sub( second ); } - + public XYZPolynomial visit( PolynomialMultiplication pm, Void param ) { - XYZPolynomial first = pm.firstOperand.accept( this,( Void ) null ); - XYZPolynomial second = pm.secondOperand.accept( this,( Void ) null ); - + XYZPolynomial first = pm.getFirstOperand().accept( this,( Void ) null ); + XYZPolynomial second = pm.getSecondOperand().accept( this,( Void ) null ); + return first.mult( second ); } - + public XYZPolynomial visit( PolynomialPower pp, Void param ) { - XYZPolynomial base = pp.base.accept( this,( Void ) null ); - return base.pow( pp.exponent ); + XYZPolynomial base = pp.getBase().accept( this,( Void ) null ); + return base.pow( pp.getExponent() ); } - + public XYZPolynomial visit( PolynomialNegation pn, Void param ) { - return pn.operand.accept( this,( Void ) null ).neg(); + return pn.getOperand().accept( this,( Void ) null ).neg(); } - + public XYZPolynomial visit( PolynomialDoubleDivision pdd, Void param ) { - XYZPolynomial dividend = pdd.dividend.accept( this,( Void ) null ); - double divisor = pdd.divisor.accept( this.valueCalculator, ( Void ) null ); + XYZPolynomial dividend = pdd.getDividend().accept( this,( Void ) null ); + double divisor = pdd.getDivisor().accept( this.valueCalculator, ( Void ) null ); return dividend.mult( 1.0 / divisor ); } - + public XYZPolynomial visit( PolynomialVariable pv, Void param ) { - switch( pv.variable ) + switch( pv.getVariable() ) { case x: return XYZPolynomial.X; @@ -78,15 +78,15 @@ case z: return XYZPolynomial.Z; default: - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(); } } - + public XYZPolynomial visit( DoubleBinaryOperation dbop, Void param ) { return new XYZPolynomial( dbop.accept( this.valueCalculator, ( Void ) null ) ); } - + public XYZPolynomial visit( DoubleUnaryOperation duop, Void param ) { return new XYZPolynomial( duop.accept( this.valueCalculator, ( Void ) null ) ); @@ -94,11 +94,11 @@ public XYZPolynomial visit( DoubleVariable dv, Void param ) { - throw new UnsupportedOperationException( "no value has been assigned to parameter '" + dv.name + "'" ); + throw new UnsupportedOperationException( "no value has been assigned to parameter '" + dv.getName() + "'" ); } - + public XYZPolynomial visit( DoubleValue dv, Void param ) { - return new XYZPolynomial( dv.value ); + return new XYZPolynomial( dv.getValue() ); } } diff -Nru jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialAddition.java jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialAddition.java --- jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialAddition.java 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialAddition.java 2018-06-05 16:36:49.000000000 +0000 @@ -18,17 +18,28 @@ public class PolynomialAddition implements PolynomialOperation { - public PolynomialOperation firstOperand; - public PolynomialOperation secondOperand; + private PolynomialOperation firstOperand; + private PolynomialOperation secondOperand; + private boolean hasParentheses; public PolynomialAddition( PolynomialOperation firstOperand, PolynomialOperation secondOperand ) { + this( firstOperand, secondOperand, false ); + } + + public PolynomialAddition( PolynomialOperation firstOperand, PolynomialOperation secondOperand, boolean hasParentheses ) + { this.firstOperand = firstOperand; this.secondOperand = secondOperand; + this.hasParentheses = hasParentheses; } - + + public PolynomialOperation getFirstOperand() { return firstOperand; } + public PolynomialOperation getSecondOperand() { return secondOperand; } + public boolean hasParentheses() { return hasParentheses; } + public < RETURN_TYPE, PARAM_TYPE > RETURN_TYPE accept( Visitor< RETURN_TYPE, PARAM_TYPE > visitor, PARAM_TYPE arg ) { return visitor.visit( this, arg ); - } + } } diff -Nru jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialDoubleDivision.java jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialDoubleDivision.java --- jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialDoubleDivision.java 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialDoubleDivision.java 2018-06-05 16:36:49.000000000 +0000 @@ -18,15 +18,26 @@ public class PolynomialDoubleDivision implements PolynomialOperation { - public PolynomialOperation dividend; - public DoubleOperation divisor; - + private PolynomialOperation dividend; + private DoubleOperation divisor; + private boolean hasParentheses; + public PolynomialDoubleDivision( PolynomialOperation dividend, DoubleOperation divisor ) { + this( dividend, divisor, false ); + } + + public PolynomialDoubleDivision( PolynomialOperation dividend, DoubleOperation divisor, boolean hasParentheses ) + { this.dividend = dividend; this.divisor = divisor; + this.hasParentheses = hasParentheses; } - + + public PolynomialOperation getDividend() { return dividend; } + public DoubleOperation getDivisor() { return divisor; } + public boolean hasParentheses() { return hasParentheses; } + public < RETURN_TYPE, PARAM_TYPE > RETURN_TYPE accept( Visitor< RETURN_TYPE, PARAM_TYPE > visitor, PARAM_TYPE arg ) { return visitor.visit( this, arg ); diff -Nru jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialExpansion.java jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialExpansion.java --- jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialExpansion.java 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialExpansion.java 2018-06-05 16:36:49.000000000 +0000 @@ -23,18 +23,18 @@ private UnivariatePolynomial x; private UnivariatePolynomial y; private UnivariatePolynomial z; - + private ValueCalculator valueCalculator; - + public PolynomialExpansion( UnivariatePolynomial x, UnivariatePolynomial y, UnivariatePolynomial z ) { this.x = x; this.y = y; this.z = z; - + this.valueCalculator = new ValueCalculator( 0.0, 0.0, 0.0 ); } - + public UnivariatePolynomial getX() { return this.x; @@ -44,27 +44,27 @@ { return this.y; } - + public UnivariatePolynomial getZ() { return this.z; - } - + } + public void setX( UnivariatePolynomial x ) { this.x = x; } - + public void setY( UnivariatePolynomial y ) { this.y = y; } - + public void setZ( UnivariatePolynomial z ) { this.z = z; } - + public void setXYZ( UnivariatePolynomial x, UnivariatePolynomial y, UnivariatePolynomial z ) { this.x = x; @@ -74,37 +74,37 @@ public UnivariatePolynomial visit( PolynomialAddition pa, Void param ) { - return pa.firstOperand.accept( this, ( Void ) null ).add( pa.secondOperand.accept( this, ( Void ) null ) ); + return pa.getFirstOperand().accept( this, ( Void ) null ).add( pa.getSecondOperand().accept( this, ( Void ) null ) ); } - + public UnivariatePolynomial visit( PolynomialSubtraction ps, Void param ) { - return ps.firstOperand.accept( this, ( Void ) null ).sub( ps.secondOperand.accept( this, ( Void ) null ) ); + return ps.getFirstOperand().accept( this, ( Void ) null ).sub( ps.getSecondOperand().accept( this, ( Void ) null ) ); } - + public UnivariatePolynomial visit( PolynomialMultiplication pm, Void param ) { - return pm.firstOperand.accept( this, ( Void ) null ).mult( pm.secondOperand.accept( this, ( Void ) null ) ); + return pm.getFirstOperand().accept( this, ( Void ) null ).mult( pm.getSecondOperand().accept( this, ( Void ) null ) ); } - + public UnivariatePolynomial visit( PolynomialPower pp, Void param ) { - return pp.base.accept( this, ( Void ) null ).pow( pp.exponent ); + return pp.getBase().accept( this, ( Void ) null ).pow( pp.getExponent() ); } public UnivariatePolynomial visit( PolynomialNegation pn, Void param ) { - return pn.operand.accept( this,( Void ) null ).neg(); + return pn.getOperand().accept( this,( Void ) null ).neg(); } public UnivariatePolynomial visit( PolynomialDoubleDivision pdd, Void param ) { - return pdd.dividend.accept( this,( Void ) null ).div( pdd.divisor.accept( this.valueCalculator, ( Void ) null ) ); + return pdd.getDividend().accept( this,( Void ) null ).div( pdd.getDivisor().accept( this.valueCalculator, ( Void ) null ) ); } - + public UnivariatePolynomial visit( PolynomialVariable pv, Void param ) { - switch( pv.variable ) + switch( pv.getVariable() ) { case x: return this.x; @@ -116,12 +116,12 @@ throw new UnsupportedOperationException(); } } - + public UnivariatePolynomial visit( DoubleBinaryOperation dbop, Void param ) { return new UnivariatePolynomial( dbop.accept( this.valueCalculator, ( Void ) null ) ); } - + public UnivariatePolynomial visit( DoubleUnaryOperation duop, Void param ) { return new UnivariatePolynomial( duop.accept( this.valueCalculator, ( Void ) null ) ); @@ -131,9 +131,9 @@ { throw new UnsupportedOperationException(); } - + public UnivariatePolynomial visit( DoubleValue dv, Void param ) { - return new UnivariatePolynomial( dv.value ); + return new UnivariatePolynomial( dv.getValue() ); } } diff -Nru jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialMultiplication.java jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialMultiplication.java --- jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialMultiplication.java 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialMultiplication.java 2018-06-05 16:36:49.000000000 +0000 @@ -18,17 +18,28 @@ public class PolynomialMultiplication implements PolynomialOperation { - public PolynomialOperation firstOperand; - public PolynomialOperation secondOperand; + private PolynomialOperation firstOperand; + private PolynomialOperation secondOperand; + private boolean hasParentheses; public PolynomialMultiplication( PolynomialOperation firstOperand, PolynomialOperation secondOperand ) { + this( firstOperand, secondOperand, false ); + } + + public PolynomialMultiplication( PolynomialOperation firstOperand, PolynomialOperation secondOperand, boolean hasParentheses ) + { this.firstOperand = firstOperand; this.secondOperand = secondOperand; + this.hasParentheses = hasParentheses; } - + + public PolynomialOperation getFirstOperand() { return firstOperand; } + public PolynomialOperation getSecondOperand() { return secondOperand; } + public boolean hasParentheses() { return hasParentheses; } + public < RETURN_TYPE, PARAM_TYPE > RETURN_TYPE accept( Visitor< RETURN_TYPE, PARAM_TYPE > visitor, PARAM_TYPE arg ) { return visitor.visit( this, arg ); - } + } } diff -Nru jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialNegation.java jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialNegation.java --- jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialNegation.java 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialNegation.java 2018-06-05 16:36:49.000000000 +0000 @@ -18,13 +18,23 @@ public class PolynomialNegation implements PolynomialOperation { - public PolynomialOperation operand; - + private PolynomialOperation operand; + private boolean hasParentheses; + public PolynomialNegation( PolynomialOperation operand ) { + this( operand, false ); + } + + public PolynomialNegation( PolynomialOperation operand, boolean hasParentheses ) + { this.operand = operand; + this.hasParentheses = hasParentheses; } - + + public PolynomialOperation getOperand() { return operand; } + public boolean hasParentheses() { return hasParentheses; } + public < RETURN_TYPE, PARAM_TYPE > RETURN_TYPE accept( Visitor< RETURN_TYPE, PARAM_TYPE > visitor, PARAM_TYPE arg ) { return visitor.visit( this, arg ); diff -Nru jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialOperation.java jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialOperation.java --- jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialOperation.java 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialOperation.java 2018-06-05 16:36:49.000000000 +0000 @@ -18,5 +18,6 @@ public interface PolynomialOperation { + public boolean hasParentheses(); public < RETURN_TYPE, PARAM_TYPE > RETURN_TYPE accept( Visitor< RETURN_TYPE, PARAM_TYPE > visitor, PARAM_TYPE arg ); } diff -Nru jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialPower.java jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialPower.java --- jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialPower.java 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialPower.java 2018-06-05 16:36:49.000000000 +0000 @@ -18,15 +18,29 @@ public class PolynomialPower implements PolynomialOperation { - public PolynomialOperation base; - public int exponent; - + private PolynomialOperation base; + private int exponent; + private boolean hasParentheses; + public PolynomialPower( PolynomialOperation base, int exponent ) { + this( base, exponent, false ); + } + + public PolynomialPower( PolynomialOperation base, int exponent, boolean hasParentheses ) + { + if( exponent < 0 ) + throw new IllegalArgumentException( "exponent must be >= 0" ); + this.base = base; this.exponent = exponent; + this.hasParentheses = hasParentheses; } - + + public PolynomialOperation getBase() { return base; } + public int getExponent() { return exponent; } + public boolean hasParentheses() { return hasParentheses; } + public < RETURN_TYPE, PARAM_TYPE > RETURN_TYPE accept( Visitor< RETURN_TYPE, PARAM_TYPE > visitor, PARAM_TYPE arg ) { return visitor.visit( this, arg ); diff -Nru jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialSubtraction.java jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialSubtraction.java --- jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialSubtraction.java 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialSubtraction.java 2018-06-05 16:36:49.000000000 +0000 @@ -18,17 +18,28 @@ public class PolynomialSubtraction implements PolynomialOperation { - public PolynomialOperation firstOperand; - public PolynomialOperation secondOperand; + private PolynomialOperation firstOperand; + private PolynomialOperation secondOperand; + private boolean hasParentheses; public PolynomialSubtraction( PolynomialOperation firstOperand, PolynomialOperation secondOperand ) { + this( firstOperand, secondOperand, false ); + } + + public PolynomialSubtraction( PolynomialOperation firstOperand, PolynomialOperation secondOperand, boolean hasParentheses ) + { this.firstOperand = firstOperand; this.secondOperand = secondOperand; + this.hasParentheses = hasParentheses; } - + + public PolynomialOperation getFirstOperand() { return firstOperand; } + public PolynomialOperation getSecondOperand() { return secondOperand; } + public boolean hasParentheses() { return hasParentheses; } + public < RETURN_TYPE, PARAM_TYPE > RETURN_TYPE accept( Visitor< RETURN_TYPE, PARAM_TYPE > visitor, PARAM_TYPE arg ) { return visitor.visit( this, arg ); - } + } } diff -Nru jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialVariable.java jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialVariable.java --- jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialVariable.java 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/PolynomialVariable.java 2018-06-05 16:36:49.000000000 +0000 @@ -19,13 +19,23 @@ public class PolynomialVariable implements PolynomialOperation { public enum Var { x, y, z; } - public Var variable; - + private Var variable; + private boolean hasParentheses; + public PolynomialVariable( Var variable ) { + this( variable, false ); + } + + public PolynomialVariable( Var variable, boolean hasParentheses ) + { this.variable = variable; + this.hasParentheses = hasParentheses; } - + + public Var getVariable() { return variable; } + public boolean hasParentheses() { return hasParentheses; } + public < RETURN_TYPE, PARAM_TYPE > RETURN_TYPE accept( Visitor< RETURN_TYPE, PARAM_TYPE > visitor, PARAM_TYPE arg ) { return visitor.visit( this, arg ); diff -Nru jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/Simplificator.java jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/Simplificator.java --- jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/Simplificator.java 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/Simplificator.java 2018-06-05 16:36:49.000000000 +0000 @@ -54,12 +54,12 @@ public PolynomialOperation visit( PolynomialAddition pa, Void param ) { - PolynomialOperation firstOperand = pa.firstOperand.accept( this, ( Void ) null ); - PolynomialOperation secondOperand = pa.secondOperand.accept( this, ( Void ) null ); + PolynomialOperation firstOperand = pa.getFirstOperand().accept( this, ( Void ) null ); + PolynomialOperation secondOperand = pa.getSecondOperand().accept( this, ( Void ) null ); try { - if( ( ( DoubleValue ) firstOperand ).value == 0.0 ) + if( ( ( DoubleValue ) firstOperand ).getValue() == 0.0 ) return secondOperand; } catch( ClassCastException cce ) @@ -67,7 +67,7 @@ } try { - if( ( ( DoubleValue ) secondOperand ).value == 0.0 ) + if( ( ( DoubleValue ) secondOperand ).getValue() == 0.0 ) return firstOperand; } catch( ClassCastException cce ) @@ -85,12 +85,12 @@ public PolynomialOperation visit( PolynomialSubtraction ps, Void param ) { - PolynomialOperation firstOperand = ps.firstOperand.accept( this, ( Void ) null ); - PolynomialOperation secondOperand = ps.secondOperand.accept( this, ( Void ) null ); + PolynomialOperation firstOperand = ps.getFirstOperand().accept( this, ( Void ) null ); + PolynomialOperation secondOperand = ps.getSecondOperand().accept( this, ( Void ) null ); try { - if( ( ( DoubleValue ) firstOperand ).value == 0.0 ) + if( ( ( DoubleValue ) firstOperand ).getValue() == 0.0 ) return new PolynomialNegation( secondOperand ).accept( this, ( Void ) null ); } catch( ClassCastException cce ) @@ -98,7 +98,7 @@ } try { - if( ( ( DoubleValue ) secondOperand ).value == 0.0 ) + if( ( ( DoubleValue ) secondOperand ).getValue() == 0.0 ) return firstOperand; } catch( ClassCastException cce ) @@ -110,20 +110,20 @@ } catch( ClassCastException cce ) { - } + } return new PolynomialSubtraction( firstOperand, secondOperand ); } public PolynomialOperation visit( PolynomialMultiplication pm, Void param ) { - PolynomialOperation firstOperand = pm.firstOperand.accept( this, ( Void ) null ); - PolynomialOperation secondOperand = pm.secondOperand.accept( this, ( Void ) null ); - + PolynomialOperation firstOperand = pm.getFirstOperand().accept( this, ( Void ) null ); + PolynomialOperation secondOperand = pm.getSecondOperand().accept( this, ( Void ) null ); + try { - if( ( ( DoubleValue ) firstOperand ).value == 0.0 ) + if( ( ( DoubleValue ) firstOperand ).getValue() == 0.0 ) return firstOperand; - else if( ( ( DoubleValue ) firstOperand ).value == 1.0 ) + else if( ( ( DoubleValue ) firstOperand ).getValue() == 1.0 ) return secondOperand; } catch( ClassCastException cce ) @@ -131,9 +131,9 @@ } try { - if( ( ( DoubleValue ) secondOperand ).value == 0.0 ) + if( ( ( DoubleValue ) secondOperand ).getValue() == 0.0 ) return secondOperand; - else if( ( ( DoubleValue ) secondOperand ).value == 1.0 ) + else if( ( ( DoubleValue ) secondOperand ).getValue() == 1.0 ) return firstOperand; } catch( ClassCastException cce ) @@ -151,12 +151,12 @@ public PolynomialOperation visit( PolynomialPower pp, Void param ) { - PolynomialOperation base = pp.base.accept( this, ( Void ) null ); - if( pp.exponent == 0 ) + PolynomialOperation base = pp.getBase().accept( this, ( Void ) null ); + if( pp.getExponent() == 0 ) { return new DoubleValue( 1.0 ); } - else if( pp.exponent == 1 ) + else if( pp.getExponent() == 1 ) { return base; } @@ -165,21 +165,21 @@ } try { - double dBase = ( ( DoubleValue ) base ).value; - return new DoubleValue( Math.pow( dBase, pp.exponent ) ); + double dBase = ( ( DoubleValue ) base ).getValue(); + return new DoubleValue( Math.pow( dBase, pp.getExponent() ) ); } catch( ClassCastException cce ) { - } - return new PolynomialPower( base, pp.exponent ); + } + return new PolynomialPower( base, pp.getExponent() ); } public PolynomialOperation visit( PolynomialNegation pn, Void param ) { - PolynomialOperation operand = pn.operand.accept( this, ( Void ) null ); + PolynomialOperation operand = pn.getOperand().accept( this, ( Void ) null ); try { - return new DoubleValue( -( ( DoubleValue ) operand ).value ); + return new DoubleValue( -( ( DoubleValue ) operand ).getValue() ); } catch( ClassCastException cce ) { @@ -189,11 +189,11 @@ public PolynomialOperation visit( PolynomialDoubleDivision pdd, Void param ) { - PolynomialOperation dividend = pdd.dividend.accept( this, ( Void ) null ); - PolynomialOperation divisor = pdd.divisor.accept( this, ( Void ) null ); + PolynomialOperation dividend = pdd.getDividend().accept( this, ( Void ) null ); + PolynomialOperation divisor = pdd.getDivisor().accept( this, ( Void ) null ); try { - return new DoubleValue( ( ( DoubleValue ) dividend ).value / ( ( DoubleValue ) divisor ).value ); + return new DoubleValue( ( ( DoubleValue ) dividend ).getValue() / ( ( DoubleValue ) divisor ).getValue() ); } catch( ClassCastException cce1 ) { @@ -215,15 +215,15 @@ public DoubleOperation visit( DoubleBinaryOperation dbop, Void param ) { - DoubleOperation firstOperand = ( DoubleOperation ) dbop.firstOperand.accept( this, ( Void ) null ); - DoubleOperation secondOperand = ( DoubleOperation ) dbop.secondOperand.accept( this, ( Void ) null ); + DoubleOperation firstOperand = ( DoubleOperation ) dbop.getFirstOperand().accept( this, ( Void ) null ); + DoubleOperation secondOperand = ( DoubleOperation ) dbop.getSecondOperand().accept( this, ( Void ) null ); try { - double firstValue = ( ( DoubleValue ) firstOperand ).value; - double secondValue = ( ( DoubleValue ) secondOperand ).value; + double firstValue = ( ( DoubleValue ) firstOperand ).getValue(); + double secondValue = ( ( DoubleValue ) secondOperand ).getValue(); double result; - switch( dbop.operator ) + switch( dbop.getOperator() ) { case add: result = firstValue + secondValue; @@ -240,9 +240,6 @@ case pow: result = Math.pow( firstValue, secondValue ); break; - case atan2: - result = Math.atan2( firstValue, secondValue ); - break; default: throw new UnsupportedOperationException(); } @@ -250,18 +247,18 @@ } catch( ClassCastException cce ) { - return new DoubleBinaryOperation( dbop.operator, firstOperand, secondOperand ); + return new DoubleBinaryOperation( dbop.getOperator(), firstOperand, secondOperand ); } } public DoubleOperation visit( DoubleUnaryOperation duop, Void param ) { - DoubleOperation operand = ( DoubleOperation ) duop.operand.accept( this, ( Void ) null ); + DoubleOperation operand = ( DoubleOperation ) duop.getOperand().accept( this, ( Void ) null ); try { - double value = ( ( DoubleValue ) operand ).value; + double value = ( ( DoubleValue ) operand ).getValue(); double result; - switch( duop.operator ) + switch( duop.getOperator() ) { case neg: result = -value; @@ -312,7 +309,7 @@ } catch( ClassCastException cce ) { - return new DoubleUnaryOperation( duop.operator, operand ); + return new DoubleUnaryOperation( duop.getOperator(), operand ); } } @@ -325,7 +322,7 @@ { try { - return new DoubleValue( this.dict.get( dv.name ) ); + return new DoubleValue( this.dict.get( dv.getName() ) ); } catch( NullPointerException npe ) { diff -Nru jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/ToStringVisitor.java jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/ToStringVisitor.java --- jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/ToStringVisitor.java 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/ToStringVisitor.java 2018-06-05 16:36:49.000000000 +0000 @@ -18,131 +18,150 @@ public class ToStringVisitor extends AbstractVisitor< String, Void > { + final static String LPAR = "("; + final static String RPAR = ")"; + + private boolean onlyExplicitParentheses; + + public ToStringVisitor() + { + this( false ); + } + + public ToStringVisitor( boolean onlyExplicitParentheses ) + { + this.onlyExplicitParentheses = onlyExplicitParentheses; + } + + protected boolean getOnlyExplicitParentheses() { return onlyExplicitParentheses; } + + String lp( PolynomialOperation pop ) + { + return !onlyExplicitParentheses || pop.hasParentheses() ? LPAR : ""; + } + + String rp( PolynomialOperation pop ) + { + return !onlyExplicitParentheses || pop.hasParentheses() ? RPAR : ""; + } + public String visit( PolynomialOperation pop, Void param ) { - return "(" + pop.toString() + ")"; + return lp(pop) + pop.toString() + rp(pop); } - + public String visit( PolynomialAddition pa, Void param ) { - return "(" + pa.firstOperand.accept( this, ( Void ) null ) + "+" + pa.secondOperand.accept( this, ( Void ) null ) + ")"; + return lp(pa) + pa.getFirstOperand().accept( this, ( Void ) null ) + "+" + pa.getSecondOperand().accept( this, ( Void ) null ) + rp(pa); } - + public String visit( PolynomialSubtraction ps, Void param ) { - return "(" + ps.firstOperand.accept( this, ( Void ) null ) + "-" + ps.secondOperand.accept( this, ( Void ) null ) + ")"; + return lp(ps) + ps.getFirstOperand().accept( this, ( Void ) null ) + "-" + ps.getSecondOperand().accept( this, ( Void ) null ) + rp(ps); } - + public String visit( PolynomialMultiplication pm, Void param ) { - return "(" + pm.firstOperand.accept( this, ( Void ) null ) + "*" + pm.secondOperand.accept( this, ( Void ) null ) + ")"; + return lp(pm) + pm.getFirstOperand().accept( this, ( Void ) null ) + "*" + pm.getSecondOperand().accept( this, ( Void ) null ) + rp(pm); } public String visit( PolynomialPower pp, Void param ) { - return "(" + pp.base.accept( this, ( Void ) null ) + "^" + pp.exponent + ")"; + return lp(pp) + pp.getBase().accept( this, ( Void ) null ) + "^" + pp.getExponent() + rp(pp); } public String visit( PolynomialNegation pn, Void param ) { - return "(" + pn.operand.accept( this, ( Void ) null ) + ")"; + return lp(pn) + "-" + pn.getOperand().accept( this, ( Void ) null ) + rp(pn); } - + public String visit( PolynomialDoubleDivision pdd, Void param ) { - return "( " + pdd.dividend.accept( this,( Void ) null ) + "/" + pdd.divisor.accept( this,( Void ) null ) + ")"; + return lp(pdd) + pdd.getDividend().accept( this,( Void ) null ) + "/" + pdd.getDivisor().accept( this,( Void ) null ) + rp(pdd); } - + public String visit( PolynomialVariable pv, Void param ) { - switch( pv.variable ) - { - case x: - return "x"; - case y: - return "y"; - case z: - return "z"; - default: - throw new UnsupportedOperationException(); - } + return lp(pv) + pv.getVariable().toString() + rp(pv); } - + public String visit( DoubleOperation dop, Void param ) { - return "(" + dop.toString() + ")"; + return lp(dop) + dop.toString() + rp(dop); } - + public String visit( DoubleBinaryOperation dbop, Void param ) { - String firstOperand = dbop.firstOperand.accept( this, ( Void ) null ); - String secondOperand = dbop.secondOperand.accept( this, ( Void ) null ); - - switch( dbop.operator ) + String lp = lp(dbop); + String rp = lp(dbop); + String firstOperand = dbop.getFirstOperand().accept( this, ( Void ) null ); + String secondOperand = dbop.getSecondOperand().accept( this, ( Void ) null ); + + switch( dbop.getOperator() ) { case add: - return "(" + firstOperand + "+" + secondOperand + ")"; + return lp + firstOperand + "+" + secondOperand + rp; case sub: - return "(" + firstOperand + "-" + secondOperand + ")"; + return lp + firstOperand + "-" + secondOperand + rp; case mult: - return "(" + firstOperand + "*" + secondOperand + ")"; + return lp + firstOperand + "*" + secondOperand + rp; case div: - return "(" + firstOperand + "/" + secondOperand + ")"; + return lp + firstOperand + "/" + secondOperand + rp; case pow: - return "(" + firstOperand + "^" + secondOperand + ")"; - case atan2: - return "atan2(" + firstOperand + ", " + secondOperand + ")"; + return lp + firstOperand + "^" + secondOperand + rp; default: throw new UnsupportedOperationException(); - } + } } - + public String visit( DoubleUnaryOperation duop, Void param ) { - String operand = duop.operand.accept( this, ( Void ) null ); - - switch( duop.operator ) + String lp = lp(duop); + String rp = lp(duop); + String operand = duop.getOperand().accept( this, ( Void ) null ); + + switch( duop.getOperator() ) { case neg: - return "(-" + operand + ")"; + return lp + "-" + operand + rp; case sin: - return "sin(" + operand + ")"; + return "sin" + lp + operand + rp; case cos: - return "cos(" + operand + ")"; + return "cos" + lp + operand + rp; case tan: - return "tan(" + operand + ")"; + return "tan" + lp + operand + rp; case asin: - return "asin(" + operand + ")"; + return "asin" + lp + operand + rp; case acos: - return "acos(" + operand + ")"; + return "acos" + lp + operand + rp; case atan: - return "atan(" + operand + ")"; + return "atan" + lp + operand + rp; case exp: - return "exp(" + operand + ")"; + return "exp" + lp + operand + rp; case log: - return "log(" + operand + ")"; + return "log" + lp + operand + rp; case sqrt: - return "sqrt(" + operand + ")"; + return "sqrt" + lp + operand + rp; case ceil: - return "ceil(" + operand + ")"; + return "ceil" + lp + operand + rp; case floor: - return "floor(" + operand + ")"; + return "floor" + lp + operand + rp; case abs: - return "abs(" + operand + ")"; + return "abs" + lp + operand + rp; case sign: - return "signum(" + operand + ")"; + return "signum" + lp + operand + rp; default: throw new UnsupportedOperationException(); } } - + public String visit( DoubleValue dv, Void param ) { - return "" + dv.value; + return lp(dv) + dv.toString() + rp(dv); } - + public String visit( DoubleVariable dv, Void param ) { - return dv.name; + return lp(dv) + dv.getName() + rp(dv); } } diff -Nru jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/UnivariatePolynomialExpansion.java jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/UnivariatePolynomialExpansion.java --- jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/UnivariatePolynomialExpansion.java 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/UnivariatePolynomialExpansion.java 2018-06-05 16:36:49.000000000 +0000 @@ -23,18 +23,18 @@ private UnivariatePolynomial x; private UnivariatePolynomial y; private UnivariatePolynomial z; - + private ValueCalculator valueCalculator; - + public UnivariatePolynomialExpansion( UnivariatePolynomial x, UnivariatePolynomial y, UnivariatePolynomial z ) { this.x = x; this.y = y; this.z = z; - + this.valueCalculator = new ValueCalculator( 0.0, 0.0, 0.0 ); } - + public UnivariatePolynomial getX() { return this.x; @@ -44,27 +44,27 @@ { return this.y; } - + public UnivariatePolynomial getZ() { return this.z; - } - + } + public void setX( UnivariatePolynomial x ) { this.x = x; } - + public void setY( UnivariatePolynomial y ) { this.y = y; } - + public void setZ( UnivariatePolynomial z ) { this.z = z; } - + public void setXYZ( UnivariatePolynomial x, UnivariatePolynomial y, UnivariatePolynomial z ) { this.x = x; @@ -74,37 +74,37 @@ public UnivariatePolynomial visit( PolynomialAddition pa, Void param ) { - return pa.firstOperand.accept( this, ( Void ) null ).add( pa.secondOperand.accept( this, ( Void ) null ) ); + return pa.getFirstOperand().accept( this, ( Void ) null ).add( pa.getSecondOperand().accept( this, ( Void ) null ) ); } - + public UnivariatePolynomial visit( PolynomialSubtraction ps, Void param ) { - return ps.firstOperand.accept( this, ( Void ) null ).sub( ps.secondOperand.accept( this, ( Void ) null ) ); + return ps.getFirstOperand().accept( this, ( Void ) null ).sub( ps.getSecondOperand().accept( this, ( Void ) null ) ); } - + public UnivariatePolynomial visit( PolynomialMultiplication pm, Void param ) { - return pm.firstOperand.accept( this, ( Void ) null ).mult( pm.secondOperand.accept( this, ( Void ) null ) ); + return pm.getFirstOperand().accept( this, ( Void ) null ).mult( pm.getSecondOperand().accept( this, ( Void ) null ) ); } - + public UnivariatePolynomial visit( PolynomialPower pp, Void param ) { - return pp.base.accept( this, ( Void ) null ).pow( pp.exponent ); + return pp.getBase().accept( this, ( Void ) null ).pow( pp.getExponent() ); } public UnivariatePolynomial visit( PolynomialNegation pn, Void param ) { - return pn.operand.accept( this,( Void ) null ).neg(); + return pn.getOperand().accept( this,( Void ) null ).neg(); } public UnivariatePolynomial visit( PolynomialDoubleDivision pdd, Void param ) { - return pdd.dividend.accept( this,( Void ) null ).div( pdd.divisor.accept( this.valueCalculator, ( Void ) null ) ); + return pdd.getDividend().accept( this,( Void ) null ).div( pdd.getDivisor().accept( this.valueCalculator, ( Void ) null ) ); } - + public UnivariatePolynomial visit( PolynomialVariable pv, Void param ) { - switch( pv.variable ) + switch( pv.getVariable() ) { case x: return this.x; @@ -116,12 +116,12 @@ throw new UnsupportedOperationException(); } } - + public UnivariatePolynomial visit( DoubleBinaryOperation dbop, Void param ) { return new UnivariatePolynomial( dbop.accept( this.valueCalculator, ( Void ) null ) ); } - + public UnivariatePolynomial visit( DoubleUnaryOperation duop, Void param ) { return new UnivariatePolynomial( duop.accept( this.valueCalculator, ( Void ) null ) ); @@ -129,11 +129,11 @@ public UnivariatePolynomial visit( DoubleVariable dv, Void param ) { - throw new UnsupportedOperationException( "no value has been assigned to parameter '" + dv.name + "'" ); + throw new UnsupportedOperationException( "no value has been assigned to parameter '" + dv.getName() + "'" ); } - + public UnivariatePolynomial visit( DoubleValue dv, Void param ) { - return new UnivariatePolynomial( dv.value ); + return new UnivariatePolynomial( dv.getValue() ); } } diff -Nru jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/ValueCalculator.java jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/ValueCalculator.java --- jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/ValueCalculator.java 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/ValueCalculator.java 2018-06-05 16:36:49.000000000 +0000 @@ -23,23 +23,23 @@ private double x; private double y; private double z; - + private Map< String, java.lang.Double > dict; - + public ValueCalculator() { this( 0.0, 0.0, 0.0 ); } - + public ValueCalculator( double x, double y, double z ) { this.x = x; this.y = y; this.z = z; - + this.dict = new HashMap< String, java.lang.Double >(); } - + public double getX() { return this.x; @@ -49,39 +49,39 @@ { return this.y; } - + public double getZ() { return this.z; - } - + } + public void setX( double x ) { this.x = x; } - + public void setY( double y ) { this.y = y; } - + public void setZ( double z ) { this.z = z; } - + public void setXYZ( double x, double y, double z ) { this.x = x; this.y = y; this.z = z; } - + public double getParameterValue( String name ) { try { - return this.dict.get( name ); + return this.dict.get( name ); } catch( NullPointerException npe ) { @@ -93,45 +93,45 @@ { return this.dict.keySet(); } - + public void setParameterValue( String name, double value ) { this.dict.put( name, value ); } - + public java.lang.Double visit( PolynomialAddition pa, Void param ) { - return pa.firstOperand.accept( this, ( Void ) null ) + pa.secondOperand.accept( this, ( Void ) null ); + return pa.getFirstOperand().accept( this, ( Void ) null ) + pa.getSecondOperand().accept( this, ( Void ) null ); } - + public java.lang.Double visit( PolynomialSubtraction ps, Void param ) { - return ps.firstOperand.accept( this, ( Void ) null ) - ps.secondOperand.accept( this, ( Void ) null ); + return ps.getFirstOperand().accept( this, ( Void ) null ) - ps.getSecondOperand().accept( this, ( Void ) null ); } public java.lang.Double visit( PolynomialMultiplication pm, Void param ) { - return pm.firstOperand.accept( this, ( Void ) null ) * pm.secondOperand.accept( this, ( Void ) null ); + return pm.getFirstOperand().accept( this, ( Void ) null ) * pm.getSecondOperand().accept( this, ( Void ) null ); } public java.lang.Double visit( PolynomialPower pp, Void param ) { - return Math.pow( pp.base.accept( this, ( Void ) null ), ( double ) pp.exponent ); + return Math.pow( pp.getBase().accept( this, ( Void ) null ), ( double ) pp.getExponent() ); } public java.lang.Double visit( PolynomialNegation pn, Void param ) { - return -pn.operand.accept( this, ( Void ) null ); - } - + return -pn.getOperand().accept( this, ( Void ) null ); + } + public java.lang.Double visit( PolynomialDoubleDivision pdd, Void param ) { - return pdd.dividend.accept( this,( Void ) null ) / pdd.divisor.accept( this,( Void ) null ); + return pdd.getDividend().accept( this,( Void ) null ) / pdd.getDivisor().accept( this,( Void ) null ); } public java.lang.Double visit( PolynomialVariable pv, Void param ) { - switch( pv.variable ) + switch( pv.getVariable() ) { case x: return this.x; @@ -143,13 +143,13 @@ throw new UnsupportedOperationException(); } } - + public java.lang.Double visit( DoubleBinaryOperation dbop, Void param ) { - double firstOperand = dbop.firstOperand.accept( this, ( Void ) null ); - double secondOperand = dbop.secondOperand.accept( this, ( Void ) null ); - - switch( dbop.operator ) + double firstOperand = dbop.getFirstOperand().accept( this, ( Void ) null ); + double secondOperand = dbop.getSecondOperand().accept( this, ( Void ) null ); + + switch( dbop.getOperator() ) { case add: return firstOperand + secondOperand; @@ -161,8 +161,6 @@ return firstOperand / secondOperand; case pow: return Math.pow( firstOperand, secondOperand ); - case atan2: - return Math.atan2( firstOperand, secondOperand ); default: throw new UnsupportedOperationException(); } @@ -170,9 +168,9 @@ public java.lang.Double visit( DoubleUnaryOperation duop, Void param ) { - double operand = duop.operand.accept( this, ( Void ) null ); - - switch( duop.operator ) + double operand = duop.getOperand().accept( this, ( Void ) null ); + + switch( duop.getOperator() ) { case neg: return -operand; @@ -209,14 +207,14 @@ public java.lang.Double visit( DoubleVariable dv, Void param ) { - java.lang.Double d = this.dict.get( dv.name ); + java.lang.Double d = this.dict.get( dv.getName() ); if( d == null ) - throw new UnsupportedOperationException( "no value has been assigned to parameter '" + dv.name + "'" ); + throw new UnsupportedOperationException( "no value has been assigned to parameter '" + dv.getName() + "'" ); return d; } - + public java.lang.Double visit( DoubleValue dv, Void param ) { - return dv.value; + return dv.getValue(); } } diff -Nru jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/VariableSubstitutor.java jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/VariableSubstitutor.java --- jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/VariableSubstitutor.java 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/VariableSubstitutor.java 2018-06-05 16:36:49.000000000 +0000 @@ -21,48 +21,48 @@ PolynomialOperation xSubstitute; PolynomialOperation ySubstitute; PolynomialOperation zSubstitute; - + public VariableSubstitutor( PolynomialOperation xSubstitute, PolynomialOperation ySubstitute, PolynomialOperation zSubstitute ) { this.xSubstitute = xSubstitute; this.ySubstitute = ySubstitute; this.zSubstitute = zSubstitute; } - + public PolynomialOperation visit( PolynomialAddition pa, Void param ) { - - return new PolynomialAddition( pa.firstOperand.accept( this, ( Void ) null ), pa.secondOperand.accept( this, ( Void ) null ) ); + + return new PolynomialAddition( pa.getFirstOperand().accept( this, ( Void ) null ), pa.getSecondOperand().accept( this, ( Void ) null ) ); } - + public PolynomialOperation visit( PolynomialSubtraction ps, Void param ) { - return new PolynomialSubtraction( ps.firstOperand.accept( this, ( Void ) null ), ps.secondOperand.accept( this, ( Void ) null ) ); + return new PolynomialSubtraction( ps.getFirstOperand().accept( this, ( Void ) null ), ps.getSecondOperand().accept( this, ( Void ) null ) ); } public PolynomialOperation visit( PolynomialMultiplication pm, Void param ) { - return new PolynomialMultiplication( pm.firstOperand.accept( this, ( Void ) null ), pm.secondOperand.accept( this, ( Void ) null ) ); + return new PolynomialMultiplication( pm.getFirstOperand().accept( this, ( Void ) null ), pm.getSecondOperand().accept( this, ( Void ) null ) ); } public PolynomialOperation visit( PolynomialPower pp, Void param ) { - return new PolynomialPower( pp.base.accept( this, ( Void ) null ), pp.exponent ); + return new PolynomialPower( pp.getBase().accept( this, ( Void ) null ), pp.getExponent() ); } public PolynomialOperation visit( PolynomialNegation pn, Void param ) { - return new PolynomialNegation( pn.operand.accept( this, ( Void ) null ) ); + return new PolynomialNegation( pn.getOperand().accept( this, ( Void ) null ) ); } - + public PolynomialOperation visit( PolynomialDoubleDivision pdd, Void param ) { - return new PolynomialDoubleDivision( pdd.dividend.accept( this, ( Void ) null ), pdd.divisor ); + return new PolynomialDoubleDivision( pdd.getDividend().accept( this, ( Void ) null ), pdd.getDivisor() ); } - + public PolynomialOperation visit( PolynomialVariable pv, Void param ) { - switch( pv.variable ) + switch( pv.getVariable() ) { case x: return xSubstitute; @@ -74,22 +74,22 @@ throw new UnsupportedOperationException(); } } - + public PolynomialOperation visit( DoubleBinaryOperation dbop, Void param ) { return dbop; } - + public PolynomialOperation visit( DoubleUnaryOperation duop, Void param ) { return duop; } - + public PolynomialOperation visit( DoubleValue dv, Void param ) { return dv; } - + public PolynomialOperation visit( DoubleVariable dv, Void param ) { return dv; diff -Nru jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/Visitor.java jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/Visitor.java --- jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/algebra/Visitor.java 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/algebra/Visitor.java 2018-06-05 16:36:49.000000000 +0000 @@ -26,7 +26,7 @@ public RETURN_TYPE visit( PolynomialNegation pn, PARAM_TYPE param ); public RETURN_TYPE visit( PolynomialDoubleDivision pdd, PARAM_TYPE param ); public RETURN_TYPE visit( PolynomialVariable pv, PARAM_TYPE param ); - + public RETURN_TYPE visit( DoubleOperation dop, PARAM_TYPE param ); public RETURN_TYPE visit( DoubleBinaryOperation dbop, PARAM_TYPE param ); public RETURN_TYPE visit( DoubleUnaryOperation duop, PARAM_TYPE param ); diff -Nru jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/Main.java jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/Main.java --- jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/Main.java 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/Main.java 2018-06-05 16:36:49.000000000 +0000 @@ -30,8 +30,18 @@ import javax.swing.JLabel; import javax.swing.SwingUtilities; +import org.apache.commons.io.FilenameUtils; import org.apache.commons.cli.*; +import javax.imageio.*; +import javax.imageio.metadata.*; +import javax.imageio.stream.*; + +import java.util.Date; +import java.util.TimeZone; +import java.text.SimpleDateFormat; +import java.util.Locale; + import de.mfo.jsurf.rendering.cpu.AntiAliasingPattern; import de.mfo.jsurf.rendering.cpu.CPUAlgebraicSurfaceRenderer; import de.mfo.jsurf.rendering.cpu.CPUAlgebraicSurfaceRenderer.AntiAliasingMode; @@ -41,7 +51,8 @@ public static final String jsurf_progname = "jsurf"; - static int size = 100; + static int size = 512; + static int quality = 1; static AntiAliasingMode aam; static AntiAliasingPattern aap; @@ -67,14 +78,70 @@ return op.filter(bi, null); } + public static OutputStream writeImage( OutputStream os, BufferedImage bi ) + throws Exception + { + ImageWriter writer = ImageIO.getImageWritersByFormatName( "png" ).next(); + + ImageWriteParam writeParam = writer.getDefaultWriteParam(); + ImageTypeSpecifier typeSpecifier = ImageTypeSpecifier.createFromBufferedImageType( BufferedImage.TYPE_INT_RGB ); + + // add metadata + // see https://docs.oracle.com/javase/7/docs/api/javax/imageio/metadata/doc-files/png_metadata.html + // and https://www.w3.org/TR/PNG/#11textinfo + IIOMetadata metadata = writer.getDefaultImageMetadata( typeSpecifier, writeParam ); + + IIOMetadataNode textEntrySoftware = new IIOMetadataNode( "tEXtEntry" ); + textEntrySoftware.setAttribute( "keyword", "Software" ); + textEntrySoftware.setAttribute( "value", jsurf_progname + " version " + Main.class.getPackage().getImplementationVersion() + " (http://imaginary.org/program/jsurf)" ); + + TimeZone tz = TimeZone.getTimeZone("UTC"); + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mmZ"); + df.setTimeZone(tz); + Date theDate; + // use either current time or the timestamp stored in the environment variable + // SOURCE_DATE_EPOCH for reproducible builds + if( System.getenv( "SOURCE_DATE_EPOCH" ) == null ) + theDate = new Date(); + else + theDate = new Date( Long.parseLong( System.getenv( "SOURCE_DATE_EPOCH" ) ) * 1000 ); + + IIOMetadataNode textEntryCreationTime = new IIOMetadataNode( "tEXtEntry" ); + textEntryCreationTime.setAttribute( "keyword", "CreationTime" ); + textEntryCreationTime.setAttribute( "value", df.format( theDate ) ); + + IIOMetadataNode textEntrySource = new IIOMetadataNode( "tEXtEntry" ); + textEntrySource.setAttribute( "keyword", "Source" ); + textEntrySource.setAttribute( "value", jsurf_progname + " settings: --quality " + quality ); + + IIOMetadataNode text = new IIOMetadataNode( "tEXt" ); + text.appendChild( textEntrySoftware ); + text.appendChild( textEntryCreationTime ); + text.appendChild( textEntrySource ); + + IIOMetadataNode root = new IIOMetadataNode( "javax_imageio_png_1.0" ); + root.appendChild( text ); + + metadata.mergeTree( "javax_imageio_png_1.0", root ); + + // write the image and meta data + ImageOutputStream image_os = ImageIO.createImageOutputStream( os ); + writer.setOutput( image_os ); + writer.write( metadata, new IIOImage( bi, null, metadata ), writeParam ); + image_os.close(); + + return os; + } + /** * @param args */ public static void main(String[] args) { + int helper_width = 103; String jsurf_filename = null; String output_filename = null; - boolean show_gui = false; + boolean show_gui = false; Options options = new Options(); @@ -82,22 +149,28 @@ options.addOption( OptionBuilder.withLongOpt( "version" ).withDescription( "print program version and exit" ).create() ); options.addOption("s","size", true, "image width and height (default: " + size + ")"); options.addOption("q","quality",true,"quality of the rendering: 0 (low), 1 (medium, default), 2 (high), 3 (extreme)"); - if( !java.awt.GraphicsEnvironment.isHeadless() ) - options.addOption( OptionBuilder.withLongOpt( "gui" ).withDescription( "display the rendering (png_output becomes optional)" ).create() ); + options.addOption("o","output",true,"output PNG into this file (overrode by the 2nd argument if present)"); + options.addOption( OptionBuilder.withLongOpt( "gui" ).withDescription( "display rendering (overrides output options)" ).create() ); CommandLineParser parser = new PosixParser(); HelpFormatter formatter = new HelpFormatter(); - String cmd_line_syntax = jsurf_progname + " [options] jsurf_input png_output\n\n"; + String cmd_line_syntax = jsurf_progname + " [options...] {jsurf_input|-} [png_output|-]\n\n"; String help_header = jsurf_progname + " is a renderer for real algebraic surfaces.\n" + - "Specify files as '-' for standard input and output."; + jsurf_progname + " translates its own language script files (generally with extension '.jsurf') into Portable Network Graphics (PNG) files; " + + "PNG is a raster graphics file format that supports lossless data compression.\n" + + "If the output filename is not specified, the output is placed in a file of the same basename with a '.png' extension in the current working directory.\n" + + "Either the input filename or the output filename can be '-' to request reading from stdin or writing to stdout, respectively. " + + "Whenever the Graphic Unit Interface (GUI) is available, the gui option takes precedence over the output options, otherwise it is ignored. " + + "That is, whenever the gui option is present (and available), the output is displayed in a window rather than written to a PNG file.\n" + + "\n" ; String help_footer = ""; try { CommandLine cmd = parser.parse( options, args ); - + if( cmd.hasOption( "help" ) ) { - formatter.printHelp( cmd_line_syntax, help_header, options, help_footer ); + formatter.printHelp( helper_width, cmd_line_syntax, help_header, options, help_footer ); return; } @@ -107,10 +180,12 @@ return; } + if( cmd.hasOption( "output" ) ) + output_filename = cmd.getOptionValue("output"); + if( cmd.hasOption("size") ) size = Integer.parseInt( cmd.getOptionValue("size") ); - int quality = 1; if( cmd.hasOption("quality") ) quality = Integer.parseInt( cmd.getOptionValue( "quality" ) ); switch( quality ) @@ -132,19 +207,30 @@ aap = AntiAliasingPattern.QUINCUNX; } - show_gui = cmd.hasOption( "gui" ); + if( cmd.hasOption( "gui" ) ) + show_gui = !java.awt.GraphicsEnvironment.isHeadless() ; - if( cmd.getArgs().length == 0 || ( cmd.getArgs().length == 1 && !show_gui ) || cmd.getArgs().length > 2 ) - { - formatter.printHelp( cmd_line_syntax, help_header, options, help_footer ); + if( cmd.getArgs().length == 0 || cmd.getArgs().length > 2 ) + { + formatter.printHelp( helper_width, cmd_line_syntax, help_header, options, help_footer ); System.exit( -1 ); } else - { - jsurf_filename = cmd.getArgs()[ 0 ]; - if( cmd.getArgs().length > 1 ) - output_filename = cmd.getArgs()[ 1 ]; - } + { + jsurf_filename = cmd.getArgs()[ 0 ]; + if (!show_gui) + { + if( cmd.getArgs().length > 1 ) output_filename = cmd.getArgs()[ 1 ]; + if( output_filename == null ) + { + output_filename = FilenameUtils.getBaseName( jsurf_filename ) + ".png" ; + } + } + else + { + output_filename = null ; + } + } } catch( ParseException exp ) { System.out.println( "Unexpected exception:" + exp.getMessage() ); @@ -155,7 +241,7 @@ formatter.printHelp( cmd_line_syntax, help_header, options, help_footer ); System.exit( -1 ); } - + try { Properties jsurf = new Properties(); @@ -200,7 +286,7 @@ os = System.out; else os = new FileOutputStream( new File( output_filename ) ); - javax.imageio.ImageIO.write( bi, "png", os ); + writeImage( os, bi ); os.flush(); os.close(); } @@ -214,8 +300,11 @@ if( show_gui ) { - // display the image in a window - final String window_title = "jsurf: " + jsurf_filename; + // display the image in a window + final String window_title = + jsurf_progname + ": " + + FilenameUtils.getBaseName( jsurf_filename ) + + " (" + FilenameUtils.getFullPathNoEndSeparator( jsurf_filename ) + ")" ; final BufferedImage window_image = bi; SwingUtilities.invokeLater( new Runnable() { public void run() diff -Nru jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/parser/AlgebraicExpression.g jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/parser/AlgebraicExpression.g --- jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/parser/AlgebraicExpression.g 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/parser/AlgebraicExpression.g 1970-01-01 00:00:00.000000000 +0000 @@ -1,164 +0,0 @@ -/* - * Copyright 2008 Christian Stussak - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -grammar AlgebraicExpression; - -options { language = Java; output = AST; } - -tokens { - PLUS = '+' ; - MINUS = '-' ; - MULT = '*' ; - DIV = '/' ; - POW = '^' ; - LPAR = '(' ; - RPAR = ')' ; -} - -@header -{ -package de.mfo.jsurf.parser; - -import de.mfo.jsurf.algebra.*; -} -@lexer::header -{ -package de.mfo.jsurf.parser; -} - -@members { - public static PolynomialOperation parse( String s ) - throws Exception - { - // Create a string - ANTLRStringStream input = new ANTLRStringStream( s ); - - // Create an ExprLexer that feeds from that stream - AlgebraicExpressionLexer lexer = new AlgebraicExpressionLexer( input ); - - // Create a stream of tokens fed by the lexer - CommonTokenStream tokens = new CommonTokenStream( lexer ); - - // Create a parser that feeds off the token stream - AlgebraicExpressionParser parser = new AlgebraicExpressionParser( tokens ); - - // Begin parsing at start rule - AlgebraicExpressionParser.start_return r = parser.start(); - - // Create a stream of nodes fed by the parser - CommonTreeNodeStream nodes = new CommonTreeNodeStream( ( CommonTree ) r.getTree() ); - - // Create a tree parser that feeds off the node stream - AlgebraicExpressionWalker walker = new AlgebraicExpressionWalker( nodes ); - - // Begin tree parsing at start rule - return walker.start(); - } - - protected void mismatch( IntStream input, int ttype, BitSet follow ) - throws RecognitionException - { - throw new MismatchedTokenException(ttype, input); - } - - @Override - public java.lang.Object recoverFromMismatchedSet( IntStream input, RecognitionException e, BitSet follow ) - throws RecognitionException - { - throw e; - } - - @Override - protected Object recoverFromMismatchedToken( IntStream input, int ttype, BitSet follow ) - throws RecognitionException - { - throw new MismatchedTokenException( ttype, input ); - } -} - -@rulecatch { - catch( RecognitionException e ) - { - throw e; - } -} - -/*------------------------------------------------------------------ - * PARSER RULES - *------------------------------------------------------------------*/ - -start - : add_expr EOF! - ; - -add_expr - : mult_expr ( PLUS^ mult_expr | MINUS^ mult_expr )* - ; - -mult_expr - : neg_expr ( MULT^ neg_expr | DIV^ neg_expr )* - ; - -neg_expr - : MINUS^ pow_expr - | pow_expr - ; - -pow_expr - : unary_expr ( POW^ pow_expr )? - ; - -unary_expr - : primary_expr - | IDENTIFIER^ LPAR! add_expr RPAR! - ; - -primary_expr - : DECIMAL_LITERAL - | FLOATING_POINT_LITERAL - | IDENTIFIER - | LPAR! add_expr RPAR! - ; - -/*------------------------------------------------------------------ - * LEXER RULES - *------------------------------------------------------------------*/ - -DECIMAL_LITERAL : ( '0' | '1'..'9' '0'..'9'* ) ; - -FLOATING_POINT_LITERAL - : DIGIT+ '.' DIGIT* EXPONENT? - | '.' DIGIT+ EXPONENT? - | DIGIT+ EXPONENT - ; - -fragment -EXPONENT : ( 'e' | 'E' ) ( PLUS | MINUS )? DIGIT+ ; - -IDENTIFIER : LETTER ( LETTER | DIGIT )*; - -WHITESPACE : ( '\t' | ' ' | '\r' | '\n' | '\u000C' )+ { $channel = HIDDEN; } ; - -fragment DIGIT : '0'..'9' ; - -fragment -LETTER - : 'A'..'Z' - | 'a'..'z' - | '_' - ; - -ERRCHAR : .; diff -Nru jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/parser/AlgebraicExpressionLexer.java jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/parser/AlgebraicExpressionLexer.java --- jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/parser/AlgebraicExpressionLexer.java 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/parser/AlgebraicExpressionLexer.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,973 +0,0 @@ -// $ANTLR 3.3 Nov 30, 2010 12:50:56 AlgebraicExpression.g 2011-07-14 17:31:42 - -package de.mfo.jsurf.parser; - - -import org.antlr.runtime.*; -import java.util.Stack; -import java.util.List; -import java.util.ArrayList; - -public class AlgebraicExpressionLexer extends Lexer { - public static final int EOF=-1; - public static final int PLUS=4; - public static final int MINUS=5; - public static final int MULT=6; - public static final int DIV=7; - public static final int POW=8; - public static final int LPAR=9; - public static final int RPAR=10; - public static final int IDENTIFIER=11; - public static final int DECIMAL_LITERAL=12; - public static final int FLOATING_POINT_LITERAL=13; - public static final int DIGIT=14; - public static final int EXPONENT=15; - public static final int LETTER=16; - public static final int WHITESPACE=17; - public static final int ERRCHAR=18; - - // delegates - // delegators - - public AlgebraicExpressionLexer() {;} - public AlgebraicExpressionLexer(CharStream input) { - this(input, new RecognizerSharedState()); - } - public AlgebraicExpressionLexer(CharStream input, RecognizerSharedState state) { - super(input,state); - - } - public String getGrammarFileName() { return "AlgebraicExpression.g"; } - - // $ANTLR start "PLUS" - public final void mPLUS() throws RecognitionException { - try { - int _type = PLUS; - int _channel = DEFAULT_TOKEN_CHANNEL; - // AlgebraicExpression.g:11:6: ( '+' ) - // AlgebraicExpression.g:11:8: '+' - { - match('+'); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - } - } - // $ANTLR end "PLUS" - - // $ANTLR start "MINUS" - public final void mMINUS() throws RecognitionException { - try { - int _type = MINUS; - int _channel = DEFAULT_TOKEN_CHANNEL; - // AlgebraicExpression.g:12:7: ( '-' ) - // AlgebraicExpression.g:12:9: '-' - { - match('-'); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - } - } - // $ANTLR end "MINUS" - - // $ANTLR start "MULT" - public final void mMULT() throws RecognitionException { - try { - int _type = MULT; - int _channel = DEFAULT_TOKEN_CHANNEL; - // AlgebraicExpression.g:13:6: ( '*' ) - // AlgebraicExpression.g:13:8: '*' - { - match('*'); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - } - } - // $ANTLR end "MULT" - - // $ANTLR start "DIV" - public final void mDIV() throws RecognitionException { - try { - int _type = DIV; - int _channel = DEFAULT_TOKEN_CHANNEL; - // AlgebraicExpression.g:14:5: ( '/' ) - // AlgebraicExpression.g:14:7: '/' - { - match('/'); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - } - } - // $ANTLR end "DIV" - - // $ANTLR start "POW" - public final void mPOW() throws RecognitionException { - try { - int _type = POW; - int _channel = DEFAULT_TOKEN_CHANNEL; - // AlgebraicExpression.g:15:5: ( '^' ) - // AlgebraicExpression.g:15:7: '^' - { - match('^'); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - } - } - // $ANTLR end "POW" - - // $ANTLR start "LPAR" - public final void mLPAR() throws RecognitionException { - try { - int _type = LPAR; - int _channel = DEFAULT_TOKEN_CHANNEL; - // AlgebraicExpression.g:16:6: ( '(' ) - // AlgebraicExpression.g:16:8: '(' - { - match('('); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - } - } - // $ANTLR end "LPAR" - - // $ANTLR start "RPAR" - public final void mRPAR() throws RecognitionException { - try { - int _type = RPAR; - int _channel = DEFAULT_TOKEN_CHANNEL; - // AlgebraicExpression.g:17:6: ( ')' ) - // AlgebraicExpression.g:17:8: ')' - { - match(')'); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - } - } - // $ANTLR end "RPAR" - - // $ANTLR start "DECIMAL_LITERAL" - public final void mDECIMAL_LITERAL() throws RecognitionException { - try { - int _type = DECIMAL_LITERAL; - int _channel = DEFAULT_TOKEN_CHANNEL; - // AlgebraicExpression.g:124:17: ( ( '0' | '1' .. '9' ( '0' .. '9' )* ) ) - // AlgebraicExpression.g:124:19: ( '0' | '1' .. '9' ( '0' .. '9' )* ) - { - // AlgebraicExpression.g:124:19: ( '0' | '1' .. '9' ( '0' .. '9' )* ) - int alt2=2; - int LA2_0 = input.LA(1); - - if ( (LA2_0=='0') ) { - alt2=1; - } - else if ( ((LA2_0>='1' && LA2_0<='9')) ) { - alt2=2; - } - else { - NoViableAltException nvae = - new NoViableAltException("", 2, 0, input); - - throw nvae; - } - switch (alt2) { - case 1 : - // AlgebraicExpression.g:124:21: '0' - { - match('0'); - - } - break; - case 2 : - // AlgebraicExpression.g:124:27: '1' .. '9' ( '0' .. '9' )* - { - matchRange('1','9'); - // AlgebraicExpression.g:124:36: ( '0' .. '9' )* - loop1: - do { - int alt1=2; - int LA1_0 = input.LA(1); - - if ( ((LA1_0>='0' && LA1_0<='9')) ) { - alt1=1; - } - - - switch (alt1) { - case 1 : - // AlgebraicExpression.g:124:36: '0' .. '9' - { - matchRange('0','9'); - - } - break; - - default : - break loop1; - } - } while (true); - - - } - break; - - } - - - } - - state.type = _type; - state.channel = _channel; - } - finally { - } - } - // $ANTLR end "DECIMAL_LITERAL" - - // $ANTLR start "FLOATING_POINT_LITERAL" - public final void mFLOATING_POINT_LITERAL() throws RecognitionException { - try { - int _type = FLOATING_POINT_LITERAL; - int _channel = DEFAULT_TOKEN_CHANNEL; - // AlgebraicExpression.g:127:2: ( ( DIGIT )+ '.' ( DIGIT )* ( EXPONENT )? | '.' ( DIGIT )+ ( EXPONENT )? | ( DIGIT )+ EXPONENT ) - int alt9=3; - alt9 = dfa9.predict(input); - switch (alt9) { - case 1 : - // AlgebraicExpression.g:127:4: ( DIGIT )+ '.' ( DIGIT )* ( EXPONENT )? - { - // AlgebraicExpression.g:127:4: ( DIGIT )+ - int cnt3=0; - loop3: - do { - int alt3=2; - int LA3_0 = input.LA(1); - - if ( ((LA3_0>='0' && LA3_0<='9')) ) { - alt3=1; - } - - - switch (alt3) { - case 1 : - // AlgebraicExpression.g:127:4: DIGIT - { - mDIGIT(); - - } - break; - - default : - if ( cnt3 >= 1 ) break loop3; - EarlyExitException eee = - new EarlyExitException(3, input); - throw eee; - } - cnt3++; - } while (true); - - match('.'); - // AlgebraicExpression.g:127:15: ( DIGIT )* - loop4: - do { - int alt4=2; - int LA4_0 = input.LA(1); - - if ( ((LA4_0>='0' && LA4_0<='9')) ) { - alt4=1; - } - - - switch (alt4) { - case 1 : - // AlgebraicExpression.g:127:15: DIGIT - { - mDIGIT(); - - } - break; - - default : - break loop4; - } - } while (true); - - // AlgebraicExpression.g:127:22: ( EXPONENT )? - int alt5=2; - int LA5_0 = input.LA(1); - - if ( (LA5_0=='E'||LA5_0=='e') ) { - alt5=1; - } - switch (alt5) { - case 1 : - // AlgebraicExpression.g:127:22: EXPONENT - { - mEXPONENT(); - - } - break; - - } - - - } - break; - case 2 : - // AlgebraicExpression.g:128:4: '.' ( DIGIT )+ ( EXPONENT )? - { - match('.'); - // AlgebraicExpression.g:128:8: ( DIGIT )+ - int cnt6=0; - loop6: - do { - int alt6=2; - int LA6_0 = input.LA(1); - - if ( ((LA6_0>='0' && LA6_0<='9')) ) { - alt6=1; - } - - - switch (alt6) { - case 1 : - // AlgebraicExpression.g:128:8: DIGIT - { - mDIGIT(); - - } - break; - - default : - if ( cnt6 >= 1 ) break loop6; - EarlyExitException eee = - new EarlyExitException(6, input); - throw eee; - } - cnt6++; - } while (true); - - // AlgebraicExpression.g:128:15: ( EXPONENT )? - int alt7=2; - int LA7_0 = input.LA(1); - - if ( (LA7_0=='E'||LA7_0=='e') ) { - alt7=1; - } - switch (alt7) { - case 1 : - // AlgebraicExpression.g:128:15: EXPONENT - { - mEXPONENT(); - - } - break; - - } - - - } - break; - case 3 : - // AlgebraicExpression.g:129:4: ( DIGIT )+ EXPONENT - { - // AlgebraicExpression.g:129:4: ( DIGIT )+ - int cnt8=0; - loop8: - do { - int alt8=2; - int LA8_0 = input.LA(1); - - if ( ((LA8_0>='0' && LA8_0<='9')) ) { - alt8=1; - } - - - switch (alt8) { - case 1 : - // AlgebraicExpression.g:129:4: DIGIT - { - mDIGIT(); - - } - break; - - default : - if ( cnt8 >= 1 ) break loop8; - EarlyExitException eee = - new EarlyExitException(8, input); - throw eee; - } - cnt8++; - } while (true); - - mEXPONENT(); - - } - break; - - } - state.type = _type; - state.channel = _channel; - } - finally { - } - } - // $ANTLR end "FLOATING_POINT_LITERAL" - - // $ANTLR start "EXPONENT" - public final void mEXPONENT() throws RecognitionException { - try { - // AlgebraicExpression.g:133:10: ( ( 'e' | 'E' ) ( PLUS | MINUS )? ( DIGIT )+ ) - // AlgebraicExpression.g:133:12: ( 'e' | 'E' ) ( PLUS | MINUS )? ( DIGIT )+ - { - if ( input.LA(1)=='E'||input.LA(1)=='e' ) { - input.consume(); - - } - else { - MismatchedSetException mse = new MismatchedSetException(null,input); - recover(mse); - throw mse;} - - // AlgebraicExpression.g:133:26: ( PLUS | MINUS )? - int alt10=2; - int LA10_0 = input.LA(1); - - if ( (LA10_0=='+'||LA10_0=='-') ) { - alt10=1; - } - switch (alt10) { - case 1 : - // AlgebraicExpression.g: - { - if ( input.LA(1)=='+'||input.LA(1)=='-' ) { - input.consume(); - - } - else { - MismatchedSetException mse = new MismatchedSetException(null,input); - recover(mse); - throw mse;} - - - } - break; - - } - - // AlgebraicExpression.g:133:44: ( DIGIT )+ - int cnt11=0; - loop11: - do { - int alt11=2; - int LA11_0 = input.LA(1); - - if ( ((LA11_0>='0' && LA11_0<='9')) ) { - alt11=1; - } - - - switch (alt11) { - case 1 : - // AlgebraicExpression.g:133:44: DIGIT - { - mDIGIT(); - - } - break; - - default : - if ( cnt11 >= 1 ) break loop11; - EarlyExitException eee = - new EarlyExitException(11, input); - throw eee; - } - cnt11++; - } while (true); - - - } - - } - finally { - } - } - // $ANTLR end "EXPONENT" - - // $ANTLR start "IDENTIFIER" - public final void mIDENTIFIER() throws RecognitionException { - try { - int _type = IDENTIFIER; - int _channel = DEFAULT_TOKEN_CHANNEL; - // AlgebraicExpression.g:135:12: ( LETTER ( LETTER | DIGIT )* ) - // AlgebraicExpression.g:135:14: LETTER ( LETTER | DIGIT )* - { - mLETTER(); - // AlgebraicExpression.g:135:21: ( LETTER | DIGIT )* - loop12: - do { - int alt12=2; - int LA12_0 = input.LA(1); - - if ( ((LA12_0>='0' && LA12_0<='9')||(LA12_0>='A' && LA12_0<='Z')||LA12_0=='_'||(LA12_0>='a' && LA12_0<='z')) ) { - alt12=1; - } - - - switch (alt12) { - case 1 : - // AlgebraicExpression.g: - { - if ( (input.LA(1)>='0' && input.LA(1)<='9')||(input.LA(1)>='A' && input.LA(1)<='Z')||input.LA(1)=='_'||(input.LA(1)>='a' && input.LA(1)<='z') ) { - input.consume(); - - } - else { - MismatchedSetException mse = new MismatchedSetException(null,input); - recover(mse); - throw mse;} - - - } - break; - - default : - break loop12; - } - } while (true); - - - } - - state.type = _type; - state.channel = _channel; - } - finally { - } - } - // $ANTLR end "IDENTIFIER" - - // $ANTLR start "WHITESPACE" - public final void mWHITESPACE() throws RecognitionException { - try { - int _type = WHITESPACE; - int _channel = DEFAULT_TOKEN_CHANNEL; - // AlgebraicExpression.g:137:12: ( ( '\\t' | ' ' | '\\r' | '\\n' | '\\u000C' )+ ) - // AlgebraicExpression.g:137:14: ( '\\t' | ' ' | '\\r' | '\\n' | '\\u000C' )+ - { - // AlgebraicExpression.g:137:14: ( '\\t' | ' ' | '\\r' | '\\n' | '\\u000C' )+ - int cnt13=0; - loop13: - do { - int alt13=2; - int LA13_0 = input.LA(1); - - if ( ((LA13_0>='\t' && LA13_0<='\n')||(LA13_0>='\f' && LA13_0<='\r')||LA13_0==' ') ) { - alt13=1; - } - - - switch (alt13) { - case 1 : - // AlgebraicExpression.g: - { - if ( (input.LA(1)>='\t' && input.LA(1)<='\n')||(input.LA(1)>='\f' && input.LA(1)<='\r')||input.LA(1)==' ' ) { - input.consume(); - - } - else { - MismatchedSetException mse = new MismatchedSetException(null,input); - recover(mse); - throw mse;} - - - } - break; - - default : - if ( cnt13 >= 1 ) break loop13; - EarlyExitException eee = - new EarlyExitException(13, input); - throw eee; - } - cnt13++; - } while (true); - - _channel = HIDDEN; - - } - - state.type = _type; - state.channel = _channel; - } - finally { - } - } - // $ANTLR end "WHITESPACE" - - // $ANTLR start "DIGIT" - public final void mDIGIT() throws RecognitionException { - try { - // AlgebraicExpression.g:139:16: ( '0' .. '9' ) - // AlgebraicExpression.g:139:18: '0' .. '9' - { - matchRange('0','9'); - - } - - } - finally { - } - } - // $ANTLR end "DIGIT" - - // $ANTLR start "LETTER" - public final void mLETTER() throws RecognitionException { - try { - // AlgebraicExpression.g:143:2: ( 'A' .. 'Z' | 'a' .. 'z' | '_' ) - // AlgebraicExpression.g: - { - if ( (input.LA(1)>='A' && input.LA(1)<='Z')||input.LA(1)=='_'||(input.LA(1)>='a' && input.LA(1)<='z') ) { - input.consume(); - - } - else { - MismatchedSetException mse = new MismatchedSetException(null,input); - recover(mse); - throw mse;} - - - } - - } - finally { - } - } - // $ANTLR end "LETTER" - - // $ANTLR start "ERRCHAR" - public final void mERRCHAR() throws RecognitionException { - try { - int _type = ERRCHAR; - int _channel = DEFAULT_TOKEN_CHANNEL; - // AlgebraicExpression.g:148:9: ( . ) - // AlgebraicExpression.g:148:11: . - { - matchAny(); - - } - - state.type = _type; - state.channel = _channel; - } - finally { - } - } - // $ANTLR end "ERRCHAR" - - public void mTokens() throws RecognitionException { - // AlgebraicExpression.g:1:8: ( PLUS | MINUS | MULT | DIV | POW | LPAR | RPAR | DECIMAL_LITERAL | FLOATING_POINT_LITERAL | IDENTIFIER | WHITESPACE | ERRCHAR ) - int alt14=12; - alt14 = dfa14.predict(input); - switch (alt14) { - case 1 : - // AlgebraicExpression.g:1:10: PLUS - { - mPLUS(); - - } - break; - case 2 : - // AlgebraicExpression.g:1:15: MINUS - { - mMINUS(); - - } - break; - case 3 : - // AlgebraicExpression.g:1:21: MULT - { - mMULT(); - - } - break; - case 4 : - // AlgebraicExpression.g:1:26: DIV - { - mDIV(); - - } - break; - case 5 : - // AlgebraicExpression.g:1:30: POW - { - mPOW(); - - } - break; - case 6 : - // AlgebraicExpression.g:1:34: LPAR - { - mLPAR(); - - } - break; - case 7 : - // AlgebraicExpression.g:1:39: RPAR - { - mRPAR(); - - } - break; - case 8 : - // AlgebraicExpression.g:1:44: DECIMAL_LITERAL - { - mDECIMAL_LITERAL(); - - } - break; - case 9 : - // AlgebraicExpression.g:1:60: FLOATING_POINT_LITERAL - { - mFLOATING_POINT_LITERAL(); - - } - break; - case 10 : - // AlgebraicExpression.g:1:83: IDENTIFIER - { - mIDENTIFIER(); - - } - break; - case 11 : - // AlgebraicExpression.g:1:94: WHITESPACE - { - mWHITESPACE(); - - } - break; - case 12 : - // AlgebraicExpression.g:1:105: ERRCHAR - { - mERRCHAR(); - - } - break; - - } - - } - - - protected DFA9 dfa9 = new DFA9(this); - protected DFA14 dfa14 = new DFA14(this); - static final String DFA9_eotS = - "\5\uffff"; - static final String DFA9_eofS = - "\5\uffff"; - static final String DFA9_minS = - "\2\56\3\uffff"; - static final String DFA9_maxS = - "\1\71\1\145\3\uffff"; - static final String DFA9_acceptS = - "\2\uffff\1\2\1\1\1\3"; - static final String DFA9_specialS = - "\5\uffff}>"; - static final String[] DFA9_transitionS = { - "\1\2\1\uffff\12\1", - "\1\3\1\uffff\12\1\13\uffff\1\4\37\uffff\1\4", - "", - "", - "" - }; - - static final short[] DFA9_eot = DFA.unpackEncodedString(DFA9_eotS); - static final short[] DFA9_eof = DFA.unpackEncodedString(DFA9_eofS); - static final char[] DFA9_min = DFA.unpackEncodedStringToUnsignedChars(DFA9_minS); - static final char[] DFA9_max = DFA.unpackEncodedStringToUnsignedChars(DFA9_maxS); - static final short[] DFA9_accept = DFA.unpackEncodedString(DFA9_acceptS); - static final short[] DFA9_special = DFA.unpackEncodedString(DFA9_specialS); - static final short[][] DFA9_transition; - - static { - int numStates = DFA9_transitionS.length; - DFA9_transition = new short[numStates][]; - for (int i=0; i"; - static final String[] DFA14_transitionS = { - "\11\15\2\14\1\15\2\14\22\15\1\14\7\15\1\6\1\7\1\3\1\1\1\15\1"+ - "\2\1\12\1\4\1\10\11\11\7\15\32\13\3\15\1\5\1\13\1\15\32\13\uff85"+ - "\15", - "", - "", - "", - "", - "", - "", - "", - "\1\26\1\uffff\12\26\13\uffff\1\26\37\uffff\1\26", - "\1\26\1\uffff\12\27\13\uffff\1\26\37\uffff\1\26", - "\12\26", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "\1\26\1\uffff\12\27\13\uffff\1\26\37\uffff\1\26", - "", - "" - }; - - static final short[] DFA14_eot = DFA.unpackEncodedString(DFA14_eotS); - static final short[] DFA14_eof = DFA.unpackEncodedString(DFA14_eofS); - static final char[] DFA14_min = DFA.unpackEncodedStringToUnsignedChars(DFA14_minS); - static final char[] DFA14_max = DFA.unpackEncodedStringToUnsignedChars(DFA14_maxS); - static final short[] DFA14_accept = DFA.unpackEncodedString(DFA14_acceptS); - static final short[] DFA14_special = DFA.unpackEncodedString(DFA14_specialS); - static final short[][] DFA14_transition; - - static { - int numStates = DFA14_transitionS.length; - DFA14_transition = new short[numStates][]; - for (int i=0; i='1' && LA14_0<='9')) ) {s = 9;} - - else if ( (LA14_0=='.') ) {s = 10;} - - else if ( ((LA14_0>='A' && LA14_0<='Z')||LA14_0=='_'||(LA14_0>='a' && LA14_0<='z')) ) {s = 11;} - - else if ( ((LA14_0>='\t' && LA14_0<='\n')||(LA14_0>='\f' && LA14_0<='\r')||LA14_0==' ') ) {s = 12;} - - else if ( ((LA14_0>='\u0000' && LA14_0<='\b')||LA14_0=='\u000B'||(LA14_0>='\u000E' && LA14_0<='\u001F')||(LA14_0>='!' && LA14_0<='\'')||LA14_0==','||(LA14_0>=':' && LA14_0<='@')||(LA14_0>='[' && LA14_0<=']')||LA14_0=='`'||(LA14_0>='{' && LA14_0<='\uFFFF')) ) {s = 13;} - - if ( s>=0 ) return s; - break; - } - NoViableAltException nvae = - new NoViableAltException(getDescription(), 14, _s, input); - error(nvae); - throw nvae; - } - } - - -} \ No newline at end of file diff -Nru jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/parser/AlgebraicExpressionParser.java jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/parser/AlgebraicExpressionParser.java --- jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/parser/AlgebraicExpressionParser.java 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/parser/AlgebraicExpressionParser.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,827 +0,0 @@ -// $ANTLR 3.3 Nov 30, 2010 12:50:56 AlgebraicExpression.g 2011-07-14 17:31:41 - -package de.mfo.jsurf.parser; - -import de.mfo.jsurf.algebra.*; - - -import org.antlr.runtime.*; -import java.util.Stack; -import java.util.List; -import java.util.ArrayList; - - -import org.antlr.runtime.tree.*; - -public class AlgebraicExpressionParser extends Parser { - public static final String[] tokenNames = new String[] { - "", "", "", "", "PLUS", "MINUS", "MULT", "DIV", "POW", "LPAR", "RPAR", "IDENTIFIER", "DECIMAL_LITERAL", "FLOATING_POINT_LITERAL", "DIGIT", "EXPONENT", "LETTER", "WHITESPACE", "ERRCHAR" - }; - public static final int EOF=-1; - public static final int PLUS=4; - public static final int MINUS=5; - public static final int MULT=6; - public static final int DIV=7; - public static final int POW=8; - public static final int LPAR=9; - public static final int RPAR=10; - public static final int IDENTIFIER=11; - public static final int DECIMAL_LITERAL=12; - public static final int FLOATING_POINT_LITERAL=13; - public static final int DIGIT=14; - public static final int EXPONENT=15; - public static final int LETTER=16; - public static final int WHITESPACE=17; - public static final int ERRCHAR=18; - - // delegates - // delegators - - - public AlgebraicExpressionParser(TokenStream input) { - this(input, new RecognizerSharedState()); - } - public AlgebraicExpressionParser(TokenStream input, RecognizerSharedState state) { - super(input, state); - - } - - protected TreeAdaptor adaptor = new CommonTreeAdaptor(); - - public void setTreeAdaptor(TreeAdaptor adaptor) { - this.adaptor = adaptor; - } - public TreeAdaptor getTreeAdaptor() { - return adaptor; - } - - public String[] getTokenNames() { return AlgebraicExpressionParser.tokenNames; } - public String getGrammarFileName() { return "AlgebraicExpression.g"; } - - - public static PolynomialOperation parse( String s ) - throws Exception - { - // Create a string - ANTLRStringStream input = new ANTLRStringStream( s ); - - // Create an ExprLexer that feeds from that stream - AlgebraicExpressionLexer lexer = new AlgebraicExpressionLexer( input ); - - // Create a stream of tokens fed by the lexer - CommonTokenStream tokens = new CommonTokenStream( lexer ); - - // Create a parser that feeds off the token stream - AlgebraicExpressionParser parser = new AlgebraicExpressionParser( tokens ); - - // Begin parsing at start rule - AlgebraicExpressionParser.start_return r = parser.start(); - - // Create a stream of nodes fed by the parser - CommonTreeNodeStream nodes = new CommonTreeNodeStream( ( CommonTree ) r.getTree() ); - - // Create a tree parser that feeds off the node stream - AlgebraicExpressionWalker walker = new AlgebraicExpressionWalker( nodes ); - - // Begin tree parsing at start rule - return walker.start(); - } - - protected void mismatch( IntStream input, int ttype, BitSet follow ) - throws RecognitionException - { - throw new MismatchedTokenException(ttype, input); - } - - @Override - public java.lang.Object recoverFromMismatchedSet( IntStream input, RecognitionException e, BitSet follow ) - throws RecognitionException - { - throw e; - } - - @Override - protected Object recoverFromMismatchedToken( IntStream input, int ttype, BitSet follow ) - throws RecognitionException - { - throw new MismatchedTokenException( ttype, input ); - } - - - public static class start_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start "start" - // AlgebraicExpression.g:87:1: start : add_expr EOF ; - public final AlgebraicExpressionParser.start_return start() throws RecognitionException { - AlgebraicExpressionParser.start_return retval = new AlgebraicExpressionParser.start_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token EOF2=null; - AlgebraicExpressionParser.add_expr_return add_expr1 = null; - - - Object EOF2_tree=null; - - try { - // AlgebraicExpression.g:88:2: ( add_expr EOF ) - // AlgebraicExpression.g:88:4: add_expr EOF - { - root_0 = (Object)adaptor.nil(); - - pushFollow(FOLLOW_add_expr_in_start128); - add_expr1=add_expr(); - - state._fsp--; - - adaptor.addChild(root_0, add_expr1.getTree()); - EOF2=(Token)match(input,EOF,FOLLOW_EOF_in_start130); - - } - - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - - catch( RecognitionException e ) - { - throw e; - } - finally { - } - return retval; - } - // $ANTLR end "start" - - public static class add_expr_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start "add_expr" - // AlgebraicExpression.g:91:1: add_expr : mult_expr ( PLUS mult_expr | MINUS mult_expr )* ; - public final AlgebraicExpressionParser.add_expr_return add_expr() throws RecognitionException { - AlgebraicExpressionParser.add_expr_return retval = new AlgebraicExpressionParser.add_expr_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token PLUS4=null; - Token MINUS6=null; - AlgebraicExpressionParser.mult_expr_return mult_expr3 = null; - - AlgebraicExpressionParser.mult_expr_return mult_expr5 = null; - - AlgebraicExpressionParser.mult_expr_return mult_expr7 = null; - - - Object PLUS4_tree=null; - Object MINUS6_tree=null; - - try { - // AlgebraicExpression.g:92:2: ( mult_expr ( PLUS mult_expr | MINUS mult_expr )* ) - // AlgebraicExpression.g:92:4: mult_expr ( PLUS mult_expr | MINUS mult_expr )* - { - root_0 = (Object)adaptor.nil(); - - pushFollow(FOLLOW_mult_expr_in_add_expr142); - mult_expr3=mult_expr(); - - state._fsp--; - - adaptor.addChild(root_0, mult_expr3.getTree()); - // AlgebraicExpression.g:92:14: ( PLUS mult_expr | MINUS mult_expr )* - loop1: - do { - int alt1=3; - int LA1_0 = input.LA(1); - - if ( (LA1_0==PLUS) ) { - alt1=1; - } - else if ( (LA1_0==MINUS) ) { - alt1=2; - } - - - switch (alt1) { - case 1 : - // AlgebraicExpression.g:92:16: PLUS mult_expr - { - PLUS4=(Token)match(input,PLUS,FOLLOW_PLUS_in_add_expr146); - PLUS4_tree = (Object)adaptor.create(PLUS4); - root_0 = (Object)adaptor.becomeRoot(PLUS4_tree, root_0); - - pushFollow(FOLLOW_mult_expr_in_add_expr149); - mult_expr5=mult_expr(); - - state._fsp--; - - adaptor.addChild(root_0, mult_expr5.getTree()); - - } - break; - case 2 : - // AlgebraicExpression.g:92:34: MINUS mult_expr - { - MINUS6=(Token)match(input,MINUS,FOLLOW_MINUS_in_add_expr153); - MINUS6_tree = (Object)adaptor.create(MINUS6); - root_0 = (Object)adaptor.becomeRoot(MINUS6_tree, root_0); - - pushFollow(FOLLOW_mult_expr_in_add_expr156); - mult_expr7=mult_expr(); - - state._fsp--; - - adaptor.addChild(root_0, mult_expr7.getTree()); - - } - break; - - default : - break loop1; - } - } while (true); - - - } - - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - - catch( RecognitionException e ) - { - throw e; - } - finally { - } - return retval; - } - // $ANTLR end "add_expr" - - public static class mult_expr_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start "mult_expr" - // AlgebraicExpression.g:95:1: mult_expr : neg_expr ( MULT neg_expr | DIV neg_expr )* ; - public final AlgebraicExpressionParser.mult_expr_return mult_expr() throws RecognitionException { - AlgebraicExpressionParser.mult_expr_return retval = new AlgebraicExpressionParser.mult_expr_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token MULT9=null; - Token DIV11=null; - AlgebraicExpressionParser.neg_expr_return neg_expr8 = null; - - AlgebraicExpressionParser.neg_expr_return neg_expr10 = null; - - AlgebraicExpressionParser.neg_expr_return neg_expr12 = null; - - - Object MULT9_tree=null; - Object DIV11_tree=null; - - try { - // AlgebraicExpression.g:96:2: ( neg_expr ( MULT neg_expr | DIV neg_expr )* ) - // AlgebraicExpression.g:96:4: neg_expr ( MULT neg_expr | DIV neg_expr )* - { - root_0 = (Object)adaptor.nil(); - - pushFollow(FOLLOW_neg_expr_in_mult_expr170); - neg_expr8=neg_expr(); - - state._fsp--; - - adaptor.addChild(root_0, neg_expr8.getTree()); - // AlgebraicExpression.g:96:13: ( MULT neg_expr | DIV neg_expr )* - loop2: - do { - int alt2=3; - int LA2_0 = input.LA(1); - - if ( (LA2_0==MULT) ) { - alt2=1; - } - else if ( (LA2_0==DIV) ) { - alt2=2; - } - - - switch (alt2) { - case 1 : - // AlgebraicExpression.g:96:15: MULT neg_expr - { - MULT9=(Token)match(input,MULT,FOLLOW_MULT_in_mult_expr174); - MULT9_tree = (Object)adaptor.create(MULT9); - root_0 = (Object)adaptor.becomeRoot(MULT9_tree, root_0); - - pushFollow(FOLLOW_neg_expr_in_mult_expr177); - neg_expr10=neg_expr(); - - state._fsp--; - - adaptor.addChild(root_0, neg_expr10.getTree()); - - } - break; - case 2 : - // AlgebraicExpression.g:96:32: DIV neg_expr - { - DIV11=(Token)match(input,DIV,FOLLOW_DIV_in_mult_expr181); - DIV11_tree = (Object)adaptor.create(DIV11); - root_0 = (Object)adaptor.becomeRoot(DIV11_tree, root_0); - - pushFollow(FOLLOW_neg_expr_in_mult_expr184); - neg_expr12=neg_expr(); - - state._fsp--; - - adaptor.addChild(root_0, neg_expr12.getTree()); - - } - break; - - default : - break loop2; - } - } while (true); - - - } - - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - - catch( RecognitionException e ) - { - throw e; - } - finally { - } - return retval; - } - // $ANTLR end "mult_expr" - - public static class neg_expr_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start "neg_expr" - // AlgebraicExpression.g:99:1: neg_expr : ( MINUS pow_expr | pow_expr ); - public final AlgebraicExpressionParser.neg_expr_return neg_expr() throws RecognitionException { - AlgebraicExpressionParser.neg_expr_return retval = new AlgebraicExpressionParser.neg_expr_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token MINUS13=null; - AlgebraicExpressionParser.pow_expr_return pow_expr14 = null; - - AlgebraicExpressionParser.pow_expr_return pow_expr15 = null; - - - Object MINUS13_tree=null; - - try { - // AlgebraicExpression.g:100:9: ( MINUS pow_expr | pow_expr ) - int alt3=2; - int LA3_0 = input.LA(1); - - if ( (LA3_0==MINUS) ) { - alt3=1; - } - else if ( (LA3_0==LPAR||(LA3_0>=IDENTIFIER && LA3_0<=FLOATING_POINT_LITERAL)) ) { - alt3=2; - } - else { - NoViableAltException nvae = - new NoViableAltException("", 3, 0, input); - - throw nvae; - } - switch (alt3) { - case 1 : - // AlgebraicExpression.g:100:11: MINUS pow_expr - { - root_0 = (Object)adaptor.nil(); - - MINUS13=(Token)match(input,MINUS,FOLLOW_MINUS_in_neg_expr205); - MINUS13_tree = (Object)adaptor.create(MINUS13); - root_0 = (Object)adaptor.becomeRoot(MINUS13_tree, root_0); - - pushFollow(FOLLOW_pow_expr_in_neg_expr208); - pow_expr14=pow_expr(); - - state._fsp--; - - adaptor.addChild(root_0, pow_expr14.getTree()); - - } - break; - case 2 : - // AlgebraicExpression.g:101:11: pow_expr - { - root_0 = (Object)adaptor.nil(); - - pushFollow(FOLLOW_pow_expr_in_neg_expr220); - pow_expr15=pow_expr(); - - state._fsp--; - - adaptor.addChild(root_0, pow_expr15.getTree()); - - } - break; - - } - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - - catch( RecognitionException e ) - { - throw e; - } - finally { - } - return retval; - } - // $ANTLR end "neg_expr" - - public static class pow_expr_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start "pow_expr" - // AlgebraicExpression.g:104:1: pow_expr : unary_expr ( POW pow_expr )? ; - public final AlgebraicExpressionParser.pow_expr_return pow_expr() throws RecognitionException { - AlgebraicExpressionParser.pow_expr_return retval = new AlgebraicExpressionParser.pow_expr_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token POW17=null; - AlgebraicExpressionParser.unary_expr_return unary_expr16 = null; - - AlgebraicExpressionParser.pow_expr_return pow_expr18 = null; - - - Object POW17_tree=null; - - try { - // AlgebraicExpression.g:105:2: ( unary_expr ( POW pow_expr )? ) - // AlgebraicExpression.g:105:4: unary_expr ( POW pow_expr )? - { - root_0 = (Object)adaptor.nil(); - - pushFollow(FOLLOW_unary_expr_in_pow_expr238); - unary_expr16=unary_expr(); - - state._fsp--; - - adaptor.addChild(root_0, unary_expr16.getTree()); - // AlgebraicExpression.g:105:15: ( POW pow_expr )? - int alt4=2; - int LA4_0 = input.LA(1); - - if ( (LA4_0==POW) ) { - alt4=1; - } - switch (alt4) { - case 1 : - // AlgebraicExpression.g:105:17: POW pow_expr - { - POW17=(Token)match(input,POW,FOLLOW_POW_in_pow_expr242); - POW17_tree = (Object)adaptor.create(POW17); - root_0 = (Object)adaptor.becomeRoot(POW17_tree, root_0); - - pushFollow(FOLLOW_pow_expr_in_pow_expr245); - pow_expr18=pow_expr(); - - state._fsp--; - - adaptor.addChild(root_0, pow_expr18.getTree()); - - } - break; - - } - - - } - - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - - catch( RecognitionException e ) - { - throw e; - } - finally { - } - return retval; - } - // $ANTLR end "pow_expr" - - public static class unary_expr_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start "unary_expr" - // AlgebraicExpression.g:108:1: unary_expr : ( primary_expr | IDENTIFIER LPAR add_expr RPAR ); - public final AlgebraicExpressionParser.unary_expr_return unary_expr() throws RecognitionException { - AlgebraicExpressionParser.unary_expr_return retval = new AlgebraicExpressionParser.unary_expr_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token IDENTIFIER20=null; - Token LPAR21=null; - Token RPAR23=null; - AlgebraicExpressionParser.primary_expr_return primary_expr19 = null; - - AlgebraicExpressionParser.add_expr_return add_expr22 = null; - - - Object IDENTIFIER20_tree=null; - Object LPAR21_tree=null; - Object RPAR23_tree=null; - - try { - // AlgebraicExpression.g:109:9: ( primary_expr | IDENTIFIER LPAR add_expr RPAR ) - int alt5=2; - int LA5_0 = input.LA(1); - - if ( (LA5_0==LPAR||(LA5_0>=DECIMAL_LITERAL && LA5_0<=FLOATING_POINT_LITERAL)) ) { - alt5=1; - } - else if ( (LA5_0==IDENTIFIER) ) { - int LA5_2 = input.LA(2); - - if ( (LA5_2==LPAR) ) { - alt5=2; - } - else if ( (LA5_2==EOF||(LA5_2>=PLUS && LA5_2<=POW)||LA5_2==RPAR) ) { - alt5=1; - } - else { - NoViableAltException nvae = - new NoViableAltException("", 5, 2, input); - - throw nvae; - } - } - else { - NoViableAltException nvae = - new NoViableAltException("", 5, 0, input); - - throw nvae; - } - switch (alt5) { - case 1 : - // AlgebraicExpression.g:109:11: primary_expr - { - root_0 = (Object)adaptor.nil(); - - pushFollow(FOLLOW_primary_expr_in_unary_expr266); - primary_expr19=primary_expr(); - - state._fsp--; - - adaptor.addChild(root_0, primary_expr19.getTree()); - - } - break; - case 2 : - // AlgebraicExpression.g:110:4: IDENTIFIER LPAR add_expr RPAR - { - root_0 = (Object)adaptor.nil(); - - IDENTIFIER20=(Token)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_unary_expr271); - IDENTIFIER20_tree = (Object)adaptor.create(IDENTIFIER20); - root_0 = (Object)adaptor.becomeRoot(IDENTIFIER20_tree, root_0); - - LPAR21=(Token)match(input,LPAR,FOLLOW_LPAR_in_unary_expr274); - pushFollow(FOLLOW_add_expr_in_unary_expr277); - add_expr22=add_expr(); - - state._fsp--; - - adaptor.addChild(root_0, add_expr22.getTree()); - RPAR23=(Token)match(input,RPAR,FOLLOW_RPAR_in_unary_expr279); - - } - break; - - } - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - - catch( RecognitionException e ) - { - throw e; - } - finally { - } - return retval; - } - // $ANTLR end "unary_expr" - - public static class primary_expr_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start "primary_expr" - // AlgebraicExpression.g:113:1: primary_expr : ( DECIMAL_LITERAL | FLOATING_POINT_LITERAL | IDENTIFIER | LPAR add_expr RPAR ); - public final AlgebraicExpressionParser.primary_expr_return primary_expr() throws RecognitionException { - AlgebraicExpressionParser.primary_expr_return retval = new AlgebraicExpressionParser.primary_expr_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token DECIMAL_LITERAL24=null; - Token FLOATING_POINT_LITERAL25=null; - Token IDENTIFIER26=null; - Token LPAR27=null; - Token RPAR29=null; - AlgebraicExpressionParser.add_expr_return add_expr28 = null; - - - Object DECIMAL_LITERAL24_tree=null; - Object FLOATING_POINT_LITERAL25_tree=null; - Object IDENTIFIER26_tree=null; - Object LPAR27_tree=null; - Object RPAR29_tree=null; - - try { - // AlgebraicExpression.g:114:2: ( DECIMAL_LITERAL | FLOATING_POINT_LITERAL | IDENTIFIER | LPAR add_expr RPAR ) - int alt6=4; - switch ( input.LA(1) ) { - case DECIMAL_LITERAL: - { - alt6=1; - } - break; - case FLOATING_POINT_LITERAL: - { - alt6=2; - } - break; - case IDENTIFIER: - { - alt6=3; - } - break; - case LPAR: - { - alt6=4; - } - break; - default: - NoViableAltException nvae = - new NoViableAltException("", 6, 0, input); - - throw nvae; - } - - switch (alt6) { - case 1 : - // AlgebraicExpression.g:114:4: DECIMAL_LITERAL - { - root_0 = (Object)adaptor.nil(); - - DECIMAL_LITERAL24=(Token)match(input,DECIMAL_LITERAL,FOLLOW_DECIMAL_LITERAL_in_primary_expr291); - DECIMAL_LITERAL24_tree = (Object)adaptor.create(DECIMAL_LITERAL24); - adaptor.addChild(root_0, DECIMAL_LITERAL24_tree); - - - } - break; - case 2 : - // AlgebraicExpression.g:115:4: FLOATING_POINT_LITERAL - { - root_0 = (Object)adaptor.nil(); - - FLOATING_POINT_LITERAL25=(Token)match(input,FLOATING_POINT_LITERAL,FOLLOW_FLOATING_POINT_LITERAL_in_primary_expr296); - FLOATING_POINT_LITERAL25_tree = (Object)adaptor.create(FLOATING_POINT_LITERAL25); - adaptor.addChild(root_0, FLOATING_POINT_LITERAL25_tree); - - - } - break; - case 3 : - // AlgebraicExpression.g:116:4: IDENTIFIER - { - root_0 = (Object)adaptor.nil(); - - IDENTIFIER26=(Token)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_primary_expr301); - IDENTIFIER26_tree = (Object)adaptor.create(IDENTIFIER26); - adaptor.addChild(root_0, IDENTIFIER26_tree); - - - } - break; - case 4 : - // AlgebraicExpression.g:117:4: LPAR add_expr RPAR - { - root_0 = (Object)adaptor.nil(); - - LPAR27=(Token)match(input,LPAR,FOLLOW_LPAR_in_primary_expr306); - pushFollow(FOLLOW_add_expr_in_primary_expr309); - add_expr28=add_expr(); - - state._fsp--; - - adaptor.addChild(root_0, add_expr28.getTree()); - RPAR29=(Token)match(input,RPAR,FOLLOW_RPAR_in_primary_expr311); - - } - break; - - } - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - - catch( RecognitionException e ) - { - throw e; - } - finally { - } - return retval; - } - // $ANTLR end "primary_expr" - - // Delegated rules - - - - - public static final BitSet FOLLOW_add_expr_in_start128 = new BitSet(new long[]{0x0000000000000000L}); - public static final BitSet FOLLOW_EOF_in_start130 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_mult_expr_in_add_expr142 = new BitSet(new long[]{0x0000000000000032L}); - public static final BitSet FOLLOW_PLUS_in_add_expr146 = new BitSet(new long[]{0x0000000000003A20L}); - public static final BitSet FOLLOW_mult_expr_in_add_expr149 = new BitSet(new long[]{0x0000000000000032L}); - public static final BitSet FOLLOW_MINUS_in_add_expr153 = new BitSet(new long[]{0x0000000000003A20L}); - public static final BitSet FOLLOW_mult_expr_in_add_expr156 = new BitSet(new long[]{0x0000000000000032L}); - public static final BitSet FOLLOW_neg_expr_in_mult_expr170 = new BitSet(new long[]{0x00000000000000C2L}); - public static final BitSet FOLLOW_MULT_in_mult_expr174 = new BitSet(new long[]{0x0000000000003A20L}); - public static final BitSet FOLLOW_neg_expr_in_mult_expr177 = new BitSet(new long[]{0x00000000000000C2L}); - public static final BitSet FOLLOW_DIV_in_mult_expr181 = new BitSet(new long[]{0x0000000000003A20L}); - public static final BitSet FOLLOW_neg_expr_in_mult_expr184 = new BitSet(new long[]{0x00000000000000C2L}); - public static final BitSet FOLLOW_MINUS_in_neg_expr205 = new BitSet(new long[]{0x0000000000003A20L}); - public static final BitSet FOLLOW_pow_expr_in_neg_expr208 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_pow_expr_in_neg_expr220 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_unary_expr_in_pow_expr238 = new BitSet(new long[]{0x0000000000000102L}); - public static final BitSet FOLLOW_POW_in_pow_expr242 = new BitSet(new long[]{0x0000000000003A20L}); - public static final BitSet FOLLOW_pow_expr_in_pow_expr245 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_primary_expr_in_unary_expr266 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_IDENTIFIER_in_unary_expr271 = new BitSet(new long[]{0x0000000000000200L}); - public static final BitSet FOLLOW_LPAR_in_unary_expr274 = new BitSet(new long[]{0x0000000000003A20L}); - public static final BitSet FOLLOW_add_expr_in_unary_expr277 = new BitSet(new long[]{0x0000000000000400L}); - public static final BitSet FOLLOW_RPAR_in_unary_expr279 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_DECIMAL_LITERAL_in_primary_expr291 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_FLOATING_POINT_LITERAL_in_primary_expr296 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_IDENTIFIER_in_primary_expr301 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_LPAR_in_primary_expr306 = new BitSet(new long[]{0x0000000000003A20L}); - public static final BitSet FOLLOW_add_expr_in_primary_expr309 = new BitSet(new long[]{0x0000000000000400L}); - public static final BitSet FOLLOW_RPAR_in_primary_expr311 = new BitSet(new long[]{0x0000000000000002L}); - -} \ No newline at end of file diff -Nru jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/parser/AlgebraicExpressionWalker.g jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/parser/AlgebraicExpressionWalker.g --- jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/parser/AlgebraicExpressionWalker.g 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/parser/AlgebraicExpressionWalker.g 1970-01-01 00:00:00.000000000 +0000 @@ -1,197 +0,0 @@ -/* - * Copyright 2008 Christian Stussak - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -tree grammar AlgebraicExpressionWalker; - -options { tokenVocab = AlgebraicExpression; ASTLabelType = CommonTree; } - -@header -{ -package de.mfo.jsurf.parser; - -import de.mfo.jsurf.algebra.*; -} - -@members -{ - public static PolynomialOperation createVariable( String name ) - { - try - { - return new PolynomialVariable( PolynomialVariable.Var.valueOf( name ) ); - } - catch( Exception e ) - { - return new DoubleVariable( name ); - } - } - - public static int createInteger( String text ) - { - try - { - return Integer.parseInt( text ); - } - catch( NumberFormatException nfe ) - { - return 0; - } - } - - public static double createDouble( String text ) - { - try - { - return Double.parseDouble( text ); - } - catch( NumberFormatException nfe ) - { - return Double.NaN; - } - } -} - -start returns [ PolynomialOperation op ] - : e = expr { $op = $e.op; } - ; - -expr returns [ PolynomialOperation op, Integer decimal ] - : ^( PLUS e1 = expr e2 = expr ) - { - try - { - $op = new DoubleBinaryOperation( DoubleBinaryOperation.Op.add, ( DoubleOperation ) $e1.op, ( DoubleOperation ) $e2.op ); - } - catch( ClassCastException cce ) - { - $op = new PolynomialAddition( $e1.op, $e2.op ); - } - } - | ^( MINUS e1 = expr ( e2 = expr )? ) - { - if( e2 != null ) - { - // subtraction - try - { - $op = new DoubleBinaryOperation( DoubleBinaryOperation.Op.sub, ( DoubleOperation ) $e1.op, ( DoubleOperation ) $e2.op ); - } - catch( ClassCastException cce ) - { - $op = new PolynomialSubtraction( $e1.op, $e2.op ); - } - } - else - { - try - { - $op = new DoubleUnaryOperation( DoubleUnaryOperation.Op.neg, ( DoubleOperation ) $e1.op ); - } - catch( ClassCastException cce ) - { - $op = new PolynomialNegation( $e1.op ); - } - } - } - | ^( MULT e1 = expr e2 = expr ) - { - try - { - $op = new DoubleBinaryOperation( DoubleBinaryOperation.Op.mult, ( DoubleOperation ) $e1.op, ( DoubleOperation ) $e2.op ); - } - catch( ClassCastException cce ) - { - $op = new PolynomialMultiplication( $e1.op, $e2.op ); - } - } - | ^( DIV e1 = expr e2 = expr ) - { - try - { - $op = new DoubleBinaryOperation( DoubleBinaryOperation.Op.div, ( DoubleOperation ) $e1.op, ( DoubleOperation ) $e2.op ); - } - catch( ClassCastException cce1 ) - { - try - { - $op = new PolynomialDoubleDivision( $e1.op, ( DoubleOperation ) $e2.op ); - } - catch( ClassCastException cce2 ) - { - throw new RecognitionException(); - } - } - } - | ^( POW e1 = expr e2 = expr ) - { - try - { - $op = new DoubleBinaryOperation( DoubleBinaryOperation.Op.pow, ( DoubleOperation ) $e1.op, ( DoubleOperation ) $e2.op ); - } - catch( ClassCastException cce ) - { - if( $e2.decimal == null ) - { - throw new RecognitionException(); - } - else - { - $op = new PolynomialPower( $e1.op, $e2.decimal ); - } - } - } - | ^( id = IDENTIFIER e1 = expr ( e2 = expr )? ) - { - if( e2 != null ) - { - try - { - $op = new DoubleBinaryOperation( DoubleBinaryOperation.Op.valueOf( $id.text ), ( DoubleOperation ) $e1.op, ( DoubleOperation ) $e2.op ); - } - catch( ClassCastException cce ) - { - throw new RecognitionException(); - } - catch( IllegalArgumentException iae ) - { - throw new RecognitionException(); - } - } - else - { - try - { - $op = new DoubleUnaryOperation( DoubleUnaryOperation.Op.valueOf( $id.text ), ( DoubleOperation ) $e1.op ); - } - catch( ClassCastException cce ) - { - throw new RecognitionException(); - } - catch( IllegalArgumentException iae ) - { - throw new RecognitionException(); - } - } - - } - | pe = primary_expr { $op = $pe.op; $decimal = pe.decimal; } - ; - -primary_expr returns [ PolynomialOperation op, Integer decimal ] - : i = DECIMAL_LITERAL { $op = new DoubleValue( createDouble( $i.text ) ); $decimal = Integer.valueOf( createInteger( $i.text ) ); } - | f = FLOATING_POINT_LITERAL { $op = new DoubleValue( createDouble( $f.text ) ); } - | id = IDENTIFIER { $op = createVariable( $id.text ); } - ; diff -Nru jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/parser/AlgebraicExpressionWalker.java jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/parser/AlgebraicExpressionWalker.java --- jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/parser/AlgebraicExpressionWalker.java 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/parser/AlgebraicExpressionWalker.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,605 +0,0 @@ -// $ANTLR 3.3 Nov 30, 2010 12:50:56 AlgebraicExpressionWalker.g 2011-06-20 15:15:19 - -package de.mfo.jsurf.parser; - -import de.mfo.jsurf.algebra.*; - - -import org.antlr.runtime.*; -import org.antlr.runtime.tree.*;import java.util.Stack; -import java.util.List; -import java.util.ArrayList; - -public class AlgebraicExpressionWalker extends TreeParser { - public static final String[] tokenNames = new String[] { - "", "", "", "", "PLUS", "MINUS", "MULT", "DIV", "POW", "LPAR", "RPAR", "IDENTIFIER", "DECIMAL_LITERAL", "FLOATING_POINT_LITERAL", "DIGIT", "EXPONENT", "LETTER", "WHITESPACE" - }; - public static final int EOF=-1; - public static final int PLUS=4; - public static final int MINUS=5; - public static final int MULT=6; - public static final int DIV=7; - public static final int POW=8; - public static final int LPAR=9; - public static final int RPAR=10; - public static final int IDENTIFIER=11; - public static final int DECIMAL_LITERAL=12; - public static final int FLOATING_POINT_LITERAL=13; - public static final int DIGIT=14; - public static final int EXPONENT=15; - public static final int LETTER=16; - public static final int WHITESPACE=17; - - // delegates - // delegators - - - public AlgebraicExpressionWalker(TreeNodeStream input) { - this(input, new RecognizerSharedState()); - } - public AlgebraicExpressionWalker(TreeNodeStream input, RecognizerSharedState state) { - super(input, state); - - } - - - public String[] getTokenNames() { return AlgebraicExpressionWalker.tokenNames; } - public String getGrammarFileName() { return "AlgebraicExpressionWalker.g"; } - - - public static PolynomialOperation createVariable( String name ) - { - try - { - return new PolynomialVariable( PolynomialVariable.Var.valueOf( name ) ); - } - catch( Exception e ) - { - return new DoubleVariable( name ); - } - } - - public static int createInteger( String text ) - { - try - { - return Integer.parseInt( text ); - } - catch( NumberFormatException nfe ) - { - return 0; - } - } - - public static double createDouble( String text ) - { - try - { - return java.lang.Double.parseDouble( text ); - } - catch( NumberFormatException nfe ) - { - return java.lang.Double.NaN; - } - } - - - - // $ANTLR start "start" - // AlgebraicExpressionWalker.g:51:1: start returns [ PolynomialOperation op ] : e= expr ; - public final PolynomialOperation start() throws RecognitionException { - PolynomialOperation op = null; - - AlgebraicExpressionWalker.expr_return e = null; - - - try { - // AlgebraicExpressionWalker.g:52:5: (e= expr ) - // AlgebraicExpressionWalker.g:52:7: e= expr - { - pushFollow(FOLLOW_expr_in_start55); - e=expr(); - - state._fsp--; - - op = (e!=null?e.op:null); - - } - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - } - return op; - } - // $ANTLR end "start" - - public static class expr_return extends TreeRuleReturnScope { - public PolynomialOperation op; - public Integer decimal; - }; - - // $ANTLR start "expr" - // AlgebraicExpressionWalker.g:55:1: expr returns [ PolynomialOperation op, Integer decimal ] : ( ^( PLUS e1= expr e2= expr ) | ^( MINUS e1= expr (e2= expr )? ) | ^( MULT e1= expr e2= expr ) | ^( DIV e1= expr e2= expr ) | ^( POW e1= expr e2= expr ) | ^(id= IDENTIFIER e1= expr (e2= expr )? ) | pe= primary_expr ); - public final AlgebraicExpressionWalker.expr_return expr() throws RecognitionException { - AlgebraicExpressionWalker.expr_return retval = new AlgebraicExpressionWalker.expr_return(); - retval.start = input.LT(1); - - CommonTree id=null; - AlgebraicExpressionWalker.expr_return e1 = null; - - AlgebraicExpressionWalker.expr_return e2 = null; - - AlgebraicExpressionWalker.primary_expr_return pe = null; - - - try { - // AlgebraicExpressionWalker.g:56:2: ( ^( PLUS e1= expr e2= expr ) | ^( MINUS e1= expr (e2= expr )? ) | ^( MULT e1= expr e2= expr ) | ^( DIV e1= expr e2= expr ) | ^( POW e1= expr e2= expr ) | ^(id= IDENTIFIER e1= expr (e2= expr )? ) | pe= primary_expr ) - int alt3=7; - switch ( input.LA(1) ) { - case PLUS: - { - alt3=1; - } - break; - case MINUS: - { - alt3=2; - } - break; - case MULT: - { - alt3=3; - } - break; - case DIV: - { - alt3=4; - } - break; - case POW: - { - alt3=5; - } - break; - case IDENTIFIER: - { - int LA3_6 = input.LA(2); - - if ( (LA3_6==DOWN) ) { - alt3=6; - } - else if ( (LA3_6==EOF||(LA3_6>=UP && LA3_6<=POW)||(LA3_6>=IDENTIFIER && LA3_6<=FLOATING_POINT_LITERAL)) ) { - alt3=7; - } - else { - NoViableAltException nvae = - new NoViableAltException("", 3, 6, input); - - throw nvae; - } - } - break; - case DECIMAL_LITERAL: - case FLOATING_POINT_LITERAL: - { - alt3=7; - } - break; - default: - NoViableAltException nvae = - new NoViableAltException("", 3, 0, input); - - throw nvae; - } - - switch (alt3) { - case 1 : - // AlgebraicExpressionWalker.g:56:4: ^( PLUS e1= expr e2= expr ) - { - match(input,PLUS,FOLLOW_PLUS_in_expr77); - - match(input, Token.DOWN, null); - pushFollow(FOLLOW_expr_in_expr83); - e1=expr(); - - state._fsp--; - - pushFollow(FOLLOW_expr_in_expr89); - e2=expr(); - - state._fsp--; - - - match(input, Token.UP, null); - - try - { - retval.op = new DoubleBinaryOperation( DoubleBinaryOperation.Op.add, ( DoubleOperation ) (e1!=null?e1.op:null), ( DoubleOperation ) (e2!=null?e2.op:null) ); - } - catch( ClassCastException cce ) - { - retval.op = new PolynomialAddition( (e1!=null?e1.op:null), (e2!=null?e2.op:null) ); - } - - - } - break; - case 2 : - // AlgebraicExpressionWalker.g:67:11: ^( MINUS e1= expr (e2= expr )? ) - { - match(input,MINUS,FOLLOW_MINUS_in_expr119); - - match(input, Token.DOWN, null); - pushFollow(FOLLOW_expr_in_expr125); - e1=expr(); - - state._fsp--; - - // AlgebraicExpressionWalker.g:67:30: (e2= expr )? - int alt1=2; - int LA1_0 = input.LA(1); - - if ( ((LA1_0>=PLUS && LA1_0<=POW)||(LA1_0>=IDENTIFIER && LA1_0<=FLOATING_POINT_LITERAL)) ) { - alt1=1; - } - switch (alt1) { - case 1 : - // AlgebraicExpressionWalker.g:67:32: e2= expr - { - pushFollow(FOLLOW_expr_in_expr133); - e2=expr(); - - state._fsp--; - - - } - break; - - } - - - match(input, Token.UP, null); - - if( e2 != null ) - { - // subtraction - try - { - retval.op = new DoubleBinaryOperation( DoubleBinaryOperation.Op.sub, ( DoubleOperation ) (e1!=null?e1.op:null), ( DoubleOperation ) (e2!=null?e2.op:null) ); - } - catch( ClassCastException cce ) - { - retval.op = new PolynomialSubtraction( (e1!=null?e1.op:null), (e2!=null?e2.op:null) ); - } - } - else - { - try - { - retval.op = new DoubleUnaryOperation( DoubleUnaryOperation.Op.neg, ( DoubleOperation ) (e1!=null?e1.op:null) ); - } - catch( ClassCastException cce ) - { - retval.op = new PolynomialNegation( (e1!=null?e1.op:null) ); - } - } - - - } - break; - case 3 : - // AlgebraicExpressionWalker.g:93:11: ^( MULT e1= expr e2= expr ) - { - match(input,MULT,FOLLOW_MULT_in_expr167); - - match(input, Token.DOWN, null); - pushFollow(FOLLOW_expr_in_expr173); - e1=expr(); - - state._fsp--; - - pushFollow(FOLLOW_expr_in_expr179); - e2=expr(); - - state._fsp--; - - - match(input, Token.UP, null); - - try - { - retval.op = new DoubleBinaryOperation( DoubleBinaryOperation.Op.mult, ( DoubleOperation ) (e1!=null?e1.op:null), ( DoubleOperation ) (e2!=null?e2.op:null) ); - } - catch( ClassCastException cce ) - { - retval.op = new PolynomialMultiplication( (e1!=null?e1.op:null), (e2!=null?e2.op:null) ); - } - - - } - break; - case 4 : - // AlgebraicExpressionWalker.g:104:11: ^( DIV e1= expr e2= expr ) - { - match(input,DIV,FOLLOW_DIV_in_expr209); - - match(input, Token.DOWN, null); - pushFollow(FOLLOW_expr_in_expr215); - e1=expr(); - - state._fsp--; - - pushFollow(FOLLOW_expr_in_expr221); - e2=expr(); - - state._fsp--; - - - match(input, Token.UP, null); - - try - { - retval.op = new DoubleBinaryOperation( DoubleBinaryOperation.Op.div, ( DoubleOperation ) (e1!=null?e1.op:null), ( DoubleOperation ) (e2!=null?e2.op:null) ); - } - catch( ClassCastException cce1 ) - { - try - { - retval.op = new PolynomialDoubleDivision( (e1!=null?e1.op:null), ( DoubleOperation ) (e2!=null?e2.op:null) ); - } - catch( ClassCastException cce2 ) - { - throw new RecognitionException(); - } - } - - - } - break; - case 5 : - // AlgebraicExpressionWalker.g:122:11: ^( POW e1= expr e2= expr ) - { - match(input,POW,FOLLOW_POW_in_expr251); - - match(input, Token.DOWN, null); - pushFollow(FOLLOW_expr_in_expr257); - e1=expr(); - - state._fsp--; - - pushFollow(FOLLOW_expr_in_expr263); - e2=expr(); - - state._fsp--; - - - match(input, Token.UP, null); - - try - { - retval.op = new DoubleBinaryOperation( DoubleBinaryOperation.Op.pow, ( DoubleOperation ) (e1!=null?e1.op:null), ( DoubleOperation ) (e2!=null?e2.op:null) ); - } - catch( ClassCastException cce ) - { - if( (e2!=null?e2.decimal:null) == null ) - { - throw new RecognitionException(); - } - else - { - retval.op = new PolynomialPower( (e1!=null?e1.op:null), (e2!=null?e2.decimal:null) ); - } - } - - - } - break; - case 6 : - // AlgebraicExpressionWalker.g:140:11: ^(id= IDENTIFIER e1= expr (e2= expr )? ) - { - id=(CommonTree)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_expr297); - - match(input, Token.DOWN, null); - pushFollow(FOLLOW_expr_in_expr303); - e1=expr(); - - state._fsp--; - - // AlgebraicExpressionWalker.g:140:40: (e2= expr )? - int alt2=2; - int LA2_0 = input.LA(1); - - if ( ((LA2_0>=PLUS && LA2_0<=POW)||(LA2_0>=IDENTIFIER && LA2_0<=FLOATING_POINT_LITERAL)) ) { - alt2=1; - } - switch (alt2) { - case 1 : - // AlgebraicExpressionWalker.g:140:42: e2= expr - { - pushFollow(FOLLOW_expr_in_expr311); - e2=expr(); - - state._fsp--; - - - } - break; - - } - - - match(input, Token.UP, null); - - if( e2 != null ) - { - try - { - retval.op = new DoubleBinaryOperation( DoubleBinaryOperation.Op.valueOf( (id!=null?id.getText():null) ), ( DoubleOperation ) (e1!=null?e1.op:null), ( DoubleOperation ) (e2!=null?e2.op:null) ); - } - catch( ClassCastException cce ) - { - throw new RecognitionException(); - } - catch( IllegalArgumentException iae ) - { - throw new RecognitionException(); - } - } - else - { - try - { - retval.op = new DoubleUnaryOperation( DoubleUnaryOperation.Op.valueOf( (id!=null?id.getText():null) ), ( DoubleOperation ) (e1!=null?e1.op:null) ); - } - catch( ClassCastException cce ) - { - throw new RecognitionException(); - } - catch( IllegalArgumentException iae ) - { - throw new RecognitionException(); - } - } - - - - } - break; - case 7 : - // AlgebraicExpressionWalker.g:174:11: pe= primary_expr - { - pushFollow(FOLLOW_primary_expr_in_expr346); - pe=primary_expr(); - - state._fsp--; - - retval.op = (pe!=null?pe.op:null); retval.decimal = pe.decimal; - - } - break; - - } - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - } - return retval; - } - // $ANTLR end "expr" - - public static class primary_expr_return extends TreeRuleReturnScope { - public PolynomialOperation op; - public Integer decimal; - }; - - // $ANTLR start "primary_expr" - // AlgebraicExpressionWalker.g:177:1: primary_expr returns [ PolynomialOperation op, Integer decimal ] : (i= DECIMAL_LITERAL | f= FLOATING_POINT_LITERAL | id= IDENTIFIER ); - public final AlgebraicExpressionWalker.primary_expr_return primary_expr() throws RecognitionException { - AlgebraicExpressionWalker.primary_expr_return retval = new AlgebraicExpressionWalker.primary_expr_return(); - retval.start = input.LT(1); - - CommonTree i=null; - CommonTree f=null; - CommonTree id=null; - - try { - // AlgebraicExpressionWalker.g:178:2: (i= DECIMAL_LITERAL | f= FLOATING_POINT_LITERAL | id= IDENTIFIER ) - int alt4=3; - switch ( input.LA(1) ) { - case DECIMAL_LITERAL: - { - alt4=1; - } - break; - case FLOATING_POINT_LITERAL: - { - alt4=2; - } - break; - case IDENTIFIER: - { - alt4=3; - } - break; - default: - NoViableAltException nvae = - new NoViableAltException("", 4, 0, input); - - throw nvae; - } - - switch (alt4) { - case 1 : - // AlgebraicExpressionWalker.g:178:4: i= DECIMAL_LITERAL - { - i=(CommonTree)match(input,DECIMAL_LITERAL,FOLLOW_DECIMAL_LITERAL_in_primary_expr367); - retval.op = new DoubleValue( createDouble( (i!=null?i.getText():null) ) ); retval.decimal = Integer.valueOf( createInteger( (i!=null?i.getText():null) ) ); - - } - break; - case 2 : - // AlgebraicExpressionWalker.g:179:4: f= FLOATING_POINT_LITERAL - { - f=(CommonTree)match(input,FLOATING_POINT_LITERAL,FOLLOW_FLOATING_POINT_LITERAL_in_primary_expr378); - retval.op = new DoubleValue( createDouble( (f!=null?f.getText():null) ) ); - - } - break; - case 3 : - // AlgebraicExpressionWalker.g:180:4: id= IDENTIFIER - { - id=(CommonTree)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_primary_expr389); - retval.op = createVariable( (id!=null?id.getText():null) ); - - } - break; - - } - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - } - return retval; - } - // $ANTLR end "primary_expr" - - // Delegated rules - - - - - public static final BitSet FOLLOW_expr_in_start55 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_PLUS_in_expr77 = new BitSet(new long[]{0x0000000000000004L}); - public static final BitSet FOLLOW_expr_in_expr83 = new BitSet(new long[]{0x00000000000039F0L}); - public static final BitSet FOLLOW_expr_in_expr89 = new BitSet(new long[]{0x0000000000000008L}); - public static final BitSet FOLLOW_MINUS_in_expr119 = new BitSet(new long[]{0x0000000000000004L}); - public static final BitSet FOLLOW_expr_in_expr125 = new BitSet(new long[]{0x00000000000039F8L}); - public static final BitSet FOLLOW_expr_in_expr133 = new BitSet(new long[]{0x0000000000000008L}); - public static final BitSet FOLLOW_MULT_in_expr167 = new BitSet(new long[]{0x0000000000000004L}); - public static final BitSet FOLLOW_expr_in_expr173 = new BitSet(new long[]{0x00000000000039F0L}); - public static final BitSet FOLLOW_expr_in_expr179 = new BitSet(new long[]{0x0000000000000008L}); - public static final BitSet FOLLOW_DIV_in_expr209 = new BitSet(new long[]{0x0000000000000004L}); - public static final BitSet FOLLOW_expr_in_expr215 = new BitSet(new long[]{0x00000000000039F0L}); - public static final BitSet FOLLOW_expr_in_expr221 = new BitSet(new long[]{0x0000000000000008L}); - public static final BitSet FOLLOW_POW_in_expr251 = new BitSet(new long[]{0x0000000000000004L}); - public static final BitSet FOLLOW_expr_in_expr257 = new BitSet(new long[]{0x00000000000039F0L}); - public static final BitSet FOLLOW_expr_in_expr263 = new BitSet(new long[]{0x0000000000000008L}); - public static final BitSet FOLLOW_IDENTIFIER_in_expr297 = new BitSet(new long[]{0x0000000000000004L}); - public static final BitSet FOLLOW_expr_in_expr303 = new BitSet(new long[]{0x00000000000039F8L}); - public static final BitSet FOLLOW_expr_in_expr311 = new BitSet(new long[]{0x0000000000000008L}); - public static final BitSet FOLLOW_primary_expr_in_expr346 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_DECIMAL_LITERAL_in_primary_expr367 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_FLOATING_POINT_LITERAL_in_primary_expr378 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_IDENTIFIER_in_primary_expr389 = new BitSet(new long[]{0x0000000000000002L}); - -} \ No newline at end of file diff -Nru jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/util/RotateSphericalDragger.java jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/util/RotateSphericalDragger.java --- jsurf-alggeo-0.3.0+ds/src/main/java/de/mfo/jsurf/util/RotateSphericalDragger.java 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/main/java/de/mfo/jsurf/util/RotateSphericalDragger.java 2018-06-05 16:36:49.000000000 +0000 @@ -25,31 +25,37 @@ Matrix4d rotation; double xSpeed; double ySpeed; - + boolean isDragging; + public RotateSphericalDragger() { this( 1, 1 ); } - + public RotateSphericalDragger( double xSpeed, double ySpeed ) { + isDragging = false; lastLocation = new Point(); rotation = new Matrix4d(); rotation.setIdentity(); this.xSpeed = xSpeed; this.ySpeed = ySpeed; } - + public void startDrag( Point p ) { + isDragging = true; lastLocation = new Point( p ); } - + public void dragTo( Point p ) { + if( !isDragging ) + return; + double xAngle = ( lastLocation.x - p.x ) * xSpeed; double yAngle = ( lastLocation.y - p.y ) * ySpeed; - + Matrix4d rotX = new Matrix4d(); rotX.setIdentity(); rotX.rotX( ( Math.PI / 180.0 ) * yAngle ); @@ -57,38 +63,43 @@ Matrix4d rotY = new Matrix4d(); rotY.setIdentity(); rotY.rotY( ( Math.PI / 180.0 ) * xAngle ); - + rotation.mul( rotX ); rotation.mul( rotY ); - + lastLocation = new Point( p ); } - + + public void stopDrag() + { + isDragging = false; + } + public Matrix4d getRotation() { return new Matrix4d( rotation ); } - + public void setRotation( Matrix4d m ) { rotation = new Matrix4d( m ); } - + public double getXSpeed() { return xSpeed; } - + public void setXSpeed( double xSpeed ) { this.xSpeed = xSpeed; } - + public double getYSpeed() { return ySpeed; } - + public void setYSpeed( double ySpeed ) { this.ySpeed = ySpeed; diff -Nru jsurf-alggeo-0.3.0+ds/src/test/java/de/mfo/jsurf/test/TestJSurf.java jsurf-alggeo-0.4.1+ds/src/test/java/de/mfo/jsurf/test/TestJSurf.java --- jsurf-alggeo-0.3.0+ds/src/test/java/de/mfo/jsurf/test/TestJSurf.java 2015-11-17 14:41:28.000000000 +0000 +++ jsurf-alggeo-0.4.1+ds/src/test/java/de/mfo/jsurf/test/TestJSurf.java 2018-06-05 16:36:49.000000000 +0000 @@ -5,6 +5,7 @@ import de.mfo.jsurf.rendering.cpu.CPUAlgebraicSurfaceRenderer; import de.mfo.jsurf.rendering.RenderingInterruptedException; import de.mfo.jsurf.algebra.*; +import de.mfo.jsurf.parser.*; import de.mfo.jsurf.util.FileFormat; import java.util.Properties; import javax.swing.SwingWorker; @@ -15,7 +16,7 @@ public void stopDrawingShouldInterruptRendering() throws java.io.IOException, Exception { - final CPUAlgebraicSurfaceRenderer asr = new CPUAlgebraicSurfaceRenderer(); + final CPUAlgebraicSurfaceRenderer asr = new CPUAlgebraicSurfaceRenderer(); Properties jsurf = new Properties(); jsurf.load( this.getClass().getResourceAsStream( "tutorial_wuerfel.jsurf" ) ); @@ -31,18 +32,18 @@ try { asr.draw( new int[ 3 * width * height ], width, height ); } - catch( RenderingInterruptedException rie ) + catch( RenderingInterruptedException rie ) { System.out.println( "Rendering interrupted" ); } - return null; + return null; } } BackgroundRenderer br = new BackgroundRenderer(); System.out.println( "Starting background rendering" ); br.execute(); - + long t = System.currentTimeMillis(); Thread.sleep( 100 ); @@ -63,14 +64,47 @@ XYZPolynomial.X.add( XYZPolynomial.X ); Assert.assertTrue( "XYZPolynomial.add changes values of its parameters", X.equals( XYZPolynomial.X ) ); } - + @Test public void testDivisionInParser() { PolynomialOperation div = new PolynomialDoubleDivision( new PolynomialVariable( PolynomialVariable.Var.x ), new DoubleValue( 2.0 ) ); PolynomialOperation mult = new PolynomialMultiplication( new PolynomialVariable( PolynomialVariable.Var.x ), new DoubleValue( 0.5 ) ); XYZPolynomial expanded_div = div.accept( new Expand(), ( Void ) null ); - XYZPolynomial expanded_mult = mult.accept( new Expand(), ( Void ) null ); + XYZPolynomial expanded_mult = mult.accept( new Expand(), ( Void ) null ); Assert.assertTrue( "x/2.0 and x*0.5 should both expand to 0.5x, but x/2.0 expands to " + expanded_div + " and x*0.5 expands to " + expanded_mult, expanded_div.equals( expanded_mult ) ); } + + @Test + public void testIfParenthesesAreCorrectlyRecognized() throws Exception + { + String input = "(x)"; + PolynomialOperation op = AlgebraicExpressionParser.parse( input ); + Assert.assertNotNull( "op must not be null", op ); + Assert.assertTrue( + "Tree node should have parentheses", + op.hasParentheses() + ); + } + + @Test + public void testParserInputAndToStringVisitorOutputShouldMatch() throws Exception + { + String[] inputs = { + "x-(x)", + "sin(1)", + "x+y+z+x*(y+x)", + "a*0.99*(64*(0.5*z)^7-112*(0.5*z)^5+56*(0.5*z)^3-7*(0.5*z)-1)+(0.7818314825-0.3765101982*y-0.7818314825*x)*(0.7818314824-0.8460107361*y-0.1930964297*x)*(0.7818314825-0.6784479340*y+0.5410441731*x)*(0.7818314825+0.8677674789*x)*(0.7818314824+0.6784479339*y+0.541044172*x)*(0.7818314824+0.8460107358*y-0.193096429*x)*(0.7818314821+0.3765101990*y-0.781831483*x)" + }; + + for( String input : inputs ) + { + String output = AlgebraicExpressionParser.parse( input ).accept( new ToStringVisitor( true ), ( Void ) null ); + Assert.assertEquals( + "Output of ToStringVisitor should be identical to input", + input, + output + ); + } + } }