Package lexer

Examples of lexer.Lexer


    // helper method to run tests; no need to change this
    // In any case making them final makes no sense since the accessor is private.
    // private final void runtest(String input, Token... output) {
    // "..." arbitrage number of parameters
    private void runtest(String input, Token... output) {
        Lexer lexer = new Lexer(new StringReader(input));
        int i=0;
        Token actual, expected;
        try {
            do {
                //System.out.println("testing "+output[i]);
                assertTrue(i < output.length);
                expected = output[i++];
                try {
                    actual = lexer.nextToken();
                    assertEquals(expected, actual);
                } catch(Error e) {
                    if(expected != null)
                        fail(e.getMessage());
                    return;
View Full Code Here


import lexer.errors.LexerException;

public class TestSystem {
 
  public static void main(String[] args) {
    Lexer lexer = new Lexer();
    final Type<Integer> integer = new Type<>("Integer");
    final Type<Double> decimal = new Type<>("Decimal");
    lexer.addRule("Integer", new Rule<Integer>("[0-9]+", integer, new Action<Integer>() {
      @Override
      public Token action(Matcher matcher, Lexer lexer, Type<Integer> type) {
        return new Token(new Integer(matcher.group()), type);
      }
    }));
    lexer.addRule("Decimal", new Rule<Double>("([0-9]+\\.[0-9]*|[0-9]*\\.[0-9]+)", decimal, new Action<Double>() {
      @Override
      public Token action(Matcher matcher, Lexer lexer, Type<Double> type) {
        return new Token(new Double(matcher.group()), type);
      }
    }));
    lexer.addDescender("Parentheses", new Descender("(", ")", new Type<Token>("Parentheses"), null));
    lexer.addDescender("Brackets", new Descender("[", "]", new Type<Token>("Brackets"), null));
    lexer.ignore("\n");
    String test = "10.0 100 (3.0 300\n) [51 5 6] ()";
    try {
      System.out.println(test + " -> " + lexer.lex(test));
    }
    catch (LexerException e) {
      System.out.println(test + " -> " + e.getMessage());
      e.printStackTrace();
    }
View Full Code Here

  }

  private void runtest(String src, boolean succeed) {
    Parser parser = new Parser();
    try {
      parser.parse(new Lexer(new StringReader(src)));
      if(!succeed) {
        fail("Test was supposed to fail, but succeeded");
      }
    } catch (beaver.Parser.Exception e) {
      if(succeed) {
View Full Code Here

  private void runtest(boolean succeed, String... srcs) {
    Parser parser = new Parser();
    try {
      List<Module> modules = new List<Module>();
      for(String src : srcs)
        modules.add((Module)parser.parse(new Lexer(new StringReader(src))));
      Program prog = new Program(modules);
      prog.namecheck();
      if(!prog.hasErrors()) prog.typecheck();
      if(succeed) {
        if(prog.hasErrors()) {
View Full Code Here

  private void runtest(String[] modules_src, String main_module, String main_function, Class<?>[] parm_types, Object[] args, Object expected) {
    try {
      List<Module> modules = new List<Module>();
      for(String module_src : modules_src) {
        Parser parser = new Parser();
        Module module = (Module)parser.parse(new Lexer(new StringReader(module_src)));
        modules.add(module);
      }
      Program prog = new Program(modules);
     
      prog.namecheck();
View Full Code Here

TOP

Related Classes of lexer.Lexer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.