25 lines
622 B
Plaintext
25 lines
622 B
Plaintext
%lexer // Appel's first Jlex example, modified for C# lg and fixing -- comments
|
|
%{
|
|
using System.IO;
|
|
using Tools;
|
|
|
|
public class Test
|
|
{
|
|
public static void Main(string[] args) {
|
|
Lexer lexer = new tokens();
|
|
lexer.Start(new StreamReader(args[0]));
|
|
TOKEN t;
|
|
while ((t=lexer.Next())!=null) {
|
|
Console.WriteLine("{0} {1} {2}", t.Name(), t.yytext, (t.yylval==null)?"":t.yylval);
|
|
}
|
|
}
|
|
}
|
|
%}
|
|
%define digits [0-9]+
|
|
" "|\n|\r ;
|
|
if %IF
|
|
[a-z][a-z0-9]* %ID
|
|
{digits} %INT { yylval = Int32.Parse(yytext); }
|
|
({digits}"."[0-9]*)|([0-9]*"."[0-9]+) %REAL { yylval = Double.Parse(yytext); }
|
|
"--".* ;
|