All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mariuszgromada.math.mxparser.syntaxchecker.SyntaxChecker.jj Maven / Gradle / Ivy

Go to download

mXparser is a super easy, rich, fast and highly flexible math expression parser library (parser and evaluator of mathematical expressions / formulas provided as plain text / string). Software delivers easy to use API for JAVA, Android and C# .NET/MONO (Common Language Specification compliant: F#, Visual Basic, C++/CLI). *** If you find the software useful donation is something you might consider: https://mathparser.org/donate/ *** Scalar Scientific Calculator, Charts and Scripts, Scalar Lite: https://play.google.com/store/apps/details?id=org.mathparser.scalar.lite *** Scalar Pro: https://play.google.com/store/apps/details?id=org.mathparser.scalar.pro *** ScalarMath.org: https://scalarmath.org/ *** MathSpace.pl: https://mathspace.pl/ ***

There is a newer version: 6.1.0
Show newest version
/*
 * @(#)SyntaxChecker.jj        4.4.3    2022-05-28
 *
 * MathParser.org-mXparser DUAL LICENSE AGREEMENT as of date 2022-05-22
 * The most up-to-date license is available at the below link:
 * - https://mathparser.org/mxparser-license
 *
 * AUTHOR: Copyright 2010 - 2022 Mariusz Gromada - All rights reserved
 * PUBLISHER: INFIMA - https://payhip.com/infima
 *
 * SOFTWARE means source code and/or binary form and/or documentation.
 * PRODUCT: MathParser.org-mXparser SOFTWARE
 * LICENSE: DUAL LICENSE AGREEMENT
 *
 * BY INSTALLING, COPYING, OR OTHERWISE USING THE PRODUCT, YOU AGREE TO BE
 * BOUND BY ALL OF THE TERMS AND CONDITIONS OF THE DUAL LICENSE AGREEMENT.
 *
 * AUTHOR & PUBLISHER provide the PRODUCT under the DUAL LICENSE AGREEMENT
 * model designed to meet the needs of both non-commercial use as well as
 * commercial use.
 *
 * NON-COMMERCIAL USE means any use or activity where a fee is not charged
 * and the purpose is not the sale of a good or service, and the use or
 * activity is not intended to produce a profit. NON-COMMERCIAL USE examples:
 *
 * 1. Free Open-Source Software ("FOSS").
 * 2. Non-commercial use in research, scholarly and education.
 *
 * COMMERCIAL USE means any use or activity where a fee is charged or the
 * purpose is the sale of a good or service, or the use or activity is
 * intended to produce a profit. COMMERCIAL USE examples:
 *
 * 1. OEMs (Original Equipment Manufacturers).
 * 2. ISVs (Independent Software Vendors).
 * 3. VARs (Value Added Resellers).
 * 4. Other distributors that combine and distribute commercially licensed
 *    software.
 *
 * IN CASE YOU WANT TO USE THE PRODUCT COMMERCIALLY, YOU MUST PURCHASE THE
 * APPROPRIATE LICENSE FROM "INFIMA" ONLINE STORE, STORE ADDRESS:
 *
 * 1. https://mathparser.org/order-commercial-license
 * 2. https://payhip.com/infima
 *
 * NON-COMMERCIAL LICENSE
 *
 * Redistribution and use of the PRODUCT in source and/or binary forms,
 * with or without modification, are permitted provided that the following
 * conditions are met:
 *
 * 1. Redistributions of source code must retain unmodified content of the
 *    entire MathParser.org-mXparser DUAL LICENSE AGREEMENT, including
 *    definition of NON-COMMERCIAL USE, definition of COMMERCIAL USE,
 *    NON-COMMERCIAL LICENSE conditions, COMMERCIAL LICENSE conditions, and
 *    the following DISCLAIMER.
 * 2. Redistributions in binary form must reproduce the entire content of
 *    MathParser.org-mXparser DUAL LICENSE AGREEMENT in the documentation
 *    and/or other materials provided with the distribution, including
 *    definition of NON-COMMERCIAL USE, definition of COMMERCIAL USE,
 *    NON-COMMERCIAL LICENSE conditions, COMMERCIAL LICENSE conditions, and
 *    the following DISCLAIMER.
 *
 * COMMERCIAL LICENSE
 *
 *  1. Before purchasing a commercial license, AUTHOR & PUBLISHER allow you
 *     to download, install and use up to three copies of the PRODUCT to
 *     perform integration tests, confirm the quality of the PRODUCT and
 *     its suitability. The testing period should be limited to fourteen
 *     days. Tests should be performed under the conditions of test
 *     environments. The purpose of the tests must not be to generate profit.
 *  2. Provided that you purchased a license from "INFIMA" online store
 *     (store address: https://mathparser.org/order-commercial-license or
 *     https://payhip.com/infima), and you comply with all below terms and
 *     conditions, and you have acknowledged and understood the following
 *     DISCLAIMER, AUTHOR & PUBLISHER grant you a nonexclusive license
 *     including the following rights:
 *  3. The license has been granted only to you, i.e., the person or entity
 *     that made the purchase, who is identified and confirmed by the data
 *     provided during the purchase.
 *  4. In case you purchased a license in the "ONE-TIME PURCHASE" model,
 *     the license has been granted only for the PRODUCT version specified
 *     in the purchase. The upgrade policy gives you additional rights and
 *     is described in the dedicated section below.
 *  5. In case you purchased a license in the "SUBSCRIPTION" model, you can
 *     install and use any version of the PRODUCT, but only during the
 *     subscription validity period.
 *  6. In case you purchased a "SINGLE LICENSE" you can install and use the
 *     PRODUCT from one workstation.
 *  7. Additional copies of the PRODUCT can be installed and used from more
 *     than one workstation; however, this number is limited to the number
 *     of workstations purchased as per order.
 *  8. In case you purchased a "SITE LICENSE ", the PRODUCT can be installed
 *     and used from all workstations located at your premises.
 *  9. You may incorporate the unmodified PRODUCT into your own products
 *     and software.
 * 10. If you purchased a license with the "SOURCE CODE" option, you may
 *     modify the PRODUCT's source code and incorporate the modified source
 *     code into your own products and/or software.
 * 11. Provided that the license validity period has not expired, you may
 *     distribute your product and/or software with the incorporated
 *     PRODUCT royalty-free.
 * 12. You may make copies of the PRODUCT for backup and archival purposes.
 * 13. AUTHOR & PUBLISHER reserve all rights not expressly granted to you
 *     in this agreement.
 *
 * ADDITIONAL CLARIFICATION ON WORKSTATION
 *
 * A workstation is a device, a remote device, or a virtual device, used by
 * you, your employees, or other entities to whom you have commissioned the
 * tasks. For example, the number of workstations may refer to the number
 * of software developers, engineers, architects, scientists, and other
 * professionals who use the PRODUCT on your behalf. The number of
 * workstations is not the number of copies of your end-product that you
 * distribute to your end-users.
 *
 * By purchasing the COMMERCIAL LICENSE, you only pay for the number of
 * workstations, while the number of copies of your final product
 * (delivered to your end-users) is not limited.
 *
 * UPGRADE POLICY
 *
 * The PRODUCT is versioned according to the following convention:
 *
 *    [MAJOR].[MINOR].[PATCH]
 *
 * 1. COMMERCIAL LICENSE holders can install and use the updated version
 *    for bug fixes free of charge, i.e. if you have purchased a license
 *    for the [MAJOR].[MINOR] version (e.g.: 5.0), you can freely install
 *    all the various releases specified in the [PATCH] version (e.g.: 5.0.2).
 *    The license terms remain unchanged after the update.
 * 2. COMMERCIAL LICENSE holders for [MAJOR].[MINOR] version (e.g.: 5.0)
 *    can install and use the updated version [MAJOR].[MINOR + 1] free of
 *    charge, i.e., plus one release in the [MINOR] range (e.g.: 5.1). The
 *    license terms remain unchanged after the update.
 * 3. COMMERCIAL LICENSE holders who wish to upgrade their version, but are
 *    not eligible for the free upgrade, can claim a discount when
 *    purchasing the upgrade. For this purpose, please contact us via e-mail.
 *
 * DISCLAIMER
 *
 * THIS PRODUCT IS PROVIDED BY AUTHOR & PUBLISHER "AS IS" AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL AUTHOR OR PUBLISHER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS PRODUCT, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE.
 *
 * THE VIEWS AND CONCLUSIONS CONTAINED IN THE PRODUCT AND DOCUMENTATION ARE
 * THOSE OF THE AUTHORS AND SHOULD NOT BE INTERPRETED AS REPRESENTING
 * OFFICIAL POLICIES, EITHER EXPRESSED OR IMPLIED, OF AUTHOR OR PUBLISHER.
 *
 * CONTACT
 *
 * - e-mail: [email protected]
 * - website: https://mathparser.org
 * - source code: https://github.com/mariuszgromada/MathParser.org-mXparser
 * - online store: https://mathparser.org/order-commercial-license
 * - online store: https://payhip.com/infima
 */

options {
	JDK_VERSION = "1.5";
	STATIC = false;
}

PARSER_BEGIN(SyntaxChecker)

package org.mariuszgromada.math.mxparser.syntaxchecker;

public final class SyntaxChecker {
	public final void checkSyntax() throws ParseException, TokenMgrError {
		start();
	}

}

PARSER_END(SyntaxChecker)

SKIP :
{
  " "
| "\t"
| "\n"
| "\r"
}

TOKEN : /* TOKENS */
{
	< #WHITESPACE:  ( " " | "\t" | "\n" | "\r" )												>
|	< #LETTER:		["_","a"-"z","A"-"Z"]														>
| 	< #DIGIT:		["0"-"9"]																	>
| 	< #DIGIT_B1:	"1"																			>
| 	< #DIGIT_B2:	["0","1"]																	>
| 	< #DIGIT_B3:	["0"-"2"]																	>
| 	< #DIGIT_B4:	["0"-"3"]																	>
| 	< #DIGIT_B5:	["0"-"4"]																	>
| 	< #DIGIT_B6:	["0"-"5"]																	>
| 	< #DIGIT_B7:	["0"-"6"]																	>
| 	< #DIGIT_B8:	["0"-"7"]																	>
| 	< #DIGIT_B9:	["0"-"8"]																	>
| 	< #DIGIT_B10:	["0"-"9"]																	>
| 	< #DIGIT_B11:	["0"-"9","a","A"]															>
| 	< #DIGIT_B12:	["0"-"9","a"-"b","A"-"B"]													>
| 	< #DIGIT_B13:	["0"-"9","a"-"c","A"-"C"]													>
| 	< #DIGIT_B14:	["0"-"9","a"-"d","A"-"D"]													>
| 	< #DIGIT_B15:	["0"-"9","a"-"e","A"-"E"]													>
| 	< #DIGIT_B16:	["0"-"9","a"-"f","A"-"F"]													>
| 	< #DIGIT_B17:	["0"-"9","a"-"g","A"-"G"]													>
| 	< #DIGIT_B18:	["0"-"9","a"-"h","A"-"H"]													>
| 	< #DIGIT_B19:	["0"-"9","a"-"i","A"-"I"]													>
| 	< #DIGIT_B20:	["0"-"9","a"-"j","A"-"J"]													>
| 	< #DIGIT_B21:	["0"-"9","a"-"k","A"-"K"]													>
| 	< #DIGIT_B22:	["0"-"9","a"-"l","A"-"L"]													>
| 	< #DIGIT_B23:	["0"-"9","a"-"m","A"-"M"]													>
| 	< #DIGIT_B24:	["0"-"9","a"-"n","A"-"N"]													>
| 	< #DIGIT_B25:	["0"-"9","a"-"o","A"-"O"]													>
| 	< #DIGIT_B26:	["0"-"9","a"-"p","A"-"P"]													>
| 	< #DIGIT_B27:	["0"-"9","a"-"q","A"-"Q"]													>
| 	< #DIGIT_B28:	["0"-"9","a"-"r","A"-"R"]													>
| 	< #DIGIT_B29:	["0"-"9","a"-"s","A"-"S"]													>
| 	< #DIGIT_B30:	["0"-"9","a"-"t","A"-"T"]													>
| 	< #DIGIT_B31:	["0"-"9","a"-"u","A"-"U"]													>
| 	< #DIGIT_B32:	["0"-"9","a"-"v","A"-"V"]													>
| 	< #DIGIT_B33:	["0"-"9","a"-"w","A"-"W"]													>
| 	< #DIGIT_B34:	["0"-"9","a"-"x","A"-"X"]													>
| 	< #DIGIT_B35:	["0"-"9","a"-"y","A"-"Y"]													>
| 	< #DIGIT_B36:	["0"-"9","a"-"z","A"-"Z"]													>
| 	< #LETTERS:		()*															>
|  	< #INTEGER:		()*															>
| 	< LEFT_PAR:		"("																			>
| 	< RIGHT_PAR:	")"																			>
| 	< PLUS:			"+"																			>
| 	< MINUS:		"-"																			>
| 	< MULTIPLY:		"*"																			>
| 	< DIV:			"/"																			>
| 	< POWER:		"^"																			>
| 	< TETRATION:	"^^"																		>
| 	< MODULO:		"#"																			>
| 	< FACTORIAL:	"!"																			>
| 	< PERCENTAGE:	"%"																			>
| 	< COMMA:		","																			>
| 	< SEMICOLON:	";"																			>
| 	< EQ:			( "=" | "==" )																>
| 	< UNIT:			( "[%]" | "[%%]" )															>
| 	< NEQ:			( "<>" | "!=" | "~=" )														>
| 	< LT:			"<"																			>
| 	< LEQ:			"<="																		>
| 	< GT:			">"																			>
| 	< GEQ:			">="																		>
| 	< OR:			( "|" | "||" | "\\/" )														>
| 	< AND:			( "&" | "&&" | "/\\" )														>
| 	< NOT:			"~"																			>
| 	< BITNOT:   	"@~"																		>
| 	< IMP:			"-->"																		>
| 	< CIMP:			"<--"																		>
| 	< NIMP:			"-/>"																		>
| 	< CNIMP:		"
|   < NAND:																				>
|   < EQV:  		"<->"																		>
|   < NOR:																				>
|   < BITWISE:		( "@&" | "@^" | "@|" | "@<<" | "@>>" )										>
| 	< XOR:			"(+)"																		>
| 	< CHAR:			( "`"  | "@" | "#" | "$" | "." | "'" | ":" | ";" | "\\" | "/" | "?" )		>
}


/*
 * Tokens representing numbers
 */
TOKEN :
{
	< #DEC_FRACT:			(  )? "." 										>
|	< #DEC_FRACT_OR_INT:	(  |  )											>
|	< DECIMAL:				 ( ( "E" | "e" ) ( "+" | "-" )?  )?		>
|	< BASE1:				( "b1" | "B1" ) "." ()*									>
|	< BASE2:				( "b2" | "B2" ) "." ()*							>
|	< BASE3:				( "b3" | "B3" ) "." ()*							>
|	< BASE4:				( "b4" | "B4" ) "." ()*							>
|	< BASE5:				( "b5" | "B5" ) "." ()*							>
|	< BASE6:				( "b6" | "B6" ) "." ()*							>
|	< BASE7:				( "b7" | "B7" ) "." ()*							>
|	< BASE8:				( "b8" | "B8" ) "." ()*							>
|	< BASE9:				( "b9" | "B9" ) "." ()*							>
|	< BASE10:				( "b10" | "B10" ) "." ()*						>
|	< BASE11:				( "b11" | "B11" ) "." ()*						>
|	< BASE12:				( "b12" | "B12" ) "." ()*						>
|	< BASE13:				( "b13" | "B13" ) "." ()*						>
|	< BASE14:				( "b14" | "B14" ) "." ()*						>
|	< BASE15:				( "b15" | "B15" ) "." ()*						>
|	< BASE16:				( "b16" | "B16" ) "." ()*						>
|	< BASE17:				( "b17" | "B17" ) "." ()*						>
|	< BASE18:				( "b18" | "B18" ) "." ()*						>
|	< BASE19:				( "b19" | "B19" ) "." ()*						>
|	< BASE20:				( "b20" | "B20" ) "." ()*						>
|	< BASE21:				( "b21" | "B21" ) "." ()*						>
|	< BASE22:				( "b22" | "B22" ) "." ()*						>
|	< BASE23:				( "b23" | "B23" ) "." ()*						>
|	< BASE24:				( "b24" | "B24" ) "." ()*						>
|	< BASE25:				( "b25" | "B25" ) "." ()*						>
|	< BASE26:				( "b26" | "B26" ) "." ()*						>
|	< BASE27:				( "b27" | "B27" ) "." ()*						>
|	< BASE28:				( "b28" | "B28" ) "." ()*						>
|	< BASE29:				( "b29" | "B29" ) "." ()*						>
|	< BASE30:				( "b30" | "B30" ) "." ()*						>
|	< BASE31:				( "b31" | "B31" ) "." ()*						>
|	< BASE32:				( "b32" | "B32" ) "." ()*						>
|	< BASE33:				( "b33" | "B33" ) "." ()*						>
|	< BASE34:				( "b34" | "B34" ) "." ()*						>
|	< BASE35:				( "b35" | "B35" ) "." ()*						>
|	< BASE36:				( "b36" | "B36" ) "." ()*						>
|	< BINARY:				( "b" | "B" ) "." ()*							>
|	< OCTAL:				( "o" | "O" ) "." ()*							>
|	< HEXADECIMAL:			( "h" | "H" ) "." ()*							>
|	< FRACTION:				(  "_" )?  "_" 							>
}

/*
 * Token representing identifiers
 */
TOKEN :
{
	< IDENTIFIER:	 (  |  )*  										>
}

/*
 * Token representing functions with special names
 */
TOKEN : /* SPECIAL FUNCTION */
{
	< FUNCTION: "der+" | "der-"																	>
}

/*
 * Lexer logic - grammar
 */
void start():{}
{
	( expression() () |  )
}

/*
 * Grammar for expression
 */
void expression():{ } 
{
	binaryExpression()
}

/*
 * Grammar for binary operators
 */
void binaryExpression():{ } 
{
	unaryRigthExpression() (
										unaryRigthExpression()
							|			unaryRigthExpression()
							|		unaryRigthExpression()
							|	
unaryRigthExpression() | unaryRigthExpression() | unaryRigthExpression() | unaryRigthExpression() | unaryRigthExpression() | unaryRigthExpression() | unaryRigthExpression() | unaryRigthExpression() | unaryRigthExpression() | unaryRigthExpression() | unaryRigthExpression() | unaryRigthExpression() | unaryRigthExpression() | unaryRigthExpression() | unaryRigthExpression() | unaryRigthExpression() | unaryRigthExpression() | unaryRigthExpression() | unaryRigthExpression() | unaryRigthExpression() | unaryRigthExpression() )* } /* * Grammar for unary rigth operators */ void unaryRigthExpression():{} { unaryLeftExpression() ( | )? } /* * Grammar for unary left operators */ void unaryLeftExpression():{} { ( | )? itemExpression() } /* * Grammar for items */ void itemExpression():{} { ( | )? ( ( | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ) | ( identifier() | ) ( argumentList() )? | expression() ) } /* * Grammar for arguments list */ void argumentList():{} { ( expression() ( ( | ) expression() )* )? } /* * Grammar for identifiers */ void identifier():{} { ( | | "[" ( | ( | | | | |
| | | | | | | | | )* )+ "]" ) } /* * Unexpected and invalid tokens */ < * > TOKEN : { < INVALID_TOKEN: ( "+" ()* "+" | "-" ()* "-" | "+" ()* "-" | "-" ()* "+" ) > | < UNEXPECTED_CHAR: ~[] > }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy