Why a so simple grammar doesn't work under c++ ?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   frederic_camps
Posted On:   Friday, May 3, 2002 01:27 AM

Why a so simple grammar doesn't work under c++ ? I try antlr in c++ way, but the grammar doesn't match the output. But the same grammar works well in C. --------> output : > ./t >word >word2 >enter rule go {"word"} depth 1 >TAG >word3 >exit rule go {"word2"} depth 1 >./t >123 >456 >enter rule go {"123"} depth 1 >INTEGER >678 >exit rule go {"456"} depth 1 >./t >tag1 >tag2 >enter rule go {"tag1"} depth 1 &   More>>

Why a so simple grammar doesn't work under c++ ?



I try antlr in c++ way, but the grammar doesn't match the output. But the same grammar works well in C.




--------> output :

> ./t

>word
>word2
>enter rule go {"word"} depth 1
>TAG
>word3
>exit rule go {"word2"} depth 1




>./t

>123
>456
>enter rule go {"123"} depth 1
>INTEGER
>678
>exit rule go {"456"} depth 1



>./t

>tag1
>tag2
>enter rule go {"tag1"} depth 1
>KEY
>tag3
>exit rule go {"tag2"} depth 1




test2.g --------------------> start


< <
#include
>>

< <
#include "PBlackBox.h"
#include "DLGLexer.h"
typedef ANTLRCommonToken ANTLRToken;

int main()
{
ParserBlackBox p(stdin);
p.parser()->go();
return 0;
}
>>

#token "[ ]+" < >
#token "
" < >

#token INTEGER "[0-9]+"
#token TAG "[a-z]+"
#token KEY "[a-z0-9]*"

class Expr {

go : INTEGER
< <
cout < <"INTEGER" <
>>
| TAG
< <
cout < <"TAG" <
>>
| KEY < < cout < <" KEY " < < endl; >>
;
}


--------------------> end



make file ----------> start

#
# PCCTS makefile for: test2.g
#
# Created from: genmk -CC -class Expr -compiler g++ test2.g
#
# PCCTS release 1.33MR23
# Project: t
# C++ output
# DLG scanner
# ANTLR-defined token types
#
TOKENS = tokens.h
#
# The following filenames must be consistent with ANTLR/DLG flags
DLG_FILE = parser.dlg
ERR = err
HDR_FILE =
SCAN = DLGLexer
PCCTS = /usr/include/pccts
ANTLR_H = $(PCCTS)
BIN = /usr/bin
ANTLR = $(BIN)/antlr
DLG = $(BIN)/dlg
CFLAGS = -I. -I$(ANTLR_H) $(COTHER)
AFLAGS = -CC -k 2 -e3 -ga -gl -gd $(AOTHER)
DFLAGS = -CC -C2 -ci $(DOTHER)
GRM = test2.g
SRC = test2.cpp
Expr.cpp
$(ANTLR_H)/AParser.cpp $(ANTLR_H)/DLexerBase.cpp $(ANTLR_H)/ATokenBuffer.cpp $(SCAN).cpp

OBJ = test2.o
Expr.o
AParser.o DLexerBase.o ATokenBuffer.o $(SCAN).o

ANTLR_SPAWN = test2.cpp Expr.cpp
Expr.h $(DLG_FILE) $(TOKENS)
DLG_SPAWN = $(SCAN).cpp $(SCAN).h
CCC = g++

t : $(SRC) $(OBJ)
$(CCC) -o t $(CFLAGS) $(OBJ)

test2.o : $(TOKENS) $(SCAN).h test2.cpp
$(CCC) -c $(CFLAGS) -o test2.o test2.cpp

Expr.o : $(TOKENS) $(SCAN).h Expr.cpp Expr.h
$(CCC) -c $(CFLAGS) -o Expr.o Expr.cpp

$(SCAN).o : $(SCAN).cpp $(TOKENS)
$(CCC) -c $(CFLAGS) -o $(SCAN).o $(SCAN).cpp

$(ANTLR_SPAWN) : $(GRM)
$(ANTLR) $(AFLAGS) $(GRM)

$(DLG_SPAWN) : $(DLG_FILE)
$(DLG) $(DFLAGS) $(DLG_FILE)

AParser.o : $(ANTLR_H)/AParser.cpp
$(CCC) -c $(CFLAGS) -o AParser.o $(ANTLR_H)/AParser.cpp

ATokenBuffer.o : $(ANTLR_H)/ATokenBuffer.cpp
$(CCC) -c $(CFLAGS) -o ATokenBuffer.o $(ANTLR_H)/ATokenBuffer.cpp

DLexerBase.o : $(ANTLR_H)/DLexerBase.cpp
$(CCC) -c $(CFLAGS) -o DLexerBase.o $(ANTLR_H)/DLexerBase.cpp

clean:
rm -f *.o core t DLGLexer.h DLGLexer.cpp tokens.h Expr.cpp Expr.h test2.cpp scan.c test.h parser.dlg

scrub: clean
rm -f $(ANTLR_SPAWN) $(DLG_SPAWN)

make file ----------> start

   <<Less
About | Sitemap | Contact