Author Topic: AST - Tokens can't start nodes?  (Read 1834 times)

RIL

  • EA User
  • **
  • Posts: 142
  • Karma: +3/-0
  • -- There's always a solution --
    • View Profile
AST - Tokens can't start nodes?
« on: August 23, 2013, 08:07:10 am »
I'm trying to pick up COMMENT as a node in the AST tree, but it seems like it doesn't even try as long as <COMMENT> is defined as a token (in the beginning of the nBNF file).

I noticed that the Simple Example started with the following declaration for tokens, and, it seems to me, thus suppressing node generation from any of those tokens:

Code: [Select]
<TOKENS>      ::=      <WHITESPACE> |
                  <COMMENT> |            <--- Huh?
                  token(<NUMBER>) |
                  token(<QUOTE>) token(<STRING_BODY>) token(<QUOTE>) |
                  token( keywords() ) |
                  token(<IDENTIFIER>);

What I'm at is that since EA recognizes the term COMMENT as a distinct model element, then why is a comment considered being only a "token" (and thus can't be picked up and stored in the model)?

I might be entirely off track here though. Am I missing the meaning of token vsv terms/named nodes? Something else? Or all of it? :)

I couldn't find a clear description in the help about how EA parser treats tokens compared to named nodes.

// Rolf
« Last Edit: August 23, 2013, 10:08:09 pm by Rolf_Lampa »
-- There's always a solution --

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 7731
  • Karma: +103/-18
    • View Profile
Re: AST - Tokens can't start nodes?
« Reply #1 on: August 26, 2013, 08:44:18 am »
So make it a token?

Code: [Select]
<TOKENS>      ::=      <WHITESPACE> |
                  token(<COMMENT>) |
                  token(<NUMBER>) |
                  token(<QUOTE>) token(<STRING_BODY>) token(<QUOTE>) |
                  token( keywords() ) |
                  token(<IDENTIFIER>);

In your parse statement you then specify that as a language escape.

Code: [Select]
parse(<translationUnit>, <languageEscape>);

<languageEscape> ::= attribute("COMMENT", <COMMENT>);
Eve

support@sparxsystems.com

RIL

  • EA User
  • **
  • Posts: 142
  • Karma: +3/-0
  • -- There's always a solution --
    • View Profile
Re: AST - Tokens can't start nodes?
« Reply #2 on: August 28, 2013, 02:17:06 am »
Ok, thank you Simon, this really clears up my fog.

I was entirely off track, simply had a "missing link" leading me astray, but now things are getting interesting. :)

// Rolf
« Last Edit: August 28, 2013, 02:17:44 am by Rolf_Lampa »
-- There's always a solution --