Hoa\Compiler Multiple Names for Token


#1

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

Example:

// C++esque grammar

...
%token dereference *
%token multiply *
...
#dereferenceExpression:
	::dereference:: expression()
	
// Demo-only -- ignore left recursion
#multiplyExpression:
	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.

#2

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.


#3

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


#4

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


#5

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


#6

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