lex_state4.py revision 6498:e21e9ab5fad0
112855Sgabeblack@google.com# lex_state4.py
212855Sgabeblack@google.com#
312855Sgabeblack@google.com# Bad state declaration
412855Sgabeblack@google.com
512855Sgabeblack@google.comimport sys
612855Sgabeblack@google.comif ".." not in sys.path: sys.path.insert(0,"..")
712855Sgabeblack@google.com
812855Sgabeblack@google.comimport ply.lex as lex
912855Sgabeblack@google.com
1012855Sgabeblack@google.comtokens = [
1112855Sgabeblack@google.com    "PLUS",
1212855Sgabeblack@google.com    "MINUS",
1312855Sgabeblack@google.com    "NUMBER",
1412855Sgabeblack@google.com    ]
1512855Sgabeblack@google.com
1612855Sgabeblack@google.com
1712855Sgabeblack@google.comstates = (('comment', 'exclsive'),)
1812855Sgabeblack@google.com
1912855Sgabeblack@google.comt_PLUS = r'\+'
2012855Sgabeblack@google.comt_MINUS = r'-'
2112855Sgabeblack@google.comt_NUMBER = r'\d+'
2212855Sgabeblack@google.com
2312855Sgabeblack@google.com# Comments
2412855Sgabeblack@google.comdef t_comment(t):
2512855Sgabeblack@google.com    r'/\*'
2612855Sgabeblack@google.com    t.lexer.begin('comment')
2712855Sgabeblack@google.com    print("Entering comment state")
2812855Sgabeblack@google.com
2912855Sgabeblack@google.comdef t_comment_body_part(t):
3012855Sgabeblack@google.com    r'(.|\n)*\*/'
3112855Sgabeblack@google.com    print("comment body %s" % t)
3212855Sgabeblack@google.com    t.lexer.begin('INITIAL')
3312855Sgabeblack@google.com
3412855Sgabeblack@google.comdef t_error(t):
3512855Sgabeblack@google.com    pass
3612855Sgabeblack@google.com
3712855Sgabeblack@google.com
3812855Sgabeblack@google.com
3912855Sgabeblack@google.comlex.lex()
4012855Sgabeblack@google.com
4112855Sgabeblack@google.com
4212855Sgabeblack@google.com