Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.jswrenn.exp0;
- import static com.jswrenn.grammar.PatternBuilder.first;
- import static com.jswrenn.grammar.PatternBuilder.just;
- import com.jswrenn.grammar.Rule;
- public class Exp0 {
- private static final Rule
- Statement = new Statement(),
- Expression = new Expression(),
- LHSVar = new LHSVar(),
- RHSVar = new RHSVar(),
- Num = new Num();
- public static class Statement extends Rule {{
- matches(first('s').then(Expression).last(Expression),
- /*or*/ first('p').last(Expression));}}
- public static class Expression extends Rule {{
- matches(first('+').then(Expression).last(Expression),
- /*or*/ first('-').then(Expression).last(Expression),
- /*or*/ first('(').then(Expression).last(')'),
- /*or*/ just(LHSVar),
- /*or*/ just(Num));}}
- public static class LHSVar extends Rule {{
- matches(just('x'),
- /*or*/ just('y'),
- /*or*/ just('z'));}}
- public static class RHSVar extends Rule {{
- matches(just('x'),
- /*or*/ just('y'),
- /*or*/ just('z'));}}
- public static class Num extends Rule {{
- matches(just('0'),
- /*or*/ just('1'),
- /*or*/ just('2'),
- /*or*/ just('3'),
- /*or*/ just('4'),
- /*or*/ just('5'),
- /*or*/ just('6'),
- /*or*/ just('7'),
- /*or*/ just('8'),
- /*or*/ just('9'));}}
- }
Advertisement
Add Comment
Please, Sign In to add comment