Fix bugs
Co-authored-by: Ezequiel Bellver <ebellver@itba.edu.ar> Co-authored-by: Juan Barmasch <jbarmasch@itba.edu.ar>
This commit is contained in:
parent
63a239fce3
commit
18ef547882
|
@ -1,26 +1,20 @@
|
||||||
# Versión mínima requerida de CMake:
|
|
||||||
cmake_minimum_required(VERSION 3.22)
|
cmake_minimum_required(VERSION 3.22)
|
||||||
|
|
||||||
# Nombre del proyecto, y lenguaje usado (C, en este caso):
|
|
||||||
project(BFBCompiler C)
|
project(BFBCompiler C)
|
||||||
|
|
||||||
# Compilar el parser con Bison:
|
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ../src/frontend/syntactic-analysis/bison-parser.c ../src/frontend/syntactic-analysis/bison-parser.h
|
OUTPUT ../src/frontend/syntactic-analysis/bison-parser.c ../src/frontend/syntactic-analysis/bison-parser.h
|
||||||
# COMMAND bison -d ../src/frontend/syntactic-analysis/bison-grammar.y -o ../src/frontend/syntactic-analysis/bison-parser.c)
|
# COMMAND bison -d ../src/frontend/syntactic-analysis/bison-grammar.y -o ../src/frontend/syntactic-analysis/bison-parser.c)
|
||||||
COMMAND bison -Wcounterexamples -d ../src/frontend/syntactic-analysis/bison-grammar.y -o ../src/frontend/syntactic-analysis/bison-parser.c)
|
COMMAND bison -Wcounterexamples -d ../src/frontend/syntactic-analysis/bison-grammar.y -o ../src/frontend/syntactic-analysis/bison-parser.c)
|
||||||
# COMMAND bison -t -d ../src/frontend/syntactic-analysis/bison-grammar.y -o ../src/frontend/syntactic-analysis/bison-parser.c)
|
# COMMAND bison -t -d ../src/frontend/syntactic-analysis/bison-grammar.y -o ../src/frontend/syntactic-analysis/bison-parser.c)
|
||||||
|
|
||||||
# Seleccionar estrategia según el compilador de C disponible en el sistema:
|
|
||||||
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
||||||
message(NOTICE "El compilador de C es GCC.")
|
message(NOTICE "El compilador de C es GCC.")
|
||||||
|
|
||||||
# Opciones para GCC:
|
|
||||||
add_compile_options(-static-libgcc)
|
add_compile_options(-static-libgcc)
|
||||||
add_compile_options(-std=gnu99)
|
add_compile_options(-std=gnu99)
|
||||||
add_compile_options(-O3)
|
add_compile_options(-O3)
|
||||||
|
|
||||||
# Compilar el scanner con Flex:
|
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ../src/frontend/lexical-analysis/flex-scanner.c
|
OUTPUT ../src/frontend/lexical-analysis/flex-scanner.c
|
||||||
COMMAND flex -o ../src/frontend/lexical-analysis/flex-scanner.c ../src/frontend/lexical-analysis/flex-patterns.l
|
COMMAND flex -o ../src/frontend/lexical-analysis/flex-scanner.c ../src/frontend/lexical-analysis/flex-patterns.l
|
||||||
|
@ -30,10 +24,6 @@ if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
||||||
elseif (CMAKE_C_COMPILER_ID STREQUAL "MSVC")
|
elseif (CMAKE_C_COMPILER_ID STREQUAL "MSVC")
|
||||||
message(NOTICE "El compilador de C es Microsoft Visual Studio.")
|
message(NOTICE "El compilador de C es Microsoft Visual Studio.")
|
||||||
|
|
||||||
# Opciones para MSVC:
|
|
||||||
# add_compile_options(...)
|
|
||||||
|
|
||||||
# Compilar el scanner con Flex, usando compatibilidad con Microsoft Windows:
|
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ../src/frontend/lexical-analysis/flex-scanner.c
|
OUTPUT ../src/frontend/lexical-analysis/flex-scanner.c
|
||||||
COMMAND flex --wincompat -o ../src/frontend/lexical-analysis/flex-scanner.c ../src/frontend/lexical-analysis/flex-patterns.l
|
COMMAND flex --wincompat -o ../src/frontend/lexical-analysis/flex-scanner.c ../src/frontend/lexical-analysis/flex-patterns.l
|
||||||
|
@ -45,7 +35,6 @@ else ()
|
||||||
|
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
# Especificar punto de entrada del proyecto y códigos fuente (extensión *.c):
|
|
||||||
add_executable(BFBCompiler
|
add_executable(BFBCompiler
|
||||||
src/main.c
|
src/main.c
|
||||||
src/backend/code-generation/generator.c
|
src/backend/code-generation/generator.c
|
||||||
|
@ -56,8 +45,14 @@ add_executable(BFBCompiler
|
||||||
src/frontend/syntactic-analysis/bison-actions.c
|
src/frontend/syntactic-analysis/bison-actions.c
|
||||||
src/frontend/syntactic-analysis/bison-parser.c)
|
src/frontend/syntactic-analysis/bison-parser.c)
|
||||||
|
|
||||||
# Linkear el proyecto y sus librerías:
|
include(CheckFunctionExists)
|
||||||
target_link_libraries(BFBCompiler)
|
check_function_exists(pow POW_FUNCTION_EXISTS)
|
||||||
|
# check_symbol_exists(pow "math.h" POW_FUNCTION_EXISTS)
|
||||||
|
if (NOT POW_FUNCTION_EXISTS)
|
||||||
|
target_link_libraries(BFBCompiler m)
|
||||||
|
else ()
|
||||||
|
target_link_libraries(BFBCompiler)
|
||||||
|
endif ()
|
||||||
|
|
||||||
file(GLOB_RECURSE correct_use_cases "doc/examples/correct/use-case-*.b" )
|
file(GLOB_RECURSE correct_use_cases "doc/examples/correct/use-case-*.b" )
|
||||||
file(GLOB_RECURSE incorrect_use_cases "doc/examples/incorrect/use-case-*.b" )
|
file(GLOB_RECURSE incorrect_use_cases "doc/examples/incorrect/use-case-*.b" )
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2022 Agustín Golmar \
|
|
||||||
Copyright (c) 2022 Santiago Lo Coco \
|
Copyright (c) 2022 Santiago Lo Coco \
|
||||||
Copyright (c) 2022 Juan Martín Barmasch \
|
Copyright (c) 2022 Juan Martín Barmasch \
|
||||||
Copyright (c) 2022 Ezequiel Bellver
|
Copyright (c) 2022 Ezequiel Bellver
|
||||||
|
|
|
@ -2,4 +2,3 @@ fun g = (1-x)^(x);
|
||||||
fun f = x^2;
|
fun f = x^2;
|
||||||
fun h = x/(x-2);
|
fun h = x/(x-2);
|
||||||
fun j = 1/x;
|
fun j = 1/x;
|
||||||
printCSV(["g", "f", "h", "j"], [[g(1), f(1), h(1) , j(1), gofohoj(1)]], "example.csv");
|
|
|
@ -1,6 +1,6 @@
|
||||||
fun f = x^2;
|
fun f = x^2;
|
||||||
fun g = derivative f in (x);
|
fun g = derivative f in (x);
|
||||||
fun h = f(x) - int f (0 ~ 1);
|
fun h = f(x) - int g (0 ~ 1);
|
||||||
for (var i = 0; i <= 1; i += 0.1) {
|
for (var i = 0; i <= 1; i += 0.1) {
|
||||||
print(g(i));
|
print(h(i));
|
||||||
}
|
}
|
2
run.sh
2
run.sh
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
if [ ! -d "bin" ]; then
|
if [ ! -d "bin" ] || [ "$2" = 'D' ]; then
|
||||||
sh compile.sh
|
sh compile.sh
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -1,21 +1,32 @@
|
||||||
#include "calculator.h"
|
#include "calculator.h"
|
||||||
|
#include "math.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementación de "calculator.h".
|
* Implementación de "calculator.h".
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int Add(const int leftAddend, const int rightAddend) {
|
double Add(const double leftAddend, const double rightAddend) {
|
||||||
return leftAddend + rightAddend;
|
return leftAddend + rightAddend;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Subtract(const int minuend, const int subtract) {
|
double Subtract(const double minuend, const double subtract) {
|
||||||
return minuend - subtract;
|
return minuend - subtract;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Multiply(const int multiplicand, const int multiplier) {
|
double Multiply(const double multiplicand, const double multiplier) {
|
||||||
return multiplicand * multiplier;
|
return multiplicand * multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Divide(const int dividend, const int divisor) {
|
double Divide(const double dividend, const double divisor) {
|
||||||
return dividend / divisor;
|
return dividend / divisor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double Power(const double base, const double exponent) {
|
||||||
|
if (base == 0 && exponent == 0)
|
||||||
|
return 0;
|
||||||
|
return pow(base, exponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
// double (* function) (double) declareFunction(char * expression) {
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
#ifndef CALCULATOR_HEADER
|
#ifndef CALCULATOR_HEADER
|
||||||
#define CALCULATOR_HEADER
|
#define CALCULATOR_HEADER
|
||||||
|
|
||||||
int Add(const int leftAddend, const int rightAddend);
|
double Add(const double leftAddend, const double rightAddend);
|
||||||
|
|
||||||
int Subtract(const int minuend, const int subtract);
|
double Subtract(const double minuend, const double subtract);
|
||||||
|
|
||||||
int Multiply(const int multiplicand, const int multiplier);
|
double Multiply(const double multiplicand, const double multiplier);
|
||||||
|
|
||||||
int Divide(const int dividend, const int divisor);
|
double Divide(const double dividend, const double divisor);
|
||||||
|
|
||||||
|
double Power(const double base, const double exponent);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -36,6 +36,6 @@ void LogErrorRaw(const char * const format, ...) {
|
||||||
void LogInfo(const char * const format, ...) {
|
void LogInfo(const char * const format, ...) {
|
||||||
va_list arguments;
|
va_list arguments;
|
||||||
va_start(arguments, format);
|
va_start(arguments, format);
|
||||||
Log(stdout, "[INFO ] ", format, "\n", arguments);
|
Log(stdout, "[INFO] ", format, "\n", arguments);
|
||||||
va_end(arguments);
|
va_end(arguments);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ TokenID DoublePatternAction(const char * lexeme) {
|
||||||
|
|
||||||
TokenID StringPatternAction(const char * lexeme) {
|
TokenID StringPatternAction(const char * lexeme) {
|
||||||
// LogDebug("StringPatternAction: '%s'.", lexeme);
|
// LogDebug("StringPatternAction: '%s'.", lexeme);
|
||||||
return STRING;
|
return ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
TokenID EscapeStringPatternAction(const char * lexeme) {
|
TokenID EscapeStringPatternAction(const char * lexeme) {
|
||||||
|
|
|
@ -67,10 +67,9 @@ typedef enum TokenID {
|
||||||
ERR,
|
ERR,
|
||||||
TAYLOR,
|
TAYLOR,
|
||||||
ESCAPESTRING,
|
ESCAPESTRING,
|
||||||
PRINTCSV,
|
|
||||||
DOUBLE,
|
DOUBLE,
|
||||||
INTEGER,
|
INTEGER,
|
||||||
STRING
|
ID
|
||||||
} TokenID;
|
} TokenID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
/* Patrones reutilizables. */
|
/* Patrones reutilizables. */
|
||||||
crlf \r\n
|
crlf \r\n
|
||||||
digit [0-9]
|
digit [0-9]
|
||||||
char [a-zA-Z]
|
char [[:alpha:]_]
|
||||||
characters [a-zA-Z., ]
|
characters [[:print:]]
|
||||||
decimal [.]
|
decimal [.]
|
||||||
endline \n
|
endline \n
|
||||||
whitespace [ \f\n\r\t\v]
|
whitespace [ \f\n\r\t\v]
|
||||||
|
@ -76,8 +76,6 @@ whitespace [ \f\n\r\t\v]
|
||||||
"var" { return VAR; }
|
"var" { return VAR; }
|
||||||
"err" { return ERR; }
|
"err" { return ERR; }
|
||||||
"taylor" { return TAYLOR; }
|
"taylor" { return TAYLOR; }
|
||||||
"printCSV" { return PRINTCSV; }
|
|
||||||
|
|
||||||
|
|
||||||
{digit}+{decimal}{digit}+ { return DoublePatternAction(yytext); }
|
{digit}+{decimal}{digit}+ { return DoublePatternAction(yytext); }
|
||||||
|
|
||||||
|
|
|
@ -55,10 +55,9 @@
|
||||||
%token ERR
|
%token ERR
|
||||||
%token TAYLOR
|
%token TAYLOR
|
||||||
%token ESCAPESTRING
|
%token ESCAPESTRING
|
||||||
%token PRINTCSV
|
|
||||||
%token DOUBLE
|
%token DOUBLE
|
||||||
%token INTEGER
|
%token INTEGER
|
||||||
%token STRING
|
%token ID
|
||||||
|
|
||||||
// Reglas de asociatividad y precedencia (de menor a mayor):
|
// Reglas de asociatividad y precedencia (de menor a mayor):
|
||||||
|
|
||||||
|
@ -66,9 +65,11 @@
|
||||||
%precedence ELSE
|
%precedence ELSE
|
||||||
|
|
||||||
%left GREATER GREATER_EQUAL LESSER LESSER_EQUAL EQUAL NOT_EQUAL
|
%left GREATER GREATER_EQUAL LESSER LESSER_EQUAL EQUAL NOT_EQUAL
|
||||||
%left ADD SUB NOT
|
%left ADD SUB
|
||||||
|
%right NOT
|
||||||
%left MUL DIV AND OR
|
%left MUL DIV AND OR
|
||||||
%left POW
|
%left POW
|
||||||
|
%left SQUOTE
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
|
@ -82,7 +83,6 @@ statement: evaluate SEMICOLON
|
||||||
| if_statement
|
| if_statement
|
||||||
| for_statement
|
| for_statement
|
||||||
| while_statement
|
| while_statement
|
||||||
| printCSV SEMICOLON
|
|
||||||
| print SEMICOLON
|
| print SEMICOLON
|
||||||
| declare_variable SEMICOLON
|
| declare_variable SEMICOLON
|
||||||
| assign_variable SEMICOLON
|
| assign_variable SEMICOLON
|
||||||
|
@ -92,7 +92,7 @@ expression: positive_constant
|
||||||
| evaluate
|
| evaluate
|
||||||
| integrate
|
| integrate
|
||||||
| derivative
|
| derivative
|
||||||
| STRING
|
| ID
|
||||||
| expression ADD expression
|
| expression ADD expression
|
||||||
| expression SUB expression
|
| expression SUB expression
|
||||||
| expression MUL expression
|
| expression MUL expression
|
||||||
|
@ -104,8 +104,8 @@ expression: positive_constant
|
||||||
|
|
||||||
domain: expression LESSER expression
|
domain: expression LESSER expression
|
||||||
| expression LESSER_EQUAL expression
|
| expression LESSER_EQUAL expression
|
||||||
| expression GREATER expression
|
|
||||||
| expression GREATER_EQUAL expression
|
| expression GREATER_EQUAL expression
|
||||||
|
| expression GREATER expression
|
||||||
| expression EQUAL expression
|
| expression EQUAL expression
|
||||||
| expression NOT_EQUAL expression
|
| expression NOT_EQUAL expression
|
||||||
| expression LESSER expression LESSER expression
|
| expression LESSER expression LESSER expression
|
||||||
|
@ -114,12 +114,7 @@ domain: expression LESSER expression
|
||||||
| expression LESSER_EQUAL expression LESSER_EQUAL expression
|
| expression LESSER_EQUAL expression LESSER_EQUAL expression
|
||||||
;
|
;
|
||||||
|
|
||||||
boolean: expression LESSER expression
|
boolean: domain
|
||||||
| expression LESSER_EQUAL expression
|
|
||||||
| expression GREATER expression
|
|
||||||
| expression GREATER_EQUAL expression
|
|
||||||
| expression EQUAL expression
|
|
||||||
| expression NOT_EQUAL expression
|
|
||||||
| boolean OR boolean
|
| boolean OR boolean
|
||||||
| boolean AND boolean
|
| boolean AND boolean
|
||||||
| OPEN_PARENTHESIS boolean CLOSE_PARENTHESIS
|
| OPEN_PARENTHESIS boolean CLOSE_PARENTHESIS
|
||||||
|
@ -130,8 +125,8 @@ positive_constant: DOUBLE
|
||||||
| INTEGER
|
| INTEGER
|
||||||
;
|
;
|
||||||
|
|
||||||
declare_function: FUNCTION STRING ASSIGN function
|
declare_function: FUNCTION ID ASSIGN function
|
||||||
| FUNCTION STRING ASSIGN OPEN_BRACES functions CLOSE_BRACES
|
| FUNCTION ID ASSIGN OPEN_BRACES functions CLOSE_BRACES
|
||||||
;
|
;
|
||||||
|
|
||||||
function: expression
|
function: expression
|
||||||
|
@ -144,16 +139,16 @@ functions: function
|
||||||
| function COMMA functions
|
| function COMMA functions
|
||||||
;
|
;
|
||||||
|
|
||||||
composite: STRING COMPOSITE STRING
|
composite: ID COMPOSITE ID
|
||||||
| composite COMPOSITE STRING
|
| composite COMPOSITE ID
|
||||||
;
|
;
|
||||||
|
|
||||||
expressions: expression
|
expressions: expression
|
||||||
| expression COMMA expressions
|
| expression COMMA expressions
|
||||||
;
|
;
|
||||||
|
|
||||||
strings: STRING
|
ids: ID
|
||||||
| STRING COMMA strings
|
| ID COMMA ids
|
||||||
;
|
;
|
||||||
|
|
||||||
numArray: OPEN_BRACKETS expressions CLOSE_BRACKETS
|
numArray: OPEN_BRACKETS expressions CLOSE_BRACKETS
|
||||||
|
@ -166,7 +161,7 @@ numArrays: numArray
|
||||||
arrayNumArray: OPEN_BRACKETS numArrays CLOSE_BRACKETS
|
arrayNumArray: OPEN_BRACKETS numArrays CLOSE_BRACKETS
|
||||||
;
|
;
|
||||||
|
|
||||||
stringArray: OPEN_BRACKETS strings CLOSE_BRACKETS
|
idArray: OPEN_BRACKETS ids CLOSE_BRACKETS
|
||||||
;
|
;
|
||||||
|
|
||||||
escapeString: ESCAPESTRING
|
escapeString: ESCAPESTRING
|
||||||
|
@ -180,18 +175,18 @@ escapeStrings: escapeString
|
||||||
escapeStringArray: OPEN_BRACKETS escapeStrings CLOSE_BRACKETS
|
escapeStringArray: OPEN_BRACKETS escapeStrings CLOSE_BRACKETS
|
||||||
;
|
;
|
||||||
|
|
||||||
evaluate: EVALUATE STRING IN OPEN_PARENTHESIS expression CLOSE_PARENTHESIS
|
evaluate: EVALUATE ID IN OPEN_PARENTHESIS expression CLOSE_PARENTHESIS
|
||||||
| EVALUATE STRING IN numArray
|
| EVALUATE ID IN numArray
|
||||||
| STRING OPEN_PARENTHESIS expression CLOSE_PARENTHESIS
|
| ID OPEN_PARENTHESIS expression CLOSE_PARENTHESIS
|
||||||
| EVALUATE stringArray IN OPEN_PARENTHESIS expression CLOSE_PARENTHESIS
|
| EVALUATE idArray IN OPEN_PARENTHESIS expression CLOSE_PARENTHESIS
|
||||||
| EVALUATE stringArray IN numArray
|
| EVALUATE idArray IN numArray
|
||||||
| stringArray OPEN_PARENTHESIS expression CLOSE_PARENTHESIS
|
| idArray OPEN_PARENTHESIS expression CLOSE_PARENTHESIS
|
||||||
;
|
;
|
||||||
|
|
||||||
integrate: INTEGRATE STRING BETWEEN OPEN_PARENTHESIS expression AND_INT expression CLOSE_PARENTHESIS
|
integrate: INTEGRATE ID BETWEEN OPEN_PARENTHESIS expression AND_INT expression CLOSE_PARENTHESIS
|
||||||
| INTEGRATE STRING OPEN_PARENTHESIS expression AND_INT expression CLOSE_PARENTHESIS
|
| INTEGRATE ID OPEN_PARENTHESIS expression AND_INT expression CLOSE_PARENTHESIS
|
||||||
| INTEGRATE stringArray BETWEEN OPEN_PARENTHESIS expression AND_INT expression CLOSE_PARENTHESIS
|
| INTEGRATE idArray BETWEEN OPEN_PARENTHESIS expression AND_INT expression CLOSE_PARENTHESIS
|
||||||
| INTEGRATE stringArray OPEN_PARENTHESIS expression AND_INT expression CLOSE_PARENTHESIS
|
| INTEGRATE idArray OPEN_PARENTHESIS expression AND_INT expression CLOSE_PARENTHESIS
|
||||||
| integrate ERR positive_constant
|
| integrate ERR positive_constant
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -207,12 +202,12 @@ statements: statement
|
||||||
| statement statements
|
| statement statements
|
||||||
;
|
;
|
||||||
|
|
||||||
derivative: DERIVATIVE STRING IN OPEN_PARENTHESIS expression CLOSE_PARENTHESIS
|
derivative: DERIVATIVE ID IN OPEN_PARENTHESIS expression CLOSE_PARENTHESIS
|
||||||
| DERIVATIVE INTEGER STRING IN OPEN_PARENTHESIS expression CLOSE_PARENTHESIS
|
| DERIVATIVE INTEGER ID IN OPEN_PARENTHESIS expression CLOSE_PARENTHESIS
|
||||||
| STRING squotes OPEN_PARENTHESIS expression CLOSE_PARENTHESIS
|
| ID squotes OPEN_PARENTHESIS expression CLOSE_PARENTHESIS
|
||||||
| DERIVATIVE stringArray IN OPEN_PARENTHESIS expression CLOSE_PARENTHESIS
|
| DERIVATIVE idArray IN OPEN_PARENTHESIS expression CLOSE_PARENTHESIS
|
||||||
| DERIVATIVE INTEGER stringArray IN OPEN_PARENTHESIS expression CLOSE_PARENTHESIS
|
| DERIVATIVE INTEGER idArray IN OPEN_PARENTHESIS expression CLOSE_PARENTHESIS
|
||||||
| stringArray squotes OPEN_PARENTHESIS expression CLOSE_PARENTHESIS
|
| idArray squotes OPEN_PARENTHESIS expression CLOSE_PARENTHESIS
|
||||||
| derivative ERR positive_constant
|
| derivative ERR positive_constant
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -228,26 +223,23 @@ for_statement: FOR OPEN_PARENTHESIS declare_variable SEMICOLON boolean SEMICOLON
|
||||||
| FOR OPEN_PARENTHESIS SEMICOLON boolean SEMICOLON assign_variable CLOSE_PARENTHESIS block
|
| FOR OPEN_PARENTHESIS SEMICOLON boolean SEMICOLON assign_variable CLOSE_PARENTHESIS block
|
||||||
;
|
;
|
||||||
|
|
||||||
taylor: TAYLOR INTEGER STRING
|
taylor: TAYLOR INTEGER ID
|
||||||
;
|
;
|
||||||
|
|
||||||
while_statement: WHILE OPEN_PARENTHESIS boolean CLOSE_PARENTHESIS block
|
while_statement: WHILE OPEN_PARENTHESIS boolean CLOSE_PARENTHESIS block
|
||||||
;
|
;
|
||||||
|
|
||||||
declare_variable: VAR STRING
|
declare_variable: VAR ID
|
||||||
| declare_variable ASSIGN expression
|
| declare_variable ASSIGN expression
|
||||||
;
|
;
|
||||||
|
|
||||||
printCSV: PRINTCSV OPEN_PARENTHESIS escapeStringArray COMMA arrayNumArray COMMA escapeString CLOSE_PARENTHESIS
|
assign_variable: ID ADD_ASSIGN expression
|
||||||
;
|
| ID SUB_ASSIGN expression
|
||||||
|
| ID MUL_ASSIGN expression
|
||||||
assign_variable: STRING ADD_ASSIGN expression
|
| ID DIV_ASSIGN expression
|
||||||
| STRING SUB_ASSIGN expression
|
| ID INCREMENT
|
||||||
| STRING MUL_ASSIGN expression
|
| ID DECREMENT
|
||||||
| STRING DIV_ASSIGN expression
|
| ID ASSIGN expression
|
||||||
| STRING INCREMENT
|
|
||||||
| STRING DECREMENT
|
|
||||||
| STRING ASSIGN expression
|
|
||||||
;
|
;
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
|
@ -3,27 +3,22 @@
|
||||||
#include "backend/support/shared.h"
|
#include "backend/support/shared.h"
|
||||||
#include "frontend/syntactic-analysis/bison-parser.h"
|
#include "frontend/syntactic-analysis/bison-parser.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
//Estado de la aplicación.
|
|
||||||
CompilerState state;
|
CompilerState state;
|
||||||
|
|
||||||
// Punto de entrada principal del compilador.
|
|
||||||
const int main(const int argumentCount, const char ** arguments) {
|
const int main(const int argumentCount, const char ** arguments) {
|
||||||
|
|
||||||
// #ifdef YYDEBUG
|
// #ifdef YYDEBUG
|
||||||
// yydebug = 1;
|
// yydebug = 1;
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
// Inicializar estado de la aplicación.
|
|
||||||
state.result = 0;
|
state.result = 0;
|
||||||
state.succeed = false;
|
state.succeed = false;
|
||||||
|
|
||||||
// Mostrar parámetros recibidos por consola.
|
|
||||||
for (int i = 0; i < argumentCount; ++i) {
|
for (int i = 0; i < argumentCount; ++i) {
|
||||||
LogInfo("Argumento %d: '%s'", i, arguments[i]);
|
LogInfo("Argumento %d: '%s'", i, arguments[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compilar el programa de entrada.
|
|
||||||
LogInfo("Compilando...\n");
|
LogInfo("Compilando...\n");
|
||||||
const int result = yyparse();
|
const int result = yyparse();
|
||||||
switch (result) {
|
switch (result) {
|
||||||
|
|
Loading…
Reference in New Issue