static void Main(string[] args) { Scanner scanner = new Scanner( new System.IO.FileStream(args[0], System.IO.FileMode.Open)); Tokens token; do { token = (Tokens)scanner.yylex(); switch (token) { case Tokens.NullLiteral: Console.WriteLine("null literal ({0})", scanner.yylval.name); break; case Tokens.CharacterLiteral: Console.WriteLine("char literal ({0})", scanner.yylval.name); break; case Tokens.EOF: Console.WriteLine("EOF"); break; default: Console.WriteLine("'{0}'", (char)token); break; } }while (token != Tokens.EOF); }
static void Main(string[] args) { try { using (var input = System.IO.File.OpenRead(args[0])) { Scanner scanner = new Scanner(input); Tokens token; do { token = (Tokens)scanner.yylex(); switch (token) { case Tokens.NUMBER: Console.WriteLine("NUMBER ({0})", scanner.yylval.num); break; case Tokens.IDENT: Console.WriteLine("IDENT ({0})", scanner.yylval.name); break; case Tokens.IF: Console.WriteLine("IF"); break; case Tokens.ELSE: Console.WriteLine("ELSE"); break; case Tokens.INT: Console.WriteLine("INT"); break; case Tokens.BOOL: Console.WriteLine("BOOL"); break; case Tokens.EOF: Console.WriteLine("EOF"); break; case Tokens.FLOATLITERAL: Console.WriteLine($"FLOATLITERAL ({scanner.yylval.floatValue})"); break; default: Console.WriteLine("'{0}'", (char)token); break; } }while (token != Tokens.EOF); } } catch (Exception e) { Console.WriteLine(e.Message); } }
static void Main(string[] args) { Scanner scanner = new Scanner(Console.OpenStandardInput()); Tokens token; do { token = (Tokens)scanner.yylex(); switch (token) { case Tokens.NUMBER: Console.WriteLine("NUMBER ({0})", scanner.yylval.num); break; case Tokens.IDENT: Console.WriteLine("IDENT ({0})", scanner.yylval.name); break; case Tokens.IF: Console.WriteLine("IF"); break; case Tokens.ELSE: Console.WriteLine("ELSE"); break; case Tokens.INT: Console.WriteLine("INT"); break; case Tokens.BOOL: Console.WriteLine("BOOL"); break; case Tokens.EOF: Console.WriteLine("EOF"); break; case Tokens.BOOLEAN: Console.WriteLine("BOOL ({0})", scanner.yylval.boolValue); break; case Tokens.OPERATOR: Console.WriteLine("'{0}'", scanner.yylval.name); break; default: Console.WriteLine("'{0}'", (char)token); break; } }while (token != Tokens.EOF); }
static void Main(string[] args) { Scanner scanner = new Scanner(new System.IO.FileStream(args[0], System.IO.FileMode.Open)); //Parser parser = new Parser(scanner); //parser.Parse(); Tokens token; do { //int x = scanner.yylex(); token = (Tokens)scanner.yylex(); switch (token) { case Tokens.NUMBER: Console.WriteLine("NUMBER ({0})", scanner.yylval.num); break; case Tokens.IDENT: Console.WriteLine("IDENT ({0})", scanner.yylval.name); break; case Tokens.IF: Console.WriteLine("IF"); break; case Tokens.ELSE: Console.WriteLine("ELSE"); break; case Tokens.INT: Console.WriteLine("INT"); break; case Tokens.BOOL: Console.WriteLine("BOOL"); break; case Tokens.EOF: Console.WriteLine("EOF"); break; default: Console.WriteLine("'{0}'", (char)token); break; } }while (token != Tokens.EOF); Console.Read(); }
static void Main(string[] args) { try { using (var input = System.IO.File.OpenRead(args[0])) { Scanner scanner = new Scanner(input); Tokens token; do { token = (Tokens)scanner.yylex(); switch (token) { case Tokens.IntergerLiteral: Console.WriteLine("IntergerLiteral ({0})", scanner.yylval.num); break; case Tokens.FloatingPointLiteral: Console.WriteLine("FloatingPointLiteral ({0})", scanner.yylval.flo); break; case Tokens.EOF: Console.WriteLine("EOF"); break; default: Console.WriteLine("'{0}'", (char)token); break; } }while (token != Tokens.EOF); } } catch (Exception e) { Console.WriteLine(e.Message); } }
public static void TestScanner(Scanner scanner) { Tokens token; do { token = (Tokens)scanner.yylex(); switch (token) { // Number Literals case Tokens.INTEGER_LITERAL: Console.WriteLine("INTEGER LITERAL ({0})", scanner.yylval.num); break; case Tokens.FLOAT_LITERAL: { Console.WriteLine("FLOAT LITERAL ({0})", scanner.yylval.floatVal); break; } // Char Literals case Tokens.CHARACTER: { Console.WriteLine("CHARACTER ({0})", scanner.yylval.name); break; } // String Literals case Tokens.STRING_LITERAL: Console.WriteLine("STRING LITERAL ({0})", scanner.yylval.name); break; // Idens case Tokens.IDENT: Console.WriteLine("IDENT ({0})", scanner.yylval.name); break; // Keywords case Tokens.IF: Console.WriteLine("IF"); break; case Tokens.PUBLIC: Console.WriteLine("PUBLIC"); break; case Tokens.STATIC: Console.WriteLine("STATIC"); break; case Tokens.VOID: Console.WriteLine("VOID"); break; case Tokens.CLASS: Console.WriteLine("CLASS"); break; case Tokens.ELSE: Console.WriteLine("ELSE"); break; case Tokens.INT: Console.WriteLine("INT"); break; case Tokens.BOOLEAN: Console.WriteLine("BOOL"); break; case Tokens.EOF: Console.WriteLine("EOF"); break; // Boolean literals case Tokens.TRUE: Console.WriteLine("TRUE"); break; // Null literals case Tokens.NULL: Console.WriteLine("NULL"); break; // Seperators case Tokens.SEPARATOR_ONE: Console.WriteLine("SEPARATOR 1 (...)"); break; default: Console.WriteLine("'{0}'", (char)token); break; } }while (token != Tokens.EOF); }