Custopootimus

Exp0 - Java

Sep 15th, 2013
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. package com.jswrenn.exp0;
  2.  
  3. import static com.jswrenn.grammar.PatternBuilder.first;
  4. import static com.jswrenn.grammar.PatternBuilder.just;
  5.  
  6. import com.jswrenn.grammar.Rule;
  7.  
  8. public class Exp0 {
  9.    
  10.     private static final Rule
  11.             Statement = new Statement(),
  12.             Expression = new Expression(),
  13.             LHSVar = new LHSVar(),
  14.             RHSVar = new RHSVar(),
  15.             Num = new Num();
  16.    
  17.     public static class Statement extends Rule {{
  18.         matches(first('s').then(Expression).last(Expression),
  19.         /*or*/  first('p').last(Expression));}}
  20.    
  21.     public static class Expression extends Rule {{
  22.         matches(first('+').then(Expression).last(Expression),
  23.         /*or*/  first('-').then(Expression).last(Expression),
  24.         /*or*/  first('(').then(Expression).last(')'),
  25.         /*or*/  just(LHSVar),
  26.         /*or*/  just(Num));}}
  27.    
  28.     public static class LHSVar extends Rule {{
  29.         matches(just('x'),
  30.         /*or*/  just('y'),
  31.         /*or*/  just('z'));}}
  32.    
  33.     public static class RHSVar extends Rule {{
  34.         matches(just('x'),
  35.         /*or*/  just('y'),
  36.         /*or*/  just('z'));}}
  37.    
  38.     public static class Num extends Rule {{
  39.         matches(just('0'),
  40.         /*or*/  just('1'),
  41.         /*or*/  just('2'),
  42.         /*or*/  just('3'),
  43.         /*or*/  just('4'),
  44.         /*or*/  just('5'),
  45.         /*or*/  just('6'),
  46.         /*or*/  just('7'),
  47.         /*or*/  just('8'),
  48.         /*or*/  just('9'));}}
  49. }
Advertisement
Add Comment
Please, Sign In to add comment