source: trunk/Examples/Parsing.n @ 32

Revision 28, 676 bytes checked in by daeken, 6 years ago (diff)

Reverted parsing example that broke the build.

Line 
1/*
2        This code is public domain -- do with it what you wish.
3       
4        Authors:
5        * Cody Brocious (cody dot brocious at gmail dot com) -- 2008
6*/
7
8using Nextem.Parsing;
9using Nextem.String;
10
11[Tokenizer]
12class TestTokenizer {
13        | Number = @"[0-9]+(\.[0-9]+)?[dfDF]?"
14        | Arith = @"[+\-*/%\^]"
15        | OpenParen = drop @"\("
16        | CloseParen = drop @"\)"
17        | Whitespace = drop "[ \t]+"
18}
19
20def tokens = TestTokenizer.Parse("( 1 + 2 ) * 3");
21foreach(token in tokens) {
22        | Number(num) =>
23                print "Number: {0}" <- num
24        | Arith(op) =>
25                print "Arith: {0}" <- op
26        | OpenParen =>
27                print "Open parenthesis"
28        | CloseParen =>
29                print "Close parenthesis"
30        | Whitespace => ()
31}
Note: See TracBrowser for help on using the repository browser.