diff options
Diffstat (limited to 'src/main/java/io/devnulllabs/openjava/syntax/TokenRule.java')
-rw-r--r-- | src/main/java/io/devnulllabs/openjava/syntax/TokenRule.java | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/main/java/io/devnulllabs/openjava/syntax/TokenRule.java b/src/main/java/io/devnulllabs/openjava/syntax/TokenRule.java new file mode 100644 index 0000000..a55d3dc --- /dev/null +++ b/src/main/java/io/devnulllabs/openjava/syntax/TokenRule.java @@ -0,0 +1,61 @@ +/* + * TokenRule.java + * + * comments here. + * + * @author Michiaki Tatsubori + * @version %VERSION% %DATE% + * @see java.lang.Object + * + * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED. + */ +package io.devnulllabs.openjava.syntax; + +import io.devnulllabs.openjava.ptree.Leaf; +import io.devnulllabs.openjava.ptree.ParseTree; +import io.devnulllabs.openjava.tools.parser.Token; + +/** + * The class <code>TokenRule</code> represents the syntax + * rule of a list separated by an separator. + * <p> + * Suppose there's a syntax rule A and token t. This class can + * represents the syntax A ( t A )*. + * <p> + * + * @author Michiaki Tatsubori + * @version 1.0 + * @since $Id: TokenRule.java,v 1.2 2003/02/19 02:54:31 tatsubori Exp $ + * @see java.lang.Object + */ +public final class TokenRule extends AbstractSyntaxRule { + private int tokenID; + + /** + * Allocates a new rule representing a specified token. + * + * @param separator_token the id of a token. + * @see io.devnulllabs.openjava.syntax.TokenID + */ + public TokenRule(int token_id) { + this.tokenID = token_id; + } + + /** + * Consumes token source. + * + * @param token_src token source. + * @return null if this fails to consume a syntax tree represented + * by this object. Otherwise it returns <code>ObjectList</code> object. + */ + public final ParseTree consume(TokenSource token_src) + throws SyntaxException { + Token t = token_src.getNextToken(); + if (t.kind != tokenID) { + /***** to become specifed error report */ + throw new SyntaxException("un expected token"); + } + return new Leaf(t.kind, t.image, t.beginLine, t.beginColumn); + } + +} |