47 lines
1.1 KiB
Plaintext
47 lines
1.1 KiB
Plaintext
// ============================================================================
|
|
// Demo lexer for a four operator calculator
|
|
// ============================================================================
|
|
unit calcLexer;
|
|
|
|
lexer TcalcLexer;
|
|
options
|
|
{
|
|
exportVocab = calcLexer;
|
|
k = 2;
|
|
}
|
|
|
|
// ============================================================================
|
|
// Simple tokens
|
|
// ============================================================================
|
|
LPAREN : '(';
|
|
RPAREN : ')';
|
|
|
|
PLUS : '+';
|
|
MINUS : '-';
|
|
STAR : '*';
|
|
SLASH : '/';
|
|
|
|
SEMI : ';';
|
|
|
|
// ============================================================================
|
|
// INT
|
|
// ============================================================================
|
|
INT : ('0'..'9')+;
|
|
|
|
// ============================================================================
|
|
// White space
|
|
// ============================================================================
|
|
WS
|
|
:
|
|
(
|
|
'\r' '\n' { newLine; }
|
|
| '\r' { newLine; }
|
|
| '\n' { newLine; }
|
|
| '\t' { tab; }
|
|
| ' '
|
|
)
|
|
{
|
|
_ttype := TT_SKIP;
|
|
}
|
|
;
|