Hoa\Compiler Multiple Names for Token

This isn’t a big issue, but I was wondering if it was possible to give a token more than one name?


// C++esque grammar

%token dereference *
%token multiply *
	::dereference:: expression()
// Demo-only -- ignore left recursion
	expression() ::multiply:: expression()

I tried something similar, and the .pp file is legal, but only the top token name would never be used. It would be nice to be able to do this for a couple reasons:

  1. It’s easier to read.
  2. It slightly reduces work required to change one of the tokens. For example, if you wanted to change dereference to @, you don’t need to change #dereferenceExpression.

Hello @KurtAhn,

Unfortunately, I am afraid the answer is no :-(. I understand your concern but in this situation, I would usually name the token star. An alternative would be to use token namespaces: Two tokens can have the same name if they live in different namespaces.

Just a curiosity: What are you implementing :-)?

I’m implementing a layer on top of MySQL. Just something to do before starting my Master’s in a related field.

Can we see the sources? I am curious, sorry… Forget my message if it annoys you :slight_smile:

No, not at all. I’ll try to upload it to Github within the next couple weeks.

1 Like