summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNagi5Yeq <wu@x-nagi.com>2020-06-01 12:02:15 +0800
committerNagi5Yeq <wu@x-nagi.com>2020-06-01 12:02:15 +0800
commita7c22d6229b5072445cb814b43140d8c8cc937a5 (patch)
tree11cd6b6876bacc66bd481a1c1d33d064d4dbc7ed
parent241f27a653330af1227694947626f409c3b128e2 (diff)
bugfix and comment support
-rw-r--r--Lexer.l11
-rw-r--r--Parser.y2
-rw-r--r--node/FunctionNode.cc2
-rw-r--r--t/common.c26
-rw-r--r--t/extern.pas16
-rw-r--r--t/trivial.pas19
6 files changed, 55 insertions, 21 deletions
diff --git a/Lexer.l b/Lexer.l
index 390e1ad..b442577 100644
--- a/Lexer.l
+++ b/Lexer.l
@@ -43,9 +43,10 @@ identifier [a-z_][0-9a-z_]*
white [\t\f\r ]
-comment1 \{((.|[\n\r])*?)\}
-comment2 \(\*((.|[\n\r])*?)\*\)
-comment {comment1}|{comment2}
+comment1 \{([^}])*\}
+comment2 \(\*((\*[^\)])|([^*]))*\*\)
+comment3 \(\*\*\*\)
+comment {comment1}|{comment2}|{comment3}
%{
#define YY_USER_ACTION loc.columns(yyleng);
@@ -167,7 +168,7 @@ comment {comment1}|{comment2}
{comment} {}
. {
- std::cerr<<"ERROR";
+ pcc::Log(pcc::LogLevel::PCC_ERROR, "Unrecognized token \"{0}\"", yytext);
}
<<EOF>> {return Parser::make_FILE_END(loc);}
@@ -179,7 +180,7 @@ int Driver::StartLexer(std::string& filename) {
yy_flex_debug = (GetLogLevel()==LogLevel::PCC_DEBUG);
yyin = std::fopen(filename.c_str(), "r");
if (yyin == NULL) {
- Log(LogLevel::PCC_ERROR, "Failed to open file %s", filename.c_str());
+ Log(LogLevel::PCC_ERROR, "Failed to open file {0}", filename);
return -1;
}
return 0;
diff --git a/Parser.y b/Parser.y
index f4e9779..5a68916 100644
--- a/Parser.y
+++ b/Parser.y
@@ -347,7 +347,7 @@ namespace pcc {
{
std::stringstream loc;
loc<<l;
- Log(LogLevel::PCC_ERROR, "error at %s: %s", loc.str().c_str(), m.c_str());
+ Log(LogLevel::PCC_ERROR, "error at {0}: {1}", loc.str().c_str(), m.c_str());
}
}
diff --git a/node/FunctionNode.cc b/node/FunctionNode.cc
index e2ab18f..0dcafb1 100644
--- a/node/FunctionNode.cc
+++ b/node/FunctionNode.cc
@@ -47,7 +47,7 @@ Value FunctionNode::CodeGen() {
context_->AddFunction(name_, {type, function});
llvm::BasicBlock* block =
llvm::BasicBlock::Create(GlobalLLVMContext, name_, function);
- Log(LogLevel::PCC_INFO, "generating function {0} of type {0}", name_,
+ Log(LogLevel::PCC_INFO, "generating function {0} of type {1}", name_,
type->GetCommonName());
builder->SetInsertPoint(block);
context_->PushScope(&locals_);
diff --git a/t/common.c b/t/common.c
new file mode 100644
index 0000000..28ef0db
--- /dev/null
+++ b/t/common.c
@@ -0,0 +1,26 @@
+#ifdef _MSC_VER
+#define _CRT_SECURE_NO_WARNINGS
+#endif // _MSC_VER
+
+#include <stdarg.h>
+#include <stdio.h>
+
+int Pascal_puts(const char* s) { return puts(s); }
+
+int Pascal_printf(const char* fmt, ...) {
+ int rv;
+ va_list va;
+ va_start(va, fmt);
+ rv = vprintf(fmt, va);
+ va_end(va);
+ return rv;
+}
+
+int Pascal_scanf(const char* fmt, ...) {
+ int rv;
+ va_list va;
+ va_start(va, fmt);
+ rv = vscanf(fmt, va);
+ va_end(va);
+ return rv;
+}
diff --git a/t/extern.pas b/t/extern.pas
index a23c371..89a3c78 100644
--- a/t/extern.pas
+++ b/t/extern.pas
@@ -1,22 +1,22 @@
program hello_world;
-extern puts(s:string):integer;
-extern printf(s:string, ...):integer;
-extern __isoc99_scanf(s:string, ...):integer;
+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
- puts('Hello, World!');
- printf('Variadic Function Test: %d, %s, %x\n', 1, 'yes', 0x12345678);
+ Pascal_puts('Hello, World!');
+ Pascal_printf('Variadic Function Test: %d, %s, %x\n', 1, 'yes', 0x12345678);
for i:=0 to 10 do
begin
if i=3 then continue;
if i=5 then break;
- printf('say something: ');
- __isoc99_scanf('%s', @buf[0]);
- printf('round %d you said: %s\n', i, @buf[0])
+ Pascal_printf('say something: ');
+ Pascal_scanf('%s', @buf[0]);
+ Pascal_printf('round %d you said: %s\n', i, @buf[0])
end;
end;
diff --git a/t/trivial.pas b/t/trivial.pas
index 72f2d40..3be4ca5 100644
--- a/t/trivial.pas
+++ b/t/trivial.pas
@@ -5,17 +5,12 @@ const
gi=5;
gr=3.1415;
gs='nagi';
-var {this is comment}
+var
gvi:integer;
gvf:real;
gvp:^char;
gva:array[0..4] of integer;
-(* multiline
-
-
-comments *)
-
function arithmetic_test(a:integer;b:char;c:real):integer;
var
d:integer;
@@ -223,3 +218,15 @@ begin
pa^.m4[1].m1[2]:=1234;
record_test:=a.m3[6]+pa^.m3[a.m1]+a.m4[1].m1[2];
end;
+
+(**)function {}comment_test({}):integer{};(**)
+{comment}
+begin{
+begin(* this is in a comment *)
+end;
+}
+comment_test:=1
+(*
+{begin end; also in a comment}
+*)(**)(****)(* *)(***)
+end;