From b07b5127905ac8340a6fa568b6bb272ccd0311d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Ar=C3=A9valo?= Date: Fri, 17 Dec 2010 14:00:47 +0000 Subject: [PATCH] Added very basic flex files for raster MapAlgebra implementation. The file 'ma_lexer_only' is for testing only the lexer, without the parser git-svn-id: http://svn.osgeo.org/postgis/trunk@6424 b70326c6-7e19-0410-871a-916f4a2858ee --- raster/ma_lexer.l | 61 ++++++++++++++++++++++++++++++++++++++++++ raster/ma_lexer_only.l | 47 ++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 raster/ma_lexer.l create mode 100644 raster/ma_lexer_only.l diff --git a/raster/ma_lexer.l b/raster/ma_lexer.l new file mode 100644 index 000000000..e3bddf4c3 --- /dev/null +++ b/raster/ma_lexer.l @@ -0,0 +1,61 @@ +%{ + +/* MapAlgebra lexer */ +#include +#include +#include "ma_parser.tab.h" + +int nlines = 0; + +%} + +DIGIT [0-9] +ID [a-zA-Z][a-zA-Z0-9_]* + +%% + +{DIGIT}+("."{DIGIT}+)? {//printf("Found TKN_REAL: %d\n", atoi(yytext)); + yylval.real = atof(yytext); + return TKN_REAL;} +"=" {//printf("Found TKN_ASSIGN: %s\n",yytext); + return TKN_ASSIGN;} +";" {//printf("Found TKN_SEMICOLON: %s\n",yytext); + return TKN_SEMICOLON;} +"*" {//printf("Found TKN_PROD: %s\n",yytext); + return TKN_PROD;} +"/" {//printf("Found TKN_DIV: %s\n",yytext); + return TKN_DIV;} +"+" {//printf("Found TKN_PLUS: %s\n",yytext); + return TKN_PLUS;} +"-" {//printf("Found TKN_MINUS: %s\n",yytext);} + return TKN_MINUS; +"(" {//printf("Found TKN_LFT_PAR: %s\n",yytext); + return TKN_LFT_PAR;} +")" {//printf("Found TKN_RGT_PAR: %s\n",yytext); + return TKN_RGT_PAR;} +"cos" {//printf("Found TKN_COS: %s\n",yytext); + return TKN_COS;} +"sin" {//printf("Found TKN_SIN: %s\n",yytext); + return TKN_SIN;} +"\n" {nlines++;} +{ID} {//printf("Found TKN_ID: %s\n", yytext); + return TKN_ID;} +. + +%% + +void main(int argc, char **argv) +{ + if (argc > 1) + yyin = fopen(argv[1], "rt"); + else + yyin = stdin; + yylex(); + printf("%d lines analyzed\n", nlines); +} + + +/* To compile: + flex ma_lexer.l + gcc lex.yy.c -o ma_lexer -lfl -lm + */ diff --git a/raster/ma_lexer_only.l b/raster/ma_lexer_only.l new file mode 100644 index 000000000..4b82da3d6 --- /dev/null +++ b/raster/ma_lexer_only.l @@ -0,0 +1,47 @@ +%{ + +/* MapAlgebra lexer */ +#include +#include + +int nlines = 0; + +%} + +DIGIT [0-9] +ID [a-zA-Z][a-zA-Z0-9_]* + +%% + +{DIGIT}+ {printf("Found TKN_INTEGER: %d\n", atoi(yytext));} +{DIGIT}+"."{DIGIT}+ {printf("Found TKN_REAL: %d\n", atoi(yytext));} +"=" {printf("Found TKN_ASSIGN: %s\n",yytext);} +";" {printf("Found TKN_SEMICOLON: %s\n",yytext);} +"*" {printf("Found TKN_PROD: %s\n",yytext);} +"/" {printf("Found TKN_DIV: %s\n",yytext);} +"+" {printf("Found TKN_PLUS: %s\n",yytext);} +"-" {printf("Found TKN_MINUS: %s\n",yytext);} +"(" {printf("Found TKN_LFT_PAR: %s\n",yytext);} +")" {printf("Found TKN_RGT_PAR: %s\n",yytext);} +"cos" {printf("Found TKN_COS: %s\n",yytext);} +"sin" {printf("Found TKN_SIN: %s\n",yytext);} +"\n" {nlines++;} +{ID} {printf("Found TKN_ID: %s\n", yytext);} +. + +%% + +void main(int argc, char **argv) +{ + if (argc > 1) + yyin = fopen(argv[1], "rt"); + else + yyin = stdin; + yylex(); + printf("%d lines analyzed\n", nlines); +} + +/* To compile: + flex ma_lexer_only.l + gcc lex.yy.c -o ma_lexer_only -lfl -lm + */