private object NewItem(object[] input)
 {
     //ignore the contents
       //this should be an id or string
       string str = dataStack.Pop().ToString();
       switch(str)
       {
     case "form":
       DynamicForm d = new DynamicForm();
       d.SuspendLayout();
       dataStack.Push(d);
       break;
     case "label":
       dataStack.Push(new Label());
       break;
     case "combobox":
       dataStack.Push(new ComboBox());
       break;
     case "textbox":
       dataStack.Push(new TextBox());
       break;
     case "button":
       dataStack.Push(new Button());
       break;
     case "checkbox":
       dataStack.Push(new CheckBox());
       break;
     default:
       throw new ArgumentException("Unknown type given");
       }
       return EmptyArray;
 }
        public FormConstructionLanguage()
        {
            dataStack = new Stack <object>();
            EnhancedGrammar grammar = new EnhancedGrammar
            {
                new Rule("S'")
                {
                    new Production {
                        "Block"
                    },
                },
                new Rule("Block")
                {
                    new Production {
                        "Rest", "return"
                    },
                },
                new Rule("Rest")
                {
                    new Production {
                        "BlockStatements",
                    },
                },
                new Rule("BlockStatements")
                {
                    new Production {
                        "BlockStatements", "BlockStatement"
                    },
                    new Production {
                        "BlockStatement"
                    },
                },
                new Rule("BlockStatement")
                {
                    new Production {
                        "Word"
                    },
                },
                new Rule("Word")
                {
                    new Production {
                        "Action"
                    },
                    new Production {
                        "Type"
                    },
                },
                new Rule("Type")
                {
                    new Production((x) => { Push(int.Parse(x[0].ToString())); return(EmptyArray); })
                    {
                        "int"
                    },
                    new Production((x) => { Push(long.Parse(x[0].ToString())); return(EmptyArray); })
                    {
                        "long"
                    },
                    new Production((x) => { Push(float.Parse(x[0].ToString())); return(EmptyArray); })
                    {
                        "float"
                    },
                    new Production((x) => { Push(double.Parse(x[0].ToString())); return(EmptyArray); })
                    {
                        "double"
                    },
                    new Production((x) => { Push(x[0].ToString().Replace("\"", string.Empty)); return(EmptyArray); })
                    {
                        "string-literal"
                    },
                    new Production((x) => { Push(x[0].ToString().Replace("\"", string.Empty)); return(EmptyArray); })
                    {
                        "id"
                    },
                    new Production((x) => { Push(true); return(EmptyArray); })
                    {
                        "true"
                    },
                    new Production((x) => { Push(false); return(EmptyArray); })
                    {
                        "false"
                    },
                },
                new Rule("Action")
                {
                    new Production(NewItem)
                    {
                        "new"
                    },
                    new Production(ImbueItem)
                    {
                        "imbue"
                    },
                    new Production(NewPoint)
                    {
                        "point"
                    },
                    new Production(NewSize)
                    {
                        "size"
                    },
                },
            };

            language = new EnhancedLR1ParsableLanguage(
                "Dynamic Form Constructor Language",
                "1.0.0.0",
                IdSymbol.DEFAULT_IDENTIFIER,
                new Comment[]
            {
                new Comment("single-line-comment", "--", "\n", "\""),
            },
                new Symbol[]
            {
                new Symbol('\n', "Newline", "<new-line>"),
                new Symbol(' ', "Space", "<space>"),
                new Symbol('\t', "Tab", "<tab>"),
                new Symbol('\r', "Carriage Return", "<cr>"),
            },
                new RegexSymbol[]
            {
                new StringLiteral(),
                new CharacterSymbol(),
                new GenericFloatingPointNumber("Single Precision Floating Point Number", "[fF]", "single"),
                new GenericFloatingPointNumber("Double Precision Floating Point Number", "double"),
                new GenericInteger("Long", "[Ll]", "long"),
                new GenericInteger("Int", "int"),
            },
                new Keyword[]
            {
                new Keyword("new"),
                new Keyword("imbue"),
                new Keyword("point"),
                new Keyword("size"),
                new Keyword("extract"),
                new Keyword("true"),
                new Keyword("false"),
                new Keyword("return"),
            },
                LexicalExtensions.DefaultTypedStringSelector,
                grammar,
                "$",
                (x) =>
            {
                object result = dataStack.Pop();
                if (result is DynamicForm)
                {
                    DynamicForm d = (DynamicForm)result;
                    d.ResumeLayout(false);
                    return(d);
                }
                else
                {
                    throw new ArgumentException("A form should always be returned from any of these scripts!");
                }
            },
                true,
                IsValid);
        }