Exemplo n.º 1
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;
 }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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;
        }
Exemplo n.º 5
0
        private void GenerateJavaScript(EvaluationContext ec, BekProgram bekpgm)
        {
            var js = new StringBuilder();
            var bek = bekpgm.ast;
            var oldname = bek.name;
            bek.name = "bek";
            bek.GenerateCode("JS", js);
            bek.name = oldname;

            string bek_js_master = (ec.bek_js_master_file != "" ? System.IO.File.ReadAllText(ec.bek_js_master_file) : "BEKJSCODE");
            string bek_js = bek_js_master.Replace("BEKJSCODE", js.ToString());

            System.IO.StreamWriter sw = new System.IO.StreamWriter("c.htm");
            sw.WriteLine(bek_js.ToString());
            sw.Close();

            ec.tw.WriteLine("Generated JavaScript for {0}:", subexpressions[0].ToString());
            ec.tw.WriteLine(js);
        }