浏览代码

Merge branch 'master' of ssh://git.lcalion.com:2245/igorfelix/ivprog

Implement AST with lexer and parser for the textual IVProg language
Lucas de Souza 6 年之前
父节点
当前提交
3bd4a2f19a

+ 102 - 7
css/ivprog-visual-1.0.css

@@ -62,10 +62,12 @@ body {
 	font-weight: bold;
 	color: black;
 }
-.ui.selection.data_types_dropdown.visible.dropdown>.text:not(.default) {
+.ui.selection.data_types_dropdown.visible.dropdown>.text:not(.default),
+.ui.selection.parameter_data_types_dropdown.visible.dropdown>.text:not(.default) {
 	font-weight: bold;
 }
-.ui.selection.data_types_dropdown.dropdown {
+.ui.selection.data_types_dropdown.dropdown,
+.ui.selection.parameter_data_types_dropdown.dropdown {
 	padding-bottom: 0;
 }
 
@@ -75,7 +77,15 @@ body {
 	border: none;
 	background: none;
 }
-.ui.fluid.dropdown.data_types_dropdown.selection .dropdown.icon {
+
+.ui.fluid.dropdown.parameter_data_types_dropdown {
+	display: inline;
+	border: none;
+	background: none;
+}
+
+.ui.fluid.dropdown.data_types_dropdown.selection .dropdown.icon,
+.ui.fluid.dropdown.parameter_data_types_dropdown.selection .dropdown.icon {
 	font-size: 1em;
 }
 
@@ -101,12 +111,11 @@ body {
 	min-width: 50px;
 }
 
-.function_name_div, .function_return_div {
+.function_name_div, .function_return_div, .function_name_parameter {
 	display: inline;
-	/*border: 1px solid #eaebed;*/
 }
 
-.enable_edit_name_function {
+.enable_edit_name_function, .enable_edit_name_parameter, .add_parameter, .remove_parameter {
 	cursor: pointer;
 }
 
@@ -144,7 +153,7 @@ body {
 	float: left;
 }
 
-.remove_function_button, .minimize_function_button {
+.remove_function_button, .minimize_function_button, .add_var_top_button, .add_command_top_button {
 	float: right;
 }
 
@@ -152,6 +161,7 @@ body {
 .ui.icon.button.minimize_function_button {
 	background: none;
 	padding: 0;
+	margin-top: 12px;
 }
 
 .ui.segment.variables_list_div,
@@ -170,4 +180,89 @@ body {
 .ui.labeled.icon.button.add_variable_button,
 .ui.labeled.icon.button.add_command_button {
 	
+}
+
+.program_signature {
+	font-weight: bold;
+	margin: -3px 0 10px -5px;
+}
+
+.program_final {
+	font-weight: bold;
+	margin: 5px 0 0 -5px;
+}
+
+.parameters_list {
+	display: inline;
+}
+
+.function_return, .parameter_type {
+	margin-left: 10px;
+    margin-right: 15px;
+}
+
+.function_return .dropdown .icon, .parameter_type .dropdown .icon {
+	margin-left: 6px;
+}
+.tabela_var {
+	display: inline;
+}
+.buttons_manage_columns i, .tr_manage_lines i {
+	cursor: pointer;
+	display: inline;
+}
+div.buttons_manage_columns {
+	display: inline;
+}
+.tr_manage_lines {
+	text-align: center;
+}
+.div_valor_var {
+	display: inline;
+}
+.ui.comment span {
+	font-style: italic;
+}
+.ui.comment {
+	border: 1px solid gray;
+	padding: 5px;
+	border-radius: 5px;
+	margin: 5px;
+	background: #f9f9f9;
+}
+
+.add_var_top_button {
+	padding-right: 50px;
+}
+
+.function_signature_div {
+	min-height: 40px;
+	padding-top: 8px;
+}
+
+.move_function {
+	margin-top: 9px;
+}
+
+.div_start_minimize_v {
+	float: right;
+	width: 22px; 
+	height: 10px;
+}
+
+.global_var {
+	margin-bottom: 10px;
+}
+
+.list_globals, .global_const {
+	display: inline;
+	cursor: pointer;
+}
+
+.created_element {
+	position: absolute;
+	width: 50%;
+	z-index: 99999999;
+	opacity: .8;
+	cursor: move;
 }

+ 117 - 0
i18n/i18n-database.json

@@ -0,0 +1,117 @@
+{
+	"function": {
+		"en": "function",
+		"es": "función",
+		"pt": "função"
+	},
+	"Function": {
+		"en": "Function",
+		"es": "Función",
+		"pt": "Função"
+	},
+	"start": {
+		"en": "start",
+		"es": "comienzo",
+		"pt": "inicio"
+	},
+	"void": {
+		"en": "void",
+		"es": "vacío",
+		"pt": "vazio"
+	},
+	"integer": {
+		"en": "integer",
+		"es": "entero",
+		"pt": "inteiro"
+	},
+	"real": {
+		"en": "real",
+		"es": "real",
+		"pt": "real"
+	},
+	"program": {
+		"en": "program",
+		"es": "programa",
+		"pt": "programa"
+	},
+	"text": {
+		"en": "text",
+		"es": "texto",
+		"pt": "texto"
+	},
+	"boolean": {
+		"en": "boolean",
+		"es": "booleano",
+		"pt": "booleano"
+	},
+	"true": {
+		"en": "true",
+		"es": "verdadero",
+		"pt": "verdadeiro"
+	},
+	"false": {
+		"en": "false",
+		"es": "falso",
+		"pt": "falso"
+	},
+	"Variable": {
+		"en": "Variable",
+		"es": "Variable",
+		"pt": "Variável"
+	},
+	"Command": {
+		"en": "Command",
+		"es": "Mando",
+		"pt": "Comando"
+	},
+	"new_parameter": {
+		"en": "new_parameter",
+		"es": "nuevo_parámetro",
+		"pt": "novo_parâmetro"
+	},
+	"new_variable": {
+		"en": "new_variable",
+		"es": "nuevo_variable",
+		"pt": "nova_variável"
+	},
+	"new_global": {
+		"en": "new_global",
+		"es": "nuevo_global",
+		"pt": "nova_global"
+	},
+	"new_function": {
+		"en": "new_function",
+		"es": "nueva_función",
+		"pt": "nova_função"
+	},
+	"vector": {
+		"en": "vector",
+		"es": "vector",
+		"pt": "vetor"
+	},
+	"text_comment_start": {
+		"en": "Initial comment of function...",
+		"es": "Comentario inicial de la función...",
+		"pt": "Comentário inicial da função..."
+	},
+	"text_comment_main": {
+		"en": "This is the main function...",
+		"es": "Esta es la función principal...",
+		"pt": "Esta é a função principal..."
+	},
+	"text_read_var": {
+		"en": "Reading data",
+		"es": "Leyendo datos",
+		"pt": "Leitura de dados"
+	},
+	"text_write_var": {
+		"en": "Writing data",
+		"es": "Escribir datos",
+		"pt": "Escrita de dados"
+	},
+	"text_comment": {
+		"en": "Comment",
+		"es": "Comentario",
+		"pt": "Comentário"
+	}
+}

+ 57 - 0
i18n/i18n-engine.js

@@ -0,0 +1,57 @@
+
+function i18n(identifier) {
+  if (!i18n.db[i18n.locale]) {
+    if (!i18n.db['en'][identifier]) {
+      return "{MISSING_I18N_IDENTIFIER}";
+    }
+    return i18n.db['en'][identifier];
+  }
+  if (!i18n.db[i18n.locale][identifier]) {
+    return "{MISSING_I18N_IDENTIFIER}";
+  }
+  return i18n.db[i18n.locale][identifier];
+}
+
+i18n.set = function(locale, identifier, translate) {
+  if (!i18n.db[locale]) {
+    i18n.db[locale] = {};
+  }
+  i18n.db[locale][identifier] = translate;
+}
+
+i18n.updateLocale = function(new_locale) {
+  i18n.locale = new_locale;
+  $( "data.i18n" ).each(function( index ) {
+    $( this ).text(i18n($( this ).val()));
+  });
+}
+
+if (iLMparameters.lang) {
+  i18n.locale = iLMparameters.lang;
+} else {
+  i18n.locale = 'en';
+}
+i18n.db = {};
+
+$.ajaxSetup({
+    async: false
+});
+
+$.getJSON('i18n/i18n-database.json', function(data) {
+    for (x in data) {
+      l = data[x];
+      i18n.set('en', x, l.en);
+      i18n.set('es', x, l.es);
+      i18n.set('pt', x, l.pt);
+    }
+});
+
+$.ajaxSetup({
+    async: true
+});
+
+$( document ).ready(function() {
+  $( "data.i18n" ).each(function( index ) {
+    $( this ).text(i18n($( this ).val()));
+  });
+});

+ 56 - 0
js/iassign-integration-functions.js

@@ -0,0 +1,56 @@
+// Função para ler parâmetros informados pelo iTarefa via URL
+// Apesar de não ser obrigatório, será muito útil para capturar os parâmetros
+function getParameterByName(name) {
+    var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
+    return match ? decodeURIComponent(match[1].replace(/\+/g, ' ')) : null;
+}
+
+// Criando um array com os parâmetros informados pelo iTarefa
+// Observe que para cada parâmetro, é realizada a chamada do método getParameterByName, implementado acima
+var iLMparameters = {
+    iLM_PARAM_ServerToGetAnswerURL: getParameterByName("iLM_PARAM_ServerToGetAnswerURL"),
+    iLM_PARAM_SendAnswer: getParameterByName("iLM_PARAM_SendAnswer"),
+    iLM_PARAM_AssignmentURL: getParameterByName("iLM_PARAM_AssignmentURL"),
+    iLM_PARAM_Assignment: getParameterByName("iLM_PARAM_Assignment"),
+    lang: getParameterByName("lang")
+};
+
+// Função chamada pelo iTarefa quando o professor finaliza a criação da atividade
+// ou quando o aluno finaliza a resolução do exercício
+// O retorno é um JSON com os dados do exercício ou da resolução
+// Esse retorno será armazenado no banco de dados do Moodle, pelo iTarefa
+function getAnswer() {
+    // Se o parâmetro "iLM_PARAM_SendAnswer" for false,
+    // então trata-se de resolução de atividade
+    if (iLMparameters.iLM_PARAM_SendAnswer == 'false') {
+        // Montar o retorno da resposta do aluno
+        
+    } else {
+        
+    }
+}
+
+// Função chamada pelo iTarefa para receber a nota do aluno na atividade
+// O retorno é um valor entre 0.0 e 1.0
+function getEvaluation() {
+    if (iLMparameters.iLM_PARAM_SendAnswer == 'false') {
+        // Calcula a nota do aluno:
+
+        // A chamada do método abaixo é obrigatória!
+        // Observe que a chamada parte do iLM para o iTarefa
+        parent.getEvaluationCallback(0);
+    }
+}
+
+
+// Função para que o iMA leia os dados da atividade fornecidos pelo iTarefa
+function getiLMContent() {
+
+    // O parâmetro "iLM_PARAM_Assignment" fornece o URL do endereço que deve ser
+    // requisitado via AJAX para a captura dos dados da atividade
+    $.get(iLMparameters.iLM_PARAM_Assignment, function (d) {
+
+        
+
+    });
+}

+ 50 - 6
js/ivprog-visual-1.0.js

@@ -1,32 +1,76 @@
 // Definição das classes utilizadas para armazenar o algoritmo
 
-var tiposDados = Object.freeze({void:"void", integer:"integer", real:"real", text:"text", boolean:"boolean"});
+// Não adicionar elementos ao tipoDados, pois existem componentes que dependem do seu tamanho e isso afetará seu funcionamento
+var tiposDados = Object.freeze({void:"void", integer:"integer", real:"real", text:"text", boolean:"boolean", vector:"vector"});
 
-var Variavel = function(tipo, nome, dimensoes = 0) {
+var tiposComandos = Object.freeze({comment:"comment", reader:"reader", writer:"writer"});
+
+var Variavel = function(tipo, nome, valor, dimensoes = 0, eh_constante = false, linhas = 0, colunas = 0) {
 	this.tipo = tipo;
 	this.nome = nome;
+	this.valor = valor;
 	this.dimensoes = dimensoes;
+	this.eh_constante = eh_constante;
+	this.linhas = linhas;
+	this.colunas = colunas;
 };
 
-var Funcao = function(nome, tipo_retorno = tiposDados.void, dimensoes_retorno = 0, lista_parametros = null, eh_principal = false, esta_oculta = false) {
+var Funcao = function(nome, tipo_retorno = tiposDados.void, dimensoes_retorno = 0, lista_parametros = null, eh_principal = false, esta_oculta = false, variaveis = null, comentario_funcao = null) {
 	this.nome = nome;
 	this.tipo_retorno = tipo_retorno;
 	this.dimensoes_retorno = dimensoes_retorno;
 	this.lista_parametros = lista_parametros;
 	this.eh_principal = eh_principal;
 	this.esta_oculta = esta_oculta;
+	this.variaveis = variaveis;
+	this.comentario_funcao = comentario_funcao;
+	this.comandos = null;
+};
+
+var Comentario = function(texto_comentario) {
+	this.tipo = tiposComandos.comment;
+	this.texto_comentario = texto_comentario;
+};
+
+var Comando = function(tipo) {
+	this.tipo = tipo;
+};
+
+var Expressao = function(conteudo) {
+	this.conteudo = conteudo;
+
 };
 
 var Programa = function () {
 	this.funcoes = new Array();
+	this.globais = new Array();
 };
 
 function adicionarFuncao(funcao) {
 	programa.funcoes.push(funcao);
-};
+}
+
+function adicionarVariavel(funcao, variavel) {
+	if (programa.funcoes[funcao].variaveis == null) {
+		programa.funcoes[funcao].variaveis = new Array();
+	}
+	programa.funcoes[funcao].variaveis.push(variavel);
+}
+
+//var tex = i18n('text');
 
 // Adicionando a função principal automaticamente
 var programa = new Programa();
-var funcaoPrincipal = new Funcao("principal", tiposDados.void, 0, null, true);
+var funcaoPrincipal = new Funcao(i18n("start"), tiposDados.void, 0, [], true);
+funcaoPrincipal.comentario_funcao = new Comentario(i18n('text_comment_main'));
+
+//funcaoPrincipal.lista_parametros.push(new Variavel(tiposDados.text, "args"));
+
+
+adicionarFuncao(funcaoPrincipal);
+
+var funcaoSomar = new Funcao("somar", tiposDados.integer, 0, [], false, false, null, new Comentario(i18n('text_comment_start')));
+funcaoSomar.lista_parametros.push(new Variavel(tiposDados.integer, "a"));
+funcaoSomar.lista_parametros.push(new Variavel(tiposDados.integer, "b"));
 
-adicionarFuncao(funcaoPrincipal);
+adicionarFuncao(funcaoSomar);

文件差异内容过多而无法显示
+ 2023 - 52
js/ivprog-visual-functions-1.0.js


+ 21 - 0
js/semantic/semantic-buttons.js

@@ -30,6 +30,12 @@ var button_ready = function() {
     .dropdown()
   ;
 
+  $('.ui.dropdown')
+    .dropdown()
+  ;
+
+  $('.program_signature_text').text(i18n('program'));
+
 
   $('.add_function_button').on('click', addFunctionHandler);
 
@@ -38,6 +44,18 @@ var button_ready = function() {
 
   $('.ivprog_visual_panel').removeClass("loading");
 
+  $(document).mousemove(function(e){
+    var parentOffset = $('.ivprog_visual_panel').offset();; 
+   
+    mouseX = e.pageX - parentOffset.left + 300;
+    mouseY = e.pageY - parentOffset.top + 100;
+
+    /*$('.created_element').css('top', mouseY);
+    $('.created_element').css('left', mouseX);*/
+
+  });
+
+
   //Sortable:
   Sortable.create(listWithHandle, {
     handle: '.glyphicon-move',
@@ -51,6 +69,9 @@ var button_ready = function() {
 
 };
 
+var mouseX;
+var mouseY;
+
 // attach ready event
 $(document)
   .ready(button_ready)

+ 28 - 1
main.html

@@ -5,6 +5,11 @@
     <link rel="stylesheet" type="text/css" href="js/semantic/semantic.min.css">
     <link rel="stylesheet" type="text/css" href="css/ivprog-visual-1.0.css">
     <script src="js/jquery-3.3.1.min.js"></script>
+
+    <script src="js/iassign-integration-functions.js"></script>
+
+    <script src="i18n/i18n-engine.js"></script>
+
     <script src="js/semantic/semantic.min.js"></script>
     <script src="js/semantic/semantic-buttons.js"></script>
 
@@ -15,6 +20,7 @@
     <script src="js/Sortable.js"></script>
   </head>
   <body>
+   
     <div class="ui one column doubling stackable grid container">
       <div class="column">
         <div class="ui container main_title">
@@ -22,6 +28,8 @@
           <span>interactive coding</span>
         </div>
 
+        
+
         <div class="ui container content_margin">
           <div class="content_sub_margin">
               <div class="blue ui ivprog_format buttons">
@@ -81,6 +89,12 @@
       </div>
 
       <div class="ui one column container segment ivprog_visual_panel loading">
+        <div class="program_signature"><span class="program_signature_text">programa</span> { </div>
+
+        <div class="global_var">
+          <div class="ui icon button" onclick="addGlobalVar()"><i class="icon superscript"></i></div>
+          <div class="list_globals"></div>
+        </div>
 
         <div class="all_functions list-group" id="listWithHandle">
 
@@ -88,12 +102,25 @@
 
 
         <div class="ui teal small labeled icon button add_function_button">
-          Function
+          <data class="i18n" value="Function">Function</data>
           <i class="add icon"></i>
         </div>
+        <div class="program_final">}</div>
 
       </div>
       
     </div>
+
+    <i class="icon trash alternate outline huge" onmouseover="console.log('oi');" ></i>
+
+
+
+
+
+
+
+
+
+
   </body>
 </html>