Class: Rley::Lexical::Token
- Inherits:
-
Object
- Object
- Rley::Lexical::Token
- Defined in:
- lib/rley/lexical/token.rb
Overview
In Rley, a (lexical) token is an object created by a lexer (tokenizer) and passed to the parser. Such token an object is created when a lexer detects that a sequence of characters(a lexeme) from the input stream is an instance of a terminal grammar symbol. Say, that in a particular language, the lexeme 'foo' is an occurrence of the terminal symbol IDENTIFIER. Then the lexer will return a Token object that states the fact that 'foo' is indeed an IDENTIFIER. Basically, a Token is a pair (lexeme, terminal): it asserts that a given lexeme is an instance of given terminal symbol.
Instance Attribute Summary collapse
-
#lexeme ⇒ String
readonly
The sequence of character(s) from the input stream that is an occurrence of the related terminal symbol.
-
#terminal ⇒ Syntax::Terminal
readonly
Terminal symbol corresponding to the lexeme.
Instance Method Summary collapse
-
#initialize(theLexeme, aTerminal) ⇒ Token
constructor
Constructor.
Constructor Details
#initialize(theLexeme, aTerminal) ⇒ Token
Constructor.
24 25 26 27 |
# File 'lib/rley/lexical/token.rb', line 24 def initialize(theLexeme, aTerminal) @lexeme = theLexeme @terminal = aTerminal end |
Instance Attribute Details
#lexeme ⇒ String (readonly)
The sequence of character(s) from the input stream that is an occurrence of the related terminal symbol.
16 17 18 |
# File 'lib/rley/lexical/token.rb', line 16 def lexeme @lexeme end |
#terminal ⇒ Syntax::Terminal (readonly)
Returns Terminal symbol corresponding to the lexeme.
19 20 21 |
# File 'lib/rley/lexical/token.rb', line 19 def terminal @terminal end |