コード例 #1
0
        //check
        public string Visit(CharLiteral node)
        {
            var s = node.AnchorToken.Lexeme;

            if (s.Length > 3)
            {
                if (specials.ContainsKey(s.Substring(1, 2)))
                {
                    return(putS(Indentar() + "ldc.i4.s " + specials[s.Substring(1, 2)])
                           + VisitChildren(node));
                }
                else if (s.Substring(1, 2) == @"\u")
                {
                    var codePoint = specialCode(s.Substring(3, 6));
                    if (codePoint <= 8)
                    {
                        return(putS(Indentar() + "ldc.i4." + codePoint)
                               + VisitChildren(node));
                    }
                    else if (codePoint <= 127)
                    {
                        return(putS(Indentar() + "ldc.i4.s " + codePoint)
                               + VisitChildren(node));
                    }
                    else
                    {
                        return(putS(Indentar() + "ldc.i4 " + codePoint)
                               + VisitChildren(node));
                    }
                }
            }
            return(putS(Indentar() + "ldc.i4.s " + (int)node.AnchorToken.Lexeme[1])
                   + VisitChildren(node));
        }
コード例 #2
0
        //<expr-primary><--<char>//
        public string Visit(CharLiteral node)
        {
            var    charVal   = 0;
            string charsting = node.AnchorToken.Lexeme;

            charVal = getmemychar(charsting, 1);
            var sb = new StringBuilder();

            sb.Append("\t\tldc.i4 " + charVal + "\n");
            return(sb.ToString());
        }
コード例 #3
0
 public virtual T Visit(CharLiteral node)
 {
     return(Visit((OrdinalLiteral)node));
 }
コード例 #4
0
 public override bool Visit(CharLiteral node)
 {
     Visit((OrdinalLiteral)node);
     return(true);
 }
コード例 #5
0
 //-----------------------------------------------------------
 public void Visit(CharLiteral node)
 {
 }
コード例 #6
0
 //-----------------------------------------------------------
 public string Visit(CharLiteral node)
 {
     return(node.AnchorToken.Lexeme);
 }
コード例 #7
0
ファイル: Parser.cs プロジェクト: karloconk/Compiladores
        //<expr-primary>//
        public Node ExprPrimary()
        {
            var xprPri = new Node();
            var funky  = new Node();

            switch (CurrentToken)
            {
            case TokenCategory.IDENTIFIER:
                var myT = Expect(TokenCategory.IDENTIFIER);
                funky = new FunCall()
                {
                    AnchorToken = myT
                };
                xprPri = new Identifier()
                {
                    AnchorToken = myT
                };

                if (CurrentToken == TokenCategory.PARENTHESIS_OPEN)
                {
                    xprPri = funky;
                    Expect(TokenCategory.PARENTHESIS_OPEN);
                    xprPri.Add(ExpressionList());
                    Expect(TokenCategory.PARENTHESIS_CLOSE);
                }
                break;

            case TokenCategory.BRACKET_OPEN:
                Expect(TokenCategory.BRACKET_OPEN);
                xprPri = ExpressionList("Array");
                Expect(TokenCategory.BRACKET_CLOSE);
                break;

            case TokenCategory.STR_LITERAL:
                xprPri = new StringLiteral()
                {
                    AnchorToken = Expect(TokenCategory.STR_LITERAL)
                };
                break;

            case TokenCategory.CHAR_LITERAL:
                xprPri = new CharLiteral()
                {
                    AnchorToken = Expect(TokenCategory.CHAR_LITERAL)
                };
                break;

            case TokenCategory.INT_LITERAL:
                xprPri = new IntLiteral()
                {
                    AnchorToken = Expect(TokenCategory.INT_LITERAL)
                };
                break;

            case TokenCategory.PARENTHESIS_OPEN:
                Expect(TokenCategory.PARENTHESIS_OPEN);
                xprPri = Expression();
                Expect(TokenCategory.PARENTHESIS_CLOSE);
                break;

            default:
                throw new SyntaxError(firstExprPrimary,
                                      tokenStream.Current);
            }
            return(xprPri);
        }
コード例 #8
0
    public void genRepeatExpresion(ILCodeGen cg, ArrayList exp, uint scope, string proc_actual,
                                   Emit.Label ini, Emit.Label body, Emit.Label fin)
    {
        int    tipo = 0;
        Symbol s    = null;

        bool hasAnd = hasToGenAndLabel(exp);

        ReorderWHILEExpression(exp, proc_actual, scope);

        cg.MarkLabel(ini);

        foreach (Expr e in exp)
        {
            if (e is IntLiteral)
            {
                IntLiteral lit = (IntLiteral)e;
                s      = new Symbol(lit.Value, new Type());
                s.Type = new Type(Type.T.INT, 0, null);
                cg.loadVariable(s, false, scope, proc_actual);
            }
            else if (e is RealLiteral)
            {
                RealLiteral lit = (RealLiteral)e;
                s      = new Symbol(lit.Value, new Type());
                s.Type = new Type(Type.T.REAL, 0, null);
                cg.loadVariable(s, false, scope, proc_actual);
            }
            else if (e is BoolLiteral)
            {
                BoolLiteral lit = (BoolLiteral)e;
                s      = new Symbol(lit.Value, new Type());
                s.Type = new Type(Type.T.BOOLEAN, 0, null);
                cg.loadVariable(s, false, scope, proc_actual);
                if (lit.Value == "true")
                {
                    cg.genFalseStatement(body);
                }
                else
                {
                    cg.genTrueStatement(body);
                }
            }
            else if (e is StringLiteral)
            {
                StringLiteral lit = (StringLiteral)e;
                s      = new Symbol(lit.Value, new Type());
                s.Type = new Type(Type.T.STRING, 0, null);
                cg.loadVariable(s, false, scope, proc_actual);
            }
            else if (e is CharLiteral)
            {
                CharLiteral lit = (CharLiteral)e;
                s      = new Symbol(lit.Value, new Type());
                s.Type = new Type(Type.T.CHAR, 0, null);
                cg.loadVariable(s, false, scope, proc_actual);
            }
            else if (e is Variable)
            {
                Variable var = (Variable)e;
                if (scope == 0)
                {
                    s = symtab.getSymbol(var.Value);
                }
                else
                {
                    s = symtab.getSymbol(proc_actual, var.Value, ref tipo);
                }
                if (s != null)
                {
                    if (tipo == 1)
                    {
                        Param p = (Param)s;
                        cg.loadVariable(s, p.Reference, scope, proc_actual);
                    }
                    else
                    {
                        cg.loadVariable(s, false, scope, proc_actual);
                    }
                }
                tipo = 0;
                if (s.Type.toString() == "BOOLEAN")
                {
                    if (var.Tipo == "NOT")
                    {
                        cg.genTrueStatement(body);
                    }
                    else
                    {
                        cg.genFalseStatement(body);
                    }
                }
            }
            else if (e is Function)
            {
                ExpFunction ex = (ExpFunction)e;
            }
            else if (e is EQExpresion)
            {
                if (hasAnd)
                {
                    cg.genDFStatement(fin);
                }
                else
                {
                    cg.genDFStatement(body);
                }
                hasAnd = false;
            }
            else if (e is DFExpresion)
            {
                if (hasAnd)
                {
                    cg.genEQStatement(fin);
                }
                else
                {
                    cg.genEQStatement(body);
                }
                hasAnd = false;
            }
            else if (e is GEExpresion)
            {
                if (hasAnd)
                {
                    cg.genLTStatement(fin);
                }
                else
                {
                    cg.genLTStatement(body);
                }
                hasAnd = false;
            }
            else if (e is GTExpresion)
            {
                if (hasAnd)
                {
                    cg.genLEStatement(fin);
                }
                else
                {
                    cg.genLEStatement(body);
                }
                hasAnd = false;
            }
            else if (e is LEExpresion)
            {
                if (hasAnd)
                {
                    cg.genGTStatement(fin);
                }
                else
                {
                    cg.genGTStatement(body);
                }
                hasAnd = false;
            }
            else if (e is LTExpresion)
            {
                if (hasAnd)
                {
                    cg.genGEStatement(fin);
                }
                else
                {
                    cg.genGEStatement(body);
                }
                hasAnd = false;
            }
        }
    }
