Skip to content

Commit

Permalink
Changed parser to a 1.4 compliant antlr-based parser. made some updat…
Browse files Browse the repository at this point in the history
…es to absyn to handle new 1.4 primitives. Fixed for-loop scooping in equations

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@667 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
henjo committed Dec 5, 2001
1 parent 0678dd1 commit f1a259b
Show file tree
Hide file tree
Showing 11 changed files with 1,855 additions and 7 deletions.
16 changes: 12 additions & 4 deletions modeq/Makefile
Expand Up @@ -6,17 +6,24 @@
# $Id$
#


ANTLR_HOME = /home/pelab/pub/pkg/antlr-2.7.1
ANTLR_CPP = $(ANTLR_HOME)/lib/cpp/gcc-2.95.2

ANTLR_INCP = -I$(ANTLR_CPP)/include
ANTLR_LIBP = -L$(ANTLR_CPP)/lib

SHELL = /bin/sh
CC = gcc
CFLAGS =
LDFLAGS = -lrml -lm
LDFLAGS = -L$(RMLHOME)/lib/plain $(ANTLR_LIBP) -lrml -lm -lantlr
#RML = /net/senilix/files/senilix3/labs/pelab/pub/pkg/rml/rml-2.1/sparc-sol2-gcc/bin/rmlc -g
RMLHOME = /home/pelab/pub/pkg/rml/current/sparc-sol2-gcc
RML = $(RMLHOME)/bin/rmlc -g
RMLINC = -I$(RMLHOME)/include/plain
#RML = rmlc -g
PROG = modeq
AST = ast/libast.a
AST = absyn_builder/absyn_builder.a
RTOBJ = runtime/rtopts.o

SRCRML= debug.rml \
Expand Down Expand Up @@ -46,7 +53,8 @@ SRCC= $(SRCRML:.rml=.c)
SRCH= $(SRCRML:.rml=.h)
SRCO= $(SRCC:.c=.o)

SUBDIRS = ast runtime
#SUBDIRS= ast runtime
SUBDIRS = runtime absyn_builder

.SUFFIXES:
.SUFFIXES: .o .rml .h
Expand All @@ -64,7 +72,7 @@ test:
@(cd testsuite ; make)

$(PROG): $(SRCO) $(AST) $(RTOBJ)
$(RML) -o $(PROG) $(SRCO) $(AST) $(RTOBJ) $(LDFLAGS)
g++ -o $(PROG) $(SRCO) $(AST) $(RTOBJ) $(LDFLAGS)

#absyn.o: absyn.rml
#exp.o: exp.rml
Expand Down
12 changes: 12 additions & 0 deletions modeq/absyn.rml
Expand Up @@ -61,9 +61,16 @@ module Absyn:
datatype ElementSpec = CLASSDEF of bool (* replaceable *)
* Class
| EXTENDS of Path * ElementArg list
| IMPORT of Import
| COMPONENTS of ElementAttributes (*1.1 contains Araydim also.*)
* Path (* type name *)
* Component list


datatype Import = NAMED_IMPORT of Ident * Path
| QUAL_IMPORT of Path
| UNQUAL_IMPORT of Path

