Fennel: CalcLexer Class Reference (original) (raw)
CalcLexer is the scanner class used by the assembler to tokenize a calculator program. More...
#include <[CalcLexer.h](CalcLexer%5F8h-source.html)>
| Public Member Functions | |
|---|---|
| CalcLexer () | |
| Constructs a new Calculator Lexer object. | |
| int | yylex () |
| The lexical analzyer function. | |
| int | getPosition () const |
| Returns the character position of the next token. | |
| int | getColumn () const |
| Returns the column number of the next token. | |
| CalcYYLocType & | getLocation () |
| Returns the location of the current token. | |
| CalcTokenValue & | getValue () |
| Returns the semantic value of the current token. | |
| void | LexerError (const char *msg) |
| Reports a fatal error message by throwing a CalcAssemblerException. | |
| Protected Member Functions | |
| void | updateLocation () |
| Updates the location of the current token. | |
| int | hex (char ch) |
| string | hex2string (const char *buf, uint buflen) |
| Protected Attributes | |
| int | yycolno |
| The column number of the next token. | |
| int | yylineno |
| The line number of the next token. | |
| int | yypos |
| The character position (starting from 0) of the next token. | |
| CalcTokenValue | yylval |
| The sematic value of the current token. | |
| CalcYYLocType | yyloc |
| The location of the current token. |
Detailed Description
CalcLexer is the scanner class used by the assembler to tokenize a calculator program.
The class is automatically generated by flex from CalcLexer.lpp.
Definition at line 89 of file CalcLexer.h.
Constructor & Destructor Documentation
| CalcLexer::CalcLexer | ( | | ) | [inline, explicit] | | -------------------- | - | | - | -------------------- |
Member Function Documentation
The lexical analzyer function.
It scans the input stream, consuming tokens, until a rule's action returns a value
Referenced by CalcYYlex().
| int CalcLexer::getPosition | ( | | ) | const [inline] | | -------------------------- | - | | - | ---------------- |
Returns the character position of the next token.
Definition at line 102 of file CalcLexer.h.
| int CalcLexer::getColumn | ( | | ) | const [inline] | | ------------------------ | - | | - | ---------------- |
Returns the column number of the next token.
Definition at line 104 of file CalcLexer.h.
| void CalcLexer::LexerError | ( | const char * | msg | ) |
|---|
| void CalcLexer::updateLocation | ( | | ) | [protected] | | ------------------------------ | - | | - | ------------- |
Updates the location of the current token.
The location of the current token is calculated prior to every matched rule's action as part of the YY_USER_ACTION macro.
Definition at line 4543 of file CalcLexer.cpp.
References CalcYYLocType::first_column, CalcYYLocType::first_line, CalcYYLocType::first_pos, CalcYYLocType::last_column, CalcYYLocType::last_line, CalcYYLocType::last_pos, yycolno, yyleng, yylineno, yyloc, and yypos.
| int CalcLexer::hex | ( | char | ch | ) | [protected] |
|---|
Definition at line 4563 of file CalcLexer.cpp.
References getLocation().
Referenced by hex2string().
04564 { 04565 if ((ch >= 'a') && (ch <= 'f')) return (ch-'a'+10); 04566 else if ((ch >= '0') && (ch <= '9')) return (ch-'0'); 04567 else if ((ch >= 'A') && (ch <= 'F')) return (ch-'A'+10); 04568 else throw CalcAssemblerException("Invalid hex character", getLocation()); 04569 }
| string CalcLexer::hex2string | ( | const char * | buf, |
|---|---|---|---|
| uint | buflen | ||
| ) | [protected] |
Definition at line 4572 of file CalcLexer.cpp.
References count(), getLocation(), and hex().
04573 { 04574 int i, count; 04575 unsigned char ch; 04576 04577 assert(buf != NULL); 04578 if ((buflen % 2) != 0) { 04579 throw CalcAssemblerException("Invalid hex encoded string", getLocation()); 04580 } 04581 04582 count = buflen/2; 04583 04584 string str(count, 0); 04585 04586 for (i=0; i<count; i++) { 04587 ch = hex(*buf++) << 4; 04588 ch = ch + hex(*buf++); 04589 str[i] = ch; 04590 } 04591 return str; 04592 }
Member Data Documentation
The sematic value of the current token.
Definition at line 129 of file CalcLexer.h.
The documentation for this class was generated from the following files:
- /home/pub/open/dev/fennel/calculator/CalcLexer.h
- /home/pub/open/dev/fennel/calculator/CalcLexer.cpp
- /home/pub/open/dev/fennel/calculator/lex.yy.c
- /home/pub/open/dev/fennel/disruptivetech/calc/CalcLexer.cpp
