2017-03-06 15:05:09 +00:00
|
|
|
/* Filename: table.h
|
2017-03-19 22:12:44 +00:00
|
|
|
* Transition Table and function declarations necessa`ry for the scanner implementation
|
2017-03-06 15:05:09 +00:00
|
|
|
* as required for CST8152 - Assignment #2.
|
2017-03-15 02:35:12 +00:00
|
|
|
* Author: Victor Fernandes, 040772243
|
2017-03-06 15:58:14 +00:00
|
|
|
* Version: 1.17.1
|
|
|
|
* Date: 30 January 2017
|
2017-03-06 15:05:09 +00:00
|
|
|
* Provided by: Svillen Ranev
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TABLE_H_
|
|
|
|
#define TABLE_H_
|
|
|
|
|
|
|
|
#ifndef BUFFER_H_
|
|
|
|
#include "buffer.h"
|
|
|
|
#endif
|
|
|
|
|
2017-03-18 21:23:57 +00:00
|
|
|
#ifndef TOKEN_H_
|
|
|
|
#include "token.h"
|
|
|
|
#endif
|
|
|
|
|
2017-03-06 15:05:09 +00:00
|
|
|
#ifndef NULL
|
|
|
|
#include <_null.h> /* NULL pointer constant is defined there */
|
|
|
|
#endif
|
|
|
|
|
2017-03-14 19:54:47 +00:00
|
|
|
/* Source end-of-file (SEOF) sentinel symbol
|
|
|
|
* '\0' or only one of the folowing constants: 255, 0xFF , EOF
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Single-lexeme tokens processed separately one by one
|
|
|
|
* in the token-driven part of the scanner
|
|
|
|
* '=' , ' ' , '(' , ')' , '{' , '}' , == , <> , '>' , '<' ,
|
|
|
|
* space
|
|
|
|
* !<comment , ',' , '"' , ';' , '-' , '+' , '*' , '/', << ,
|
|
|
|
* .AND., .OR. , SEOF, 'wrong symbol',
|
|
|
|
*/
|
2017-03-06 15:05:09 +00:00
|
|
|
|
2017-03-19 22:12:44 +00:00
|
|
|
#define ES 12 /* Error state */
|
2017-03-18 21:23:57 +00:00
|
|
|
#define ESWR 13 /* Error state (no retract) */
|
2017-03-19 22:12:44 +00:00
|
|
|
#define IS -1 /* Invalid state */
|
2017-03-06 15:05:09 +00:00
|
|
|
|
2017-04-04 21:35:52 +00:00
|
|
|
/*Avoid platform dependency and use fixed 2-byte short */
|
|
|
|
#define PLT_SHRT_MAX 32767
|
2017-03-06 15:05:09 +00:00
|
|
|
/* State transition table definition */
|
|
|
|
|
2017-03-15 07:04:51 +00:00
|
|
|
#define TABLE_COLUMNS 7
|
2017-03-06 15:05:09 +00:00
|
|
|
/*transition table - type of states defined in separate table */
|
2017-03-14 19:54:47 +00:00
|
|
|
int st_table[][TABLE_COLUMNS] = {
|
|
|
|
/* INPUT COLUMNS:
|
2017-03-18 21:23:57 +00:00
|
|
|
COLUMN # | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
|
|
|
|
|[a-zA-Z]| 0 |[1-7]|[8-9]| . | # | other |
|
2017-03-15 07:04:51 +00:00
|
|
|
*/
|
2017-03-28 16:01:07 +00:00
|
|
|
/* State 0 */ {1, 6 , 4 , 4 , IS , IS , IS},
|
2017-03-18 21:23:57 +00:00
|
|
|
/* State 1 */ {1, 1 , 1 , 1 , 2 , 3 , 2 },
|
|
|
|
/* State 2 */ {IS, IS , IS, IS, IS , IS , IS},
|
|
|
|
/* State 3 */ {IS, IS , IS, IS, IS , IS , IS},
|
|
|
|
/* State 4 */ {ES, 4 , 4 , 4 , 7 , 5 , 5 },
|
|
|
|
/* State 5 */ {IS, IS , IS, IS, IS , IS , IS},
|
|
|
|
/* State 6 */ {ES, 9 , 9 , ES, 7 , ES , 5 },
|
|
|
|
/* State 7 */ {8 , 7 , 7 , 7, 8 , 8 , 8 },
|
|
|
|
/* State 8 */ {IS, IS , IS, IS, IS , IS , IS},
|
2017-03-28 16:01:07 +00:00
|
|
|
/* State 9 */ {ES, 9 , 11, ES, ES , ES , 10},
|
2017-03-18 21:23:57 +00:00
|
|
|
/* State 10 */ {IS, IS , IS, IS, IS , IS , IS},
|
|
|
|
/* State 11 */ {ES, 11 , 11, ES, ES , ES , 10},
|
|
|
|
/* State 12 */ {IS, IS , IS, IS, IS , IS , IS},
|
|
|
|
/* State 13 */ {IS, IS , IS, IS, IS , IS , IS}
|
2017-03-16 00:57:28 +00:00
|
|
|
|
2017-03-14 19:54:47 +00:00
|
|
|
};
|
2017-03-06 15:05:09 +00:00
|
|
|
/* Accepting state table definition */
|
2017-03-16 00:57:28 +00:00
|
|
|
#define ASWR 1 /* accepting state with retract */
|
|
|
|
#define ASNR 2 /* accepting state with no retract */
|
2017-03-14 19:54:47 +00:00
|
|
|
#define NOAS 0 /* not accepting state */
|
|
|
|
|
|
|
|
int as_table[] = {
|
|
|
|
|
|
|
|
/* State 0 */ NOAS,
|
|
|
|
/* State 1 */ NOAS,
|
|
|
|
/* State 2 */ ASWR,
|
|
|
|
/* State 3 */ ASNR,
|
|
|
|
/* State 4 */ NOAS,
|
|
|
|
/* State 5 */ ASWR,
|
|
|
|
/* State 6 */ NOAS,
|
|
|
|
/* State 7 */ NOAS,
|
|
|
|
/* State 8 */ ASWR,
|
|
|
|
/* State 9 */ NOAS,
|
|
|
|
/* State 10 */ ASWR,
|
2017-03-18 21:23:57 +00:00
|
|
|
/* State 11 */ NOAS,
|
2017-03-14 19:54:47 +00:00
|
|
|
/* State 12 */ ASNR,
|
|
|
|
/* State 13 */ ASWR
|
2017-03-06 15:05:09 +00:00
|
|
|
|
2017-03-14 19:54:47 +00:00
|
|
|
};
|
2017-03-06 15:05:09 +00:00
|
|
|
|
|
|
|
/* Accepting action function declarations */
|
|
|
|
|
2017-03-16 00:57:28 +00:00
|
|
|
Token aa_func02(char* lexeme); /* AVID/KW */
|
|
|
|
Token aa_func03(char* lexeme); /* SVID */
|
|
|
|
Token aa_func05(char* lexeme); /* DIL */
|
|
|
|
Token aa_func08(char* lexeme); /* FPL */
|
|
|
|
Token aa_func10(char* lexeme); /* OIL */
|
2017-03-18 21:23:57 +00:00
|
|
|
Token aa_func12(char* lexeme); /* ES ASNR */
|
|
|
|
Token aa_func13(char* lexeme); /* ES ASWR */
|
2017-03-14 19:54:47 +00:00
|
|
|
|
|
|
|
/* defining a new type: pointer to function (of one char * argument)
|
2017-03-06 15:05:09 +00:00
|
|
|
returning Token
|
2017-03-14 19:54:47 +00:00
|
|
|
*/
|
2017-03-06 15:05:09 +00:00
|
|
|
|
2017-03-14 19:54:47 +00:00
|
|
|
typedef Token(*PTR_AAF)(char *lexeme);
|
2017-03-06 15:05:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Accepting function (action) callback table (array) definition */
|
|
|
|
/* If you do not want to use the typedef, the equvalent declaration is:
|
|
|
|
* Token (*aa_table[])(char lexeme[]) = {
|
|
|
|
*/
|
|
|
|
|
2017-03-14 19:54:47 +00:00
|
|
|
PTR_AAF aa_table[] = {
|
|
|
|
|
|
|
|
/* State 0 */ NULL,
|
|
|
|
/* State 1 */ NULL,
|
|
|
|
/* State 2 */ aa_func02,
|
|
|
|
/* State 3 */ aa_func03,
|
|
|
|
/* State 4 */ NULL,
|
|
|
|
/* State 5 */ aa_func05,
|
|
|
|
/* State 6 */ NULL,
|
|
|
|
/* State 7 */ NULL,
|
|
|
|
/* State 8 */ aa_func08,
|
|
|
|
/* State 9 */ NULL,
|
|
|
|
/* State 10 */ aa_func10,
|
2017-03-15 07:04:51 +00:00
|
|
|
/* State 11 */ NULL,
|
2017-03-18 21:23:57 +00:00
|
|
|
/* State 12 */ aa_func12,
|
2017-03-16 00:57:28 +00:00
|
|
|
/* State 13 */ aa_func13
|
2017-03-16 21:54:28 +00:00
|
|
|
|
2017-03-06 15:05:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Keyword lookup table (.AND. and .OR. are not keywords) */
|
|
|
|
|
|
|
|
#define KWT_SIZE 8
|
|
|
|
|
2017-03-14 19:54:47 +00:00
|
|
|
char * kw_table[] = {
|
|
|
|
"ELSE",
|
|
|
|
"IF",
|
|
|
|
"INPUT",
|
|
|
|
"OUTPUT",
|
|
|
|
"PLATYPUS",
|
|
|
|
"REPEAT",
|
|
|
|
"THEN",
|
|
|
|
"USING"
|
|
|
|
};
|
2017-03-06 15:05:09 +00:00
|
|
|
|
|
|
|
#endif
|