Blob


1 // Declarations
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.
8 %eof EOF
10 // Declare an error token called Error.
11 %error Error
13 Integer = "0" | [1-9][0-9]*;
14 Ident = [a-zA-Z_][a-zA-Z_0-9]*;
16 %%
17 // Definitions
19 Whitespace : [ \n\t\r\f]+;
20 // A File can be either an integer, or an identifier.
21 File : Integer | Ident;
23 %%
24 // Code
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);
34 while (true) {
35 var token = tokens.get();
36 if (token.getType() == TokenType.EOF)
37 break;
38 System.out.println(token);
39 }
40 } catch (IOException e) {}
41 }