⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readme

📁 java 编译器java复杂编译器,可以编译java文件的类库
💻
字号:
/* * Copyright © 2002 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, * California 95054, U.S.A. All rights reserved.  Sun Microsystems, Inc. has * intellectual property rights relating to technology embodied in the product * that is described in this document. In particular, and without limitation, * these intellectual property rights may include one or more of the U.S. * patents listed at http://www.sun.com/patents and one or more additional * patents or pending patent applications in the U.S. and in other countries. * U.S. Government Rights - Commercial software. Government users are subject * to the Sun Microsystems, Inc. standard license agreement and applicable * provisions of the FAR and its supplements.  Use is subject to license terms. * Sun,  Sun Microsystems,  the Sun logo and  Java are trademarks or registered * trademarks of Sun Microsystems, Inc. in the U.S. and other countries.  This * product is covered and controlled by U.S. Export Control laws and may be * subject to the export or import laws in other countries.  Nuclear, missile, * chemical biological weapons or nuclear maritime end uses or end users, * whether direct or indirect, are strictly prohibited.  Export or reexport * to countries subject to U.S. embargo or to entities identified on U.S. * export exclusion lists, including, but not limited to, the denied persons * and specially designated nationals lists is strictly prohibited. */JJTreeExamplesThis directory contains some simple JJTree input files intended toillustrate some of the basic ideas.  All of them are based on angrammar to recognize arithmetic expressions built out of identifiersand constants.eg1.jjtThis example is just the JavaCC grammar, with a little extra code inthe parser's main method to call the dump method on the generatedtree.  It illustrates how the default behavior of JJTree will producea tree of non-terminals.eg2.jjtThis example is the same grammar as eg1.jjt with modifications tocustomize the generated tree.  It illustrates how unnecessaryintermediate nodes can be suppressed, and how actions in the grammarcan attach extra information to the nodes.eg3.jjtThis example is a modification of eg2.jjt with the NODE_DEFAULT_VOIDoption set.  This instructs JJTree to treat all undecoratednon-terminals as if they were decorated as #void. The default JJTreebehavior is to treat such non-terminals as if they were decoratedwith the name of the non-terminal.eg4.jjtThis is a modification of eg3.jjt with the VISITOR option set.  Thisinstructs JJTree to insert a jjtAccept() method into all nodes itgenerates, and to produce a visitor class.  The visitor is used todump the tree.Here are some instructions on how to run the examples and the outputyou can expect to see.eg1.jjt-------The only bit of JJTree-specific code is an action in the startproduction that dumps the constructed parse tree when the parse iscomplete.  It uses JJTree simple mode.The input file is eg1.jjt.trane% jjtree eg1.jjtJava Compiler Compiler Version 2.0 (Tree Builder)Copyright (c) 1996-1999 Sun Microsystems, Inc.Copyright (c) 1997-1999 Metamata, Inc.(type "jjtree" with no arguments for help)Reading from file eg1.jjt . . .File "Node.java" does not exist.  Will create one.File "SimpleNode.java" does not exist.  Will create one.Annotated grammar generated successfully in eg1.jjtrane% JJTree has now generated the JavaCC parser source, as well as Javasource for the parse tree node building classes.  Running JavaCC inthe normal way generates the remaining Java code.trane% javacc eg1.jjJava Compiler Compiler Version 2.0 (Parser Generator)Copyright (c) 1996-1999 Sun Microsystems, Inc.Copyright (c) 1997-1999 Metamata, Inc.(type "javacc" with no arguments for help)Reading from file eg1.jj . . .File "TokenMgrError.java" does not exist.  Will create one.File "ParseException.java" does not exist.  Will create one.File "Token.java" does not exist.  Will create one.File "ASCII_CharStream.java" does not exist.  Will create one.Parser generated successfully.trane% Compile and run the Java as usual.  The expression is read from thestandard input (you type in "(a + b) * (c + 1);"):trane% javac eg1.javatrane% java eg1Reading from standard input...(a + b) * (c + 1);Start Expression  AdditiveExpression   MultiplicativeExpression    UnaryExpression     Expression      AdditiveExpression       MultiplicativeExpression        UnaryExpression         Identifier       MultiplicativeExpression        UnaryExpression         Identifier    UnaryExpression     Expression      AdditiveExpression       MultiplicativeExpression        UnaryExpression         Identifier       MultiplicativeExpression        UnaryExpression         IntegerThank you.trane% eg2.jjt-------This is a modification of the first example to illustrate how theparse tree can be customized:trane% jjtree eg2.jjt Java Compiler Compiler Version 2.0 (Tree Builder)Copyright (c) 1996-1999 Sun Microsystems, Inc.Copyright (c) 1997-1999 Metamata, Inc.(type "jjtree" with no arguments for help)Reading from file eg2.jjt . . .File "Node.java" does not exist.  Will create one.File "SimpleNode.java" does not exist.  Will create one.File "ASTStart.java" does not exist.  Will create one.File "ASTAdd.java" does not exist.  Will create one.File "ASTMult.java" does not exist.  Will create one.File "ASTInteger.java" does not exist.  Will create one.Annotated grammar generated successfully in eg2.jjtrane% trane% javacc eg2.jjJava Compiler Compiler Version 2.0 (Parser Generator)Copyright (c) 1996-1999 Sun Microsystems, Inc.Copyright (c) 1997-1999 Metamata, Inc.(type "javacc" with no arguments for help)Reading from file eg2.jj . . .File "TokenMgrError.java" does not exist.  Will create one.File "ParseException.java" does not exist.  Will create one.File "Token.java" does not exist.  Will create one.File "ASCII_CharStream.java" does not exist.  Will create one.Parser generated successfully.trane% trane% javac eg2.javatrane% java eg2Reading from standard input...(a + b) * (c + 1);Start Mult  Add   Identifier: a   Identifier: b  Add   Identifier: c   IntegerThank you.trane% Look at eg2.jjt to see how node annotations can be used to restructurethe parse tree, and at ASTMyID.java to see how you can write your ownnode classes that maintain more information from the input stream.eg3.jjt-------This example can be run in the same manner as you ran eg2.jjt.eg4.jjt-------This example again can be run in the same manner as you ran eg2.jjt.One thing to take care in this case is that you must run jjtree ona clean directory (that does not contain previously generated files).For example, the file SimpleNode.java is different when the optionVISITOR is set to true.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -