diff options
-rw-r--r-- | examples/echo.lyn | 2 | ||||
-rw-r--r-- | examples/multiline.lyn | 3 | ||||
-rw-r--r-- | src/lexer.l | 3 | ||||
-rw-r--r-- | src/parser.y | 7 |
4 files changed, 13 insertions, 2 deletions
diff --git a/examples/echo.lyn b/examples/echo.lyn new file mode 100644 index 0000000..bfaa9ae --- /dev/null +++ b/examples/echo.lyn @@ -0,0 +1,2 @@ +use-modules (ice-9 readline) +display (readline "Type something: ") diff --git a/examples/multiline.lyn b/examples/multiline.lyn new file mode 100644 index 0000000..8cb0653 --- /dev/null +++ b/examples/multiline.lyn @@ -0,0 +1,3 @@ +if (< 10 20) \ + {display "math works"; newline} \ + {display "what"; newline} diff --git a/src/lexer.l b/src/lexer.l index 3c611ab..4756cf0 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -27,7 +27,7 @@ static void update_yylloc(struct parser *parser, YYLTYPE *lloc, const char *text #define YY_USER_ACTION update_yylloc(parser, yylloc, yytext); %} -ID [^(){};[:space:]]+ +ID [^(){};\\[:space:]]+ STRING \"(\\.|[^"\\])*\" HEX 0[xX][0-9a-fA-F]+ @@ -50,6 +50,7 @@ FLOAT {HEXF}|{DECF} "{" {return LBRACE;} "}" {return RBRACE;} ";" {return SEMICOLON;} +"\\" {return BACKSLASH;} "\n" {return NL;} {STRING} { diff --git a/src/parser.y b/src/parser.y index a87b6c6..edf71c1 100644 --- a/src/parser.y +++ b/src/parser.y @@ -45,6 +45,7 @@ %token LBRACE "{" %token RBRACE "}" %token SEMICOLON ";" +%token BACKSLASH "\\" %token NL "nl" %nterm <ast> arg args rev_args @@ -101,8 +102,12 @@ arg | INT {$$ = gen_int($1);} | FLOAT {$$ = gen_float($1);} +cont + : BACKSLASH NL + rev_args - : rev_args arg {$$ = $1; vect_append(struct lyn_value, $$.args, &$2);} + : rev_args cont arg {$$ = $1; vect_append(struct lyn_value, $$.args, &$3);} + | rev_args arg {$$ = $1; vect_append(struct lyn_value, $$.args, &$2);} | arg {$$ = gen_list(); vect_append(struct lyn_value, $$.args, &$1);} args |