void ParseNum(out DirectValueSymbol res) { Expect(45); Expect(5); Expresion(); Expect(8); var number = _symbolStack.Pop(); res = _varBuilder.NewVariable(Type.Decimal); DoParse(number, res); }
/// <summary> /// Builds commands so that the current value of an array is stored. /// </summary> /// <param name="array">Array to be accessed.</param> /// <param name="recipient">Symbol where value will be stored.</param> private void DoGetArrayValue(DirectValueSymbol array, DirectValueSymbol recipient) { var cmd = new Assign { Recipient = recipient, Source = array }; _currentScope.CommandList.Commands.Add(cmd); }
/// <summary> /// Builds a new Random command and adds it to current scope. /// </summary> /// <param name="result">Symbol where result will be stored.</param> private void DoRandom(DirectValueSymbol result) { var cmd = new Random { Result = result }; _currentScope.CommandList.Commands.Add(cmd); }
void Constante(out DirectValueSymbol sym) { sym = null; if (la.kind == 3) { Get(); sym = _constBuilder.IntConstant(t.val); } else if (la.kind == 4) { Get(); sym = _constBuilder.DecConstant(t.val); } else if (la.kind == 46 || la.kind == 47) { Ctebol(); sym = _constBuilder.BoolConstant(t.val); } else if (la.kind == 2) { Get(); sym = _constBuilder.StrConstant(t.val); } else if (la.kind == 45) { ParseNum(out sym); _currentScope.Add(sym); } else if (la.kind == 43) { Aleatorio(); sym = _varBuilder.NewVariable(Type.Decimal); DoRandom(sym); _currentScope.Add(sym); } else if (la.kind == 44) { Lectura(); sym = _varBuilder.NewVariable(Type.Cadena); DoRead(sym); _currentScope.Add(sym); } else if (FollowedByLPar()) { Function function; List <DirectValueSymbol> parameters; Funcion(out function, out parameters); var result = _varBuilder.NewVariable(function.Type); DoFunction(function, parameters, result); sym = result; _currentScope.Add(sym); } else if (la.kind == 1) { Variable variable; List <DirectValueSymbol> indexes; Variable(out variable, out indexes); sym = variable; if (variable is VariableArray) { sym = _varBuilder.NewVariable(variable.Type); DoGetArrayValue(variable, sym); _currentScope.Add(sym); } } else { SynErr(53); } }
/// <summary> /// Updates a function object to include its return symbol. /// </summary> /// <param name="name">Name of the function to update.</param> /// <param name="returns">The symbol with the return value.</param> private void AddReturns(string name, DirectValueSymbol returns) { var function = _currentScope.Search(name) as Function; if (function != null) { function.Returns = returns; } }
/// <summary> /// Builds a new dibujarTriangulo command and adds it to current scope /// </summary> /// <param name="backgroundColor">Background color of the triangle</param> /// <param name="lineColor">Line color of the triangle</param> /// <param name="thickness">thickness of the triangle</param> /// <param name="x1">coodinate</param> /// <param name="y1">coodinate</param> /// <param name="x2">coodinate</param> /// <param name="y2">coodinate</param> /// <param name="x3">coodinate</param> /// <param name="y3">coodinate</param> void DoTriangle(DirectValueSymbol backgroundColor, DirectValueSymbol lineColor, DirectValueSymbol thickness, DirectValueSymbol x1, DirectValueSymbol y1, DirectValueSymbol x2, DirectValueSymbol y2, DirectValueSymbol x3, DirectValueSymbol y3) { if (backgroundColor.Type != Type.Cadena) { SemErr("Error de tipos"); return; } else if (lineColor.Type != Type.Cadena) { SemErr("Error de tipos"); return; } else if (thickness.Type != Type.Entero) { SemErr("Error de tipos"); return; } else if (x1.Type != Type.Decimal && x1.Type != Type.Entero) { SemErr("Error de tipos"); return; } else if (y1.Type != Type.Decimal && y1.Type != Type.Entero) { SemErr("Error de tipos"); return; } else if (x2.Type != Type.Decimal && x2.Type != Type.Entero) { SemErr("Error de tipos"); return; } else if (y2.Type != Type.Decimal && y2.Type != Type.Entero) { SemErr("Error de tipos"); return; } else if (x3.Type != Type.Decimal && x3.Type != Type.Entero) { SemErr("Error de tipos"); return; } else if (y3.Type != Type.Decimal && y3.Type != Type.Entero) { SemErr("Error de tipos"); return; } var cmd = new Triangle { BackgroundColor = backgroundColor, LineColor = lineColor, Thickness = thickness, X1 = x1, Y1 = y1, X2 = x2, Y2 = y2, X3 = x3, Y3 = y3 }; _currentScope.CommandList.Commands.Add(cmd); }
/// <summary> /// Builds a conditional command and adds it to the current scope. /// </summary> /// <param name="condition">The symbol containing the condition value. /// </param> /// <param name="ifBlock">Commands executed if condition is met.</param> /// <param name="elseBlock">Commands to execute if false.</param> private void DoIfElse(DirectValueSymbol condition, CommandList ifBlock, CommandList elseBlock) { var cmd = new Conditional { Condition = condition, If = ifBlock, Else = elseBlock }; _currentScope.CommandList.Commands.Add(cmd); }
/// <summary> /// Does a parse command. /// </summary> /// <param name="str">Symbol with the string to parse.</param> /// <param name="result">Symbol where parsed value will be stored.</param> private void DoParse(DirectValueSymbol str, DirectValueSymbol result) { if (str.Type != Type.Cadena) { SemErr("El valor a convertir debe de ser una cadena."); } var cmd = new Parse { Source = str, Recipient = result }; _currentScope.CommandList.Commands.Add(cmd); }
/// <summary> /// Builds a new While command and adds it to current scope. /// </summary> /// <param name="expression">Commands to update the condition.</param> /// <param name="result">Symbol where result of condition is stored.</param> /// <param name="whileBlock">Commands to be executed in loop.</param> private void DoWhile(CommandList expression, DirectValueSymbol result, CommandList whileBlock) { if (result.Type != Type.Booleano) { SemErr("Error de tipos"); return; } var cmd = new While { Expression = expression, WhileBlock = whileBlock, Result = result }; _currentScope.CommandList.Commands.Add(cmd); }
/// <summary> /// Builds a new dibujarArco command and adds it to current scope /// </summary> /// <param name="lineColor">Line color of the Arc</param> /// <param name="thickness">thickness of the Arc</param> /// <param name="x">Coordinate</param> /// <param name="y">Coordinate</param> /// <param name="width">Width of the Arc</param> /// <param name="height">Height of the Arc</param> /// <param name="startAngle">startAngle of the Arc</param> /// <param name="finalAngle">startAngle of the Arc</param> void DoArc(DirectValueSymbol lineColor, DirectValueSymbol thickness, DirectValueSymbol x, DirectValueSymbol y, DirectValueSymbol width, DirectValueSymbol height, DirectValueSymbol startAngle, DirectValueSymbol finalAngle) { if (lineColor.Type != Type.Cadena) { SemErr("Error de tipos"); return; } else if (thickness.Type != Type.Entero) { SemErr("Error de tipos"); return; } else if (x.Type != Type.Decimal && x.Type != Type.Entero) { SemErr("Error de tipos"); return; } else if (y.Type != Type.Decimal && y.Type != Type.Entero) { SemErr("Error de tipos"); return; } else if (width.Type != Type.Decimal && width.Type != Type.Entero) { SemErr("Error de tipos"); return; } else if (height.Type != Type.Decimal && height.Type != Type.Entero) { SemErr("Error de tipos"); return; } else if (startAngle.Type != Type.Entero) { SemErr("Error de tipos"); return; } else if (finalAngle.Type != Type.Entero) { SemErr("Error de tipos"); return; } var cmd = new Arc { Color = lineColor, Thickness = thickness, X = x, Y = y, Width = width, Height = height, StartAngle = startAngle, FinalAngle = finalAngle }; _currentScope.CommandList.Commands.Add(cmd); }
/// <summary> /// Builds a new dibujarRectangle command and adds it to current scope /// </summary> /// <param name="backgroundColor">Background color of the Rectangle</param> /// <param name="lineColor">Line color of the Rectangle</param> /// <param name="thickness">thickness of the Rectangle</param> /// <param name="x">Coordinate</param> /// <param name="y">Coordinate</param> /// <param name="width">Width of the Rectangle</param> /// <param name="height">Height of the Rectangle</param> void DoRectangle(DirectValueSymbol backgroundColor, DirectValueSymbol lineColor, DirectValueSymbol thickness, DirectValueSymbol x, DirectValueSymbol y, DirectValueSymbol width, DirectValueSymbol height) { if (backgroundColor.Type != Type.Cadena) { SemErr("Error de tipos"); return; } else if (lineColor.Type != Type.Cadena) { SemErr("Error de tipos"); return; } else if (thickness.Type != Type.Entero) { SemErr("Error de tipos"); return; } else if (x.Type != Type.Decimal && x.Type != Type.Entero) { SemErr("Error de tipos"); return; } else if (y.Type != Type.Decimal && y.Type != Type.Entero) { SemErr("Error de tipos"); return; } else if (width.Type != Type.Decimal && width.Type != Type.Entero) { SemErr("Error de tipos"); return; } else if (height.Type != Type.Decimal && height.Type != Type.Entero) { SemErr("Error de tipos"); return; } var cmd = new Rectan { BackgroundColor = backgroundColor, LineColor = lineColor, Thickness = thickness, X = x, Y = y, Width = width, Height = height }; _currentScope.CommandList.Commands.Add(cmd); }
/// <summary> /// Builds a new dibujarLinea command and adds it to current scope /// </summary> /// <param name="lineColor">Line color of the Line</param> /// <param name="thickness">thickness of the Line</param> /// <param name="x1">Coordinate</param> /// <param name="y1">Coordinate</param> /// <param name="x2">Coordinate</param> /// <param name="y2">Coordinate</param> void DoLine(DirectValueSymbol lineColor, DirectValueSymbol thickness, DirectValueSymbol x1, DirectValueSymbol y1, DirectValueSymbol x2, DirectValueSymbol y2) { if (lineColor.Type != Type.Cadena) { SemErr("Error de tipos"); return; } else if (thickness.Type != Type.Entero) { SemErr("Error de tipos"); return; } else if (x1.Type != Type.Decimal && x1.Type != Type.Entero) { SemErr("Error de tipos"); return; } else if (y1.Type != Type.Decimal && y1.Type != Type.Entero) { SemErr("Error de tipos"); return; } else if (x2.Type != Type.Decimal && x2.Type != Type.Entero) { SemErr("Error de tipos"); return; } else if (y2.Type != Type.Decimal && y2.Type != Type.Entero) { SemErr("Error de tipos"); return; } var cmd = new Line { Color = lineColor, Thickness = thickness, X1 = x1, Y1 = y1, X2 = x2, Y2 = y2 }; _currentScope.CommandList.Commands.Add(cmd); }
void Bloque(string name, Variable[] parameters, bool isFunction, out DirectValueSymbol returns) { Expect(17); CreateNewScope(name, new List <Variable>(parameters)); DoPushDefaults(); returns = null; while (StartOf(3)) { if (DoubleFollowedByLPar()) { DeclaracionFunc(); } else if (StartOf(2)) { Declaracion(); } else if (la.kind == 21) { Condicion(); } else if (la.kind == 23) { Ciclo(); } else if (la.kind == 25) { DrawLine(); } else if (la.kind == 26) { DrawArc(); } else if (la.kind == 27) { DrawRec(); } else if (la.kind == 28) { DrawEllipse(); } else if (la.kind == 29) { DrawTriangle(); } else if (la.kind == 24) { Impresion(); } else if (FollowedByLPar()) { Function function; List <DirectValueSymbol> paras; Funcion(out function, out paras); Expect(9); DoRoutine(function, paras); } else { Asignacion(); } } CheckFunctionsNoBody(); var hasReturn = false; if (la.kind == 18) { Get(); Expresion(); Expect(9); hasReturn = true; returns = _symbolStack.Pop(); _currentScope.Returns = returns; } Expect(19); ValidateHasReturn(isFunction, hasReturn); DoPopLocals(); _currentScope = _currentScope.Parent; }
/// <summary> /// Builds a new CallFunction command and adds it to current scope. /// </summary> /// <param name="function">Function to be called</param> /// <param name="parameters">Symbols that correspond to the parameters. /// </param> /// <param name="result">Symbol where result will be stored.</param> private void DoFunction(Function function, List <DirectValueSymbol> parameters, DirectValueSymbol result) { if (function.Type == Type.Rutina) { SemErr("La función no tiene un valor de retorno."); return; } for (var para = 0; para < parameters.Count; para++) { if (_cube[(int)function.Parameters[para].Type, (int)parameters[para].Type, (int)Operator.Asignation] != function.Parameters[para].Type) { SemErr("Error de tipos"); return; } } result.Type = function.Type; var cmd = new CallFunction { Function = function, ScopeCalled = _currentScope, Result = result, Parameters = parameters }; _currentScope.CommandList.Commands.Add(cmd); }