From 50c71fdd495b74e812f0e2a1af87e932a8aa9ade Mon Sep 17 00:00:00 2001 From: Nagi5Yeq Date: Sun, 21 Jun 2020 16:00:07 +0800 Subject: add error handling --- Parser.y | 1 + t/bad.pas | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 t/bad.pas diff --git a/Parser.y b/Parser.y index 8bc1546..7e7abde 100644 --- a/Parser.y +++ b/Parser.y @@ -215,6 +215,7 @@ statements statement : open_statement {$$=$1;} | closed_statement {$$=$1;} + | error {$$=std::make_shared(ctx);} ; open_statement diff --git a/t/bad.pas b/t/bad.pas new file mode 100644 index 0000000..3bc25ef --- /dev/null +++ b/t/bad.pas @@ -0,0 +1,26 @@ +program hello_world; + +extern Pascal_puts(s:string):integer; +extern Pascal_printf(s:string; ...):integer; +extern Pascal_scanf(s:string; ...):integer; + +function main():integer; +var + buf:array[0..1023] of char; + i:integer; +begin + Pascal_puts(; + (; + i+; + i:=3+; + Pascal_puts('Hello, World!'); + Pascal_printf('Variadic Function Test: %d, %s, %llx\n', 1, 'yes', 0x123456789abcd); + for i:=0 to 10 do + begin + if i=3 then continue; + if i=5 then break; + Pascal_printf('say something: '); + Pascal_scanf('%s', @buf[0]); + Pascal_printf('round %d you said: %s\n', i, @buf[0]) + end; +end; -- cgit