mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 01:52:56 +01:00
grammar.py and friends: Make test/grammar compile and start
Doesn't successfully parse grammartest.code, yet, it errors out with a syntax error on whitespace. But at least it compiles and starts. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
8c5934725c
commit
16ce7abd93
5 changed files with 129 additions and 77 deletions
|
|
@ -1,10 +1,10 @@
|
|||
TOPDIR = ../..
|
||||
|
||||
USE_PROJECT_LIB = true
|
||||
MEMBERS += local.a($(OBJ))
|
||||
EXE_ARGS ?= grammartest.code
|
||||
PREREQ_BUILD += ytools
|
||||
FB_NAME = grammartest
|
||||
NAMESPACE_IN_GENERATED = gt
|
||||
|
||||
include $(TOPDIR)/make/proj.mk
|
||||
include $(TOPDIR)/make/generate-flex-bison.mk
|
||||
include $(MODDIR)/make/exe.mk
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
PROGRAM DEMO1
|
||||
BEGIN
|
||||
A:=3;
|
||||
B:=45;
|
||||
H:=-100023;
|
||||
C:=A;
|
||||
D123:=B34A;
|
||||
BABOON:=GIRAFFE;
|
||||
TEXT:="Hello world!";
|
||||
END.
|
||||
PROGRAM DEMO1
|
||||
BEGIN
|
||||
A:=3;
|
||||
B:=45;
|
||||
H:=-100023;
|
||||
C:=A;
|
||||
D123:=B34A;
|
||||
BABOON:=GIRAFFE;
|
||||
TEXT:="Hello world!";
|
||||
END.
|
||||
|
|
|
|||
44
test/grammar/main.cpp
Normal file
44
test/grammar/main.cpp
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#include <string>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <misc.h>
|
||||
#include <slog.h>
|
||||
#include <YMisc.h>
|
||||
|
||||
// TODO: this should be included from grammartest.tab.h automatically
|
||||
#include "include/grammartest.h"
|
||||
|
||||
#include "include/defs.h"
|
||||
#include "include/grammartest.tab.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "usage: %s input-file\n", filenotdir(argv[0]));
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char *path = argv[1];
|
||||
string content;
|
||||
if (YMisc::suck_in_file(path, content)<0) {
|
||||
slog(PRI_ERR, "failed to read [%s] (%s)", path, err());
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct context context = {
|
||||
line: 0
|
||||
};
|
||||
|
||||
struct vp_scanner *scanner = FB_SYM(init_scanner)(content.c_str());
|
||||
int status = FB_SYM(parse)(&context, FB_SYM(scanner_get_data)(scanner));
|
||||
FB_SYM(cleanup_scanner)(scanner);
|
||||
if (status) {
|
||||
slog(PRI_ERR, "failed to parse [%s] (%s)", path, err());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue