Update README and file headers
This commit is contained in:
parent
57a7fa3e43
commit
8a8188e07d
18
README.md
18
README.md
|
@ -1,5 +1,5 @@
|
||||||
# PLATYPUS
|
# PLATYPUS
|
||||||
*Buffer Descriptor for the PLATYPUS language specification*
|
*Frontend compiler for the PLATYPUS language specification*
|
||||||
|
|
||||||
## Building
|
## Building
|
||||||
|
|
||||||
|
@ -8,12 +8,12 @@
|
||||||
*gcc (tested in version 6.3.x) or clang (tested under LLVM clang-0800.0.42.1)*
|
*gcc (tested in version 6.3.x) or clang (tested under LLVM clang-0800.0.42.1)*
|
||||||
|
|
||||||
- `make [gcc | clang]`
|
- `make [gcc | clang]`
|
||||||
- Default is to build both versions (this is an aftermath of testing behaviour from different compilers)
|
- No argument will build both versions (this is an aftermath of having to check behaviour in the binary from multiple compilers)
|
||||||
- It is safe to modify the default to either gcc or clang if you don't have one of them
|
- It is safe to modify the default to either gcc or clang if you wish. ** SEE NOTES BELOW **
|
||||||
- **NOTE: I haven't tested or created make targets for the scanner yet.**
|
- **NOTE: I haven't tested or created make targets for the final implementation yet. This is somewhat buried deep into the backburner**
|
||||||
### Windows
|
### Windows
|
||||||
#### Requires
|
#### Requires
|
||||||
- `msvc` (tested under Visual Studio 2015 with Update 3, however VS2013 shouldn't behave abnormally either, nor should 2017)
|
- `msvc` (tested under Visual Studio 2015 with Update 3, however VS 2012 and 2013 shouldn't behave abnormally either, nor should 2017)
|
||||||
- Disable language extensions (use ANSI C)
|
- Disable language extensions (use ANSI C)
|
||||||
---
|
---
|
||||||
## Running
|
## Running
|
||||||
|
@ -31,10 +31,10 @@
|
||||||
|
|
||||||
# Notes
|
# Notes
|
||||||
|
|
||||||
This is in no way complete, it is missing a scanner implementation, parser, symbol table, etc.
|
**This is in no way complete, or ready for production in any shape or form.** It works up to the parser, but still contains incorrect grammar parsing and some edge cases that causes crashes.
|
||||||
|
|
||||||
You can modify the initial capacity and increment factor defined in `platy_bt.c` (should really make that a command line parameter in a future release)
|
You can modify the initial capacity and increment factor defined in `platy.c` (should really make that a command line parameter in a future release)
|
||||||
- Increment factor range for additive mode: `1 - 255`. (setting this to 0 implies fixed mode, regardless of the mode given in the command line)
|
- Increment factor range for additive mode: `1 - 255`. (setting this to 0 implies fixed mode, regardless of the mode given in the command line)
|
||||||
- Initial capacity range (in bytes): `0 - 32767 (SHRT_MAX)`
|
- Initial capacity range (in bytes): `0 - 32767 (SHRT_MAX)`
|
||||||
- This is due to my environment's install locations for the C include libraries:
|
- This is an issue caused by my environment's install locations for the C include libraries:
|
||||||
- **Inside `buffer.h`, there is a `#DEFINE` line for `MACOS_DEP`. If you are using a Linux system or Windows and your malloc.h is actually named malloc.h, you can leave `#undef MACOS_DEP` alone, otherwise comment it out.**
|
- **`buffer.h` contains an `#ifdef` directive checking if `WIN32` exists. Due to an upgrade issue with GCC in macOS (possibly only in my machine), `malloc.h` is actually named `mm_maloc.h`. If your system uses `malloc.h`, you can safely delete the check and use the regular filename instead.**
|
||||||
|
|
2
buffer.c
2
buffer.c
|
@ -4,7 +4,7 @@
|
||||||
* Author: Victor Fernandes, 040772243
|
* Author: Victor Fernandes, 040772243
|
||||||
* Course: CST8152 - Compilers, Lab Section: 011
|
* Course: CST8152 - Compilers, Lab Section: 011
|
||||||
* Date: February 1, 2017
|
* Date: February 1, 2017
|
||||||
* Professor: Svillen Ranev
|
* Professor: S^R
|
||||||
* A character buffer utility with three modes of self-incrementation
|
* A character buffer utility with three modes of self-incrementation
|
||||||
through dynamic memory allocation, and ability to set a mark flag.
|
through dynamic memory allocation, and ability to set a mark flag.
|
||||||
* Function list: b_create, b_isfull, b_isempty, b_size, b_capacity,
|
* Function list: b_create, b_isfull, b_isempty, b_size, b_capacity,
|
||||||
|
|
64
parser.c
64
parser.c
|
@ -1,6 +1,7 @@
|
||||||
/* File Name: parser.c
|
/* File Name: parser.c
|
||||||
* The PLATYPUS parsing program for the final assignment of
|
* The PLATYPUS parsing program for the final assignment of
|
||||||
How To Train Your Dragon (AKA Compilers)
|
How To Train Your Dragon (AKA Compilers)
|
||||||
|
* Compiler: GNU GCC 6
|
||||||
* Author: Victor Fernandes, 040772243
|
* Author: Victor Fernandes, 040772243
|
||||||
* Course: CST8152 - Compilers, Lab Section: 011
|
* Course: CST8152 - Compilers, Lab Section: 011
|
||||||
* Date: April 21, 2017
|
* Date: April 21, 2017
|
||||||
|
@ -11,14 +12,14 @@
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
|
|
||||||
/* Global variables for the parser */
|
/* Global variables for the parser */
|
||||||
Token lookahead;
|
Token lookahead;
|
||||||
extern int synerrno; /* Error counter */
|
int synerrno; /* Error counter */
|
||||||
extern char* kw_table[]; /* Keyword table with matching enum */
|
Buffer *sc_buf; /* Scanner buffer */
|
||||||
extern STD sym_table; /* The symbol table */
|
extern char *kw_table[]; /* Keyword table with matching enum */
|
||||||
extern Buffer* sc_buf; /* Scanner buffer */
|
extern STD sym_table; /* The symbol table */
|
||||||
extern Buffer* str_LTBL; /* String literal table */
|
extern Buffer *str_LTBL; /* String literal table */
|
||||||
extern int line /* Line position of the Scanner */
|
extern int line; /* Line position of the Scanner */
|
||||||
|
extern Token malar_next_token(Buffer *); /* Scanner function to get the next token */
|
||||||
|
|
||||||
/* Begins the source file parsing
|
/* Begins the source file parsing
|
||||||
* Author: Victor Fernandes, 040772243
|
* Author: Victor Fernandes, 040772243
|
||||||
|
@ -29,6 +30,7 @@
|
||||||
*/
|
*/
|
||||||
void parser(pBuffer in_buf)
|
void parser(pBuffer in_buf)
|
||||||
{
|
{
|
||||||
|
synerrno = 0;
|
||||||
sc_buf = in_buf;
|
sc_buf = in_buf;
|
||||||
lookahead = malar_next_token(sc_buf);
|
lookahead = malar_next_token(sc_buf);
|
||||||
program();
|
program();
|
||||||
|
@ -68,7 +70,7 @@ void match(int pr_token_code, int pr_token_attribute)
|
||||||
lookahead = malar_next_token(sc_buf);
|
lookahead = malar_next_token(sc_buf);
|
||||||
if (lookahead.code == ERR_T)
|
if (lookahead.code == ERR_T)
|
||||||
{
|
{
|
||||||
synerrno++;
|
++synerrno;
|
||||||
syn_printe();
|
syn_printe();
|
||||||
lookahead = malar_next_token(sc_buf);
|
lookahead = malar_next_token(sc_buf);
|
||||||
}
|
}
|
||||||
|
@ -90,7 +92,7 @@ void match(int pr_token_code, int pr_token_attribute)
|
||||||
void syn_eh(int pr_token_code)
|
void syn_eh(int pr_token_code)
|
||||||
{
|
{
|
||||||
syn_printe();
|
syn_printe();
|
||||||
synerrno++;
|
++synerrno;
|
||||||
|
|
||||||
while (lookahead.code != SEOF_T)
|
while (lookahead.code != SEOF_T)
|
||||||
{
|
{
|
||||||
|
@ -117,7 +119,7 @@ void syn_eh(int pr_token_code)
|
||||||
*/
|
*/
|
||||||
void syn_printe()
|
void syn_printe()
|
||||||
{
|
{
|
||||||
printf("PLATY: Syntax error: Line:%3d\n" + "***** Token code: %3d Attribute: ", line, lookahead.code);
|
printf("PLATY: Syntax error: Line:%3d\n***** Token code: %3d Attribute: ", line, lookahead.code);
|
||||||
switch (lookahead.code)
|
switch (lookahead.code)
|
||||||
{
|
{
|
||||||
case ERR_T:
|
case ERR_T:
|
||||||
|
@ -196,7 +198,6 @@ void gen_incode(char *code)
|
||||||
* Grammar functions ahoy
|
* Grammar functions ahoy
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* <additive_arithmetic_expression> ->
|
* <additive_arithmetic_expression> ->
|
||||||
<multiplicative_arithmetic_expression> <additive_arithmetic_expression_prime>
|
<multiplicative_arithmetic_expression> <additive_arithmetic_expression_prime>
|
||||||
|
@ -215,7 +216,7 @@ void additive_arithmetic_expression()
|
||||||
*/
|
*/
|
||||||
void additive_arithmetic_expression_prime()
|
void additive_arithmetic_expression_prime()
|
||||||
{
|
{
|
||||||
if (lookahead.code == ART_OP &&
|
if (lookahead.code == ART_OP_T &&
|
||||||
lookahead.attribute.arr_op != MULT &&
|
lookahead.attribute.arr_op != MULT &&
|
||||||
lookahead.attribute.arr_op != DIV)
|
lookahead.attribute.arr_op != DIV)
|
||||||
{
|
{
|
||||||
|
@ -233,6 +234,9 @@ void additive_arithmetic_expression_prime()
|
||||||
*/
|
*/
|
||||||
void arithmetic_expression()
|
void arithmetic_expression()
|
||||||
{
|
{
|
||||||
|
/* GCC complains that PLUS and MINUS enums aren't handled,
|
||||||
|
but this is automatically handled in additive_arithmetic_expression()
|
||||||
|
*/
|
||||||
switch (lookahead.code)
|
switch (lookahead.code)
|
||||||
{
|
{
|
||||||
case ART_OP_T:
|
case ART_OP_T:
|
||||||
|
@ -389,7 +393,7 @@ void logical_or_expression()
|
||||||
.OR. <logical_and_expression> <logical_or_expression_prime>
|
.OR. <logical_and_expression> <logical_or_expression_prime>
|
||||||
FIRST Set = { .OR., E }
|
FIRST Set = { .OR., E }
|
||||||
*/
|
*/
|
||||||
voic logical_or_expression_prime()
|
void logical_or_expression_prime()
|
||||||
{
|
{
|
||||||
if (lookahead.code == LOG_OP_T &&
|
if (lookahead.code == LOG_OP_T &&
|
||||||
lookahead.attribute.log_op == OR)
|
lookahead.attribute.log_op == OR)
|
||||||
|
@ -450,7 +454,8 @@ void opt_statements()
|
||||||
}
|
}
|
||||||
case AVID_T:
|
case AVID_T:
|
||||||
case SVID_T:
|
case SVID_T:
|
||||||
statements() : break;
|
statements();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
gen_incode("PLATY: Opt_statements parsed");
|
gen_incode("PLATY: Opt_statements parsed");
|
||||||
}
|
}
|
||||||
|
@ -522,18 +527,18 @@ void primary_arithmetic_expression()
|
||||||
{
|
{
|
||||||
switch (lookahead.code)
|
switch (lookahead.code)
|
||||||
{
|
{
|
||||||
case AVID_T:
|
case AVID_T:
|
||||||
case FPL_T:
|
case FPL_T:
|
||||||
case INL_T:
|
case INL_T:
|
||||||
match(lookahead.code, lookahead.attribute.arr_op);
|
match(lookahead.code, lookahead.attribute.arr_op);
|
||||||
break;
|
break;
|
||||||
case LPR_T:
|
case LPR_T:
|
||||||
match(lookahead.code, lookahead.attribute,arr_op);
|
match(lookahead.code, lookahead.attribute.arr_op);
|
||||||
arithmetic_expression();
|
arithmetic_expression();
|
||||||
match(RPR_T, NO_ATTR);
|
match(RPR_T, NO_ATTR);
|
||||||
default:
|
default:
|
||||||
syn_printe();
|
syn_printe();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
gen_incode("PLATY: Primary arithmetic expression parsed");
|
gen_incode("PLATY: Primary arithmetic expression parsed");
|
||||||
}
|
}
|
||||||
|
@ -661,7 +666,7 @@ void relational_expression_prime_string()
|
||||||
case NE:
|
case NE:
|
||||||
case GT:
|
case GT:
|
||||||
case LT:
|
case LT:
|
||||||
match(lookahead.codem, lookahead.attribute.arr_op);
|
match(lookahead.code, lookahead.attribute.arr_op);
|
||||||
primary_s_relational_expression();
|
primary_s_relational_expression();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -791,7 +796,7 @@ void string_expression_prime()
|
||||||
{
|
{
|
||||||
match(SCC_OP_T, NO_ATTR);
|
match(SCC_OP_T, NO_ATTR);
|
||||||
primary_string_expression();
|
primary_string_expression();
|
||||||
stirng_expression_prime();
|
string_expression_prime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -803,6 +808,7 @@ void string_expression_prime()
|
||||||
*/
|
*/
|
||||||
void unary_arithmetic_expression()
|
void unary_arithmetic_expression()
|
||||||
{
|
{
|
||||||
|
/* Again, GCC complains about PLUS and MINUS enums */
|
||||||
switch (lookahead.code)
|
switch (lookahead.code)
|
||||||
{
|
{
|
||||||
case ART_OP_T:
|
case ART_OP_T:
|
||||||
|
|
3
parser.h
3
parser.h
|
@ -3,7 +3,7 @@
|
||||||
* Author: Victor Fernandes, 040772243
|
* Author: Victor Fernandes, 040772243
|
||||||
* Course: CST8152 - Compilers, Lab Section: 011
|
* Course: CST8152 - Compilers, Lab Section: 011
|
||||||
* Date: April 17, 2017
|
* Date: April 17, 2017
|
||||||
* Professor: Svillen Ravev
|
* Professor: S^R
|
||||||
* Version: 0.1
|
* Version: 0.1
|
||||||
*/
|
*/
|
||||||
#ifndef PARSER_H_
|
#ifndef PARSER_H_
|
||||||
|
@ -63,6 +63,7 @@ void statement(void);
|
||||||
void statements(void);
|
void statements(void);
|
||||||
void statements_prime(void);
|
void statements_prime(void);
|
||||||
void string_expression(void);
|
void string_expression(void);
|
||||||
|
void string_expression_prime(void);
|
||||||
void unary_arithmetic_expression(void);
|
void unary_arithmetic_expression(void);
|
||||||
void variable_identifier(void);
|
void variable_identifier(void);
|
||||||
void variable_list(void);
|
void variable_list(void);
|
||||||
|
|
2
platy.c
2
platy.c
|
@ -2,7 +2,7 @@
|
||||||
* Purpose:This is the main program for Assignment#4 - Platypus Parser
|
* Purpose:This is the main program for Assignment#4 - Platypus Parser
|
||||||
* CST8152 - Compilers
|
* CST8152 - Compilers
|
||||||
* Version: 1.17.01
|
* Version: 1.17.01
|
||||||
* Author: Svillen Ranev
|
* Author: S^R
|
||||||
* Date: 18 March 2017
|
* Date: 18 March 2017
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/* File name: platy_bt.c
|
/* File name: platy_bt.c
|
||||||
* Purpose:This is the main program for Assignment #1, CST8152, Winter 17
|
* Purpose:This is the main program for Assignment #1, CST8152, Winter 17
|
||||||
* Version: 1.17.1
|
* Version: 1.17.1
|
||||||
* Author: Svillen Ranev
|
* Author: S^R
|
||||||
* Date: 9 January 2017
|
* Date: 9 January 2017
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* Purpose:This is the main program for Assignment #2 - Scanner
|
* Purpose:This is the main program for Assignment #2 - Scanner
|
||||||
* CST8152 - Compilers
|
* CST8152 - Compilers
|
||||||
* Version: 1.17.1
|
* Version: 1.17.1
|
||||||
* Author: Svillen Ranev
|
* Author: S^R
|
||||||
* Date: 30 January 2017
|
* Date: 30 January 2017
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* Purpose:This is the main program for Assignment #3 - Symbol Table
|
* Purpose:This is the main program for Assignment #3 - Symbol Table
|
||||||
* CST8152 - Compilers
|
* CST8152 - Compilers
|
||||||
* Version: 1.17.01
|
* Version: 1.17.01
|
||||||
* Author: Svillen Ranev
|
* Author: S^R
|
||||||
* Date: 1 March 2017
|
* Date: 1 March 2017
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
12
scanner.c
12
scanner.c
|
@ -5,7 +5,7 @@
|
||||||
* scanner_init() must be called before using the scanner.
|
* scanner_init() must be called before using the scanner.
|
||||||
* The file is incomplete;
|
* The file is incomplete;
|
||||||
* Author: Victor Fernandes, 040772243
|
* Author: Victor Fernandes, 040772243
|
||||||
* Provided by: Svillen Ranev
|
* Provided by: S^R
|
||||||
* Version: 1.17.1
|
* Version: 1.17.1
|
||||||
* Date: 30 January 2017
|
* Date: 30 January 2017
|
||||||
* Function list: scanner_init, malar_next_token, get_next_state, char_class,
|
* Function list: scanner_init, malar_next_token, get_next_state, char_class,
|
||||||
|
@ -45,7 +45,7 @@
|
||||||
It is defined in platy_st.c */
|
It is defined in platy_st.c */
|
||||||
extern Buffer * str_LTBL; /*String literal table */
|
extern Buffer * str_LTBL; /*String literal table */
|
||||||
int line; /* current line number of the source code */
|
int line; /* current line number of the source code */
|
||||||
extern int scerrnum; /* defined in platy_st.c - run-time error number */
|
extern int synerrno; /* defined in platy_st.c - run-time error number */
|
||||||
extern STD sym_table; /* symbol table */
|
extern STD sym_table; /* symbol table */
|
||||||
/* Local(file) global objects - variables */
|
/* Local(file) global objects - variables */
|
||||||
static Buffer *lex_buf; /*pointer to temporary lexeme buffer*/
|
static Buffer *lex_buf; /*pointer to temporary lexeme buffer*/
|
||||||
|
@ -74,7 +74,7 @@ int scanner_init(Buffer * sc_buf) {
|
||||||
b_reset(str_LTBL);
|
b_reset(str_LTBL);
|
||||||
line = 1;
|
line = 1;
|
||||||
return EXIT_SUCCESS;/*0*/
|
return EXIT_SUCCESS;/*0*/
|
||||||
/* scerrnum = 0; *//*no need - global ANSI C */
|
/* synerrno = 0; *//*no need - global ANSI C */
|
||||||
}
|
}
|
||||||
/* Reads the source code buffer and generates a token
|
/* Reads the source code buffer and generates a token
|
||||||
* Author: Victor Fernandes
|
* Author: Victor Fernandes
|
||||||
|
@ -107,7 +107,8 @@ Token malar_next_token(Buffer * sc_buf)
|
||||||
pBuffer err_lex_buf;
|
pBuffer err_lex_buf;
|
||||||
|
|
||||||
if (sc_buf == NULL) {
|
if (sc_buf == NULL) {
|
||||||
scerrnum = 1;
|
synerrno
|
||||||
|
= 1;
|
||||||
return aa_table[ES]("RUN TIME ERROR: "); /* WHOOPS */
|
return aa_table[ES]("RUN TIME ERROR: "); /* WHOOPS */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,7 +280,8 @@ Token malar_next_token(Buffer * sc_buf)
|
||||||
t = aa_table[state](b_setmark(lex_buf, 0));
|
t = aa_table[state](b_setmark(lex_buf, 0));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
scerrnum = 1;
|
synerrno
|
||||||
|
= 1;
|
||||||
t = aa_table[ES]("RUN TIME ERROR: ");
|
t = aa_table[ES]("RUN TIME ERROR: ");
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
4
stable.c
4
stable.c
|
@ -2,7 +2,7 @@
|
||||||
* Compiler: msvc (Visual Studio 2015)
|
* Compiler: msvc (Visual Studio 2015)
|
||||||
* Store and provide functions for the symbol table database
|
* Store and provide functions for the symbol table database
|
||||||
* CST8152, Assignment #3
|
* CST8152, Assignment #3
|
||||||
* Professor: Svillen Ranev
|
* Professor: S^R
|
||||||
* Author: Victor Fernandes, 040772243
|
* Author: Victor Fernandes, 040772243
|
||||||
* Version: 0.1
|
* Version: 0.1
|
||||||
* Date: 24 March 2017
|
* Date: 24 March 2017
|
||||||
|
@ -13,7 +13,7 @@
|
||||||
#define PLSBD_INC 64
|
#define PLSBD_INC 64
|
||||||
|
|
||||||
#define DEBUG
|
#define DEBUG
|
||||||
#undef DEBUG*/
|
#undef DEBUG
|
||||||
|
|
||||||
/* Forward function declarations */
|
/* Forward function declarations */
|
||||||
static void st_setsize(void);
|
static void st_setsize(void);
|
||||||
|
|
4
stable.h
4
stable.h
|
@ -1,8 +1,8 @@
|
||||||
/* Filename: stable.h
|
/* Filename: stable.h
|
||||||
* Compiler: msvc (Visual Studio 2015)
|
* Compiler: msvc (Visual Studio 2015)
|
||||||
* Function declarations for the symbol table
|
* Function declarations for the symbol table
|
||||||
* CST8152, Assignment #3
|
* CST8152, Assignment #3
|
||||||
* Professor: Svillen Ranev
|
* Professor: S^R
|
||||||
* Author: Victor Fernandes, 040772243
|
* Author: Victor Fernandes, 040772243
|
||||||
* Version: 0.1
|
* Version: 0.1
|
||||||
* Date: 24 March 2017
|
* Date: 24 March 2017
|
||||||
|
|
2
table.h
2
table.h
|
@ -4,7 +4,7 @@
|
||||||
* Author: Victor Fernandes, 040772243
|
* Author: Victor Fernandes, 040772243
|
||||||
* Version: 1.17.1
|
* Version: 1.17.1
|
||||||
* Date: 30 January 2017
|
* Date: 30 January 2017
|
||||||
* Provided by: Svillen Ranev
|
* Provided by: S^R
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TABLE_H_
|
#ifndef TABLE_H_
|
||||||
|
|
2
token.h
2
token.h
|
@ -4,7 +4,7 @@
|
||||||
* Author: Victor Fernandes, 040772243
|
* Author: Victor Fernandes, 040772243
|
||||||
* Version: 1.17.1
|
* Version: 1.17.1
|
||||||
* Date: 30 January 2017
|
* Date: 30 January 2017
|
||||||
* Provided by: Svillen Ranev
|
* Provided by: S^R
|
||||||
* The file is complete and MUST NOT be modified.
|
* The file is complete and MUST NOT be modified.
|
||||||
*/
|
*/
|
||||||
#ifndef TOKEN_H_
|
#ifndef TOKEN_H_
|
||||||
|
|
Loading…
Reference in New Issue