From 0df7f6fa71cea5de0e041df80854d307930e418d Mon Sep 17 00:00:00 2001 From: Shinya Sato Date: Tue, 2 Nov 2021 16:05:52 +0900 Subject: v0.5.1 --- src/inpla.l | 193 ------------------------------------------------------------ 1 file changed, 193 deletions(-) delete mode 100644 src/inpla.l (limited to 'src/inpla.l') diff --git a/src/inpla.l b/src/inpla.l deleted file mode 100644 index 85bf522..0000000 --- a/src/inpla.l +++ /dev/null @@ -1,193 +0,0 @@ -%{ -#include -#include -#include "linenoise/linenoise.h" - -#undef YY_INPUT -#define YY_INPUT(buf,result,max_size) result = mygetinput(buf, max_size); - -static int mygetinput(char *buf, int size) { - char *line; - if (feof(yyin)) return YY_NULL; - - if (yyin!=stdin) { - int len; - char ch; - for (len = 0; len < size; len++) { - ch = getc(yyin); - if (ch == EOF) - break; - buf[len] = ch; - } - return len; - } - - linenoiseSetMultiLine(1); - if (yylineno == 1) { - line = linenoise(">>> "); - } else { - line = linenoise("... "); - } - if(!line) return YY_NULL; - if(strlen(line) > size-2){ - fprintf(stderr,"input line too long\n"); - return YY_NULL; - } - sprintf(buf, "%s\n", line); - linenoiseHistoryAdd(line); - linenoiseHistorySave(".inpla.history.txt"); - free(line); - return strlen(buf); -} - - -//#undef YY_INPUT -//#define YYINPUT(buf, result, max_size) result = (c == EOF) ? YY_NULL : (buf[0] = c, 1); - - -/************************************ - Strings -*************************************/ -#define MAX_STRING_LENGTH 1024 -static char ParseStringBuffer[MAX_STRING_LENGTH]; -static int nextPtr_ParseStringBuffer = 0; -void Parse_StringBuffer_reInit() { - nextPtr_ParseStringBuffer = 0; -} - -void Parse_addString(char ch) { - ParseStringBuffer[nextPtr_ParseStringBuffer] = ch; - nextPtr_ParseStringBuffer++; -} - -char *Parse_closeStringBuffer() { - char *ret; - ParseStringBuffer[nextPtr_ParseStringBuffer]='\0'; - ret = ParseStringBuffer; - return ret; -} - - - -%} - -%option nounput -%option yylineno -%option noyywrap -%x STRING_STATE COM_STATE -%% -";" return (DELIMITER); -":" return (COLON); -"(" return (LP); -")" return (RP); -"{" return LC; -"}" return RC; -"[" return LB; -"]" return RB; -"," return (COMMA); -"><" return (CROSS); -"=>" return (TO); -"~" return (CNCT); -"-" return (SUB); -"|" return(PIPE); -"&" return(AMP); -"=" return(LD); -"==" return(EQUAL); -"!=" return(NE); -">" return(GT); -">=" return(GE); -"<" return(LT); -"<=" return(LE); -"+" return (ADD); -"*" return (MUL); -"/" return (DIV); -"%" return (MOD); -"_" return (ANY); -"<<" return (ABR); - -"int" return(INT); - -"let" return(LET); -"in" return(IN); -"end" return(END); - -"where" return(WHERE); - -"if" return(IF); -"then" return(THEN); -"else" return(ELSE); - -"interface" return(INTERFACE); -"ifce" return(IFCE); - -"prnat" return(PRNAT); -"free" return(FREE); -"exit" return(EXIT); - -"rand" return(RAND); - -"const" return(DEF); - -"use" return(USE); - -"*L" return(ANNOTATE_L); -"*R" return(ANNOTATE_R); -[a-z][a-zA-Z0-9_'\.]* { yylval.chval = strdup(yytext); - return (NAME);} -[A-Z][a-zA-Z0-9_'\.]* { yylval.chval = strdup(yytext); - return (AGENT);} -[0-9]+ { yylval.intval = atoi(yytext); - return (INT_LITERAL);} - -"//"[^\n]* ; //comment -"/*" BEGIN(COM_STATE); -. ; -\n ; -"*/" BEGIN INITIAL; //comment - -\r\n ; -[\n|\r] ; -[ \t]+ ; -<> {return END_OF_FILE;} -\" { - Parse_StringBuffer_reInit(); - BEGIN STRING_STATE; -} - -. {return yytext[0];} - - - - -\" { - yylval.chval = strdup(Parse_closeStringBuffer()); - BEGIN INITIAL; - return STRING_LITERAL; -} -\n { -// Parse_addString('\n'); -yyerror("Unterminated string"); -BEGIN(INITIAL); -return DELIMITER; -} -\\\" Parse_addString('"'); -\\n Parse_addString('\n'); -\\t Parse_addString('\t'); -\\\\ Parse_addString('\\'); -. Parse_addString(yytext[0]); -%% - -void pushFP(FILE *fp) { - yypush_buffer_state(yy_create_buffer(fp, YY_BUF_SIZE)); -} - -int popFP() { - yypop_buffer_state(); - if (! YY_CURRENT_BUFFER ) { - yyterminate(); - return 0; - } - return 1; -} - - -- cgit v1.2.3