summaryrefslogtreecommitdiff
path: root/tutorial/examples/syntax/RichSyntaxClass.oj
diff options
context:
space:
mode:
Diffstat (limited to 'tutorial/examples/syntax/RichSyntaxClass.oj')
-rw-r--r--tutorial/examples/syntax/RichSyntaxClass.oj102
1 files changed, 102 insertions, 0 deletions
diff --git a/tutorial/examples/syntax/RichSyntaxClass.oj b/tutorial/examples/syntax/RichSyntaxClass.oj
new file mode 100644
index 0000000..61005a7
--- /dev/null
+++ b/tutorial/examples/syntax/RichSyntaxClass.oj
@@ -0,0 +1,102 @@
+/*
+ * RichSyntaxClass.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.syntax;
+
+
+import java.lang.Object;
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+public class RichSyntaxClass instantiates Metaclass extends OJClass
+{
+ public void translateDefinition() {
+ String[] str = new String[] {
+ "hates", "loves", "keeps", "forwards", "before", "after",
+ "chooses", "adapts", "pre" };
+ for (int i = 0; i < str.length; ++i) {
+ ParseTree suffix;
+ suffix = this.getSuffix( str[i] );
+ if (suffix != null) {
+ System.out.println( this.toString() + " involves a suffix " +
+ " \"" + str[i] + "\" :" );
+ System.out.println( "\t" + suffix );
+ }
+ OJMethod[] methods = getDeclaredMethods();
+ for (int j = 0; j < methods.length; ++j) {
+ suffix = methods[j].getSuffix( str[i] );
+ if (suffix != null) {
+ System.out.println( methods[j].toString() +
+ " involves a suffix " +
+ " ( " + str[i] + " ):" );
+ System.out.println( "\t" + suffix );
+ }
+ }
+ }
+ }
+
+ public static boolean isRegisteredKeyword( String keyword ) {
+ if (keyword.equals( "replacedBy" )) return true;
+ if (keyword.equals( "hates" )) return true;
+ if (keyword.equals( "loves" )) return true;
+ if (keyword.equals( "keeps" )) return true;
+ if (keyword.equals( "forwards" )) return true;
+ if (keyword.equals( "before" )) return true;
+ if (keyword.equals( "after" )) return true;
+ if (keyword.equals( "chooses" )) return true;
+ if (keyword.equals( "adapts" )) return true;
+ if (keyword.equals( "pre" )) return true;
+ return OJClass.isRegisteredKeyword( keyword );
+ }
+
+ public static SyntaxRule getDeclSuffixRule( String keyword ) {
+ if (keyword.equals( "hates" )) return new NameRule();
+ if (keyword.equals( "loves" )) return new TypeNameRule();
+ if (keyword.equals( "keeps" )) return new ExpressionRule();
+ if (keyword.equals( "forwards" )) {
+ return new IterationRule( new TypeNameRule(), false );
+ }
+ if (keyword.equals( "before" ) || keyword.equals( "after" )) {
+ return new BlockRule();
+ }
+ if (keyword.equals( "chooses" ) || keyword.equals( "after" )) {
+ return new SelectionRule( new TypeNameRule(), new BlockRule() );
+ }
+ if (keyword.equals( "adapts" ) || keyword.equals( "after" )) {
+ return new CompositeRule(
+ new NameRule(),
+ new PrepPhraseRule( "in", new NameRule() ),
+ new PrepPhraseRule( "to", new NameRule() ) );
+ }
+ return OJClass.getDeclSuffixRule( keyword );
+ }
+
+ public static SyntaxRule getDeclSuffixRule(Environment env,
+ String keyword)
+ {
+ if (keyword.equals("pre")) return new ExpressionRule(env);
+ return OJClass.getDeclSuffixRule(env, keyword);
+ }
+
+ public static SyntaxRule getTypeSuffixRule( String keyword ) {
+ if (keyword.equals( "replacedBy" )) return new TypeNameRule();
+ return OJClass.getTypeSuffixRule( keyword );
+ }
+
+ public static boolean isRegisteredModifier( String keyword ) {
+ if (keyword.equals( "remote" )) return true;
+ if (keyword.equals( "crazy" )) return true;
+ return false;
+ }
+
+}