コード例 #9
0
    public void genAritExpresion(ILCodeGen cg, ArrayList exp, uint scope,
                                 string proc_actual, string store)
    {
        int    tipo = 0;
        Symbol s    = null;

        foreach (Expr e in exp)
        {
            if (e is IntLiteral)
            {
                IntLiteral lit = (IntLiteral)e;
                s      = new Symbol(lit.Value, new Type());
                s.Type = new Type(Type.T.INT, 0, null);
                cg.loadVariable(s, false, scope, proc_actual);
            }
            else if (e is RealLiteral)
            {
                RealLiteral lit = (RealLiteral)e;
                s      = new Symbol(lit.Value, new Type());
                s.Type = new Type(Type.T.REAL, 0, null);
                cg.loadVariable(s, false, scope, proc_actual);
            }
            else if (e is BoolLiteral)
            {
                BoolLiteral lit = (BoolLiteral)e;
                s      = new Symbol(lit.Value, new Type());
                s.Type = new Type(Type.T.BOOLEAN, 0, null);
                cg.loadVariable(s, false, scope, proc_actual);
            }
            else if (e is StringLiteral)
            {
                StringLiteral lit = (StringLiteral)e;
                s      = new Symbol(lit.Value, new Type());
                s.Type = new Type(Type.T.STRING, 0, null);
                cg.loadVariable(s, false, scope, proc_actual);
            }
            else if (e is CharLiteral)
            {
                CharLiteral lit = (CharLiteral)e;
                s      = new Symbol(lit.Value, new Type());
                s.Type = new Type(Type.T.CHAR, 0, null);
                cg.loadVariable(s, false, scope, proc_actual);
            }
            else if (e is Variable)
            {
                Variable var = (Variable)e;
                if (scope == 0)
                {
                    s = symtab.getSymbol(var.Value);
                }
                else
                {
                    s = symtab.getSymbol(proc_actual, var.Value, ref tipo);
                }
                if (s != null)
                {
                    if (tipo == 1)
                    {
                        Param p = (Param)s;
                        cg.loadVariable(s, p.Reference, scope, proc_actual);
                    }
                    else
                    {
                        cg.loadVariable(s, false, scope, proc_actual);
                    }
                }
                tipo = 0;
            }
            else if (e is Function)
            {
                ExpFunction ex = (ExpFunction)e;
                if (scope == 0)
                {
                    s = symtab.find(store);
                }
                else
                {
                    s = symtab.getSymbol(proc_actual, store, ref tipo);
                }

                if (s != null)
                {
                    if (s.Type.toString() != ex.Tipo)
                    {
                        throw new fpc2ilException("Cannot assing type " + ex.Tipo + " to variable '" + s.Name + "' (" +
                                                  s.Type.toString() + ")");
                    }
                }
                tipo = 0;
            }
            else if (e is PlusExpresion)
            {
                cg.genSuma();
            }
            else if (e is MinusExpresion)
            {
                cg.genResta();
            }
            else if (e is ProductoExpresion)
            {
                cg.genMult();
            }
            else if (e is DivisionExpresion)
            {
                cg.genDivision();
            }
            else if (e is DIVExpresion)
            {
                cg.genDivision();
            }
            else if (e is MODExpresion)
            {
                cg.genMod();
            }
        }

        /* Una vez estan generados todos los loads generamos el store */
        if (scope == 0)
        {
            s = symtab.getSymbol(store);
        }
        else
        {
            s = symtab.getSymbol(proc_actual, store, ref tipo);
        }

        if (s != null)
        {
            if (tipo == 1)
            {
                Param p = (Param)s;
                cg.storeVariable(s, p.Reference, scope, proc_actual);
            }
            else
            {
                /* TODO: Si es una variable de retorno de funcion de momento no hacemos nada */
                if (s.Name != proc_actual)
                {
                    cg.storeVariable(s, false, scope, proc_actual);
                }
            }
        }
    }
