コード例 #1
0
        static void Main(string[] args)
        {
            Grammer g = new Grammer("code := {vardec}\nvardec := var(\\s)+{name}(\\s)+=(\\s)+{value}\nname := [A-Za-z]+\nvalue := [0-9]+");
            var x = g.Parse("code", "var i = 10;");

            X86Compiler cp = new X86Compiler();
            List<Asty> CodeBlock = new List<Asty>();
            CodeBlock.Add(new VarDec() { Type = DataType.int32 });
            cp.Compile(new Method() { Name = "main", CodeBlock = CodeBlock });
            File.WriteAllText("test.asm", cp.GetString());
        }
コード例 #2
0
ファイル: Automata.cs プロジェクト: sohaibafifi/automata
    /// <summary>
    /// Obtenir le grammaire qui defini le language defini par l'automate courant
    /// </summary>
    /// <returns>Un grammer equivalant</returns>
    public Grammer toGrammer()
    {
        Gfa auto = this.toGfa();
        ArrayList v = new ArrayList();
        for (char i = 'A'; i < auto.S + 'A'; i++)
            v.Add(i);
        if (v.Count == 0) v.Add('A');
        Grammer result = new Grammer(auto.X, v, (char)v[auto.S0]);
        for (int i = 0; i < this.S; i++)
            for (int k = 0; k < auto.Read.Count; k++)
            {
                string word = auto.Read[k].ToString();
                foreach (int j in auto.getInstruction(i, word))
                {
                    result.AddProduction(new Grammer.ProductionRule((char)result.V[i], word, (char)result.V[j]));
                    if (auto.F.Contains(j))
                        result.AddProduction(new Grammer.ProductionRule((char)result.V[i], word, Grammer.NOVARIABLE));

                }
            }
        return result;
    }
コード例 #3
0
 public static void Init()
 {
     Grammmer = new Grammer(Properties.Resources.Grammer);
 }