-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from tomasanchez/CFG-13-parser
Cfg 13 parser
- Loading branch information
Showing
19 changed files
with
2,234 additions
and
239 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
%code top{ | ||
#include <stdio.h> | ||
|
||
#include "scanner.h" | ||
#include "semantic.h" | ||
} | ||
|
||
%code provides{ | ||
void yyerror(const char *); | ||
extern int yylexerrs; | ||
} | ||
|
||
%defines "./include/console/parser.h" | ||
%output "./src/console/parser.c" | ||
|
||
%define api.value.type {char *} | ||
%define parse.error verbose | ||
|
||
%token CONSTANT EXIT NO_OP READ IO WRITE COPY | ||
|
||
%start instructions | ||
|
||
%% | ||
|
||
instructions | ||
: instruction | ||
| instructions instruction | ||
; | ||
|
||
instruction | ||
: EXIT { request_exit(); } | ||
| NO_OP CONSTANT { request_no_op($2); } | ||
| IO CONSTANT { request_io($2); } | ||
| READ CONSTANT { request_read($2); } | ||
| WRITE CONSTANT CONSTANT { request_write($2, $3); } | ||
| COPY CONSTANT CONSTANT { request_copy($2, $3); } | ||
; | ||
|
||
%% | ||
|
||
/* Informa la ocurrencia de un error. */ | ||
void yyerror(const char *s){ | ||
printf("línea #%d: %s\n", yylineno, s); | ||
return; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
NO_OP 5 | ||
I/O 3000 | ||
READ 0 | ||
WRITE 4 42 | ||
COPY 0 3 | ||
EXIT |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,47 @@ | ||
/* Auto-Generated Header file name */ | ||
%option header-file = "include/console/lexer.h" | ||
/* Auto-generated Source file name */ | ||
%option outfile = "src/console/lexer.c" | ||
/* 8-bit Scanner (THREAD-SAFE)*/ | ||
%option 8bit noyywrap | ||
/*For "include"*/ | ||
%{ | ||
|
||
#include <stdio.h> | ||
#include "parser.h" | ||
|
||
#define ERROR_LEXICO(mensaje) yylexerrs++; char buffer[8229]; sprintf(buffer, "Error léxico: %s: %s", mensaje, yytext ); yyerror(buffer); | ||
|
||
%} | ||
|
||
%option outfile="./src/console/scanner.c" | ||
%option header-file="./include/console/scanner.h" | ||
|
||
%option 8bit | ||
%option stack | ||
/* Case insensitve option*/ | ||
%option case-insensitive | ||
/* Count line number*/ | ||
%option noyywrap | ||
%option nounput | ||
%option noinput | ||
%option yylineno | ||
%option case-insensitive | ||
|
||
/* C/C++ code included inside %top{} are copied to both the `_lexer.c` and the `_lexer.h` */ | ||
%top{ | ||
} | ||
space [[:space:]] | ||
|
||
/* C/C++ code included inside %{%} is copied to `_lexer.c` but not to the header-file*/ | ||
%{ | ||
/** | ||
* console_lexer.c | ||
* | ||
* @file Auto-generated lexer by Flex. | ||
* @author Tomás Sánchez | ||
* @since 04.14.2022 | ||
*/ | ||
|
||
#include <stdlib.h> | ||
|
||
// Avoiding warning implicit-function-declaration as fileno is no std in C | ||
extern int fileno(FILE *); | ||
%} | ||
invalid_character [~`!@#$^&\[}[\]'"?\\>] | ||
|
||
alpha [[:alpha:]] | ||
|
||
digit [[:digit:]] | ||
|
||
constant {digit}+ | ||
|
||
%% | ||
[ \t] | ||
("NO_OP") { puts("No operation");} | ||
("I/O") { puts("Input/Output");} | ||
("READ") { puts("Read");} | ||
("COPY") { puts("Copy");} | ||
("WRITE") { puts("Write");} | ||
("Exit") { puts("Exit");} | ||
[\n] { puts("End of line");} | ||
[0-9]+ { puts("Number");} | ||
. { puts("Invalid symbol");} | ||
|
||
"NO_OP" { return NO_OP;} | ||
"I/O" { return IO;} | ||
"READ" { return READ;} | ||
"COPY" { return COPY;} | ||
"WRITE" { return WRITE;} | ||
"EXIT" { return EXIT;} | ||
|
||
{space}+ {} /* ignore new lines, tabulations and spaces */ | ||
|
||
{constant} { yylval = strdup(yytext); return CONSTANT; } | ||
{constant}({invalid_character}|{alpha})({invalid_character}|{alpha}|{digit})* { ERROR_LEXICO("constante inválida"); } | ||
|
||
. { ERROR_LEXICO("caracter desconocido"); } | ||
|
||
%% |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* A Bison parser, made by GNU Bison 3.8.2. */ | ||
|
||
/* Bison interface for Yacc-like parsers in C | ||
Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, | ||
Inc. | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. */ | ||
|
||
/* As a special exception, you may create a larger work that contains | ||
part or all of the Bison parser skeleton and distribute that work | ||
under terms of your choice, so long as that work isn't itself a | ||
parser generator using the skeleton or a modified version thereof | ||
as a parser skeleton. Alternatively, if you modify or redistribute | ||
the parser skeleton itself, you may (at your option) remove this | ||
special exception, which will cause the skeleton and the resulting | ||
Bison output files to be licensed under the GNU General Public | ||
License without this special exception. | ||
This special exception was added by the Free Software Foundation in | ||
version 2.2 of Bison. */ | ||
|
||
/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, | ||
especially those whose name start with YY_ or yy_. They are | ||
private implementation details that can be changed or removed. */ | ||
|
||
#ifndef YY_YY_INCLUDE_CONSOLE_PARSER_H_INCLUDED | ||
# define YY_YY_INCLUDE_CONSOLE_PARSER_H_INCLUDED | ||
/* Debug traces. */ | ||
#ifndef YYDEBUG | ||
# define YYDEBUG 0 | ||
#endif | ||
#if YYDEBUG | ||
extern int yydebug; | ||
#endif | ||
|
||
/* Token kinds. */ | ||
#ifndef YYTOKENTYPE | ||
# define YYTOKENTYPE | ||
enum yytokentype | ||
{ | ||
YYEMPTY = -2, | ||
YYEOF = 0, /* "end of file" */ | ||
YYerror = 256, /* error */ | ||
YYUNDEF = 257, /* "invalid token" */ | ||
CONSTANT = 258, /* CONSTANT */ | ||
EXIT = 259, /* EXIT */ | ||
NO_OP = 260, /* NO_OP */ | ||
READ = 261, /* READ */ | ||
IO = 262, /* IO */ | ||
WRITE = 263, /* WRITE */ | ||
COPY = 264 /* COPY */ | ||
}; | ||
typedef enum yytokentype yytoken_kind_t; | ||
#endif | ||
|
||
/* Value type. */ | ||
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED | ||
typedef char * YYSTYPE; | ||
# define YYSTYPE_IS_TRIVIAL 1 | ||
# define YYSTYPE_IS_DECLARED 1 | ||
#endif | ||
|
||
|
||
extern YYSTYPE yylval; | ||
|
||
|
||
int yyparse (void); | ||
|
||
/* "%code provides" blocks. */ | ||
#line 8 "./bison/parser.y" | ||
|
||
void yyerror(const char *); | ||
extern int yylexerrs; | ||
|
||
#line 88 "./include/console/parser.h" | ||
|
||
#endif /* !YY_YY_INCLUDE_CONSOLE_PARSER_H_INCLUDED */ |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
#define CONTEXT_AVAILABLE 0 | ||
#define CONTEXT_UNAVAILABLE -1 | ||
|
||
typedef struct context | ||
{ | ||
char *input_file_name; | ||
int process_size; | ||
int status; | ||
} context_t; | ||
|
||
context_t read_context(int argc, char *argv[]); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* template.c | ||
* | ||
* Copyright 2020 Roberto Nicolás Savinelli <rnsavinelli@est.frba.utn.edu.ar> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
* MA 02110-1301, USA. | ||
* | ||
*/ | ||
|
||
#ifndef SEMANTIC_H_ | ||
#define SEMANTIC_H_ | ||
|
||
#include "parser.h" | ||
|
||
void request_exit(void); | ||
|
||
void request_no_op(char *constant); | ||
|
||
void request_io(char *constant); | ||
|
||
void request_read(char *constant); | ||
|
||
void request_write(char *constant_l, char *constant_r); | ||
|
||
void request_copy(char *constant_l, char *constant_r); | ||
|
||
#endif // SEMANTIC_H_ |
Oops, something went wrong.