File: dbprolog.l

package info (click to toggle)
whitedb 0.7.3%2Bgit200711-1
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 3,340 kB
  • sloc: ansic: 33,250; javascript: 3,299; python: 790; lex: 359; java: 277; makefile: 192; sh: 164; yacc: 138; sed: 41
file content (165 lines) | stat: -rw-r--r-- 3,682 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
* $Id:  $
* $Version: $
*
* Copyright (c) Tanel Tammet 2004,2005,2006,2007,2008,2009,2010
*
* Contact: tanel.tammet@gmail.com                 
*
* This file is part of WhiteDB
*
* WhiteDB 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.
* 
* WhiteDB 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 WhiteDB.  If not, see <http://www.gnu.org/licenses/>.
*
*/

 /** @file dbprolog.l
 *  Lexer rules for prolog parser
 *
 */

%{
#include <math.h>
#include <stdio.h>
#include "dbprologparse.h"
#include "dbprolog.tab.h"

/*  reentrant stuff starts */

#define PARM    yyget_extra(yyscanner)

/*

#define YY_INPUT(buffer, res, max_size)             \
    do {                                                \
        if (PARM->pos >= PARM->length)                  \
            res = YY_NULL;                              \
        else                                            \
        {                                               \
            res = PARM->length - PARM->pos;             \
            res > (int)max_size ? res = max_size : 0;   \
            memcpy(buffer, PARM->buf + PARM->pos, res); \
            PARM->pos += res;                           \
        }                                               \
    } while (0)

*/

char linebuf[1024];
char elmparsestrbuf[1024]; 
char *s; 

%}


%option reentrant 
%option bison-bridge
%option noyywrap
%option yylineno 
%option nounput
%option noinput

%x SQLSTATE
%x STRSTATE 

ATOM	[a-z#][_a-zA-Z0-9]*
VAR	[A-Z][_a-zA-Z0-9]*

%%


"%".*\n	{
	parseprintf("A lineful of comment.\n"); /* eat line comments */
	}

:-	{
	parseprintf("A :- , \"IS\"\n");
	return IS;
	}


not	{
	parseprintf("A \"not\".\n");
	return NOT;
	}

{ATOM}	{
	parseprintf("An atom: %s\n", yytext);
	*yylval=strdup(yytext);
	return ATOM;
	}

{VAR}	{
	parseprintf("A variable: %s\n", yytext);
	*yylval=strdup(yytext);
	return VAR;
	}

[0-9]+	{ parseprintf( "An integer: %s (%d)\n", yytext, atoi(yytext));
	*yylval=strdup(yytext);
	return INT;
	}

[0-9]+"."[0-9]+	{
		parseprintf( "A float: %s (%lf)\n", yytext, atof(yytext));
		*yylval=strdup(yytext);
		return FLOAT;
		}


"'"[^']+"'"	{
		parseprintf("A \'-quoted string, basically an atom: %s\n", yytext);
		*yylval = strdup(yytext) + 1; // erase the first character
		((char*)*yylval)[strlen(*yylval) - 1] = '\0'; // erase the last character '
		return ATOM;
		}

"\""[^"]+"\""	{
		parseprintf("A quoted string, basically an atom: %s\n", yytext);
	   *yylval = strdup(yytext); // erase the first character
		//((char*)*yylval)[strlen(*yylval) - 1] = '\0'; // erase the last character '
    
		return ATOM;
		}


[)] return ')';
[(] return '(';
[,] return ',';
[.] return '.';
[;] return ';';
[!] return '!';
[~] return '~';

<<EOF>>		{
		parseprintf("file end. Read %d lines.\n", yylineno);
		yyterminate();
		return 0;
		}


[\r\n]     { yylineno++; }  
[ \t]+     ;/* eat up whitespace */
.         { parseprintf( "Unrecognized character: %s\n", yytext ); }


%%


void wg_yyprologerror(parse_parm* parm, void* scanner, char* msg) {
  //printf("\n yyerror called with xx msg %s\n",msg);
  printf("parse error at prolog file %s line %d text fragment %s: %s \n", 
          parm->filename,yyget_lineno(scanner),yyget_text(scanner),msg);  
}