AuD
Lecture 'Algorithmen und Datenstrukturen' (code examples)
aud.example.expr.Tokenizer Class Reference

Breaks input string into pieces ("tokens"). More...

+ Inheritance diagram for aud.example.expr.Tokenizer:
+ Collaboration diagram for aud.example.expr.Tokenizer:

Public Member Functions

 Tokenizer (String input)
 create new tokenizer for input
More...
 
- Public Member Functions inherited from aud.util.LexicalScanner
 LexicalScanner (Rule[] rules, String input)
 create new scanner processing input @endiliteral
More...
 
void setInput (String input)
 set input (resets scanner state) More...
 
String matchedText ()
 get text of last match or call to next More...
 
int matchedTokenId ()
 get result of last call to next() More...
 
String remainder ()
 get remaining text More...
 
boolean endOfInput ()
 reached end of input? More...
 
int next ()
 match remainder to rules provided to constructor More...
 

Static Public Member Functions

static void main (String[] args)
 testing and example for usage More...
 
static void main (String[] args)
 testing and example for usage More...
 

Static Public Attributes

static final int PLUS ='+'
 
static final int MINUS ='-'
 
static final int TIMES ='*'
 
static final int DIVIDE ='/'
 
static final int POWER ='^'
 
static final int LEFT_PAREN ='('
 
static final int RIGHT_PAREN =')'
 
static final int IDENTIFIER =0x100
 
static final int NUMBER =0x101
 
- Static Public Attributes inherited from aud.util.LexicalScanner
static final int END_OF_INPUT = -1
 no more input More...
 
static final int NO_MATCH = -2
 no match (usually implies a syntax error) More...
 
static final Pattern P_WHITESPACE = Pattern.compile("\\s+")
 white space More...
 
static final Pattern P_IDENTIFIER
 identifiers More...
 
static final Pattern P_FLOAT
 floating point number More...
 

Static Protected Attributes

static final Pattern P_PLUS = Pattern.compile("\\+")
 
static final Pattern P_MINUS = Pattern.compile("-")
 
static final Pattern P_TIMES = Pattern.compile("\\*")
 
static final Pattern P_DIVIDE = Pattern.compile("/")
 
static final Pattern P_POWER = Pattern.compile("(\\*\\*)|\\^")
 
static final Pattern P_LEFTPAREN = Pattern.compile("\\‍(")
 
static final Pattern P_RIGHTPAREN = Pattern.compile("\\‍)")
 
static final LexicalScanner.Rule[] RULES
 

Additional Inherited Members