(** An element is something that occurs in a public or protected
** section in a class definition. There is one constructor in the
** `ElementSpec' type for each possible element type. There are
Expand Down Expand Up @@ -91,6 +98,7 @@ module Absyn:
| EQ_CONNECT of ComponentRef * ComponentRef
| EQ_FOR of Ident * Exp * Equation list
| EQ_WHEN_E of Exp * Equation list (*1.1*)
| EQ_ASSERT of Assert

(** The `Equation' type describes one equation in an equation *)
(** section. *)
Expand All @@ -104,11 +112,15 @@ module Absyn:
| ALG_WHILE of Exp * Algorithm list
(* Old 1.0 | ALG_WHEN of Exp * Algorithm list *)
| ALG_WHEN_A of Exp * Algorithm list (*1.1*)
| ALG_ASSERT of Assert
(** The `Algorithm' type describes one algorithm statement in an *)
(** algorithm section. It does not describe a whole algorithm. The *)
(** reason this type is named like this is that the name of the *)
(** grammar rule for algorithm statements is `algorithm'. *)

datatype Assert = ASSERT of Exp * string list
| TERMINATE of string list

(** - Modifications *)
datatype Modification = CLASSMOD of ElementArg list * Exp option

Expand Down
69 changes: 69 additions & 0 deletions modeq/absyn_builder/Makefile
@@ -0,0 +1,69 @@
CC=gcc
CXX=g++

ANTLR_HOME = /home/pelab/pub/pkg/antlr-2.7.1
ANTLR_CPP = $(ANTLR_HOME)/lib/cpp/gcc-2.95.2

ANTLR_INCP = -I$(ANTLR_CPP)/include
ANTLR_LIBP = -L$(ANTLR_CPP)/lib

RML_HOME = /home/pelab/pub/pkg/rml/current
RML_INCP = -I$(RML_HOME)/sparc-sol2-gcc/include/plain

PARSE_HOME = ../../modelica_parser
PARSE_INCP = -I$(PARSE_HOME)/src
PARSE_LIBP = -L$(PARSE_HOME)/src

INCP = $(ANTLR_INCP) $(PARSE_INCP) $(RML_INCP)
LIBP = $(ANTLR_LIBP) $(PARSE_LIBP)

CFLAGS = $(INCP) -g -Wall
CXXFLAGS = $(CFLAGS)
LINKFLAGS = $(LIBP)

LIBS = -lantlr -lmodelica_parser

PARSER_OBJS = $(PARSE_HOME)/src/modelica_parser.o $(PARSE_HOME)/src/modelica_lexer.o \
$(PARSE_HOME)/src/token_names.o $(PARSE_HOME)/src/parse_tree_dumper.o


walkergen= modelica_tree_parser.cpp modelica_tree_parser.hpp \
modelica_tree_parserTokenTypes.hpp modelica_tree_parserTokenTypes.txt

walkersrcs=$(filter %.cpp,$(walkergen))
walkerobjs=$(walkersrcs:.cpp=.o)

OBJS += $(walkerobjs) $(PARSER_OBJS) parse.o yacclib.o

ANTLR = java -cp $(ANTLR_HOME) antlr.Tool

all : parser absyn_builder.a


parser:
cd $(PARSE_HOME)/src; $(MAKE) -f Makefile

absyn_builder.a : $(OBJS)
ar -r $@ $(OBJS)

#walker : $(OBJS)
# $(CXX) -o $@ $(OBJS) $(LINKFLAGS) $(LIBS)

$(walkergen): walker.g modelica_parserTokenTypes.txt
java antlr.Tool $(ANTLRFLAGS) $<


modelica_parserTokenTypes.txt : $(PARSE_HOME)/src/modelica_parserTokenTypes.txt
cp $(PARSE_HOME)/src/modelica_parserTokenTypes.txt .

clean:
-rm -f *.o *~ core *.core walker absyn_builder.a
-rm -f $(walkergen) modelica_parserTokenTypes.txt

reallyclean: clean



walker.o : walker.cpp $(PARSE_HOME)/src/modelica_lexer.hpp $(PARSE_HOME)/src/modelica_parser.hpp


71 changes: 71 additions & 0 deletions modeq/absyn_builder/parse.cpp
@@ -0,0 +1,71 @@

#include <iostream>
#include <strstream>
#include <fstream>

#include "modelica_lexer.hpp"
#include "modelica_parser.hpp"
#include "modelica_tree_parser.hpp"
#include "parse_tree_dumper.hpp"

extern "C"
{

int check_debug_flag(char const* strdata);

#include <errno.h>


void Parser_5finit(void)
{
}


RML_BEGIN_LABEL(Parser__parse)
{
char* filename = RML_STRINGDATA(rmlA0);
bool debug = check_debug_flag("parsedump");
try
{
std::ifstream stream(filename);

modelica_lexer lex(stream);
modelica_parser parse(lex);
parse.stored_definition();
antlr::RefAST t = parse.getAST();

if (t)
{
if (debug)
{
parse_tree_dumper dumper(std::cout);
dumper.dump(t);
}

modelica_tree_parser build;
void* ast = build.stored_definition(t);

if (debug)
{
std::cout << "Build done\n";
}

rmlA0 = ast ? ast : mk_nil();

RML_TAILCALLK(rmlSC);
}
}
catch (std::exception &e)
{
std::cerr << "Error while parsing:\n" << e.what() << "\n";
}
catch (...)
{
std::cerr << "Error while parsing\n";
}
RML_TAILCALLK(rmlFC);
}
RML_END_LABEL

} // extern "C"

0 comments on commit f1a259b

Please sign in to comment.