using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Irony.Ast;
using Irony.Interpreter;
using Irony.Parsing;
namespace IronyTests
{
public class CameraControlGrammar : Grammar
{
public CameraControlGrammar()
{
var program = new NonTerminal("program");
var cameraSize = new NonTerminal("cameraSize");
var cameraPosition = new NonTerminal("cameraPosition");
var commandList = new NonTerminal("commandList");
var command = new NonTerminal("command");
var direction = new NonTerminal("direction");
var number = new NonTerminal("number");
this.Root = program;
program.Rule = cameraSize + cameraPosition + commandList;
cameraSize.Rule = Symbol("set") + "camera" + "position" + ":" +
number + "," + number + ".";
cameraPosition.Rule = Symbol("set") + "camera" + "size" + ":" +
number + "," + number + ".";
commandList.Rule = MakePlusRule(commandList, null, command);
command.Rule = Symbol("move") + number + "pixels" + direction + ".";
direction.Rule = Symbol("up") | "down" | "left" | "right";
this.RegisterPunctuation("set", "camera", "size", ":",
"by", "pixels", ".", "position", ",", "move");
}
public void Compile()
{
CameraControlGrammar grammar = new CameraControlGrammar();
LanguageCompiler compiler = new LanguageCompiler(grammar);
AstNode program = compiler.Parse("some code");
}
}
}