Exemplo n.º 1
0
        private Rule parseUpdateRule(string pname, string rule, Declarations decls)
        {
            int len   = 1;
            int equal = rule.IndexOf(":=");

            if (equal < 0)
            {
                equal = rule.IndexOf('=');
            }
            else
            {
                len = 2;
            }
            if (equal < 0)
            {
                throw new ParseException(String.Format("Invalid update rule '{0}'!", rule));
            }

            string varname = rule.Substring(0, equal).Trim();
            string upexpr  = rule.Substring(equal + len).Trim();

            VarDecl vd = decls.getVar(varname);

            if (vd == null)
            {
                throw new ParseException(String.Format("Unknown variable {0}!", varname));
            }

            string       expr     = String.Format("int _UPDATE_{0} = {1};", varname, upexpr);
            Declarations newdecls = parseDeclarations(expr, decls);
            Expression   e        = newdecls.getFirstDecl().Expr;

            return(new UpdateRule(varname, e));
        }
Exemplo n.º 2
0
        private Rule parseSyncRule(string pname, string rule, Declarations decls)
        {
            SyncRule.Direction dir;

            if (rule.EndsWith("?"))
            {
                dir = SyncRule.Direction.Receive;
            }
            else
            if (rule.EndsWith("!"))
            {
                dir = SyncRule.Direction.Send;
            }
            else
            {
                throw new ParseException(String.Format("Synchronization rule '{0}' must end with '!' or '?'!"));
            }

            rule = rule.TrimEnd(new char[] { '?', '!' });
            string       expr     = String.Format("chan _CHANNEL_ = {0};", rule);
            Declarations newdecls = parseDeclarations(expr, decls);
            Expression   e        = newdecls.getVar("_CHANNEL_").Expr;

            return(new SyncRule(e, dir));
        }
Exemplo n.º 3
0
        public TypeDecl GetType(Declarations symtab)
        {
            switch (Type)
            {
            case ExpType.Const:
                return(new TypeDecl()
                {
                    Type = VarType.Int
                });

            case ExpType.Var:
                VarDecl v = symtab.getVar(Var);
                if (v == null)
                {
                    throw new ParseException(String.Format("Unknown variable {0}", Var));
                }
                return(v.Type);

            case ExpType.Func:
                // this should be improved later
                return(new TypeDecl()
                {
                    Type = VarType.Int
                });

            default:
                throw new ParseException("Internal error 1");
            }
        }
Exemplo n.º 4
0
        private Rule parseGuardRule(string pname, string rule, Declarations decls)
        {
            string       expr     = String.Format("bool _GUARD_ = {0};", rule);
            Declarations newdecls = parseDeclarations(expr, decls);
            Expression   e        = newdecls.getVar("_GUARD_").Expr;

            return(new GuardRule(e));
        }