Ejemplo n.º 1
0
 public static IEnumerable<iterassgn> Initializers(iterexpr e, Symtab stab)
 {
     foreach (iterassgn ia in assign_filter.Apply(e.initializer))
     {
         yield return ia;
     }
 }
Ejemplo n.º 2
0
 public static IEnumerable<iterassgn> AllUpdates(itercase ic, Symtab stab=null)
 {
     foreach (iterassgn ia in assign_filter.Apply(ic))
     {
         yield return ia;
     }
 }
Ejemplo n.º 3
0
 public static BekProgram BekFromString(string program)
 {
     var tree = ParseFromString(program);
     var stab = new Symtab(tree);
     //TypeChecker.TypeCheck(tree, stab);
     var res = new BekProgram(tree, stab);
     return res;
 }
Ejemplo n.º 4
0
 public static IEnumerable<iterassgn> InitialChars(iterexpr e, Symtab stab)
 {
     foreach (iterassgn ia in assign_filter.Apply(e.initializer))
     {
         if (stab.Get(ia.lhs).type == BekTypes.CHAR)
             yield return ia;
     }
 }
Ejemplo n.º 5
0
 public static IEnumerable<iterassgn> CharUpdates(itercase ic, Symtab stab)
 {
     foreach (iterassgn ia in assign_filter.Apply(ic))
     {
         if (stab.Get(ia.lhs).type == BekTypes.CHAR)
             yield return ia;
     }
 }
Ejemplo n.º 6
0
        public static List <BekProgram> DefsFromString(string programs)
        {
            var res = new List <BekProgram>();

            try
            {
                var input  = new Antlr.Runtime.ANTLRStringStream(programs);
                var lexer  = new bekLexer(input);
                var tokens = new Antlr.Runtime.CommonTokenStream(lexer);
                var parser = new bekParser(tokens);

                var resp = parser.BekPgms();
                foreach (BekPgm cur in resp)
                {
                    var stab = new Symtab(cur);
                    //TypeChecker.TypeCheck(cur, stab);
                    var p = new BekProgram(cur, stab);
                    //Library.PerformExpansions(p);
                    res.Add(p);
                }
            }
            catch (Antlr.Runtime.MismatchedTokenException e)
            {
                string tok = (e.Token != null ? "'" + e.Token.Text + "'" : (e.Character >= 0 ? Microsoft.Automata.StringUtility.Escape((char)e.Character) : ""));
                string msg = "unexpected token " + tok;
                if (tok != "" && 0 <= e.Expecting && e.Expecting < ParserImpl.bekParser.tokenNames.Length)
                {
                    msg += string.Format(" expecting {0}", ParserImpl.bekParser.tokenNames[e.Expecting]);
                }
                throw new BekParseException(e.Line, e.CharPositionInLine, msg);
            }
            catch (Antlr.Runtime.FailedPredicateException e)
            {
                string msg = string.Format("unexpected '{0}' failed {1}", (e.Token != null ? e.Token.Text : ((char)e.Character).ToString()), e.PredicateText);
                throw new BekParseException(e.Line, e.CharPositionInLine, msg);
            }
            catch (Antlr.Runtime.NoViableAltException e)
            {
                string msg = string.Format("unexpected '{0}' no alternatives", (e.Token != null ? e.Token.Text : ((char)e.Character).ToString()));
                throw new BekParseException(e.Line, e.CharPositionInLine, msg);
            }
            catch (Antlr.Runtime.RecognitionException e)
            {
                string msg = string.Format("unexpected '{0}'", (e.Token != null ? e.Token.Text : ((char)e.Character).ToString()));
                throw new BekParseException(e.Line, e.CharPositionInLine, msg);
            }
            catch (BekParseException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                throw new BekParseException(1, 1, e.Message);
            }
            return(res);
        }
Ejemplo n.º 7
0
        public static List<BekProgram> DefsFromString(string programs)
        {
            var res = new List<BekProgram>();
            try
            {
                var input = new Antlr.Runtime.ANTLRStringStream(programs);
                var lexer = new bekLexer(input);
                var tokens = new Antlr.Runtime.CommonTokenStream(lexer);
                var parser = new bekParser(tokens);

                var resp = parser.BekPgms();
                foreach (BekPgm cur in resp)
                {
                    var stab = new Symtab(cur);
                    //TypeChecker.TypeCheck(cur, stab);
                    var p = new BekProgram(cur, stab);
                    //Library.PerformExpansions(p);
                    res.Add(p);
                }
            }
            catch (Antlr.Runtime.MismatchedTokenException e)
            {
                string tok = (e.Token != null ? "'" + e.Token.Text + "'" : (e.Character >= 0 ? Microsoft.Automata.StringUtility.Escape((char)e.Character) : ""));
                string msg = "unexpected token " + tok;
                if (tok != "" && 0 <= e.Expecting && e.Expecting < ParserImpl.bekParser.tokenNames.Length)
                    msg += string.Format(" expecting {0}", ParserImpl.bekParser.tokenNames[e.Expecting]);
                throw new BekParseException(e.Line, e.CharPositionInLine, msg);
            }
            catch (Antlr.Runtime.FailedPredicateException e)
            {
                string msg = string.Format("unexpected '{0}' failed {1}", (e.Token != null ? e.Token.Text : ((char)e.Character).ToString()), e.PredicateText);
                throw new BekParseException(e.Line, e.CharPositionInLine, msg);
            }
            catch (Antlr.Runtime.NoViableAltException e)
            {
                string msg = string.Format("unexpected '{0}' no alternatives", (e.Token != null ? e.Token.Text : ((char)e.Character).ToString()));
                throw new BekParseException(e.Line, e.CharPositionInLine, msg);
            }
            catch (Antlr.Runtime.RecognitionException e)
            {
                string msg = string.Format("unexpected '{0}'", (e.Token != null ? e.Token.Text : ((char)e.Character).ToString()));
                throw new BekParseException(e.Line, e.CharPositionInLine, msg);
            }
            catch (BekParseException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                throw new BekParseException(1, 1, e.Message);
            }
            return res;
        }
Ejemplo n.º 8
0
 public BekProgram(BekPgm ast, Symtab tab)
 {
     this.ast = ast;
     this.stab = tab;
 }
Ejemplo n.º 9
0
 public BekProgram(BekPgm ast, Symtab tab)
 {
     this.ast  = ast;
     this.stab = tab;
 }