Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 8th, 2010  |  syntax: C#  |  size: 1.73 KB  |  views: 231  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Irony.Ast;
  6. using Irony.Interpreter;
  7. using Irony.Parsing;
  8.  
  9. namespace IronyTests
  10. {
  11.     public class CameraControlGrammar : Grammar
  12.     {
  13.         public CameraControlGrammar()
  14.         {
  15.  
  16.             var program = new NonTerminal("program");
  17.             var cameraSize = new NonTerminal("cameraSize");
  18.             var cameraPosition = new NonTerminal("cameraPosition");
  19.             var commandList = new NonTerminal("commandList");
  20.             var command = new NonTerminal("command");
  21.             var direction = new NonTerminal("direction");
  22.             var number = new NonTerminal("number");
  23.  
  24.  
  25.             this.Root = program;
  26.  
  27.             program.Rule = cameraSize + cameraPosition + commandList;
  28.  
  29.             cameraSize.Rule = Symbol("set") + "camera" + "position" + ":" +
  30.                                 number + "," + number + ".";
  31.  
  32.             cameraPosition.Rule = Symbol("set") + "camera" + "size" + ":" +
  33.                                 number + "," + number + ".";
  34.  
  35.             commandList.Rule = MakePlusRule(commandList, null, command);
  36.  
  37.             command.Rule = Symbol("move") + number + "pixels" + direction + ".";
  38.  
  39.             direction.Rule = Symbol("up") | "down" | "left" | "right";
  40.  
  41.             this.RegisterPunctuation("set", "camera", "size", ":",
  42.                                      "by", "pixels", ".", "position", ",", "move");
  43.  
  44.         }
  45.  
  46.         public void Compile()
  47.         {
  48.             CameraControlGrammar grammar = new CameraControlGrammar();
  49.             LanguageCompiler compiler = new LanguageCompiler(grammar);
  50.             AstNode program = compiler.Parse("some code");
  51.         }
  52.     }
  53. }
clone this paste RAW Paste Data