新建 文本文档 (2).txt
上传用户:dehuomake
上传日期:2014-05-14
资源大小:1k
文件大小:1k
- //FILE:tiny.1
- %{
- #include "globals.h"
- #include"util.h"
- #include"scan.h'
- char token string[MAXLEN+1];
- %}
- digit [0-9]
- number {digit}+
- letter [a-zA-Z]
- identifier {letter|number}+
- newline n
- whitespace [t]+
- %%
- "IF" {return IF;}
- "then" {return THEN;}
- "else" {return ELSE;}
- "end" {return END;}
- "repeat" {return REPEAT;}
- "until" {return UNTIL;}
- "read" {return READ;}
- "write" {return WRITE;}
- ":=" {return ASSIGN;}
- "=" {return EQ;}
- "<" {return LT;}
- "+" {return PLUS;}
- "*" {return TIMES;}
- "-" {return MINUS;}
- ";" {return SEMI;}
- "(" {return LPAREN;}
- ")" {return RPAREN;}
- {number} {return NUM;}
- {identifier} {return ID;}
- {newline} {lineno++}
- {whitespace} {/*skip whitespace*/}
- "{ {char c;
- do
- {c=input();
- if(c=='n') lineno++;
- }while(c!='}');
- }
- {return ERROR;}
- %%
- Token Type get Token(void)
- { static int firstTime=TRUE;
- TokenType currentToken;
- if(firstTime)
- {firstTime=FALSE;
- lineno++;
- yyin=source;
- yyout=listing;}
- currentToken=yylex();
- strncpy(tlkenString,yytex,MAXLEN);
- if(TraceScan){
- fprintf{ listing,"t%d:",lineno);
- printToken(currentToken,takenString);
- }
- return currentToken;}