コード例 #10
0
 public override Value Visit(CharLiteral node)
 {
     return(Value.CreateConstInt8((sbyte)node.Value.Val <char>()));
 }
コード例 #11
0
 public Boolean Equals(CharLiteral other) => Stringier.Equals(Char, other.Char, ComparisonType);
コード例 #12
0
        //-----------------------------------------------------------
        public string Visit(CharLiteral node)
        {
            var number = (int)Convert.ToChar(node.AnchorToken.Lexeme.Substring(1, 1));

            return(number.ToString());
        }
コード例 #13
0
 public void Visit(CharLiteral node)
 {
     return;
 }
コード例 #14
0
    public Expr getExpresion(string s, uint scope, string proc_actual)
    {
        Symbol symbol = null;
        int    foo    = 0;

        if (scope == 0)
        {
            symbol = symtab.getSymbol(s);
        }
        else
        {
            symbol = symtab.getSymbol(proc_actual, s, ref foo);
        }

        if (symbol == null && !isReservedWord(s))
        {
            if (s == "true" || s == "false")
            {
                BoolLiteral exp1 = new BoolLiteral();
                exp1.Value = s;
                return(exp1);
            }
            else
            {
                int  number     = 0;
                bool canConvert = int.TryParse(s, out number);
                if (!canConvert)
                {
                    double number2;
                    canConvert = double.TryParse(s, out number2);
                    if (canConvert)
                    {
                        RealLiteral exp2 = new RealLiteral();
                        exp2.Value = s;
                        return(exp2);
                    }
                    else
                    {
                        if (s.Length > 1)
                        {
                            StringLiteral exp3 = new StringLiteral();
                            exp3.Value = s;
                            return(exp3);
                        }
                        else
                        {
                            CharLiteral exp4 = new CharLiteral();
                            exp4.Value = s;
                            return(exp4);
                        }
                    }
                }
                else
                {
                    IntLiteral exp4 = new IntLiteral();
                    exp4.Value = s;
                    return(exp4);
                }
            }
        }
        else if (symbol != null)
        {
            switch (symbol.Type.toString())
            {
            case "INT":
                Variable exp5 = new Variable();
                exp5.Value = s;
                exp5.Tipo  = "INT";
                return(exp5);

                break;

            case "REAL":
                Variable exp6 = new Variable();
                exp6.Value = s;
                exp6.Tipo  = "REAL";
                return(exp6);

                break;

            case "STRING":
                Variable exp7 = new Variable();
                exp7.Value = s;
                exp7.Tipo  = "STRING";
                return(exp7);

                break;

            case "BOOLEAN":
                Variable exp8 = new Variable();
                exp8.Value = s;
                exp8.Tipo  = "BOOLEAN";
                return(exp8);

                break;

            case "CHAR":
                Variable exp9 = new Variable();
                exp9.Value = s;
                exp9.Tipo  = "CHAR";
                return(exp9);

                break;
            }
        }
        else
        {
            //Esto son los simbolos reservados que ignoramos
            return(null);
        }
        //Console.WriteLine("No deberia pasar por aqui: " + s);
        return(null);
    }
コード例 #15
0
 //-----------------------------------------------------------
 //<expr-primary><--<char>//
 public void Visit(CharLiteral node, char i)
 {
     ;
 }