2000-12-08 21:42:35 +01:00
|
|
|
%{
|
|
|
|
/****************************************************************************
|
|
|
|
lexer.l
|
|
|
|
ParserWizard generated Lex file.
|
|
|
|
|
|
|
|
Date: 07 December 2000
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "parser.h"
|
|
|
|
#include "var.h"
|
2000-12-15 21:29:33 +01:00
|
|
|
#include "function.h"
|
2000-12-11 21:28:41 +01:00
|
|
|
#include "prepro.h"
|
2000-12-08 21:42:35 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
|
|
%}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// declarations section
|
|
|
|
|
|
|
|
// lexical analyser name
|
|
|
|
%name mylexer
|
|
|
|
|
|
|
|
// class definition
|
|
|
|
{
|
2000-12-11 21:28:41 +01:00
|
|
|
int openInputFile(char *_filename);
|
|
|
|
int closeInputFile();
|
|
|
|
|
|
|
|
void setCurrentParser(class myparser *_parser) {m_currentParser=_parser;}
|
|
|
|
class myparser *getCurrentParser() {return m_currentParser;}
|
|
|
|
|
2000-12-12 21:51:59 +01:00
|
|
|
void error();
|
|
|
|
int getErrorCount();
|
2000-12-11 21:28:41 +01:00
|
|
|
|
|
|
|
// Overridden lexer functions
|
2000-12-12 21:51:59 +01:00
|
|
|
int yygetchar();
|
2000-12-11 21:28:41 +01:00
|
|
|
|
|
|
|
private:
|
2000-12-12 21:51:59 +01:00
|
|
|
void unexpectedChar();
|
2000-12-22 18:10:46 +01:00
|
|
|
void comment();
|
2000-12-12 21:51:59 +01:00
|
|
|
|
2000-12-11 21:28:41 +01:00
|
|
|
|
|
|
|
class myparser *m_currentParser;
|
2000-12-08 21:42:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// constructor
|
|
|
|
{
|
|
|
|
// place any extra initialisation code here
|
|
|
|
}
|
|
|
|
|
|
|
|
// place any declarations here
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// rules section
|
|
|
|
|
|
|
|
%{
|
|
|
|
// extract yylval for use later on in actions
|
|
|
|
YYSTYPE& yylval = *(YYSTYPE*)yyparserptr->yylvalptr;
|
|
|
|
%}
|
|
|
|
|
|
|
|
// place your Lex rules here
|
|
|
|
|
2000-12-12 21:51:59 +01:00
|
|
|
^#.* {if(preprocessorCmd(yytext+1)!=(int)true)error();}
|
|
|
|
# {printf("# commands must be at start of line!\n");error();}
|
2000-12-11 21:28:41 +01:00
|
|
|
|
2000-12-08 21:42:35 +01:00
|
|
|
stop {return STOP;}
|
|
|
|
if {return IF;}
|
|
|
|
else {return ELSE;}
|
2000-12-20 21:15:24 +01:00
|
|
|
while {return WHILE;}
|
|
|
|
do {return DO;}
|
2000-12-08 21:42:35 +01:00
|
|
|
pause {return PAUSE;}
|
|
|
|
print {return PRINT;}
|
|
|
|
= {return ASSIGN;}
|
|
|
|
== {return EQUAL;}
|
|
|
|
!= {return NOTEQUAL;}
|
2000-12-20 21:15:24 +01:00
|
|
|
\< {return LESSTHAN;}
|
|
|
|
\> {return GREATERTHAN;}
|
2000-12-08 21:42:35 +01:00
|
|
|
\+ {return PLUS;}
|
2000-12-20 21:15:24 +01:00
|
|
|
\- {return SUBTRACT;}
|
2000-12-22 18:10:46 +01:00
|
|
|
\* {return MULTIPLY;}
|
|
|
|
\/ {return DIVIDE;}
|
2000-12-08 21:42:35 +01:00
|
|
|
; {return END_STMT;}
|
|
|
|
\( {return OPEN_PAR;}
|
|
|
|
\) {return CLOSE_PAR;}
|
|
|
|
\{ {return BEGIN_CS;}
|
2000-12-20 21:15:24 +01:00
|
|
|
\} {return END_CS;}
|
2000-12-15 21:29:33 +01:00
|
|
|
, {return COMMA;}
|
|
|
|
|
2000-12-11 21:28:41 +01:00
|
|
|
|
2000-12-08 21:42:35 +01:00
|
|
|
\$[a-zA-Z_][a-zA-Z_0-9]* {yylval.variableIdx=lookupVarName(yytext+1);return VARIABLE;}
|
|
|
|
[0-9]+ {yylval.value=atoi(yytext);return VALUE;}
|
2000-12-11 21:28:41 +01:00
|
|
|
// \"[^\"]*\" {printf("s:%s\n",yytext);return STRING;}
|
|
|
|
|
2000-12-15 21:29:33 +01:00
|
|
|
_[a-zA-Z_][a-zA-Z_0-9]* {yylval.functionNumber=lookupFunctionName(yytext+1);return FUNCTION;}
|
|
|
|
|
2000-12-11 21:28:41 +01:00
|
|
|
\/\/.* {}
|
2000-12-22 18:10:46 +01:00
|
|
|
\/\* {comment();}
|
2000-12-08 21:42:35 +01:00
|
|
|
[ \t]+ {}
|
2000-12-11 21:28:41 +01:00
|
|
|
\n {}
|
2000-12-08 21:42:35 +01:00
|
|
|
|
2000-12-12 21:51:59 +01:00
|
|
|
. {unexpectedChar();}
|
2000-12-08 21:42:35 +01:00
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// programs section
|
|
|
|
|