![]() |
AuD
Lecture 'Algorithmen und Datenstrukturen' (code examples)
|
Base class for a simple lexical scanner. More...
Inheritance diagram for aud.util.LexicalScanner:
Collaboration diagram for aud.util.LexicalScanner:Classes | |
| class | Rule |
| a rule for lexical scanner | |
Public Member Functions | |
| 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 Public Attributes | |
| 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... | |
Protected Member Functions | |
| 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... | |
Base class for a simple lexical scanner.
A lexical scanner splits input into tokens. Here, token types are referenced by integer constants given in a table of rules. Each token is characterized by a regular expression.
Note: java.util.Scanner is often a better choice. However, this requires definition of a delimiter, which is problematic in this context.
Definition at line 19 of file LexicalScanner.java.
| aud.util.LexicalScanner.LexicalScanner | ( | Rule[] | rules, |
| String | input | ||
| ) |
create new scanner processing input @endiliteral
| rules | table of rules used by next, rules will be applied sequentially in the given order |
| input | text to be analyzed |
Definition at line 68 of file LexicalScanner.java.
|
protected |
ignore white space (called by match
Definition at line 74 of file LexicalScanner.java.
References aud.util.LexicalScanner.endOfInput(), and aud.util.LexicalScanner.P_WHITESPACE.
Referenced by aud.util.LexicalScanner.next().
Here is the call graph for this function:
Here is the caller graph for this function:| boolean aud.util.LexicalScanner.endOfInput | ( | ) |
reached end of input?
Definition at line 94 of file LexicalScanner.java.
Referenced by aud.util.LexicalScanner.eatWhiteSpace(), and aud.util.LexicalScanner.next().
Here is the caller graph for this function:
|
static |
testing and example for usage
Reimplemented in aud.example.expr.Tokenizer.
Definition at line 143 of file LexicalScanner.java.
References aud.util.LexicalScanner.END_OF_INPUT, aud.util.LexicalScanner.matchedText(), aud.util.LexicalScanner.matchedTokenId(), aud.util.LexicalScanner.next(), aud.util.LexicalScanner.NO_MATCH, and aud.util.LexicalScanner.remainder().
Here is the call graph for this function:
|
protected |
Match remainder against pattern p.
match skips any preceding white space.
| p | regular expression pattern |
true if there was a match Definition at line 103 of file LexicalScanner.java.
| String aud.util.LexicalScanner.matchedText | ( | ) |
get text of last match or call to next
Definition at line 88 of file LexicalScanner.java.
Referenced by aud.example.expr.Tokenizer.main(), and aud.util.LexicalScanner.main().
Here is the caller graph for this function:| int aud.util.LexicalScanner.matchedTokenId | ( | ) |
get result of last call to next()
Definition at line 90 of file LexicalScanner.java.
Referenced by aud.example.expr.Tokenizer.main(), and aud.util.LexicalScanner.main().
Here is the caller graph for this function:| int aud.util.LexicalScanner.next | ( | ) |
match remainder to rules provided to constructor
NO_MATCH or END_OF_INPUT Definition at line 139 of file LexicalScanner.java.
References aud.util.LexicalScanner.next().
Referenced by aud.util.LexicalScanner.next().
Here is the call graph for this function:
Here is the caller graph for this function:
|
protected |
match remainder to table of rules @endiliteral
NO_MATCH or END_OF_INPUT Definition at line 123 of file LexicalScanner.java.
References aud.util.LexicalScanner.eatWhiteSpace(), and aud.util.LexicalScanner.endOfInput().
Referenced by aud.example.expr.Tokenizer.main(), and aud.util.LexicalScanner.main().
Here is the call graph for this function:
Here is the caller graph for this function:| String aud.util.LexicalScanner.remainder | ( | ) |
get remaining text
Definition at line 92 of file LexicalScanner.java.
Referenced by aud.example.expr.Tokenizer.main(), and aud.util.LexicalScanner.main().
Here is the caller graph for this function:| void aud.util.LexicalScanner.setInput | ( | String | input | ) |
set input (resets scanner state)
Definition at line 84 of file LexicalScanner.java.
|
static |
no more input
Definition at line 22 of file LexicalScanner.java.
Referenced by aud.example.graph.GraphParser.graph(), aud.example.expr.Tokenizer.main(), and aud.util.LexicalScanner.main().
|
static |
no match (usually implies a syntax error)
Definition at line 24 of file LexicalScanner.java.
Referenced by aud.example.expr.Tokenizer.main(), and aud.util.LexicalScanner.main().
|
static |
floating point number
Definition at line 60 of file LexicalScanner.java.
|
static |
identifiers
Definition at line 57 of file LexicalScanner.java.
|
static |
white space
Definition at line 55 of file LexicalScanner.java.
Referenced by aud.util.LexicalScanner.eatWhiteSpace().