Last active
August 31, 2015 11:42
-
-
Save andersonfraga/d787178c850fe2640a37 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## | |
# Anderson Jean Fraga | |
# 13180375 | |
# Compiladores - Trabalho 1 - Execute | |
## | |
file="Lexica_0$1" | |
if [[ -f "$file.flex" ]]; then | |
ucfile="$(tr '[:lower:]' '[:upper:]' <<< ${file:0:1})${file:1}" | |
rm $file.{java,java~,html} | |
jflex $file.flex | |
javac $ucfile.java | |
java $ucfile $file.txt | |
else | |
echo "File '${file}.flex' not found. Create, too, '${file}.txt' to test" | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% | |
/** | |
* Anderson Jean Fraga | |
* 13180375 | |
* Compiladores - Trabalho 1 - Exercicio 1 | |
*/ | |
%public | |
%class Lexica_01 | |
%standalone | |
%ignorecase | |
%unicode | |
%line | |
NEWLINE = \n|\r|\n\r | |
digit = [0-9] | |
letter = [a-zA-Z0-9_] | |
Drive = {letter} | |
Id = ({letter}|{digit})({letter}|{digit})* | |
PathName = {Id} | |
FileName = {Id} | |
FileType = {Id} | |
%% | |
^({Drive}\:)?(\\)?({PathName}\\)*{FileName}(\.{FileType})?$ { | |
System.out.println("Está ok: " + yytext()); | |
} | |
{NEWLINE} {} | |
.* { System.out.println("Está inválido: " + yytext()); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
D:\acad\disc\compil\compil_u02_lexico | |
ExercicioLexico.doc | |
\Windows\System32 | |
sa&$\Windows\System32 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
/** | |
* Anderson Jean Fraga | |
* 13180375 | |
* Compiladores - Trabalho 1 - Exercicio 2 | |
*/ | |
%% | |
%init{ | |
try { | |
writer = new PrintWriter("Lexica_02.html"); | |
writer.append("<html>\n<head>\n"); | |
writer.append("<style>\n"); | |
writer.append("body { background:#23241f; color:#fff; }\n"); | |
writer.append(".reserved { color:#f92672; }\n"); | |
writer.append(".identifiers { color:#66d9ef; }\n"); | |
writer.append(".strings { color:#e6db74; }\n"); | |
writer.append(".numbers { color:#ae81ff; }\n"); | |
writer.append(".comments { color:#75715e; }\n"); | |
writer.append(".operators { color:#a6e22e; }\n"); | |
writer.append(".scopes { color:#7f9f7f; }\n"); | |
writer.append("</style>\n"); | |
writer.append("<body>\n"); | |
} | |
catch (FileNotFoundException e) { | |
} | |
catch (Exception e) { | |
} | |
%init} | |
%eof{ | |
try { | |
writer.append("</body>\n</html>"); | |
writer.flush(); | |
writer.close(); | |
} | |
catch (Exception e) { | |
} | |
%eof} | |
%{ | |
private PrintWriter writer = null; | |
private void toHtml(String klass, String str) { | |
if (str.length() == 0) { | |
return; | |
} | |
try { | |
writer.append("<span class=\"" + klass + "\">" + str + "</span>\n"); | |
} | |
catch (Exception e) { | |
} | |
} | |
private void toHtml(String str) { | |
if (str.length() == 0) { | |
return; | |
} | |
try { | |
writer.append("<span>" + str + "</span>\n"); | |
} | |
catch (Exception e) { | |
} | |
} | |
%} | |
%public | |
%class Lexica_02 | |
%standalone | |
%ignorecase | |
%byaccj | |
%integer | |
%line | |
%char | |
%unicode | |
NEWLINE = \n|\r|\n\r | |
TAB = \t|\s+ | |
digit = [0-9] | |
letter = [a-zA-Z0-9_] | |
letterWithDot = [a-zA-Z0-9\.\*] | |
%% | |
=|==|\+|-|\*|\\|\|\||\/|\&\&|\~|\<|\+\+|\>|\<\=|\>\= { | |
toHtml("operators", yytext()); | |
} | |
import|final|static|public|protected|private|extends|implements { | |
toHtml("reserved", yytext()); | |
} | |
if|else|while|for { | |
toHtml("reserved", yytext()); | |
} | |
class|void|String|int|double|float|new|return|null|true|false { | |
toHtml("identifiers", yytext()); | |
} | |
\"{letter}+\" { | |
toHtml("strings", yytext()); | |
} | |
[-+]?{digit}*(\.{digit}+)? { | |
toHtml("numbers", yytext()); | |
} | |
\/\*(.|[\r\n]|\t)*?\*\/ { toHtml("comments", yytext()); } | |
{letterWithDot}+ { toHtml(yytext()); } | |
{NEWLINE} { toHtml("<br>"); } | |
{TAB} { toHtml(" "); } | |
\{|\}|\[|\]|\(|\)|\,|\;|\.|\: { toHtml("scopes", yytext()); } | |
. { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.utils.*; | |
public class Teste extends Abc implements Def | |
{ | |
private String t; | |
/** | |
* Construtor | |
*/ | |
Teste() | |
{ | |
t = new abc(); | |
} | |
public void hello() | |
{ | |
for (int x = 0; x < 5; x++) { | |
abc.flush(); | |
} | |
} | |
private String haa(int as, float sua) | |
{ | |
if (as == null || sua == null) { | |
return "putz"; | |
} | |
else { | |
abc.hup(as * 3, sua / 12.9); | |
} | |
return abc; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% | |
/** | |
* Anderson Jean Fraga | |
* 13180375 | |
* Compiladores - Trabalho 1 - Exercicio 3 | |
*/ | |
%public | |
%class Lexica_03 | |
%standalone | |
%ignorecase | |
%unicode | |
%line | |
NEWLINE = \t|\n|\r|\n\r | |
digit = [0-9] | |
letter = [a-zA-Z0-9_\ ] | |
%% | |
\"{letter}+\" { | |
String itemstr = new String(yytext()); | |
System.out.println("Code: STRING\n - Elem: " + itemstr.substring(1, itemstr.length() - 1) + "\n - Line: " + yyline); | |
} | |
"[" { | |
System.out.println("Code: ABRE_COLCHETE\n - Elem: " + yytext() + "\n - Line: " + yyline); | |
} | |
"]" { | |
System.out.println("Code: FECHA_COLCHETE\n - Elem: " + yytext() + "\n - Line: " + yyline); | |
} | |
"{" { | |
System.out.println("Code: ABRE_CHAVE\n - Elem: " + yytext() + "\n - Line: " + yyline); | |
} | |
"}" { | |
System.out.println("Code: FECHA_CHAVE\n - Elem: " + yytext() + "\n - Line: " + yyline); | |
} | |
"," { | |
System.out.println("Code: VIRGULA\n - Elem: " + yytext() + "\n - Line: " + yyline); | |
} | |
":" { | |
System.out.println("Code: DOIS-PONTOS\n - Elem: " + yytext() + "\n - Line: " + yyline); | |
} | |
[-+]?{digit}+ { | |
System.out.println("Code: INTEIRO\n - Elem: " + yytext() + "\n - Line: " + yyline); | |
} | |
[-+]?{digit}*\.{digit}+ { | |
System.out.println("Code: PONTO FLUTUANTE\n - Elem: " + yytext() + "\n - Line: " + yyline); | |
} | |
{NEWLINE}+ { } | |
. { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"id": 1, | |
"name": "Toner para Impressora XK 4532", | |
"price": 219.23, | |
"tags": [ "Toner", "4532" ], | |
"stock": { | |
"shopping iguatemi": 3 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment