001: /*
002: * ArithmeticTokenizer.java
003: *
004: * THIS FILE HAS BEEN GENERATED AUTOMATICALLY. DO NOT EDIT!
005: *
006: * This work is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published
008: * by the Free Software Foundation; either version 2 of the License,
009: * or (at your option) any later version.
010: *
011: * This work is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * As a special exception, the copyright holders of this library give
022: * you permission to link this library with independent modules to
023: * produce an executable, regardless of the license terms of these
024: * independent modules, and to copy and distribute the resulting
025: * executable under terms of your choice, provided that you also meet,
026: * for each linked independent module, the terms and conditions of the
027: * license of that module. An independent module is a module which is
028: * not derived from or based on this library. If you modify this
029: * library, you may extend this exception to your version of the
030: * library, but you are not obligated to do so. If you do not wish to
031: * do so, delete this exception statement from your version.
032: *
033: * Copyright (c) 2003 Per Cederberg. All rights reserved.
034: */
035:
036: package net.percederberg.grammatica.test;
037:
038: import java.io.Reader;
039:
040: import net.percederberg.grammatica.parser.ParserCreationException;
041: import net.percederberg.grammatica.parser.TokenPattern;
042: import net.percederberg.grammatica.parser.Tokenizer;
043:
044: /**
045: * A character stream tokenizer.
046: *
047: * @author Per Cederberg, <per at percederberg dot net>
048: * @version 1.0
049: */
050: class ArithmeticTokenizer extends Tokenizer {
051:
052: /**
053: * Creates a new tokenizer for the specified input stream.
054: *
055: * @param input the input stream to read
056: *
057: * @throws ParserCreationException if the tokenizer couldn't be
058: * initialized correctly
059: */
060: public ArithmeticTokenizer(Reader input)
061: throws ParserCreationException {
062:
063: super (input);
064: createPatterns();
065: }
066:
067: /**
068: * Initializes the tokenizer by creating all the token patterns.
069: *
070: * @throws ParserCreationException if the tokenizer couldn't be
071: * initialized correctly
072: */
073: private void createPatterns() throws ParserCreationException {
074: TokenPattern pattern;
075:
076: pattern = new TokenPattern(ArithmeticConstants.ADD, "ADD",
077: TokenPattern.STRING_TYPE, "+");
078: addPattern(pattern);
079:
080: pattern = new TokenPattern(ArithmeticConstants.SUB, "SUB",
081: TokenPattern.STRING_TYPE, "-");
082: addPattern(pattern);
083:
084: pattern = new TokenPattern(ArithmeticConstants.MUL, "MUL",
085: TokenPattern.STRING_TYPE, "*");
086: addPattern(pattern);
087:
088: pattern = new TokenPattern(ArithmeticConstants.DIV, "DIV",
089: TokenPattern.STRING_TYPE, "/");
090: addPattern(pattern);
091:
092: pattern = new TokenPattern(ArithmeticConstants.LEFT_PAREN,
093: "LEFT_PAREN", TokenPattern.STRING_TYPE, "(");
094: addPattern(pattern);
095:
096: pattern = new TokenPattern(ArithmeticConstants.RIGHT_PAREN,
097: "RIGHT_PAREN", TokenPattern.STRING_TYPE, ")");
098: addPattern(pattern);
099:
100: pattern = new TokenPattern(ArithmeticConstants.NUMBER,
101: "NUMBER", TokenPattern.REGEXP_TYPE, "[0-9]+");
102: addPattern(pattern);
103:
104: pattern = new TokenPattern(ArithmeticConstants.IDENTIFIER,
105: "IDENTIFIER", TokenPattern.REGEXP_TYPE, "[a-z]");
106: addPattern(pattern);
107:
108: pattern = new TokenPattern(ArithmeticConstants.WHITESPACE,
109: "WHITESPACE", TokenPattern.REGEXP_TYPE, "[ \\t\\n\\r]+");
110: pattern.setIgnore();
111: addPattern(pattern);
112: }
113: }
|