/* SI 413 Fall 2011 * Lab 6 * spl-pt2.lpp * This is a scanner specification for the SPL programming language. * The semantic values are all one-node ParseTree objects. */ %{ #include <iostream> using namespace std; #include "parsetree.hpp" #include "spl2.tab.hpp" %} %option noyywrap %% [0-9]+ {yylval = new ParseTree(yytext); return NUM;} true|false {yylval = new ParseTree(yytext); return BOOL;} [+-] {yylval = new ParseTree(yytext); return OPA;} [*/] {yylval = new ParseTree(yytext); return OPM;} and|or {yylval = new ParseTree(yytext); return BOP;} "!" {yylval = new ParseTree(yytext); return NOT;} ":=" {yylval = new ParseTree(yytext); return ASN;} "(" {yylval = new ParseTree(yytext); return LP;} ")" {yylval = new ParseTree(yytext); return RP;} "{" {yylval = new ParseTree(yytext); return LC;} "}" {yylval = new ParseTree(yytext); return RC;} ";" {yylval = new ParseTree(yytext); return STOP;} [><=]|([><!]=) {yylval = new ParseTree(yytext); return COMP;} if {yylval = new ParseTree(yytext); return IF;} else {yylval = new ParseTree(yytext); return ELSE;} while {yylval = new ParseTree(yytext); return WHILE;} read {yylval = new ParseTree(yytext); return READ;} write {yylval = new ParseTree(yytext); return WRITE;} lambda {yylval = new ParseTree(yytext); return LAMBDA;} new {yylval = new ParseTree(yytext); return NEW;} [a-zA-Z0-9_]+ {yylval = new ParseTree(yytext); return ID;} <<EOF>> { return 0; } [ \t\n]+ { } "#".* { } . { cerr << "Unrecognized token!" << endl; exit(1); } %%