Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Plain Text by hellyeah ( 17 years ago )
#ifndef _TOKENS_H
#define _TOKENS_H

#include <stdio.h>

enum Tokens {
  tEndOfFile = 0,
  tBeginOfTokens = 127,
  
  tNewline,
  tEndOfTokens
};

// const cFirstTokenValue = tBeginOfTokens + 1;
// const cLastTokenValue = tEndOfTokens - 1;

static char *theTokenNames[] = {"tNewLine"};

#endif

tokens.h

%{
#include <stdio.h>
#include "tokens.h"


char *yylval;

#define Return(t) { yylval = yytext; return(t);}
void yyerror(char* errorMsg);
%}
newline      "\n"




%%
{newline}    { Return(tNewline); }

.            { yyerror("[illegal token]"); }
  
%%

scanner.l

 ./scanner 
\n
[illegal token]
[illegal token]
token = tNewLine, value = "
"

 

Revise this Paste

Your Name: Code Language: