summaryrefslogtreecommitdiff
path: root/test/lhs1.lm
blob: 99499abe20f51ba29eeb64b5212c21ec2f279dee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
##### LM #####

lex
	ignore /space+/
	literal '*', '(', ')', '!', ';\n'
	token id /[a-zA-Z_0-9]+/ 
end

def item 
	[id]
	{
		lhs = cons item ["( " ^r1 " )"]
	}
|	['(' item* ')']
	{
		lhs = cons item ["( " ^r2 " )"]
	}

def A 
	[] {
		print( 'A\n' )
	}

def B
	[] {
		print( 'B\n' )
	}

def start 
	[A item* '!']
|	[B item* ';\n']

parse Start: start[ stdin ]
print( Start "\n" )
##### IN #####
a b c ( d1 d2 ) e f g ;
##### EXP #####
A
B
( a )( b )( c )( ( d1 )( d2 ) )( e )( f )( g );