Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e21b0b
commit 57342fe
Showing
6 changed files
with
114 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,60 @@ | ||
class OMCC | ||
|
||
import Util; | ||
import RTOpts; | ||
import System; | ||
import Absyn; | ||
import LexerGenerator; | ||
import ParserGenerator; | ||
constant String copyright = "OMCCp v0.10.0 OpenModelica lexer and parser generator (2014)"; | ||
|
||
public function main | ||
import Util; | ||
import RTOpts; | ||
import System; | ||
import Absyn; | ||
import LexerGenerator; | ||
import ParserGenerator; | ||
constant String copyright = "OMCCp v0.10.0 OpenModelica lexer and parser generator (2014)"; | ||
|
||
public function main | ||
"function: main | ||
This is the main function that the MetaModelica Compiler (MMC) runtime system calls to | ||
start the translation." | ||
input list<String> inStringLst; | ||
algorithm | ||
|
||
_ := matchcontinue (inStringLst) | ||
local | ||
String ver_str,errstr,filename,parser,ast; | ||
list<String> args_1,args,chars; | ||
String s,str,omhome,oldpath,newpath; | ||
Boolean result; | ||
case args as _::_ | ||
equation | ||
{parser} = Flags.new(args); | ||
print("Generating FLEX grammar file lexer" + parser +".c ...\n"); | ||
0 = System.systemCall("flex -t -l lexer" + parser +".l > lexer" + parser +".c"); | ||
print("Generating BISON grammar file parser" + parser +".c ...\n"); | ||
0 = System.systemCall("bison parser" + parser +".y --output=parser" + parser +".c"); | ||
str = LexerGenerator.genLexer("lexer"+ parser +".c", "lexer"+ parser +".l", parser); | ||
print("Result:" + str + "\n"); | ||
str = ParserGenerator.genParser("parser"+ parser +".c","parser"+ parser +".y",parser); | ||
print("Result:" + str + "\n"); | ||
|
||
print("\n 9 Files Generated for the language grammar:" + parser); | ||
printUsage(); | ||
then (); | ||
case _ | ||
equation | ||
print("\n**********Error*************"); | ||
printUsage(); | ||
then fail(); | ||
end matchcontinue; | ||
end main; | ||
|
||
public function printUsage | ||
protected | ||
Integer n; | ||
List<String> strs; | ||
Absyn.Program prog; | ||
Absyn.Class mClass; | ||
Absyn.ClassDef mCDef; | ||
algorithm | ||
/* mCDef := Absyn.OVERLOAD({Absyn.IDENT("fname")},NONE()); | ||
mClass := Absyn.CLASS("ctest",false,false,false,Absyn.R_CLASS(),mCDef); | ||
prog := Absyn.PROGRAM({mClass},Absyn.WITHIN(Absyn.IDENT("test")),Absyn.TIMESTAMP(System.getCurrentTime(),System.getCurrentTime())); | ||
printAny(prog); */ | ||
print("\n" + copyright +& "\n"); | ||
end printUsage; | ||
|
||
protected function readSettings | ||
"function: readSettings | ||
author: x02lucpo | ||
Checks if 'settings.mos' exist and uses handleCommand with runScript(...) to execute it. | ||
Checks if '-s <file>.mos' has been | ||
returns Interactive.InteractiveSymbolTable which is used in the rest of the loop" | ||
input list<String> inStringLst; | ||
output String str; | ||
algorithm | ||
str:= | ||
matchcontinue (inStringLst) | ||
local | ||
list<String> args; | ||
case (args) | ||
equation | ||
outSymbolTable = Interactive.emptySymboltable; | ||
"" = Util.flagValue("-s",args); | ||
// this is out-commented because automatically reading settings.mos | ||
// can make a system bad | ||
// outSymbolTable = readSettingsFile("settings.mos", Interactive.emptySymboltable); | ||
then | ||
outSymbolTable; | ||
case (args) | ||
equation | ||
str = Util.flagValue("-s",args); | ||
str = System.trim(str," \""); | ||
outSymbolTable = readSettingsFile(str, Interactive.emptySymboltable); | ||
then | ||
outSymbolTable; | ||
end matchcontinue; | ||
end readSettings; | ||
|
||
|
||
This is the main function that the MetaModelica Compiler (MMC) runtime system calls to | ||
start the translation." | ||
input list<String> inStringLst; | ||
algorithm | ||
|
||
_ := matchcontinue (inStringLst) | ||
local | ||
String ver_str,errstr,filename,parser,ast; | ||
list<String> args_1,args,chars; | ||
String s,str,omhome,oldpath,newpath; | ||
Boolean result; | ||
case "--lexer-only" :: args | ||
equation | ||
{parser} = Flags.new(args); | ||
print("Generating FLEX grammar file lexer" + parser +".c ...\n"); | ||
0 = System.systemCall("flex -t -l lexer" + parser +".l > lexer" + parser +".c"); | ||
str = LexerGenerator.genLexer("lexer"+ parser +".c", "lexer"+ parser +".l", parser); | ||
print("Result:" + str + "\n"); | ||
print("\nGenerated files:\n" + sum(" " + s + "Modelica.mo\n" for s in {"LexerCode","Lexer","LexTable"})); | ||
then (); | ||
case args as _::_ | ||
equation | ||
{parser} = Flags.new(args); | ||
print("Generating FLEX grammar file lexer" + parser +".c ...\n"); | ||
0 = System.systemCall("flex -t -l lexer" + parser +".l > lexer" + parser +".c"); | ||
print("Generating BISON grammar file parser" + parser +".c ...\n"); | ||
0 = System.systemCall("bison parser" + parser +".y --output=parser" + parser +".c"); | ||
str = LexerGenerator.genLexer("lexer"+ parser +".c", "lexer"+ parser +".l", parser); | ||
print("Result:" + str + "\n"); | ||
str = ParserGenerator.genParser("parser"+ parser +".c","parser"+ parser +".y",parser); | ||
print("Result:" + str + "\n"); | ||
|
||
print("\n 9 Files Generated for the language grammar:" + parser); | ||
then (); | ||
case _ | ||
equation | ||
print("\n**********Error*************"); | ||
printUsage(); | ||
then fail(); | ||
end matchcontinue; | ||
end main; | ||
|
||
public function printUsage | ||
algorithm | ||
print("\n" + copyright + "\n"); | ||
end printUsage; | ||
|
||
end OMCC; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,29 @@ | ||
OpenModelica.Scripting.setCFlags("-g " + getCFlags());getErrorString(); | ||
compilerSources := "../../../OMCompiler/Compiler/"; | ||
files := { | ||
"OMCC.mo", | ||
"../../../Compiler/FrontEnd/Absyn.mo", | ||
"../../../Compiler/Util/List.mo", | ||
"../../../Compiler/Util/Config.mo", | ||
"../../../Compiler/Global/Global.mo", | ||
"../../../Compiler/Util/Debug.mo", | ||
"../../../Compiler/Util/ErrorExt.mo", | ||
"../../../Compiler/Util/Error.mo", | ||
"../../../Compiler/Util/Print.mo", | ||
"../../../Compiler/Util/Corba.mo", | ||
"../../../Compiler/Util/Settings.mo", | ||
"../../../Compiler/Util/Flags.mo", | ||
"../../../Compiler/Util/Util.mo", | ||
"../../../Compiler/Util/System.mo", | ||
compilerSources + "/Util/List.mo", | ||
compilerSources + "/Util/Config.mo", | ||
compilerSources + "/Global/Global.mo", | ||
compilerSources + "/Util/Debug.mo", | ||
compilerSources + "/Util/ErrorExt.mo", | ||
compilerSources + "/Util/Error.mo", | ||
compilerSources + "/Util/Print.mo", | ||
compilerSources + "/Util/Corba.mo", | ||
compilerSources + "/Util/Settings.mo", | ||
compilerSources + "/Util/Flags.mo", | ||
compilerSources + "/Util/Util.mo", | ||
compilerSources + "/Util/StringUtil.mo", | ||
compilerSources + "/Util/System.mo", | ||
"LexerGenerator.mo", | ||
"ParserGenerator.mo"};getErrorString(); | ||
setCommandLineOptions({"+g=MetaModelica","+d=rml"}); | ||
loadFile(files);getErrorString(); | ||
OMCC.main({"Modelica"});getErrorString(); | ||
res:=loadFile(files); | ||
if min(res) == false then | ||
print(getErrorString()); | ||
exit(1); | ||
end if; | ||
getErrorString(); | ||
// OMCC.main({"Modelica"});getErrorString(); | ||
generateCode(OMCC.main); | ||
generateEntryPoint("omccMain.c", OMCC.main); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters