├── .classpath ├── .gitignore ├── .project ├── CODE_OF_CONDUCT.md ├── LICENSE.txt ├── README.md ├── docs ├── Parsing Expressions by Recursive Descent-Dateien │ ├── exp_parsing-0.png │ ├── exp_parsing-1.png │ └── exp_parsing-2.png └── Parsing Expressions by Recursive Descent.html ├── examples ├── CORBA-IDL │ ├── Hello.idl │ ├── IDL.jj │ └── README ├── GUIParsing │ ├── ParserVersion │ │ ├── CalcGUI.java │ │ ├── CalcInput.jj │ │ ├── Main.java │ │ ├── ProducerConsumer.java │ │ ├── README │ │ └── TokenCollector.java │ ├── README │ └── TokenMgrVersion │ │ ├── CalcGUI.java │ │ ├── CalcInput.jj │ │ ├── CharCollector.java │ │ ├── Main.java │ │ ├── MyLexer.java │ │ └── README ├── Interpreter │ ├── ASTAddNode.java │ ├── ASTAndNode.java │ ├── ASTAssignment.java │ ├── ASTBitwiseAndNode.java │ ├── ASTBitwiseComplNode.java │ ├── ASTBitwiseOrNode.java │ ├── ASTBitwiseXorNode.java │ ├── ASTBlock.java │ ├── ASTCompilationUnit.java │ ├── ASTDivNode.java │ ├── ASTEQNode.java │ ├── ASTFalseNode.java │ ├── ASTGENode.java │ ├── ASTGTNode.java │ ├── ASTId.java │ ├── ASTIfStatement.java │ ├── ASTIntConstNode.java │ ├── ASTLENode.java │ ├── ASTLTNode.java │ ├── ASTModNode.java │ ├── ASTMulNode.java │ ├── ASTNENode.java │ ├── ASTNotNode.java │ ├── ASTOrNode.java │ ├── ASTReadStatement.java │ ├── ASTStatementExpression.java │ ├── ASTSubtractNode.java │ ├── ASTTrueNode.java │ ├── ASTVarDeclaration.java │ ├── ASTWhileStatement.java │ ├── ASTWriteStatement.java │ ├── MyNode.java │ ├── Node.java │ ├── README │ ├── SPL.java │ ├── SPL.jjt │ ├── fact.spl │ ├── odd.spl │ └── sqrt.spl ├── JJTreeExamples │ ├── cpp │ │ ├── ASTMyID.cc │ │ ├── ASTMyID.h │ │ ├── ASTMyOtherID.cc │ │ ├── ASTMyOtherID.h │ │ ├── EG4DumpVisitor.cc │ │ ├── EG4DumpVisitor.h │ │ ├── MyErrorHandler.cc │ │ ├── MyErrorHandler.h │ │ ├── README │ │ ├── build.xml │ │ ├── eg1.cc │ │ ├── eg1.jjt │ │ ├── eg2.cc │ │ ├── eg2.jjt │ │ ├── eg3.cc │ │ ├── eg3.jjt │ │ ├── eg4.cc │ │ └── eg4.jjt │ └── java │ │ ├── ASTMyID.java │ │ ├── ASTMyOtherID.java │ │ ├── Eg4DumpVisitor.java │ │ ├── README │ │ ├── build.xml │ │ ├── eg1.jjt │ │ ├── eg2.jjt │ │ ├── eg3.jjt │ │ └── eg4.jjt ├── JavaCCGrammar │ └── JavaCC.jj ├── JavaGrammars │ ├── 1.5 │ │ ├── Java1.5.jj │ │ ├── JavaGenerics.java │ │ ├── Main.java │ │ ├── MyToken.java │ │ ├── README │ │ ├── Test.java │ │ └── build.xml │ ├── Java1.0.2.jj │ ├── Java1.0.2LS.jj │ ├── Java1.1-cpp.jj │ ├── Java1.1.jj │ ├── Java1.1noLA.jj │ ├── OPTIMIZING │ ├── README │ ├── Test.java │ └── cpp │ │ ├── Java1.1.jjt │ │ ├── Makefile │ │ ├── allmain.cc │ │ ├── main.cc │ │ ├── myparser.h │ │ ├── mytm.h │ │ └── token_base.h ├── Lookahead │ ├── Example1.jj │ ├── Example10.jj │ ├── Example2.jj │ ├── Example3.jj │ ├── Example4.jj │ ├── Example5.jj │ ├── Example6.jj │ ├── Example7.jj │ ├── Example8.jj │ ├── Example9.jj │ └── README ├── MailProcessing │ ├── Digest.jj │ ├── Faq.jj │ ├── README │ └── sampleMailFile ├── Obfuscator │ ├── Globals.java │ ├── IdsFile.jj │ ├── Java1.1.jj │ ├── Main.java │ ├── MapFile.jj │ ├── Obfuscator.java │ ├── README │ ├── input │ │ ├── package1 │ │ │ └── Main.java │ │ └── package2 │ │ │ └── Incr.java │ ├── maps │ ├── nochangeids │ └── useids ├── README ├── SimpleExamples │ ├── IdList.jj │ ├── NL_Xlator.jj │ ├── README │ ├── Simple1.jj │ ├── Simple2.jj │ └── Simple3.jj ├── Transformer │ ├── ASTCompilationUnit.java │ ├── ASTSpecialBlock.java │ ├── README │ ├── SimpleNode.java │ ├── ToyJava.jjt │ └── divide.toy └── VTransformer │ ├── AddAcceptVisitor.java │ ├── Java1.1.jjt │ ├── Main.java │ ├── README │ ├── SimpleNode.java │ └── UnparseVisitor.java ├── findbugs-exclude.xml ├── grammars ├── AsnParser.jj ├── BackupCharStream.java ├── CParser.jj ├── ChemNumber.jj ├── CobolParser.jj ├── ConditionParser.jj ├── DTDParser.jj ├── EcmaScript.jjt ├── ExpressParser.jj ├── FormsPlSql.jj ├── GdmoTranslator.jj ├── IDLParser.jj ├── JSONParser.jjt ├── JavaCC.jj ├── OberonParser.jj ├── ParserCSS30.jjt ├── ParserCSSCharsetDetector.jjt ├── ParserXP2.jjt ├── PetalParser.jj ├── PlSql.jj ├── RTFParser.jj └── RuleCompiler.jj ├── pom.xml ├── src ├── etc │ ├── javadoc.css │ └── license-template.txt ├── main │ ├── java │ │ └── com │ │ │ └── helger │ │ │ └── pgcc │ │ │ ├── CPG.java │ │ │ ├── EJDKVersion.java │ │ │ ├── PGPrinter.java │ │ │ ├── PGVersion.java │ │ │ ├── jjdoc │ │ │ ├── BNFGenerator.java │ │ │ ├── HTMLGenerator.java │ │ │ ├── IDocGenerator.java │ │ │ ├── JJDoc.java │ │ │ ├── JJDocGlobals.java │ │ │ ├── JJDocMain.java │ │ │ ├── JJDocOptions.java │ │ │ ├── TextGenerator.java │ │ │ ├── XTextGenerator.java │ │ │ └── package.html │ │ │ ├── jjtree │ │ │ ├── ASTBNF.java │ │ │ ├── ASTBNFAction.java │ │ │ ├── ASTBNFDeclaration.java │ │ │ ├── ASTBNFNodeScope.java │ │ │ ├── ASTCompilationUnit.java │ │ │ ├── ASTExpansionNodeScope.java │ │ │ ├── ASTGrammar.java │ │ │ ├── ASTJavacode.java │ │ │ ├── ASTJavacodeBody.java │ │ │ ├── ASTLHS.java │ │ │ ├── ASTNodeDescriptor.java │ │ │ ├── ASTNodeDescriptorExpression.java │ │ │ ├── ASTOptionBinding.java │ │ │ ├── ASTOptions.java │ │ │ ├── ASTProduction.java │ │ │ ├── CodeGeneratorCpp.java │ │ │ ├── CodeGeneratorJava.java │ │ │ ├── DefaultJJTreeVisitor.java │ │ │ ├── JJTree.java │ │ │ ├── JJTreeGlobals.java │ │ │ ├── JJTreeIO.java │ │ │ ├── JJTreeNode.java │ │ │ ├── JJTreeOptions.java │ │ │ ├── JJTreeParserVisitor.java │ │ │ ├── Main.java │ │ │ ├── NodeScope.java │ │ │ ├── Token.java │ │ │ ├── TokenUtils.java │ │ │ ├── output │ │ │ │ ├── JJTreeStateCpp.java │ │ │ │ ├── JJTreeStateJava.java │ │ │ │ ├── NodeFilesCpp.java │ │ │ │ └── NodeFilesJava.java │ │ │ └── package.html │ │ │ ├── main │ │ │ ├── JavaCCInterpreter.java │ │ │ ├── javacc.java │ │ │ ├── jjdoc.java │ │ │ └── jjtree.java │ │ │ ├── output │ │ │ ├── EOutputLanguage.java │ │ │ ├── OutputFile.java │ │ │ ├── OutputHelper.java │ │ │ ├── UnsupportedOutputLanguageException.java │ │ │ ├── cpp │ │ │ │ ├── FilesCpp.java │ │ │ │ └── OtherFilesGenCPP.java │ │ │ └── java │ │ │ │ ├── FilesJava.java │ │ │ │ ├── IJavaResourceTemplateLocations.java │ │ │ │ ├── JavaModernResourceTemplateLocationImpl.java │ │ │ │ ├── JavaResourceTemplateLocationImpl.java │ │ │ │ └── OtherFilesGenJava.java │ │ │ ├── package.html │ │ │ ├── parser │ │ │ ├── AbstractCodeProduction.java │ │ │ ├── BNFProduction.java │ │ │ ├── CodeGenerator.java │ │ │ ├── CodeProductionCpp.java │ │ │ ├── CodeProductionJava.java │ │ │ ├── Container.java │ │ │ ├── ETokenKind.java │ │ │ ├── ExpansionTreeWalker.java │ │ │ ├── ITreeWalkerOperation.java │ │ │ ├── JavaCCErrors.java │ │ │ ├── JavaCCGlobals.java │ │ │ ├── JavaCCParserInternals.java │ │ │ ├── LexGenCpp.java │ │ │ ├── LexGenJava.java │ │ │ ├── LookaheadCalc.java │ │ │ ├── LookaheadWalk.java │ │ │ ├── Main.java │ │ │ ├── MatchInfo.java │ │ │ ├── MetaParseException.java │ │ │ ├── Nfa.java │ │ │ ├── NfaState.java │ │ │ ├── NormalProduction.java │ │ │ ├── Options.java │ │ │ ├── ParseEngine.java │ │ │ ├── ParseGenCPP.java │ │ │ ├── ParseGenJava.java │ │ │ ├── ParserData.java │ │ │ ├── RegExprSpec.java │ │ │ ├── Semanticize.java │ │ │ ├── Token.java │ │ │ ├── TokenProduction.java │ │ │ ├── TokenizerData.java │ │ │ ├── exp │ │ │ │ ├── AbstractExpRegularExpression.java │ │ │ │ ├── CharacterRange.java │ │ │ │ ├── ExpAction.java │ │ │ │ ├── ExpChoice.java │ │ │ │ ├── ExpLookahead.java │ │ │ │ ├── ExpNonTerminal.java │ │ │ │ ├── ExpOneOrMore.java │ │ │ │ ├── ExpRCharacterList.java │ │ │ │ ├── ExpRChoice.java │ │ │ │ ├── ExpREndOfFile.java │ │ │ │ ├── ExpRJustName.java │ │ │ │ ├── ExpROneOrMore.java │ │ │ │ ├── ExpRRepetitionRange.java │ │ │ │ ├── ExpRSequence.java │ │ │ │ ├── ExpRStringLiteral.java │ │ │ │ ├── ExpRZeroOrMore.java │ │ │ │ ├── ExpRZeroOrOne.java │ │ │ │ ├── ExpSequence.java │ │ │ │ ├── ExpTryBlock.java │ │ │ │ ├── ExpZeroOrMore.java │ │ │ │ ├── ExpZeroOrOne.java │ │ │ │ ├── Expansion.java │ │ │ │ ├── ICCCharacter.java │ │ │ │ └── SingleCharacter.java │ │ │ ├── package.html │ │ │ └── table │ │ │ │ ├── TableDrivenJavaCodeGenerator.java │ │ │ │ └── TokenManagerCodeGenerator.java │ │ │ └── utils │ │ │ ├── EOptionType.java │ │ │ ├── OptionInfo.java │ │ │ └── OutputFileGenerator.java │ ├── javacc │ │ ├── ConditionParser.jj │ │ └── JavaCC.jj │ ├── jjtree │ │ └── JJTree.jjt │ └── resources │ │ ├── LICENSE │ │ ├── NOTICE │ │ ├── pgcc-version.properties │ │ └── templates │ │ ├── DumpDebugMethods.template │ │ ├── DumpStaticVarDeclarations.template │ │ ├── ParseException.template │ │ ├── TableDrivenTokenManager.template │ │ ├── Token.template │ │ ├── TokenManager.template │ │ ├── TokenManagerBoilerPlateMethods.template │ │ ├── TokenMgrError.template │ │ ├── TokenizerAlgorithm.template │ │ ├── cpp │ │ ├── DumpDebugMethods.template │ │ ├── DumpVarDeclarations.template │ │ ├── ErrorHandler.h.template │ │ ├── JavaCC.h.template │ │ ├── MultiNode.cc.template │ │ ├── MultiNode.h.template │ │ ├── MultiNode.template │ │ ├── ParseException.cc.template │ │ ├── ParseException.h.template │ │ ├── SimpleNodeImpl.template │ │ ├── SimpleNodeInterface.template │ │ ├── Token.cc.template │ │ ├── Token.h.template │ │ ├── TokenManager.h.template │ │ ├── TokenManagerBoilerPlateMethods.template │ │ ├── TokenMgrError.cc.template │ │ ├── TokenMgrError.h.template │ │ └── TreeIncludeHeader.template │ │ ├── gwt │ │ └── ParseException.template │ │ ├── jjtree │ │ ├── cpp │ │ │ ├── JJTTreeState.cc.template │ │ │ ├── JJTTreeState.h.template │ │ │ ├── MultiNodeImpl.template │ │ │ ├── MultiNodeInterface.template │ │ │ ├── Node.h.template │ │ │ ├── SimpleNode.cc.template │ │ │ ├── SimpleNode.h.template │ │ │ └── _unused_TreeImplHeader.template │ │ └── java │ │ │ ├── MultiNode.template │ │ │ ├── Node.template │ │ │ └── SimpleNode.template │ │ └── stream │ │ ├── cpp │ │ ├── CharStream.cc.template │ │ └── CharStream.h.template │ │ └── java │ │ ├── AbstractCharStream.template │ │ ├── CharStream.template │ │ ├── JavaCharStream.template │ │ ├── SimpleCharStream.template │ │ └── modern │ │ ├── JavaCharStream.template │ │ ├── Provider.template │ │ ├── SimpleCharStream.template │ │ ├── StreamProvider.template │ │ └── StringProvider.template └── test │ ├── java │ └── com │ │ └── helger │ │ └── pgcc │ │ ├── AbstractJavaCCTestCase.java │ │ ├── issues │ │ ├── Issue20Test.java │ │ ├── Issue24Test.java │ │ ├── Issue33Test.java │ │ └── Java7FuncTest.java │ │ ├── jjdoc │ │ └── test │ │ │ └── JJDocMainTest.java │ │ ├── jjtree │ │ └── JJTreeOptionsTest.java │ │ ├── output │ │ └── java │ │ │ └── JavaTemplateValidityFuncTest.java │ │ ├── parser │ │ ├── GrammarsParsingFuncTest.java │ │ ├── OptionsTest.java │ │ ├── exp │ │ │ ├── ExpChoiceTest.java │ │ │ └── ExpansionTest.java │ │ └── test │ │ │ └── NfaStateTest.java │ │ └── utils │ │ ├── ConditionParserTest.java │ │ └── OutputFileGeneratorTest.java │ └── resources │ └── issues │ ├── 20 │ └── grammar.jj │ ├── 24 │ └── grammar.jj │ ├── 33 │ ├── grammar.jj │ └── sample.txt │ └── java7 │ └── grammar.jj ├── test ├── TestTokenManagerUsesParser │ └── TestTokenManagerUsesParser.jj ├── TestTokenManagerUsesParser2 │ └── TestTokenManagerUsesParser2.jj ├── build.xml ├── exceptions │ ├── Parser.jj │ └── build.xml ├── imports │ ├── Parser.jj │ └── build.xml ├── javaFileGeneration │ ├── Parser.jj │ ├── README.txt │ ├── build.xml │ ├── expected │ │ ├── generated.txt │ │ ├── no-keep-line │ │ │ ├── ParseException.java │ │ │ ├── Parser.java │ │ │ ├── ParserConstants.java │ │ │ ├── ParserTokenManager.java │ │ │ ├── SimpleCharStream.java │ │ │ ├── Token.java │ │ │ └── TokenMgrError.java │ │ ├── non-static │ │ │ ├── ParseException.java │ │ │ ├── Parser.java │ │ │ ├── ParserConstants.java │ │ │ ├── ParserTokenManager.java │ │ │ ├── SimpleCharStream.java │ │ │ ├── Token.java │ │ │ └── TokenMgrError.java │ │ ├── not-public │ │ │ ├── ParseException.java │ │ │ ├── Parser.java │ │ │ ├── ParserConstants.java │ │ │ ├── ParserTokenManager.java │ │ │ ├── SimpleCharStream.java │ │ │ ├── Token.java │ │ │ └── TokenMgrError.java │ │ └── static │ │ │ ├── ParseException.java │ │ │ ├── Parser.java │ │ │ ├── ParserConstants.java │ │ │ ├── ParserTokenManager.java │ │ │ ├── SimpleCharStream.java │ │ │ ├── Token.java │ │ │ └── TokenMgrError.java │ └── template.txt ├── javaFiles │ ├── BaseSimpleCharStream.java │ ├── BaseSimpleNode.java │ ├── ChangedOptionsSimpleCharStream.java │ ├── IncompatSimpleNode.java │ ├── ModifiedOldSimpleCharStream.java │ ├── ModifiedSimpleCharStream.java │ ├── ModifiedSimpleNode.java │ ├── Multi.jjt │ ├── OldSimpleCharStream.java │ ├── Parser.jj │ ├── README.txt │ ├── StaticParser.jj │ ├── Tree.jjt │ └── build.xml ├── javacodeLA │ ├── build.xml │ └── javacode.jj ├── lineNumbers │ ├── JJTree.jjt │ └── build.xml ├── lom │ ├── Parser.jj │ └── build.xml └── newToken │ ├── OldToken.java │ ├── Parser.jj │ ├── ParserTokenFactory.jj │ └── build.xml └── www ├── doc ├── CharStream.html ├── JJDoc.html ├── JJTree.html ├── JavaCC.html ├── JavaCC.txt ├── apiroutines.html ├── commandline.html ├── docindex.html ├── errorrecovery.html ├── features.html ├── index.html ├── installhelp.html ├── javacc-c++-releasenotes.html ├── javaccgrm.html ├── javaccreleasenotes.html ├── jjdocreleasenotes.html ├── jjtree-c++-releasenotes.html ├── jjtreeREADME.html ├── jjtreeintro.html ├── jjtreereleasenotes.html ├── lexertips.html ├── lookahead.html ├── mailinglist.html ├── simpleREADME.html ├── support.html └── tokenmanager.html ├── index.html └── styles.css /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | zz 3 | JavaCCParserTokenManager.java 4 | .settings/ 5 | .project 6 | .classpath 7 | *.iml 8 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | parser-generator-cc 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.pde.PluginNature 21 | org.eclipse.m2e.core.maven2Nature 22 | org.eclipse.jdt.core.javanature 23 | 24 | 25 | 26 | 1747990631956 27 | 28 | 30 29 | 30 | org.eclipse.core.resources.regexFilterMatcher 31 | node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright 2017-2021 Philip Helger, pgcc@helger.com 2 | 3 | Copyright 2011 Google Inc. All Rights Reserved. 4 | Author: sreeni@google.com (Sreeni Viswanadha) 5 | 6 | Copyright (c) 2006, Sun Microsystems, Inc. 7 | All rights reserved. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions are met: 11 | 12 | * Redistributions of source code must retain the above copyright notice, 13 | this list of conditions and the following disclaimer. 14 | * Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | * Neither the name of the Sun Microsystems, Inc. nor the names of its 18 | contributors may be used to endorse or promote products derived from 19 | this software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | THE POSSIBILITY OF SUCH DAMAGE. 32 | -------------------------------------------------------------------------------- /docs/Parsing Expressions by Recursive Descent-Dateien/exp_parsing-0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulipcc/ParserGeneratorCC/5038d1b62a6c951bcb30ced53bcf10329da26934/docs/Parsing Expressions by Recursive Descent-Dateien/exp_parsing-0.png -------------------------------------------------------------------------------- /docs/Parsing Expressions by Recursive Descent-Dateien/exp_parsing-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulipcc/ParserGeneratorCC/5038d1b62a6c951bcb30ced53bcf10329da26934/docs/Parsing Expressions by Recursive Descent-Dateien/exp_parsing-1.png -------------------------------------------------------------------------------- /docs/Parsing Expressions by Recursive Descent-Dateien/exp_parsing-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulipcc/ParserGeneratorCC/5038d1b62a6c951bcb30ced53bcf10329da26934/docs/Parsing Expressions by Recursive Descent-Dateien/exp_parsing-2.png -------------------------------------------------------------------------------- /docs/Parsing Expressions by Recursive Descent.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulipcc/ParserGeneratorCC/5038d1b62a6c951bcb30ced53bcf10329da26934/docs/Parsing Expressions by Recursive Descent.html -------------------------------------------------------------------------------- /examples/CORBA-IDL/Hello.idl: -------------------------------------------------------------------------------- 1 | module HelloApp 2 | { 3 | interface Hello 4 | { 5 | string sayHello(); 6 | }; 7 | }; 8 | -------------------------------------------------------------------------------- /examples/CORBA-IDL/README: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006, Sun Microsystems, Inc. 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 13 | * contributors may be used to endorse or promote products derived from 14 | * this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 26 | * THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | This directory contains an CORBA 2.0 grammar for IDL. Build it in the 30 | usual manner and try it out. 31 | 32 | javacc IDL.jj 33 | javac *.java 34 | java IDLParser 35 | -------------------------------------------------------------------------------- /examples/GUIParsing/ParserVersion/Main.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | public class Main { 35 | 36 | public static void main(String[] args) { 37 | new CalcGUI(); 38 | TokenManager tm = new TokenCollector(); 39 | CalcInputParser cp = new CalcInputParser(tm); 40 | while (true) { 41 | try { 42 | cp.Input(); 43 | } catch (ParseException e) { 44 | CalcGUI.print("ERROR (click 0)"); 45 | } 46 | } 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /examples/GUIParsing/ParserVersion/TokenCollector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | public class TokenCollector implements TokenManager { 35 | 36 | public Token getNextToken() { 37 | return ProducerConsumer.pc.getToken(); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /examples/GUIParsing/README: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006, Sun Microsystems, Inc. 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 13 | * contributors may be used to endorse or promote products derived from 14 | * this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 26 | * THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | In this directory are two examples that illustrate the use of JavaCC 30 | generated parsers to collect input from a GUI and process it 31 | appropriately. The example used is a simple calculator. There are 32 | two versions of this example: 33 | 34 | . A version that uses a JavaCC parser without the JavaCC token manager 35 | in directory ParserVersion. 36 | 37 | . A version that uses a JavaCC token manager without the JavaCC parser 38 | in directory TokenMgrVersion. This example also illustrates the 39 | ability to build a state machine as a lexical specification. 40 | 41 | The README files in these directories provide more details. 42 | -------------------------------------------------------------------------------- /examples/GUIParsing/TokenMgrVersion/Main.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | public class Main { 35 | 36 | public static void main(String[] args) { 37 | CalcGUI gui = new CalcGUI(); 38 | MyLexer lexer = new MyLexer(gui); 39 | while (true) { 40 | try { 41 | lexer.getNextToken(); 42 | } catch (TokenMgrError e) { 43 | } 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /examples/Interpreter/ASTAddNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | public class ASTAddNode extends SimpleNode { 35 | public ASTAddNode(int id) { 36 | super(id); 37 | } 38 | 39 | public ASTAddNode(SPLParser p, int id) { 40 | super(p, id); 41 | } 42 | 43 | public void interpret() 44 | { 45 | jjtGetChild(0).interpret(); 46 | jjtGetChild(1).interpret(); 47 | 48 | stack[--top] = Integer.valueOf(((Integer)stack[top]).intValue() + 49 | ((Integer)stack[top + 1]).intValue()); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /examples/Interpreter/ASTAssignment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | public class ASTAssignment extends SimpleNode { 35 | public ASTAssignment(int id) { 36 | super(id); 37 | } 38 | 39 | public ASTAssignment(SPLParser p, int id) { 40 | super(p, id); 41 | } 42 | 43 | public void interpret() 44 | { 45 | String name; 46 | 47 | jjtGetChild(1).interpret(); 48 | symtab.put(name = ((ASTId)jjtGetChild(0)).name, stack[top]); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /examples/Interpreter/ASTBitwiseComplNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | public class ASTBitwiseComplNode extends SimpleNode { 35 | public ASTBitwiseComplNode(int id) { 36 | super(id); 37 | } 38 | 39 | public ASTBitwiseComplNode(SPLParser p, int id) { 40 | super(p, id); 41 | } 42 | 43 | public void interpret() 44 | { 45 | jjtGetChild(0).interpret(); 46 | 47 | stack[top] = Integer.valueOf(~((Integer)stack[top]).intValue()); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /examples/Interpreter/ASTBlock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | public class ASTBlock extends SimpleNode { 35 | public ASTBlock(int id) { 36 | super(id); 37 | } 38 | 39 | public ASTBlock(SPLParser p, int id) { 40 | super(p, id); 41 | } 42 | 43 | public void interpret() 44 | { 45 | int i, k = jjtGetNumChildren(); 46 | 47 | for (i = 0; i < k; i++) 48 | jjtGetChild(i).interpret(); 49 | 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /examples/Interpreter/ASTDivNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | public class ASTDivNode extends SimpleNode { 35 | public ASTDivNode(int id) { 36 | super(id); 37 | } 38 | 39 | public ASTDivNode(SPLParser p, int id) { 40 | super(p, id); 41 | } 42 | 43 | public void interpret() 44 | { 45 | jjtGetChild(0).interpret(); 46 | jjtGetChild(1).interpret(); 47 | 48 | stack[--top] = Integer.valueOf(((Integer)stack[top]).intValue() / 49 | ((Integer)stack[top + 1]).intValue()); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /examples/Interpreter/ASTFalseNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | public class ASTFalseNode extends SimpleNode { 35 | public ASTFalseNode(int id) { 36 | super(id); 37 | } 38 | 39 | public ASTFalseNode(SPLParser p, int id) { 40 | super(p, id); 41 | } 42 | 43 | public void interpret() 44 | { 45 | stack[++top] = Boolean.FALSE; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /examples/Interpreter/ASTGENode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | public class ASTGENode extends SimpleNode { 35 | public ASTGENode(int id) { 36 | super(id); 37 | } 38 | 39 | public ASTGENode(SPLParser p, int id) { 40 | super(p, id); 41 | } 42 | 43 | public void interpret() 44 | { 45 | jjtGetChild(0).interpret(); 46 | jjtGetChild(1).interpret(); 47 | 48 | stack[--top] = Boolean.valueOf(((Integer)stack[top]).intValue() >= 49 | ((Integer)stack[top + 1]).intValue()); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /examples/Interpreter/ASTGTNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | public class ASTGTNode extends SimpleNode { 35 | public ASTGTNode(int id) { 36 | super(id); 37 | } 38 | 39 | public ASTGTNode(SPLParser p, int id) { 40 | super(p, id); 41 | } 42 | 43 | public void interpret() 44 | { 45 | jjtGetChild(0).interpret(); 46 | jjtGetChild(1).interpret(); 47 | 48 | stack[--top] = Boolean.valueOf(((Integer)stack[top]).intValue() > 49 | ((Integer)stack[top + 1]).intValue()); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /examples/Interpreter/ASTId.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | public class ASTId extends SimpleNode { 35 | 36 | String name; 37 | 38 | public ASTId(int id) { 39 | super(id); 40 | } 41 | 42 | public ASTId(SPLParser p, int id) { 43 | super(p, id); 44 | } 45 | 46 | public void interpret() 47 | { 48 | stack[++top] = symtab.get(name); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /examples/Interpreter/ASTIfStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | public class ASTIfStatement extends SimpleNode { 35 | public ASTIfStatement(int id) { 36 | super(id); 37 | } 38 | 39 | public ASTIfStatement(SPLParser p, int id) { 40 | super(p, id); 41 | } 42 | 43 | public void interpret() 44 | { 45 | jjtGetChild(0).interpret(); 46 | 47 | if (((Boolean)stack[top--]).booleanValue()) 48 | jjtGetChild(1).interpret(); 49 | else if (jjtGetNumChildren() == 3) 50 | jjtGetChild(2).interpret(); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /examples/Interpreter/ASTIntConstNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | public class ASTIntConstNode extends SimpleNode { 35 | 36 | int val; 37 | 38 | public ASTIntConstNode(int id) { 39 | super(id); 40 | } 41 | 42 | public ASTIntConstNode(SPLParser p, int id) { 43 | super(p, id); 44 | } 45 | 46 | public void interpret() 47 | { 48 | stack[++top] = Integer.valueOf(val); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /examples/Interpreter/ASTLENode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | public class ASTLENode extends SimpleNode { 35 | public ASTLENode(int id) { 36 | super(id); 37 | } 38 | 39 | public ASTLENode(SPLParser p, int id) { 40 | super(p, id); 41 | } 42 | 43 | public void interpret() 44 | { 45 | jjtGetChild(0).interpret(); 46 | jjtGetChild(1).interpret(); 47 | 48 | stack[--top] = Boolean.valueOf(((Integer)stack[top]).intValue() <= 49 | ((Integer)stack[top + 1]).intValue()); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /examples/Interpreter/ASTLTNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | public class ASTLTNode extends SimpleNode { 35 | public ASTLTNode(int id) { 36 | super(id); 37 | } 38 | 39 | public ASTLTNode(SPLParser p, int id) { 40 | super(p, id); 41 | } 42 | 43 | public void interpret() 44 | { 45 | jjtGetChild(0).interpret(); 46 | jjtGetChild(1).interpret(); 47 | 48 | stack[--top] = Boolean.valueOf(((Integer)stack[top]).intValue() < 49 | ((Integer)stack[top + 1]).intValue()); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /examples/Interpreter/ASTModNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | public class ASTModNode extends SimpleNode { 35 | public ASTModNode(int id) { 36 | super(id); 37 | } 38 | 39 | public ASTModNode(SPLParser p, int id) { 40 | super(p, id); 41 | } 42 | 43 | public void interpret() 44 | { 45 | jjtGetChild(0).interpret(); 46 | jjtGetChild(1).interpret(); 47 | 48 | stack[--top] = Integer.valueOf(((Integer)stack[top]).intValue() % 49 | ((Integer)stack[top + 1]).intValue()); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /examples/Interpreter/ASTMulNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | public class ASTMulNode extends SimpleNode { 35 | public ASTMulNode(int id) { 36 | super(id); 37 | } 38 | 39 | public ASTMulNode(SPLParser p, int id) { 40 | super(p, id); 41 | } 42 | 43 | public void interpret() 44 | { 45 | jjtGetChild(0).interpret(); 46 | jjtGetChild(1).interpret(); 47 | 48 | stack[--top] = Integer.valueOf(((Integer)stack[top]).intValue() * 49 | ((Integer)stack[top + 1]).intValue()); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /examples/Interpreter/ASTNotNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | public class ASTNotNode extends SimpleNode { 35 | public ASTNotNode(int id) { 36 | super(id); 37 | } 38 | 39 | public ASTNotNode(SPLParser p, int id) { 40 | super(p, id); 41 | } 42 | 43 | public void interpret() 44 | { 45 | jjtGetChild(0).interpret(); 46 | stack[top] = Boolean.valueOf(!((Boolean)stack[top]).booleanValue()); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /examples/Interpreter/ASTStatementExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | public class ASTStatementExpression extends SimpleNode { 35 | public ASTStatementExpression(int id) { 36 | super(id); 37 | } 38 | 39 | public ASTStatementExpression(SPLParser p, int id) { 40 | super(p, id); 41 | } 42 | 43 | public void interpret() 44 | { 45 | jjtGetChild(0).interpret(); 46 | top--; //just throw away the value. 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /examples/Interpreter/ASTSubtractNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | public class ASTSubtractNode extends SimpleNode { 35 | public ASTSubtractNode(int id) { 36 | super(id); 37 | } 38 | 39 | public ASTSubtractNode(SPLParser p, int id) { 40 | super(p, id); 41 | } 42 | 43 | public void interpret() 44 | { 45 | jjtGetChild(0).interpret(); 46 | jjtGetChild(1).interpret(); 47 | 48 | stack[--top] = Integer.valueOf(((Integer)stack[top]).intValue() - 49 | ((Integer)stack[top + 1]).intValue()); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /examples/Interpreter/ASTTrueNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | public class ASTTrueNode extends SimpleNode { 35 | public ASTTrueNode(int id) { 36 | super(id); 37 | } 38 | 39 | public ASTTrueNode(SPLParser p, int id) { 40 | super(p, id); 41 | } 42 | 43 | public void interpret() 44 | { 45 | stack[++top] = Boolean.valueOf(true); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /examples/Interpreter/ASTVarDeclaration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | public class ASTVarDeclaration extends SimpleNode 35 | implements SPLParserConstants { 36 | 37 | int type; 38 | String name; 39 | 40 | public ASTVarDeclaration(int id) { 41 | super(id); 42 | } 43 | 44 | public ASTVarDeclaration(SPLParser p, int id) { 45 | super(p, id); 46 | } 47 | 48 | public void interpret() 49 | { 50 | if (type == BOOL) 51 | symtab.put(name, Boolean.FALSE); 52 | else 53 | symtab.put(name, Integer.valueOf(0)); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /examples/Interpreter/ASTWhileStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | public class ASTWhileStatement extends SimpleNode { 35 | public ASTWhileStatement(int id) { 36 | super(id); 37 | } 38 | 39 | public ASTWhileStatement(SPLParser p, int id) { 40 | super(p, id); 41 | } 42 | 43 | public void interpret() 44 | { 45 | do { 46 | jjtGetChild(0).interpret(); 47 | 48 | if (((Boolean)stack[top--]).booleanValue()) 49 | jjtGetChild(1).interpret(); 50 | else 51 | break; 52 | } while (true); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /examples/Interpreter/README: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006, Sun Microsystems, Inc. 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 13 | * contributors may be used to endorse or promote products derived from 14 | * this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 26 | * THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | This is an interpreter for SPL (Stupid Programming Language). It builds 30 | jjtree's for a given SPL program and interprets it. It shows how you can 31 | implement simple loop and conditional constructs. 32 | 33 | Note how easy it is to annotate a grammar file to build useful tree nodes 34 | and then extend these nodes for purposes of interpreting, etc. 35 | 36 | This example will be improved as JJTree evolves. 37 | 38 | To run it : 39 | 40 | jjtree SPL.jjt 41 | javacc SPL.jj 42 | javac *.java 43 | java SPL fact.spl 44 | java SPL sqrt.spl 45 | java SPL odd.spl 46 | -------------------------------------------------------------------------------- /examples/Interpreter/fact.spl: -------------------------------------------------------------------------------- 1 | int n; 2 | int fact; 3 | 4 | read n; 5 | 6 | fact = 1; 7 | 8 | while (n > 1) 9 | { 10 | fact = fact * n; 11 | n = n - 1; 12 | } 13 | 14 | write fact; 15 | -------------------------------------------------------------------------------- /examples/Interpreter/odd.spl: -------------------------------------------------------------------------------- 1 | int num; 2 | boolean odd; 3 | 4 | num = 10; 5 | 6 | read num; 7 | 8 | if (num % 2 != 0) 9 | odd = true; 10 | else 11 | odd = false; 12 | 13 | write odd; 14 | -------------------------------------------------------------------------------- /examples/Interpreter/sqrt.spl: -------------------------------------------------------------------------------- 1 | 2 | int val; 3 | 4 | read val; 5 | int sqrt; 6 | 7 | sqrt = 1; 8 | 9 | while (sqrt * sqrt <= val && ((sqrt + 1) * (sqrt + 1)) <= val) 10 | sqrt = sqrt + 1; 11 | 12 | write sqrt 13 | -------------------------------------------------------------------------------- /examples/JJTreeExamples/cpp/ASTMyID.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * ASTMyID.cpp 3 | * 4 | * Created on: 28 mars 2014 5 | * Author: FrancisANDRE 6 | */ 7 | 8 | #include "ASTMyID.h" 9 | 10 | namespace @NAMESPACE@ { 11 | 12 | ASTMyID::ASTMyID(int i) : SimpleNode(i) { 13 | } 14 | ASTMyID::ASTMyID(Parser *p, int id) : SimpleNode(p, id){ 15 | } 16 | 17 | void 18 | ASTMyID::setName(JAVACC_STRING_TYPE image) { 19 | name = image; 20 | } 21 | 22 | ASTMyID::~ASTMyID() { 23 | } 24 | 25 | JAVACC_STRING_TYPE ASTMyID::toString() const { 26 | return "Identifier: " + name; 27 | } 28 | 29 | 30 | } /* namespace @NAMESPACE@ */ 31 | -------------------------------------------------------------------------------- /examples/JJTreeExamples/cpp/ASTMyOtherID.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * ASTMyOtherID.cpp 3 | * 4 | * Created on: 27 mars 2014 5 | * Author: FrancisANDRE 6 | */ 7 | 8 | #include "ASTMyOtherID.h" 9 | #include "ParserVisitor.h" 10 | 11 | namespace @NAMESPACE@ { 12 | 13 | ASTMyOtherID::ASTMyOtherID(int id) : SimpleNode(id) { 14 | } 15 | ASTMyOtherID::ASTMyOtherID(Parser *p, int id) : SimpleNode(p, id){ 16 | } 17 | ASTMyOtherID::~ASTMyOtherID() { 18 | } 19 | 20 | void 21 | ASTMyOtherID::setName(JAVACC_STRING_TYPE image) { 22 | name = image; 23 | } 24 | 25 | 26 | JAVACC_STRING_TYPE 27 | ASTMyOtherID::toString() const { 28 | return "Identifier: " + name; 29 | } 30 | /** Accept the visitor. **/ 31 | void* 32 | ASTMyOtherID::jjtAccept(ParserVisitor *visitor, void * data) const { 33 | return visitor->visit(this, data); 34 | } 35 | 36 | 37 | } /* namespace @NAMESPACE@ */ 38 | 39 | -------------------------------------------------------------------------------- /examples/JJTreeExamples/cpp/EG4DumpVisitor.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * EG4DumpVisitor.cpp 3 | * 4 | * Created on: 28 mars 2014 5 | * Author: FrancisANDRE 6 | */ 7 | 8 | #include 9 | #include "JavaCC.h" 10 | #include "EG4DumpVisitor.h" 11 | #include "ASTMyID.h" 12 | #include "ASTMyOtherID.h" 13 | 14 | using namespace std; 15 | 16 | namespace @NAMESPACE@ { 17 | 18 | EG4DumpVisitor::EG4DumpVisitor() : indent (0) { 19 | } 20 | 21 | EG4DumpVisitor::~EG4DumpVisitor() { 22 | } 23 | JAVACC_SIMPLE_STRING EG4DumpVisitor::indentString() const { 24 | JAVACC_STRING_TYPE buffer; 25 | for (int i = 0; i < indent; i++) { 26 | buffer.append(" "); 27 | } 28 | return buffer; 29 | } 30 | 31 | void* EG4DumpVisitor::visit(const SimpleNode* node, void* data) { 32 | // System.out.println(indentString() + node + 33 | // ": acceptor not unimplemented in subclass?"); 34 | ++indent; 35 | node->jjtChildrenAccept(this, data); 36 | --indent; 37 | return data; 38 | } 39 | 40 | void* EG4DumpVisitor::visit(const ASTStart* node, void* data) { 41 | cout << indentString() + node->toString() << endl; 42 | ++indent; 43 | node->jjtChildrenAccept(this, data); 44 | --indent; 45 | return data; 46 | } 47 | 48 | void* EG4DumpVisitor::visit(const ASTAdd* node, void* data) { 49 | cout << indentString() + node->toString() << endl; 50 | ++indent; 51 | node->jjtChildrenAccept(this, data); 52 | --indent; 53 | return data; 54 | } 55 | 56 | void* EG4DumpVisitor::visit(const ASTMult* node, void* data) { 57 | cout << indentString() + node->toString() << endl; 58 | ++indent; 59 | node->jjtChildrenAccept(this, data); 60 | --indent; 61 | return data; 62 | } 63 | 64 | void* EG4DumpVisitor::visit(const ASTMyID* node, void* data) { 65 | cout << indentString() + node->toString() << endl; 66 | ++indent; 67 | node->jjtChildrenAccept(this, data); 68 | --indent; 69 | return data; 70 | } 71 | 72 | void* EG4DumpVisitor::visit(const ASTMyOtherID* node, void* data) { 73 | cout << indentString() + node->toString() << endl; 74 | ++indent; 75 | node->jjtChildrenAccept(this, data); 76 | --indent; 77 | return data; 78 | } 79 | 80 | void* EG4DumpVisitor::visit(const ASTInteger* node, void* data) { 81 | cout << indentString() + node->toString() << endl; 82 | ++indent; 83 | node->jjtChildrenAccept(this, data); 84 | --indent; 85 | return data; 86 | } 87 | 88 | } /* namespace @NAMESPACE@ */ 89 | -------------------------------------------------------------------------------- /examples/JJTreeExamples/cpp/MyErrorHandler.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * MyErrorHandler.cpp 3 | * 4 | * Created on: 12 avr. 2014 5 | * Author: FrancisANDRE 6 | */ 7 | 8 | #include "MyErrorHandler.h" 9 | 10 | namespace @NAMESPACE@ { 11 | 12 | MyErrorHandler::MyErrorHandler() { 13 | } 14 | 15 | MyErrorHandler::~MyErrorHandler() { 16 | } 17 | 18 | } /* namespace @NAMESPACE@ */ 19 | -------------------------------------------------------------------------------- /examples/JJTreeExamples/cpp/MyErrorHandler.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | /* 35 | * MyErrorHandler.h 36 | * 37 | * Created on: 12 avr. 2014 38 | * Author: FrancisANDRE 39 | */ 40 | 41 | #ifndef MYERRORHANDLER_H_ 42 | #define MYERRORHANDLER_H_ 43 | #include "ErrorHandler.h" 44 | 45 | namespace @NAMESPACE@ { 46 | 47 | class MyErrorHandler : public ErrorHandler { 48 | public: 49 | MyErrorHandler(); 50 | virtual ~MyErrorHandler(); 51 | }; 52 | 53 | } /* namespace @NAMESPACE@ */ 54 | 55 | #endif /* MYERRORHANDLER_H_ */ 56 | -------------------------------------------------------------------------------- /examples/JJTreeExamples/cpp/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulipcc/ParserGeneratorCC/5038d1b62a6c951bcb30ced53bcf10329da26934/examples/JJTreeExamples/cpp/README -------------------------------------------------------------------------------- /examples/JJTreeExamples/cpp/eg1.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "JavaCC.h" 7 | #include "Parser.h" 8 | #include "ParseException.h" 9 | #include "ParserTokenManager.h" 10 | 11 | using namespace std; 12 | using namespace EG1; 13 | 14 | JAVACC_STRING_TYPE ReadFileFully(char *file_name) { 15 | return "(1 + 2) * (a + b);\n"; 16 | } 17 | 18 | int main(int argc, char** argv) { 19 | cout << "Reading from standard input..." << endl; 20 | JAVACC_STRING_TYPE s = ReadFileFully(argv[1]); 21 | try { 22 | CharStream *stream = new CharStream(s.c_str(), s.size() - 1, 1, 1); 23 | ParserTokenManager *scanner = new ParserTokenManager(stream); 24 | Parser parser(scanner); 25 | SimpleNode* n = parser.Start(); 26 | n->dump(""); 27 | cout << "Thank you." << endl; 28 | } catch (const ParseException& e) { 29 | 30 | } 31 | return 0; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /examples/JJTreeExamples/cpp/eg2.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "Parser.h" 7 | #include "ParseException.h" 8 | #include "ParserTree.h" 9 | #include "ParserTokenManager.h" 10 | 11 | using namespace std; 12 | using namespace EG2; 13 | 14 | JAVACC_STRING_TYPE ReadFileFully(char *file_name) { 15 | // JAVACC_STRING_TYPE s; 16 | //#if WIDE_CHAR 17 | // wifstream in; 18 | //#else 19 | // ifstream in; 20 | //#endif 21 | // in.open(file_name, ios::in); 22 | // // Very inefficient. 23 | // while (!in.eof()) { 24 | // s += in.get(); 25 | // } 26 | return "1 + 2 * (a + b);\n";//s; 27 | } 28 | 29 | int main(int argc, char** argv) { 30 | cout << "Reading from standard input..." << endl; 31 | JAVACC_STRING_TYPE s = ReadFileFully(argv[1]); 32 | try { 33 | CharStream *stream = new CharStream(s.c_str(), s.size() - 1, 1, 1); 34 | ParserTokenManager *scanner = new ParserTokenManager(stream); 35 | Parser parser(scanner); 36 | ASTStart* n = parser.Start(); 37 | n->dump(""); 38 | cout << "Thank you." << endl; 39 | } catch (const ParseException& e) { 40 | 41 | } 42 | return 0; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /examples/JJTreeExamples/cpp/eg3.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "Parser.h" 7 | #include "ParseException.h" 8 | #include "ParserTree.h" 9 | #include "ParserTokenManager.h" 10 | 11 | using namespace std; 12 | using namespace EG3; 13 | 14 | JAVACC_STRING_TYPE ReadFileFully(char *file_name) { 15 | // JAVACC_STRING_TYPE s; 16 | //#if WIDE_CHAR 17 | // wifstream in; 18 | //#else 19 | // ifstream in; 20 | //#endif 21 | // in.open(file_name, ios::in); 22 | // // Very inefficient. 23 | // while (!in.eof()) { 24 | // s += in.get(); 25 | // } 26 | return "1 + 2 * (a + b);\n";//s; 27 | } 28 | 29 | int main(int argc, char** argv) { 30 | cout << "Reading from standard input..." << endl; 31 | JAVACC_STRING_TYPE s = ReadFileFully(argv[1]); 32 | try { 33 | CharStream *stream = new CharStream(s.c_str(), s.size() - 1, 1, 1); 34 | ParserTokenManager *scanner = new ParserTokenManager(stream); 35 | Parser parser(scanner); 36 | ASTStart* n = parser.Start(); 37 | n->dump(""); 38 | cout << "Thank you." << endl; 39 | } catch (const ParseException& e) { 40 | 41 | } 42 | return 0; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /examples/JJTreeExamples/cpp/eg4.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "Parser.h" 7 | #include "EG4DumpVisitor.h" 8 | #include "ParseException.h" 9 | #include "MyErrorHandler.h" 10 | #include "ParserTokenManager.h" 11 | 12 | using namespace std; 13 | using namespace EG4; 14 | 15 | JAVACC_STRING_TYPE ReadFileFully(char *file_name) { 16 | // JAVACC_STRING_TYPE s; 17 | //#if WIDE_CHAR 18 | // wifstream in; 19 | //#else 20 | // ifstream in; 21 | //#endif 22 | // in.open(file_name, ios::in); 23 | // // Very inefficient. 24 | // while (!in.eof()) { 25 | // s += in.get(); 26 | // } 27 | // return s; 28 | return "(1 + 2) * (a + b);\n"; 29 | } 30 | 31 | int main(int argc, char** argv) { 32 | cout << "Reading from standard input..." << endl; 33 | JAVACC_STRING_TYPE s = ReadFileFully(argv[1]); 34 | try { 35 | CharStream *stream = new CharStream(s.c_str(), s.size() - 1, 1, 1); 36 | ParserTokenManager *scanner = new ParserTokenManager(stream); 37 | Parser parser(scanner); 38 | parser.setErrorHandler(new MyErrorHandler()); 39 | ASTStart* n = parser.Start(); 40 | EG4DumpVisitor eg4dv; 41 | eg4dv.visit(n, NULL); 42 | cout << "Thank you." << endl; 43 | } catch (const ParseException& e) { 44 | 45 | } 46 | return 0; 47 | } 48 | 49 | -------------------------------------------------------------------------------- /examples/JavaGrammars/1.5/JavaGenerics.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | import java.util.*; 35 | 36 | public class JavaGenerics 37 | { 38 | private Map map; 39 | 40 | public void jriat() 41 | { 42 | int i = 1 >>> 4; 43 | int j = 1 >> 4; 44 | boolean b = 1 > 4; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /examples/JavaGrammars/1.5/MyToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | public class MyToken extends Token 35 | { 36 | /** 37 | * Constructs a new token for the specified Image and Kind. 38 | */ 39 | public MyToken(int kind, String image) 40 | { 41 | this.kind = kind; 42 | this.image = image; 43 | } 44 | 45 | int realKind = JavaParserConstants.GT; 46 | 47 | /** 48 | * Returns a new Token object. 49 | */ 50 | 51 | public static final Token newToken(int ofKind, String tokenImage) 52 | { 53 | return new MyToken(ofKind, tokenImage); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /examples/JavaGrammars/1.5/README: -------------------------------------------------------------------------------- 1 | 2 | This directory contains the JavaCC grammar for parsing (the proposed) 3 | JDK 1.5 Java language syntax. It handles generics, new for loops, static 4 | imports and annotation types. 5 | 6 | BUILDING 7 | -------- 8 | 9 | Just run 10 | 11 | ant 12 | 13 | in this directory and it will build the parser. 14 | 15 | 16 | RUNNING 17 | ------- 18 | 19 | You can run the parser directly using 20 | 21 | java JavaParser 22 | 23 | or there is a new Main class that accepts @ where the 24 | file with contains list of files one per line: 25 | 26 | java Main @ 27 | 28 | REPORTING BUGS 29 | -------------- 30 | 31 | If you find bugs in the grammar, please file an issue at 32 | javacc.dev.java.net, by logging in and clicking on the 'Issue Tracking' 33 | link on the navigation bar on the left side. You can also send email to: 34 | sreeni@viswanadha.net. 35 | -------------------------------------------------------------------------------- /examples/JavaGrammars/1.5/Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | import java.io.*; 35 | 36 | class Test 37 | { 38 | public static void main(String[] args) throws Exception 39 | { 40 | Reader fr = null; 41 | if (args.length == 2) 42 | fr = new InputStreamReader(new FileInputStream(new File(args[0])), args[1]); 43 | else 44 | fr = new InputStreamReader(new FileInputStream(new File(args[0]))); 45 | JavaParser jp = new JavaParser(fr); 46 | jp.CompilationUnit(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /examples/JavaGrammars/Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | import java.io.*; 35 | 36 | class Test 37 | { 38 | public static void main(String[] args) throws Exception 39 | { 40 | Reader fr = null; 41 | if (args.length == 2) 42 | fr = new InputStreamReader(new FileInputStream(new File(args[0])), args[1]); 43 | else 44 | fr = new InputStreamReader(new FileInputStream(new File(args[0]))); 45 | JavaParser jp = new JavaParser(fr); 46 | jp.CompilationUnit(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /examples/JavaGrammars/cpp/Makefile: -------------------------------------------------------------------------------- 1 | all: javaparser wjavaparser 2 | 3 | javaparser: main.cc gen/*.cc 4 | $(CXX) $(CXXFLAGS) -std=c++11 -Wall -fpermissive -o javaparser -I. main.cc gen/*.cc 5 | 6 | wjavaparser: main.cc gen/*.cc 7 | $(CXX) $(CXXFLAGS) -std=c++11 -Wall -fpermissive -DWIDE_CHAR=1 -DJAVACC_CHAR_TYPE=wchar_t -o wjavaparser -I. main.cc gen/*.cc 8 | 9 | gen/Java1.1.jj: Java1.1.jjt ../../../target/javacc.jar 10 | java -cp ../../../target/javacc.jar jjtree $(JAVACC_OPTS) $< 11 | 12 | gen/*.cc: gen/Java1.1.jj ../../../target/javacc.jar 13 | java -cp ../../../target/javacc.jar javacc $(JAVACC_OPTS) $< 14 | 15 | clean: 16 | /bin/rm -rf gen javaparser.* wjavaparser.* 17 | -------------------------------------------------------------------------------- /examples/JavaGrammars/cpp/allmain.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "gen/CharStream.h" 8 | #include "gen/JavaParser.h" 9 | #include "gen/JavaParserTokenManager.h" 10 | 11 | using namespace java::parser; 12 | using namespace std; 13 | 14 | JAVACC_STRING_TYPE ReadFileFully(char *file_name) { 15 | JAVACC_STRING_TYPE s; 16 | #if WIDE_CHAR 17 | wifstream fp_in; 18 | #else 19 | ifstream fp_in; 20 | #endif 21 | fp_in.open(file_name, ios::in); 22 | // Very inefficient. 23 | while (!fp_in.eof()) { 24 | s += fp_in.get(); 25 | } 26 | return s; 27 | } 28 | 29 | int main(int argc, char **argv) { 30 | if (argc < 2) { 31 | cout << "Usage: wjavaparser " << endl; 32 | exit(1); 33 | } 34 | JAVACC_STRING_TYPE s = ReadFileFully(argv[1]); 35 | CharStream *stream = new CharStream(s.c_str(), s.size() - 1, 1, 1); 36 | JavaParserTokenManager *scanner = new JavaParserTokenManager(stream); 37 | JavaParser parser(scanner); 38 | parser.setErrorHandler(new MyErrorHandler()); 39 | parser.CompilationUnit(); 40 | SimpleNode *root = (SimpleNode*)parser.jjtree.peekNode(); 41 | if (root) { 42 | JAVACC_STRING_TYPE buffer; 43 | #if WIDE_CHAR 44 | //root->dumpToBuffer(L" ", L"\n", &buffer); 45 | //wcout << buffer << "\n"; 46 | root->dump(L" "); 47 | #else 48 | root->dumpToBuffer(" ", "\n", &buffer); 49 | printf("%s\n", buffer.c_str()); 50 | #endif 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /examples/JavaGrammars/cpp/main.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "gen/JavaParserConstants.h" 8 | #include "gen/CharStream.h" 9 | #include "gen/JavaParser.h" 10 | #include "gen/JavaParserTokenManager.h" 11 | 12 | using namespace java::parser; 13 | using namespace std; 14 | 15 | JAVACC_STRING_TYPE ReadFileFully(char *file_name) { 16 | JAVACC_STRING_TYPE s; 17 | #if WIDE_CHAR 18 | wifstream fp_in; 19 | #else 20 | ifstream fp_in; 21 | #endif 22 | fp_in.open(file_name, ios::in); 23 | // Very inefficient. 24 | while (!fp_in.eof()) { 25 | s += fp_in.get(); 26 | } 27 | return s; 28 | } 29 | 30 | int main(int argc, char **argv) { 31 | if (argc < 2) { 32 | cout << "Usage: wjavaparser " << endl; 33 | exit(1); 34 | } 35 | JAVACC_STRING_TYPE s = ReadFileFully(argv[1]); 36 | CharStream *stream = new CharStream(s.c_str(), s.size() - 1, 1, 1); 37 | JavaParserTokenManager *scanner = new JavaParserTokenManager(stream); 38 | JavaParser parser(scanner); 39 | parser.setErrorHandler(new MyErrorHandler()); 40 | parser.CompilationUnit(); 41 | SimpleNode *root = (SimpleNode*)parser.jjtree.peekNode(); 42 | if (root) { 43 | JAVACC_STRING_TYPE buffer; 44 | #if WIDE_CHAR 45 | //root->dumpToBuffer(L" ", L"\n", &buffer); 46 | //wcout << buffer << "\n"; 47 | root->dump(L" "); 48 | #else 49 | root->dumpToBuffer(" ", "\n", &buffer); 50 | printf("%s\n", buffer.c_str()); 51 | #endif 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /examples/JavaGrammars/cpp/myparser.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | #include "gen/ErrorHandler.h" 35 | #include "gen/Token.h" 36 | #include "gen/JavaParser.h" 37 | 38 | namespace java { namespace parser { 39 | 40 | class MyParser { 41 | }; 42 | 43 | class MyErrorHandler: public ErrorHandler { 44 | virtual void handleUnexpectedToken(int expectedKind, JAVACC_STRING_TYPE expectedToken, Token *actual, JavaParser *parser) { } 45 | virtual void handleParseError(Token *last, Token *unexpected, JAVACC_SIMPLE_STRING production, JavaParser *parser) { } 46 | 47 | }; 48 | 49 | } } 50 | -------------------------------------------------------------------------------- /examples/JavaGrammars/cpp/mytm.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | class MyTm { 35 | }; 36 | -------------------------------------------------------------------------------- /examples/JavaGrammars/cpp/token_base.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | class TokenBase { }; 35 | -------------------------------------------------------------------------------- /examples/Lookahead/Example1.jj: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2023 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | PARSER_BEGIN(Example) 35 | 36 | public class Example { 37 | 38 | public static void main(String args[]) throws ParseException { 39 | Example parser = new Example(System.in); 40 | parser.Input(); 41 | } 42 | 43 | } 44 | 45 | PARSER_END(Example) 46 | 47 | SKIP : 48 | { 49 | " " 50 | | "\t" 51 | | "\n" 52 | | "\r" 53 | } 54 | 55 | void Input() : 56 | {} 57 | { 58 | "a" BC() "c" 59 | } 60 | 61 | void BC() : 62 | {} 63 | { 64 | "b" [ "c" ] 65 | } 66 | -------------------------------------------------------------------------------- /examples/Lookahead/Example10.jj: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2023 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | PARSER_BEGIN(Example) 35 | 36 | public class Example { 37 | 38 | public static void main(String args[]) throws ParseException { 39 | Example parser = new Example(System.in); 40 | parser.IfStm(); 41 | } 42 | 43 | } 44 | 45 | PARSER_END(Example) 46 | 47 | SKIP : 48 | { 49 | " " 50 | | "\t" 51 | | "\n" 52 | | "\r" 53 | } 54 | 55 | void IfStm() : 56 | {} 57 | { 58 | "if" C() S() [ "else" S() ] 59 | } 60 | 61 | void C() : 62 | {} 63 | { 64 | "TBD" 65 | } 66 | 67 | void S() : 68 | {} 69 | { 70 | "TBD" 71 | | 72 | IfStm() 73 | } 74 | -------------------------------------------------------------------------------- /examples/Lookahead/Example4.jj: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2023 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | PARSER_BEGIN(Example) 35 | 36 | public class Example { 37 | 38 | public static void main(String args[]) throws ParseException { 39 | Example parser = new Example(System.in); 40 | parser.identifier_list(); 41 | } 42 | 43 | } 44 | 45 | PARSER_END(Example) 46 | 47 | SKIP : 48 | { 49 | " " 50 | | "\t" 51 | | "\n" 52 | | "\r" 53 | } 54 | 55 | void identifier_list() : 56 | {} 57 | { 58 | ( "," )* 59 | } 60 | 61 | TOKEN [IGNORE_CASE] : 62 | { 63 | 64 | } 65 | -------------------------------------------------------------------------------- /examples/Lookahead/Example7.jj: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2023 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | PARSER_BEGIN(Example) 35 | 36 | public class Example { 37 | 38 | public static void main(String args[]) throws ParseException { 39 | Example parser = new Example(System.in); 40 | parser.funny_list(); 41 | } 42 | 43 | } 44 | 45 | PARSER_END(Example) 46 | 47 | SKIP : 48 | { 49 | " " 50 | | "\t" 51 | | "\n" 52 | | "\r" 53 | } 54 | 55 | void funny_list() : 56 | {} 57 | { 58 | "," ( "," )* 59 | } 60 | 61 | TOKEN [IGNORE_CASE] : 62 | { 63 | 64 | | 65 | 66 | } 67 | -------------------------------------------------------------------------------- /examples/Obfuscator/input/package1/Main.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | package package1; 35 | 36 | public class Main { 37 | 38 | public static void main(String[] args) { 39 | System.out.println("Calling incr 10 times..."); 40 | for (int i = 0; i < 10; i++) { 41 | System.out.println(package2.Incr.incr()); 42 | } 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /examples/Obfuscator/input/package2/Incr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | package package2; 35 | 36 | public class Incr { 37 | 38 | static private int count = 0; 39 | 40 | /** 41 | * Returns the next integer value each time it is called. The 42 | * state information is stored in the variable count. 43 | */ 44 | static public int incr() { 45 | return count++; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /examples/Obfuscator/maps: -------------------------------------------------------------------------------- 1 | // Mappings from original names to obfuscated names 2 | 3 | incr -> square_root; 4 | Incr -> MyMath; 5 | -------------------------------------------------------------------------------- /examples/Obfuscator/nochangeids: -------------------------------------------------------------------------------- 1 | // Identifiers that must not be obfuscated. 2 | 3 | System 4 | out 5 | println 6 | String 7 | -------------------------------------------------------------------------------- /examples/Obfuscator/useids: -------------------------------------------------------------------------------- 1 | // Obfuscated identifiers to use (preferably). 2 | 3 | fileName 4 | randomNumber 5 | html 6 | -------------------------------------------------------------------------------- /examples/Transformer/divide.toy: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006, Sun Microsystems, Inc. 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 13 | * contributors may be used to endorse or promote products derived from 14 | * this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 26 | * THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | class Test { 30 | 31 | int divide(int x, int y) { 32 | return x/y; 33 | } catch (ArithmeticException e) { 34 | return Integer.MAX_VALUE; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /findbugs-exclude.xml: -------------------------------------------------------------------------------- 1 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/etc/license-template.txt: -------------------------------------------------------------------------------- 1 | Copyright 2017-2025 Philip Helger, pgcc@helger.com 2 | 3 | Copyright 2011 Google Inc. All Rights Reserved. 4 | Author: sreeni@google.com (Sreeni Viswanadha) 5 | 6 | Copyright (c) 2006, Sun Microsystems, Inc. 7 | All rights reserved. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions are met: 11 | 12 | * Redistributions of source code must retain the above copyright notice, 13 | this list of conditions and the following disclaimer. 14 | * Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | * Neither the name of the Sun Microsystems, Inc. nor the names of its 18 | contributors may be used to endorse or promote products derived from 19 | this software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | THE POSSIBILITY OF SUCH DAMAGE. 32 | -------------------------------------------------------------------------------- /src/main/java/com/helger/pgcc/CPG.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | package com.helger.pgcc; 35 | 36 | import com.helger.annotation.concurrent.Immutable; 37 | 38 | @Immutable 39 | public final class CPG 40 | { 41 | /** Application/tool name */ 42 | public static final String APP_NAME = "ParserGeneratorCC"; 43 | public static final String CMDLINE_NAME = "pgcc"; 44 | 45 | private CPG () 46 | {} 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/helger/pgcc/jjdoc/package.html: -------------------------------------------------------------------------------- 1 | 2 | 37 | 39 | 40 | 41 | 43 | org.javacc.jjdoc 44 | 45 | 46 |

Generates BNF documentation from a grammar.

47 | 48 | 49 | -------------------------------------------------------------------------------- /src/main/java/com/helger/pgcc/jjtree/ASTBNFDeclaration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | package com.helger.pgcc.jjtree; 35 | 36 | public class ASTBNFDeclaration extends JJTreeNode 37 | { 38 | NodeScope m_node_scope; 39 | 40 | ASTBNFDeclaration (final int nID) 41 | { 42 | super (nID); 43 | } 44 | 45 | /** Accept the visitor. **/ 46 | @Override 47 | public Object jjtAccept (final JJTreeParserVisitor visitor, final Object data) 48 | { 49 | return visitor.visit (this, data); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/helger/pgcc/jjtree/ASTBNFNodeScope.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | package com.helger.pgcc.jjtree; 35 | 36 | public class ASTBNFNodeScope extends JJTreeNode 37 | { 38 | NodeScope m_node_scope; 39 | JJTreeNode m_expansion_unit; 40 | 41 | ASTBNFNodeScope (final int nID) 42 | { 43 | super (nID); 44 | } 45 | 46 | /** Accept the visitor. **/ 47 | @Override 48 | public Object jjtAccept (final JJTreeParserVisitor visitor, final Object data) 49 | { 50 | return visitor.visit (this, data); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/helger/pgcc/jjtree/ASTCompilationUnit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | package com.helger.pgcc.jjtree; 35 | 36 | public class ASTCompilationUnit extends JJTreeNode 37 | { 38 | ASTCompilationUnit (final int nID) 39 | { 40 | super (nID); 41 | } 42 | 43 | @Override 44 | public Object jjtAccept (final JJTreeParserVisitor visitor, final Object data) 45 | { 46 | return visitor.visit (this, data); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/helger/pgcc/jjtree/ASTExpansionNodeScope.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | package com.helger.pgcc.jjtree; 35 | 36 | public class ASTExpansionNodeScope extends JJTreeNode 37 | { 38 | NodeScope m_node_scope; 39 | JJTreeNode m_expansion_unit; 40 | 41 | ASTExpansionNodeScope (final int nID) 42 | { 43 | super (nID); 44 | } 45 | 46 | /** Accept the visitor. **/ 47 | @Override 48 | public Object jjtAccept (final JJTreeParserVisitor visitor, final Object data) 49 | { 50 | return visitor.visit (this, data); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/helger/pgcc/jjtree/ASTJavacode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | package com.helger.pgcc.jjtree; 35 | 36 | public class ASTJavacode extends ASTProduction 37 | { 38 | Token stmBeginLoc; 39 | 40 | ASTJavacode (final int nID) 41 | { 42 | super (nID); 43 | } 44 | 45 | /** Accept the visitor. **/ 46 | @Override 47 | public Object jjtAccept (final JJTreeParserVisitor visitor, final Object data) 48 | { 49 | return visitor.visit (this, data); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/helger/pgcc/jjtree/ASTJavacodeBody.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | package com.helger.pgcc.jjtree; 35 | 36 | public class ASTJavacodeBody extends JJTreeNode 37 | { 38 | NodeScope m_node_scope; 39 | 40 | ASTJavacodeBody (final int nID) 41 | { 42 | super (nID); 43 | } 44 | 45 | /** Accept the visitor. **/ 46 | @Override 47 | public Object jjtAccept (final JJTreeParserVisitor visitor, final Object data) 48 | { 49 | return visitor.visit (this, data); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/helger/pgcc/jjtree/ASTLHS.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | package com.helger.pgcc.jjtree; 35 | 36 | public class ASTLHS extends JJTreeNode 37 | { 38 | ASTLHS (final int nID) 39 | { 40 | super (nID); 41 | } 42 | 43 | @Override 44 | public Object jjtAccept (final JJTreeParserVisitor visitor, final Object data) 45 | { 46 | return visitor.visit (this, data); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/helger/pgcc/jjtree/ASTNodeDescriptorExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | package com.helger.pgcc.jjtree; 35 | 36 | public class ASTNodeDescriptorExpression extends JJTreeNode 37 | { 38 | ASTNodeDescriptorExpression (final int nID) 39 | { 40 | super (nID); 41 | } 42 | 43 | @Override 44 | String translateImage (final Token t) 45 | { 46 | return whiteOut (t); 47 | } 48 | 49 | /** Accept the visitor. **/ 50 | @Override 51 | public Object jjtAccept (final JJTreeParserVisitor visitor, final Object data) 52 | { 53 | return visitor.visit (this, data); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/helger/pgcc/jjtree/ASTOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | package com.helger.pgcc.jjtree; 35 | 36 | public class ASTOptions extends JJTreeNode 37 | { 38 | public ASTOptions (final int nID) 39 | { 40 | super (nID); 41 | } 42 | 43 | /** Accept the visitor. **/ 44 | @Override 45 | public Object jjtAccept (final JJTreeParserVisitor visitor, final Object data) 46 | { 47 | return visitor.visit (this, data); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/helger/pgcc/jjtree/Main.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | package com.helger.pgcc.jjtree; 35 | 36 | import com.helger.base.state.ESuccess; 37 | 38 | /** 39 | * Entry point. 40 | */ 41 | public final class Main 42 | { 43 | private Main () 44 | {} 45 | 46 | public static void main (final String args[]) 47 | { 48 | final JJTree jjtree = new JJTree (); 49 | final ESuccess eSuccess = jjtree.main (args); 50 | System.exit (eSuccess.isFailure () ? 1 : 0); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/helger/pgcc/jjtree/package.html: -------------------------------------------------------------------------------- 1 | 2 | 37 | 39 | 40 | 41 | 43 | org.javacc.jjtree 44 | 45 | 46 |

A tree generator.

47 | 48 | 49 | -------------------------------------------------------------------------------- /src/main/java/com/helger/pgcc/output/UnsupportedOutputLanguageException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | package com.helger.pgcc.output; 35 | 36 | import jakarta.annotation.Nonnull; 37 | 38 | public class UnsupportedOutputLanguageException extends RuntimeException 39 | { 40 | public UnsupportedOutputLanguageException (@Nonnull final EOutputLanguage eOutputLanguage) 41 | { 42 | super ("Unsupported output language: " + eOutputLanguage); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/helger/pgcc/package.html: -------------------------------------------------------------------------------- 1 | 2 | 37 | 39 | 40 | 41 | 43 | org.javacc 44 | 45 | 46 |

A tree, grammar and lexer generator and a documentation generator.

47 | 48 | 49 | -------------------------------------------------------------------------------- /src/main/java/com/helger/pgcc/parser/CodeProductionCpp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | package com.helger.pgcc.parser; 35 | 36 | /** 37 | * Describes CPPCODE productions. 38 | */ 39 | public class CodeProductionCpp extends AbstractCodeProduction 40 | {} 41 | -------------------------------------------------------------------------------- /src/main/java/com/helger/pgcc/parser/CodeProductionJava.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | package com.helger.pgcc.parser; 35 | 36 | /** 37 | * Describes JAVACODE productions. 38 | */ 39 | public class CodeProductionJava extends AbstractCodeProduction 40 | {} 41 | -------------------------------------------------------------------------------- /src/main/java/com/helger/pgcc/parser/Container.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | package com.helger.pgcc.parser; 35 | 36 | /** 37 | * An object container. Used to pass references to objects as parameter. 38 | */ 39 | 40 | public final class Container 41 | { 42 | public Object member; 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/helger/pgcc/parser/ETokenKind.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | package com.helger.pgcc.parser; 35 | 36 | /** 37 | * Definitions of constants that identify the kind of regular expression 38 | * production this is. 39 | * 40 | * @author Philip Helger 41 | * @since 1.1.0 42 | */ 43 | public enum ETokenKind 44 | { 45 | TOKEN, 46 | SKIP, 47 | MORE, 48 | SPECIAL; 49 | 50 | public String getImage () 51 | { 52 | return name (); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/helger/pgcc/parser/MatchInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | package com.helger.pgcc.parser; 35 | 36 | /** 37 | * Describes a match, within a given lookahead. 38 | */ 39 | public class MatchInfo 40 | { 41 | public static int s_laLimit; 42 | 43 | int [] m_match = new int [s_laLimit]; 44 | int m_firstFreeLoc; 45 | 46 | public static void reInitStatic () 47 | { 48 | s_laLimit = 0; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/helger/pgcc/parser/MetaParseException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | package com.helger.pgcc.parser; 35 | 36 | /** 37 | * Thrown when there is a mis-configuration or a bug. 38 | */ 39 | public class MetaParseException extends ParseException 40 | { 41 | public MetaParseException (final String sMsg) 42 | { 43 | super (sMsg); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/helger/pgcc/parser/ParserData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | package com.helger.pgcc.parser; 35 | 36 | import java.util.List; 37 | import java.util.Map; 38 | 39 | public class ParserData 40 | { 41 | public enum LookaheadType 42 | { 43 | TOKEN, 44 | PRODUCTION, 45 | SEQUENCE, 46 | CHOICE, 47 | ZERORORMORE 48 | } 49 | 50 | public static class LookaheadInfo 51 | { 52 | public LookaheadType lokaheadType; 53 | public List data; 54 | } 55 | 56 | Map > lookaheads; 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/helger/pgcc/parser/exp/ExpREndOfFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | package com.helger.pgcc.parser.exp; 35 | 36 | import com.helger.pgcc.parser.Nfa; 37 | 38 | /** 39 | * Describes the EOF regular expression 40 | */ 41 | 42 | public class ExpREndOfFile extends AbstractExpRegularExpression 43 | { 44 | @Override 45 | public Nfa generateNfa (final boolean ignoreCase) 46 | { 47 | return null; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/helger/pgcc/parser/exp/ICCCharacter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | package com.helger.pgcc.parser.exp; 35 | 36 | import java.io.Serializable; 37 | 38 | /** 39 | * Marker interface 40 | * 41 | * @author Philip Helger 42 | */ 43 | public interface ICCCharacter extends Serializable 44 | { 45 | // empty 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/helger/pgcc/parser/package.html: -------------------------------------------------------------------------------- 1 | 2 | 37 | 39 | 40 | 41 | 43 | org.javacc.parser 44 | 45 | 46 |

A grammar and lexer generator.

47 | 48 | 49 | -------------------------------------------------------------------------------- /src/main/java/com/helger/pgcc/utils/EOptionType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | package com.helger.pgcc.utils; 35 | 36 | /** 37 | * @author Chris Ainsley 38 | */ 39 | public enum EOptionType 40 | { 41 | BOOLEAN, 42 | INTEGER, 43 | STRING, 44 | OTHER; 45 | } 46 | -------------------------------------------------------------------------------- /src/main/resources/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2017-2018 Philip Helger, pgcc@helger.com 2 | 3 | Copyright 2011 Google Inc. All Rights Reserved. 4 | Author: sreeni@google.com (Sreeni Viswanadha) 5 | 6 | Copyright (c) 2006, Sun Microsystems, Inc. 7 | All rights reserved. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions are met: 11 | 12 | * Redistributions of source code must retain the above copyright notice, 13 | this list of conditions and the following disclaimer. 14 | * Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | * Neither the name of the Sun Microsystems, Inc. nor the names of its 18 | contributors may be used to endorse or promote products derived from 19 | this software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | THE POSSIBILITY OF SUCH DAMAGE. 32 | -------------------------------------------------------------------------------- /src/main/resources/NOTICE: -------------------------------------------------------------------------------- 1 | ============================================================================= 2 | = NOTICE file corresponding to section 4d of the Apache License Version 2.0 = 3 | ============================================================================= 4 | This product includes Open Source Software developed by 5 | Philip Helger - https://www.helger.com/ 6 | -------------------------------------------------------------------------------- /src/main/resources/pgcc-version.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | # 4 | # Copyright 2011 Google Inc. All Rights Reserved. 5 | # Author: sreeni@google.com (Sreeni Viswanadha) 6 | # 7 | # Copyright (c) 2006, Sun Microsystems, Inc. 8 | # All rights reserved. 9 | # 10 | # Redistribution and use in source and binary forms, with or without 11 | # modification, are permitted provided that the following conditions are met: 12 | # 13 | # * Redistributions of source code must retain the above copyright notice, 14 | # this list of conditions and the following disclaimer. 15 | # * Redistributions in binary form must reproduce the above copyright 16 | # notice, this list of conditions and the following disclaimer in the 17 | # documentation and/or other materials provided with the distribution. 18 | # * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | # contributors may be used to endorse or promote products derived from 20 | # this software without specific prior written permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | # THE POSSIBILITY OF SUCH DAMAGE. 33 | # 34 | 35 | # Project version number - this is generated automatically 36 | version=${project.version} 37 | -------------------------------------------------------------------------------- /src/main/resources/templates/DumpDebugMethods.template: -------------------------------------------------------------------------------- 1 | int kindCnt = 0; 2 | protected final String jjKindsForBitVector(int i, long vec) 3 | { 4 | String retVal = ""; 5 | if (i == 0) 6 | kindCnt = 0; 7 | for (int j = 0; j < 64; j++) 8 | { 9 | if ((vec & (1L << j)) != 0L) 10 | { 11 | if (kindCnt++ > 0) 12 | retVal += ", "; 13 | if (kindCnt % 5 == 0) 14 | retVal += "\n "; 15 | retVal += tokenImage[i * 64 + j]; 16 | } 17 | } 18 | return retVal; 19 | } 20 | 21 | 22 | protected final String jjKindsForStateVector(int lexState, int[] vec, int start, int end) 23 | { 24 | boolean[] kindDone = new boolean[${maxOrdinal}]; 25 | String retVal = ""; 26 | int cnt = 0; 27 | for (int i = start; i < end; i++) 28 | { 29 | if (vec[i] == -1) 30 | continue; 31 | int[] stateSet = States.statesForState[curLexState][vec[i]]; 32 | for (int j = 0; j < stateSet.length; j++) 33 | { 34 | int state = stateSet[j]; 35 | if (!kindDone[Kinds.kindForState[lexState][state]]) 36 | { 37 | kindDone[Kinds.kindForState[lexState][state]] = true; 38 | if (cnt++ > 0) 39 | retVal += ", "; 40 | if (cnt % 5 == 0) 41 | retVal += "\n "; 42 | retVal += tokenImage[Kinds.kindForState[lexState][state]]; 43 | } 44 | } 45 | } 46 | if (cnt == 0) 47 | return "{ }"; 48 | else 49 | return "{ " + retVal + " }"; 50 | } 51 | -------------------------------------------------------------------------------- /src/main/resources/templates/DumpStaticVarDeclarations.template: -------------------------------------------------------------------------------- 1 | protected ${charStreamName} input_stream; 2 | 3 | #if !TABLE_DRIVEN 4 | private final int[] jjrounds = new int[${stateSetSize}]; 5 | private final int[] jjstateSet = new int[2 * ${stateSetSize}]; 6 | #fi 7 | private final StringBuilder jjimage = new StringBuilder(); 8 | private StringBuilder image = jjimage; 9 | private int jjimageLen; 10 | private int lengthOfMatch; 11 | protected int curChar; 12 | -------------------------------------------------------------------------------- /src/main/resources/templates/TokenManager.template: -------------------------------------------------------------------------------- 1 | /** 2 | * An implementation for this interface is generated by 3 | * JavaCCParser. The user is free to use any implementation 4 | * of their choice. 5 | */ 6 | ${SUPPORT_CLASS_VISIBILITY_PUBLIC?public :}interface TokenManager { 7 | /** This gets the next token from the input stream. 8 | * A token of kind 0 (<EOF>) should be returned on EOF. 9 | * @return the next Token. Should not be null. 10 | */ 11 | Token getNextToken(); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/resources/templates/cpp/DumpDebugMethods.template: -------------------------------------------------------------------------------- 1 | const JJSimpleString ${tokMgrClassName}::jjKindsForBitVector(int i, unsigned long long vec) 2 | { 3 | int kindCnt = 0; 4 | JJSimpleString retVal; 5 | if (i == 0) 6 | kindCnt = 0; 7 | for (int j = 0; j < 64; j++) 8 | { 9 | if ((vec & (1L << j)) != 0L) 10 | { 11 | if (kindCnt++ > 0) 12 | retVal += ", "; 13 | if (kindCnt % 5 == 0) 14 | retVal += "\n "; 15 | retVal += addUnicodeEscapes(tokenImage[i * 64 + j]); 16 | } 17 | } 18 | 19 | return retVal; 20 | } 21 | 22 | const JJSimpleString ${tokMgrClassName}::jjKindsForStateVector(int lexState, int vec[], int start, int end) 23 | { 24 | bool kindDone[${maxOrdinal}]; 25 | JJSimpleString retVal; 26 | int cnt = 0; 27 | for (int i = start; i < end; i++) 28 | { 29 | if (vec[i] == -1) 30 | continue; 31 | const int *stateSet = statesForState[curLexState][vec[i]]; 32 | for (int j = 0; j < ${stateSetSize}; j++) 33 | { 34 | int state = stateSet[j]; 35 | if (!kindDone[kindForState[lexState][state]]) 36 | { 37 | kindDone[kindForState[lexState][state]] = true; 38 | if (cnt++ > 0) 39 | retVal += ", "; 40 | if (cnt % 5 == 0) 41 | retVal += "\n "; 42 | retVal += addUnicodeEscapes(tokenImage[kindForState[lexState][state]]); 43 | } 44 | } 45 | } 46 | if (cnt == 0) 47 | return "{ }"; 48 | else 49 | return "{ " + retVal + " }"; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /src/main/resources/templates/cpp/DumpVarDeclarations.template: -------------------------------------------------------------------------------- 1 | JAVACC_CHARSTREAM* input_stream; 2 | int jjrounds[${stateSetSize}]; 3 | int jjstateSet[2 * ${stateSetSize}]; 4 | JJString jjimage; 5 | JJString image; 6 | int jjimageLen; 7 | int lengthOfMatch; 8 | JJChar curChar; 9 | TokenManagerErrorHandler* errorHandler = nullptr; 10 | 11 | public: 12 | void setErrorHandler(TokenManagerErrorHandler *eh) { 13 | if (errorHandler) delete errorHandler, errorHandler = nullptr; 14 | errorHandler = eh; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/resources/templates/cpp/JavaCC.h.template: -------------------------------------------------------------------------------- 1 | \#ifndef JAVACC_JAVACC_H_ 2 | \#define JAVACC_JAVACC_H_ 3 | 4 | \#include 5 | \#include 6 | \#include 7 | \#include 8 | 9 | \#ifndef JAVACC_CHAR_TYPE 10 | \#define JAVACC_CHAR_TYPE char 11 | \#endif 12 | 13 | \#ifndef JAVACC_STRING_TYPE 14 | \#define JAVACC_STRING_TYPE std::basic_string 15 | \#endif 16 | 17 | \#define JAVACC_SIMPLE_STRING std::basic_string 18 | 19 | typedef JAVACC_CHAR_TYPE JJChar; 20 | typedef JAVACC_STRING_TYPE JJString; 21 | typedef JAVACC_STRING_TYPE JJStringBuffer; 22 | typedef JAVACC_SIMPLE_STRING JJSimpleString; 23 | 24 | // Abstraction on stream classes to read a block of data into a buffer. 25 | class ReaderStream { 26 | public: 27 | // Read block of data into a buffer and return the actual number read. 28 | virtual size_t read(JAVACC_CHAR_TYPE *buffer, int offset, size_t len) { return 0; } 29 | virtual bool endOfInput() { return true; } 30 | virtual ~ReaderStream() {} 31 | }; 32 | 33 | const JAVACC_CHAR_TYPE EMPTY[] = { 0 }; 34 | 35 | \#ifndef MAX 36 | \#define MAX(a,b) (a>=b?a:b) 37 | \#endif 38 | \#ifndef MIN 39 | \#define MIN(a,b) (a<=b?a:b) 40 | \#endif 41 | \#ifndef null 42 | \#define null 0 43 | \#endif 44 | 45 | template 46 | struct JJEnter 47 | { 48 | JJEnter(T f_) : f{f_} {f();} 49 | ~JJEnter(){} 50 | T f; 51 | }; 52 | template 53 | struct JJExit 54 | { 55 | JJExit(T f_) : f{f_} {} 56 | ~JJExit(){f();} 57 | T f; 58 | }; 59 | 60 | \#endif 61 | -------------------------------------------------------------------------------- /src/main/resources/templates/cpp/MultiNode.cc.template: -------------------------------------------------------------------------------- 1 | \#include "${NODE_TYPE}.h" 2 | \#include "JJTree.h" 3 | #if VISITOR 4 | \#include "${PARSER_NAME}Visitor.h" 5 | #fi 6 | 7 | _${NODE_TYPE}::_${NODE_TYPE}(int id) : ${NODE_CLASS:-_SimpleNode}(id){ 8 | } 9 | 10 | _${NODE_TYPE}::_${NODE_TYPE}(${PARSER_NAME} *p, int id) : ${NODE_CLASS:-_SimpleNode}(p, id){ 11 | } 12 | 13 | #if VISITOR 14 | 15 | /** Accept the visitor. **/ 16 | ${VISITOR_RETURN_TYPE} _${NODE_TYPE}::jjtAccept(${PARSER_NAME}Visitor visitor, ${VISITOR_DATA_TYPE:-Object} data) { 17 | #if VISITOR_RETURN_TYPE_VOID 18 | visitor->visit(this, data); 19 | #else 20 | return visitor->visit(this, data); 21 | #fi 22 | } 23 | 24 | _${NODE_TYPE}::~_${NODE_TYPE}() { 25 | } 26 | #fi 27 | -------------------------------------------------------------------------------- /src/main/resources/templates/cpp/MultiNode.h.template: -------------------------------------------------------------------------------- 1 | \#ifndef JAVACC_${NODE_TYPE}_H 2 | \#define JAVACC_${NODE_TYPE}_H 3 | 4 | \#include "JavaCC.h" 5 | \#include "SimpleNode.h" 6 | 7 | #if NODE_FACTORY 8 | \#define jjtCreate(id) new _${NODE_TYPE}(id) 9 | \#define jjtCreate(parser, id) new _${NODE_TYPE}(parser, id); 10 | #fi 11 | 12 | typedef class _${NODE_TYPE} *${NODE_TYPE}; 13 | class _${NODE_TYPE} : public ${NODE_CLASS:-_SimpleNode} { 14 | public: 15 | _${NODE_TYPE}(int id); 16 | _${NODE_TYPE}(${PARSER_NAME} *parser, int id); 17 | virtual ~_${NODE_TYPE}(); 18 | 19 | #if VISITOR 20 | /** Accept the visitor. **/ 21 | virtual ${VISITOR_RETURN_TYPE} jjtAccept(${PARSER_NAME}Visitor visitor, ${VISITOR_DATA_TYPE:-Object} data); 22 | #fi 23 | }; 24 | 25 | \#endif 26 | -------------------------------------------------------------------------------- /src/main/resources/templates/cpp/MultiNode.template: -------------------------------------------------------------------------------- 1 | 2 | class ${NODE_TYPE} : public ${NODE_CLASS:-SimpleNode} { 3 | public: 4 | ${NODE_TYPE}(int id) : ${NODE_CLASS:-SimpleNode}(id){ 5 | } 6 | ${NODE_TYPE}(${PARSER_NAME} *parser, int id) : ${NODE_CLASS:-SimpleNode}(parser, id) { 7 | } 8 | virtual ~${NODE_TYPE}(){ 9 | 10 | #if VISITOR 11 | /** Accept the visitor. **/ 12 | ${VISITOR_RETURN_TYPE} jjtAccept(${PARSER_NAME}Visitor *visitor, ${VISITOR_DATA_TYPE:-void *} data) const { 13 | #if !VISITOR_RETURN_TYPE_VOID 14 | return 15 | #fi 16 | #if VISITOR_METHOD_NAME_INCLUDES_TYPE_NAME 17 | visitor->visit${NODE_TYPE}(this, data); 18 | #else 19 | visitor->visit(this, data); 20 | #fi 21 | } 22 | } 23 | #fi 24 | }; 25 | -------------------------------------------------------------------------------- /src/main/resources/templates/cpp/TokenManager.h.template: -------------------------------------------------------------------------------- 1 | \#ifndef JAVACC_TOKENMANAGER_H 2 | \#define JAVACC_TOKENMANAGER_H 3 | 4 | \#include 5 | \#include "JavaCC.h" 6 | \#include "Token.h" 7 | 8 | #if NAMESPACE 9 | namespace ${NAMESPACE_OPEN} 10 | #fi 11 | /** 12 | * An implementation for this interface is generated by 13 | * JavaCCParser. The user is free to use any implementation 14 | * of their choice. 15 | */ 16 | 17 | class TokenManager { 18 | public: 19 | /** This gets the next token from the input stream. 20 | * A token of kind 0 () should be returned on EOF. 21 | */ 22 | virtual ~TokenManager() { } 23 | virtual Token *getNextToken() = 0; 24 | virtual void setParser(void* parser) {}; 25 | virtual void lexicalError() { 26 | std::cerr << "Lexical error encountered." << std::endl; 27 | } 28 | 29 | }; 30 | 31 | #if NAMESPACE 32 | ${NAMESPACE_CLOSE} 33 | #fi 34 | 35 | \#endif 36 | -------------------------------------------------------------------------------- /src/main/resources/templates/cpp/TokenManagerBoilerPlateMethods.template: -------------------------------------------------------------------------------- 1 | /** Reinitialise parser. */ 2 | void ${tokMgrClassName}::ReInit(JAVACC_CHARSTREAM *stream, int lexState) { 3 | clear(); 4 | jjmatchedPos = jjnewStateCnt = 0; 5 | curLexState = lexState; 6 | input_stream = stream; 7 | ReInitRounds(); 8 | debugStream = stdout; // init 9 | SwitchTo(lexState); 10 | errorHandler = new TokenManagerErrorHandler(); 11 | } 12 | 13 | void ${tokMgrClassName}::ReInitRounds() { 14 | int i; 15 | jjround = 0x80000001; 16 | for (i = ${stateSetSize}; i-- > 0;) 17 | jjrounds[i] = 0x80000000; 18 | } 19 | 20 | /** Switch to specified lex state. */ 21 | void ${tokMgrClassName}::SwitchTo(int lexState) { 22 | if (lexState >= ${lexStateNameLength} || lexState < 0) { 23 | JJString message; 24 | \#ifdef WIDE_CHAR 25 | message += L"Error: Ignoring invalid lexical state : "; 26 | message += lexState; message += L". State unchanged."; 27 | \#else 28 | message += "Error: Ignoring invalid lexical state : "; 29 | message += lexState; message += ". State unchanged."; 30 | \#endif 31 | throw new TokenMgrError(message, INVALID_LEXICAL_STATE); 32 | } else 33 | curLexState = lexState; 34 | } 35 | 36 | /** Constructor. */ 37 | ${tokMgrClassName}::${tokMgrClassName} (JAVACC_CHARSTREAM *stream, int lexState) 38 | #if TOKEN_MANAGER_SUPER_CLASS 39 | : ${TOKEN_MANAGER_SUPER_CLASS}() 40 | #fi 41 | { 42 | input_stream = nullptr; 43 | ReInit(stream, lexState); 44 | } 45 | 46 | // Destructor 47 | ${tokMgrClassName}::~${tokMgrClassName} () { 48 | clear(); 49 | } 50 | 51 | // clear 52 | void ${tokMgrClassName}::clear() { 53 | //Since input_stream was generated outside of TokenManager 54 | //TokenManager should not take care of deleting it 55 | //if (input_stream) delete input_stream; 56 | if (errorHandler) delete errorHandler, errorHandler = nullptr; 57 | } 58 | 59 | 60 | -------------------------------------------------------------------------------- /src/main/resources/templates/cpp/TreeIncludeHeader.template: -------------------------------------------------------------------------------- 1 | \#include 2 | \#include "JavaCC.h" 3 | \#include "Token.h" 4 | \#include "Node.h" 5 | \#include "${PARSER_NAME}TreeConstants.h" 6 | \#include "SimpleNode.h" 7 | 8 | #if NODE_INCLUDES 9 | \#include "${NODE_INCLUDES}" 10 | #fi 11 | 12 | -------------------------------------------------------------------------------- /src/main/resources/templates/jjtree/cpp/MultiNodeImpl.template: -------------------------------------------------------------------------------- 1 | \#include "${NODE_TYPE}.h" 2 | #if VISITOR 3 | \#include "${PARSER_NAME}Visitor.h" 4 | #fi 5 | 6 | #if NAMESPACE 7 | namespace ${NAMESPACE_OPEN} 8 | #fi 9 | 10 | ${NODE_TYPE}::${NODE_TYPE}(int id) : ${NODE_CLASS:-SimpleNode}(id) { 11 | } 12 | ${NODE_TYPE}::${NODE_TYPE}(${PARSER_NAME} *parser, int id) : ${NODE_CLASS:-SimpleNode}(parser, id) { 13 | } 14 | ${NODE_TYPE}::~${NODE_TYPE}() { 15 | } 16 | 17 | #if VISITOR 18 | /** Accept the visitor. **/ 19 | ${VISITOR_RETURN_TYPE} ${NODE_TYPE}::jjtAccept(${PARSER_NAME}Visitor *visitor, ${VISITOR_DATA_TYPE:-void *} data) const { 20 | #if !VISITOR_RETURN_TYPE_VOID 21 | return 22 | #fi 23 | #if VISITOR_METHOD_NAME_INCLUDES_TYPE_NAME 24 | visitor->visit${NODE_TYPE}(this, data); 25 | #else 26 | visitor->visit(this, data); 27 | #fi 28 | } 29 | #fi 30 | 31 | #if NAMESPACE 32 | ${NAMESPACE_CLOSE} 33 | #fi 34 | -------------------------------------------------------------------------------- /src/main/resources/templates/jjtree/cpp/MultiNodeInterface.template: -------------------------------------------------------------------------------- 1 | \#ifndef ${NODE_TYPE}_H_ 2 | \#define ${NODE_TYPE}_H_ 3 | 4 | \#include "${NODE_CLASS:-SimpleNode}.h" 5 | 6 | #if NAMESPACE 7 | namespace ${NAMESPACE_OPEN} 8 | #fi 9 | class ${PARSER_NAME}; 10 | 11 | class ${NODE_TYPE} : public ${NODE_CLASS:-SimpleNode} { 12 | public: 13 | ${NODE_TYPE}(int id); 14 | ${NODE_TYPE}(${PARSER_NAME} *parser, int id); 15 | virtual ~${NODE_TYPE}(); 16 | 17 | #if VISITOR 18 | /** Accept the visitor. **/ 19 | virtual ${VISITOR_RETURN_TYPE} jjtAccept(${PARSER_NAME}Visitor *visitor, ${VISITOR_DATA_TYPE:-void *} data) const ; 20 | #fi 21 | }; 22 | 23 | #if NAMESPACE 24 | ${NAMESPACE_CLOSE} 25 | #fi 26 | 27 | \#endif 28 | -------------------------------------------------------------------------------- /src/main/resources/templates/jjtree/cpp/_unused_TreeImplHeader.template: -------------------------------------------------------------------------------- 1 | \#include "${PARSER_NAME}Tree.h" 2 | #if VISITOR 3 | \#include "${PARSER_NAME}Visitor.h" 4 | #fi 5 | -------------------------------------------------------------------------------- /src/main/resources/templates/jjtree/java/MultiNode.template: -------------------------------------------------------------------------------- 1 | #if SUPPORT_CLASS_VISIBILITY_PUBLIC 2 | public 3 | #fi 4 | class ${NODE_TYPE} extends ${NODE_CLASS:-SimpleNode} { 5 | public ${NODE_TYPE}(int id) { 6 | super(id); 7 | } 8 | 9 | public ${NODE_TYPE}(${PARSER_NAME} p, int id) { 10 | super(p, id); 11 | } 12 | 13 | #if NODE_FACTORY 14 | public static Node jjtCreate(int id) { 15 | return new ${NODE_TYPE}(id); 16 | } 17 | 18 | public static Node jjtCreate(${PARSER_NAME} p, int id) { 19 | return new ${NODE_TYPE}(p, id); 20 | } 21 | #fi 22 | #if VISITOR 23 | 24 | /** Accept the visitor. **/ 25 | #if VISITOR_EXCEPTION 26 | public ${VISITOR_RETURN_TYPE} jjtAccept(${PARSER_NAME}Visitor visitor, ${VISITOR_DATA_TYPE:-Object} data) throws ${VISITOR_EXCEPTION} { 27 | #else 28 | public ${VISITOR_RETURN_TYPE} jjtAccept(${PARSER_NAME}Visitor visitor, ${VISITOR_DATA_TYPE:-Object} data) { 29 | #fi 30 | #if VISITOR_RETURN_TYPE_VOID 31 | #else 32 | return 33 | #fi 34 | #if VISITOR_METHOD_NAME_INCLUDES_TYPE_NAME 35 | visitor.visit${NODE_TYPE}(this, data); 36 | #else 37 | visitor.visit(this, data); 38 | #fi 39 | } 40 | #fi 41 | } 42 | -------------------------------------------------------------------------------- /src/main/resources/templates/jjtree/java/Node.template: -------------------------------------------------------------------------------- 1 | /* All AST nodes must implement this interface. It provides basic 2 | machinery for constructing the parent and child relationships 3 | between nodes. */ 4 | 5 | #if SUPPORT_CLASS_VISIBILITY_PUBLIC 6 | public 7 | #fi 8 | interface Node extends java.io.Serializable { 9 | /** This method is called after the node has been made the current 10 | node. It indicates that child nodes can now be added to it. */ 11 | void jjtOpen(); 12 | 13 | /** This method is called after all the child nodes have been 14 | added. */ 15 | void jjtClose(); 16 | 17 | /** 18 | * Set the parent node of this node 19 | * @param n parent node to set 20 | */ 21 | void jjtSetParent(Node n); 22 | 23 | /** 24 | * @return parent node 25 | */ 26 | Node jjtGetParent(); 27 | 28 | /** 29 | * This method tells the node to add its argument to the node's 30 | * list of children. 31 | * @param n node to add as a child 32 | * @param i zero-based index where to add the child 33 | */ 34 | void jjtAddChild(Node n, int i); 35 | 36 | /** 37 | * This method returns a child node. The children are numbered 38 | * from zero, left to right. 39 | * @param i zero-baeed child index 40 | */ 41 | Node jjtGetChild(int i); 42 | 43 | /** 44 | * @return the number of children the node has. Always ≥ 0. 45 | */ 46 | int jjtGetNumChildren(); 47 | 48 | int getId(); 49 | #if VISITOR 50 | 51 | /** Accept the visitor. **/ 52 | #if VISITOR_EXCEPTION 53 | ${VISITOR_RETURN_TYPE} jjtAccept(${PARSER_NAME}Visitor visitor, ${VISITOR_DATA_TYPE:-Object} data) throws ${VISITOR_EXCEPTION}; 54 | #else 55 | ${VISITOR_RETURN_TYPE} jjtAccept(${PARSER_NAME}Visitor visitor, ${VISITOR_DATA_TYPE:-Object} data); 56 | #fi 57 | #fi 58 | } 59 | -------------------------------------------------------------------------------- /src/main/resources/templates/stream/java/modern/Provider.template: -------------------------------------------------------------------------------- 1 | import java.io.IOException; 2 | 3 | /** 4 | * Abstract interface for reading from a stream. 5 | * The buffering should be done internally. 6 | */ 7 | public interface Provider extends java.io.Closeable 8 | { 9 | /** 10 | * Reads characters into an array 11 | * 12 | * @param aDest Destination buffer. May not be null. 13 | * @param nOfs Offset at which to start storing characters. Must be ≥ 0. 14 | * @param nLen The maximum possible number of characters to read. Must be ≥ 0. 15 | * @return The number of characters read, or -1 at the end of the stream 16 | * @exception IOException if reading fails 17 | */ 18 | int read (char [] aDest, int nOfs, int nLen) throws IOException; 19 | } 20 | -------------------------------------------------------------------------------- /src/main/resources/templates/stream/java/modern/SimpleCharStream.template: -------------------------------------------------------------------------------- 1 | /** 2 | * An implementation of interface CharStream, where the stream is assumed to 3 | * contain only ASCII characters (without unicode processing). 4 | */ 5 | #if SUPPORT_CLASS_VISIBILITY_PUBLIC 6 | public 7 | #fi 8 | class SimpleCharStream extends AbstractCharStream 9 | { 10 | private Provider inputStream; 11 | 12 | @Override 13 | protected int streamRead (final char[] aBuf, final int nOfs, final int nLen) throws java.io.IOException 14 | { 15 | return inputStream.read (aBuf, nOfs, nLen); 16 | } 17 | 18 | @Override 19 | protected void streamClose() throws java.io.IOException 20 | { 21 | inputStream.close (); 22 | } 23 | 24 | /** Constructor. */ 25 | public SimpleCharStream(final Provider dstream, 26 | final int startline, 27 | final int startcolumn, 28 | final int buffersize) 29 | { 30 | super (startline, startcolumn, buffersize); 31 | inputStream = dstream; 32 | } 33 | 34 | /** Constructor. */ 35 | public SimpleCharStream(final Provider dstream, 36 | final int startline, 37 | final int startcolumn) 38 | { 39 | this(dstream, startline, startcolumn, DEFAULT_BUF_SIZE); 40 | } 41 | 42 | /** Constructor. */ 43 | public SimpleCharStream(final Provider dstream) 44 | { 45 | this(dstream, 1, 1, DEFAULT_BUF_SIZE); 46 | } 47 | 48 | /** Reinitialise. */ 49 | public void reInit(final Provider dstream, 50 | final int startline, 51 | final int startcolumn, 52 | final int buffersize) 53 | { 54 | inputStream = dstream; 55 | super.reInit (startline, startcolumn, buffersize); 56 | } 57 | 58 | /** Reinitialise. */ 59 | public void reInit(final Provider dstream, 60 | final int startline, 61 | final int startcolumn) 62 | { 63 | reInit(dstream, startline, startcolumn, DEFAULT_BUF_SIZE); 64 | } 65 | 66 | /** Reinitialise. */ 67 | public void reInit(final Provider dstream) 68 | { 69 | reInit(dstream, 1, 1, DEFAULT_BUF_SIZE); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/resources/templates/stream/java/modern/StreamProvider.template: -------------------------------------------------------------------------------- 1 | 2 | import java.io.BufferedReader; 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.io.InputStreamReader; 6 | import java.io.Reader; 7 | 8 | /** 9 | * NOTE : This generated class can be safely deleted if installing in a GWT installation (use StringProvider instead) 10 | */ 11 | public class StreamProvider implements Provider 12 | { 13 | private Reader m_aReader; 14 | 15 | #if AT_LEAST_JDK6 16 | @Deprecated 17 | #fi 18 | public StreamProvider(final InputStream stream, final String charsetName) throws IOException 19 | { 20 | this (new BufferedReader (new InputStreamReader (stream, charsetName))); 21 | } 22 | 23 | public StreamProvider(final InputStream stream, final java.nio.charset.Charset charset) 24 | { 25 | this (new BufferedReader (new InputStreamReader (stream, charset))); 26 | } 27 | 28 | public StreamProvider (final Reader reader) 29 | { 30 | m_aReader = reader; 31 | } 32 | 33 | public int read (final char[] aDest, final int nOfs, final int nLen) throws IOException 34 | { 35 | int result = m_aReader.read(aDest, nOfs, nLen); 36 | 37 | /* CBA -- Added 2014/03/29 -- 38 | This logic allows the generated Java code to be easily translated to C# (via sharpen) - 39 | as in C# 0 represents end of file, and in Java, -1 represents end of file 40 | See : http://msdn.microsoft.com/en-us/library/9kstw824(v=vs.110).aspx 41 | ** Technically, this is not required for java but the overhead is extremely low compared to the code generation benefits. 42 | */ 43 | if (result == 0) 44 | if (nOfs < aDest.length && nLen > 0) 45 | result = -1; 46 | 47 | return result; 48 | } 49 | 50 | public void close () throws IOException 51 | { 52 | if (m_aReader != null) 53 | m_aReader.close(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/resources/templates/stream/java/modern/StringProvider.template: -------------------------------------------------------------------------------- 1 | 2 | import java.io.IOException; 3 | 4 | public class StringProvider implements Provider 5 | { 6 | private String m_sStr; 7 | private int m_nPos = 0; 8 | private final int m_nLen; 9 | 10 | public StringProvider(final String sStr) 11 | { 12 | m_sStr = sStr; 13 | m_nLen = sStr.length(); 14 | } 15 | 16 | public int read (final char[] aDest, final int nOfs, final int nLen) throws IOException 17 | { 18 | final int nLeft = m_nLen - m_nPos; 19 | if (nLeft <= 0) 20 | return -1; 21 | 22 | int nCharsRead = aDest.length - nOfs; 23 | if (nLen < nCharsRead) 24 | nCharsRead = nLen; 25 | if (nLeft < nCharsRead) 26 | nCharsRead = nLeft; 27 | 28 | m_sStr.getChars(m_nPos, m_nPos + nCharsRead, aDest, nOfs); 29 | m_nPos += nCharsRead; 30 | 31 | return nCharsRead; 32 | } 33 | 34 | public void close() 35 | { 36 | m_sStr = null; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/resources/issues/20/grammar.jj: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2023 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | PARSER_BEGIN(IssueParser) 35 | public class IssueParser { 36 | } 37 | PARSER_END(IssueParser) 38 | 39 | TOKEN : 40 | { 41 | < LITERAL_EXPRESSION: 42 | ((~["\\", "$", "#"]) 43 | | ("\\" ("\\" | "$" | "#")) 44 | | ("$" ~["{", "$"]) 45 | | ("#" ~["{", "#"]) 46 | )+ 47 | | "$" 48 | | "#" 49 | > 50 | | 51 | < START_DYNAMIC_EXPRESSION: "${" > {stack.push(DEFAULT);}: 52 | IN_EXPRESSION 53 | | 54 | < START_DEFERRED_EXPRESSION: "#{" > {stack.push(DEFAULT);}: 55 | IN_EXPRESSION 56 | } 57 | SKIP : { "\\" } 58 | SKIP : { "#" } 59 | 60 | -------------------------------------------------------------------------------- /test/javaFileGeneration/README.txt: -------------------------------------------------------------------------------- 1 | ==== 2 | Copyright 2017-2018 Philip Helger, pgcc@helger.com 3 | 4 | Copyright 2011 Google Inc. All Rights Reserved. 5 | Author: sreeni@google.com (Sreeni Viswanadha) 6 | 7 | Copyright (c) 2006, Sun Microsystems, Inc. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, 14 | this list of conditions and the following disclaimer. 15 | * Redistributions in binary form must reproduce the above copyright 16 | notice, this list of conditions and the following disclaimer in the 17 | documentation and/or other materials provided with the distribution. 18 | * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | contributors may be used to endorse or promote products derived from 20 | this software without specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | THE POSSIBILITY OF SUCH DAMAGE. 33 | ==== 34 | 35 | Tests the contents of the near bolier-plate Java Files, created by 36 | JavaFiles.java. 37 | -------------------------------------------------------------------------------- /test/javaFileGeneration/expected/generated.txt: -------------------------------------------------------------------------------- 1 | ==== 2 | Copyright 2017-2018 Philip Helger, pgcc@helger.com 3 | 4 | Copyright 2011 Google Inc. All Rights Reserved. 5 | Author: sreeni@google.com (Sreeni Viswanadha) 6 | 7 | Copyright (c) 2006, Sun Microsystems, Inc. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, 14 | this list of conditions and the following disclaimer. 15 | * Redistributions in binary form must reproduce the above copyright 16 | notice, this list of conditions and the following disclaimer in the 17 | documentation and/or other materials provided with the distribution. 18 | * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | contributors may be used to endorse or promote products derived from 20 | this software without specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | THE POSSIBILITY OF SUCH DAMAGE. 33 | ==== 34 | 35 | Hello, world 36 | But this should 37 | -->someString<-- 38 | 39 | True1 40 | someString 41 | Should be here 42 | True2 43 | 44 | This should say no: no 45 | This should say yes: yes 46 | 47 | This should say someString: someString 48 | This should say xxsomeStringxx: xxsomeStringxx 49 | 50 | The end. 51 | -------------------------------------------------------------------------------- /test/javaFiles/README.txt: -------------------------------------------------------------------------------- 1 | ==== 2 | Copyright 2017-2018 Philip Helger, pgcc@helger.com 3 | 4 | Copyright 2011 Google Inc. All Rights Reserved. 5 | Author: sreeni@google.com (Sreeni Viswanadha) 6 | 7 | Copyright (c) 2006, Sun Microsystems, Inc. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, 14 | this list of conditions and the following disclaimer. 15 | * Redistributions in binary form must reproduce the above copyright 16 | notice, this list of conditions and the following disclaimer in the 17 | documentation and/or other materials provided with the distribution. 18 | * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | contributors may be used to endorse or promote products derived from 20 | this software without specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | THE POSSIBILITY OF SUCH DAMAGE. 33 | ==== 34 | 35 | Tests the creation of the near bolier-plate Java Files, created by 36 | JavaFiles.java. It checks that files are recreated automatically if 37 | they are unchanged, but not modified if they have changed. It also 38 | checks that incompatible options are handled correctly. 39 | 40 | See also "javaFileGeneration" test, which checks the contents of the files. 41 | -------------------------------------------------------------------------------- /www/styles.css: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017-2025 Philip Helger, pgcc@helger.com 3 | * 4 | * Copyright 2011 Google Inc. All Rights Reserved. 5 | * Author: sreeni@google.com (Sreeni Viswanadha) 6 | * 7 | * Copyright (c) 2006, Sun Microsystems, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of the Sun Microsystems, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | li { 35 | padding: 2px; 36 | } 37 | pre { 38 | background-color:#F0F1F5; 39 | } --------------------------------------------------------------------------------