1

I'm trying to write a compiler program for a specific grammar I defined.

There are a few ε in the grammar because of some iterative and recursive rules. I tried to define ε by creating an empty token:

tokens = (
    'EMPTY'
) 

t_EMPTY = r'\ ' 

That caused some parsing problems, therefore I ignored spaces earlier in the lexer code:

t_ignore  = ' \t' 

What are other ways to describe define ε?

Click here to see the project files

  • 1
    Reading [yacc.py](https://github.com/euleriscoding/A-Parsing-Trial/blob/main/yacc.py#L1812), it appears to use a special value, `''`, to represent the empty terminal. Have you tried that? – Nick ODell May 20 '22 at 17:35

1 Answers1

0

Solved.The yacc.py module I used includes a special <empty> value for ε. Here is empty defining in the grammar part of the code:

def p_empty(p):
    'empty :'
    pass

def p_option(p):
    '''option : start 
              | empty '''