From d9716ed74693b64ccbff1bf6de25aed38715acc3 Mon Sep 17 00:00:00 2001 From: Adrian Thurston Date: Sun, 29 Dec 2019 16:25:24 +0200 Subject: colm: updated hello_world and assign examples Removed the string concatenation from hello world examples (even though we want to bring it back eventually). Updated assign example so it does not use named lexical regions. Also removed the overlap between id and number, which resulted in the id form of number never matching. Added some error handling. refs #94 --- doc/colm/0_04_hello_world.adoc | 3 +-- doc/colm/code/assign.lm | 23 +++++++++++++++-------- doc/colm/code/hello_world.lm | 2 +- 3 files changed, 17 insertions(+), 11 deletions(-) (limited to 'doc') diff --git a/doc/colm/0_04_hello_world.adoc b/doc/colm/0_04_hello_world.adoc index 0406a159..8cbfab53 100644 --- a/doc/colm/0_04_hello_world.adoc +++ b/doc/colm/0_04_hello_world.adoc @@ -57,11 +57,10 @@ TIP: It turns out that print is also a function that can have multiple arguments [source,chapel] .hello_world_ext.lm ---- -print( 'hello ', "world" "\r\n" ) +print( 'hello ', "world\r\n" ) ---- We also notice that: * the quotes can be single and double -* there is no need for a concat operator * the whitespace is not significant * the newlines '\n' appear to be '\r\n' diff --git a/doc/colm/code/assign.lm b/doc/colm/code/assign.lm index d8b40d76..6add7cce 100644 --- a/doc/colm/code/assign.lm +++ b/doc/colm/code/assign.lm @@ -1,13 +1,15 @@ -lex start +lex token id / ('a' .. 'z' | 'A' .. 'Z' ) + / - token value / ( 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' )+ / + token number / ( '0' .. '9' )+ / literal `= `; - ignore / [ \t\n] / + ignore / [ \t\n]+ / end -def assignment - [ id `= value `;] +def value + [id] | [number] +def assignment + [id `= value `;] def assignment_list [assignment assignment_list] @@ -16,7 +18,12 @@ def assignment_list parse Simple: assignment_list[ stdin ] -for I:assignment in Simple { - print( I.id, "->", I.value, "\n" ) +if ( ! Simple ) { + print( "[error]\n" ) + exit( 1 ) +} +else { + for I:assignment in Simple { + print( $I.id, "->", $I.value, "\n" ) + } } - diff --git a/doc/colm/code/hello_world.lm b/doc/colm/code/hello_world.lm index 5522c5e1..a739e52d 100644 --- a/doc/colm/code/hello_world.lm +++ b/doc/colm/code/hello_world.lm @@ -1 +1 @@ -print "hello world" "\n" +print "hello world\n" -- cgit v1.2.1