M#++ recordando un lenguaje que hicimos para la clase del compiladores por ahi del año 2000

julio 9, 2015

Bienvenido a la página del lenguaje de programación M#++

Este es un lenguaje amateur un poco parecido a C pero con significativas diferencias. Una de ellas es que no te tienes que preocupar por puntos y comas. ¿Cómo se logra esto? En vez de revisar el final de una expresion para delimitarla, usamos el principio, que además nos indica el tipo de expresión que esta es.

Algunos tipos de expresión son:

[# INICIO (equivalente al main de C, cierra con SALIDA #] )

<@ (equivalente a un printf, se pueden usar llaves para imprimir varias cosas)

@> (equivalente a una asignación -en C se utiliza el caracter igual-, tambien equivalente a un scanf usando {STDIN}, en fin es guardar un valor en una variable)

$NAT, $REL y $REA se usan para declarar variables de esos tipos (NAT es equivalente a int, REA a float y REL son numeros relacionales o fracciones, los cuales no existen en C y aqui se representan como [numerador|denominador] ). Tambien acepta arreglos de una, dos y tres dimensiones.

REGRESA (equivalente a return; de C)

[# (se usa para declarar una funcion, cierra con #] )

[: (se usa para llamar una funcion, cierra con ] )

[! un ciclo (incluye while y do-while)

[? una condicion (incluye IF, IF-ELSE, y SWITCH-CASE)

=p! Ejemplo de comentario !=p

Por si fuera poco diferencia variables globales de locales, realiza operaciones anidadas y ADMITE RECURSION!!!!!! (ver último ejemplo)

Aqui unos ejemplos de códigos:

=p! Carlos Madrazo P !=p
=p! archivo: prueba0.txt !=p[# INICIO

<@ { [2|4] {43} [3|6] {61} [2|4]+[3|6] {10} }
<@ { [2|4] {45} [3|6] {61} [2|4]-[3|6] {10} }
<@ { [2|4] {120} [3|6] {61} [2|4]*[3|6] {10} }
<@ { [2|4] {47} [3|6] {61} [2|4]/[3|6] {10} }

SALIDA #]

Ejecutable de este programa
Código ensamblador generado
=p! Carlos Madrazo P !=p
=p! archivo: prueba1.txt !=p$NAT x
$REL f
[#CAR par_impar {$NAT x}
$NAT f
@>f x-x/2*2
[? f EQ 0 ? REGRESA ‘P’ :: REGRESA ‘I’ ?]
#]

[#REL factorial {$NAT x}
$REL resultado
$NAT i
@>i 1
@>resultado i
[! i<=x ? ->
@>resultado resultado*i
@>i i+1
]
REGRESA resultado
#]
[# INICIO
@>x {STDIN}
<@ { x {[:par_impar x]} }
<@ { {[:par_impar x+1]} }
@>f [:factorial x]
<@ { x f }
SALIDA #]

Ejecutable de este programa
=p! Carlos Madrazo P !=p
=p! archivo: prueba2.txt !=p$NAT valor[100]
$CAR pares_o_nones[100]
$REL resultado[100]
$NAT x i y
$REL f
[#CAR par_impar {$NAT x}
$NAT f
@>f x-x/2*2
[? f EQ 0 ? REGRESA ‘P’ :: REGRESA ‘I’ ?]
#]

[#REL factorial {$NAT x}
$REL resultado
$NAT i
@>i 1
@>resultado i
[! i<=x ? ->
@>resultado resultado*i
@>i i+1
]
REGRESA resultado
#]
[# INICIO
@>x {STDIN}
@>y CON (DIR x)
<@ { x y }
@>i 1
[! i<=x ? ->
@>valor[i] i
@>pares_o_nones[i] [:par_impar valor[i]]
@>f [:factorial i]
@>resultado[i] f
@>i i+1
]
@>i 1
[! ->
<@ { valor[i] {pares_o_nones[i]} resultado[i] }
@>i i+1
? i>x ?
]

SALIDA #]

Ejecutable de este programa
=p! Carlos Madrazo P !=p
=p! archivo: prueba3.txt !=p$CAR letra[5%10]
$NAT vocales numeros i j
$NAT s[3]
[# INICIO
@>i 0
[! i<5 ? ->
@>j 0
[! j<10 ? ->
=p!<@ {10*(i)+j} linea a capturar !=p
@>letra[i%j] { STDIN }
=p! <@ {letra[i%j]} !=p
@>j j+1
]
@>i i+1
]
@>vocales 0 @>numeros vocales
=p! <@ {vocales numeros} 0 0 !=p
@>i 0
[! i<3 ? -> @>s[i] 0 @>i i+1 ]
@>i 0
[! i<5 ? ->
@>j 0
[! j<10 ? ->
[? letra[i%j] ::
‘A’ ? @>vocales vocales+1
@>s[0] s[0]+(letra[i%j]-64)
::
‘1’ ? @>numeros numeros+1
@>s[1]=s[1]+(letra[i%j]-48)
::
DE_PERDIS ? @>s[2] s[2]+1
?]
@>j j+1
]
@>i i+1
]
<@ {s[0] s[1] s[2]}
<@ {vocales numeros}
@>i 0
[! i<5 ? ->
@>j 0
[! j<10 ? ->
<@ {letra[i%j]}
@>j j+1
]
<@ {i}
@>i i+1
]

SALIDA #]

Ejecutable de este programa
=p! Carlos Madrazo P !=p
=p! archivo: prueba4.txt !=p$NAT valores[5%5]
$NAT i j
$REL s[5]

[# INICIO
@>i 0
[! i<5 ? ->
@>s[i] [1|1]
@>j 0
[! j<5 ? ->
@>valores[i%j] { STDIN }
=p! <@ {valores[i%j] s[i]} !=p
@>s[i] s[i]*valores[i%j]
=p! <@ {s[i]} !=p
@>j j+1
]
<@ {s[i]}
@>i i+1
]
@>i 0
[! i<5 ? ->
@>j 0
[! j<5 ? ->
<@ { valores[i%j] }
@>j j+1
]
<@ { s[i] }
@>i i+1
]

SALIDA #]

Ejecutable de este programa
=p! Carlos Madrazo P !=p
=p! archivo: factorial.txt !=p[#NAT factorial {$NAT n}
[? n EQ 0 ? REGRESA 1 :: REGRESA n*[:factorial n-1] ?]
#]
[# INICIO
$NAT x
@>x {STDIN}
<@ { [:factorial x] }
SALIDA #]
Ejecutable de este programa
Código ensamblador generado

Se utilizaron PCYACC y PCLEX para que generara un codigo intermedio y una tabla de variables, y posteriormente en una segunda fase código ensamblador para nasm, el cual necesita un archivo de macros para ensamblar (ver tutoriales).

Ejemplo de un .bat para construir y compilar todo:

pcyacc -d proy3py.y
pclex proy3pl.l
cl /FePROY3P proy3pl.c proy3py.c

pcyacc -d cfinaly.y
pclex cfinall.l
cl /FeCFINAL cfinall.c cfinaly.c

pcyacc -d cfinal2y.y
pclex cfinal2l.l
cl /FeCFINAL2 cfinal2l.c cfinal2y.c

PROY3P < factorial.txt
CFINAL < codint.txt
CFINAL2 < codint.txt
nasmw codfin.asm -fwin32
cl /Fefactorial codfin_main.cpp codfin.obj
echo TERMINO COMPILACION


Mts to mov

febrero 17, 2013

Para convertir vídeos en formato MTS usando FFMPEG
for x in *.MTS; do ffmpeg -i ${x} -vcodec mpeg1video -acodec mp2 -ac 2 -sameq ${x/.MTS/.mov}; done
Referente: http://phajdan-jr.blogspot.com/2012/05/ffmpeg-saves-day-mts-files.html


Compile a OpenGL program in Windows (Visual Studio)

febrero 27, 2012

SOURCE: http://www.divms.uiowa.edu/~cwyman/classes/common/howto/winGLUT.html

Compiling OpenGL Progams at Home Using Visual Studio

Windows does not include GLUT standard, like the lab machines in MLH 301 do. Thus, getting your OpenGL programs to compile and run at home is slightly more difficult. However by following the following steps, you should be able to figure out how to make it work:

Download GLUT
Unzip the file.
Put the file “glut32.dll” into the system path.
This can be in the same directory as your executable file.
On Windows XP or earlier, this can be in “C:\WINDOWS\system32”
Or you can create a directory like “C:\DLLs”, put the file in this directory and change your system path to include this new directory.
Do this by opening Control Panel -> System, clicking on “Advanced System Settings”, followed by “Environment Variables”, and editing the “Path” variable.
Put the file “glut.h” into the standard Visual C++ include directoy
(For Visual Studio 2010, this should be: “C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\gl”)
(For Visual Studio 2008, this should be: “C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include\gl”)
(For Visual Studio 2005, this should be: “C:\Program Files\Microsoft Visual Studio.NET\Vc7\PlatformSDK\Include\gl”)
You’ve got the right directory if you see a copy of “gl.h”
Put the file “glut32.lib” into the standard Visual C++ library directory
(For Visual Studio 2010, this should be: “C:\Program Files\Microsoft SDKs\Windows\v7.0A\Lib”)
(For Visual Studio 2008, this should be: “C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib”)
(For Visual Studio 2005, this should be: “C:\Program Files\Microsoft Visual Studio.NET\Vc7\PlatformSDK\lib”)
There should be lots of .lib files here, including “opengl32.lib” and “glu32.lib”.
Make sure your Visual C++ project links in the GLUT/gl/glu libraries (see also this page). This is located in:
Menu: “Project -> (your-project-name) Properties”
Tab: “Configuration Properties -> Linker -> Input”
Under “Additional Dependancies”, add “glut32.lib glu32.lib opengl32.lib”
#include in your program.
Note: This needs to come after you #include and .
Note: This needs to come before you #include .
Also note that glut.h includes gl.h for you (so you need not explicitly #include ).
You should not include windows.h or any other Windows-specific header files, no matter what you may read on random forum postings!
If you get compilation errors because of multiple conflicting definitions of “exit()”, then “stdio.h” and “glut.h” have been #include’d in the wrong order. You may fix this by:
Reordering your #include files (see step #7). This is the “right” way.
Add “#define GLUT_DISABLE_ATEXIT_HACK” to glut.h on the line immediately after the first “#if defined(_WIN32)”.
If you happen to have a 64-bit version of Windows and Visual Studio, make sure you compile a 32-bit executable.
NOTE: Later in the course, you may also need to install GLEW. Follow the same directions: install the DLLs into the system directory, the header files in the include directory, and the library files into the lib directory.

Last Modified: Friday, August 28, 2009

Chris Wyman (cwyman@cs.uiowa.edu)


Editores de Texto

noviembre 27, 2011

Windows
notepad++ (MEL definition)
mi (windows ver.)

Mac
mi (mel definition)
TextWrangler
Carbon emacs
Vim

Linux

Multiplataforma (java)
jEdit


Interval tree for 2D intersection tests

octubre 14, 2010

“We can use the interval tree [Ede83] for static query, as well as for the
rectangle intersection problem. Each query of interval intersection takes
O(logn + k) time where k is the number of reported intersection and n
is the number of intervals. Therefore, reporting intersection among n
rectangles can be done in O(nlogn + K) where K is the total number of
intersecting rectangles.”

Collision detection between geometricmodels: a survey
Ming C. Lin & Stefan Gottschalk


Japanese Latex on Mac in texshop, including Beamer

agosto 31, 2010

Option 1) Use CJK pakage (CJKutf8 for UTF-8 encoding) and use normal latex

¥usepackage[10pt]{type1ec} % use only 10pt fonts
¥usepackage[T1]{fontenc}
¥usepackage{CJKutf8}
¥usepackage[german, russian, vietnam, USenglish]{babel}
¥usepackage[overlap, CJK]{ruby}
¥usepackage{CJKulem}
¥renewcommand{¥rubysep}{-0.2ex}
¥newenvironment{Japanese}{%
¥CJKfamily{min}%
¥CJKtilde
¥CJKnospace}{}
¥begin{document}
¥begin{CJK}{UTF8}{}
¥begin{Japanese}
これは日本語の文章
¥end{Japanese}
¥end{CJK}
¥end{document}

A latex code

Option 2) Use ptex (platex) *Recommended

Install by Macports:
sudo port install pTeX +hiragino +otf +utf8 +motif +macosx

In texshop->configuration, change “Profile” (a Drop menu at the bottom) to pTeX (EUC).
Save a tex file in EUC encoding.

I had to modify the file “/Users/carlos/Library/TeXShop/bin/platex2pdf-euc” to change path to “opt” instead of “usr”

If fontspec is needed:
sudo tlmgr update –self
sudo tlmgr install fontspec

%¥documentclass[twocolumn,11pt]{jarticle} %In case two column layout
¥documentclass[a4j]{jarticle}
¥usepackage{graphicx} %for including graphics
¥usepackage{nidanfloat}
¥usepackage{url}
¥title{タイトル}
¥author{ 僕の名前 }
¥date{2010年}
¥renewcommand{¥refname}{References}
¥begin{document}
¥maketitle
¥section{テスト}
これはテストです。
¥end{document}

A latex code

To use Beamer with platex, I had to reinstall the caption package in CTAN (Download all the .ins and .dtx files and type “platex caption.ins” in the terminal; copy to current directory). The following templete from here was useful:

\documentclass[14pt,dvipdfm]{beamer}
% pdfの栞の字化けを防ぐ
% \AtBeginDvi{\special{pdf:tounicode EUC-UCS2}}
% テーマ
\usetheme{AnnArbor}
% navi. symbolsは目立たないが,dvipdfmxを使うと機能しないので非表示に
\setbeamertemplate{navigation symbols}{}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amssymb}
% フォントはお好みで
\usepackage{txfonts}
\mathversion{bold}
\renewcommand{\familydefault}{\sfdefault}
\renewcommand{\kanjifamilydefault}{\gtdefault}
\setbeamerfont{title}{size=\large,series=\bfseries}
\setbeamerfont{frametitle}{size=\large,series=\bfseries}
\setbeamertemplate{frametitle}[default][center]
\usefonttheme{professionalfonts}
%
\title{PowerPoint{\color{red}なしで}
プレゼンテーション}
\author{かさい ますみ}
\institute{弘前大学}
\date{2005年12月吉日}
\begin{document}
\frame{\titlepage}
\end{document}

To include furigana (small kana above the kanji), use furikana.sty

Y copied all files to /opt/local/share/Library/texmf/ptex/platex/base and ran sudo mktexlsr
Include
\usepackage{furikana}
in your document.
use the “kana” command: ¥kana{漢}{かん}¥kana{字}{じ}

This made me a problem in beamer (an @ appeared in the background), so I had to use the following marco (found here) instead:
%
% macro ルビ usage: \ruby{漢}{かん}\ruby{字}{じ}
%
\def\ruby#1#2{%
\leavevmode
\setbox0=\hbox{#1}\setbox1=\hbox{\tiny#2}%
\ifdim\wd0>\wd1 \dimen0=\wd0 \else \dimen0=\wd1 \fi
\hbox{\kanjiskip=\fill
\vbox{\hbox to \dimen0{\tiny \hfil#2\hfil}%
\nointerlineskip
\hbox to \dimen0{\hfil#1\hfil}}}}


DevIL on Mac with PNG support

junio 3, 2010

DevIL is a library to manage many kind of image formats, as jpg, bmp, jpg, tga..
In Mac, can be installed libpng or libpng12 in darwin ports (mac ports) for png format, and then configure DevIL by:

./configure CC=”gcc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk” CFLAGS=”-I/sw/include -L/sw/lib” LDFLAGS=”-L/sw/lib”

As an alternative, by installing libpng (and libjpg) by this binary file:
http://ethan.tira-thompson.org/Mac_OS_X_Ports.html

and configure DevIL by:
./configure CC=”gcc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk” CFLAGS=”-I/usr/local/include/libpng -L/local/lib” LDFLAGS=”-L/local/lib”

On both cases, run:
autoreconf -i
before ./configure

and
make
sudo make install

to install


Implicit representation of a sphere and cube on a regular grid

mayo 4, 2010


void MakeSphere(Grid &grid, Double h, const Vector &pos, Double radius)
{
FOR_ALL
grid[INDEX(i,j,k)] =((pos-Vector(i,j,k)).Length()-radius) *h;
END_THREE
}


void MakeCube(Grid &init, Double h, const Vector &pos1, const Vector &pos2)
{
FOR_ALL_LS
//Find Nearest Point
Vector Nearest;
Nearest[0] = Clamp((Float)i,pos1[0],pos2[0]);
Nearest[1] = Clamp((Float)j,pos1[1],pos2[1]);
Nearest[2] = Clamp((Float)k,pos1[2],pos2[2]);
if(Nearest[0]==i&&Nearest[1]==j&&Nearest[2]==k){ //inside
Double d1 = min(abs(i-pos1[0]),abs(i-pos2[0]));
Double d2 = min(abs(j-pos1[1]),abs(j-pos2[1]));
Double d3 = min(abs(k-pos1[2]),abs(k-pos2[2]));
init(i,j,k) = -min(d1,min(d2,d3))* h;
}else{ //outside
init(i,j,k) = (Nearest-Vector(i,j,k)).Length()* h;
}
END_FOR_THREE
}


Delaunay triangulations

mayo 4, 2010

Sometimes we want to divide a space (delimited by a polygon / polyhedral representation) into triangles. This is useful for calculations inside a body such as stress in elastic / breaking simulations and also fluid simulation. There are many ways to to do this. Delaunay is optimal since avoids “skinny triangles”. Algorithms to create Delaunay triangulations include: Flip method, incremental, divide and conquer, and sweepline. For 3D triangle construction from a isosurface input, “isosurface stuffing” (Labelle, SIGGRAPH 2007) can be used:

“The isosurface stuffing algorithm by Labelle and Shewchuk produces a well-conditioned mesh by snapping some vertices to the triangulated surface and refining others using a precomputed stencil”.

Useful when higher resolution is desired near the surface.

Some useful triangulation code:

Triangle
http://www.compgeom.com/~piyush/scripts/triangle/index.html
(in 2D!)

Pyramid
3D version of Triangle but maybe it is not available?

Qhull
http://www.qhull.org/

CGAL
http://www.cgal.org/Manual/last/doc_html/cgal_manual/packages.html#Pkg:Triangulation3

LEDA
http://www.algorithmic-solutions.com/leda/ledar/index.htm


Text in OpenGL

marzo 21, 2010

There are various ways for including text in a OpenGL.
Some of them are discussed here:
http://www.opengl.org/resources/features/fontsurvey/