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