41
Lenguajes de Programación Compiladores e Interpretes M.C Said Zamora

Notas Lenguajes de Programación S1 - 3

Embed Size (px)

DESCRIPTION

Notas

Citation preview

Lenguajes de Programación

Compiladores e Interpretes

M.C Said Zamora

Interpretación

Compilación

Ámbito o alcance

• Parte de un programa en la que una variable es visible.

• let f x = x + 3

Ámbito estático

• El alcance de las ligas sigue la estructura sintáctica del programa.

• C, C++, Pascal, Algol, Scheme, Java, C#, F#

Ámbito anidado

• Un ámbito interior podría ocasionar un problema de ligadura en un ámbito exterior.

• let f x = (let x = 8 in x*2) + (x + 3)

• Algol, Pascal, C, C++.

Lenguajes de Programación Javascript

M.C Said Zamora

Uso

<script ...> JavaScript code

</script>

<script language="javascript" type="text/javascript">

JavaScript code

</script>

Mensaje

<html>

<body>

<script language="javascript" type="text/javascript">

<!--

document.write (“Mensaje")

//-->

</script>

</body>

</html>

Comentarios

<script language="javascript" type="text/javascript">

<!--

//

/*

*

*

*/

//-->

</script>

<html>

<head>

<script type="text/javascript">

<!--

function Hola() {

alert(“Hola")

}

//-->

</script>

</head>

<body>

Click para ver el resultado

<input type="button" onclick=“Hola()" value=“Hola" />

</body>

</html>

Variables

• Números, Strings, Booleanas

<script type="text/javascript">

<!--

var name = "Ali";

var money;

money = 2000.50;

//-->

</script>

Alcance

<script type="text/javascript">

<!--

var myVar = "global"; // Global

function checkscope( ) {

var myVar = "local"; // Local

document.write(myVar);

}

//-->

</script>

Palabras reservadas

Abstract boolean break byte

case catch char class const

continue debugger default delete do

doublé else enum export extends

false final finally float for

function goto if implements import

in Instanceof int interface long

Palabras reservadas

• native new null

• package private protected while

• public return short with

• static super switch

• synchronized this

• throw volatile

• throws transient true

• try typeof void

• var

Lenguajes de Programación Python

M.C Said Zamora

Compilador online

• http://pythonspot.com/run.php

• http://codepad.org/

• http://www.codeskulptor.org/

Mensajes y números

• print("Hello Hi!")

• x = 3

• f = 3.1415926

• name = "Python“

• big = 358315791L

• z = complex(2,3)

• # Comentario

Operadores

• Aritmeticos: + * / -

• Relacionales: = , ==

Entrada

• x = int(raw_input(“Introduzca x:"))

• y = int(raw_input(“Introduzca y:"))

• sum = x + y

• print(sum)

Strings

• s = "Hello Python"

• print(s)

• print(s[0])

• print(s[1])

• print(s[2:4])

• print(s[6:])

Listas

• l = [ "Derpina", "Derp", "Derpette" ]

• print l • print l[0] • print l[1]

• l.append("") • l.remove("") • l.sort() • l.reverse()

Tuplés

• tuple = ()

• tuple = (3,)

• persInfo = ("Diana", 32, “Chiapas")

• nom,edad,pais,carrera = ('Diana',32,’Mexico','Comp')

• x = (3,4,5,6)

• x = x + (1,2,3)

Condicionales

• if ( ):

• Elif( ):

• Else:

for

• words = ['cat', 'window', 'defenestrate']

• >>> for w in words:

• print(w, len(w))

• range()

Funciones

• def nombre( ):

Lenguajes de Programación Perl

M.C Said Zamora

• # Comentario

• Print “Mensaje”;

Identificadores

• $ Escalar

• @ Arreglo

• % Tabla hash

• $edad = 25;

• $nombre= "John Paul";

Arreglos y tablas Hash

• @edades = (25, 30, 40);

• @nombres = ("John Paul", "Lisa", "Kumar");

• print "\$nombres[2] = $nombres[2]\n";

• %data = ('John Paul', 45, 'Lisa', 30, 'Kumar', 40);

Contexto

• @nombres = ('John Paul', 'Lisa', 'Kumar');

• @copia = @nombres;

• $tamaño = @nombres;

Operadores escalares

• $str = "hello" . “hi”;

• $num = 5 + 10;

• $mul = 4 * 5;

$mix = $str . $num;

Arreglos

• @array = (1, 2, 'Hello');

• print "$dia[0]\n";

• @var_20 = (10..20);

• @var_abc = (a..z);

• push (@ARRAY, LIST)

• pop (@ARRAY, LIST)

• shift (@ARRAY, LIST)

• unshift (@ARRAY, LIST)

• @days = qw/Mon Tue Wed Thu Fri Sat Sun/;

• @weekdays = @days[3,4,5];

Tabla Hash

• $data{'John Paul'} = 45;

• $data{'Lisa'} = 30;

• $data{'Kumar'} = 40;

• %data = ('John Paul', 45, 'Lisa', 30, 'Kumar', 40);

• %data = (-JohnPaul => 45, -Lisa => 30, -Kumar => 40);

• @array = @data{-JohnPaul, -Lisa};

Tabla Hash

• $data{'Ali'} = 55;

• delete $data{'Ali'};

If

• $status = ($age > 60 )?

• if(){

• }

• if(){

• }else{

• }

While / For

• while()

• {

• ;

• }

• for ( init; cond; incr ){

• ;

• }

For each

• foreach var () {

• ...

• }

Subrutina

• sub nom{

• }

• nom( arg );