92 lines
2.4 KiB
Plaintext
92 lines
2.4 KiB
Plaintext
unit hocLexer;
|
|
|
|
// ============================================================================
|
|
// Lexer class declaration
|
|
// ============================================================================
|
|
lexer ThocLexer;
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// Lexer options
|
|
// ----------------------------------------------------------------------------
|
|
options
|
|
{
|
|
k = 2;
|
|
exportVocab = hocLexer;
|
|
caseSensitive = false;
|
|
}
|
|
|
|
// ============================================================================
|
|
// Begin rule definitions
|
|
//
|
|
// Remember: All lexer rule names must begin with UPPERCASE letter!
|
|
// ============================================================================
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// Simple tokens
|
|
// ----------------------------------------------------------------------------
|
|
LPAREN : '(';
|
|
RPAREN : ')';
|
|
|
|
PLUS : '+';
|
|
MINUS : '-';
|
|
STAR : '*';
|
|
SLASH : '/';
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// NUMBER
|
|
// ----------------------------------------------------------------------------
|
|
UNUMBER
|
|
: UINT ('.' UINT)?
|
|
;
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// UINT
|
|
// ----------------------------------------------------------------------------
|
|
protected
|
|
UINT
|
|
: (DIGIT)+
|
|
;
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// DIGIT
|
|
// ----------------------------------------------------------------------------
|
|
protected
|
|
DIGIT
|
|
: '0'..'9'
|
|
;
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// NEWLINE
|
|
// ----------------------------------------------------------------------------
|
|
NEWLINE
|
|
:
|
|
(
|
|
options
|
|
{
|
|
generateAmbigWarnings = false;
|
|
}
|
|
: '\r' '\n' { newLine; }
|
|
| '\r' { newLine; }
|
|
| '\n' { newLine; }
|
|
)
|
|
;
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// WHITESPACE
|
|
// ----------------------------------------------------------------------------
|
|
WHITESPACE
|
|
:
|
|
(
|
|
' '
|
|
| '\t' { tab; }
|
|
)
|
|
{
|
|
_ttype := TT_SKIP;
|
|
}
|
|
;
|
|
|
|
// ============================================================================
|
|
// End rule definitions
|
|
// ============================================================================
|
|
|