- Protected Member Functions inherited from aud.util.LexicalScanner
void eatWhiteSpace ()
 ignore white space (called by match More...
 
boolean match (Pattern p)
 Match remainder against pattern p. More...
 
int next (Rule[] rules)
 match remainder to table of rules @endiliteral
More...
 

Detailed Description

Breaks input string into pieces ("tokens").

Definition at line 9 of file expr/Tokenizer.java.

Constructor & Destructor Documentation

◆ Tokenizer()

create new tokenizer for input

Definition at line 44 of file expr/Tokenizer.java.

44 {
45 super(RULES,input);
46 }
static final LexicalScanner.Rule[] RULES

References aud.example.expr.Tokenizer.RULES.

Member Function Documentation

◆ main()

static void aud.example.expr.Tokenizer.main ( String[]  args)
static

testing and example for usage

Reimplemented from aud.util.LexicalScanner.

Definition at line 49 of file expr/Tokenizer.java.

49 {
50
52 (args.length==0 ? "2*(3+4)/x-3.14+2^3-2**3" : args[0]);
53
54 System.out.println("input = '"+t.remainder()+"'");
55
56 while (t.next()!=END_OF_INPUT) {
57 if (t.matchedTokenId()==NO_MATCH) {
58 System.out.println("syntax error near '"+t.remainder()+"'");
59 break;
60 }
61 else if (t.matchedTokenId()==NUMBER) {
62 double d=Double.parseDouble(t.matchedText());
63 System.out.println("read a number: "+d);
64 }
65 System.out.println("next token id = "+t.matchedTokenId());
66 System.out.println("matched text = '"+t.matchedText()+"'");
67 System.out.println("remaining input = '"+t.remainder()+"'");
68 }
69 }
Tokenizer(String input)
create new tokenizer for input
static final int END_OF_INPUT
no more input
static final int NO_MATCH
no match (usually implies a syntax error)

References aud.util.LexicalScanner.END_OF_INPUT, aud.util.LexicalScanner.matchedText(), aud.util.LexicalScanner.matchedTokenId(), aud.util.LexicalScanner.next(), aud.util.LexicalScanner.NO_MATCH, aud.example.expr.Tokenizer.NUMBER, and aud.util.LexicalScanner.remainder().

+ Here is the call graph for this function:

Member Data Documentation

◆ DIVIDE

final int aud.example.expr.Tokenizer.DIVIDE ='/'
static

◆ IDENTIFIER

final int aud.example.expr.Tokenizer.IDENTIFIER =0x100
static

Definition at line 27 of file expr/Tokenizer.java.

Referenced by aud.example.expr.ExpressionParser.factor().

◆ LEFT_PAREN

final int aud.example.expr.Tokenizer.LEFT_PAREN ='('
static

Definition at line 24 of file expr/Tokenizer.java.

Referenced by aud.example.expr.ExpressionParser.factor().

◆ MINUS

final int aud.example.expr.Tokenizer.MINUS ='-'
static

◆ NUMBER

final int aud.example.expr.Tokenizer.NUMBER =0x101
static

◆ P_DIVIDE

final Pattern aud.example.expr.Tokenizer.P_DIVIDE = Pattern.compile("/")
staticprotected

Definition at line 14 of file expr/Tokenizer.java.

◆ P_LEFTPAREN

final Pattern aud.example.expr.Tokenizer.P_LEFTPAREN = Pattern.compile("\\‍(")
staticprotected

Definition at line 16 of file expr/Tokenizer.java.

◆ P_MINUS

final Pattern aud.example.expr.Tokenizer.P_MINUS = Pattern.compile("-")
staticprotected

Definition at line 12 of file expr/Tokenizer.java.

◆ P_PLUS

final Pattern aud.example.expr.Tokenizer.P_PLUS = Pattern.compile("\\+")
staticprotected

Definition at line 11 of file expr/Tokenizer.java.

◆ P_POWER

final Pattern aud.example.expr.Tokenizer.P_POWER = Pattern.compile("(\\*\\*)|\\^")
staticprotected

Definition at line 15 of file expr/Tokenizer.java.

◆ P_RIGHTPAREN

final Pattern aud.example.expr.Tokenizer.P_RIGHTPAREN = Pattern.compile("\\‍)")
staticprotected

Definition at line 17 of file expr/Tokenizer.java.

◆ P_TIMES

final Pattern aud.example.expr.Tokenizer.P_TIMES = Pattern.compile("\\*")
staticprotected

Definition at line 13 of file expr/Tokenizer.java.

◆ PLUS

final int aud.example.expr.Tokenizer.PLUS ='+'
static

◆ POWER

final int aud.example.expr.Tokenizer.POWER ='^'
static

Definition at line 23 of file expr/Tokenizer.java.

◆ RIGHT_PAREN

final int aud.example.expr.Tokenizer.RIGHT_PAREN =')'
static

Definition at line 25 of file expr/Tokenizer.java.

Referenced by aud.example.expr.ExpressionParser.factor().

◆ RULES

final LexicalScanner.Rule [] aud.example.expr.Tokenizer.RULES
staticprotected
Initial value:
=
{
new LexicalScanner.Rule(IDENTIFIER,LexicalScanner.P_IDENTIFIER)
}
static final Pattern P_POWER
static final Pattern P_TIMES
static final int RIGHT_PAREN
static final Pattern P_RIGHTPAREN
static final Pattern P_PLUS
static final Pattern P_DIVIDE
static final Pattern P_MINUS
static final Pattern P_LEFTPAREN
LexicalScanner(Rule[] rules, String input)
create new scanner processing input @endiliteral

Definition at line 30 of file expr/Tokenizer.java.

Referenced by aud.example.expr.Tokenizer.Tokenizer().

◆ TIMES

final int aud.example.expr.Tokenizer.TIMES ='*'
static

The documentation for this class was generated from the following file: