Inheritance: expr
Example #1
0
 public SymtabElt Get(ident i)
 {
     SymtabElt ret;
     if (!symtab.TryGetValue(i, out ret))
     {
         throw new BekParseException(i.line, i.pos, string.Format("'{0}' undefined", i.name));
     }
     return ret;
 }
Example #2
0
        protected void DefineJavaScriptFunction(ident f, StringBuilder sb)
        {
            var func = funcs.Find(fn => fn.id.name.Equals(f.name));
            if (func != null)
            {
                func.ToJS(sb);
                sb.AppendLine(";");
                return;
            }

            switch (f.name)
            {
                case "dec":
                    {
                        sb.AppendLine(@"
            function _dec(){
            var _dec_result = 0;
            var k = 1;
            for (var i = _dec.arguments.length-1; i >= 0; i--)
            {
            _dec_result = _dec_result + ((_dec.arguments[i] & 0xF) * k);
            k = k * 10;
            }
            return _dec_result;
            };");
                        break;
                    }
                case "hex":
                    {
                        sb.AppendLine(@"
            function _hex(){
            var h = 0;
            if (_hex.arguments.length == 1)
            {
            h = _hex.arguments[0] & 0xF;
            h = (h <= 9 ? h + 48 : h + 55);
            }
            else if (_hex.arguments.length > 1)
            {
            h = (_hex.arguments[1] >> (4 * _hex.arguments[0])) & 0xF;
            h = (h <= 9 ? h + 48 : h + 55);
            }
            return h;
            };");
                        break;

                    }
                case "BitExtract":
                    {
                        sb.AppendLine(@"
            function _BitExtract(m, n, c){
            var mask = 0;
            for (var i = 0; i <= (m - n); i++) { mask = (mask << 1) + 1; }
            return (c >> n) & mask;
            };");

                        break;

                    }
                case "Bits":
                    {
                        sb.AppendLine(@"
            function _Bits(m, n, c){
            var mask = 0;
            for (var i = 0; i <= (m - n); i++) { mask = (mask << 1) + 1; }
            return (c >> n) & mask;
            };");

                        break;

                    }

                case "IsLowSurrogate":
                    {
                        sb.AppendLine(@"
            function _IsLowSurrogate(c){
            return ((0xdc00 <= c) && (c <= 0xdfff))
            };");
                        break;
                    }
                case "IsHighSurrogate":
                    {
                        sb.AppendLine(@"
            function _IsHighSurrogate(c){
            return ((0xd800 <= c) && (c <= 0xdbff))
            };");
                        break;

                    }
                case "IsWhitespace":
                    {
                        sb.AppendLine(@"
            function _IsWhitespace(c){
            if (String.fromCharCode(c).match(/^(\s)$/))
              return true;
            else
              return false;
            };");
                        break;
                    }
                case "IsWordletter":
                    {
                        sb.AppendLine(@"
            function _IsWordletter(c){
            if (String.fromCharCode(c).match(/^(\w)$/))
              return true;
            else
              return false;
            };");
                        break;
                    }
                case "IsDecimalDigitNumber":  //digit
                    {
                        sb.AppendLine(@"
            function _IsDecimalDigitNumber(c){
            if (String.fromCharCode(c).match(/^(\d)$/))
              return true;
            else
              return false;
            };");
                        break;
                    }

                default:
                    throw new BekParseException(f.line, f.pos, string.Format("Unknown function '{0}'", f));
            }
        }
Example #3
0
 public BekPgm(ident id, ident inputvar, stmt body)
 {
     this.id = id;
     this.name = id.name;
     this.input = inputvar;
     this.body = body;
 }
Example #4
0
 public replacecase(ident id, params expr[] args)
     : base(id, args)
 {
 }
Example #5
0
 public replace(ident id, IEnumerable<expr> cases)
     : base(id, cases)
 {
 }
Example #6
0
 public replace(ident id, params expr[] cases)
     : base(id, cases)
 {
 }
Example #7
0
 public iterexpr(ident c0, expr src, iterinit init, IEnumerable<itercase> cont)
 {
     this.binder = c0;
     this.source = src;
     this.initializer = init;
     this.body = new List<itercase>(cont);
 }
Example #8
0
 internal SymtabElt GetElt(ident i)
 {
     SymtabElt ret;
     if (!TryGetElt(i.name, out ret))
     {
         throw new BekParseException(i.line, i.pos, string.Format("'{0}' undefined", i.name));
     }
     return ret;
 }
Example #9
0
 public iterassgn(ident l, expr r)
 {
     lhs = l;
     rhs = r;
 }
Example #10
0
 public BekLocalFunction(ident id, ident[] args, expr body)
 {
     this.id = id;
     this.body = body;
     this.args = args;
 }
Example #11
0
        internal void HandleLhs(ident i, BekTypes t, bool implicitdefine=false)
        {
            SymtabElt e;
            if (TryGetElt(i.name, out e))
            {
                if (implicitdefine)
                    throw new BekParseException(i.line, i.pos, string.Format("'{0}' already defined", i.name));
                if (e.type != t)
                    throw new BekParseException(i.line, i.pos, string.Format("'{0}' inconsistent type", i.name));

                this.symtab[i] = e;
            }
            else if (implicitdefine)
            {
                e = new SymtabElt(i, t);
                this.AddElt(i, e);
            }
            else
            {
                throw new BekParseException(i.line, i.pos, string.Format("'{0}' undefined", i.name));
            }
        }
Example #12
0
 public void Alias(ident a, ident withb)
 {
     symtab[a] = symtab[withb];
 }
Example #13
0
 internal SymtabElt AddElt(ident i, SymtabElt e)
 {
     this.names.Peek()[i.name] = e;
     this.symtab[i] = e;
     return e;
 }
Example #14
0
 public functioncall(ident n, IEnumerable<expr> cont)
 {
     this.id = n;
     args = new List<expr>(cont);
 }
Example #15
0
 public iterexpr(ident c0, expr src, iterinit init, params itercase[] cont)
 {
     this.binder = c0;
     this.source = src;
     this.initializer = init;
     this.body = new List<itercase>(cont);
 }
Example #16
0
 public functioncall(ident n, params expr[] cont)
 {
     this.id = n;
     args = new List<expr>(cont);
 }
Example #17
0
        internal void PushIter(ident binder, iterinit initializer)
        {
            this.PushBlock();

            // clear names
            this.RemoveElt(binder.name);
            foreach (var assgn in initializer.assgns)
            {
                this.RemoveElt(assgn.lhs.name);
            }

            // re-assign names
            foreach (var assgn in initializer.assgns)
            {
                this.HandleLhs(assgn.lhs, iter_init_visitor.Visit(this, assgn.rhs), true);
            }
            this.HandleLhs(binder, BekTypes.CHAR, true);
        }