This commit is contained in:
Paul 2000-12-11 20:28:41 +00:00
parent f6a49831f1
commit c83e9cbd5a
12 changed files with 786 additions and 471 deletions

View file

@ -8,6 +8,7 @@ Date: 07 December 2000
#include "parser.h"
#include "var.h"
#include "prepro.h"
#include <stdlib.h>
@ -21,7 +22,30 @@ Date: 07 December 2000
// class definition
{
// place any extra class members here
int openInputFile(char *_filename);
int closeInputFile();
void setCurrentParser(class myparser *_parser) {m_currentParser=_parser;}
class myparser *getCurrentParser() {return m_currentParser;}
int getCurrentLine() {return m_lineCount+1;}
int getCurrentCharOnLine() {return m_currentCharOnLine;}
int getErrorCount() {return m_errorCount;}
void error() {m_errorCount++;}
// Overridden lexer functions
int yygetchar();
private:
FILE *m_fhInput;
int m_charCount;
int m_lineCount;
int m_currentCharOnLine;
int m_errorCount;
class myparser *m_currentParser;
}
// constructor
@ -44,8 +68,9 @@ YYSTYPE& yylval = *(YYSTYPE*)yyparserptr->yylvalptr;
// place your Lex rules here
^[ \t]*#.* {/*preprocess(yytext);*/}
//# {yyerror("# commands must be at start of line!");}
^#.* {if(preprocessorCmd(yytext+1)!=0)error();}
# {printf("# commands must be at start of line! ( line %d )\n",getCurrentLine());error();}
stop {return STOP;}
if {return IF;}
else {return ELSE;}
@ -60,13 +85,16 @@ print {return PRINT;}
\) {return CLOSE_PAR;}
\{ {return BEGIN_CS;}
\} {return END_CS;}
\$[a-zA-Z_][a-zA-Z_0-9]* {yylval.variableIdx=lookupVarName(yytext+1);return VARIABLE;}
\/\/.* {}
[0-9]+ {yylval.value=atoi(yytext);return VALUE;}
[ \t]+ {}
\n {/*s_linesProcessed++;*/}
. {printf("?\n");/*printf("line:%d\n",yylineno);printf("-%s-\n",yytext);yyerror("Unexpected character in source");*/}
\$[a-zA-Z_][a-zA-Z_0-9]* {yylval.variableIdx=lookupVarName(yytext+1);return VARIABLE;}
[0-9]+ {yylval.value=atoi(yytext);return VALUE;}
// \"[^\"]*\" {printf("s:%s\n",yytext);return STRING;}
\/\/.* {}
[ \t]+ {}
\n {}
. {printf("UNEXPECTED CHAR: '%s' in line %d ( char %d )\n",yytext,getCurrentLine(),getCurrentCharOnLine());error();}
%%