![]() The end-of-file situation is a bit nutty (since version 2.7.1) because Terence used -1 as a char not an int (-1 is '\uFFFF'.oops). Throws TokenStreamException, CharStreamException * stream exception ("I found the end of this file, * exceptions like: "Heh, premature eof" or a retry * You might want to throw token or char stream * for another token beyond that last non-EOF token. * of the previous token and only if your parser asks * uponEOF() is called after the complete evaluation * evaluation of normal lexical rules, which * during syntactic predicate evaluation or during ![]() * This method is not called if EOF is reached ** This method is called by YourLexer.nextToken() You should instead override CharScanner.uponEOF(), in your lexer grammar: While you can test for end-of-file as a character, it is not really a character-it is a condition. You can test for EOF_CHAR in actions of lexer rules: The EOF token is automatically generated for use in parser rules: Single-quoted characters are not supported in parser rules.Įnd of file. In lexer rules, single quotes represent a character to be matched on the input character stream. They may contain octal-escape characters (e.g., '\377'), Unicode characters (e.g., '\uFF00'), and the usual special character escapes recognized by Java ( '\b', '\r', '\t', '\n', '\f', '\'', '\\'). Character literals are specified just like in Java. **This grammar recognizes simple expressionsĬharacters. Java-style documenting comments are allowed on grammar classes and rules, which are passed to the generated output if requested. ANTLR accepts C-style block comments and C -style line comments. For example, " FirstName LastName" appears as a sequence of two token references to ANTLR not token reference, space, followed by token reference.Ĭomments. Spaces, tabs, and newlines are separators in that they can separate ANTLR vocabulary symbols such as identifiers, but are ignored beyond that. The generated recognizers are human-readable and you can consult the output to clear up many of your questions about ANTLR's behavior. Because ANTLR uses LL(k) analysis for all three grammar variants, the grammar specifications are similar, and the generated lexers and parsers behave similarly. ANTLR Specification: Meta Language ANTLR Meta-LanguageĪNTLR accepts three types of grammar specifications - parsers, lexers, and tree-parsers (also called tree-walkers).
0 Comments
Leave a Reply. |