1 2228b436 2024-02-10 benni // Declarations
2 2228b436 2024-02-10 benni %import eu.bandm.tools.lexic.*
3 2228b436 2024-02-10 benni %import java.io.IOException
4 2228b436 2024-02-10 benni %import java.io.InputStreamReader
5 2228b436 2024-02-10 benni %import java.nio.charset.StandardCharsets
7 2228b436 2024-02-10 benni // Declare an end-of-file token called EOF.
10 2228b436 2024-02-10 benni // Declare an error token called Error.
11 2228b436 2024-02-10 benni %error Error
13 2228b436 2024-02-10 benni Integer = "0" | [1-9][0-9]*;
14 2228b436 2024-02-10 benni Ident = [a-zA-Z_][a-zA-Z_0-9]*;
17 2228b436 2024-02-10 benni // Definitions
19 2228b436 2024-02-10 benni Whitespace : [ \n\t\r\f]+;
20 2228b436 2024-02-10 benni // A File can be either an integer, or an identifier.
21 2228b436 2024-02-10 benni File : Integer | Ident;
26 2228b436 2024-02-10 benni public static void main(String[] args) {
27 2228b436 2024-02-10 benni // The construct() function is generated by lexicgen and returns a Lexer.
28 2228b436 2024-02-10 benni var lexer = construct();
30 2228b436 2024-02-10 benni try (var rdr = new InputStreamReader(System.in, StandardCharsets.UTF_8)) {
31 2228b436 2024-02-10 benni TokenSource<String, TokenType> tokens = lexer
32 2228b436 2024-02-10 benni .lex(CodePointSource.read(rdr, e -> {}))
33 2228b436 2024-02-10 benni .removeTypes(TokenType.Whitespace);
34 2228b436 2024-02-10 benni while (true) {
35 2228b436 2024-02-10 benni var token = tokens.get();
36 2228b436 2024-02-10 benni if (token.getType() == TokenType.EOF)
38 2228b436 2024-02-10 benni System.out.println(token);
40 2228b436 2024-02-10 benni } catch (IOException e) {}