source: cpp/frams/vm/framscript.l @ 171

Last change on this file since 171 was 163, checked in by sz, 11 years ago

Framscript grammar files

  • Property svn:eol-style set to native
File size: 3.2 KB
Line 
1%{
2// This file is a part of the Framsticks GDK.
3// Copyright (C) 2002-2014  Maciej Komosinski and Szymon Ulatowski.  See LICENSE.txt for details.
4// Refer to http://www.framsticks.com/ for further information.
5
6#include "framscript-defs.h"
7#include "framscript.tab.cpp.h"
8#include <math.h>
9
10#define YY_INPUT(buf,result,maxsize) {result=trctx.in->Vread(buf,1,maxsize);}
11#define YY_NEVER_INTERACTIVE 1
12
13%}
14
15%option noyywrap
16%x asmcode
17%x asmcode2
18%x comment
19
20%%
21
22\$[0-9a-fA-F]+ {int i; sscanf(yytext+1,"%x",&i); framscriptlval.setInt(i); return CONSTANT;}
230x[0-9a-fA-F]+ {int i; sscanf(yytext+2,"%x",&i); framscriptlval.setInt(i); return CONSTANT;}
24[0-9]+\.[0-9]*    {framscriptlval.setDouble(atof(yytext)); return CONSTANT;}
25[0-9]+            {framscriptlval.setInt(atoi(yytext)); return CONSTANT;}
26[0-9]+\.[0-9]*[eE][+-]?[0-9]+    {framscriptlval.setDouble(atof(yytext)); return CONSTANT;}
27[0-9]+*[eE][+-]?[0-9]+           {framscriptlval.setDouble(atof(yytext)); return CONSTANT;}
28"null"            {framscriptlval.setEmpty(); return CONSTANT;}
29\"([^\\\"]|\\.)*\" {framscriptlval.setString(SString(yytext+1,yyleng-2));return CONSTANT;}
30"@line "[0-9]+\n   {trctx.line=atol(yytext+6);}
31"@file "[^\n\t\r]+\n {trctx.srcname=SString(yytext+6,yyleng-7);}
32
33[a-zA-Z_][a-zA-Z0-9_]* { int t=lookupToken(yytext);
34                         if (t>=0) return t;
35                         else
36                            {
37                            framscriptlval.setString(yytext);
38                            return framscriptIsObjectName(yytext)?OBJNAME:IDENT;
39                            }
40                       }
41"=="               return EQUAL;
42"<>"               return NOT_EQUAL;
43"!="               return NOT_EQUAL;
44">="               return GEQUAL;
45"<="               return LEQUAL;
46
47"+="                return ASSIGN_ADD;
48"-="                return ASSIGN_SUB;
49"*="                return ASSIGN_MUL;
50"/="                return ASSIGN_DIV;
51"%="                return ASSIGN_MOD;
52
53"++"                return PLUSPLUS;
54"--"                return MINUSMINUS;
55
56"&&"                return LOGIC_AND;
57"||"                return LOGIC_OR;
58
59"<<"                return LSHIFT;
60">>"                return RSHIFT;
61
62<INITIAL,asmcode,asmcode2>\/\/.*\n         {trctx.line++;} // komentarz jednoliniowy
63<INITIAL,asmcode,asmcode2>\/\/[^\n]*       ;               // komentarz ale nie ma potem \n
64
65<INITIAL>\/\*       BEGIN comment;
66<comment>\n         {trctx.line++;}
67<comment>\*\/       BEGIN 0;
68<comment>.          ;
69
70[ \t\r\f]           ;
71\n                  {trctx.line++;}
72.                   return yytext[0];
73
74"asm"[ \t\n\r]*"{"  {
75                    BEGIN asmcode;
76                    char *t=yytext;
77                    while(t=strchr(t+1,'\n')) trctx.line++;
78                    return ASM;
79                    }
80<asmcode>.*\n {
81              char *t=yytext;
82              trctx.line++;
83              while ((*t==' ')||(*t=='\t')) t++;
84              if (*t=='}') {yyless((t-yytext)+1); BEGIN 0; return '}';}
85              char *e=yytext+yyleng-1;
86              while (e[-1]=='\r') e--;
87              framscriptlval.setString(SString(t,e-t));
88              return ASMLINE;
89              }
90
91%%
92void framscript_init_lex()
93{
94BEGIN 0;
95yyrestart(0);
96}
97
98void framscript_cleanup_lex()
99{
100yy_delete_buffer(yy_current_buffer);
101}
Note: See TracBrowser for help on using the repository browser.